整理代码,调整textBox控件机制

This commit is contained in:
MrZ626
2021-04-08 15:27:01 +08:00
parent 1e22364429
commit 2a098a9445
3 changed files with 29 additions and 33 deletions

View File

@@ -845,7 +845,7 @@ function textBox:update()
end
function textBox:push(t)
ins(self.texts,t)
if self.scrollPos==#self.texts-1 then
if self.scrollPos==#self.texts-1 and not(self.hide and self.hide())then
self.scrollPos=#self.texts
else
SFX.play("spin_0",.8)

View File

@@ -69,25 +69,8 @@ end
function NET.wsconn_app()
WS.connect("app","/app")
end
function NET.wsconn_play()
if _lock("conn_play")then
WS.connect("play","/play",JSON.encode{
uid=USER.uid,
accessToken=NET.accessToken,
})
end
end
function NET.wsconn_stream()
if _lock("connectStream")then
WS.connect("stream","/stream",JSON.encode{
uid=USER.uid,
accessToken=NET.accessToken,
rid=NET.rsid,
})
end
end
function NET.wsconn_user_pswd(email,password)
if _lock("conn_user")then
if _lock("wsc_user")then
WS.connect("user","/user",JSON.encode{
email=email,
password=password,
@@ -95,13 +78,30 @@ function NET.wsconn_user_pswd(email,password)
end
end
function NET.wsconn_user_token(uid,authToken)
if _lock("conn_user")then
if _lock("wsc_user")then
WS.connect("user","/user",JSON.encode{
uid=uid,
authToken=authToken,
})
end
end
function NET.wsconn_play()
if _lock("wsc_play")then
WS.connect("play","/play",JSON.encode{
uid=USER.uid,
accessToken=NET.accessToken,
})
end
end
function NET.wsconn_stream()
if _lock("wsc_stream")then
WS.connect("stream","/stream",JSON.encode{
uid=USER.uid,
accessToken=NET.accessToken,
rid=NET.rsid,
})
end
end
--Disconnect
function NET.wsclose_play()
@@ -110,9 +110,6 @@ end
function NET.wsclose_stream()
WS.close("stream")
end
function NET.wsclose_user()
WS.close("user")
end
--Account
function NET.pong(wsName,message)
@@ -288,7 +285,7 @@ function NET.updateWS_user()
--Get self infos
NET.getUserInfo(USER.uid)
_unlock("conn_user")
_unlock("wsc_user")
elseif res.action==0 then--Get accessToken
NET.accessToken=res.accessToken
LOG.print(text.accessSuccessed)
@@ -323,7 +320,7 @@ function NET.updateWS_play()
if res then
if res.type=="Connect"then
SCN.go("net_menu")
_unlock("conn_play")
_unlock("wsc_play")
elseif res.action==0 then--Fetch rooms
NET.roomList=res.roomList
_unlock("fetchRoom")
@@ -426,7 +423,7 @@ function NET.updateWS_stream()
local res=_parse(message)
if res then
if res.type=="Connect"then
--?
_unlock("wsc_stream")
elseif res.action==0 then--Game start
SCN.socketRead("Begin",res.data)
elseif res.action==1 then--Game finished

View File

@@ -9,8 +9,7 @@ local onVirtualkey=onVirtualkey
local pressVirtualkey=pressVirtualkey
local updateVirtualkey=updateVirtualkey
local hideChatBox
local textBox=WIDGET.newTextBox{name="texts",x=340,y=80,w=600,h=550,hide=function()return hideChatBox end}
local textBox=WIDGET.newTextBox{name="texts",x=340,y=80,w=600,h=550,hide=false}
local playing
local lastUpstreamTime
@@ -28,7 +27,7 @@ function scene.sceneBack()
end
function scene.sceneInit()
love.keyboard.setKeyRepeat(false)
hideChatBox=true
textBox.hide=true
textBox:clear()
resetGameData("n")
@@ -85,7 +84,7 @@ function scene.keyDown(key)
LOG.print(text.sureQuit,COLOR.orange)
end
elseif key=="\\"then
hideChatBox=not hideChatBox
textBox.hide=not textBox.hide
elseif playing then
if noKey then return end
local k=keyMap.keyboard[key]
@@ -274,7 +273,7 @@ function scene.draw()
drawFWM()
--Players
for p=hideChatBox and 1 or 2,#PLAYERS do
for p=textBox.hide and 1 or 2,#PLAYERS do
PLAYERS[p]:draw()
end
@@ -285,7 +284,7 @@ function scene.draw()
drawWarning()
--New message
if textBox.new and hideChatBox then
if textBox.new and textBox.hide then
setFont(30)
gc.setColor(1,TIME()%.4<.2 and 1 or 0,0)
gc.print("M",460,15)
@@ -296,7 +295,7 @@ scene.widgetList={
WIDGET.newKey{name="ready",x=640,y=440,w=200,h=80,color="yellow",font=40,code=pressKey"space",hide=function()
return
playing or
not hideChatBox or
not textBox.hide or
NET.getLock("ready")
end},
WIDGET.newKey{name="hideChat",fText="...",x=380,y=35,w=60,font=35,code=pressKey"\\"},