diff --git a/assets/images/desktop/captionButtons.png b/assets/images/desktop/captionButtons.png new file mode 100644 index 00000000..dd4a02dd Binary files /dev/null and b/assets/images/desktop/captionButtons.png differ diff --git a/assets/images/desktop/cursor.png b/assets/images/desktop/cursor.png new file mode 100644 index 00000000..63d81900 Binary files /dev/null and b/assets/images/desktop/cursor.png differ diff --git a/assets/images/desktop/windowFrame.png b/assets/images/desktop/windowFrame.png new file mode 100644 index 00000000..c675cfcf Binary files /dev/null and b/assets/images/desktop/windowFrame.png differ diff --git a/buildnumber.txt b/buildnumber.txt index 40ca05e7..8d28c8c9 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -534 \ No newline at end of file +554 \ No newline at end of file diff --git a/source/funkin/desktop/DesktopMain.hx b/source/funkin/desktop/DesktopMain.hx new file mode 100644 index 00000000..8677fc21 --- /dev/null +++ b/source/funkin/desktop/DesktopMain.hx @@ -0,0 +1,67 @@ +package funkin.desktop; + +import lime.app.Application; +import openfl.display.BitmapData; +import flixel.system.scaleModes.BaseScaleMode; +import flixel.system.scaleModes.FixedScaleAdjustSizeScaleMode; +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.math.FlxPoint; + +class DesktopMain extends MusicBeatState { + var oldScaleMode:BaseScaleMode; + var wallpaper:FlxSprite; + var screenSize:FlxPoint; + + var windows:WindowGroup; + + public var instance:DesktopMain; + + public override function create() { + super.create(); + instance = this; + + FlxG.mouse.visible = true; + FlxG.mouse.load(Paths.image('desktop/cursor')); + oldScaleMode = FlxG.scaleMode; + FlxG.scaleMode = new FixedScaleAdjustSizeScaleMode(false, false); + + wallpaper = new FlxSprite(); + #if windows + try { + wallpaper.loadGraphic(BitmapData.fromFile('${Sys.getEnv("AppData")}\\Microsoft\\Windows\\Themes\\TranscodedWallpaper')); + } catch(e) #end wallpaper.loadGraphic(Paths.image("menuBG")); + wallpaper.scrollFactor.set(0, 0); // anchor at top left + add(wallpaper); + + screenSize = new FlxPoint(FlxG.width, FlxG.height); + + windows = new WindowGroup(); + add(windows); + windows.add(new Window("Test Window", 640, 480, 200, 200)); + } + + public override function update(elapsed:Float) { + super.update(elapsed); + + // trace(FlxG.width, FlxG.height); + + if (screenSize.x != FlxG.width || screenSize.y != FlxG.height) { + screenSize.set(FlxG.width, FlxG.height); + updateScreenRes(); + } + } + + public function updateScreenRes() { + // update wallpaper + wallpaper.setUnstretchedGraphicSize(FlxG.width, FlxG.height); + } + + public override function destroy() { + super.destroy(); + FlxG.scaleMode = oldScaleMode; + + // TODO: switch back while using config + FlxG.resizeGame(1280, 720); + } +} \ No newline at end of file diff --git a/source/funkin/desktop/Window.hx b/source/funkin/desktop/Window.hx new file mode 100644 index 00000000..feab033a --- /dev/null +++ b/source/funkin/desktop/Window.hx @@ -0,0 +1,39 @@ +package funkin.desktop; + +import flixel.group.FlxSpriteGroup; +import openfl.geom.Rectangle; +import flixel.addons.ui.FlxUI9SliceSprite; +import flixel.FlxSprite; +import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; + +class Window extends FlxTypedSpriteGroup { + public var windowFrame:FlxUI9SliceSprite; + public var captionButtons:FlxTypedSpriteGroup; + + public var windowWidth:Int = 0; + public var windowHeight:Int = 0; + public function new(caption:String, width:Int = 640, height:Int = 480, x:Int = 20, y:Int = 20) { + super(); + windowFrame = new FlxUI9SliceSprite(0, 0, Paths.image('desktop/windowFrame'), new Rectangle(width, height), [3, 3, 6, 6]); + add(windowFrame); + + captionButtons = new FlxTypedSpriteGroup(); + for(i in 0...3) { + var btn = new WindowCaptionButton(this, i); + btn.x = (i+1) * -18; + captionButtons.add(btn); + } + add(captionButtons); + + windowWidth = width; + windowHeight = height; + + scrollFactor.set(0.5, 0.5); + updateWindowFrame(); + } + + public function updateWindowFrame() { + captionButtons.setPosition(windowWidth - 4, 4); + windowFrame.resize(windowWidth, windowHeight); + } +} \ No newline at end of file diff --git a/source/funkin/desktop/WindowCaptionButton.hx b/source/funkin/desktop/WindowCaptionButton.hx new file mode 100644 index 00000000..cb763869 --- /dev/null +++ b/source/funkin/desktop/WindowCaptionButton.hx @@ -0,0 +1,38 @@ +package funkin.desktop; + +import flixel.addons.ui.FlxUIButton; +import flixel.FlxSprite; + +class WindowCaptionButton extends FlxUIButton { + public var icon:FlxSprite; + + public function new(window:Window, i:Int) { + super(0, 0, "", function() { + switch(i) { + default: + trace(i); + } + }); + ID = i; + resize(18, 18); + color = (i > 0) ? 0xFF8888FF : 0xFFFF0000; + + icon = new FlxSprite(0, 0).loadGraphic(Paths.image('desktop/captionButtons'), true, 18, 18); + icon.animation.add("button", [switch(i) { + case 0: 2; + case 1: 1; + case 2: 0; + default: i; + }]); + icon.animation.play("button"); + } + + public override function draw() { + super.draw(); + + icon.setPosition(x, y); + icon.cameras = this.cameras; + icon.draw(); + icon.scrollFactor.set(scrollFactor.x, scrollFactor.y); + } +} \ No newline at end of file diff --git a/source/funkin/desktop/WindowGroup.hx b/source/funkin/desktop/WindowGroup.hx new file mode 100644 index 00000000..e2808d3f --- /dev/null +++ b/source/funkin/desktop/WindowGroup.hx @@ -0,0 +1,7 @@ +package funkin.desktop; + +import flixel.group.FlxGroup.FlxTypedGroup; + +class WindowGroup extends FlxTypedGroup { + // not removing, may be interesting +} \ No newline at end of file diff --git a/source/funkin/menus/MainMenuState.hx b/source/funkin/menus/MainMenuState.hx index 77cd676b..0d697fd9 100644 --- a/source/funkin/menus/MainMenuState.hx +++ b/source/funkin/menus/MainMenuState.hx @@ -122,6 +122,9 @@ class MainMenuState extends MusicBeatState if (!selectedSomethin) { + if (FlxG.keys.justPressed.SEVEN) + FlxG.switchState(new funkin.desktop.DesktopMain()); + if (controls.UP_P) { CoolUtil.playMenuSFX(0); diff --git a/source/funkin/system/CoolUtil.hx b/source/funkin/system/CoolUtil.hx index 73e7548c..249d822d 100644 --- a/source/funkin/system/CoolUtil.hx +++ b/source/funkin/system/CoolUtil.hx @@ -6,6 +6,7 @@ import flixel.animation.FlxAnimation; import flixel.util.FlxColor; import flixel.math.FlxMath; import flixel.FlxG; +import flixel.FlxSprite; using StringTools; @@ -130,6 +131,13 @@ class CoolUtil anim2.frames = old; } + public static function setUnstretchedGraphicSize(sprite:FlxSprite, width:Int, height:Int, fill:Bool = true) { + sprite.setGraphicSize(width, height); + sprite.updateHitbox(); + var nScale = (fill ? Math.max : Math.min)(sprite.scale.x, sprite.scale.y); + sprite.scale.set(nScale, nScale); + } + public static function keyToString(key:Null):String { return switch(key) { case null | 0 | NONE: "---";