local UILoginMain = UIViewClass() local EventSystem = require('Event/EventSystem') local RefreshInterval = 30 -- 刷新间隔 function UILoginMain:OnCreated() self.group_Login = self.group_Login.gameObject self.group_Regist02 = self.group_Regist02.gameObject self.group_Regist01 = self.group_Regist01.gameObject end function UILoginMain:OnOpened() self:InitBaseComponent() self:RegisterEvents() self:RefreshLanguageToggleView() -- 多语言 self.group_ServerState.gameObject:SetActive(false) --登陆时,先初始化一次随机数, LogicRandom.SetRandomPool(math.random(99999)); self.txt_Version.text = MDL.HotFix.GetVersionInfo() self.txt_Version.gameObject.transform.parent.gameObject:SetActive(false) UIUtils.SetActive(self.btn_Language, Localization.IsSwitchLanguage()) UIUtils.SetActive(self.btn_Services, self:IsShowServiceBtn()) UIUtils.SetActive(self.btn_CG, false) UIUtils.SetActive(self.btn_UserCenter, self:IsShowNTSDKSwichAccountBtn()) UIUtils.SetActive(self.btn_RemoveAccountVN, self:IsShowRemoveAccountVNBtn()) UIUtils.SetActive(self.btn_QrCode, MDL.WinLogin:IsShowScanButton()) self:SetVN18LogoConfig() self:RefreshShowUserAgreement() UTL.UIRender.AdaptivePadStretch(self.gameObject.transform) self.ani_Btn:PlayAnim() end function UILoginMain:IsShowNTSDKSwichAccountBtn() if GameAppInfo.IsPCPackageWithSdk() then return true end return AppInfo.SDKType ~= 0 and Localization.IsShowNTSDKSwichAccountBtn() end function UILoginMain:IsShowRemoveAccountVNBtn() if UNITY_IOS and GameAppInfo.IsVietnamPackage() and MDL.Login.IsReviewService then return true end return false end function UILoginMain:RefreshShowUserAgreement() UIUtils.SetActive(self.btn_UserAgreement, self:IsShowUserAgreement()) end function UILoginMain:IsShowUserAgreement() logging.log(LTAG.LOG,"AndroidPrivarySwitch ", CTL.Login.GetAndroidPrivarySwitch(), "IOSPrivarySwitch ",CTL.Login.GetIOSPrivarySwitch()) if GameAppInfo.IsOverseaPackage() and not GameAppInfo.IsPCPackage() then if GameAppInfo.IsAndroidPackage() then return CTL.Login.GetAndroidPrivarySwitch() elseif GameAppInfo.IsiOSPackage() then return CTL.Login.GetIOSPrivarySwitch() end end return false end function UILoginMain:OnBackButtonPressed() SDKUtil.Exit() end function UILoginMain:InitBaseComponent() UIUtils.SetActive(self.login_Password, CTL.WinLogin.IsGameStreamerPackage()) UIUtils.SetActive(self.btn_regist, not CTL.WinLogin.IsGameStreamerPackage()) self.CurShardInfo = MDL.Login.ShardInfo local userName = PersistentData.DeviceData:Get(MDL.Login.LoginConstKey.KEY_LOGIN_USERNAME) local password = PersistentData.DeviceData:Get(MDL.Login.LoginConstKey.KEY_LOGIN_PASSWORD) if not string.isNilOrEmpty(userName) then self.login_Username.text = userName end self.login_Password.text = string.isNilOrEmpty(password) and "1" or password --sdk登陆 隐藏登陆UI,先隐藏著作权显示 local isShowRegist= SDKUtil.IsShowRegistUI() self.group_Regist01:SetActive(isShowRegist) UIUtils.SetActive(self.btn_AgePreference, self:IsShowLimitAgeTip()) if self:IsShowLimitAgeTip() then UIUtils.SetLabelText(self.lab_Tips01, Const_IDS.IDS_LOGONSCREEN_BOTTON_01) UIUtils.SetLabelText(self.lab_Tips02, Const_IDS.IDS_LOGONSCREEN_BOTTON_02) UIUtils.SetLabelText(self.lab_Tips03, Const_IDS.IDS_LOGONSCREEN_BOTTON_03) UIUtils.SetActive(self.group_Tips, true) else UIUtils.SetActive(self.group_Tips, false) end if not isShowRegist then self:CheckCSTimeDiff() end end function UILoginMain:IsShowLimitAgeTip() return GameAppInfo.IsChinesePackage() end function UILoginMain:IsShowCopyRight() return GameAppInfo.IsChinesePackage() end --检测客户端和服务器时间是否相差太多(5秒) function UILoginMain:CheckCSTimeDiff() if MDL.Login.HasClientServerTimeDiffErrorReported then -- CTL.Tips.AddTipsMsg(UIUtils.GetLocalizedTxt(Const_IDS["IDS_Device_Local_Time_Error"])) MDL.Login.HasClientServerTimeDiffErrorReported = false end end function UILoginMain:RegisterEvents() self:RegistSystemEvent(EventID.UI_Login_RegisterComplete, self.RegisterComplete) self:RegistSystemEvent(EventID.UI_Login_OnAuthComplete, self.OnAuthComplete) self:RegistSystemEvent(EventID.UI_Login_GetCurShardInfo, self.GetCurShardInfo) self:RegistSystemEvent(EventID.UI_Login_RefreshLoginServerInfo, self.RefreshLoginServerInfo) self:RegistSystemEvent(EventID.UI_Login_RefreshAnnouncementInfo, self.ClickNotice) self:RegistSystemEvent(EventID.UI_Login_PrivacySwitchUpdate, self.RefreshShowUserAgreement) end --注册成功,进入服务器选择界面 function UILoginMain:RegisterComplete() local tmpUserName = self.group_Username.text; local tmpPassword = self.group_Password.text; PersistentData.DeviceData:Set(MDL.Login.LoginConstKey.KEY_LOGIN_USERNAME,tmpUserName,true) PersistentData.DeviceData:Set(MDL.Login.LoginConstKey.KEY_LOGIN_PASSWORD,tmpPassword,true) self.login_Username.text = tmpUserName self.login_Password.text = string.isNilOrEmpty(tmpPassword) and "1" or tmpPassword self:ClickLogin() end --登录成功,进入服务器选择界面 function UILoginMain:OnAuthComplete() local tmpUserName = self.login_Username.text PersistentData.DeviceData:Set(MDL.Login.LoginConstKey.KEY_LOGIN_USERNAME,tmpUserName,true) if CTL.WinLogin.IsGameStreamerPackage() then PersistentData.DeviceData:Set(MDL.Login.LoginConstKey.KEY_LOGIN_PASSWORD, self.login_Password.text, true) end UIUtils.SetActive(self.group_Regist01,false) UIUtils.SetActive(self.group_Regist02,false) self:ShowEnterGameGroup() self:CheckCSTimeDiff() UIUtils.SetActive(self.btn_QrCode, MDL.WinLogin:IsShowScanButton()) UIUtils.SetActive(self.btn_RemoveAccountVN, UILoginMain.IsShowRemoveAccountVNBtn()) end function UILoginMain:ShowEnterGameGroup() UIUtils.SetActive(self.group_Login,true) if self.StateSwitch.CurState == 0 then UIUtils.SetLocalizationImage(self.img_Start, "loading_msz_ksyx.png") end end --获取服务器信息 function UILoginMain:GetCurShardInfo(shardId, shardName, shardState, shardVirtualDistrictId) self.CurShardInfo = MDL.Login.GetShardInfo(shardId, shardName, shardState, shardVirtualDistrictId) UIUtils.SetLabel(self.lab_ServerList,shardName) shardState = tonumber(shardState) if shardState == MDL.Login.ShardShowState.ShowState_Maintenance then self.UIState:SetState(1) else if shardState == MDL.Login.ShardShowState.ShowState_NewSer then self.UIState:SetState(2) elseif shardState == MDL.Login.ShardShowState.ShowState_Hot then self.UIState:SetState(0) elseif shardState == MDL.Login.ShardShowState.ShowState_Crowd then self.UIState:SetState(0) elseif shardState == MDL.Login.ShardShowState.ShowState_Fluent then self.UIState:SetState(2) else self.UIState:SetState(2) end end self:StartRepeatFunc(self.RefreshServerList, RefreshInterval) self.group_ServerState.gameObject:SetActive(true) if DEF.USE_BATCH_MODE then self:ClickStartGame() end end function UILoginMain:RefreshServerList() CTL.Login.RequestServerList() end function UILoginMain:OnButtonClicked(obj) if obj == self.btn_Announce then self:ClickNotice() elseif obj == self.btn_OpenURL then --跳转工信部网站 UnityEngine.Application.OpenURL("https://beian.miit.gov.cn/#/Integrated/index") elseif obj == self.btn_regist then self:ClickOpenRegist() elseif obj == self.btn_Login then self:ClickLogin() elseif obj == self.btn_backreg then self:ClickBack() elseif obj == self.btn_registreg then self:ClickRegistBtn() elseif obj == self.btn_Start or obj == self.btn_Start_Text then self:ClickStartGame() EventSystem.Dispatch(EventID.BI_ViewClick, BIManager.ViewBIEvent.UILoginMain_btn_Start) elseif obj == self.btn_ServerChange then self:ClickChangeServer() BIManager.DispatchBIClientEvent(BIManager.EventName.ClickSeverList) elseif obj== self.btn_Language then UIUtils.SetActive(self.group_language.gameObject, true) UIUtils.SetActive(self.btn_CloseLanguage.gameObject, true) self:ShowLanguages() elseif obj == self.btn_CloseLanguage then -- 关闭多语言弹窗 UIUtils.SetActive(self.group_language.gameObject, false) UIUtils.SetActive(self.btn_CloseLanguage.gameObject, false) elseif obj == self.btn_UserCenter then if not SDKUtil.IsLogging then if CTL.WinLogin.IsUsePCNtSdk() then SDKUtil.SwitchAccount() elseif GameAppInfo.IsPCPackageWithSdk() then CTL.WinLogin.SwitchAccount() else SDKUtil.SwitchAccount() end end elseif obj == self.btn_Log then if CTL.WinLogin.IsUsePCNtSdk() then SettingAPI.SetLogFilePause(true) CTL.Setting.UploadLog(CTL.Setting.UploadLogProblemType.CommonUpload, "") elseif GameAppInfo.IsPCPackageWithSdk() then CTL.WinLogin.UploadPCLogs("tk_logs", "log-*", 5) else if GameAppInfo.IsPCPackage() then SettingAPI.SetLogFilePause(true) end CTL.Setting.UploadLog(CTL.Setting.UploadLogProblemType.CommonUpload, "") end elseif obj == self.btn_Services then self:OpenService() elseif obj == self.btn_Fix then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_Login_Repair, Const_IDS.IDS_Login_RepairTips, UILoginMain.FixAssetBundles, nil, Const_IDS.IDS_Login_Repair) elseif obj == self.btn_AgePreference then UIManager.OpenView(Const_UI_Lua.UIEnum.UILoginRemind) elseif obj == self.btn_QrCode then SDKUtil.LaunchBarcodeScanner("") elseif obj == self.btn_UserAgreement then UnityEngine.Application.OpenURL(self:GetUserAgreementURL()) elseif obj == self.btn_RemoveAccountVN then if GameAppInfo.IsVietnamPackage() then SDKUtil.OpenDeleteAccountService("") end end end function UILoginMain:OpenLoginVideo() CTL.Login.ShowLoginMoviePanel(MDL.Login.LoginBGTypeCfgValue, MDL.Login.GetLoginShowPath()) end function UILoginMain.FixAssetBundles() logging.crit(LTAG.CRIT, "执行修复") --将pkgver删除,保证下次启动用包内环境,类似覆盖安装 LuaExt.FileDelete("pkgver") LuaExt.DirectoryDelete("AppDataExt", true) AuxUtil.FixAssetBundles("TKData/AssetBundles") end function UILoginMain:ClickOpenRegist() UIUtils.SetActive(self.group_Regist01,false) UIUtils.SetActive(self.group_Regist02,true) end function UILoginMain:ClickLogin() local tmpUserName = self.login_Username.text local tmpPassword = self.login_Password.text if NetManager.IsValidNet(true) then MDL.Login.AuthInfoRequest(tmpUserName,tmpPassword) end end --打开公告界面 function UILoginMain:ClickNotice() if not CTL.Login.IsClickNotice then CTL.Login.IsClickNotice = true CTL.Login.GetEntryAddress() end end --进入游戏 function UILoginMain:ClickStartGame() if tonumber(self.CurShardInfo._shardState) == MDL.Login.ShardShowState.ShowState_Maintenance and not CTL.Login.HasWhiteListBase64Input() then --当前服务器维护中 if self.CurShardInfo._shardId == "515065" then UTL.MessageBox.ShowOnlyOkBox("", "激战区65服由于异常原因即将关闭不再开放,请65服的将军前往新服进行游戏,以下是补偿方案\n补偿一:若您在激战区65服创建过角色,且在1月24日前前往后续新服创建角色,将通过邮件获得【特惠月卡】和【尊享月卡】\n补偿二:若您在激战区65服创建过角色并且进行了充值,且在1月24日前前往新服创建角色,除了可以获得补偿一,还将根据您在65服的充值额度,通过邮件返还相应的【充值积分】,并补偿3倍【龙玉】和3倍【元宝】(1元=1充值积分=10龙玉=10元宝)") else UTL.MessageBox.ShowOnlyOkBox("", UIUtils.GetLocalizedTxt(Const_IDS.IDS_SingleMaintain_TiShiXiangQing)) end BIManager.DispatchBIClientEvent(BIManager.EventName.ClickStartGameBtn, "ClickInfo", "Server Maintenance") return end if NetManager.IsValidNet(true) then --X秒内连接不上,可以重新点击 self:StartRepeatFunc(self.CloseWaitingDelay, 5, 1) MDL.Login.ClickStartGame(self.CurShardInfo) end if GameAppInfo.IsOpenRegion() then Localization.SaveRegion() end end function UILoginMain:CloseWaitingDelay() logging.crit(LTAG.CRIT, "ClickStartGame-CloseWaitingDelay") --连接之前先尝试清理一下socket,主要是处理握手失败的情况 LuaNetManager.Disconnect(-1, true) CTL.Login.OpenConnectingPanel(false) end function UILoginMain:ClickBack() UIUtils.SetActive(self.group_Regist01,true) UIUtils.SetActive(self.group_Regist02,false) end --注册账号 function UILoginMain:ClickRegistBtn() local tmpUserName = self.group_Username.text local tmpPassword = "1"--self.group_Password.text local tmpPasswordAgain = "1"--self.group_Reconfirm.text if tmpPassword~=tmpPasswordAgain then CTL.Tips.AddTipsMsg(Const_IDS.IDS_LoginSystem_Register_Tips4) elseif(MDL.Login.CheckUsername(tmpUserName) == false)then CTL.Tips.AddTipsMsg(Const_IDS.IDS_LoginSystem_Register_Tips2) elseif (MDL.Login.CheckPassword(tmpPassword) == false) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_LoginSystem_Register_Tips3) else if NetManager.IsValidNet(true) then MDL.Login.RegisterRequest(tmpUserName,tmpPassword) end end end function UILoginMain:ClickChangeServer() CTL.Login.OpenSelectServerPanel() end function UILoginMain:GetUserAgreementURL() local URL if Localization.IsChinese() then URL = "https://www.newtypegames.com/privacy?lang=zh" elseif Localization.IsTraditional() then URL = "https://www.newtypegames.com/privacy?lang=zh-hmt" else URL = "https://www.newtypegames.com/privacy?lang=en" end return URL end --选择服务器,刷新界面 function UILoginMain:RefreshLoginServerInfo(shardId, shardName, shardState, shardVirtualDistrictId) self:GetCurShardInfo(shardId, shardName, shardState, shardVirtualDistrictId) end --region -------------------------------- 刷新多语言 -------------------------- function UILoginMain:RefreshLanguageToggleView() local languageID = Localization.GetLanguage() UIUtils.SetLabelText(self.txt_Language, Const_IDS[Localization.GetLanguageIDS(languageID)]) UTL.Item.SetLocalizationImage(nil, self.img_Logo, "img_Logo.png") UIUtils.SetActive(self.group_language.gameObject, false) UIUtils.SetActive(self.btn_CloseLanguage.gameObject, false) end --endregion -------------------------------- 刷新多语言 -------------------------- function UILoginMain:OnCellClicked(scrollRect, index, cellTable, target, data) local language = Localization.GetLanguageByIndex(index + 1) if language ~= nil then CTL.Setting.SwitchLanguage(language) end end function UILoginMain:OnCellInit(scrollRect, index, cellTable, data) local languageID = Localization.GetLanguage() UIUtils.SetLabelText(cellTable.txt_Uncheck, Const_IDS[Localization.GetLanguageIDS(data)]) UIUtils.SetActive(cellTable.img_ChineseUncheck, Localization.GetLanguageIndex(data) ~= Localization.GetLanguageIndex(languageID)) UIUtils.SetActive(cellTable.img_ChineseChecked, Localization.GetLanguageIndex(data) == Localization.GetLanguageIndex(languageID)) end function UILoginMain:ShowLanguages() if self.loop_Language.Count == 0 then for i,v in ipairs( Localization.GetSwitchLanguages()) do self.loop_Language:AddData(v,0) end end end function UILoginMain:OpenService() if GameAppInfo.IsOverseaPackage() or GameAppInfo.IsJapanesePackage() or GameAppInfo.IsVietnamPackage() then SDKUtil.OpenService(CTL.Setting.GetUploadLogCustom(CTL.Setting.UploadLogProblemType.ClientService)) elseif GameAppInfo.IsChinesePackage() then if SDKUtil.ChannelID == LuaConst.SDKChannelId.Hero_Android or SDKUtil.ChannelID == LuaConst.SDKChannelId.Hero_iOS then SDKUtil.OpenPlatWebUrl("http://kf.yingxiong.com/v1/public/login/sdkLogin/game/2022?lang=zh", nil) else SDKUtil.OpenPlatWebUrl("http://kf.yingxiong.com/kf2.0/user-center?game_id=2022&lang=zh", nil) end end end function UILoginMain:IsShowServiceBtn() if GameAppInfo.IsPCPackage() and GameAppInfo.IsChinesePackage() then return false end if GameAppInfo.IsOverseaPackage() then return not MDL.Login.IsReviewService end if GameAppInfo.IsChinesePackage() or GameAppInfo.IsJapanesePackage() or GameAppInfo.IsVietnamPackage() then return CTL.Login.IsShowCustomerBtn() end return false end function UILoginMain:SetVN18LogoConfig() --越南版本开启 其他版本默认关闭 if not UNITY_EDITOR and GameAppInfo.IsVietnamPackage() then UIUtils.SetLocalizationImage(self.icon_VN_AgeLimit18, "icon_VN_AgeLimit18.png") UIUtils.SetActive(self.icon_VN_AgeLimit18, GameAppInfo.IsShowVietnam18Logo()) end end return UILoginMain