LoginView.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. if(QDManager.isInited)
  75. {
  76. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
  77. }
  78. else
  79. {
  80. //初始化平台配置
  81. QDManager.InitPlatform();
  82. }
  83. }
  84. protected override void OnHide()
  85. {
  86. if (_sceneObject != null)
  87. {
  88. GameObject.Destroy(_sceneObject);
  89. _sceneObject = null;
  90. }
  91. base.OnHide();
  92. }
  93. protected override void RemoveEventListener()
  94. {
  95. base.RemoveEventListener();
  96. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  97. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  98. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  99. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  100. }
  101. private void UpdateServer(ServerInfo info)
  102. {
  103. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  104. if (serverInfosComponent.ServerInfoList.Count == 0)
  105. {
  106. _ui.m_btnChange.visible = false;
  107. return;
  108. }
  109. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  110. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  111. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  112. }
  113. private void OnPlatformInitet(EventContext context)
  114. {
  115. ViewManager.Hide<ModalStatusView>();
  116. var success = (bool)context.data;
  117. Debug.Log($"InitPlatform success {success}");
  118. if (success)
  119. {
  120. QDManager.isInited = true;
  121. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  122. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  123. //尝试自动登录
  124. OnClickBtnStart();
  125. }
  126. else
  127. {
  128. AlertSystem.Show("初始化平台sdk失败!")
  129. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  130. }
  131. }
  132. private void OnPlatformLogined(EventContext context)
  133. {
  134. var account = (string)context.data;
  135. if(!string.IsNullOrEmpty(account))
  136. {
  137. _ui.m_btnTapLogin.visible = false;
  138. if(QDManager.IsHYKB)
  139. {
  140. //好游快爆因为SDK的防沉迷会使游戏失去焦点,需要检测焦点
  141. Timers.inst.AddUpdate(CheckHykbLoginServer);
  142. }
  143. else
  144. {
  145. LoginController.LoginTest(account).Coroutine();
  146. }
  147. }
  148. else
  149. {
  150. ViewManager.Hide<ModalStatusView>();
  151. //尝试自动登录
  152. OnClickBtnStart();
  153. }
  154. }
  155. private void CheckHykbLoginServer(object p)
  156. {
  157. if(Application.isFocused)
  158. {
  159. LoginController.LoginTest(QDHYKBManager.Instance.UserId).Coroutine();
  160. Timers.inst.Remove(CheckHykbLoginServer);
  161. }
  162. }
  163. private void OnLoginSuccess(EventContext context)
  164. {
  165. _ui.m_btnLogout.visible = true;
  166. _ui.m_btnStart.visible = true;
  167. }
  168. private void OnSeverChangeListener(EventContext context)
  169. {
  170. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  171. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  172. }
  173. private void OnBtnChangeClick()
  174. {
  175. ViewManager.Show<ServerListView>();
  176. }
  177. private void OnClickBtnNotice()
  178. {
  179. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  180. {
  181. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  182. return;
  183. }
  184. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  185. }
  186. private void OnClickBtnStart()
  187. {
  188. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  189. if (serverInfosComponent.ServerInfoList.Count <= 0)
  190. {
  191. if (QDManager.IsTaptap)
  192. {
  193. QDTapTapManager.Instance.Login();
  194. }
  195. else if (QDManager.IsHYKB)
  196. {
  197. QDHYKBManager.Instance.Login();
  198. }
  199. else if(QDManager.IsBiliBili)
  200. {
  201. QDBiliBiliManager.Instance.Login();
  202. }
  203. else
  204. {
  205. bool login = GameController.CheckLoginCache(true);
  206. if (!login)
  207. {
  208. ViewManager.Show<LoginInputView>();
  209. }
  210. }
  211. }
  212. else
  213. {
  214. LoginController.GetRoles().Coroutine();
  215. }
  216. }
  217. private void OnClickBtnLogout()
  218. {
  219. GameController.QuitToLoginView(true);
  220. }
  221. private void OnClickBtnAge()
  222. {
  223. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  224. }
  225. }
  226. }