LoginView.cs 6.8 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. if (_sceneObject != null)
  18. {
  19. GameObject.Destroy(_sceneObject);
  20. _sceneObject = null;
  21. }
  22. if (_ui != null)
  23. {
  24. _ui.Dispose();
  25. _ui = null;
  26. }
  27. base.Dispose();
  28. }
  29. protected override void Init()
  30. {
  31. base.Init();
  32. packageName = UI_LoginUI.PACKAGE_NAME;
  33. _ui = UI_LoginUI.Create();
  34. viewCom = _ui.target;
  35. isfullScreen = true;
  36. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneMain"));
  37. }
  38. protected override void OnInit()
  39. {
  40. base.OnInit();
  41. _ui.m_txtVersion.text = GameGlobal.version;
  42. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  43. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  44. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  45. _ui.m_btnAge.onClick.Add(OnClickBtnAge);
  46. _ui.m_btnTapLogin.onClick.Add(OnClickBtnTabLogin);
  47. _ui.m_imgLogo.visible = LauncherConfig.netType != LauncherConfig.EnumNetType.TEMP;
  48. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  49. }
  50. protected override void AddEventListener()
  51. {
  52. base.AddEventListener();
  53. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  54. EventAgent.AddEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  55. }
  56. protected override void OnShown()
  57. {
  58. base.OnShown();
  59. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  60. if (_sceneObject == null)
  61. {
  62. _sceneObject = GameObject.Instantiate(_scenePrefab);
  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. InitLoginStatus(serverInfosComponent).Coroutine();
  72. }
  73. protected override void OnHide()
  74. {
  75. if (_sceneObject != null)
  76. {
  77. GameObject.Destroy(_sceneObject);
  78. _sceneObject = null;
  79. }
  80. base.OnHide();
  81. }
  82. protected override void RemoveEventListener()
  83. {
  84. base.RemoveEventListener();
  85. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  86. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  87. }
  88. private async ETTask InitLoginStatus(ServerInfosComponent serverInfosComponent)
  89. {
  90. if (PlatformManager.IsTaptap)//taptap平台
  91. {
  92. var success = await PlatformTapManager.Instance.LoginCache();
  93. _ui.m_btnTapLogin.visible = !success;
  94. }
  95. else//自有登录
  96. {
  97. _ui.m_btnStart.visible = true;
  98. //尝试自动登录
  99. if (serverInfosComponent.ServerInfoList.Count <= 0)
  100. {
  101. OnClickBtnStart();
  102. }
  103. }
  104. }
  105. private void OnClickBtnTabLogin()
  106. {
  107. OnClickBtnTabLoginAsync().Coroutine();
  108. }
  109. private async ETTask OnClickBtnTabLoginAsync()
  110. {
  111. var success = await PlatformTapManager.Instance.Login();
  112. _ui.m_btnTapLogin.visible = !success;
  113. }
  114. private void UpdateServer(ServerInfo info)
  115. {
  116. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  117. if (serverInfosComponent.ServerInfoList.Count == 0)
  118. {
  119. _ui.m_btnChange.visible = false;
  120. return;
  121. }
  122. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  123. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  124. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  125. }
  126. private void OnLoginSuccess(EventContext context)
  127. {
  128. _ui.m_btnLogout.visible = true;
  129. _ui.m_btnStart.visible = true;
  130. }
  131. private void OnSeverChangeListener(EventContext context)
  132. {
  133. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  134. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  135. }
  136. private void OnBtnChangeClick()
  137. {
  138. ViewManager.Show<ServerListView>();
  139. }
  140. private void OnClickBtnNotice()
  141. {
  142. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  143. {
  144. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  145. return;
  146. }
  147. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  148. }
  149. private void OnClickBtnStart()
  150. {
  151. if (PlatformManager.IsTaptap)//taptap平台
  152. {
  153. LoginController.GetRoles().Coroutine();
  154. }
  155. else
  156. {
  157. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  158. if (serverInfosComponent.ServerInfoList.Count <= 0)
  159. {
  160. bool login = GameController.CheckLoginCache(true);
  161. if (!login)
  162. {
  163. ViewManager.Show<LoginInputView>();
  164. }
  165. }
  166. else
  167. {
  168. LoginController.GetRoles().Coroutine();
  169. }
  170. }
  171. }
  172. private void OnClickBtnLogout()
  173. {
  174. GameController.QuitToLoginView(true);
  175. }
  176. private void OnClickBtnAge()
  177. {
  178. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  179. }
  180. }
  181. }