LoginView.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Login;
  4. using ET;
  5. using GFGGame.Launcher;
  6. using System;
  7. namespace GFGGame
  8. {
  9. public class LoginView : BaseView
  10. {
  11. private UI_LoginUI _ui;
  12. private GameObject _sceneObject;
  13. private bool autoLogined;
  14. public override void Dispose()
  15. {
  16. if (_sceneObject != null)
  17. {
  18. GameObject.DestroyImmediate(_sceneObject);
  19. _sceneObject = null;
  20. }
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void Init()
  29. {
  30. base.Init();
  31. packageName = UI_LoginUI.PACKAGE_NAME;
  32. _ui = UI_LoginUI.Create();
  33. viewCom = _ui.target;
  34. isfullScreen = true;
  35. }
  36. protected override void OnInit()
  37. {
  38. base.OnInit();
  39. _ui.m_txtVersion.text = GameGlobal.version;
  40. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  41. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  42. _ui.m_btnAge.onClick.Add(OnClickBtnAge);
  43. _ui.m_btnChange.visible = false;
  44. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  45. _ui.m_loaEventa.onClick.Add(() => { FullScreenTextController.Show("event:a"); });
  46. _ui.m_loaEventb.onClick.Add(() => { FullScreenTextController.Show("event:b"); });
  47. _ui.m_loaEventc.onClick.Add(() => { FullScreenTextController.Show("event:c"); });
  48. _ui.m_btnAgree.onClick.Add(OnBtnAgreeCklick);
  49. }
  50. protected override void AddEventListener()
  51. {
  52. base.AddEventListener();
  53. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  54. }
  55. protected override void OnShown()
  56. {
  57. base.OnShown();
  58. _ui.m_btnStart.visible = true;
  59. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  60. if (_sceneObject == null)
  61. {
  62. PrefabManager.Instance.InstantiateAsync(
  63. ResPathUtil.GetLoginResPath("LoginSkin1/SceneLogin"),
  64. (go) =>
  65. {
  66. _sceneObject = go;
  67. if (_sceneObject != null)
  68. {
  69. // 场景对象加载完成后的后续初始化
  70. ContinueAfterSceneLoad();
  71. }
  72. else
  73. {
  74. Debug.LogError("Failed to instantiate login scene");
  75. }
  76. });
  77. }
  78. else
  79. {
  80. // 如果场景对象已存在,直接继续初始化
  81. ContinueAfterSceneLoad();
  82. }
  83. }
  84. private void ContinueAfterSceneLoad()
  85. {
  86. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  87. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  88. UpdateServer(recentlyServerInfo);
  89. _ui.m_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false);
  90. _ui.m_btnAgree.selected = true;
  91. if (GameConfig.openTime > TimeHelper.ClientNow())
  92. {
  93. var date = DateTimeUtil.LongTimeStampToDateTime(GameConfig.openTime);
  94. string minuteText = "";
  95. if (date.Minute > 0)
  96. {
  97. minuteText = date.Minute + "分";
  98. }
  99. AlertUI.Show($" 亲爱的研究员,万世镜将于{date.Year}年{date.Month}月{date.Day}日{date.Hour}点{minuteText}开放,敬请期待!")
  100. .SetLeftButton(true, "好的", (obj) => { Application.Quit(); });
  101. return;
  102. }
  103. if (!autoLogined)
  104. {
  105. autoLogined = true;
  106. TryLogin();
  107. }
  108. }
  109. protected override void OnHide()
  110. {
  111. autoLogined = false;
  112. if (_sceneObject != null)
  113. {
  114. PrefabManager.Instance.Restore(_sceneObject);
  115. _sceneObject = null;
  116. }
  117. base.OnHide();
  118. }
  119. protected override void RemoveEventListener()
  120. {
  121. base.RemoveEventListener();
  122. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  123. }
  124. private void UpdateServer(ServerInfo info)
  125. {
  126. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  127. if (serverInfosComponent.ServerInfoList.Count == 0)
  128. {
  129. _ui.m_btnChange.visible = false;
  130. return;
  131. }
  132. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  133. _ui.m_btnChange.title =
  134. string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  135. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  136. }
  137. private void OnSeverChangeListener(EventContext context)
  138. {
  139. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  140. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  141. }
  142. private void OnBtnChangeClick()
  143. {
  144. ViewManager.Show<ServerListView>();
  145. }
  146. private void OnClickBtnNotice()
  147. {
  148. if (NoticeDataManager.Instance.LastNoticeInfo == null ||
  149. NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  150. {
  151. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  152. return;
  153. }
  154. ViewManager.Show<SystemNoticeView>(new object[]
  155. { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  156. }
  157. private void OnClickBtnStart()
  158. {
  159. TryLogin();
  160. }
  161. private void OnClickBtnAge()
  162. {
  163. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  164. }
  165. private void TryLogin()
  166. {
  167. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", LauncherConfig.cfgName);
  168. url = url + "?t=" + DateTime.Now.Ticks;
  169. HttpTool.Instance.Get(url, (string json) =>
  170. {
  171. LauncherConfig.InitPlatform(json);
  172. if (LauncherConfig.serverStatus == 1)
  173. {
  174. if (string.IsNullOrEmpty(LauncherConfig.statusPrompt))
  175. {
  176. LauncherConfig.statusPrompt = "游戏正在更新维护中,请稍后再试。";
  177. }
  178. AlertSystem.Show(LauncherConfig.statusPrompt)
  179. .SetLeftButton(true, "知道了", (data) => { Application.Quit(); });
  180. return;
  181. }
  182. if (!_ui.m_btnAgree.selected)
  183. {
  184. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  185. return;
  186. }
  187. LoginHelper.H5Login(GameGlobal.zoneScene, GameConfig.LoginAddress).Coroutine();
  188. });
  189. }
  190. private void OnBtnAgreeCklick()
  191. {
  192. LocalCache.SetBool(LauncherConfig.LAST_LOGIN_IS_AGREE_KEY, _ui.m_btnAgree.selected);
  193. }
  194. }
  195. }