LoginView.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 _sceneObject;
  11. public override void Dispose()
  12. {
  13. if (_sceneObject != null)
  14. {
  15. GameObject.DestroyImmediate(_sceneObject);
  16. _sceneObject = null;
  17. }
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void Init()
  26. {
  27. base.Init();
  28. packageName = UI_LoginUI.PACKAGE_NAME;
  29. _ui = UI_LoginUI.Create();
  30. viewCom = _ui.target;
  31. isfullScreen = true;
  32. }
  33. protected override void OnInit()
  34. {
  35. base.OnInit();
  36. _ui.m_txtVersion.text = GameGlobal.version;
  37. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  38. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  39. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  40. _ui.m_btnAge.onClick.Add(OnClickBtnAge);
  41. _ui.m_btnTapLogin.onClick.Add(OnClickBtnStart);
  42. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  43. _ui.m_loaEventa.onClick.Add(() => { FullScreenTextController.Show("event:a"); });
  44. _ui.m_loaEventb.onClick.Add(() => { FullScreenTextController.Show("event:b"); });
  45. _ui.m_loaEventc.onClick.Add(() => { FullScreenTextController.Show("event:c"); });
  46. //_ui.m_btnAgree.onClick.Add(OnBtnAgreeCklick);
  47. GameGlobal.isLogon = true;
  48. }
  49. protected override void AddEventListener()
  50. {
  51. base.AddEventListener();
  52. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  53. EventAgent.AddEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  54. EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  55. EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  56. }
  57. protected override void OnShown()
  58. {
  59. base.OnShown();
  60. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  61. if (_sceneObject == null)
  62. {
  63. _sceneObject = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetLoginResPath("LoginSkin1/SceneLogin"));
  64. }
  65. // SceneController.UpdateLoginScene(_sceneObject);
  66. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  67. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  68. UpdateServer(recentlyServerInfo);
  69. _ui.m_btnStart.visible = false;
  70. _ui.m_btnTapLogin.visible = false;
  71. _ui.m_btnLogout.visible = false;
  72. //_ui.m_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_AGREE_KEY, false);
  73. _ui.m_btnAgree.selected = true;
  74. if(GameConfig.openTime > TimeHelper.ClientNow())
  75. {
  76. AlertUI.Show("未到开放时间!")
  77. .SetLeftButton(true, "稍后再试", (obj) =>
  78. {
  79. Application.Quit();
  80. });
  81. return;
  82. }
  83. if (QDManager.isInited)
  84. {
  85. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
  86. }
  87. else
  88. {
  89. //初始化平台配置
  90. QDManager.InitPlatform();
  91. }
  92. GameGlobal.isLogon = true;
  93. }
  94. protected override void OnHide()
  95. {
  96. if (_sceneObject != null)
  97. {
  98. PrefabManager.Instance.Restore(_sceneObject);
  99. _sceneObject = null;
  100. }
  101. base.OnHide();
  102. }
  103. protected override void RemoveEventListener()
  104. {
  105. base.RemoveEventListener();
  106. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  107. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  108. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  109. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  110. }
  111. private void UpdateServer(ServerInfo info)
  112. {
  113. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  114. if (serverInfosComponent.ServerInfoList.Count == 0)
  115. {
  116. _ui.m_btnChange.visible = false;
  117. return;
  118. }
  119. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  120. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  121. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  122. }
  123. private void OnPlatformInitet(EventContext context)
  124. {
  125. ViewManager.Hide<ModalStatusView>();
  126. var success = (bool)context.data;
  127. Debug.Log($"InitPlatform success {success}");
  128. if (success)
  129. {
  130. QDManager.isInited = true;
  131. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  132. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  133. //尝试自动登录
  134. OnClickBtnStart();
  135. }
  136. else
  137. {
  138. AlertSystem.Show("初始化平台sdk失败!")
  139. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  140. }
  141. }
  142. private void OnPlatformLogined(EventContext context)
  143. {
  144. var account = (string)context.data;
  145. if (!string.IsNullOrEmpty(account))
  146. {
  147. _ui.m_btnTapLogin.visible = false;
  148. LoginController.LoginTest(account).Coroutine();
  149. }
  150. else
  151. {
  152. ViewManager.Hide<ModalStatusView>();
  153. //尝试自动登录
  154. OnClickBtnStart();
  155. }
  156. }
  157. private void OnLoginSuccess(EventContext context)
  158. {
  159. _ui.m_btnLogout.visible = true;
  160. _ui.m_btnStart.visible = true;
  161. }
  162. private void OnSeverChangeListener(EventContext context)
  163. {
  164. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  165. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  166. }
  167. private void OnBtnChangeClick()
  168. {
  169. ViewManager.Show<ServerListView>();
  170. }
  171. private void OnClickBtnNotice()
  172. {
  173. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  174. {
  175. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  176. return;
  177. }
  178. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  179. }
  180. private void OnClickBtnStart()
  181. {
  182. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  183. if (serverInfosComponent.ServerInfoList.Count <= 0)
  184. {
  185. QDManager.Login();
  186. }
  187. else
  188. {
  189. if (!_ui.m_btnAgree.selected)
  190. {
  191. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  192. return;
  193. }
  194. LoginController.GetRoles().Coroutine();
  195. }
  196. }
  197. private void OnClickBtnLogout()
  198. {
  199. GameController.QuitToLoginView(true);
  200. }
  201. private void OnClickBtnAge()
  202. {
  203. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  204. }
  205. //private void OnBtnAgreeCklick()
  206. //{
  207. // LocalCache.SetBool(LauncherConfig.LAST_LOGIN_IS_AGREE_KEY, _ui.m_btnAgree.selected);
  208. //}
  209. }
  210. }