LoginView.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. _ui.m_btnAgree.selected = true;
  76. if (QDManager.isInited)
  77. {
  78. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
  79. }
  80. else
  81. {
  82. //初始化平台配置
  83. QDManager.InitPlatform();
  84. }
  85. }
  86. protected override void OnHide()
  87. {
  88. if (_sceneObject != null)
  89. {
  90. GameObject.Destroy(_sceneObject);
  91. _sceneObject = null;
  92. }
  93. base.OnHide();
  94. }
  95. protected override void RemoveEventListener()
  96. {
  97. base.RemoveEventListener();
  98. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  99. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  100. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  101. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  102. }
  103. private void UpdateServer(ServerInfo info)
  104. {
  105. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  106. if (serverInfosComponent.ServerInfoList.Count == 0)
  107. {
  108. _ui.m_btnChange.visible = false;
  109. return;
  110. }
  111. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  112. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  113. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  114. }
  115. private void OnPlatformInitet(EventContext context)
  116. {
  117. ViewManager.Hide<ModalStatusView>();
  118. var success = (bool)context.data;
  119. Debug.Log($"InitPlatform success {success}");
  120. if (success)
  121. {
  122. QDManager.isInited = true;
  123. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  124. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  125. //尝试自动登录
  126. OnClickBtnStart();
  127. }
  128. else
  129. {
  130. AlertSystem.Show("初始化平台sdk失败!")
  131. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  132. }
  133. }
  134. private void OnPlatformLogined(EventContext context)
  135. {
  136. var account = (string)context.data;
  137. if (!string.IsNullOrEmpty(account))
  138. {
  139. _ui.m_btnTapLogin.visible = false;
  140. LoginController.LoginTest(account).Coroutine();
  141. }
  142. else
  143. {
  144. ViewManager.Hide<ModalStatusView>();
  145. //尝试自动登录
  146. OnClickBtnStart();
  147. }
  148. }
  149. private void OnLoginSuccess(EventContext context)
  150. {
  151. _ui.m_btnLogout.visible = true;
  152. _ui.m_btnStart.visible = true;
  153. }
  154. private void OnSeverChangeListener(EventContext context)
  155. {
  156. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  157. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  158. }
  159. private void OnBtnChangeClick()
  160. {
  161. ViewManager.Show<ServerListView>();
  162. }
  163. private void OnClickBtnNotice()
  164. {
  165. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  166. {
  167. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  168. return;
  169. }
  170. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  171. }
  172. private void OnClickBtnStart()
  173. {
  174. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  175. if (serverInfosComponent.ServerInfoList.Count <= 0)
  176. {
  177. QDManager.Login();
  178. }
  179. else
  180. {
  181. if (!_ui.m_btnAgree.selected)
  182. {
  183. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  184. return;
  185. }
  186. LoginController.GetRoles().Coroutine();
  187. }
  188. }
  189. private void OnClickBtnLogout()
  190. {
  191. GameController.QuitToLoginView(true);
  192. }
  193. private void OnClickBtnAge()
  194. {
  195. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  196. }
  197. private void OnClickRichTextAgreeLink(string eventname)
  198. {
  199. Debug.Log("link target " + eventname);
  200. string content = null;
  201. switch (eventname)
  202. {
  203. case "event:a":
  204. content = GFGAsset.Load<TextAsset>(ResPathUtil.GetTxtPath("serviceProtocal")).text;
  205. break;
  206. case "event:b":
  207. content = GFGAsset.Load<TextAsset>(ResPathUtil.GetTxtPath("privacyPolicy")).text;
  208. break;
  209. case "event:c":
  210. content = GFGAsset.Load<TextAsset>(ResPathUtil.GetTxtPath("privacyPolicyChildren")).text;
  211. break;
  212. }
  213. if (!string.IsNullOrEmpty(content))
  214. {
  215. FullScreenTextView.Instance.Show(content);
  216. }
  217. }
  218. private void OnBtnAgreeCklick()
  219. {
  220. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_AGREE_KEY, _ui.m_btnAgree.selected);
  221. }
  222. }
  223. }