LoginView.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Login;
  4. using ET;
  5. namespace GFGGame
  6. {
  7. public class LoginView : BaseView
  8. {
  9. private UI_LoginUI _ui;
  10. private GameObject _scenePrefab;
  11. private GameObject _sceneObject;
  12. public override void Dispose()
  13. {
  14. if (_sceneObject != null)
  15. {
  16. GameObject.DestroyImmediate(_sceneObject);
  17. _sceneObject = null;
  18. }
  19. if (_ui != null)
  20. {
  21. _ui.Dispose();
  22. _ui = null;
  23. }
  24. base.Dispose();
  25. }
  26. protected override void Init()
  27. {
  28. base.Init();
  29. packageName = UI_LoginUI.PACKAGE_NAME;
  30. _ui = UI_LoginUI.Create();
  31. viewCom = _ui.target;
  32. isfullScreen = true;
  33. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneLogin"));
  34. }
  35. protected override void OnInit()
  36. {
  37. base.OnInit();
  38. _ui.m_txtVersion.text = GameGlobal.version;
  39. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  40. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  41. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  42. _ui.m_btnAge.onClick.Add(OnClickBtnAge);
  43. _ui.m_btnTapLogin.onClick.Add(OnClickBtnStart);
  44. _ui.m_imgLogo.visible = LauncherConfig.netType != LauncherConfig.EnumNetType.TEMP;
  45. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  46. _ui.m_loaEventa.onClick.Add(() => { OnClickRichTextAgreeLink("event:a"); });
  47. _ui.m_loaEventb.onClick.Add(() => { OnClickRichTextAgreeLink("event:b"); });
  48. _ui.m_loaEventc.onClick.Add(() => { OnClickRichTextAgreeLink("event:c"); });
  49. _ui.m_btnAgree.onClick.Add(OnBtnAgreeCklick);
  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. _ui.m_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_AGREE_KEY, false);
  75. if (QDManager.isInited)
  76. {
  77. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
  78. }
  79. else
  80. {
  81. //初始化平台配置
  82. QDManager.InitPlatform();
  83. }
  84. }
  85. protected override void OnHide()
  86. {
  87. if (_sceneObject != null)
  88. {
  89. GameObject.Destroy(_sceneObject);
  90. _sceneObject = null;
  91. }
  92. base.OnHide();
  93. }
  94. protected override void RemoveEventListener()
  95. {
  96. base.RemoveEventListener();
  97. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  98. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  99. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  100. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  101. }
  102. private void UpdateServer(ServerInfo info)
  103. {
  104. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  105. if (serverInfosComponent.ServerInfoList.Count == 0)
  106. {
  107. _ui.m_btnChange.visible = false;
  108. return;
  109. }
  110. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  111. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  112. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  113. }
  114. private void OnPlatformInitet(EventContext context)
  115. {
  116. ViewManager.Hide<ModalStatusView>();
  117. var success = (bool)context.data;
  118. Debug.Log($"InitPlatform success {success}");
  119. if (success)
  120. {
  121. QDManager.isInited = true;
  122. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  123. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  124. //尝试自动登录
  125. OnClickBtnStart();
  126. }
  127. else
  128. {
  129. AlertSystem.Show("初始化平台sdk失败!")
  130. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  131. }
  132. }
  133. private void OnPlatformLogined(EventContext context)
  134. {
  135. var account = (string)context.data;
  136. if (!string.IsNullOrEmpty(account))
  137. {
  138. _ui.m_btnTapLogin.visible = false;
  139. LoginController.LoginTest(account).Coroutine();
  140. }
  141. else
  142. {
  143. ViewManager.Hide<ModalStatusView>();
  144. //尝试自动登录
  145. OnClickBtnStart();
  146. }
  147. }
  148. private void OnLoginSuccess(EventContext context)
  149. {
  150. _ui.m_btnLogout.visible = true;
  151. _ui.m_btnStart.visible = true;
  152. }
  153. private void OnSeverChangeListener(EventContext context)
  154. {
  155. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  156. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  157. }
  158. private void OnBtnChangeClick()
  159. {
  160. ViewManager.Show<ServerListView>();
  161. }
  162. private void OnClickBtnNotice()
  163. {
  164. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  165. {
  166. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  167. return;
  168. }
  169. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  170. }
  171. private void OnClickBtnStart()
  172. {
  173. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  174. if (serverInfosComponent.ServerInfoList.Count <= 0)
  175. {
  176. QDManager.Login();
  177. }
  178. else
  179. {
  180. if (!_ui.m_btnAgree.selected)
  181. {
  182. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  183. return;
  184. }
  185. LoginController.GetRoles().Coroutine();
  186. }
  187. }
  188. private void OnClickBtnLogout()
  189. {
  190. GameController.QuitToLoginView(true);
  191. }
  192. private void OnClickBtnAge()
  193. {
  194. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  195. }
  196. private void OnClickRichTextAgreeLink(string eventname)
  197. {
  198. Debug.Log("link target " + eventname);
  199. string content = null;
  200. switch (eventname)
  201. {
  202. case "event:a":
  203. content = GFGAsset.Load<TextAsset>(ResPathUtil.GetTxtPath("serviceProtocal")).text;
  204. break;
  205. case "event:b":
  206. content = GFGAsset.Load<TextAsset>(ResPathUtil.GetTxtPath("privacyPolicy")).text;
  207. break;
  208. case "event:c":
  209. content = GFGAsset.Load<TextAsset>(ResPathUtil.GetTxtPath("privacyPolicyChildren")).text;
  210. break;
  211. }
  212. if (!string.IsNullOrEmpty(content))
  213. {
  214. ViewManager.Show<FullScreenTextView>(content);
  215. }
  216. }
  217. private void OnBtnAgreeCklick()
  218. {
  219. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_AGREE_KEY, _ui.m_btnAgree.selected);
  220. }
  221. }
  222. }