LoginView.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_AGREE_KEY, false);
  69. _ui.m_btnAgree.selected = true;
  70. if(GameConfig.openTime > TimeHelper.ClientNow())
  71. {
  72. var date = DateTimeUtil.LongTimeStampToDateTime(GameConfig.openTime);
  73. string minuteText = "";
  74. if(date.Minute > 0)
  75. {
  76. minuteText = date.Minute + "分";
  77. }
  78. AlertUI.Show($" 亲爱的研究员,万世镜将于{date.Year}年{date.Month}月{date.Day}日{date.Hour}点{minuteText}开放,敬请期待!")
  79. .SetLeftButton(true, "好的", (obj) =>
  80. {
  81. Application.Quit();
  82. });
  83. return;
  84. }
  85. if (!autoLogined)
  86. {
  87. autoLogined = true;
  88. ResetLoginButton();
  89. TryLogin();
  90. }
  91. }
  92. protected override void OnHide()
  93. {
  94. autoLogined = false;
  95. if (_sceneObject != null)
  96. {
  97. PrefabManager.Instance.Restore(_sceneObject);
  98. _sceneObject = null;
  99. }
  100. base.OnHide();
  101. }
  102. protected override void RemoveEventListener()
  103. {
  104. base.RemoveEventListener();
  105. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  106. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  107. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  108. }
  109. private void UpdateServer(ServerInfo info)
  110. {
  111. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  112. if (serverInfosComponent.ServerInfoList.Count == 0)
  113. {
  114. _ui.m_btnChange.visible = false;
  115. return;
  116. }
  117. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  118. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  119. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  120. }
  121. private void OnPlatformLogined(EventContext context)
  122. {
  123. var account = (string)context.data;
  124. if (!string.IsNullOrEmpty(account))
  125. {
  126. _ui.m_btnTapLogin.visible = false;
  127. LoginController.LoginTest(account).Coroutine();
  128. }
  129. else
  130. {
  131. ViewManager.Hide<ModalStatusView>();
  132. //尝试自动登录
  133. TryLogin();
  134. }
  135. }
  136. private void OnLoginSuccess(EventContext context)
  137. {
  138. _ui.m_btnLogout.visible = true;
  139. _ui.m_btnStart.visible = true;
  140. }
  141. private void OnSeverChangeListener(EventContext context)
  142. {
  143. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  144. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  145. }
  146. private void OnBtnChangeClick()
  147. {
  148. ViewManager.Show<ServerListView>();
  149. }
  150. private void OnClickBtnNotice()
  151. {
  152. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  153. {
  154. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  155. return;
  156. }
  157. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  158. }
  159. private void OnClickBtnStart()
  160. {
  161. TryLogin();
  162. }
  163. private void OnClickBtnLogout()
  164. {
  165. ResetLoginButton();
  166. QDManager.Logout(false);
  167. }
  168. private void OnClickBtnAge()
  169. {
  170. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  171. }
  172. private void TryLogin()
  173. {
  174. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  175. if (serverInfosComponent.ServerInfoList.Count <= 0)
  176. {
  177. QDManager.Login();
  178. }
  179. else
  180. {
  181. if (!_ui.m_btnAgree.selected)
  182. {
  183. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  184. return;
  185. }
  186. LoginController.GetRoles().Coroutine();
  187. }
  188. }
  189. private void ResetLoginButton()
  190. {
  191. _ui.m_btnLogout.visible = false;
  192. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  193. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  194. }
  195. }
  196. }