Implemented chatting room (#17)

This commit is contained in:
Particle_G
2020-12-03 16:09:25 +08:00
committed by MrZ626
parent 325c544e17
commit 37d7dd5fe0
11 changed files with 189 additions and 66 deletions

View File

@@ -1,27 +1,8 @@
local function send()
local W=WIDGET.active.text
--sendMessage(W.value)
W.value=""
end
function sceneInit.chat()
BG.set("none")
end
local function socketConnect()
wsConnect(
TICK.wsCONN_connect,
"/solo?room_id=114",
{}
)
end
local function socketWrite()
local function socketWrite(message)
if not WSCONN then
LOG.print("尚未连接到服务器","warn")
return
end
local message = WIDGET.active.message.value
print("TextBox: "..message)
local writeErr = client.write(WSCONN, message)
if writeErr then
print(writeErr, "warn")
@@ -29,6 +10,21 @@ local function socketWrite()
return true
end
local function send()
local W=WIDGET.active.text
socketWrite(W.value)
W.value=""
end
function sceneInit.chat()
BG.set("none")
wsConnect(
TICK.wsCONN_connect,
PATH.socket..PATH.chat.."?email="..urlEncode(ACCOUNT.email).."&access_token="..urlEncode(ACCOUNT.access_token),
{}
)
end
WIDGET.init("chat",{
WIDGET.newTextBox{name="text", x=40, y=500,w=980,h=180,font=40},
WIDGET.newButton{name="send", x=1140, y=540,w=170,h=80,font=40,code=send},

View File

@@ -35,7 +35,7 @@ end
WIDGET.init("main",{
WIDGET.newButton{name="offline",x=150,y=220,w=200,h=140,color="lRed", font=40,code=WIDGET.lnk_goScene("mode")},
WIDGET.newButton{name="online", x=370,y=220,w=200,h=140,color="lCyan", font=40,code=function()SCN.go(LOGIN and"netgame"or"login")end},
WIDGET.newButton{name="online", x=370,y=220,w=200,h=140,color="lCyan", font=40,code=WIDGET.lnk_goNetgame},
WIDGET.newButton{name="custom", x=590,y=220,w=200,h=140,color="lBlue", font=40,code=WIDGET.lnk_goScene("customGame")},
WIDGET.newButton{name="setting",x=150,y=380,w=200,h=140,color="lOrange",font=40,code=WIDGET.lnk_goScene("setting_game")},
WIDGET.newButton{name="stat", x=370,y=380,w=200,h=140,color="lGreen", font=40,code=WIDGET.lnk_goScene("stat")},