fixing bug where you can select char anims off the window

This commit is contained in:
lunarcleint
2023-07-14 16:30:54 -07:00
parent 9f40e59936
commit 58afc70ab8
4 changed files with 17 additions and 2 deletions
@@ -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);
-1
View File
@@ -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) {
+3 -1
View File
@@ -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;
+10
View File
@@ -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());