LoginView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. using System.Threading.Tasks;
  9. namespace GFGGame
  10. {
  11. public class LoginView : BaseView
  12. {
  13. private UI_LoginUI _ui;
  14. private GameObject _scenePrefab;
  15. private GameObject _sceneObject;
  16. public override void Dispose()
  17. {
  18. if (_sceneObject != null)
  19. {
  20. GameObject.DestroyImmediate(_sceneObject);
  21. _sceneObject = null;
  22. }
  23. if (_ui != null)
  24. {
  25. _ui.Dispose();
  26. _ui = 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("SceneLogin"));
  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(OnClickBtnStart);
  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. EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  57. EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  58. }
  59. protected override void OnShown()
  60. {
  61. base.OnShown();
  62. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  63. if (_sceneObject == null)
  64. {
  65. _sceneObject = GameObject.Instantiate(_scenePrefab);
  66. }
  67. SceneController.UpdateLoginScene(_sceneObject);
  68. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  69. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  70. UpdateServer(recentlyServerInfo);
  71. _ui.m_btnStart.visible = false;
  72. _ui.m_btnTapLogin.visible = false;
  73. _ui.m_btnLogout.visible = false;
  74. //初始化平台配置
  75. QDManager.InitPlatform();
  76. }
  77. protected override void OnHide()
  78. {
  79. if (_sceneObject != null)
  80. {
  81. GameObject.Destroy(_sceneObject);
  82. _sceneObject = null;
  83. }
  84. base.OnHide();
  85. }
  86. protected override void RemoveEventListener()
  87. {
  88. base.RemoveEventListener();
  89. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  90. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  91. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  92. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  93. }
  94. private void UpdateServer(ServerInfo info)
  95. {
  96. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  97. if (serverInfosComponent.ServerInfoList.Count == 0)
  98. {
  99. _ui.m_btnChange.visible = false;
  100. return;
  101. }
  102. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  103. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  104. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  105. }
  106. private void OnPlatformInitet(EventContext context)
  107. {
  108. ViewManager.Hide<ModalStatusView>();
  109. var success = (bool)context.data;
  110. Debug.Log($"InitPlatform success {success}");
  111. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  112. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  113. if (success)
  114. {
  115. //尝试自动登录
  116. OnClickBtnStart();
  117. }
  118. else
  119. {
  120. AlertSystem.Show("初始化平台sdk失败!")
  121. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  122. }
  123. }
  124. private void OnPlatformLogined(EventContext context)
  125. {
  126. var account = (string)context.data;
  127. if(!string.IsNullOrEmpty(account))
  128. {
  129. _ui.m_btnTapLogin.visible = false;
  130. if(QDManager.IsHYKB)
  131. {
  132. Timers.inst.Add(1, 1, (a) => { LoginController.LoginTest(account).Coroutine(); });
  133. }
  134. else
  135. {
  136. LoginController.LoginTest(account).Coroutine();
  137. }
  138. }
  139. else
  140. {
  141. ViewManager.Hide<ModalStatusView>();
  142. //尝试自动登录
  143. OnClickBtnStart();
  144. }
  145. }
  146. private void OnLoginSuccess(EventContext context)
  147. {
  148. _ui.m_btnLogout.visible = true;
  149. _ui.m_btnStart.visible = true;
  150. }
  151. private void OnSeverChangeListener(EventContext context)
  152. {
  153. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  154. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  155. }
  156. private void OnBtnChangeClick()
  157. {
  158. ViewManager.Show<ServerListView>();
  159. }
  160. private void OnClickBtnNotice()
  161. {
  162. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  163. {
  164. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  165. return;
  166. }
  167. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  168. }
  169. private void OnClickBtnStart()
  170. {
  171. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  172. if (serverInfosComponent.ServerInfoList.Count <= 0)
  173. {
  174. if (QDManager.IsTaptap)
  175. {
  176. QDTapTapManager.Instance.Login();
  177. }
  178. else if (QDManager.IsHYKB)
  179. {
  180. QDHYKBManager.Instance.Login();
  181. }
  182. else if(QDManager.IsBiliBili)
  183. {
  184. QDBiliBiliManager.Instance.Login();
  185. }
  186. else
  187. {
  188. bool login = GameController.CheckLoginCache(true);
  189. if (!login)
  190. {
  191. ViewManager.Show<LoginInputView>();
  192. }
  193. }
  194. }
  195. else
  196. {
  197. LoginController.GetRoles().Coroutine();
  198. }
  199. }
  200. private void OnClickBtnLogout()
  201. {
  202. GameController.QuitToLoginView(true);
  203. }
  204. private void OnClickBtnAge()
  205. {
  206. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  207. }
  208. }
  209. }