房间选择界面初版

This commit is contained in:
MrZ626
2021-01-01 04:11:44 +08:00
parent 0ae960834d
commit 40d88a1838
5 changed files with 111 additions and 19 deletions

View File

@@ -90,6 +90,7 @@ return{
wsFailed="WebSocket: connection failed", wsFailed="WebSocket: connection failed",
wsDisconnected="WebSocket: disconnected", wsDisconnected="WebSocket: disconnected",
wsNoConn="WebSocket: you are not connected", wsNoConn="WebSocket: you are not connected",
waitNetTask="Connecting, please wait",
chatJoin="joined the room.", chatJoin="joined the room.",
chatLeave="left the room.", chatLeave="left the room.",
@@ -98,6 +99,7 @@ return{
chatHistory="------New messages below------", chatHistory="------New messages below------",
chatQuit="Press again to exit", chatQuit="Press again to exit",
noRooms="No Rooms Now",
roomsFetchFailed="Failed to fetch rooms", roomsFetchFailed="Failed to fetch rooms",
errorMsg="An error has occurred and Techmino needs to restart.\nError info has been created, and you can send it to the author.", errorMsg="An error has occurred and Techmino needs to restart.\nError info has been created, and you can send it to the author.",
@@ -248,6 +250,11 @@ return{
rooms="Rooms", rooms="Rooms",
chat="Chat", chat="Chat",
}, },
net_rooms={
fresh="Fresh",
up="",
down="",
},
net_chat={ net_chat={
clear="Clear", clear="Clear",
send="Send", send="Send",

View File

@@ -93,6 +93,7 @@ return{
-- wsFailed="WebSocket: connection failed", -- wsFailed="WebSocket: connection failed",
-- wsDisconnected="WebSocket: disconnected", -- wsDisconnected="WebSocket: disconnected",
-- wsNoConn="WebSocket: you are not connected", -- wsNoConn="WebSocket: you are not connected",
-- waitNetTask="Connecting, please wait",
-- chatJoin="joined the room.", -- chatJoin="joined the room.",
-- chatLeave="left the room.", -- chatLeave="left the room.",
@@ -101,6 +102,7 @@ return{
-- chatHistory="------New messages below------", -- chatHistory="------New messages below------",
-- chatQuit="Press again to exit", -- chatQuit="Press again to exit",
-- noRooms="No Rooms Now",
-- roomsFetchFailed="Failed to fetch rooms", -- roomsFetchFailed="Failed to fetch rooms",
errorMsg="Une erreur est survenue et Techmino doit redémarrer.\nDes informations concernant l'erreur ont été créées, et vous pouvez les envoyer au créateur.", errorMsg="Une erreur est survenue et Techmino doit redémarrer.\nDes informations concernant l'erreur ont été créées, et vous pouvez les envoyer au créateur.",
@@ -227,6 +229,11 @@ return{
-- rooms="Rooms", -- rooms="Rooms",
-- chat="Chat", -- chat="Chat",
}, },
net_rooms={
-- fresh="Fresh",
up="",
down="",
},
net_chat={ net_chat={
-- clear="Clear", -- clear="Clear",
-- send="Send", -- send="Send",

View File

@@ -94,6 +94,7 @@ return{
-- wsFailed="WebSocket: connection failed", -- wsFailed="WebSocket: connection failed",
-- wsDisconnected="WebSocket: disconnected", -- wsDisconnected="WebSocket: disconnected",
-- wsNoConn="WebSocket: you are not connected", -- wsNoConn="WebSocket: you are not connected",
-- waitNetTask="Connecting, please wait",
-- chatJoin="joined the room.", -- chatJoin="joined the room.",
-- chatLeave="left the room.", -- chatLeave="left the room.",
@@ -102,6 +103,7 @@ return{
-- chatHistory="------New messages below------", -- chatHistory="------New messages below------",
-- chatQuit="Press again to exit", -- chatQuit="Press again to exit",
-- noRooms="No Rooms Now",
-- roomsFetchFailed="Failed to fetch rooms", -- roomsFetchFailed="Failed to fetch rooms",
errorMsg="Ha ocurrido un error y Techmino necesita reiniciarse.\nSe creó un registro de error, puedes enviarlo al autor.", errorMsg="Ha ocurrido un error y Techmino necesita reiniciarse.\nSe creó un registro de error, puedes enviarlo al autor.",
@@ -231,6 +233,11 @@ return{
-- rooms="Rooms", -- rooms="Rooms",
-- chat="Chat", -- chat="Chat",
}, },
net_rooms={
-- fresh="Fresh",
up="",
down="",
},
net_chat={ net_chat={
-- clear="Clear", -- clear="Clear",
-- send="Send", -- send="Send",

View File

@@ -91,6 +91,7 @@ return{
wsFailed="WS连接失败", wsFailed="WS连接失败",
wsDisconnected="WS连接断开", wsDisconnected="WS连接断开",
wsNoConn="WS未连接", wsNoConn="WS未连接",
waitNetTask="正在连接,请稍候",
chatJoin="进入房间", chatJoin="进入房间",
chatLeave="离开房间", chatLeave="离开房间",
@@ -99,6 +100,7 @@ return{
chatHistory="------以上是历史消息------", chatHistory="------以上是历史消息------",
chatQuit="再按一次退出", chatQuit="再按一次退出",
noRooms="一个房间都没有哎...",
roomsFetchFailed="拉取房间列表失败", roomsFetchFailed="拉取房间列表失败",
errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.", errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.",
@@ -251,6 +253,11 @@ return{
rooms="房间列表", rooms="房间列表",
chat="聊天室", chat="聊天室",
}, },
net_rooms={
fresh="刷新",
up="",
down="",
},
net_chat={ net_chat={
clear="清空", clear="清空",
send="发送", send="发送",

View File

@@ -1,8 +1,8 @@
local gc=love.graphics local gc=love.graphics
local max,min=math.max,math.min local min=math.min
local rooms local rooms
local scrollPos,curPos local scrollPos,selected
local lastfreshTime local lastfreshTime
local function task_fetchRooms(task) local function task_fetchRooms(task)
@@ -14,8 +14,7 @@ local function task_fetchRooms(task)
local res=json.decode(response.body) local res=json.decode(response.body)
if res then if res then
if response.code==200 then if response.code==200 then
rooms=res.rooms rooms=res.room_list
curPos=1
else else
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
end end
@@ -32,13 +31,40 @@ local function task_fetchRooms(task)
end end
end end
end end
local function task_enterRoom(task)
local time=0
while true do
coroutine.yield()
local wsconn,connErr=client.poll(task)
if wsconn then
WSCONN=wsconn
SCN.go("net_game")
loadGame("sprint_40")
LOG.print(text.wsSuccessed,"warn")
return
elseif connErr then
LOG.print(text.wsFailed..": "..connErr,"warn")
return
end
time=time+1
if time>360 then
LOG.print(text.wsFailed..": "..text.httpTimeout,"message")
return
end
end
end
local function fresh() local function fresh()
lastfreshTime=TIME() lastfreshTime=TIME()
rooms=nil rooms=nil
httpRequest( httpRequest(
task_fetchRooms, task_fetchRooms,
PATH.api..PATH.rooms, PATH.api..PATH.rooms,
"GET" "GET",
{["Content-Type"]="application/json"},
json.encode{
email=USER.email,
access_token=USER.access_token,
}
) )
end end
@@ -47,7 +73,7 @@ local scene={}
function scene.sceneInit() function scene.sceneInit()
BG.set("bg1") BG.set("bg1")
scrollPos=0 scrollPos=0
curPos=0 selected=1
fresh() fresh()
end end
@@ -55,13 +81,36 @@ function scene.wheelMoved(_,y)
wheelScroll(y) wheelScroll(y)
end end
function scene.keyDown(k) function scene.keyDown(k)
if rooms then if rooms and #rooms>0 then
if k=="down"then if k=="down"then
curPos=min(curPos+1,#rooms) if selected<#rooms then
selected=selected+1
if selected>scrollPos+10 then
scrollPos=scrollPos+1
end
end
elseif k=="up"then elseif k=="up"then
curPos=max(curPos-1,1) if selected>1 then
selected=selected-1
if selected<scrollPos+1 then
scrollPos=scrollPos-1
end
end
elseif k=="return"then
wsConnect(
task_enterRoom,
PATH.socket..PATH.play_room..
"?email="..urlEncode(USER.email)..
"&access_token="..urlEncode(USER.access_token)..
"&room_id="..urlEncode(rooms[selected].room_id)
-- "&password="..urlEncode(password),
)
elseif k=="r"then elseif k=="r"then
fresh() if TIME()-lastfreshTime>1 then
fresh()
end
elseif k=="escape"then
SCN.back()
end end
end end
end end
@@ -74,20 +123,35 @@ end
function scene.draw() function scene.draw()
if rooms then if rooms then
setFont(40) gc.setColor(1,1,1)
for i=scrollPos,min(scrollPos+9,#rooms)do if #rooms>0 then
local R=rooms[i+1] gc.setLineWidth(2)
gc.setColor(.7,.7,1) gc.rectangle("line",55,110,1100,400)
gc.print(i,50,100+50*i) gc.setColor(1,1,1,.3)
gc.setColor(1,1,.7) gc.rectangle("fill",55,40*(1+selected-scrollPos)+30,1100,40)
gc.print(R.name,130,100+50*i) setFont(35)
for i=1,min(10,#rooms-scrollPos)do
local R=rooms[scrollPos+i]
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.print("",20,50+50*curPos)
end end
end end
scene.widgetList={ scene.widgetList={
WIDGET.newButton{name="back",x=1140,y=640,w=170,h=80,font=40,code=WIDGET.lnk_BACK}, WIDGET.newKey{name="fresh", x=440,y=620,w=140,h=140,font=40,code=fresh,hide=function()return TIME()-lastfreshTime<1 end},
WIDGET.newKey{name="up", x=840,y=585,w=140,h=70,font=40,code=WIDGET.lnk_pressKey("up")},
WIDGET.newKey{name="down", x=840,y=655,w=140,h=70,font=40,code=WIDGET.lnk_pressKey("down")},
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=40,code=WIDGET.lnk_BACK},
} }
return scene return scene