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 -- 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() ViewUtil.ShowModalWait(true, "正在登录游戏...") 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_phone = view:GetChild("btn_phone") btn_phone.onClick:Set(function() self:PhoneLogin() end) self:InitClip() end function M:Destroy() if self._agreement then self._agreement:Destroy() end BaseView.Destroy(self) coroutine.stop(self.donhua) end function M:Show() BaseView.Show(self) self:QuickLogin() self:InitClip() 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(true, "正在加入房间...") __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(function(res) if res.ReturnCode == 0 then _phoneView:Destroy() end __login_response(self, res) end) _phoneView: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(true, "正在登录游戏...") 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(true) 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 function M:InitClip() local xuehuaEnd = 120 local xuehuaName = "ui://Login/xuehua_00" local xuehua = self._view:GetChild('clip_xuehua') local xuehuaIndex = 0 self.donhua = coroutine.start( function() while true do xuehuaIndex = self:ReplaceClip1(xuehuaEnd, xuehua, xuehuaIndex, xuehuaName) coroutine.wait(0.12) end end ) end function M:ReplaceClip1(e, t, i, n) if i > e then i = 0 end t.url = string.format("%s%03d", n, i) return i + 6 end