From be059c533a355befdc76d74ed021359b3ecba1a8 Mon Sep 17 00:00:00 2001 From: lunarcleint Date: Sun, 29 Dec 2024 01:35:01 -0700 Subject: [PATCH] resizablable charter --- source/funkin/editors/charter/Charter.hx | 25 ++++++++++- source/funkin/editors/ui/UIScaleMode.hx | 55 ++++++++++++++++++++++++ source/funkin/editors/ui/UIState.hx | 28 ++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 source/funkin/editors/ui/UIScaleMode.hx diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 842c0615..b4080049 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -550,7 +550,7 @@ class Charter extends UIState { Framerate.memoryCounter.alpha = 0.4; Framerate.codenameBuildField.alpha = 0.4; } - updateDisplaySprites(); + UIState.setResolutionAware(); // ! IF YOU EVER WANNA VIEW IN THE FUTURE, JUST USE A FLXSPRITE :D -lunar /*var dataDisplay:FlxSprite = new FlxSprite().loadGraphic(waveformHandler.waveDatas.get("Voices.ogg")); @@ -1355,7 +1355,10 @@ class Charter extends UIState { function updateDisplaySprites() { gridBackdrops.strumlinesAmount = strumLines.members.length; - charterBG.scale.set(1 / charterCamera.zoom, 1 / charterCamera.zoom); + charterBG.scale.set( + (1 / charterCamera.zoom) * (FlxG.width/charterBG.width), + (1 / charterCamera.zoom) * (FlxG.height/charterBG.height) + ); strumlineInfoBG.scale.set(FlxG.width / charterCamera.zoom, 1); strumlineInfoBG.updateHitbox(); @@ -1369,6 +1372,24 @@ class Charter extends UIState { strumlineLockButton.y = strumlineInfoBG.y; } + public override function onResize(width:Int, height:Int) { + super.onResize(width, height); + + if (width < FlxG.initialWidth || height < FlxG.initialHeight) { + width = FlxG.initialWidth; height = FlxG.initialHeight; + } + + scrollBar.x = width - 20; + scrollBar.scale.y = Std.int(height - scrollBar.y); + scrollBar.updateHitbox(); + + songPosInfo.x = width - 30 - 400; + playBackSlider.x = width - 160 - 26 - 20; + + updateDisplaySprites(); + charterBG.screenCenter(); + } + var zoom(default, set):Float = 0; var __camZoom(default, set):Float = 1; function set_zoom(val:Float) { diff --git a/source/funkin/editors/ui/UIScaleMode.hx b/source/funkin/editors/ui/UIScaleMode.hx new file mode 100644 index 00000000..5d67bc7c --- /dev/null +++ b/source/funkin/editors/ui/UIScaleMode.hx @@ -0,0 +1,55 @@ +package funkin.editors.ui; + +import flixel.system.scaleModes.StageSizeScaleMode; + +class UIScaleMode extends StageSizeScaleMode { + override public function onMeasure(Width:Int, Height:Int):Void { + if (Width < FlxG.initialWidth || Height < FlxG.initialHeight) { + @:privateAccess { + FlxG.width = FlxG.initialWidth; + FlxG.height = FlxG.initialHeight; + } + + updateGameSize(Width, Height); + updateDeviceSize(Width, Height); + updateScaleOffset(); + updateGamePosition(); + } else { + super.onMeasure(Width, Height); + + for (camera in FlxG.cameras.list) { + camera.width = Width; + camera.height = Height; + } + } + } + + override function updateGameSize(Width:Int, Height:Int):Void + { + var ratio:Float = FlxG.width / FlxG.height; + var realRatio:Float = Width / Height; + + var scaleY:Bool = realRatio < ratio; + + if (scaleY) + { + gameSize.x = Width; + gameSize.y = Math.floor(gameSize.x / ratio); + } + else + { + gameSize.y = Height; + gameSize.x = Math.floor(gameSize.y * ratio); + } + + @:privateAccess { + for(camera in FlxG.cameras.list) { + camera.width = FlxG.initialWidth; + camera.height = FlxG.initialHeight; + } + + FlxG.width = FlxG.initialWidth; + FlxG.height = FlxG.initialHeight; + } + } +} \ No newline at end of file diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index 34be9f9e..f56c158c 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -1,5 +1,6 @@ package funkin.editors.ui; +import openfl.Lib; import funkin.editors.ui.notifications.UIBaseNotification; import flixel.math.FlxPoint; import flixel.math.FlxRect; @@ -9,6 +10,7 @@ import funkin.editors.ui.UIContextMenu.UIContextMenuCallback; import funkin.editors.ui.UIContextMenu.UIContextMenuOption; import lime.ui.KeyCode; import lime.ui.KeyModifier; +import flixel.system.scaleModes.StageSizeScaleMode; import openfl.ui.Mouse; import openfl.ui.MouseCursor; @@ -117,6 +119,16 @@ class UIState extends MusicBeatState { } public override function destroy() { + if (resolutionAware) { + resolutionAware = false; + + for (camera in FlxG.cameras.list) { + camera.width = FlxG.initialWidth; + camera.height = FlxG.initialHeight; + } + FlxG.scaleMode = Main.scaleMode; + } + super.destroy(); __mousePos.put(); @@ -164,4 +176,20 @@ class UIState extends MusicBeatState { //notification.appearAnimation(); //FlxTween.tween(notification, {x: __mousePos.x, y: __mousePos.y, alpha: 1}, .3, {ease: FlxEase.circInOut}); } + + public static var resolutionAware:Bool = false; + public static var uiScaleMode:UIScaleMode = new UIScaleMode(); + + public static function setResolutionAware() { + resolutionAware = true; + FlxG.scaleMode = uiScaleMode; + } + + public override function onResize(width:Int, height:Int) { + super.onResize(width, height); + + if (!resolutionAware) return; + + trace(width, height); + } } \ No newline at end of file