@@ -15,7 +15,6 @@ local eventNames={
1515
1616local SCN = {
1717 mainTouchID = nil , -- First touching ID(userdata)
18- cur = ' NULL' , -- Current scene name
1918 maxScroll = 0 ,
2019 curScroll = 0 ,
2120
@@ -53,7 +52,6 @@ function SCN.swapUpdate(dt)
5352 S .time = S .time - dt
5453 if S .time < S .changeTime and S .time + dt >= S .changeTime then
5554 -- Scene swapped this frame
56- SCN .prev = SCN .cur
5755 SCN .load (S .tar )
5856 SCN .mainTouchID = nil
5957 end
6563function SCN .load (s )
6664 love .keyboard .setTextInput (false )
6765
68- SCN .cur = s
69-
7066 local S = scenes [s ]
7167 SCN .maxScroll = S .scrollHeight or 0
7268 SCN .curScroll = 0
@@ -78,15 +74,14 @@ function SCN.load(s)
7874 if S .enter then S .enter () end
7975end
8076function 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
77+ table.insert (SCN .stack ,tar or SCN .stack [# SCN .stack - 1 ])
78+ table.insert (SCN .stack ,style or ' fade' )
79+ -- print("-------") for i=1,#SCN.stack,2 do print(SCN.stack[i]) end
8680end
8781function SCN .pop ()
8882 table.remove (SCN .stack )
8983 table.remove (SCN .stack )
84+ -- print("-------") for i=1,#SCN.stack,2 do print(SCN.stack[i]) end
9085end
9186
9287local swap = {
@@ -149,8 +144,10 @@ local swap={
149144}-- Scene swapping animations
150145function SCN .swapTo (tar ,style ,...)-- Parallel scene swapping, cannot back
151146 if scenes [tar ] then
152- if not SCN .swapping and tar ~= SCN .cur then
147+ if not SCN .swapping and tar ~= SCN .stack [ # SCN . stack - 3 ] then
153148 style = style or ' fade'
149+ SCN .prev = SCN .stack [# SCN .stack - 1 ]
150+ SCN .stack [# SCN .stack - 1 ],SCN .stack [# SCN .stack ]= tar ,style
154151 SCN .swapping = true
155152 SCN .args = {... }
156153 local S = SCN .state
@@ -165,8 +162,12 @@ function SCN.swapTo(tar,style,...)-- Parallel scene swapping, cannot back
165162end
166163function SCN .go (tar ,style ,...)-- Normal scene swapping, can back
167164 if scenes [tar ] then
168- SCN .push ()
169- SCN .swapTo (tar ,style ,... )
165+ if not SCN .swapping and tar ~= SCN .stack [# SCN .stack - 3 ] then
166+ local prev = SCN .stack [# SCN .stack - 1 ]
167+ SCN .push (tar ,style )
168+ SCN .swapTo (tar ,style ,... )
169+ SCN .prev = prev
170+ end
170171 else
171172 MES .new (' warn' ," No Scene: " .. tar )
172173 end
@@ -175,16 +176,32 @@ function SCN.back(...)
175176 if SCN .swapping then return end
176177
177178 local m =# SCN .stack
178- if m > 0 then
179+ if m > 2 then
179180 -- Leave scene
180181 if SCN .leave then SCN .leave () end
181182
182183 -- 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 )
184+ if # SCN .stack > 2 then
185+ SCN .pop ()
186+ SCN .swapTo (SCN .stack [# SCN .stack - 1 ],SCN .stack [# SCN .stack ],... )
187+ end
186188 else
187189 Zenitha ._quit ()
188190 end
189191end
192+ function SCN .backTo (name ,...)
193+ if SCN .swapping then return end
194+
195+ -- Leave scene
196+ if SCN .sceneBack then
197+ SCN .sceneBack ()
198+ end
199+
200+ -- Poll&Back to previous Scene
201+ while SCN .stack [# SCN .stack - 1 ]~= name and # SCN .stack > 2 do
202+ SCN .pop ()
203+ end
204+ SCN .swapTo (SCN .stack [# SCN .stack - 1 ],SCN .stack [# SCN .stack ],... )
205+ end
206+
190207return SCN
0 commit comments