This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
flxstate.monkey
221 lines (156 loc) · 3.58 KB
/
flxstate.monkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
Strict
Import flxgroup
Class FlxState Extends FlxGroup Abstract
Const ORDER_ASC:Int = 0
Const ORDER_DESC:Int = 1
Field persistentUpdate:Bool = False
Field persistentDraw:Bool = True
Field drawOrder:Int
Field updateOrder:Int
Method Create:Void() Abstract
Method OnActivate:Void(prevSubstate:FlxSubState)
End Method
Method Destroy:Void()
Super.Destroy()
If (_subState <> Null And _subState._initialized) Then
_subState.Destroy()
End If
End Method
Method OnBack:Bool()
Return True
End Method
Method OnClose:Bool()
Return True
End Method
Method SetSubState:Void(subState:FlxSubState)
If (_subState = subState) Return
If (_subState <> Null) Then
If ( Not _subState.OnClose(_subState._closedBySystem)) Then
_subState.PreventDefault()
_subState.StopPropagation()
Return
End If
_subState._parent = Null
End If
If (subState <> Null) Then
_subState = subState
_subState._parent = Self
If ( Not _subState._initialized) Then
_subState.Create()
_subState._initialized = True
End If
_subState.OnActivate()
Else
subState = _subState
_subState = Null
OnActivate(subState)
End If
End Method
Method GetSubState:FlxSubState()
Return _subState
End Method
Method CloseSubState:Void()
If (_subState = Null) Return
SetSubState(Null)
End Method
Method DoUpdate:Void()
If (_subState = Null) Then
Update()
Return
End If
If (updateOrder = ORDER_DESC) Then
_subState.Update()
End If
If (persistentUpdate) Then
Update()
End If
If (updateOrder = ORDER_ASC) Then
_subState.Update()
End If
End Method
Method DoDraw:Void()
If (_subState = Null) Then
Draw()
Return
End If
If (drawOrder = ORDER_DESC) Then
_subState.Draw()
End If
If (persistentDraw) Then
Draw()
End If
If (drawOrder = ORDER_ASC) Then
_subState.Draw()
End If
End Method
Method DoBack:Bool()
If (_subState = Null) Then
Return OnBack()
End If
_subState._closedBySystem = True
_subState.Close()
If ( Not _subState._stopPropagation) Then
If ( Not _subState._preventDefault) Then
Return OnBack()
End If
OnBack()
End If
Return Not _subState._preventDefault
End Method
Method DoClose:Bool()
If (_subState = Null) Then
Return OnClose()
End If
Local subState:FlxSubState = _subState
subState._closedBySystem = True
subState.Close()
If ( Not subState._stopPropagation) Then
If ( Not subState._preventDefault) Then
Return OnClose()
End If
OnClose()
End If
Return Not subState._preventDefault
End Method
Private
Field _subState:FlxSubState
End Class
Class FlxSubState Extends FlxGroup Abstract
Method Create:Void() Abstract
Method Destroy:Void()
Super.Destroy()
_parent = Null
_initialized = False
End Method
Method Close:Void()
If (_parent = Null) Return
_preventDefault = False
_stopPropagation = False
_parent.CloseSubState()
_closedBySystem = False
End Method
Method GetParent:FlxState()
Return _parent
End Method
Method OnActivate:Void()
End Method
Method OnClose:Bool(system:Bool)
Destroy()
Return True
End Method
Method StopPropagation:Void()
_stopPropagation = True
End Method
Method PreventDefault:Void()
_preventDefault = True
End Method
Private
Field _parent:FlxState
Field _initialized:Bool
Field _preventDefault:Bool
Field _stopPropagation:Bool
Field _closedBySystem:Bool
End Class
Interface FlxSwitchStateListener
Method OnSwitchState:Void(oldState:FlxState, newState:FlxState)
End Interface