From 2a098a94450f2b535a48c0c74d027d62780f988f Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 8 Apr 2021 15:27:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4textBox=E6=8E=A7=E4=BB=B6=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/widget.lua | 2 +- parts/net.lua | 47 ++++++++++++++++++--------------------- parts/scenes/net_game.lua | 13 +++++------ 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/Zframework/widget.lua b/Zframework/widget.lua index 2a8e379f..f5d601f9 100644 --- a/Zframework/widget.lua +++ b/Zframework/widget.lua @@ -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) diff --git a/parts/net.lua b/parts/net.lua index 11d33dc8..b16fe645 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -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 diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index 4aea64c7..ba1a459b 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -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"\\"},