From 58afc70ab89030fdb93cdda9e523d0a125a0bc18 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Fri, 14 Jul 2023 16:30:54 -0700 Subject: [PATCH] fixing bug where you can select char anims off the window --- .../funkin/editors/character/CharacterAnimsWindow.hx | 4 ++++ source/funkin/editors/ui/UIButton.hx | 1 - source/funkin/editors/ui/UISprite.hx | 4 +++- source/funkin/editors/ui/UIState.hx | 10 ++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/source/funkin/editors/character/CharacterAnimsWindow.hx b/source/funkin/editors/character/CharacterAnimsWindow.hx index 82a4a790..b4fda18c 100644 --- a/source/funkin/editors/character/CharacterAnimsWindow.hx +++ b/source/funkin/editors/character/CharacterAnimsWindow.hx @@ -113,8 +113,10 @@ class CharacterAnimButtons extends UIButton { super(x,y, '$anim (${offset.x}, ${offset.y})', function () { CharacterEditor.instance.playAnimation(this.anim); }, 282); + cameraLocked = true; ghostButton = new UIButton(x+282+17, y, "", null, 32); + ghostButton.cameraLocked = true; members.push(ghostButton); ghostIcon = new FlxSprite(ghostButton.x + 8, ghostButton.y + 8).loadGraphic(Paths.image('editors/character/ghost-button'), true, 16, 16); @@ -128,6 +130,7 @@ class CharacterAnimButtons extends UIButton { editButton = new UIButton(ghostButton.x+32+17, y, "", function () { CharacterEditor.instance.editAnimWithUI(this.anim); }, 32); + editButton.cameraLocked = true; members.push(editButton); editIcon = new FlxSprite(editButton.x + 8, editButton.y + 8).loadGraphic(Paths.image('editors/character/edit-button')); @@ -137,6 +140,7 @@ class CharacterAnimButtons extends UIButton { deleteButton = new UIButton(editButton.x+32+17, y, "", function () { CharacterEditor.instance.deleteAnim(this.anim); }, 32); + deleteButton.cameraLocked = true; deleteButton.color = FlxColor.RED; members.push(deleteButton); diff --git a/source/funkin/editors/ui/UIButton.hx b/source/funkin/editors/ui/UIButton.hx index 5b53f194..ad722970 100644 --- a/source/funkin/editors/ui/UIButton.hx +++ b/source/funkin/editors/ui/UIButton.hx @@ -4,7 +4,6 @@ import flixel.graphics.frames.FlxFrame; class UIButton extends UISliceSprite { public var callback:Void->Void = null; - public var field:UIText; public override function new(x:Float, y:Float, text:String, callback:Void->Void, w:Int = 120, h:Int = 32) { diff --git a/source/funkin/editors/ui/UISprite.hx b/source/funkin/editors/ui/UISprite.hx index d9fb178e..808cc400 100644 --- a/source/funkin/editors/ui/UISprite.hx +++ b/source/funkin/editors/ui/UISprite.hx @@ -22,6 +22,7 @@ class UISprite extends FlxSprite { public var cursor:MouseCursor = ARROW; public var focused(get, set):Bool; + public var cameraLocked:Bool = false; private inline function get_focused():Bool return UIState.state.currentFocus == cast this; @@ -43,7 +44,8 @@ class UISprite extends FlxSprite { hoveredByChild = false; super.update(elapsed); - updateButton(); + if (cameraLocked ? UIState.state.checkMouseOnCam(this) : true) + updateButton(); @:privateAccess { __oldDefCams = FlxCamera._defaultCameras; diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index d287e630..1391f63d 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -60,6 +60,16 @@ class UIState extends MusicBeatState { updateRectButtonHandler(spr, spr.__rect, buttonHandler); } + public function checkMouseOnCam(spr:UISprite) { + for(camera in spr.__lastDrawCameras) { + var pos = FlxG.mouse.getScreenPosition(FlxG.camera, FlxPoint.get()); + + if (((pos.x > camera.x) && (pos.x < camera.x + camera.width)) && ((pos.y > camera.y) && (pos.y < camera.y + camera.height))) + return true; + } + return false; + } + public function isOverlapping(spr:UISprite, rect:FlxRect) { for(camera in spr.__lastDrawCameras) { var pos = FlxG.mouse.getScreenPosition(camera, FlxPoint.get());