local PhoneLoginView = import(".PhoneLoginView") LoginView = {} local M = {} --- Create a new LoginView function LoginView.new() setmetatable(M, { __index = BaseView }) local self = setmetatable({}, { __index = M }) self.class = "LoginView" self._full = true self:init() return self end --- --@function [parent=#LoginView] init --@param self function M:init() UIPackage.AddPackage("base/login/ui/Login") --UIPackage.AddPackage("UI/Card") ViewUtil.PlaySoundBg() self:InitView("ui://Login/Main") local view = self._view -- view:GetChild("tex_version").text = "Version:" .. GetGameInfoPlatform("version") -- print(GameApplication.Instance.accountTest and 1 or 0) view:GetController("test").selectedIndex = GameApplication.Instance.accountTest and 1 or 0 self.agree = view:GetController("agree"); -- Utils.LoadBg("loginbg", view) if GameApplication.Instance.accountTest then local json_data = Utils.LoadLocalFile("userId") if json_data then local _data = json.decode(json_data) view:GetChild("tex_unionid").text = _data.userId end end local _btn_login = view:GetChild("btn_wx") _btn_login.onClick:Add(function() if self.agree.selectedIndex == 0 then ViewUtil.ErrorTip(self._root_view, "请勾选同意《用户协议》") return end ViewUtil.ShowModalWait(self._root_view, "正在登录游戏...") coroutine.start(function() coroutine.wait(8) if self.isWXCallBackMark then return end ViewUtil.CloseModalWait() ViewUtil.ErrorTip(10000, "微信登录失败!") end) if (not GameApplication.Instance.accountTest) then GameApplication.Instance:WXLogin(handler(self, self.LoginCallBack)) else --local ctr_user = view:GetController("user") local _tex_unionid = view:GetChild("tex_unionid") local utez = _tex_unionid.text --.. (ctr_user.selectedIndex + 1) local _data = {} _data["userId"] = utez local key = "userId" local s, e = pcall(function() Utils.SaveLocalFile(key, json.encode(_data)) end) if not s then print("Error:" .. e) end DataManager.SelfUser.acc = utez DataManager.SelfUser.nick_name = utez DataManager.SelfUser.sex = 1 DataManager.SelfUser.head_url = "" self:LoginCallBack(0) end end) --按钮取消,功能暂时不用 -- local btn_passwrod = view:GetChild("btn_passwrod") -- btn_passwrod.onClick:Set(function() -- self:PhoneLogin() -- end) local btn_phone_code = view:GetChild("btn_phone_code") btn_phone_code.onClick:Set(function() if self.agree.selectedIndex == 0 then ViewUtil.ErrorTip(self._root_view, "请勾选同意《用户协议》") return end self:PhoneCodeLogin() end) end function M:Destroy() if self._agreement then self._agreement:Destroy() end BaseView.Destroy(self) end function M:Show() BaseView.Show(self) self:QuickLogin() end local function __goto_lobby(response) if response.Data then local notices = response.Data.notice_list if notices and #notices > 0 then local tem = {} tem.data = notices tem.auto_show = true DataManager.SelfUser.notices = tem end end ControllerManager.ChangeController(LoddyController) ViewManager.ChangeView(ViewManager.View_Lobby) end local function __join_room(roomid, res) local loddyctr = ControllerManager.GetController(LoddyController) loddyctr:JoinRoom(roomid, function(res1) ViewUtil.CloseModalWait() if res1.ReturnCode == -2 then __join_room(roomid, res) elseif res1.ReturnCode == 0 then ViewManager.ChangeView(ViewManager.View_Main, DataManager.CurrenRoom.game_id) elseif res1.ReturnCode == 101 or res1.ReturnCode == 6 then __goto_lobby(res) else ViewUtil.ErrorTip(res1.ReturnCode, "登录失败!") end end) end local function __login_response(self, response) ViewUtil.CloseModalWait() local skey = "session_id" if (response.ReturnCode == 0) then local user = DataManager.SelfUser -- if (user.guild) then ExtendManager.Destroy() local function f_enterLobby(...) -- body local _client = ControllerManager.WebClient PlayerPrefs.SetString(skey, _client:getSession()) PlayerPrefs.Save() ExtendManager.Init(user.games) local roomid = user.room_id if (string.len(roomid) > 1) then if user.group_id == 0 then ViewUtil.ShowModalWait(self._root_view, "正在加入房间...") __join_room(roomid, response) return end end __goto_lobby(response) end if user.update ~= 0 then ExtendHotupdate.UpdateGameList(user.games, f_enterLobby) else f_enterLobby() end else if (response.ReturnCode == Table_Error_code.ERR_SERVER or response.ReturnCode == Table_Error_code.ERR_LOGOUT) then PlayerPrefs.DeleteKey(skey) PlayerPrefs.Save() end ViewUtil.ErrorTip(response.ReturnCode, "登录失败!") end end function M:PhoneLogin() local _phoneView = nil _phoneView = PhoneLoginView.new(0, function(res) if res.ReturnCode == 0 then _phoneView:Destroy() end __login_response(self, res) end) _phoneView:Show() end function M:PhoneCodeLogin() local _phoneCodeView = nil _phoneCodeView = PhoneLoginView.new(1, function(res) if res.ReturnCode == 0 then _phoneCodeView:Destroy() end __login_response(self, res) end) _phoneCodeView.agree = self.agree; _phoneCodeView:Show() end function M:IDLogin() local _idView = nil _idView = IDLoginView.new(function(res) if res.ReturnCode == 0 then _idView:Destroy() end __login_response(self, res) end) _idView:Show() end function M:QuickLogin() if (not GameApplication.Instance.accountTest) then local session_id = PlayerPrefs.GetString("session_id") print("session_id:" .. session_id) if session_id and string.len(session_id) > 3 then ViewUtil.ShowModalWait(self._root_view, "正在登录游戏...") local loginCtr = ControllerManager.GetController(LoginController) loginCtr:QuickLogin(session_id, function(response) __login_response(self, response) end) end end end function M:LoginCallBack(result, data) self.isWXCallBackMark = true --print("微信登录返回================================================================") --print("result===>"..result) --pt(data) if (not result) or result ~= 0 then if result == 10 then ViewUtil.ShowModalWait(self._root_view) return end ViewUtil.CloseModalWait() return end if data then local jd = json.decode(data) pt(jd) local headurl = jd["headimgurl"] local unionid = jd["unionid"] local sex = jd["sex"] if (sex == 0) then sex = 1 end local nickname = jd["nickname"] DataManager.SelfUser.acc = unionid DataManager.SelfUser.nick_name = nickname DataManager.SelfUser.sex = sex DataManager.SelfUser.head_url = headurl if not DataManager.SelfUser.acc or string.len(DataManager.SelfUser.acc) < 1 then ViewUtil.CloseModalWait() return end end local loginCtr = ControllerManager.GetController(LoginController) loginCtr:Login(function(response) __login_response(self, response) end) end function M:Destroy() BaseView.Destroy(self) -- UIPackage.RemovePackage("base/embed/ui/Hotupdate") UIPackage.RemovePackage("base/login/ui/Login") -- ResourcesManager.UnLoad("base/ui/Login.bytes") end