Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compatibility with new FlxButtonState enum #271

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
------------------------------

Expand Down
12 changes: 11 additions & 1 deletion flixel/addons/ui/FlxUIDropDownMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 19 additions & 9 deletions flixel/addons/ui/FlxUITypedButton.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<T:FlxSprite> extends FlxTypedButton<T> implements IFlxUIButton implements IResizable implements IFlxUIWidget implements IFlxUIClickable
implements IHasParams implements ICursorPointable
{
Expand Down Expand Up @@ -274,7 +284,7 @@ class FlxUITypedButton<T:FlxSprite> extends FlxTypedButton<T> 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
Expand Down Expand Up @@ -526,9 +536,9 @@ class FlxUITypedButton<T:FlxSprite> extends FlxTypedButton<T> 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)
Expand All @@ -540,9 +550,9 @@ class FlxUITypedButton<T:FlxSprite> extends FlxTypedButton<T> 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);
Expand Down Expand Up @@ -1018,12 +1028,12 @@ class FlxUITypedButton<T:FlxSprite> extends FlxTypedButton<T> 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"
Expand Down
4 changes: 4 additions & 0 deletions flixel/addons/ui/interfaces/IFlxUIButton.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
Loading