添加退出登录按钮

This commit is contained in:
MrZ626
2021-04-09 17:33:50 +08:00
parent f7fa8d0758
commit 48ce3a3d8f
8 changed files with 34 additions and 8 deletions

View File

@@ -246,6 +246,7 @@ return{
ffa="FFA",
rooms="Rooms",
chat="Chat",
logout="Log out",
},
net_rooms={
refreshing="Refreshing Rooms",

View File

@@ -219,6 +219,7 @@ return{
ffa="FFA",
rooms="Salons",
chat="Chat",
-- logout="Log out",
},
net_rooms={
-- refreshing="Refreshing Rooms",

View File

@@ -246,6 +246,7 @@ return{
ffa="FFA",
rooms="Salas",
chat="Chat",
-- logout="Log out",
},
net_rooms={
-- refreshing="Refreshing Rooms",

View File

@@ -224,6 +224,7 @@ return{
ffa="FFA",
rooms="Salas",
chat="Chat",
-- logout="Log out",
},
net_rooms={
-- refreshing="Refreshing Rooms",

View File

@@ -246,6 +246,7 @@ return{
ffa="FFA",
rooms="房间列表",
chat="聊天室",
logout="退出登录",
},
net_rooms={
refreshing="刷新房间列表中",

View File

@@ -2,7 +2,6 @@ local data=love.data
local ins,rem=table.insert,table.remove
local WS,TIME=WS,TIME
local NET={
login=false,
allow_online=false,
roomList={},
accessToken=false,
@@ -110,6 +109,9 @@ function NET.wsconn_stream()
end
--Disconnect
function NET.wsclose_user()
WS.close("user")
end
function NET.wsclose_play()
WS.close("play")
end
@@ -152,7 +154,7 @@ function NET.storeUserInfo(res)
--Get own name
if res.uid==USER.uid then
USER.username=res.username
FILE.save(USER,"conf/user")
FILE.save(USER,"conf/user","q")
end
-- FILE.save(USERS,"conf/users")
@@ -282,10 +284,11 @@ function NET.updateWS_user()
local res=_parse(message)
if res then
if res.type=="Connect"then
NET.login=true
if res.uid then
USER.uid=res.uid
USER.authToken=res.authToken
WIDGET.active.email:clear()
WIDGET.active.password:clear()
FILE.save(USER,"conf/user","q")
SCN.back()
end

View File

@@ -71,7 +71,7 @@ function scene.keyDown(key)
end
elseif key=="a"then
if testButton(3)then
if NET.login then
if WS.status("user")=="running"then
if not NET.allow_online then
TEXT.show(text.needUpdate,640,450,60,"flicker")
SFX.play("finesseError")

View File

@@ -1,6 +1,9 @@
local lastLogoutTime
local scene={}
function scene.sceneInit()
lastLogoutTime=-1e99
BG.set("space")
end
function scene.sceneBack()
@@ -8,10 +11,25 @@ function scene.sceneBack()
end
scene.widgetList={
-- WIDGET.newButton{name="ffa", x=640, y=200,w=350,h=120,font=40,code=NULL},
WIDGET.newButton{name="rooms", x=640, y=360,w=350,h=120,font=40,code=goScene"net_rooms"},
-- WIDGET.newButton{name="chat", x=640, y=540,w=350,h=120,font=40,code=goScene"net_chat"},
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=backScene},
WIDGET.newButton{name="ffa", x=640, y=200,w=350,h=120,color="black",font=40,code=NULL},
WIDGET.newButton{name="rooms", x=640, y=360,w=350,h=120, font=40,code=goScene"net_rooms"},
WIDGET.newButton{name="chat", x=640, y=540,w=350,h=120,color="black",font=40,code=NULL},
WIDGET.newButton{name="logout", x=1140, y=70,w=180,h=70,color="dR",code=function()
if TIME()-lastLogoutTime<1 then
if USER.uid then
NET.wsclose_play()
NET.wsclose_user()
USER.username=false
USER.uid=false
USER.authToken=false
FILE.save(USER,"conf/user","q")
SCN.back()
end
else
lastLogoutTime=TIME()
end
end},
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80, font=40,code=backScene},
}
return scene