Skip to content

Commit 2537c71

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

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
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: 31 additions & 19 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
@@ -77,16 +73,11 @@ function SCN.load(s)
7773

7874
if S.enter then S.enter() end
7975
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])
8678
end
8779
function SCN.pop()
8880
table.remove(SCN.stack)
89-
table.remove(SCN.stack)
9081
end
9182

9283
local swap={
@@ -149,8 +140,10 @@ local swap={
149140
}-- Scene swapping animations
150141
function SCN.swapTo(tar,style,...)-- Parallel scene swapping, cannot back
151142
if scenes[tar] then
152-
if not SCN.swapping and tar~=SCN.cur then
143+
if not SCN.swapping then
153144
style=style or 'fade'
145+
SCN.prev=SCN.stack[#SCN.stack]
146+
SCN.stack[#SCN.stack]=tar
154147
SCN.swapping=true
155148
SCN.args={...}
156149
local S=SCN.state
@@ -165,26 +158,45 @@ function SCN.swapTo(tar,style,...)-- Parallel scene swapping, cannot back
165158
end
166159
function SCN.go(tar,style,...)-- Normal scene swapping, can back
167160
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
170165
else
171166
MES.new('warn',"No Scene: "..tar)
172167
end
173168
end
174-
function SCN.back(...)
169+
function SCN.back(style,...)
175170
if SCN.swapping then return end
176171

177172
local m=#SCN.stack
178-
if m>0 then
173+
if m>1 then
179174
-- Leave scene
180175
if SCN.leave then SCN.leave() end
181176

182177
-- 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,...)
186180
else
187181
Zenitha._quit()
188182
end
189183
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+
190202
return SCN

0 commit comments

Comments
 (0)