require("Base/BasePanel") LoginPanel = Inherit(BasePanel) local this = LoginPanel this.LoginWay = { Account = 0, WeChat = 1 } local IsSDKLogin = AppConst.isSDK and AppConst.isSDKLogin local IsDevelopLogin = false local openIdkey = "openIdkey" local openIdPw = "openIdPw" local lastServerIndex = "lastServerIndex" local defaultOpenIdkey = Language[11118] local defaultOpenIdPw = "" local LoginRoot_Url = VersionManager:GetVersionInfo("serverUrl") local LoginRoot_SubChannel = VersionManager:GetVersionInfo("subChannel") local LoginRoot_Channel = VersionManager:GetVersionInfo("channel") local LoginRoot_Version = VersionManager:GetVersionInfo("version") local LoginRoot_PackageVersion = VersionManager:GetVersionInfo("packageVersion") local orginLayer --初始化组件(用于子类重写) function this:InitComponent() orginLayer = 0 this.loginPart = Util.GetGameObject(self.transform, "fx_map_Effect_youxikaishi/Image effect") this.tip = Util.GetGameObject(this.loginPart, "tip/Text") this.btnLoginPart = Util.GetGameObject(this.loginPart, "youxikaishi") this.btnLogin = Util.GetGameObject(this.btnLoginPart, "btn") --this.dropDownPart = Util.GetGameObject(this.loginPart, "quyuxuanzhe") --this.dropDown = Util.GetGameObject(this.dropDownPart, "Dropdown"):GetComponent("Dropdown") this.inputField = Util.GetGameObject(this.loginPart, "InputField"):GetComponent("InputField") this.UserBtn = Util.GetGameObject(this.loginPart, "userBtn") this.UserBtnText = Util.GetGameObject(this.loginPart, "userBtn/Text"):GetComponent("Text") this.btnUser = Util.GetGameObject(this.loginPart, "btnUser") this.btnNotice = Util.GetGameObject(this.loginPart, "btnNotice") ---selectServerPart this.serverSelectPart = Util.GetGameObject(this.loginPart, "serverSelect") this.serverMes = Util.GetGameObject(this.serverSelectPart, "serverMes"):GetComponent("Text") this.changeServerBtn = Util.GetGameObject(this.serverSelectPart, "changeServer") this.sdkLoginBtn = Util.GetGameObject(this.loginPart, "loginBtn") this.SetLoginPart(false) this.versionText = Util.GetGameObject(this.loginPart, "version"):GetComponent("Text") this.versionText.text = Language[11119]..LoginRoot_Version end --绑定事件(用于子类重写) function this:BindEvent() Util.AddClick(this.btnLogin, this.OnLoginClick) --this.dropDown:ClearOptions() Util.AddInputField_OnEndEdit(this.inputField.gameObject, function(str) PlayerPrefs.SetString(openIdkey, str) end) Util.AddClick(this.btnUser, function() local user = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey) local userPw = PlayerPrefs.GetString(openIdPw, defaultOpenIdPw) UIManager.OpenPanel(UIName.LoginPopup, user, userPw, function(str, pw) this.UserBtnText.text = str PlayerPrefs.SetString(openIdkey, str) PlayerPrefs.SetString(openIdPw, pw) end) end) Util.AddClick(this.btnNotice, function() UIManager.OpenPanel(UIName.NoticePopup) end) Util.AddClick(this.UserBtn, function() local user = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey) local userPw = PlayerPrefs.GetString(openIdPw, defaultOpenIdPw) UIManager.OpenPanel(UIName.LoginPopup, user, userPw, function(str, pw) this.UserBtnText.text = str PlayerPrefs.SetString(openIdkey, str) PlayerPrefs.SetString(openIdPw, pw) end) end) ---SelectServer Util.AddClick(this.changeServerBtn, function() UIManager.OpenPanel(UIName.ServerListSelectPanel, { serverList = this.serverList, myServerList = this.myServerList, lastServer = this.lastServer, recommend = this.recommend, callback = function(index) local list = this.serverList[index] PlayerPrefs.SetInt(lastServerIndex, index) PlayerManager.serverInfo = list LoginManager.SocketAddress = list.ip LoginManager.SocketPort = list.port LoginManager.ServerId = list.server_id local severArea = tonumber(string.sub(list.server_id, 0, -5)) this.serverMes.text = PlayerManager.serverInfo.name .. "\t" .. severArea .. "" .. Language[11120] end }) end) --SDK 登录 Util.AddClick(this.sdkLoginBtn, function() this.sdkLoginBtn:SetActive(false) this.SDKLogin() end) end --添加事件监听(用于子类重写) function this:AddListener() Game.GlobalEvent:AddEvent(Protocal.Connect, this.OnConnect) Game.GlobalEvent:AddEvent(Protocal.Disconnect, this.OnDisconnect) Game.GlobalEvent:AddEvent(GameEvent.LoginSuccess.OnLoginSuccess, this.RefreshLoginStatus) Game.GlobalEvent:AddEvent(GameEvent.LoginSuccess.OnLogout, this.OnLogout) end --移除事件监听(用于子类重写) function this:RemoveListener() Game.GlobalEvent:RemoveEvent(Protocal.Connect, this.OnConnect) Game.GlobalEvent:RemoveEvent(Protocal.Disconnect, this.OnDisconnect) Game.GlobalEvent:RemoveEvent(GameEvent.LoginSuccess.OnLoginSuccess, this.RefreshLoginStatus) Game.GlobalEvent:RemoveEvent(GameEvent.LoginSuccess.OnLogout, this.OnLogout) end function this:OnLogout() if IsSDKLogin then this.sdkLoginBtn:SetActive(false) this.inputField.gameObject:SetActive(false) this.UserBtn:SetActive(false) this.btnUser:SetActive(false) this.btnNotice.transform.position = this.btnUser.transform.position this.SDKLogin() else this.sdkLoginBtn:SetActive(false) local userId = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey) if IsDevelopLogin then this.UserBtn:SetActive(false) this.btnUser:SetActive(false) this.inputField.gameObject:SetActive(true) this.inputField.text = userId else this.UserBtn:SetActive(true) this.btnUser:SetActive(true) this.inputField.gameObject:SetActive(false) this.UserBtnText.text = userId end RequestPanel.Show(Language[11121]) this.SetLoginPart(true) networkMgr:SendGetHttp(string.format("%sjl_loginserver/getServerList?openId=%s&channel=%s&plat=android&sub_channel=%s", LoginRoot_Url, userId, LoginRoot_Channel, LoginRoot_SubChannel), this.OnReceiveServerList, nil, nil, nil) end end function this:OnSortingOrderChange() Util.AddParticleSortLayer(self.gameObject, self.sortingOrder - orginLayer) orginLayer = this.sortingOrder end --界面打开时调用(用于子类重写) function this:OnOpen(...) if AppConst.Code ~= "" then MsgPanel.ShowOne(AppConst.Code) AppConst.Code = "" end if IsSDKLogin then this.sdkLoginBtn:SetActive(false) this.inputField.gameObject:SetActive(false) this.UserBtn:SetActive(false) this.btnUser:SetActive(false) this.btnNotice.transform.position = this.btnUser.transform.position this.SDKLogin() else this.sdkLoginBtn:SetActive(false) local userId = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey) if IsDevelopLogin then this.UserBtn:SetActive(false) this.btnUser:SetActive(false) this.inputField.gameObject:SetActive(true) this.inputField.text = userId else this.UserBtn:SetActive(true) this.btnUser:SetActive(true) this.inputField.gameObject:SetActive(false) this.UserBtnText.text = userId end RequestPanel.Show(Language[11121]) this.SetLoginPart(true) networkMgr:SendGetHttp(string.format("%sjl_loginserver/getServerList?openId=%s&channel=%s&plat=android&sub_channel=%s", LoginRoot_Url, userId, LoginRoot_Channel, LoginRoot_SubChannel), this.OnReceiveServerList, nil, nil, nil) end local tran = this.tip:GetComponent("RectTransform") local offsetX = (LayoutUtility.GetPreferredWidth(tran) + Screen.width) / 2 tran.anchoredPosition = Vector2.New(offsetX, 0) tran:DOAnchorPosX(-offsetX, 30, false):SetEase(Ease.Linear):SetLoops(-1) SoundManager.PlayMusic(SoundConfig.BGM_Login) SoundManager.PlayAmbient(SoundConfig.Ambient_Login) end --界面关闭时调用(用于子类重写) function this:OnClose() this.SetLoginPart(false) SoundManager.PauseAmbient() end --界面销毁时调用(用于子类重写) function this:OnDestroy() end function this.SDKLogin() SDKMgr:Login() end function this.RefreshLoginStatus(loginResp) local result = string.split(loginResp, "#") if tonumber(result[1]) == SDK_RESULT.SUCCESS then RequestPanel.Show(Language[11121]) this.SetLoginPart(true) AppConst.SdkId = result[2] AppConst.OpenId = result[2] AppConst.TokenStr = result[4] AppConst.SdkChannel = result[5] -- this.SetSDKExtensionParams(result[4]) Log(string.format("%sjl_loginserver/getServerList?openId=%s&channel=%s&plat=android&sub_channel=%s", LoginRoot_Url, AppConst.OpenId, LoginRoot_Channel, LoginRoot_SubChannel)) networkMgr:SendGetHttp(string.format("%sjl_loginserver/getServerList?openId=%s&channel=%s&plat=android&sub_channel=%s", LoginRoot_Url, AppConst.OpenId, LoginRoot_Channel, LoginRoot_SubChannel), this.OnReceiveServerList, nil, nil, nil) else this.sdkLoginBtn:SetActive(true) end end function this.SetSDKExtensionParams(params) if not params or params == "" then return end local json = require 'cjson' local context = json.decode(params) BindPhoneNumberManager.SetPtToken(context.token) LoginManager.pt_pId = context.pid LoginManager.pt_gId = context.gid end --收到公告 function this.OnReceiveAnnouncement(str) if str == nil then return end ; pcall(function() local json = require 'cqueryAllies' local data = json.decode(str); if data.content ~= nil and data.content ~= "" then UIManager.OpenPanel(UIName.GongGaoPanel, data.content) end end); end --获取服务器列表地址 function this.OnReceiveServerList(str) if str == nil then return end if str ~= nil and str ~= "" then MyPCall(function() local json = require 'cjson' local data = json.decode(str) ---selectServerPart this.SetServerList(data) if not IsSDKLogin and not IsDevelopLogin then local user = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey) local userPw = PlayerPrefs.GetString(openIdPw, defaultOpenIdPw) if user == defaultOpenIdkey or userPw == defaultOpenIdPw then UIManager.OpenPanel(UIName.RegistPopup, function(str, pw) this.UserBtnText.text = str PlayerPrefs.SetString(openIdkey, str) PlayerPrefs.SetString(openIdPw, pw) end) else LoginManager.RequestUser(user, userPw, function(code) if code ~= 0 then UIManager.OpenPanel(UIName.LoginPopup, user, userPw, function(str, pw) this.UserBtnText.text = str PlayerPrefs.SetString(openIdkey, str) PlayerPrefs.SetString(openIdPw, pw) end) else UIManager.OpenPanel(UIName.NoticePopup) end end) end else UIManager.OpenPanel(UIName.NoticePopup) end end) end end function this.SetServerList(data) this.CacheLoginData(data) local lastIndex = PlayerPrefs.GetInt(lastServerIndex, 1) if this.lastServer then --有最近登录显示最近登录,没有显示推荐,否则显示第一个服 --for i = 1, #this.serverList do -- if this.serverList[i].server_id == this.lastServer.serverid then -- lastIndex = i -- break -- end --end else if this.recommend then for i = 1, #this.serverList do if this.serverList[i].server_id == this.recommend then lastIndex = i break end end end end if not this.serverList[lastIndex] then lastIndex = 1 PlayerPrefs.SetInt(lastServerIndex, 1) end PlayerManager.serverInfo = this.serverList[lastIndex] LoginManager.SocketAddress = this.serverList[lastIndex].ip LoginManager.SocketPort = tonumber(this.serverList[lastIndex].port) LoginManager.ServerId = this.serverList[lastIndex].server_id local severArea = tonumber(string.sub(this.serverList[lastIndex].server_id, 0, -5)) this.serverMes.text = PlayerManager.serverInfo.name .. "\t" .. severArea .. "" .. Language[11120] RequestPanel.Hide() end function this.CacheLoginData(data) this.serverList = {} for i = 1, #data.serverList do this.serverList[i] = data.serverList[i] end table.sort(this.serverList, function(a, b) if a.isnew == b.isnew then return a.server_id < b.server_id else return a.isnew > b.isnew end end) this.myServerList = {} for i = 1, #data.myServerList do this.myServerList[i] = data.myServerList[i] end this.lastServer = data.lastServer this.recommend = data.recommend end --用户id登录 function this.OnReceiveLogin(str) RequestPanel.Hide() if str == nil then return end if str ~= nil and str ~= "" then MyPCall(function() Log(str) local json = require 'cjson' local data = json.decode(str) Log("uid:" .. data.uid) Log("token:" .. data.token) if data.uid and data.token and not LoginManager.IsLogin then AppConst.UserId = data.uid AppConst.Token = data.token local openId = AppConst.isSDKLogin and AppConst.OpenId or PlayerPrefs.GetString(openIdkey) NetManager.LoginRequest(openId, LoginManager.pt_pId, LoginManager.pt_gId, function() if not LoginManager.IsLogin then LoginManager.IsLogin = true this.ExecuteLoading() end end) end end) end end --登录进主界面之前需要依次请求玩家数据,物品数据,装备数据,英雄数据,编队数据,任务数据, 异妖数据,工坊数据, 冒险数据 function this.ExecuteLoading() local requestList = { [1] = function() NetManager.PlayerInfoRequest(LoadingPanel.OnStep) end, -- 基础信息 [2] = function() NetManager.RequestMission(LoadingPanel.OnStep) end, -- 任务信息 [3] = function() NetManager.ItemInfoRequest(0, LoadingPanel.OnStep) end, -- 物品信息 [4] = function() NetManager.AllEquipRequest(0, LoadingPanel.OnStep) end, -- 装备 [5] = function() NetManager.AllEquipTreasureRequest(0, LoadingPanel.OnStep) end, -- [6] = function() NetManager.GetSoulPrintDataRequest(0, LoadingPanel.OnStep) end, -- 魂印 [7] = function() NetManager.DiffMonsterRequest(LoadingPanel.OnStep) end, -- 异妖 [8] = function() NetManager.HeroInfoRequest(0, LoadingPanel.OnStep) end, -- [9] = function() NetManager.TeamInfoRequest(LoadingPanel.OnStep) end, -- 编队 [10] = function() NetManager.GetAllMailData(LoadingPanel.OnStep) end, -- 邮件 [11] = function() NetManager.GetAllFightDataRequest(LoadingPanel.OnStep) end, -- [12] = function() NetManager.GetActivityAllRewardRequest(LoadingPanel.OnStep) end, -- 活动奖励 [13] = function() NetManager.RequestBaseArenaData(LoadingPanel.OnStep) end, -- 竞技场 [14] = function() ShopManager.InitData(LoadingPanel.OnStep) end, -- 商店 [15] = function() NetManager.GetWorkShopInfoRequest(LoadingPanel.OnStep) end, -- 工坊? [16] = function() ChatManager.InitData(LoadingPanel.OnStep) end, -- 聊天 [17] = function() NetManager.GetAllFunState(LoadingPanel.OnStep) end, -- 功能开启信息 [18] = function() NetManager.RequestGetFriendInfo(1, LoadingPanel.OnStep) end, -- 好友 [19] = function() NetManager.RequestGetFriendInfo(2, LoadingPanel.OnStep) end, -- 好友申请 [20] = function() NetManager.RequestGetFriendInfo(3, LoadingPanel.OnStep) end, -- 好友搜索 [21] = function() NetManager.RequestGetFriendInfo(4, LoadingPanel.OnStep) end, -- 黑名单 [22] = function() FriendChatManager.InitData(LoadingPanel.OnStep) end, -- 好友消息 [23] = function() MyGuildManager.InitBaseData(LoadingPanel.OnStep) end, -- 公会信息 [24] = function() GuildFightManager.InitBaseData(LoadingPanel.OnStep) end, -- 公会战 [25] = function() NetManager.GetAllGuildSkillData(LoadingPanel.OnStep) end, -- 公会技能 [26] = function() NetManager.InitFightPointLevelInfo(LoadingPanel.OnStep) end, -- 关卡 [27] = function() NetManager.GetExpeditionRequest(ExpeditionManager.expeditionLeve,LoadingPanel.OnStep) end, -- 大闹天宫 [28] = function() NetManager.GuildHelpGetAllRequest(LoadingPanel.OnStep) end, -- 公会援助 [29] = function() DeathPosManager.InitData(LoadingPanel.OnStep) end, -- 十绝阵 [30] = function() NetManager.TreasureOfHeavenScoreRequest(LoadingPanel.OnStep) end, -- 天宫秘宝积分 [31] = function() NetManager.RankFirstRequest({3,22,20,4,21},{0,0,0,0,20},LoadingPanel.OnStep) end, -- 排行榜数据 [32] = function() -- 登录请求最终接口,所有请求放在此接口之前 if AppConst.isGuide then if GuideManager.GetCurId(GuideType.Force) == 1 and PlayerManager.nickName == tostring(PlayerManager.uid) then --创号阶段先进入剧情对话,进入假战斗,然后对话起名,最后进入主界面 local exBattle = function () PatFaceManager.isLogin = true UIManager.OpenPanelAsync(UIName.MainPanel, function () UIManager.OpenPanel(UIName.FightPointPassMainPanel) LoadingPanel.End() end) end StoryManager.EventTrigger(100001, exBattle) else if PlayerManager.curMapId ~= 0 then NetManager.MapInfoRequest(PlayerManager.curMapId, FormationTypeDef.FORMATION_DREAMLAND, function(msg) MapManager.isReloadEnter = false MapTrialManager.firstEnter = true MapManager.SetViewSize(20)--设置视野范围(明雷形式) MapManager.curAreaId =FormationTypeDef.FORMATION_DREAMLAND MapManager.trialHeroInfo=msg.infos UIManager.OpenPanelAsync(UIName.MapPanel, LoadingPanel.End) end) else PatFaceManager.isLogin = true UIManager.OpenPanelAsync(UIName.MainPanel, function () UIManager.OpenPanel(UIName.FightPointPassMainPanel) LoadingPanel.End() end) end end else UIManager.OpenPanelAsync(UIName.MainPanel, function() if RoomManager.RoomAddress == nil or RoomManager.RoomAddress == "" then RoomManager.IsMatch = 0 elseif RoomManager.RoomAddress == "1" then RoomManager.IsMatch = 1 UIManager.OpenPanel(UIName.GMPanel) PopupTipPanel.ShowTip(Language[11122]) else if RoomManager.CurRoomType == 1 then Log(Language[11123]) RoomManager.RoomReGetGameRequest(RoomManager.RoomAddress) end end LoadingPanel.End() end) end -- 登录成功刷新红点数据 RedpotManager.CheckAllRedPointStatus() -- 检查新字状态 FunctionOpenMananger.InitCheck() this.SubmitGameData() DataCenterManager.CommitBootStatus() end, } -- for _, func in ipairs(requestList) do LoadingPanel.AddStep(func) end LoadingPanel.Start() this:ClosePanel() end function this.OnLoginClick() RequestPanel.Show(Language[11124]) SocketManager.AddNetwork(SocketType.LOGIN, LoginManager.SocketAddress, LoginManager.SocketPort) SocketManager.TryConnect(SocketType.LOGIN) end function this.OnConnect(network) RequestPanel.Hide() if network.type ~= SocketType.LOGIN then return end RequestPanel.Show(Language[11125]) if IsSDKLogin then Log(LoginRoot_Url .. "jl_loginserver/getUserInfo?openId=" .. AppConst.OpenId .. "&serverId=" .. LoginManager.ServerId .. "&token=" .. AppConst.TokenStr .. "&platform=" .. 1 .. "&sub_channel=" .. LoginRoot_SubChannel .. "&pid=" .. AppConst.SdkChannel --LoginManager.pt_pId .. "&gid=" .. "" --LoginManager.pt_gId .. "&version=" .. LoginRoot_PackageVersion) networkMgr:SendGetHttp(LoginRoot_Url .. "jl_loginserver/getUserInfo?openId=" .. AppConst.OpenId .. "&serverId=" .. LoginManager.ServerId .. "&token=" .. AppConst.TokenStr .. "&platform=" .. 1 .. "&sub_channel=" .. LoginRoot_SubChannel .. "&pid=" .. AppConst.SdkChannel --LoginManager.pt_pId .. "&gid=" .. "" --LoginManager.pt_gId .. "&version=" .. LoginRoot_PackageVersion, this.OnReceiveLogin, nil, nil, nil) else if IsDevelopLogin then -- 开发用 local str = this.inputField.text PlayerPrefs.SetString(openIdkey, str) networkMgr:SendGetHttp(LoginRoot_Url .. "jl_loginserver/getUserInfo?openId=" .. str .. "&serverId=" .. LoginManager.ServerId .. "&token=111" .. "&platform=3" .. "&sub_channel=" .. LoginRoot_SubChannel .. "&admin=d53b3e8ef74bf72d8aafce3a1c8671a0" .. "&version=" .. LoginRoot_PackageVersion, this.OnReceiveLogin, nil, nil, nil) else networkMgr:SendGetHttp(LoginRoot_Url .. "jl_loginserver/getUserInfo?openId=" ..LoginManager.openId .. "&serverId=" .. LoginManager.ServerId .. "&token=" .. LoginManager.token .. "&platform=4" .. "&sub_channel=" .. LoginRoot_SubChannel .. "&version=" .. LoginRoot_PackageVersion, this.OnReceiveLogin, nil, nil, nil) end -- if IsTestLogin then -- networkMgr:SendGetHttp(LoginRoot_Url -- .. "jl_loginserver/getUserInfo?openId=" .. LoginManager.openId -- .. "&serverId=" .. LoginManager.ServerId -- .. "&token=" .. LoginManager.token -- .. "&platform="..4 -- .. "&version=" .. LoginRoot_PackageVersion, -- this.OnReceiveLogin, nil, nil, nil) -- else -- -- -- networkMgr:SendGetHttp(LoginRoot_Url -- .. "jl_loginserver/getUserInfo?openId=" .. str -- .. "&platform=3&sub_channel=" .. LoginRoot_SubChannel -- .. "&serverId=" .. LoginManager.ServerId -- .. "&token=" .. AppConst.Token -- .. "&version=" .. LoginRoot_PackageVersion, -- this.OnReceiveLogin, nil, nil, nil) -- --TODO:线上调试用 -- -- networkMgr:SendGetHttp(LoginRoot_Url -- -- .. "jl_loginserver/getUserInfo?openId=" .. str -- -- .. "&platform=1&sub_channel=" .. LoginRoot_SubChannel -- -- .. "&serverId=" .. LoginManager.ServerId -- -- .. "&token=111&admin=d53b3e8ef74bf72d8aafce3a1c8671a0" -- -- .. "&version=" .. LoginRoot_PackageVersion, -- -- this.OnReceiveLogin, nil, nil, nil) -- end end end function this.OnDisconnect(network) RequestPanel.Hide() PopupTipPanel.ShowTip(Language[11126]) end function this.SetLoginPart(flag) this.btnLoginPart:SetActive(flag) --this.dropDownPart:SetActive(flag) this.serverSelectPart:SetActive(flag) end function this.SubmitGameData() local isNewRole = PlayerPrefs.GetString(tostring(PlayerManager.uid), "") if isNewRole == "" then PlayerPrefs.SetString(tostring(PlayerManager.uid), tostring(PlayerManager.uid)) SubmitExtraData({ type = SDKSubMitType.TYPE_CREATE_ROLE }) end SubmitExtraData({ type = SDKSubMitType.TYPE_ENTER_GAME }) end return LoginPanel