@@ -18,21 +18,6 @@ import flixel.util.FlxDestroyUtil;
18
18
import flixel .input .touch .FlxTouch ;
19
19
#end
20
20
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
-
36
21
/**
37
22
* A simple button class that calls a function when clicked by the mouse.
38
23
*/
@@ -41,30 +26,17 @@ class FlxButton extends FlxTypedButton<FlxText>
41
26
/**
42
27
* Used with public variable status, means not highlighted or pressed.
43
28
*/
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 ;
47
30
48
31
/**
49
32
* Used with public variable status, means highlighted (usually from mouse over).
50
33
*/
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 ;
54
35
55
36
/**
56
37
* Used with public variable status, means pressed (usually from mouse click).
57
38
*/
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 ;
68
40
69
41
/**
70
42
* Shortcut to setting label.text
@@ -108,7 +80,7 @@ class FlxButton extends FlxTypedButton<FlxText>
108
80
{
109
81
if (Text != null )
110
82
{
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 );
112
84
label .setFormat (null , 8 , 0x333333 , " center" );
113
85
label .alpha = labelAlphas [status ];
114
86
label .drawFrame (true );
@@ -150,19 +122,19 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
150
122
/**
151
123
* What offsets the `label` should have for each status.
152
124
*/
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 )];
154
126
155
127
/**
156
128
* What alpha value the label should have for each status. Default is `[0.8, 1.0, 0.5]`.
157
129
* Multiplied with the button's `alpha`.
158
130
*/
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 ];
160
132
161
133
/**
162
134
* What animation should be played for each status.
163
135
* Default is ["normal", "highlight", "pressed"].
164
136
*/
165
- public var statusAnimations : Array <String > = [" normal" , " highlight" , " pressed" , " disabled " ];
137
+ public var statusAnimations : Array <String > = [" normal" , " highlight" , " pressed" ];
166
138
167
139
/**
168
140
* 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
185
157
public var maxInputMovement : Float = Math .POSITIVE_INFINITY ;
186
158
187
159
/**
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`.
190
162
*/
191
- public var status (default , set ): FlxButtonState ;
163
+ public var status (default , set ): Int ;
192
164
193
165
/**
194
166
* The properties of this button's `onUp` event (callback function, sound).
@@ -250,7 +222,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
250
222
onOver = new FlxButtonEvent ();
251
223
onOut = new FlxButtonEvent ();
252
224
253
- status = NORMAL ;
225
+ status = FlxButton . NORMAL ;
254
226
255
227
// Since this is a UI element, the default scrollFactor is (0, 0)
256
228
scrollFactor .set ();
@@ -260,8 +232,8 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
260
232
#end
261
233
262
234
#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 ;
265
237
#end
266
238
267
239
input = new FlxInput (0 );
@@ -271,10 +243,9 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
271
243
{
272
244
super .graphicLoaded ();
273
245
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 );
278
249
}
279
250
280
251
function loadDefaultGraphic (): Void
@@ -413,9 +384,6 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
413
384
*/
414
385
function updateButton (): Void
415
386
{
416
- // Prevent interactions with this input if it's currently disabled
417
- if (status == DISABLED )
418
- return ;
419
387
// We're looking for any touch / mouse overlaps with this button
420
388
var overlapFound = checkMouseOverlap ();
421
389
if (! overlapFound )
@@ -426,7 +394,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
426
394
onUpHandler ();
427
395
}
428
396
429
- if (status != NORMAL && (! overlapFound || (currentInput != null && currentInput .justReleased )))
397
+ if (status != FlxButton . NORMAL && (! overlapFound || (currentInput != null && currentInput .justReleased )))
430
398
{
431
399
onOutHandler ();
432
400
}
@@ -496,7 +464,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
496
464
currentInput = input ;
497
465
onDownHandler ();
498
466
}
499
- else if (status == NORMAL )
467
+ else if (status == FlxButton . NORMAL )
500
468
{
501
469
// Allow "swiping" to press a button (dragging it over the button while pressed)
502
470
if (allowSwiping && input .pressed )
@@ -521,7 +489,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
521
489
522
490
function updateLabelAlpha ()
523
491
{
524
- if (_spriteLabel != null && labelAlphas .length > ( status : Int ) )
492
+ if (_spriteLabel != null && labelAlphas .length > status )
525
493
{
526
494
_spriteLabel .alpha = alpha * labelAlphas [status ];
527
495
}
@@ -534,7 +502,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
534
502
#if FLX_MOUSE
535
503
function onUpEventListener (_ ): Void
536
504
{
537
- if (visible && exists && active && status == PRESSED )
505
+ if (visible && exists && active && status == FlxButton . PRESSED )
538
506
{
539
507
onUpHandler ();
540
508
}
@@ -546,7 +514,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
546
514
*/
547
515
function onUpHandler (): Void
548
516
{
549
- status = HIGHLIGHT ;
517
+ status = FlxButton . HIGHLIGHT ;
550
518
input .release ();
551
519
currentInput = null ;
552
520
// 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
558
526
*/
559
527
function onDownHandler (): Void
560
528
{
561
- status = PRESSED ;
529
+ status = FlxButton . PRESSED ;
562
530
input .press ();
563
531
// Order matters here, because onDown.fire() could cause a state change and destroy this object.
564
532
onDown .fire ();
@@ -574,11 +542,11 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
574
542
// by remaining in the normal state (until mouse input is re-enabled).
575
543
if (! FlxG .mouse .enabled )
576
544
{
577
- status = NORMAL ;
545
+ status = FlxButton . NORMAL ;
578
546
return ;
579
547
}
580
548
#end
581
- status = HIGHLIGHT ;
549
+ status = FlxButton . HIGHLIGHT ;
582
550
// Order matters here, because onOver.fire() could cause a state change and destroy this object.
583
551
onOver .fire ();
584
552
}
@@ -588,7 +556,7 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
588
556
*/
589
557
function onOutHandler (): Void
590
558
{
591
- status = NORMAL ;
559
+ status = FlxButton . NORMAL ;
592
560
input .release ();
593
561
// Order matters here, because onOut.fire() could cause a state change and destroy this object.
594
562
onOut .fire ();
@@ -611,9 +579,9 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
611
579
return Value ;
612
580
}
613
581
614
- function set_status (value : FlxButtonState ) : FlxButtonState
582
+ function set_status (Value : Int ) : Int
615
583
{
616
- status = value ;
584
+ status = Value ;
617
585
updateLabelAlpha ();
618
586
return status ;
619
587
}
0 commit comments