LoginView.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. var success = (bool)context.data;
  116. Debug.Log($"InitPlatform success {success}");
  117. if (success)
  118. {
  119. QDManager.isInited = true;
  120. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  121. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  122. if(QDManager.IsHYKB)
  123. {
  124. Timers.inst.Add(1, 1, DelayToHYKBLogin);
  125. }
  126. else
  127. {
  128. //尝试自动登录
  129. OnClickBtnStart();
  130. }
  131. }
  132. else
  133. {
  134. ViewManager.Hide<ModalStatusView>();
  135. AlertSystem.Show("初始化平台sdk失败!")
  136. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  137. }
  138. }
  139. private void OnPlatformLogined(EventContext context)
  140. {
  141. var account = (string)context.data;
  142. if(!string.IsNullOrEmpty(account))
  143. {
  144. _ui.m_btnTapLogin.visible = false;
  145. if(QDManager.IsHYKB)
  146. {
  147. //好游快爆因为SDK的防沉迷会使游戏失去焦点,需要检测焦点
  148. focusCount = 0;
  149. Timers.inst.Add(1, 0, CheckHykbLoginServer);
  150. }
  151. else
  152. {
  153. LoginController.LoginTest(account).Coroutine();
  154. }
  155. }
  156. else
  157. {
  158. ViewManager.Hide<ModalStatusView>();
  159. //尝试自动登录
  160. OnClickBtnStart();
  161. }
  162. }
  163. //start==================垃圾代码,处理好游快爆sdk防沉迷无回调的问题
  164. private void DelayToHYKBLogin(object obj)
  165. {
  166. //尝试自动登录
  167. OnClickBtnStart();
  168. }
  169. private int focusCount;
  170. private void CheckHykbLoginServer(object obj)
  171. {
  172. if(Application.isFocused)
  173. {
  174. focusCount++;
  175. if(focusCount >= 2)
  176. {
  177. LoginController.LoginTest(QDHYKBManager.Instance.UserId).Coroutine();
  178. Timers.inst.Remove(CheckHykbLoginServer);
  179. }
  180. }
  181. else
  182. {
  183. focusCount = 0;
  184. }
  185. }
  186. //end==================垃圾代码,处理好游快爆sdk防沉迷无回调的问题
  187. private void OnLoginSuccess(EventContext context)
  188. {
  189. _ui.m_btnLogout.visible = true;
  190. _ui.m_btnStart.visible = true;
  191. }
  192. private void OnSeverChangeListener(EventContext context)
  193. {
  194. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  195. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  196. }
  197. private void OnBtnChangeClick()
  198. {
  199. ViewManager.Show<ServerListView>();
  200. }
  201. private void OnClickBtnNotice()
  202. {
  203. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  204. {
  205. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  206. return;
  207. }
  208. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  209. }
  210. private void OnClickBtnStart()
  211. {
  212. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  213. if (serverInfosComponent.ServerInfoList.Count <= 0)
  214. {
  215. if (QDManager.IsTaptap)
  216. {
  217. QDTapTapManager.Instance.Login();
  218. }
  219. else if (QDManager.IsHYKB)
  220. {
  221. QDHYKBManager.Instance.Login();
  222. }
  223. else if(QDManager.IsBiliBili)
  224. {
  225. QDBiliBiliManager.Instance.Login();
  226. }
  227. else
  228. {
  229. bool login = GameController.CheckLoginCache(true);
  230. if (!login)
  231. {
  232. ViewManager.Show<LoginInputView>();
  233. }
  234. }
  235. }
  236. else
  237. {
  238. LoginController.GetRoles().Coroutine();
  239. }
  240. }
  241. private void OnClickBtnLogout()
  242. {
  243. GameController.QuitToLoginView(true);
  244. }
  245. private void OnClickBtnAge()
  246. {
  247. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  248. }
  249. }
  250. }