LoginView.cs 7.7 KB

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