LoginView.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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("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(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. var success = (bool)context.data;
  109. Debug.Log($"InitPlatform success {success}");
  110. if (success)
  111. {
  112. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  113. //尝试自动登录
  114. OnClickBtnStart();
  115. }
  116. else
  117. {
  118. ViewManager.Hide<ModalStatusView>();
  119. AlertSystem.Show("初始化平台sdk失败!")
  120. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  121. }
  122. }
  123. private void OnPlatformLogined(EventContext context)
  124. {
  125. var account = (string)context.data;
  126. if(!string.IsNullOrEmpty(account))
  127. {
  128. LoginController.LoginTest(account).Coroutine();
  129. }
  130. else
  131. {
  132. ViewManager.Hide<ModalStatusView>();
  133. AlertSystem.Show("sdk登录失败!")
  134. .SetRightButton(true, "重试", (t) => { QDHYKBManager.Instance.Login(); });
  135. }
  136. }
  137. private void OnLoginSuccess(EventContext context)
  138. {
  139. _ui.m_btnLogout.visible = true;
  140. _ui.m_btnStart.visible = true;
  141. }
  142. private void OnSeverChangeListener(EventContext context)
  143. {
  144. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  145. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  146. }
  147. private void OnBtnChangeClick()
  148. {
  149. ViewManager.Show<ServerListView>();
  150. }
  151. private void OnClickBtnNotice()
  152. {
  153. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  154. {
  155. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  156. return;
  157. }
  158. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  159. }
  160. private void OnClickBtnStart()
  161. {
  162. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  163. if (serverInfosComponent.ServerInfoList.Count <= 0)
  164. {
  165. if (QDManager.IsTaptap)
  166. {
  167. OnClickBtnTabLoginAsync().Wait();
  168. }
  169. else if (QDManager.IsHYKB)
  170. {
  171. QDHYKBManager.Instance.Login();
  172. }
  173. else
  174. {
  175. bool login = GameController.CheckLoginCache(true);
  176. if (!login)
  177. {
  178. ViewManager.Show<LoginInputView>();
  179. }
  180. }
  181. }
  182. else
  183. {
  184. LoginController.GetRoles().Coroutine();
  185. }
  186. }
  187. private async Task OnClickBtnTabLoginAsync()
  188. {
  189. var success = await QDTapTapManager.Instance.Login();
  190. _ui.m_btnTapLogin.visible = !success;
  191. }
  192. private void OnClickBtnLogout()
  193. {
  194. GameController.QuitToLoginView(true);
  195. }
  196. private void OnClickBtnAge()
  197. {
  198. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  199. }
  200. }
  201. }