From 5f50b80df7a578342e2aca95b61ba9b4f0456010 Mon Sep 17 00:00:00 2001 From: Dirk-Dinkum <134403819+Dirk-Dinkum@users.noreply.github.com> Date: Sat, 13 Apr 2024 21:55:44 +0200 Subject: [PATCH] UIWindow collapsing fix Co-Authored-By: Ne_Eo --- source/funkin/backend/FunkinSprite.hx | 1 + source/funkin/editors/charter/CharterNote.hx | 2 +- .../editors/charter/CharterStrumline.hx | 2 +- .../editors/charter/CharterStrumlineButton.hx | 2 +- source/funkin/editors/ui/UISliceSprite.hx | 10 ++++++++ source/funkin/editors/ui/UISprite.hx | 10 +++++++- source/funkin/editors/ui/UIState.hx | 17 ++----------- source/funkin/editors/ui/UIWindow.hx | 25 +++++++++++++------ 8 files changed, 42 insertions(+), 27 deletions(-) diff --git a/source/funkin/backend/FunkinSprite.hx b/source/funkin/backend/FunkinSprite.hx index 3f3f538c..6e247850 100644 --- a/source/funkin/backend/FunkinSprite.hx +++ b/source/funkin/backend/FunkinSprite.hx @@ -123,6 +123,7 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I private var countedBeat = 0; public function beatHit(curBeat:Int) { + if(!animEnabled) return; if (beatAnims.length > 0 && (curBeat + beatOffset) % beatInterval == 0) { if(skipNegativeBeats && curBeat < 0) return; diff --git a/source/funkin/editors/charter/CharterNote.hx b/source/funkin/editors/charter/CharterNote.hx index bc214209..af6dc7ea 100644 --- a/source/funkin/editors/charter/CharterNote.hx +++ b/source/funkin/editors/charter/CharterNote.hx @@ -139,7 +139,7 @@ class CharterNote extends UISprite implements ICharterSelectable { sustainDraggable = false; if (!hovered && susLength != 0) { - UIState.state.updateSpriteRect(sustainSpr); + sustainSpr.updateSpriteRect(); sustainDraggable = UIState.state.isOverlapping(sustainSpr, @:privateAccess sustainSpr.__rect); } diff --git a/source/funkin/editors/charter/CharterStrumline.hx b/source/funkin/editors/charter/CharterStrumline.hx index c7b332e3..6ffb297a 100644 --- a/source/funkin/editors/charter/CharterStrumline.hx +++ b/source/funkin/editors/charter/CharterStrumline.hx @@ -85,7 +85,7 @@ class CharterStrumline extends UISprite { healthIcons.follow(this, ((40 * 4) - healthIcons.width) / 2, 7 + (__healthYOffset = FlxMath.lerp(__healthYOffset, draggable ? 8 : 0, 1/20))); draggingSprite.selectable = draggable; - UIState.state.updateSpriteRect(draggingSprite); + draggingSprite.updateSpriteRect(); var dragScale:Float = FlxMath.lerp(draggingSprite.scale.x, draggable ? 1 : 0.8, 1/16); draggingSprite.scale.set(dragScale, dragScale); diff --git a/source/funkin/editors/charter/CharterStrumlineButton.hx b/source/funkin/editors/charter/CharterStrumlineButton.hx index a0a8c7df..c7d4944a 100644 --- a/source/funkin/editors/charter/CharterStrumlineButton.hx +++ b/source/funkin/editors/charter/CharterStrumlineButton.hx @@ -58,7 +58,7 @@ class CharterStrumlineButton extends UISprite { super.update(elapsed); - UIState.state.updateSpriteRect(button); + button.updateSpriteRect(); if(UIState.state.curContextMenu == null && UIState.state.isOverlapping(button, button.__rect)) { buttonScale.set(0.95, 0.95); if (FlxG.mouse.justPressed && onClick != null) { diff --git a/source/funkin/editors/ui/UISliceSprite.hx b/source/funkin/editors/ui/UISliceSprite.hx index e1f91b8d..664ede98 100644 --- a/source/funkin/editors/ui/UISliceSprite.hx +++ b/source/funkin/editors/ui/UISliceSprite.hx @@ -45,6 +45,11 @@ class UISliceSprite extends UISprite { var bottom:FlxFrame = null; var bottomright:FlxFrame = null; + public var topHeight:Int = 0; + public var bottomHeight:Int = 0; + public var leftWidth:Int = 0; + public var rightWidth:Int = 0; + override function set_frames(val) { super.set_frames(val); calculateFrames(); @@ -70,6 +75,11 @@ class UISliceSprite extends UISprite { bottomleft = frames.frames[framesOffset + 6]; bottom = frames.frames[framesOffset + 7]; bottomright = frames.frames[framesOffset + 8]; + + leftWidth = Std.int(Math.max(topleft.frame.width, Math.max(middleleft.frame.width, bottomleft.frame.width))); + rightWidth = Std.int(Math.max(topright.frame.width, Math.max(middleright.frame.width, bottomright.frame.width))); + topHeight = Std.int(Math.max(topleft.frame.height, Math.max(top.frame.height, topright.frame.height))); + bottomHeight = Std.int(Math.max(topleft.frame.height, Math.max(top.frame.height, topright.frame.height))); } public override function draw() @:privateAccess { diff --git a/source/funkin/editors/ui/UISprite.hx b/source/funkin/editors/ui/UISprite.hx index 1246e6de..07c9adc8 100644 --- a/source/funkin/editors/ui/UISprite.hx +++ b/source/funkin/editors/ui/UISprite.hx @@ -55,7 +55,8 @@ class UISprite extends FlxSprite { FlxCamera._defaultCameras = cameras; for(m in members) - m.update(elapsed); + if(m.exists && m.active) + m.update(elapsed); FlxCamera._defaultCameras = __oldDefCams; } @@ -114,4 +115,11 @@ class UISprite extends FlxSprite { if (hoverCallback != null) hoverCallback(); } + + public function updateSpriteRect() { + __rect.x = x; + __rect.y = y; + __rect.width = width; + __rect.height = height; + } } \ No newline at end of file diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index 1c32fad6..da3fdfc8 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -59,28 +59,15 @@ class UIState extends MusicBeatState { currentFocus.onTextEdit(str, start, end); } - public inline function updateSpriteRect(spr:UISprite) { - spr.__rect.x = spr.x; - spr.__rect.y = spr.y; - spr.__rect.width = spr.width; - spr.__rect.height = spr.height; - } - public function updateButtonHandler(spr:UISprite, buttonHandler:Void->Void) { - spr.__rect.x = spr.x; - spr.__rect.y = spr.y; - spr.__rect.width = spr.width; - spr.__rect.height = spr.height; + spr.updateSpriteRect(); updateRectButtonHandler(spr, spr.__rect, buttonHandler); } public function isOverlapping(spr:UISprite, rect:FlxRect) { for(camera in spr.__lastDrawCameras) { var pos = FlxG.mouse.getScreenPosition(camera, FlxPoint.get()); - __rect.x = rect.x; - __rect.y = rect.y; - __rect.width = rect.width; - __rect.height = rect.height; + __rect.copyFrom(rect); __rect.x -= camera.scroll.x * spr.scrollFactor.x; __rect.y -= camera.scroll.y * spr.scrollFactor.y; diff --git a/source/funkin/editors/ui/UIWindow.hx b/source/funkin/editors/ui/UIWindow.hx index 59ff735f..64f11eb8 100644 --- a/source/funkin/editors/ui/UIWindow.hx +++ b/source/funkin/editors/ui/UIWindow.hx @@ -18,19 +18,28 @@ class UIWindow extends UISliceSprite { public override function update(elapsed:Float) { super.update(elapsed); - if(collapsable && FlxG.mouse.justPressed) { - // TOOLBAR + cursor = ARROW; + + if(collapsable) { __rect.x = x; __rect.y = y; - __rect.width = bWidth; __rect.height = 23; + __rect.width = bWidth; __rect.height = topHeight; + if(UIState.state.isOverlapping(this, __rect)) { - content.exists = !content.exists; - drawMiddle = !drawMiddle; - drawBottom = !drawBottom; + cursor = BUTTON; + if(FlxG.mouse.justPressed) { + content.exists = !content.exists; + drawMiddle = !drawMiddle; + drawBottom = !drawBottom; + } } } - __rect.x = x; __rect.y = y+23; - __rect.width = bWidth; __rect.height = bHeight-23; + __rect.x = x; + __rect.width = bWidth; + if(content.exists) { + __rect.y = y+topHeight; + __rect.height = bHeight-topHeight; + } hovered = UIState.state.isOverlapping(this, __rect); } } \ No newline at end of file