房间列表场景的rooms变量移入NET,改名roomList(用于全局读写)
This commit is contained in:
@@ -2,6 +2,7 @@ local data=love.data
|
||||
local NET={
|
||||
login=false,
|
||||
allow_online=false,
|
||||
roomList=false,
|
||||
}
|
||||
|
||||
--Account
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
local gc=love.graphics
|
||||
local min=math.min
|
||||
|
||||
local rooms
|
||||
local NET=NET
|
||||
local scrollPos,selected
|
||||
local lastfreshTime
|
||||
local lastCreateRoomTime=0
|
||||
|
||||
local function fresh()
|
||||
local function freshRoomList()
|
||||
NET.roomList=nil
|
||||
lastfreshTime=TIME()
|
||||
rooms=nil
|
||||
NET.freshRoom()
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ function scene.sceneInit()
|
||||
BG.set("bg1")
|
||||
scrollPos=0
|
||||
selected=1
|
||||
fresh()
|
||||
freshRoomList()
|
||||
end
|
||||
|
||||
function scene.wheelMoved(_,y)
|
||||
@@ -27,7 +27,7 @@ end
|
||||
function scene.keyDown(k)
|
||||
if k=="r"then
|
||||
if TIME()-lastfreshTime>1 then
|
||||
fresh()
|
||||
freshRoomList()
|
||||
end
|
||||
elseif k=="n"then
|
||||
if TIME()-lastCreateRoomTime>26 then
|
||||
@@ -38,9 +38,9 @@ function scene.keyDown(k)
|
||||
end
|
||||
elseif k=="escape"then
|
||||
SCN.back()
|
||||
elseif rooms and #rooms>0 then
|
||||
elseif NET.roomList and #NET.roomList>0 then
|
||||
if k=="down"then
|
||||
if selected<#rooms then
|
||||
if selected<#NET.roomList then
|
||||
selected=selected+1
|
||||
if selected>scrollPos+10 then
|
||||
scrollPos=scrollPos+1
|
||||
@@ -54,34 +54,34 @@ function scene.keyDown(k)
|
||||
end
|
||||
end
|
||||
elseif k=="return"then
|
||||
if rooms[selected].private then
|
||||
if NET.roomList[selected].private then
|
||||
LOG.print("Can't enter private room now")
|
||||
return
|
||||
end
|
||||
NET.enterRoom(rooms[selected].id)--,password
|
||||
NET.enterRoom(NET.roomList[selected].id)--,password
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function scene.update()
|
||||
if TIME()-lastfreshTime>5 then
|
||||
fresh()
|
||||
freshRoomList()
|
||||
end
|
||||
end
|
||||
|
||||
function scene.draw()
|
||||
gc.setColor(1,1,1,.26)
|
||||
gc.arc("fill","pie",240,620,60,-1.5708,-1.5708+1.2566*(TIME()-lastfreshTime))
|
||||
if rooms then
|
||||
if NET.roomList then
|
||||
gc.setColor(1,1,1)
|
||||
if #rooms>0 then
|
||||
if #NET.roomList>0 then
|
||||
gc.setLineWidth(2)
|
||||
gc.rectangle("line",55,110,1100,400)
|
||||
gc.setColor(1,1,1,.3)
|
||||
gc.rectangle("fill",55,40*(1+selected-scrollPos)+30,1100,40)
|
||||
setFont(35)
|
||||
for i=1,min(10,#rooms-scrollPos)do
|
||||
local R=rooms[scrollPos+i]
|
||||
for i=1,min(10,#NET.roomList-scrollPos)do
|
||||
local R=NET.roomList[scrollPos+i]
|
||||
if R.private then
|
||||
gc.setColor(1,1,1)
|
||||
gc.draw(IMG.lock,64,75+40*i)
|
||||
@@ -102,11 +102,11 @@ function scene.draw()
|
||||
end
|
||||
|
||||
scene.widgetList={
|
||||
WIDGET.newKey{name="fresh", x=240,y=620,w=140,h=140,font=40,code=fresh,hide=function()return TIME()-lastfreshTime<1.26 end},
|
||||
WIDGET.newKey{name="fresh", x=240,y=620,w=140,h=140,font=40,code=freshRoomList,hide=function()return TIME()-lastfreshTime<1.26 end},
|
||||
WIDGET.newKey{name="new", x=440,y=620,w=140,h=140,font=25,code=pressKey"n"},
|
||||
WIDGET.newKey{name="join", x=640,y=620,w=140,h=140,font=40,code=pressKey"return",hide=function()return not rooms end},
|
||||
WIDGET.newKey{name="up", x=840,y=585,w=140,h=70,font=40,code=pressKey"up",hide=function()return not rooms end},
|
||||
WIDGET.newKey{name="down", x=840,y=655,w=140,h=70,font=40,code=pressKey"down",hide=function()return not rooms end},
|
||||
WIDGET.newKey{name="join", x=640,y=620,w=140,h=140,font=40,code=pressKey"return",hide=function()return not NET.roomList end},
|
||||
WIDGET.newKey{name="up", x=840,y=585,w=140,h=70,font=40,code=pressKey"up",hide=function()return not NET.roomList end},
|
||||
WIDGET.newKey{name="down", x=840,y=655,w=140,h=70,font=40,code=pressKey"down",hide=function()return not NET.roomList end},
|
||||
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=40,code=backScene},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user