@@ -15,7 +15,6 @@ local eventNames={
15
15
16
16
local SCN = {
17
17
mainTouchID = nil , -- First touching ID(userdata)
18
- cur = ' NULL' , -- Current scene name
19
18
maxScroll = 0 ,
20
19
curScroll = 0 ,
21
20
@@ -53,7 +52,6 @@ function SCN.swapUpdate(dt)
53
52
S .time = S .time - dt
54
53
if S .time < S .changeTime and S .time + dt >= S .changeTime then
55
54
-- Scene swapped this frame
56
- SCN .prev = SCN .cur
57
55
SCN .load (S .tar )
58
56
SCN .mainTouchID = nil
59
57
end
65
63
function SCN .load (s )
66
64
love .keyboard .setTextInput (false )
67
65
68
- SCN .cur = s
69
-
70
66
local S = scenes [s ]
71
67
SCN .maxScroll = S .scrollHeight or 0
72
68
SCN .curScroll = 0
@@ -77,16 +73,11 @@ function SCN.load(s)
77
73
78
74
if S .enter then S .enter () end
79
75
end
80
- function SCN .push (tar ,style )
81
- if not SCN .swapping then
82
- local m =# SCN .stack
83
- SCN .stack [m + 1 ]= tar or SCN .cur
84
- SCN .stack [m + 2 ]= style or ' fade'
85
- end
76
+ function SCN .push (tar )
77
+ table.insert (SCN .stack ,tar or SCN .stack [# SCN .stack - 1 ])
86
78
end
87
79
function SCN .pop ()
88
80
table.remove (SCN .stack )
89
- table.remove (SCN .stack )
90
81
end
91
82
92
83
local swap = {
@@ -149,8 +140,10 @@ local swap={
149
140
}-- Scene swapping animations
150
141
function SCN .swapTo (tar ,style ,...)-- Parallel scene swapping, cannot back
151
142
if scenes [tar ] then
152
- if not SCN .swapping and tar ~= SCN . cur then
143
+ if not SCN .swapping then
153
144
style = style or ' fade'
145
+ SCN .prev = SCN .stack [# SCN .stack ]
146
+ SCN .stack [# SCN .stack ]= tar
154
147
SCN .swapping = true
155
148
SCN .args = {... }
156
149
local S = SCN .state
@@ -165,26 +158,45 @@ function SCN.swapTo(tar,style,...)-- Parallel scene swapping, cannot back
165
158
end
166
159
function SCN .go (tar ,style ,...)-- Normal scene swapping, can back
167
160
if scenes [tar ] then
168
- SCN .push ()
169
- SCN .swapTo (tar ,style ,... )
161
+ if not SCN .swapping then
162
+ SCN .push (SCN .stack [# SCN .stack ] or ' _' )
163
+ SCN .swapTo (tar ,style ,... )
164
+ end
170
165
else
171
166
MES .new (' warn' ," No Scene: " .. tar )
172
167
end
173
168
end
174
- function SCN .back (...)
169
+ function SCN .back (style , ...)
175
170
if SCN .swapping then return end
176
171
177
172
local m =# SCN .stack
178
- if m > 0 then
173
+ if m > 1 then
179
174
-- Leave scene
180
175
if SCN .leave then SCN .leave () end
181
176
182
177
-- Poll&Back to previous Scene
183
- SCN .swapTo (SCN .stack [m - 1 ],SCN .stack [m ],... )
184
- table.remove (SCN .stack )
185
- table.remove (SCN .stack )
178
+ SCN .pop ()
179
+ SCN .swapTo (SCN .stack [# SCN .stack ],style ,... )
186
180
else
187
181
Zenitha ._quit ()
188
182
end
189
183
end
184
+ function SCN .backTo (tar ,style ,...)
185
+ if SCN .swapping then return end
186
+
187
+ -- Leave scene
188
+ if SCN .sceneBack then
189
+ SCN .sceneBack ()
190
+ end
191
+
192
+ -- Poll&Back to previous Scene
193
+ while SCN .stack [# SCN .stack - 1 ]~= tar and # SCN .stack > 1 do
194
+ SCN .pop ()
195
+ end
196
+ SCN .swapTo (SCN .stack [# SCN .stack ],style ,... )
197
+ end
198
+ function SCN .printStack ()
199
+ for i = 1 ,# SCN .stack do print (SCN .stack [i ]) end
200
+ end
201
+
190
202
return SCN
0 commit comments