--大厅View对象 --author:-- local CreateRoomView = import(".Lobby.CreateRoomView") local JoinRoomView = import(".Lobby.JoinRoomView") local LobbySettingView = import(".Lobby.LobbySettingView") local RankView = import(".Lobby.RankView") local GroupMainView = import(".NewGroup.GroupMainView") local NoticeView = import(".Lobby.NoticeView") local HeadView = import(".Lobby.LobbyHeadView") local PhoneBindView = import(".Lobby.PhoneBindView") local RealAddressView = import(".Lobby.RealAddressView") local LobbyHeadView = import(".Lobby.LobbyHeadView") local IDPasswordAlone = import(".Lobby.IDPasswordAlone") local SelectAcc = import(".Lobby.SelectAcc") LobbyView = {} local M = {} function LobbyView.new() --print("new lobbyView!!!!") setmetatable(M, { __index = BaseView }) local self = setmetatable({}, { __index = M }) self.class = "LobbyView" UIPackage.AddPackage("base/lobby/ui/Lobby") self.lobby_pause_time = 0 self._full = true self:InitView("ui://Lobby/Main") self._close_destroy = false return self end function M:InitView(url) BaseView.InitView(self, url) self._full_offset = false local view = self._view local btn_head = view:GetChild("btn_head") ImageLoad.Load(DataManager.SelfUser.head_url, btn_head._iconObject) btn_head.onClick:Set(function() local lobbyHeadView = LobbyHeadView.new(DataManager.SelfUser, DataManager.SelfUser.agent, function() ImageLoad.Load(DataManager.SelfUser.head_url, btn_head._iconObject) end) lobbyHeadView:Show() end) view:GetChild("tex_name").text = DataManager.SelfUser.nick_name view:GetChild("tex_id").text = string.format("ID:%s", DataManager.SelfUser.account_id) view:GetChild("gcm_diamo").text = tostring(DataManager.SelfUser.diamo) local btn_joinroom = self._view:GetChild("btn_joinroom") btn_joinroom.touchable = false btn_joinroom.onClick:Add(handler(self, self.OnJoinRoomAction)) local createRoomBtn = self._view:GetChild("btn_ChuangJian") createRoomBtn.touchable = false createRoomBtn.onClick:Set(function() local _createRoomView = CreateRoomView.new(1) _createRoomView.onCeateRoom = function() ViewManager.ChangeView(ViewManager.View_Main, DataManager.CurrenRoom.game_id) end _createRoomView:Show() end) local btn_setting = self._view:GetChild("btn_setting") btn_setting.onClick:Set(handler(self, function() local settingView = LobbySettingView.new() settingView:Show() end)) -- local btn_exit = self._view:GetChild("btn_exit") -- btn_exit.onClick:Set(handler(self, function() -- local _curren_msg = MsgWindow.new(self._root_view, '确认退出游戏', MsgWindow.MsgMode.OkAndCancel) -- _curren_msg.onOk:Add(function() -- Application.Quit() -- end) -- _curren_msg:Show() -- end)) self.groupMainView = GroupMainView.new(self._view:GetChild("group"), self._root_view, self._view) local btn_more_group = self._view:GetChild("btn_more_group") btn_more_group.onClick:Set(function() ViewUtil.ShowModalWait(self._root_view, "请稍等,获取牌友圈中...") local enterGroupCallBackFunc = function(code) ViewUtil.CloseModalWait() if code == 0 then self.groupMainView._view.visible = true else Application.Quit() end end self.groupMainView:Show(nil, enterGroupCallBackFunc) end) self:__GetMessage() end function M:OnJoinRoomAction(context) local joinRoomView = JoinRoomView.new(self._root_view) joinRoomView:Show() end function M:__GetMessage(data) if not data or not data.notice_list then self._mesList = "" local message = self._view:GetChild("Comp_Message") message.visible = false else local message = self._view:GetChild("Comp_Message") message.visible = true if not self._message then self._message = message:GetChild('Lab_Message') end if not self._tex_message then self._tex_message = self._message:GetChild('text') end local mesl = {} for i = 1, #data.notice_list do mesl[i] = data.notice_list[i].informContent end self._mesList = mesl self:__moveMsg(0) end end function M:__PopMsg(index) local num = #self._mesList index = index + 1 if index > num then index = 1 end local str = tostring(self._mesList[index]) if str == nil or str == "nil" then str = "" end return index, string.gsub(str, "\r", "") end function M:__moveMsg(index) if not self._tex_message then return end index, self._tex_message.text = self:__PopMsg(index) self._tex_message.x = self._message.width if self._mesTw then TweenUtils.Kill(self._mesTw) end local change = -self._message.width * 2 local dd = self._tex_message.width / self._message.width if dd < 1 then dd = 1 end self._mesTw = TweenUtils.TweenFloat(0, 1 * dd, 10 * dd, function(value) self._tex_message.x = self._message.width + (change * value) end) TweenUtils.OnComplete(self._mesTw, function() self._mesTw = nil if (#self._mesList == 0) then self:__GetMessage() else self:__PopMsg(index) self:__moveMsg(index) end end) end function M:__ShowShare() local pop_share = self._view:GetChild("pop_share") local shareUrl = GetGameInfo("invite_link") .. "?uid=" .. DataManager.SelfUser.account_id local btn_wx_session = pop_share:GetChild("btn_wx_session") btn_wx_session.onClick:Add(function() shareQRCodePicture(shareUrl, 0) end) local btn_wx_line = pop_share:GetChild("btn_wx_line").asButton btn_wx_line.onClick:Add(function() shareQRCodePicture(shareUrl, 1) end) end function M:OnUpdate() local roomid = GameApplication.Instance:GetRoomID() if roomid and string.len(roomid) > 1 then ControllerManager.WebClient:clearActionQueue() local joinRoomView = JoinRoomView.new(self._root_view) joinRoomView:JoinRoom(roomid) end end function M:Close() BaseView.Close(self) UpdateBeat:Remove(self.OnUpdate, self) coroutine.stopAll() if self._mesTw then TweenUtils.Kill(self._mesTw) end BaseWindow.DestroyAll() DSTweenManager.ClearTween() end function M:Destroy() UpdateBeat:Remove(self.OnUpdate, self) if self._mesTw then TweenUtils.Kill(self._mesTw) end self._tex_message = nil coroutine.stopAll() BaseView.Destroy(self) BaseWindow.DestroyAll() DSTweenManager.ClearTween() end function M:Show() BaseView.Show(self) ViewUtil.PlaySoundBg() UpdateBeat:Add(self.OnUpdate, self) coroutine.start(self.GetUserIp, self) -- 如果在圈子内的房间,显示tip local user = DataManager.SelfUser local tem = user.notices if user.group_id ~= 0 then local msg_tip = MsgWindow.new(self._root_view, "还在圈子的房间中,现在重连吗?", MsgWindow.MsgMode.OkAndCancel) msg_tip.onOk:Add(function() if self.groupMainView ~= nil then self.groupMainView:Show(user.group_id) end end) msg_tip:Show() tem.auto_show = false else local lobbyCtr1 = ControllerManager.GetController(LoddyController) lobbyCtr1:UpdateNotice(DataManager.SelfUser.account_id, function(result, data) -- local data1 = {} -- data1.notice_list = {} -- data1.notice_list[1] = "ccccccccccccccccccccccccccc" if result then self:__GetMessage(data) end end) end local loddyCtr1 = ControllerManager.GetController(LoddyController) self:GetPlayerInfoData() -- 获取GPS坐标 if not DataManager.SelfUser.location or DataManager.SelfUser.location:Location2String() == "" then get_gps() end if self.groupMainView and self.groupMainView._groupInfoView then self.groupMainView._groupInfoView:hidePipei() local gamectrl = ControllerManager.GetController(GameController) if gamectrl and gamectrl.tmpRoomID ~= nil then self.groupMainView._groupInfoView:ShowReturnToGame(true) else self.groupMainView._groupInfoView:ShowReturnToGame(false) end end if not DataManager.SelfUser.bind_pwd then local idPasswordAlone = IDPasswordAlone.new() idPasswordAlone:Show() elseif not DataManager.SelfUser.retri_pwd then local idPasswordAlone = IDPasswordAlone.new({ only_retrieve = true }) idPasswordAlone:Show() elseif DataManager.SelfUser.isBangding and DataManager.SelfUser.isBangding == 0 then local selectAcc = SelectAcc.new({}, function() self._close_destroy = true end) end --如果本地没有配置且设备没有绑定则弹窗提示 local fristLogin = PlayerPrefs.GetString("isLock_" .. DataManager.SelfUser.account_id) if #fristLogin == 0 and DataManager.SelfUser.is_lock == 0 then local _curren_msg = MsgWindow.new(self._root_view, "当前用户没有锁定设备\n为了您的安全\n请点击确定锁定当前设备", MsgWindow.MsgMode.OnlyOk, nil, nil, { openClose = true }) _curren_msg.onOk:Add( function() local settingView = LobbySettingView.new() settingView:Show() end ) _curren_msg:Show() end PlayerPrefs.SetString("isLock_" .. DataManager.SelfUser.account_id, DataManager.SelfUser.account_id) end function M:ChangeReturnToGame() if self.groupMainView and self.groupMainView._groupInfoView then local gamectrl = ControllerManager.GetController(GameController) if gamectrl and gamectrl.tmpRoomID ~= nil then self.groupMainView._groupInfoView:ShowReturnToGame(true) else self.groupMainView._groupInfoView:ShowReturnToGame(false) end end end function M:GetPlayerInfoData() local loddyCtr1 = ControllerManager.GetController(LoddyController) loddyCtr1:UpdatePlayerInfo(function(result, data) if result then self:ShowPlayerInfo(data.raffle, data.diamo, data.newMail) end end) end function M:ShowPlayerInfo(raffle, diamo, newMail) self._view:GetChild("gcm_diamo"):GetChild("title").text = diamo or 0 end function M:OnApplicationPause() ControllerManager.WebClient:clearActionQueue() -- 切后台时间 if DataManager.SelfUser.cur_group then self.lobby_pause_time = os.time() DataManager.SelfUser.cur_group.pause = true end end function M:OnApplicationActive() ControllerManager.WebClient:clearActionQueue() self:GetPlayerInfoData() -- 切后台太久牌友圈重连 if DataManager.SelfUser.cur_group then DataManager.SelfUser.cur_group.pause = false if os.time() - self.lobby_pause_time > 15 then self.lobby_pause_time = os.time() DataManager.SelfUser.cur_group:Reconnect() end end end function M:GetUserIp() local url = "https://ipv4.icanhazip.com" local www = UnityEngine.WWW(url) coroutine.www(www) if string.utf8len(www.error) == 0 then local txt = www.text local lobbyCtr = ControllerManager.GetController(LoddyController) local _data = {} _data.ip = txt lobbyCtr:SetUserIp(_data, function(res) end) end end