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

86 lines
2.4 KiB
Lua

--进入房间View对象
local JoinRoomView = {}
local M = JoinRoomView
local KEY_DEL = "del"
local KEY_CLEAR = "c"
function JoinRoomView.new()
setmetatable(M, {__index = BaseWindow})
local self = setmetatable({}, {__index = M})
self.class = "JoinRoomView"
self._currenIndex = 0
self._close_destroy = true
self:init("ui://Lobby/Win_JoinRoom")
return self
end
function M:init(url)
BaseWindow.init(self,url)
self.tex_num = self._view:GetChild("tex_num")
self:ClearNumTex()
local cnt = self._view.numChildren - 1
for i = 0 , 9 do
local obj = self._view:GetChild("btn_"..i)
obj.onClick:Add(handler(self , self.OnNumButtonAction))
i = i + 1
end
local btn_c = self._view:GetChild("btn_c")
btn_c.onClick:Add(handler(self , self.OnNumButtonAction))
local btn_del = self._view:GetChild("btn_del")
btn_del.onClick:Add(handler(self , self.OnNumButtonAction))
end
function M:OnNumButtonAction(context)
local typer = string.sub(context.sender.name ,5)
if typer == KEY_DEL then
if (self._currenIndex > 0) then
self._currenIndex = self._currenIndex - 1
self._texnum_str = string.sub(self._texnum_str,0,self._currenIndex)
self.tex_num.text = self._texnum_str
end
elseif typer == KEY_CLEAR then
self:ClearNumTex()
else
if (self._currenIndex < 6) then
self._currenIndex = self._currenIndex + 1
self._texnum_str = self._texnum_str .. typer
self.tex_num.text = self._texnum_str
if(self._currenIndex == 6) then
self:JoinRoom(self._texnum_str)
end
end
end
end
function M:JoinRoom(str)
ViewUtil.ShowModalWait(self._root_view,"正在加入房间...")
local boddyCtr = ControllerManager.GetController(LoddyController)
boddyCtr:JoinRoom(str, function (response)
ViewUtil.CloseModalWait()
if response.ReturnCode == -2 then
self:JoinRoom(str)
return
elseif response.ReturnCode ~=0 then
ViewUtil.ErrorTip(response.ReturnCode,"进入房间失败")
return
end
self:Destroy()
ViewManager.ChangeView(ViewManager.View_Main,DataManager.CurrenRoom.game_id)
end)
end
function M:ClearNumTex()
self._texnum_str = ""
self._currenIndex = 0
self.tex_num.text = self._texnum_str
end
return JoinRoomView