LoginView.cs 7.6 KB

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