Skip to content

Commit ea9b737

Browse files
committed
场景模块更新
1 parent 0afa62e commit ea9b737

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

init.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ function love.errorhandler(msg)
587587

588588
if mainLoopStarted and #errData<3 and SCN.scenes['error'] then
589589
BG.set('none')
590-
local scn=SCN and SCN.cur or 'NULL'
590+
local scn=SCN and SCN.stack[#SCN.stack-1] or "NULL"
591591
table.insert(errData,{mes=err,scene=scn})
592592

593593
-- Write messages to log file
@@ -637,7 +637,7 @@ function love.errorhandler(msg)
637637
setFont(40,'_basic') gc.printf(errorMsg,100,160,SCR.w/k-200)
638638
setFont(25,'_basic') gc.printf(err[1],100,380,SCR.w/k-200)
639639
setFont(20,'_basic')
640-
GC.print(love.system.getOS().."-"..versionText.." scene:"..(SCN and SCN.cur or "NULL"),100,640)
640+
GC.print(love.system.getOS().."-"..versionText.." scene:"..(SCN and SCN.stack[#SCN.stack-1] or "NULL"),100,640)
641641
GC.print("TRACEBACK",100,430)
642642
for i=4,#err-2 do
643643
gc_print(err[i],100,380+20*i)
@@ -695,9 +695,9 @@ function love.run()
695695

696696
love.resize(gc.getWidth(),gc.getHeight())
697697
if #errData>0 then
698-
SCN.load('error')
698+
SCN.load('error','none')
699699
elseif SCN.scenes[firstScene] then
700-
SCN.load(firstScene)
700+
SCN.go(firstScene,'none')
701701
SCN.scenes._zenitha=nil
702702
else
703703
if firstScene then

scene.lua

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ local eventNames={
1515

1616
local 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
@@ -65,8 +63,6 @@ end
6563
function 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
7975
end
8076
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
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
8680
end
8781
function 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
9085
end
9186

9287
local swap={
@@ -149,8 +144,10 @@ local swap={
149144
}-- Scene swapping animations
150145
function 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
165162
end
166163
function 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
189191
end
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+
190207
return SCN

0 commit comments

Comments
 (0)