From 3a59d8609a0c47ebbb1465b8eccc42d6acc64417 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Mon, 18 Mar 2024 11:27:43 -0700 Subject: [PATCH] fix compatibility with new FlxButtonState enum (#271) * fix compatibility with new FlxButtonState enum * add prev version --- CHANGELOG.md | 5 ++++ flixel/addons/ui/FlxUIDropDownMenu.hx | 12 ++++++++- flixel/addons/ui/FlxUITypedButton.hx | 28 ++++++++++++++------- flixel/addons/ui/interfaces/IFlxUIButton.hx | 4 +++ haxelib.json | 4 +-- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7f6e6b..0bff25f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +2.6.1 (March 18, 2024) +------------------------------ +Fixed compatibility with upcoming Flixel version 5.7.0 + + 2.6.0 (March 15, 2024) ------------------------------ diff --git a/flixel/addons/ui/FlxUIDropDownMenu.hx b/flixel/addons/ui/FlxUIDropDownMenu.hx index 3f043ca..f7a5696 100644 --- a/flixel/addons/ui/FlxUIDropDownMenu.hx +++ b/flixel/addons/ui/FlxUIDropDownMenu.hx @@ -12,6 +12,16 @@ import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; import flixel.util.FlxStringUtil; +#if (flixel < version("5.7.0")) +import flixel.ui.FlxButton.NORMAL; +import flixel.ui.FlxButton.HIGHLIGHT; +import flixel.ui.FlxButton.PRESSED; +#else +import flixel.ui.FlxButton.FlxButtonState.NORMAL; +import flixel.ui.FlxButton.FlxButtonState.HIGHLIGHT; +import flixel.ui.FlxButton.FlxButtonState.PRESSED; +import flixel.ui.FlxButton.FlxButtonState.DISABLED; +#end /** * @author larsiusprime */ @@ -330,7 +340,7 @@ class FlxUIDropDownMenu extends FlxUIGroup implements IFlxUIWidget implements IF t.loadGraphicSlice9([FlxUIAssets.IMG_INVIS, FlxUIAssets.IMG_HILIGHT, FlxUIAssets.IMG_HILIGHT], Std.int(header.background.width), Std.int(header.background.height), [[1, 1, 3, 3], [1, 1, 3, 3], [1, 1, 3, 3]], FlxUI9SliceSprite.TILE_NONE); - t.labelOffsets[FlxButton.PRESSED].y -= 1; // turn off the 1-pixel depress on click + t.labelOffsets[PRESSED].y -= 1; // turn off the 1-pixel depress on click t.up_color = FlxColor.BLACK; t.over_color = FlxColor.WHITE; diff --git a/flixel/addons/ui/FlxUITypedButton.hx b/flixel/addons/ui/FlxUITypedButton.hx index 3057410..5f3e5c1 100644 --- a/flixel/addons/ui/FlxUITypedButton.hx +++ b/flixel/addons/ui/FlxUITypedButton.hx @@ -23,6 +23,16 @@ import openfl.Assets; import openfl.display.BitmapData; import openfl.errors.Error; +#if (flixel < version("5.7.0")) +enum abstract FlxButtonState(Int) to Int +{ + var NORMAL = 0; + var HIGHLIGHT = 1; + var PRESSED = 2; + var DISABLED = 3; +} +#end + class FlxUITypedButton extends FlxTypedButton implements IFlxUIButton implements IResizable implements IFlxUIWidget implements IFlxUIClickable implements IHasParams implements ICursorPointable { @@ -274,7 +284,7 @@ class FlxUITypedButton extends FlxTypedButton implements IFlxUIB { super.update(elapsed); - if (status == FlxButton.NORMAL && mouseIsOver && input.justReleased == false) + if (status == NORMAL && mouseIsOver && input.justReleased == false) { // Detect rare edge case: // The button is not in a hilight/pressed state, but the button has ALSO not just been released, HOWEVER it thinks the mouse is still hovering @@ -526,9 +536,9 @@ class FlxUITypedButton extends FlxTypedButton implements IFlxUIB bd = getBmp(asset); } - upB = grabButtonFrame(bd, FlxButton.NORMAL, has_toggle, 0, 0, key); - overB = grabButtonFrame(bd, FlxButton.HIGHLIGHT, has_toggle, 0, 0, key); - downB = grabButtonFrame(bd, FlxButton.PRESSED, has_toggle, 0, 0, key); + upB = grabButtonFrame(bd, FlxButtonState.NORMAL, has_toggle, 0, 0, key); + overB = grabButtonFrame(bd, FlxButtonState.HIGHLIGHT, has_toggle, 0, 0, key); + downB = grabButtonFrame(bd, FlxButtonState.PRESSED, has_toggle, 0, 0, key); var normalGraphic:FlxGraphicAsset = key; if (key == null || key == "" || FlxG.bitmap.checkCache(key) == false) @@ -540,9 +550,9 @@ class FlxUITypedButton extends FlxTypedButton implements IFlxUIB { var normalPixels:BitmapData = assembleButtonFrames(upB, overB, downB); - upB = grabButtonFrame(bd, FlxButton.NORMAL + 3, true, 0, 0, key); - overB = grabButtonFrame(bd, FlxButton.HIGHLIGHT + 3, true, 0, 0, key); - downB = grabButtonFrame(bd, FlxButton.PRESSED + 3, true, 0, 0, key); + upB = grabButtonFrame(bd, (FlxButtonState.NORMAL:Int) + 3, true, 0, 0, key); + overB = grabButtonFrame(bd, (FlxButtonState.HIGHLIGHT:Int) + 3, true, 0, 0, key); + downB = grabButtonFrame(bd, (FlxButtonState.PRESSED:Int) + 3, true, 0, 0, key); var togglePixels:BitmapData = assembleButtonFrames(upB, overB, downB); var combinedPixels:BitmapData = combineToggleBitmaps(normalPixels, togglePixels); @@ -1018,12 +1028,12 @@ class FlxUITypedButton extends FlxTypedButton implements IFlxUIB if (framesHigh == 4) { // we have exactly 4 frames, assume "up","over","down","down_over" - if (button_state == FlxButton.HIGHLIGHT + 3) + if (button_state == FlxButtonState.HIGHLIGHT + 3) { // toggle-hilight _flashRect.y = (3) * h; // show "down_over" } - else if (button_state == FlxButton.PRESSED + 3) + else if (button_state == FlxButtonState.PRESSED + 3) { // toggle-pressed _flashRect.y = (2) * h; // show "down" diff --git a/flixel/addons/ui/interfaces/IFlxUIButton.hx b/flixel/addons/ui/interfaces/IFlxUIButton.hx index 145ecac..795be0b 100644 --- a/flixel/addons/ui/interfaces/IFlxUIButton.hx +++ b/flixel/addons/ui/interfaces/IFlxUIButton.hx @@ -57,5 +57,9 @@ interface IFlxUIButton extends IFlxUIWidget extends IHasParams extends IFlxDestr public function loadGraphicsUpOverDown(asset:Dynamic, for_toggle:Bool = false, ?key:String):Void; public function forceStateHandler(event:String):Void; + #if (flixel >= version("5.7.0")) + public var status(default, set):FlxButtonState; + #else public var status(default, set):Int; + #end } diff --git a/haxelib.json b/haxelib.json index 6150e45..32f7b73 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,7 +4,7 @@ "license": "MIT", "tags": ["game", "openfl", "flash", "neko", "cpp", "android", "ios", "cross"], "description": "A UI library for Flixel", - "version": "2.6.0", - "releasenote": "Various FlxInputText improvements", + "version": "2.6.1", + "releasenote": "Flixel 5.7.0 compatibility", "contributors": ["haxeflixel", "larsiusprime", "Gama11", "GeoKureli"] }