LoginView.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Login;
  4. using ET;
  5. using TapTap.Bootstrap;
  6. using System;
  7. using TapTap.Common;
  8. namespace GFGGame
  9. {
  10. public class LoginView : BaseView
  11. {
  12. private UI_LoginUI _ui;
  13. private GameObject _scenePrefab;
  14. private GameObject _sceneObject;
  15. public override void Dispose()
  16. {
  17. _ui = null;
  18. if (_sceneObject != null)
  19. {
  20. GameObject.Destroy(_sceneObject);
  21. _sceneObject = null;
  22. }
  23. if (_scenePrefab != null)
  24. {
  25. GFGAsset.Release(ResPathUtil.GetPrefabPath("SceneMain"));
  26. _scenePrefab = null;
  27. }
  28. base.Dispose();
  29. }
  30. protected override void Init()
  31. {
  32. base.Init();
  33. packageName = UI_LoginUI.PACKAGE_NAME;
  34. _ui = UI_LoginUI.Create();
  35. viewCom = _ui.target;
  36. isfullScreen = true;
  37. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneMain"));
  38. }
  39. protected override void OnInit()
  40. {
  41. base.OnInit();
  42. _ui.m_txtVersion.text = GameGlobal.version;
  43. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  44. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  45. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  46. _ui.m_btnAge.onClick.Add(OnClickBtnAge);
  47. _ui.m_btnTapLogin.onClick.Add(OnClickBtnTabLogin);
  48. _ui.m_imgLogo.visible = LauncherConfig.netType != LauncherConfig.EnumNetType.TEMP;
  49. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  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. }
  57. protected override void OnShown()
  58. {
  59. base.OnShown();
  60. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  61. if (_sceneObject == null)
  62. {
  63. _sceneObject = GameObject.Instantiate(_scenePrefab);
  64. }
  65. SceneController.UpdateLoginScene(_sceneObject);
  66. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  67. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  68. UpdateServer(recentlyServerInfo);
  69. _ui.m_btnStart.visible = false;
  70. _ui.m_btnTapLogin.visible = false;
  71. _ui.m_btnLogout.visible = false;
  72. InitLoginStatus(serverInfosComponent).Coroutine();
  73. }
  74. protected override void OnHide()
  75. {
  76. if (_sceneObject != null)
  77. {
  78. GameObject.Destroy(_sceneObject);
  79. _sceneObject = null;
  80. }
  81. base.OnHide();
  82. }
  83. protected override void RemoveEventListener()
  84. {
  85. base.RemoveEventListener();
  86. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  87. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  88. }
  89. private async ETTask InitLoginStatus(ServerInfosComponent serverInfosComponent)
  90. {
  91. if (PlatformManager.IsTaptap)//taptap平台
  92. {
  93. var success = await PlatformTapManager.Instance.LoginCache();
  94. _ui.m_btnTapLogin.visible = !success;
  95. }
  96. else//自有登录
  97. {
  98. _ui.m_btnStart.visible = true;
  99. //尝试自动登录
  100. if (serverInfosComponent.ServerInfoList.Count <= 0)
  101. {
  102. OnClickBtnStart();
  103. }
  104. }
  105. }
  106. private void OnClickBtnTabLogin()
  107. {
  108. OnClickBtnTabLoginAsync().Coroutine();
  109. }
  110. private async ETTask OnClickBtnTabLoginAsync()
  111. {
  112. var success = await PlatformTapManager.Instance.Login();
  113. _ui.m_btnTapLogin.visible = !success;
  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 OnLoginSuccess(EventContext context)
  128. {
  129. _ui.m_btnLogout.visible = true;
  130. _ui.m_btnStart.visible = true;
  131. }
  132. private void OnSeverChangeListener(EventContext context)
  133. {
  134. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  135. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  136. }
  137. private void OnBtnChangeClick()
  138. {
  139. ViewManager.Show<ServerListView>();
  140. }
  141. private void OnClickBtnNotice()
  142. {
  143. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  144. {
  145. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  146. return;
  147. }
  148. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  149. }
  150. private void OnClickBtnStart()
  151. {
  152. if (PlatformManager.IsTaptap)//taptap平台
  153. {
  154. LoginController.GetRoles().Coroutine();
  155. }
  156. else
  157. {
  158. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  159. if (serverInfosComponent.ServerInfoList.Count <= 0)
  160. {
  161. bool login = GameController.CheckLoginCache(true);
  162. if (!login)
  163. {
  164. ViewManager.Show<LoginInputView>();
  165. }
  166. }
  167. else
  168. {
  169. LoginController.GetRoles().Coroutine();
  170. }
  171. }
  172. }
  173. private void OnClickBtnLogout()
  174. {
  175. GameController.QuitToLoginView(true);
  176. }
  177. private void OnClickBtnAge()
  178. {
  179. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  180. }
  181. }
  182. }