LoginView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. _ui.m_loaEventa.onClick.Add(() => { OnClickRichTextAgreeLink("event:a"); });
  51. _ui.m_loaEventb.onClick.Add(() => { OnClickRichTextAgreeLink("event:b"); });
  52. _ui.m_loaEventc.onClick.Add(() => { OnClickRichTextAgreeLink("event:c"); });
  53. _ui.m_btnAgree.onClick.Add(OnBtnAgreeCklick);
  54. }
  55. protected override void AddEventListener()
  56. {
  57. base.AddEventListener();
  58. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  59. EventAgent.AddEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  60. EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  61. EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  62. }
  63. protected override void OnShown()
  64. {
  65. base.OnShown();
  66. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  67. if (_sceneObject == null)
  68. {
  69. _sceneObject = GameObject.Instantiate(_scenePrefab);
  70. }
  71. SceneController.UpdateLoginScene(_sceneObject);
  72. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  73. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  74. UpdateServer(recentlyServerInfo);
  75. _ui.m_btnStart.visible = false;
  76. _ui.m_btnTapLogin.visible = false;
  77. _ui.m_btnLogout.visible = false;
  78. _ui.m_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_AGREE_KEY, false);
  79. if (QDManager.isInited)
  80. {
  81. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
  82. }
  83. else
  84. {
  85. //初始化平台配置
  86. QDManager.InitPlatform();
  87. }
  88. }
  89. protected override void OnHide()
  90. {
  91. if (_sceneObject != null)
  92. {
  93. GameObject.Destroy(_sceneObject);
  94. _sceneObject = null;
  95. }
  96. base.OnHide();
  97. }
  98. protected override void RemoveEventListener()
  99. {
  100. base.RemoveEventListener();
  101. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  102. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  103. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  104. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  105. }
  106. private void UpdateServer(ServerInfo info)
  107. {
  108. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  109. if (serverInfosComponent.ServerInfoList.Count == 0)
  110. {
  111. _ui.m_btnChange.visible = false;
  112. return;
  113. }
  114. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  115. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  116. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  117. }
  118. private void OnPlatformInitet(EventContext context)
  119. {
  120. ViewManager.Hide<ModalStatusView>();
  121. var success = (bool)context.data;
  122. Debug.Log($"InitPlatform success {success}");
  123. if (success)
  124. {
  125. QDManager.isInited = true;
  126. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  127. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  128. if (QDManager.IsHYKB)
  129. {
  130. Timers.inst.Add(1, 1, DelayToHYKBLogin);
  131. }
  132. else
  133. {
  134. //尝试自动登录
  135. OnClickBtnStart();
  136. }
  137. }
  138. else
  139. {
  140. AlertSystem.Show("初始化平台sdk失败!")
  141. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  142. }
  143. }
  144. private void OnPlatformLogined(EventContext context)
  145. {
  146. var account = (string)context.data;
  147. if (!string.IsNullOrEmpty(account))
  148. {
  149. _ui.m_btnTapLogin.visible = false;
  150. if (QDManager.IsHYKB)
  151. {
  152. //好游快爆因为SDK的防沉迷会使游戏失去焦点,需要检测焦点
  153. focusCount = 0;
  154. Timers.inst.Add(1, 0, CheckHykbLoginServer);
  155. }
  156. else
  157. {
  158. LoginController.LoginTest(account).Coroutine();
  159. }
  160. }
  161. else
  162. {
  163. ViewManager.Hide<ModalStatusView>();
  164. //尝试自动登录
  165. OnClickBtnStart();
  166. }
  167. }
  168. //start==================垃圾代码,处理好游快爆sdk防沉迷无回调的问题
  169. private void DelayToHYKBLogin(object obj)
  170. {
  171. //尝试自动登录
  172. OnClickBtnStart();
  173. }
  174. private int focusCount;
  175. private void CheckHykbLoginServer(object obj)
  176. {
  177. if (Application.isFocused)
  178. {
  179. focusCount++;
  180. if (focusCount >= 2)
  181. {
  182. LoginController.LoginTest(QDHYKBManager.Instance.UserId).Coroutine();
  183. Timers.inst.Remove(CheckHykbLoginServer);
  184. }
  185. }
  186. else
  187. {
  188. focusCount = 0;
  189. }
  190. }
  191. //end==================垃圾代码,处理好游快爆sdk防沉迷无回调的问题
  192. private void OnLoginSuccess(EventContext context)
  193. {
  194. _ui.m_btnLogout.visible = true;
  195. _ui.m_btnStart.visible = true;
  196. }
  197. private void OnSeverChangeListener(EventContext context)
  198. {
  199. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  200. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  201. }
  202. private void OnBtnChangeClick()
  203. {
  204. ViewManager.Show<ServerListView>();
  205. }
  206. private void OnClickBtnNotice()
  207. {
  208. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  209. {
  210. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  211. return;
  212. }
  213. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  214. }
  215. private void OnClickBtnStart()
  216. {
  217. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  218. if (serverInfosComponent.ServerInfoList.Count <= 0)
  219. {
  220. if (QDManager.IsTaptap)
  221. {
  222. QDTapTapManager.Instance.Login();
  223. }
  224. else if (QDManager.IsHYKB)
  225. {
  226. QDHYKBManager.Instance.Login();
  227. }
  228. else if (QDManager.IsBiliBili)
  229. {
  230. QDBiliBiliManager.Instance.Login();
  231. }
  232. else
  233. {
  234. bool login = GameController.CheckLoginCache(true);
  235. if (!login)
  236. {
  237. ViewManager.Show<LoginInputView>();
  238. }
  239. }
  240. }
  241. else
  242. {
  243. if (!_ui.m_btnAgree.selected)
  244. {
  245. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意服务协议、隐私政策、保护规则");
  246. return;
  247. }
  248. LoginController.GetRoles().Coroutine();
  249. }
  250. }
  251. private void OnClickBtnLogout()
  252. {
  253. GameController.QuitToLoginView(true);
  254. }
  255. private void OnClickBtnAge()
  256. {
  257. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  258. }
  259. private void OnClickRichTextAgreeLink(string eventname)
  260. {
  261. Debug.Log("link target " + eventname);
  262. string content = null;
  263. switch (eventname)
  264. {
  265. case "event:a":
  266. content = GFGAsset.Load<TextAsset>(ResPathUtil.GetTxtPath("serviceProtocal")).text;
  267. break;
  268. case "event:b":
  269. content = GFGAsset.Load<TextAsset>(ResPathUtil.GetTxtPath("privacyPolicy")).text;
  270. break;
  271. case "event:c":
  272. content = GFGAsset.Load<TextAsset>(ResPathUtil.GetTxtPath("privacyPolicyChildren")).text;
  273. break;
  274. }
  275. if (!string.IsNullOrEmpty(content))
  276. {
  277. ViewManager.Show<FullScreenTextView>(content);
  278. }
  279. }
  280. private void OnBtnAgreeCklick()
  281. {
  282. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_AGREE_KEY, _ui.m_btnAgree.selected);
  283. }
  284. }
  285. }