修改刷新房间相关代码
This commit is contained in:
@@ -252,7 +252,7 @@ return{
|
|||||||
chat="Chat",
|
chat="Chat",
|
||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
fresh="Reresh",
|
refresh="Refresh",
|
||||||
new="New Room",
|
new="New Room",
|
||||||
join="Join",
|
join="Join",
|
||||||
up="↑",
|
up="↑",
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ return{
|
|||||||
chat="Chat",
|
chat="Chat",
|
||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
fresh="Fresh",
|
-- refresh="Refresh",
|
||||||
new="Nouveau salon",
|
new="Nouveau salon",
|
||||||
join="Rejoindre",
|
join="Rejoindre",
|
||||||
up="↑",
|
up="↑",
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ return{
|
|||||||
chat="Chat",
|
chat="Chat",
|
||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
fresh="Fresh",
|
-- refresh="Refresh",
|
||||||
-- new="New room",
|
-- new="New room",
|
||||||
-- join="Join",
|
-- join="Join",
|
||||||
up="↑",
|
up="↑",
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ return{
|
|||||||
-- chat="Chat",
|
-- chat="Chat",
|
||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
-- fresh="Fresh",
|
-- refresh="Refresh",
|
||||||
-- new="New room",
|
-- new="New room",
|
||||||
-- join="Join",
|
-- join="Join",
|
||||||
up="↑",
|
up="↑",
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ return{
|
|||||||
chat="聊天室",
|
chat="聊天室",
|
||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
fresh="刷新",
|
refresh="刷新",
|
||||||
new="创建房间",
|
new="创建房间",
|
||||||
join="加入",
|
join="加入",
|
||||||
up="↑",
|
up="↑",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local data=love.data
|
|||||||
local NET={
|
local NET={
|
||||||
login=false,
|
login=false,
|
||||||
allow_online=false,
|
allow_online=false,
|
||||||
roomList=false,
|
roomList={},
|
||||||
accessToken=false,
|
accessToken=false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +26,9 @@ end
|
|||||||
local function _unlock(name)
|
local function _unlock(name)
|
||||||
locks[name]=false
|
locks[name]=false
|
||||||
end
|
end
|
||||||
|
function NET.getLock(name)
|
||||||
|
return locks[name]
|
||||||
|
end
|
||||||
|
|
||||||
--Parse json message
|
--Parse json message
|
||||||
local function _parse(res)
|
local function _parse(res)
|
||||||
@@ -119,15 +122,17 @@ function NET.signal_quit()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Room
|
--Room
|
||||||
function NET.freshRoom()
|
function NET.fetchRoom()
|
||||||
WS.send("play",JSON.encode{
|
if _lock("fetchRoom")then
|
||||||
action=0,
|
WS.send("play",JSON.encode{
|
||||||
data={
|
action=0,
|
||||||
type=nil,
|
data={
|
||||||
begin=0,
|
type=nil,
|
||||||
count=10,
|
begin=0,
|
||||||
}
|
count=10,
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
function NET.createRoom()
|
function NET.createRoom()
|
||||||
if _lock("enterRoom")then
|
if _lock("enterRoom")then
|
||||||
@@ -266,6 +271,7 @@ function NET.TICK_WS_play()
|
|||||||
SCN.go("net_menu")
|
SCN.go("net_menu")
|
||||||
elseif res.action==0 then--Fetch rooms
|
elseif res.action==0 then--Fetch rooms
|
||||||
NET.roomList=res.roomList
|
NET.roomList=res.roomList
|
||||||
|
_unlock("fetchRoom")
|
||||||
elseif res.action==2 then--Join(create) room
|
elseif res.action==2 then--Join(create) room
|
||||||
-- loadGame("netBattle",true,true)
|
-- loadGame("netBattle",true,true)
|
||||||
_unlock("enterRoom")
|
_unlock("enterRoom")
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ local min=math.min
|
|||||||
|
|
||||||
local NET=NET
|
local NET=NET
|
||||||
local scrollPos,selected
|
local scrollPos,selected
|
||||||
local lastfreshTime
|
local lastFetchTime
|
||||||
local lastCreateRoomTime=0
|
local lastCreateRoomTime=0
|
||||||
|
|
||||||
local function freshRoomList()
|
local function fetchRoom()
|
||||||
NET.roomList=nil
|
lastFetchTime=TIME()
|
||||||
lastfreshTime=TIME()
|
NET.fetchRoom()
|
||||||
NET.freshRoom()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local scene={}
|
local scene={}
|
||||||
@@ -18,7 +17,7 @@ function scene.sceneInit()
|
|||||||
BG.set("bg1")
|
BG.set("bg1")
|
||||||
scrollPos=0
|
scrollPos=0
|
||||||
selected=1
|
selected=1
|
||||||
freshRoomList()
|
fetchRoom()
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.wheelMoved(_,y)
|
function scene.wheelMoved(_,y)
|
||||||
@@ -26,8 +25,8 @@ function scene.wheelMoved(_,y)
|
|||||||
end
|
end
|
||||||
function scene.keyDown(k)
|
function scene.keyDown(k)
|
||||||
if k=="r"then
|
if k=="r"then
|
||||||
if TIME()-lastfreshTime>1 then
|
if TIME()-lastFetchTime>1 then
|
||||||
freshRoomList()
|
fetchRoom()
|
||||||
end
|
end
|
||||||
elseif k=="n"then
|
elseif k=="n"then
|
||||||
if TIME()-lastCreateRoomTime>26 then
|
if TIME()-lastCreateRoomTime>26 then
|
||||||
@@ -38,7 +37,7 @@ function scene.keyDown(k)
|
|||||||
end
|
end
|
||||||
elseif k=="escape"then
|
elseif k=="escape"then
|
||||||
SCN.back()
|
SCN.back()
|
||||||
elseif NET.roomList and #NET.roomList>0 then
|
elseif #NET.roomList>0 then
|
||||||
if k=="down"then
|
if k=="down"then
|
||||||
if selected<#NET.roomList then
|
if selected<#NET.roomList then
|
||||||
selected=selected+1
|
selected=selected+1
|
||||||
@@ -54,6 +53,7 @@ function scene.keyDown(k)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif k=="return"then
|
elseif k=="return"then
|
||||||
|
if NET.getLock("fetchRoom")then return end
|
||||||
if NET.roomList[selected].private then
|
if NET.roomList[selected].private then
|
||||||
LOG.print("Can't enter private room now")
|
LOG.print("Can't enter private room now")
|
||||||
return
|
return
|
||||||
@@ -64,49 +64,51 @@ function scene.keyDown(k)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function scene.update()
|
function scene.update()
|
||||||
if TIME()-lastfreshTime>5 then
|
if TIME()-lastFetchTime>5 then
|
||||||
freshRoomList()
|
fetchRoom()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.draw()
|
function scene.draw()
|
||||||
|
--Fetching timer
|
||||||
gc.setColor(1,1,1,.26)
|
gc.setColor(1,1,1,.26)
|
||||||
gc.arc("fill","pie",240,620,60,-1.5708,-1.5708+1.2566*(TIME()-lastfreshTime))
|
gc.arc("fill","pie",240,620,60,-1.5708,-1.5708+1.2566*(TIME()-lastFetchTime))
|
||||||
if NET.roomList then
|
|
||||||
gc.setColor(1,1,1)
|
--Room list
|
||||||
if #NET.roomList>0 then
|
gc.setColor(1,1,1)
|
||||||
gc.setLineWidth(2)
|
gc.setLineWidth(2)
|
||||||
gc.rectangle("line",55,110,1100,400)
|
gc.rectangle("line",55,110,1100,400)
|
||||||
gc.setColor(1,1,1,.3)
|
gc.setColor(1,1,1,.3)
|
||||||
gc.rectangle("fill",55,40*(1+selected-scrollPos)+30,1100,40)
|
gc.rectangle("fill",55,40*(1+selected-scrollPos)+30,1100,40)
|
||||||
setFont(35)
|
setFont(35)
|
||||||
for i=1,min(10,#NET.roomList-scrollPos)do
|
for i=1,min(10,#NET.roomList-scrollPos)do
|
||||||
local R=NET.roomList[scrollPos+i]
|
local R=NET.roomList[scrollPos+i]
|
||||||
if R.private then
|
if R.private then
|
||||||
gc.setColor(1,1,1)
|
gc.setColor(1,1,1)
|
||||||
gc.draw(IMG.lock,64,75+40*i)
|
gc.draw(IMG.lock,64,75+40*i)
|
||||||
end
|
|
||||||
gc.setColor(.9,.9,1)
|
|
||||||
gc.print(scrollPos+i,100,66+40*i)
|
|
||||||
gc.setColor(1,1,.7)
|
|
||||||
gc.print(R.name,200,66+40*i)
|
|
||||||
gc.setColor(1,1,1)
|
|
||||||
gc.printf(R.type,500,66+40*i,500,"right")
|
|
||||||
gc.print(R.count.."/"..R.capacity,1050,66+40*i)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
setFont(60)
|
|
||||||
mStr(text.noRooms,640,315)
|
|
||||||
end
|
end
|
||||||
|
gc.setColor(.9,.9,1)
|
||||||
|
gc.print(scrollPos+i,100,66+40*i)
|
||||||
|
gc.setColor(1,1,.7)
|
||||||
|
gc.print(R.name,200,66+40*i)
|
||||||
|
gc.setColor(1,1,1)
|
||||||
|
gc.printf(R.type,500,66+40*i,500,"right")
|
||||||
|
gc.print(R.count.."/"..R.capacity,1050,66+40*i)
|
||||||
|
end
|
||||||
|
|
||||||
|
--No room message
|
||||||
|
if #NET.roomList==0 then
|
||||||
|
setFont(60)
|
||||||
|
mStr(text.noRooms,640,315)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
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="refresh", x=240,y=620,w=140,h=140,font=40,code=fetchRoom, hide=function()return TIME()-lastFetchTime<1.26 end},
|
||||||
WIDGET.newKey{name="new", x=440,y=620,w=140,h=140,font=25,code=pressKey"n"},
|
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 NET.roomList end},
|
WIDGET.newKey{name="join", x=640,y=620,w=140,h=140,font=40,code=pressKey"return", hide=function()return #NET.roomList==0 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="up", x=840,y=585,w=140,h=70,font=40,code=pressKey"up", hide=function()return #NET.roomList==0 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.newKey{name="down", x=840,y=655,w=140,h=70,font=40,code=pressKey"down", hide=function()return #NET.roomList==0 end},
|
||||||
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=40,code=backScene},
|
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=40,code=backScene},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user