| using System; | 
| using System.Collections; | 
| using System.Collections.Generic; | 
| using System.Diagnostics.Tracing; | 
| using UnityEngine; | 
| using UnityEngine.UI; | 
| using System.IO; | 
|   | 
| public class LoginWin : UIBase, ICanvasRaycastFilter | 
| { | 
|     public static bool firstOpenEnd  | 
|     { | 
|         get; | 
|         private set; | 
|     } | 
|   | 
|     private string m_ServerIP = "mobile.173on.com"; | 
|     private int m_Port = 9090; | 
|     private int m_GamePort = 19006; | 
|   | 
|   | 
|     [SerializeField] Image m_Logo; | 
|     // [SerializeField] UIAlphaTween m_AlphaTween; | 
|     [SerializeField] RectTransform m_WaitServerList; | 
|     [SerializeField] RectTransform m_ContainerEnterGame; | 
|     [SerializeField] RectTransform m_ContainerAccount; | 
|     [SerializeField] Image m_ServerState; | 
|     [SerializeField] Text m_ServerStateDescription; | 
|     [SerializeField] Text m_ServerName; | 
|     [SerializeField] protected InputField m_Account; | 
|     [SerializeField] Button m_EnterGame; | 
|     //[SerializeField] Button m_QQLogin; | 
|     //[SerializeField] Button m_WXLogin; | 
|     [SerializeField] Button m_ServerSelect; | 
|     [SerializeField] Button m_SwitchAccount; | 
|     [SerializeField] Button m_Notice; | 
|     //[SerializeField] Button m_UserHelp; | 
|     [SerializeField] Button m_CleanCache; | 
|     [SerializeField] Toggle checkRead; | 
|     [SerializeField] Button serverRead; | 
|     [SerializeField] Button hideRead; | 
|     [SerializeField] Button ageWarn; | 
|     [SerializeField] Text verInfo; | 
|   | 
|     protected override void InitComponent() | 
|     { | 
|         base.InitComponent(); | 
|         Debug.Log("初始化登录窗口"); | 
|   | 
| #if UNITY_EDITOR | 
|         m_Account.onEndEdit.AddListener(x => { EnterGame(); }); | 
| #endif | 
|         m_EnterGame.SetListener(EnterGame); | 
|         //m_QQLogin.SetListener(QQLogin); | 
|         //m_WXLogin.SetListener(WXLogin); | 
|         m_ServerSelect.SetListener(OpenServerListWin); | 
|         m_SwitchAccount.SetListener(SwitchAccount); | 
|         m_Notice.SetListener(VeiwNotice); | 
|         //if (m_UserHelp) | 
|         //{ | 
|         //    m_UserHelp.SetListener(OpenUserHelp); | 
|         //} | 
|   | 
|         m_CleanCache.SetListener(CleanCache); | 
|   | 
|         serverRead.SetListener(() => { | 
|             GameAgeWarnWin.data = 1; | 
|             UIManager.Instance.OpenWindow<GameAgeWarnWin>(); | 
|         }); | 
|   | 
|         hideRead.SetListener(() => { | 
|             GameAgeWarnWin.data = 2; | 
|             UIManager.Instance.OpenWindow<GameAgeWarnWin>(); | 
|         }); | 
|         ageWarn.SetListener(() => { | 
|             GameAgeWarnWin.data = 3; | 
|             UIManager.Instance.OpenWindow<GameAgeWarnWin>(); | 
|         }); | 
|     } | 
|   | 
|     protected override void OnPreOpen() | 
|     { | 
|         base.OnPreOpen(); | 
|         Debug.Log("打开登录窗口"); | 
|   | 
|   | 
|         ServerListCenter.Instance.serverSelectEvent += OnServerChange; | 
|         ServerListCenter.Instance.onServerListRefreshEvent += OnServerListRefresh; | 
|   | 
|         ServerListCenter.Instance.RequestPlayerServerList(); | 
|         LoginManager.Instance.isLogined = false; | 
|         ServerListCenter.Instance.FiltrateDefaultServerAndServerGroup(); | 
|         // m_AlphaTween.SetStartState(); | 
|   | 
|         Refresh(); | 
|   | 
|         // m_AlphaTween.Play(() => {  | 
|         //     firstOpenEnd = true; | 
|         //     InGameDownLoad.Instance.downLoadGo = false; | 
|         //     DownloadMgr.MaxDownLoadTask = InGameDownLoad.Instance.GetMaxTask(); | 
|         // }); | 
|         AutoFightModel.Instance.isAutoAttack = false; | 
|         AutoFightModel.Instance.isPause = false; | 
|   | 
|     } | 
|   | 
|     protected override void OnOpenAnimationComplete() | 
|     { | 
|         base.OnOpenAnimationComplete(); | 
|   | 
|         firstOpenEnd = true; | 
|         InGameDownLoad.Instance.downLoadGo = false; | 
|         DownloadHotMgr.MaxDownLoadTask = InGameDownLoad.Instance.GetMaxTask(); | 
|     } | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         base.OnPreClose(); | 
|         Debug.Log("关闭登录窗口"); | 
|         ServerListCenter.Instance.serverSelectEvent -= OnServerChange; | 
|         ServerListCenter.Instance.onServerListRefreshEvent -= OnServerListRefresh; | 
|   | 
|         SDKUtils.Instance.onFreePlatformLoginOk -= OnLoginOk; | 
|         SDKUtils.Instance.SendShowFloatWin(); | 
|     } | 
|   | 
|     public override void Refresh() | 
|     { | 
|         base.Refresh(); | 
|         Debug.Log("刷新登录窗口"); | 
|   | 
|         //打包版本 + 功能版本 + 语言ID | 
|         verInfo.text = LoginManager.Instance.GetVersionStr(); | 
|   | 
|         var sprite = BuiltInLoader.LoadSprite("TB_DL_Logo"); | 
|         m_Logo.overrideSprite = sprite; | 
|         m_Logo.SetNativeSize(); | 
|         m_Logo.rectTransform.anchoredPosition = VersionConfig.Get().logoPosition; | 
|         m_Notice.SetActive(GameNotice.HasNotice()); | 
|   | 
|   | 
|         bool hasNotice = GameNotice.HasNotice(); | 
|   | 
|         //  账号切换 | 
|         m_SwitchAccount.SetActive(false); | 
|         //  用户帮助 | 
|         // TODO YYL | 
|         var appId = VersionConfig.Get().appId; | 
|         var branch = VersionConfig.Get().branch; | 
|         // m_UserHelp.SetActive(ContactConfig.GetConfig(appId, branch) != null); | 
|   | 
|         //  是否已经获取到服务器列表 | 
|         bool isGetServerList = ServerListCenter.Instance.serverListGot; | 
|         m_WaitServerList.SetActive(!isGetServerList); | 
|   | 
|         m_ContainerEnterGame.SetActive(isGetServerList); | 
|         m_ContainerAccount.SetActive(isGetServerList | 
|             && (VersionConfig.Get().versionAuthority == VersionAuthority.InterTest || VersionConfig.Get().isBanShu)); | 
|         m_EnterGame.SetActive(isGetServerList); | 
|   | 
|         if (isGetServerList) | 
|         { | 
|             ChangeServerInfo(ServerListCenter.Instance.currentServer); | 
|         } | 
|   | 
|   | 
|         ChangeUserInfo(LoginManager.Instance.localSaveAccountName); | 
|   | 
|         m_EnterGame.SetActive(true); | 
|         //m_QQLogin.SetActive(false); | 
|         //m_WXLogin.SetActive(false); | 
|   | 
|         // 用户协议 todo | 
|         checkRead.isOn = LocalSave.GetBool("tqsecretToggle"); | 
|     } | 
|   | 
|     private void OnLoginOk(SDKUtils.FP_LoginOk arg0) | 
|     { | 
|     } | 
|   | 
|     private void OnServerChange() | 
|     { | 
|         ChangeServerInfo(ServerListCenter.Instance.currentServer); | 
|     } | 
|   | 
|     // private void OnLoginBtnClick() | 
|     // { | 
|     //     //  TODO 登录 | 
|     //     Debug.Log("登录" + username.text + " / " + password.text); | 
|     //     CloseWindow(); | 
|   | 
|     //     StageManager.Instance.ToGameScene(); | 
|     // } | 
|   | 
|     private void ChangeServerInfo(ServerData _serverData) | 
|     { | 
|         m_ServerName.text = _serverData.name.Replace("@gm", ""); | 
|         m_ServerIP = _serverData.region_domain; | 
|         m_Port = _serverData.login_port; | 
|         m_GamePort = _serverData.game_port; | 
|   | 
|         switch ((ServerState)_serverData.running_status) | 
|         { | 
|             case ServerState.Maintain: | 
|             case ServerState.Predicted: | 
|                 m_ServerState.SetSprite("XT_FWQ_TB4"); | 
|                 m_ServerStateDescription.text = Language.GetFromLocal(29); | 
|                 break; | 
|             case ServerState.Normal: | 
|                 m_ServerState.SetSprite("XT_FWQ_TB2"); | 
|                 m_ServerStateDescription.text = Language.GetFromLocal(28); | 
|                 break; | 
|             case ServerState.Busy: | 
|                 m_ServerState.SetSprite("XT_FWQ_TB3"); | 
|                 m_ServerStateDescription.text = Language.GetFromLocal(27); | 
|                 break; | 
|             case ServerState.Hot: | 
|                 m_ServerState.SetSprite("XT_FWQ_TB1"); | 
|                 m_ServerStateDescription.text = Language.GetFromLocal(26); | 
|                 break; | 
|         } | 
|     } | 
|   | 
|     private void ChangeUserInfo(string user) | 
|     { | 
|         m_Account.text = user; | 
|     } | 
|   | 
|     private void OnServerListRefresh() | 
|     { | 
|         m_WaitServerList.SetActive(!ServerListCenter.Instance.serverListGot); | 
|         m_ContainerEnterGame.SetActive(ServerListCenter.Instance.serverListGot); | 
|         m_ContainerAccount.SetActive(ServerListCenter.Instance.serverListGot | 
|             && (VersionConfig.Get().versionAuthority == VersionAuthority.InterTest || VersionConfig.Get().isBanShu)); | 
|     } | 
|   | 
|     protected virtual void EnterGame() | 
|     { | 
|         if (!checkRead.isOn) | 
|         { | 
|             ConfirmCancel.ShowPopConfirm(Language.Get("agreementTitle"), Language.Get("agreementInfo")); | 
|             LocalSave.SetBool("tqsecretToggle", false); //方便测试 | 
|             return; | 
|         } | 
|   | 
|         LocalSave.SetBool("tqsecretToggle", true); | 
|   | 
|         SDKUtils.Instance.SendHideFloatWin(); | 
|   | 
|         Login(); | 
|   | 
|         //到这里一定是下载表结束 | 
|         InGameDownLoad.Instance.SetDownloadMark(); | 
|     } | 
|   | 
|     protected void LateUpdate() | 
|     { | 
|         raycastTarget = true; | 
|         LoginManager.Instance.RequestServerListLoop(); | 
|     } | 
|   | 
|   | 
|     private void OpenServerListWin() | 
|     { | 
|         UIManager.Instance.OpenWindow<ServerListWin>(); | 
|     } | 
|   | 
|     private void SwitchAccount() | 
|     { | 
|         SDKUtils.Instance.FreePlatformLoginout(); | 
|         LoginManager.Instance.sdkLogined = true; | 
|     } | 
|   | 
|     private void VeiwNotice() | 
|     { | 
|         GameNotice.OpenGameNoticeForce(); | 
|     } | 
|   | 
|     //private void OpenUserHelp() | 
|     //{ | 
|     //    //  TODO YYL | 
|     //    // UIManager.Instance.OpenWindow<UserHelpWin>(); | 
|     //} | 
|   | 
|     protected void Login() | 
|     { | 
|         var allow = false; | 
|         if (DebugUtility.Instance.isWhiteListAccount) | 
|         { | 
|             allow = true; | 
|         } | 
|         else | 
|         { | 
|             if (ServerListCenter.Instance.currentServer.running_status == (int)ServerState.Maintain | 
|                 || ServerListCenter.Instance.currentServer.running_status == (int)ServerState.Predicted) | 
|             { | 
|                 allow = false; | 
|             } | 
|             else | 
|             { | 
|                 allow = true; | 
|             } | 
|         } | 
|   | 
|         if (!allow) | 
|         { | 
|             switch ((ServerState)ServerListCenter.Instance.currentServer.running_status) | 
|             { | 
|                 case ServerState.Maintain: | 
|                     SysNotifyMgr.Instance.ShowTip("ServerDown"); | 
|                     break; | 
|                 case ServerState.Predicted: | 
|                     SysNotifyMgr.Instance.ShowTip("ServerOpen", ServerListCenter.Instance.currentServer.start_date.ToString("yyyy-MM-dd HH:mm")); | 
|                     break; | 
|             } | 
|   | 
|             return; | 
|         } | 
|   | 
|         if (GameNetSystem.Instance.netState == GameNetSystem.NetState.NerverConnect) | 
|         { | 
|             switch (VersionConfig.Get().versionAuthority) | 
|             { | 
|                 case VersionAuthority.InterTest: | 
|                     if (string.IsNullOrEmpty(m_Account.text)) | 
|                     { | 
|                         ServerTipDetails.DisplayNormalTip(Language.Get("L1095")); | 
|                         return; | 
|                     } | 
|   | 
|                     LoginManager.Instance.AccountLogin(m_Account.text, m_ServerIP, m_Port, m_GamePort); | 
|                     break; | 
|                 case VersionAuthority.Release: | 
|                     LoginManager.Instance.AccountLogin(m_ServerIP, m_Port, m_GamePort); | 
|                     break; | 
|             } | 
|   | 
|             //  TODO YYL | 
|             // OperationLogCollect.Instance.RecordLauchEvent(6); | 
|             // OperationLogCollect.Instance.RecordEvent(7); | 
|         } | 
|   | 
|     } | 
|   | 
|   | 
|     public void CleanCache() | 
|     { | 
|         ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), | 
|         Language.Get("CleanCache2"), (bool isOk) => | 
|         { | 
|             if (isOk) | 
|             { | 
|                 try | 
|                 { | 
|                     LocalSave.DeleteAll(); | 
|                     // 获取persistentDataPath下的所有文件和文件夹   | 
|                     string[] files = Directory.GetFiles(ResourcesPath.Instance.ExternalStorePath); | 
|                     string[] dirs = Directory.GetDirectories(ResourcesPath.Instance.ExternalStorePath); | 
|   | 
|                     // 删除所有文件   | 
|                     foreach (string file in files) | 
|                     { | 
|                         File.Delete(file); | 
|                     } | 
|   | 
|   | 
|                     // 递归删除所有文件夹   | 
|                     foreach (string dir in dirs) | 
|                     { | 
|                         Directory.Delete(dir, true); | 
|                     } | 
|   | 
|                 } | 
|                 catch (System.Exception e) | 
|                 { | 
|                     Debug.LogError("Failed to clean persistent data: " + e.Message); | 
|                 } | 
|                 finally | 
|                 { | 
|                     Clock.AlarmAfter(0.1f, () => | 
|                     { | 
|                         Application.Quit(); | 
|                     }); | 
|                     Debug.Log("Persistent data cleaned."); | 
|                 } | 
|   | 
|             } | 
|         }); | 
|   | 
|          | 
|     } | 
| } |