LoginView.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. public override void Dispose()
  12. {
  13. if (_sceneObject != null)
  14. {
  15. GameObject.DestroyImmediate(_sceneObject);
  16. _sceneObject = null;
  17. }
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void Init()
  26. {
  27. base.Init();
  28. packageName = UI_LoginUI.PACKAGE_NAME;
  29. _ui = UI_LoginUI.Create();
  30. viewCom = _ui.target;
  31. isfullScreen = true;
  32. }
  33. protected override void OnInit()
  34. {
  35. base.OnInit();
  36. _ui.m_txtVersion.text = GameGlobal.version;
  37. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  38. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  39. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  40. _ui.m_btnAge.onClick.Add(OnClickBtnAge);
  41. _ui.m_btnTapLogin.onClick.Add(OnClickBtnStart);
  42. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  43. _ui.m_loaEventa.onClick.Add(() => { FullScreenTextController.Show("event:a"); });
  44. _ui.m_loaEventb.onClick.Add(() => { FullScreenTextController.Show("event:b"); });
  45. _ui.m_loaEventc.onClick.Add(() => { FullScreenTextController.Show("event:c"); });
  46. //_ui.m_btnAgree.onClick.Add(OnBtnAgreeCklick);
  47. }
  48. protected override void AddEventListener()
  49. {
  50. base.AddEventListener();
  51. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  52. EventAgent.AddEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  53. EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  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_btnStart.visible = false;
  69. _ui.m_btnTapLogin.visible = false;
  70. _ui.m_btnLogout.visible = false;
  71. //_ui.m_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_AGREE_KEY, false);
  72. _ui.m_btnAgree.selected = true;
  73. if(GameConfig.openTime > TimeHelper.ClientNow())
  74. {
  75. var date = DateTimeUtil.LongTimeStampToDateTime(GameConfig.openTime);
  76. string minuteText = "";
  77. if(date.Minute > 0)
  78. {
  79. minuteText = date.Minute + "分";
  80. }
  81. AlertUI.Show($" 亲爱的研究员,万世镜将于{date.Year}年{date.Month}月{date.Day}日{date.Hour}点{minuteText}开放,敬请期待!")
  82. .SetLeftButton(true, "好的", (obj) =>
  83. {
  84. Application.Quit();
  85. });
  86. return;
  87. }
  88. if (QDManager.isInited)
  89. {
  90. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
  91. }
  92. else
  93. {
  94. //初始化平台配置
  95. QDManager.InitPlatform();
  96. }
  97. }
  98. protected override void OnHide()
  99. {
  100. if (_sceneObject != null)
  101. {
  102. PrefabManager.Instance.Restore(_sceneObject);
  103. _sceneObject = null;
  104. }
  105. base.OnHide();
  106. }
  107. protected override void RemoveEventListener()
  108. {
  109. base.RemoveEventListener();
  110. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  111. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  112. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  113. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  114. }
  115. private void UpdateServer(ServerInfo info)
  116. {
  117. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  118. if (serverInfosComponent.ServerInfoList.Count == 0)
  119. {
  120. _ui.m_btnChange.visible = false;
  121. return;
  122. }
  123. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  124. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  125. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  126. }
  127. private void OnPlatformInitet(EventContext context)
  128. {
  129. ViewManager.Hide<ModalStatusView>();
  130. var success = (bool)context.data;
  131. Debug.Log($"InitPlatform success {success}");
  132. if (success)
  133. {
  134. QDManager.isInited = true;
  135. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  136. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  137. //尝试自动登录
  138. TryLogin();
  139. }
  140. else
  141. {
  142. AlertSystem.Show("初始化平台sdk失败!")
  143. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  144. }
  145. }
  146. private void OnPlatformLogined(EventContext context)
  147. {
  148. var account = (string)context.data;
  149. if (!string.IsNullOrEmpty(account))
  150. {
  151. _ui.m_btnTapLogin.visible = false;
  152. LoginController.LoginTest(account).Coroutine();
  153. }
  154. else
  155. {
  156. ViewManager.Hide<ModalStatusView>();
  157. //尝试自动登录
  158. TryLogin();
  159. }
  160. }
  161. private void OnLoginSuccess(EventContext context)
  162. {
  163. _ui.m_btnLogout.visible = true;
  164. _ui.m_btnStart.visible = true;
  165. }
  166. private void OnSeverChangeListener(EventContext context)
  167. {
  168. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  169. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  170. }
  171. private void OnBtnChangeClick()
  172. {
  173. ViewManager.Show<ServerListView>();
  174. }
  175. private void OnClickBtnNotice()
  176. {
  177. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  178. {
  179. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  180. return;
  181. }
  182. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  183. }
  184. private void OnClickBtnStart()
  185. {
  186. TryLogin();
  187. }
  188. private void OnClickBtnLogout()
  189. {
  190. GameController.QuitToLoginView(true);
  191. }
  192. private void OnClickBtnAge()
  193. {
  194. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  195. }
  196. private void TryLogin()
  197. {
  198. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  199. if (serverInfosComponent.ServerInfoList.Count <= 0)
  200. {
  201. QDManager.Login();
  202. }
  203. else
  204. {
  205. if (!_ui.m_btnAgree.selected)
  206. {
  207. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  208. return;
  209. }
  210. LoginController.GetRoles().Coroutine();
  211. }
  212. }
  213. }
  214. }