hengyang_client/lua_probject/base_project/Game/View/Lobby/JoinRoomView.lua

90 lines
2.7 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
--进入房间View对象
local JoinRoomView = {}
local M = JoinRoomView
local KEY_DEL = "del"
local KEY_CLEAR = "reset"
function JoinRoomView.new()
2025-04-11 12:49:08 +08:00
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
2025-04-01 10:48:36 +08:00
self.class = "JoinRoomView"
self._currenIndex = 0
self._close_destroy = true
self:init("ui://Lobby/JoinRoom")
return self
end
function M:init(url)
2025-04-11 12:49:08 +08:00
BaseWindow.init(self, url)
2025-04-01 10:48:36 +08:00
self.tex_num = self._view:GetChild("show_text")
self:ClearNumTex()
2025-04-11 12:49:08 +08:00
for i = 0, 9 do
local obj = self._view:GetChild("btn_num_" .. i)
obj.onClick:Add(handler(self, self.OnNumButtonAction))
2025-04-01 10:48:36 +08:00
i = i + 1
end
local btn_reset = self._view:GetChild("btn_reset")
2025-04-11 12:49:08 +08:00
btn_reset.onClick:Add(handler(self, self.OnNumButtonAction))
2025-04-01 10:48:36 +08:00
local btn_del = self._view:GetChild("btn_del")
2025-04-11 12:49:08 +08:00
btn_del.onClick:Add(handler(self, self.OnNumButtonAction))
2025-04-01 10:48:36 +08:00
end
function M:OnNumButtonAction(context)
2025-04-11 12:49:08 +08:00
local typer = string.sub(context.sender.name, 5)
2025-04-01 10:48:36 +08:00
printlog("==========================OnNumButtonAction==============================")
printlog(typer)
if typer == KEY_DEL then
2025-04-11 12:49:08 +08:00
if (self._currenIndex > 0) then
2025-04-01 10:48:36 +08:00
self._currenIndex = self._currenIndex - 1
printlog("==================test=================")
2025-04-11 12:49:08 +08:00
-- print("ok")
2025-04-01 10:48:36 +08:00
printlog(#self._texnum_str)
printlog(self._currenIndex)
printlog("==================test=================")
2025-04-11 12:49:08 +08:00
self._texnum_str = string.sub(self._texnum_str, 0, self._currenIndex)
2025-04-01 10:48:36 +08:00
self.tex_num.text = self._texnum_str
end
elseif typer == KEY_CLEAR then
2025-04-11 12:49:08 +08:00
self:ClearNumTex()
2025-04-01 10:48:36 +08:00
else
if (self._currenIndex < 6) then
self._currenIndex = self._currenIndex + 1
2025-04-11 12:49:08 +08:00
self._texnum_str = self._texnum_str .. string.sub(typer, -1)
2025-04-01 10:48:36 +08:00
self.tex_num.text = self._texnum_str
2025-04-11 12:49:08 +08:00
if (self._currenIndex == 6) then
2025-04-01 10:48:36 +08:00
self:JoinRoom(self._texnum_str)
end
end
end
end
function M:JoinRoom(str)
2025-11-06 17:37:53 +08:00
ViewUtil.ShowModalWait2(self._root_view, "正在加入房间...")
2025-04-01 10:48:36 +08:00
local boddyCtr = ControllerManager.GetController(LoddyController)
2025-04-11 12:49:08 +08:00
boddyCtr:JoinRoom(str, function(response)
2025-11-06 17:37:53 +08:00
ViewUtil.CloseModalWait2()
2025-04-01 10:48:36 +08:00
if response.ReturnCode == -2 then
self:JoinRoom(str)
return
2025-04-11 12:49:08 +08:00
elseif response.ReturnCode ~= 0 then
ViewUtil.ErrorTip(response.ReturnCode, "进入房间失败")
2025-04-01 10:48:36 +08:00
return
end
self:Destroy()
2025-04-11 12:49:08 +08:00
ViewManager.ChangeView(ViewManager.View_Main, DataManager.CurrenRoom.game_id)
2025-04-01 10:48:36 +08:00
end)
end
function M:ClearNumTex()
self._texnum_str = ""
self._currenIndex = 0
self.tex_num.text = self._texnum_str
end
return JoinRoomView