made buttons activate when buttons were pressed prior
This commit is contained in:
@@ -6,6 +6,7 @@ class UIButton extends UISliceSprite {
|
||||
public var callback:Void->Void = null;
|
||||
public var field:UIText;
|
||||
public var shouldPress = true;
|
||||
public var hasBeenPressed = false;
|
||||
|
||||
public override function new(x:Float, y:Float, text:String, callback:Void->Void, w:Int = 120, h:Int = 32) {
|
||||
super(x, y, w, h, 'editors/ui/button');
|
||||
@@ -28,12 +29,16 @@ class UIButton extends UISliceSprite {
|
||||
|
||||
public override function onHovered() {
|
||||
super.onHovered();
|
||||
if (FlxG.mouse.justReleased && callback != null && shouldPress)
|
||||
if (FlxG.mouse.justPressed) hasBeenPressed = true;
|
||||
if (FlxG.mouse.justReleased && callback != null && shouldPress && hasBeenPressed) {
|
||||
callback();
|
||||
hasBeenPressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
field.follow(this, 0, (bHeight - field.height) / 2);
|
||||
if (!hovered && hasBeenPressed && FlxG.mouse.justReleased) hasBeenPressed = false;
|
||||
super.update(elapsed);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user