--进入房间View对象 local JoinRoomView = {} local M = JoinRoomView local KEY_DEL = "del" local KEY_CLEAR = "reset" 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/JoinRoom") return self end function M:init(url) BaseWindow.init(self, url) self.tex_num = self._view:GetChild("show_text") self:ClearNumTex() for i = 0, 9 do local obj = self._view:GetChild("btn_num_" .. i) obj.onClick:Add(handler(self, self.OnNumButtonAction)) i = i + 1 end local btn_reset = self._view:GetChild("btn_reset") btn_reset.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) printlog("==========================OnNumButtonAction==============================") printlog(typer) if typer == KEY_DEL then if (self._currenIndex > 0) then self._currenIndex = self._currenIndex - 1 printlog("==================test=================") -- print("ok") printlog(#self._texnum_str) printlog(self._currenIndex) printlog("==================test=================") 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 .. string.sub(typer, -1) 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