LoginView.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. focusCount = 0;
  142. Timers.inst.Add(1, 0, CheckHykbLoginServer);
  143. }
  144. else
  145. {
  146. LoginController.LoginTest(account).Coroutine();
  147. }
  148. }
  149. else
  150. {
  151. ViewManager.Hide<ModalStatusView>();
  152. //尝试自动登录
  153. OnClickBtnStart();
  154. }
  155. }
  156. //start==================垃圾代码,处理好游快爆sdk防沉迷无回调的问题
  157. private int focusCount;
  158. private void CheckHykbLoginServer(object p)
  159. {
  160. if(Application.isFocused)
  161. {
  162. focusCount++;
  163. if(focusCount >= 2)
  164. {
  165. LoginController.LoginTest(QDHYKBManager.Instance.UserId).Coroutine();
  166. Timers.inst.Remove(CheckHykbLoginServer);
  167. }
  168. }
  169. else
  170. {
  171. focusCount = 0;
  172. }
  173. }
  174. //end==================垃圾代码,处理好游快爆sdk防沉迷无回调的问题
  175. private void OnLoginSuccess(EventContext context)
  176. {
  177. _ui.m_btnLogout.visible = true;
  178. _ui.m_btnStart.visible = true;
  179. }
  180. private void OnSeverChangeListener(EventContext context)
  181. {
  182. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  183. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  184. }
  185. private void OnBtnChangeClick()
  186. {
  187. ViewManager.Show<ServerListView>();
  188. }
  189. private void OnClickBtnNotice()
  190. {
  191. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  192. {
  193. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  194. return;
  195. }
  196. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  197. }
  198. private void OnClickBtnStart()
  199. {
  200. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  201. if (serverInfosComponent.ServerInfoList.Count <= 0)
  202. {
  203. if (QDManager.IsTaptap)
  204. {
  205. QDTapTapManager.Instance.Login();
  206. }
  207. else if (QDManager.IsHYKB)
  208. {
  209. QDHYKBManager.Instance.Login();
  210. }
  211. else if(QDManager.IsBiliBili)
  212. {
  213. QDBiliBiliManager.Instance.Login();
  214. }
  215. else
  216. {
  217. bool login = GameController.CheckLoginCache(true);
  218. if (!login)
  219. {
  220. ViewManager.Show<LoginInputView>();
  221. }
  222. }
  223. }
  224. else
  225. {
  226. LoginController.GetRoles().Coroutine();
  227. }
  228. }
  229. private void OnClickBtnLogout()
  230. {
  231. GameController.QuitToLoginView(true);
  232. }
  233. private void OnClickBtnAge()
  234. {
  235. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  236. }
  237. }
  238. }