using UnityEngine; using FairyGUI; using UI.Login; using ET; using GFGGame.Launcher; using System; using SimpleJSON; namespace GFGGame { public class LoginView : BaseView { private UI_LoginUI _ui; private GameObject _sceneObject; private bool autoLogined; public override void Dispose() { if (_sceneObject != null) { GameObject.DestroyImmediate(_sceneObject); _sceneObject = null; } if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void Init() { base.Init(); packageName = UI_LoginUI.PACKAGE_NAME; _ui = UI_LoginUI.Create(); viewCom = _ui.target; isfullScreen = true; } protected override void OnInit() { base.OnInit(); _ui.m_txtVersion.text = GameGlobal.version; _ui.m_btnNotice.onClick.Add(OnClickBtnNotice); _ui.m_btnStart.onClick.Add(OnClickBtnStart); _ui.m_btnAge.onClick.Add(OnClickBtnAge); _ui.m_btnChange.visible = false; _ui.m_btnChange.onClick.Add(OnBtnChangeClick); _ui.m_loaEventa.onClick.Add(() => { FullScreenTextController.Show("event:a"); }); _ui.m_loaEventb.onClick.Add(() => { FullScreenTextController.Show("event:b"); }); _ui.m_loaEventc.onClick.Add(() => { FullScreenTextController.Show("event:c"); }); _ui.m_btnAgree.onClick.Add(OnBtnAgreeCklick); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener); } protected override void OnShown() { base.OnShown(); _ui.m_btnStart.visible = false; _ui.m_btnStart.text = "登录中..."; MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT)); if (_sceneObject == null) { PrefabManager.Instance.InstantiateAsync( ResPathUtil.GetLoginResPath("LoginSkin1/SceneLogin"), (go) => { _sceneObject = go; if (_sceneObject != null) { // 场景对象加载完成后的后续初始化 ContinueAfterSceneLoad(); } else { Debug.LogError("Failed to instantiate login scene"); } }); } else { // 如果场景对象已存在,直接继续初始化 ContinueAfterSceneLoad(); } } private void ContinueAfterSceneLoad() { _ui.m_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false); _ui.m_btnAgree.selected = true; if (GameConfig.openTime > TimeHelper.ClientNow()) { var date = DateTimeUtil.LongTimeStampToDateTime(GameConfig.openTime); string minuteText = ""; if (date.Minute > 0) { minuteText = date.Minute + "分"; } _ui.m_btnStart.text = ""; AlertUI.Show($" 亲爱的研究员,万世镜将于{date.Year}年{date.Month}月{date.Day}日{date.Hour}点{minuteText}开放,敬请期待!") .SetLeftButton(true, "好的", (obj) => { Application.Quit(); }); return; } if (!autoLogined) { autoLogined = true; TryLogin(a => { ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent(); ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo; UpdateServer(recentlyServerInfo); }); } } protected override void OnHide() { autoLogined = false; if (_sceneObject != null) { PrefabManager.Instance.Restore(_sceneObject); _sceneObject = null; } base.OnHide(); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener); } private void UpdateServer(ServerInfo info) { ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent(); if (serverInfosComponent.ServerInfoList.Count == 0) { _ui.m_btnChange.visible = false; return; } _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1; _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName); LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer); } private void OnSeverChangeListener(EventContext context) { ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent(); UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]); } private void OnBtnChangeClick() { ViewManager.Show(); } private void OnClickBtnNotice() { if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无公告发布"); return; } ViewManager.Show(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content }); } private void OnClickBtnStart() { LoginController.GetRoles().Coroutine(); } private void OnClickBtnAge() { ViewManager.Show(new object[] { LoginController.ageTipsTitle, LoginController.ageTips }); } private void TryLogin(Action action) { var url = LauncherConfig.cfgUrl.Replace("{cfgName}", LauncherConfig.cfgName); Debug.Log($"TryLogin, {url}"); url = url + "?t=" + DateTime.Now.Ticks; //HttpTool.Instance.Get(url, json => //{ // LauncherConfig.InitPlatform(json); // if (LauncherConfig.serverStatus == 1) // { // if (string.IsNullOrEmpty(LauncherConfig.statusPrompt)) // { // _ui.m_btnStart.text = "维护中"; // LauncherConfig.statusPrompt = "游戏正在更新维护中,请稍后再试。"; // } // AlertSystem.Show(LauncherConfig.statusPrompt) // .SetLeftButton(true, "知道了", (data) => { Application.Quit(); }); // return; // } // if (!_ui.m_btnAgree.selected) // { // PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策"); // return; // } // LoginHelper.H5Login(GameGlobal.zoneScene, GameConfig.LoginAddress, // error => // { // LoginController.OnLoginSuccess(action).Coroutine(); // _ui.m_btnStart.visible = true; // _ui.m_btnStart.text = "开始游戏"; // }).Coroutine(); //}); //-------------------测试-------- string data = "{\"loginApiUrl\":\"129.204.4.238:11005\",\"platformName\":\"\",\"showGM\":\"1\",\"tsStatus\":\"0\",\"openTime\":\"[2024][6][19][05:00:00]\",\"tsServer\":\"1\"}"; LauncherConfig.InitPlatform(data); if (LauncherConfig.serverStatus == 1) { if (string.IsNullOrEmpty(LauncherConfig.statusPrompt)) { _ui.m_btnStart.text = "维护中"; LauncherConfig.statusPrompt = "游戏正在更新维护中,请稍后再试。"; } AlertSystem.Show(LauncherConfig.statusPrompt) .SetLeftButton(true, "知道了", (data) => { Application.Quit(); }); return; } if (!_ui.m_btnAgree.selected) { PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策"); return; } LoginHelper.H5Login(GameGlobal.zoneScene, GameConfig.LoginAddress, error => { LoginController.OnLoginSuccess(action).Coroutine(); _ui.m_btnStart.visible = true; _ui.m_btnStart.text = "开始游戏"; }).Coroutine(); } private void OnBtnAgreeCklick() { LocalCache.SetBool(LauncherConfig.LAST_LOGIN_IS_AGREE_KEY, _ui.m_btnAgree.selected); } } }