LoginView.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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(() => {
  44. Application.OpenURL("http://ysxy.wan383.com/mwyhxy.html");
  45. //FullScreenTextController.Show("event:a");
  46. });
  47. _ui.m_loaEventb.onClick.Add(() => { FullScreenTextController.Show("event:b"); });
  48. _ui.m_loaEventc.onClick.Add(() => { FullScreenTextController.Show("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.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  63. if (_sceneObject == null)
  64. {
  65. _sceneObject = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetLoginResPath("LoginSkin1/SceneLogin"));
  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(GameConfig.openTime > TimeHelper.ClientNow())
  77. {
  78. AlertUI.Show("未到开放时间!")
  79. .SetLeftButton(true, "稍后再试", (obj) =>
  80. {
  81. Application.Quit();
  82. });
  83. return;
  84. }
  85. if (QDManager.isInited)
  86. {
  87. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
  88. }
  89. else
  90. {
  91. //初始化平台配置
  92. QDManager.InitPlatform();
  93. }
  94. }
  95. protected override void OnHide()
  96. {
  97. if (_sceneObject != null)
  98. {
  99. PrefabManager.Instance.Restore(_sceneObject);
  100. _sceneObject = null;
  101. }
  102. base.OnHide();
  103. }
  104. protected override void RemoveEventListener()
  105. {
  106. base.RemoveEventListener();
  107. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  108. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  109. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
  110. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  111. }
  112. private void UpdateServer(ServerInfo info)
  113. {
  114. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  115. if (serverInfosComponent.ServerInfoList.Count == 0)
  116. {
  117. _ui.m_btnChange.visible = false;
  118. return;
  119. }
  120. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  121. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  122. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  123. }
  124. private void OnPlatformInitet(EventContext context)
  125. {
  126. ViewManager.Hide<ModalStatusView>();
  127. var success = (bool)context.data;
  128. Debug.Log($"InitPlatform success {success}");
  129. if (success)
  130. {
  131. QDManager.isInited = true;
  132. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  133. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  134. //尝试自动登录
  135. TryLogin();
  136. }
  137. else
  138. {
  139. AlertSystem.Show("初始化平台sdk失败!")
  140. .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
  141. }
  142. }
  143. private void OnPlatformLogined(EventContext context)
  144. {
  145. var account = (string)context.data;
  146. if (!string.IsNullOrEmpty(account))
  147. {
  148. _ui.m_btnTapLogin.visible = false;
  149. LoginController.LoginTest(account).Coroutine();
  150. }
  151. else
  152. {
  153. ViewManager.Hide<ModalStatusView>();
  154. //尝试自动登录
  155. TryLogin();
  156. }
  157. }
  158. private void OnLoginSuccess(EventContext context)
  159. {
  160. _ui.m_btnLogout.visible = true;
  161. _ui.m_btnStart.visible = true;
  162. }
  163. private void OnSeverChangeListener(EventContext context)
  164. {
  165. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  166. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  167. }
  168. private void OnBtnChangeClick()
  169. {
  170. ViewManager.Show<ServerListView>();
  171. }
  172. private void OnClickBtnNotice()
  173. {
  174. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  175. {
  176. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  177. return;
  178. }
  179. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  180. }
  181. private void OnClickBtnStart()
  182. {
  183. TryLogin();
  184. }
  185. private void OnClickBtnLogout()
  186. {
  187. GameController.QuitToLoginView(true);
  188. }
  189. private void OnClickBtnAge()
  190. {
  191. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  192. }
  193. private void TryLogin()
  194. {
  195. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  196. if (serverInfosComponent.ServerInfoList.Count <= 0)
  197. {
  198. QDManager.Login();
  199. }
  200. else
  201. {
  202. if (!_ui.m_btnAgree.selected)
  203. {
  204. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  205. return;
  206. }
  207. LoginController.GetRoles().Coroutine();
  208. }
  209. }
  210. }
  211. }