@@ -18,21 +18,6 @@ import flixel.util.FlxDestroyUtil;
1818import flixel .input .touch .FlxTouch ;
1919#end
2020
21- enum abstract FlxButtonState (Int ) to Int
22- {
23- /** The button is not highlighted or pressed */
24- var NORMAL = 0 ;
25-
26- /** The button is selected, usually meaning the mouse is hovering over it */
27- var HIGHLIGHT = 1 ;
28-
29- /** The button is being pressed usually by a mouse */
30- var PRESSED = 2 ;
31-
32- /** The button is not interactible */
33- var DISABLED = 3 ;
34- }
35-
3621/**
3722 * A simple button class that calls a function when clicked by the mouse.
3823 */
@@ -41,30 +26,17 @@ class FlxButton extends FlxTypedButton<FlxText>
4126 /**
4227 * Used with public variable status, means not highlighted or pressed.
4328 */
44- @:dox (hide ) @:noCompletion
45- @:deprecated (" FlxButton.NORMAL is deprecated, use FlxButtonState.NORMAL" )
46- public static inline var NORMAL = FlxButtonState .NORMAL ;
29+ public static inline var NORMAL : Int = 0 ;
4730
4831 /**
4932 * Used with public variable status, means highlighted (usually from mouse over).
5033 */
51- @:dox (hide ) @:noCompletion
52- @:deprecated (" FlxButton.HIGHLIGHT is deprecated, use FlxButtonState.HIGHLIGHT" )
53- public static inline var HIGHLIGHT = FlxButtonState .HIGHLIGHT ;
34+ public static inline var HIGHLIGHT : Int = 1 ;
5435
5536 /**
5637 * Used with public variable status, means pressed (usually from mouse click).
5738 */
58- @:dox (hide ) @:noCompletion
59- @:deprecated (" FlxButton.PRESSED is deprecated, use FlxButtonState.PRESSED" )
60- public static inline var PRESSED = FlxButtonState .PRESSED ;
61-
62- /**
63- * Used with public variable status, means non interactible.
64- */
65- @:dox (hide ) @:noCompletion
66- @:deprecated (" FlxButton.DISABLED is deprecated, use FlxButtonState.DISABLED" )
67- public static inline var DISABLED = FlxButtonState .DISABLED ;
39+ public static inline var PRESSED : Int = 2 ;
6840
6941 /**
7042 * Shortcut to setting label.text
@@ -108,7 +80,7 @@ class FlxButton extends FlxTypedButton<FlxText>
10880 {
10981 if (Text != null )
11082 {
111- label = new FlxText (x + labelOffsets [FlxButtonState . NORMAL ].x , y + labelOffsets [FlxButtonState . NORMAL ].y , 80 , Text );
83+ label = new FlxText (x + labelOffsets [NORMAL ].x , y + labelOffsets [NORMAL ].y , 80 , Text );
11284 label .setFormat (null , 8 , 0x333333 , " center" );
11385 label .alpha = labelAlphas [status ];
11486 label .drawFrame (true );
@@ -150,19 +122,19 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
150122 /**
151123 * What offsets the `label` should have for each status.
152124 */
153- public var labelOffsets : Array <FlxPoint > = [FlxPoint .get (), FlxPoint .get (), FlxPoint .get (0 , 1 ), FlxPoint . get () ];
125+ public var labelOffsets : Array <FlxPoint > = [FlxPoint .get (), FlxPoint .get (), FlxPoint .get (0 , 1 )];
154126
155127 /**
156128 * What alpha value the label should have for each status. Default is `[0.8, 1.0, 0.5]`.
157129 * Multiplied with the button's `alpha`.
158130 */
159- public var labelAlphas : Array <Float > = [0.8 , 1.0 , 0.5 , 0.3 ];
131+ public var labelAlphas : Array <Float > = [0.8 , 1.0 , 0.5 ];
160132
161133 /**
162134 * What animation should be played for each status.
163135 * Default is ["normal", "highlight", "pressed"].
164136 */
165- public var statusAnimations : Array <String > = [" normal" , " highlight" , " pressed" , " disabled " ];
137+ public var statusAnimations : Array <String > = [" normal" , " highlight" , " pressed" ];
166138
167139 /**
168140 * Whether you can press the button simply by releasing the touch / mouse button over it (default).
@@ -185,10 +157,10 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
185157 public var maxInputMovement : Float = Math .POSITIVE_INFINITY ;
186158
187159 /**
188- * Shows the current state of the button, either `NORMAL`,
189- * `HIGHLIGHT` or `PRESSED`.
160+ * Shows the current state of the button, either `FlxButton. NORMAL`,
161+ * `FlxButton. HIGHLIGHT` or `FlxButton. PRESSED`.
190162 */
191- public var status (default , set ): FlxButtonState ;
163+ public var status (default , set ): Int ;
192164
193165 /**
194166 * The properties of this button's `onUp` event (callback function, sound).
@@ -250,7 +222,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
250222 onOver = new FlxButtonEvent ();
251223 onOut = new FlxButtonEvent ();
252224
253- status = NORMAL ;
225+ status = FlxButton . NORMAL ;
254226
255227 // Since this is a UI element, the default scrollFactor is (0, 0)
256228 scrollFactor .set ();
@@ -260,8 +232,8 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
260232 #end
261233
262234 #if FLX_NO_MOUSE // no need for highlight frame without mouse input
263- statusAnimations [HIGHLIGHT ] = " normal" ;
264- labelAlphas [HIGHLIGHT ] = 1 ;
235+ statusAnimations [FlxButton . HIGHLIGHT ] = " normal" ;
236+ labelAlphas [FlxButton . HIGHLIGHT ] = 1 ;
265237 #end
266238
267239 input = new FlxInput (0 );
@@ -271,10 +243,9 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
271243 {
272244 super .graphicLoaded ();
273245
274- setupAnimation (" normal" , NORMAL );
275- setupAnimation (" highlight" , HIGHLIGHT );
276- setupAnimation (" pressed" , PRESSED );
277- setupAnimation (" disabled" , DISABLED );
246+ setupAnimation (" normal" , FlxButton .NORMAL );
247+ setupAnimation (" highlight" , FlxButton .HIGHLIGHT );
248+ setupAnimation (" pressed" , FlxButton .PRESSED );
278249 }
279250
280251 function loadDefaultGraphic (): Void
@@ -413,9 +384,6 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
413384 */
414385 function updateButton (): Void
415386 {
416- // Prevent interactions with this input if it's currently disabled
417- if (status == DISABLED )
418- return ;
419387 // We're looking for any touch / mouse overlaps with this button
420388 var overlapFound = checkMouseOverlap ();
421389 if (! overlapFound )
@@ -426,7 +394,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
426394 onUpHandler ();
427395 }
428396
429- if (status != NORMAL && (! overlapFound || (currentInput != null && currentInput .justReleased )))
397+ if (status != FlxButton . NORMAL && (! overlapFound || (currentInput != null && currentInput .justReleased )))
430398 {
431399 onOutHandler ();
432400 }
@@ -496,7 +464,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
496464 currentInput = input ;
497465 onDownHandler ();
498466 }
499- else if (status == NORMAL )
467+ else if (status == FlxButton . NORMAL )
500468 {
501469 // Allow "swiping" to press a button (dragging it over the button while pressed)
502470 if (allowSwiping && input .pressed )
@@ -521,7 +489,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
521489
522490 function updateLabelAlpha ()
523491 {
524- if (_spriteLabel != null && labelAlphas .length > ( status : Int ) )
492+ if (_spriteLabel != null && labelAlphas .length > status )
525493 {
526494 _spriteLabel .alpha = alpha * labelAlphas [status ];
527495 }
@@ -534,7 +502,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
534502 #if FLX_MOUSE
535503 function onUpEventListener (_ ): Void
536504 {
537- if (visible && exists && active && status == PRESSED )
505+ if (visible && exists && active && status == FlxButton . PRESSED )
538506 {
539507 onUpHandler ();
540508 }
@@ -546,7 +514,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
546514 */
547515 function onUpHandler (): Void
548516 {
549- status = HIGHLIGHT ;
517+ status = FlxButton . HIGHLIGHT ;
550518 input .release ();
551519 currentInput = null ;
552520 // Order matters here, because onUp.fire() could cause a state change and destroy this object.
@@ -558,7 +526,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
558526 */
559527 function onDownHandler (): Void
560528 {
561- status = PRESSED ;
529+ status = FlxButton . PRESSED ;
562530 input .press ();
563531 // Order matters here, because onDown.fire() could cause a state change and destroy this object.
564532 onDown .fire ();
@@ -574,11 +542,11 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
574542 // by remaining in the normal state (until mouse input is re-enabled).
575543 if (! FlxG .mouse .enabled )
576544 {
577- status = NORMAL ;
545+ status = FlxButton . NORMAL ;
578546 return ;
579547 }
580548 #end
581- status = HIGHLIGHT ;
549+ status = FlxButton . HIGHLIGHT ;
582550 // Order matters here, because onOver.fire() could cause a state change and destroy this object.
583551 onOver .fire ();
584552 }
@@ -588,7 +556,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
588556 */
589557 function onOutHandler (): Void
590558 {
591- status = NORMAL ;
559+ status = FlxButton . NORMAL ;
592560 input .release ();
593561 // Order matters here, because onOut.fire() could cause a state change and destroy this object.
594562 onOut .fire ();
@@ -611,9 +579,9 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
611579 return Value ;
612580 }
613581
614- function set_status (value : FlxButtonState ) : FlxButtonState
582+ function set_status (Value : Int ) : Int
615583 {
616- status = value ;
584+ status = Value ;
617585 updateLabelAlpha ();
618586 return status ;
619587 }
0 commit comments