LoginView.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Login;
  4. using ET;
  5. using GFGGame.Launcher;
  6. namespace GFGGame
  7. {
  8. public class LoginView : BaseView
  9. {
  10. private UI_LoginUI _ui;
  11. private GameObject _sceneObject;
  12. private bool autoLogined;
  13. public override void Dispose()
  14. {
  15. if (_sceneObject != null)
  16. {
  17. GameObject.DestroyImmediate(_sceneObject);
  18. _sceneObject = null;
  19. }
  20. if (_ui != null)
  21. {
  22. _ui.Dispose();
  23. _ui = null;
  24. }
  25. base.Dispose();
  26. }
  27. protected override void Init()
  28. {
  29. base.Init();
  30. packageName = UI_LoginUI.PACKAGE_NAME;
  31. _ui = UI_LoginUI.Create();
  32. viewCom = _ui.target;
  33. isfullScreen = true;
  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_btnChange.onClick.Add(OnBtnChangeClick);
  45. _ui.m_loaEventa.onClick.Add(() => { FullScreenTextController.Show("event:a"); });
  46. _ui.m_loaEventb.onClick.Add(() => { FullScreenTextController.Show("event:b"); });
  47. _ui.m_loaEventc.onClick.Add(() => { FullScreenTextController.Show("event:c"); });
  48. //_ui.m_btnAgree.onClick.Add(OnBtnAgreeCklick);
  49. }
  50. protected override void AddEventListener()
  51. {
  52. base.AddEventListener();
  53. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  54. EventAgent.AddEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  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_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_AGREE_KEY, false);
  70. _ui.m_btnAgree.selected = true;
  71. if(GameConfig.openTime > TimeHelper.ClientNow())
  72. {
  73. var date = DateTimeUtil.LongTimeStampToDateTime(GameConfig.openTime);
  74. string minuteText = "";
  75. if(date.Minute > 0)
  76. {
  77. minuteText = date.Minute + "分";
  78. }
  79. AlertUI.Show($" 亲爱的研究员,万世镜将于{date.Year}年{date.Month}月{date.Day}日{date.Hour}点{minuteText}开放,敬请期待!")
  80. .SetLeftButton(true, "好的", (obj) =>
  81. {
  82. Application.Quit();
  83. });
  84. return;
  85. }
  86. if (!autoLogined)
  87. {
  88. autoLogined = true;
  89. ResetLoginButton();
  90. TryLogin();
  91. }
  92. }
  93. protected override void OnHide()
  94. {
  95. autoLogined = false;
  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_LOGINED, OnPlatformLogined);
  109. }
  110. private void UpdateServer(ServerInfo info)
  111. {
  112. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  113. if (serverInfosComponent.ServerInfoList.Count == 0)
  114. {
  115. _ui.m_btnChange.visible = false;
  116. return;
  117. }
  118. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  119. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  120. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  121. }
  122. private void OnPlatformLogined(EventContext context)
  123. {
  124. var account = (string)context.data;
  125. if (!string.IsNullOrEmpty(account))
  126. {
  127. _ui.m_btnTapLogin.visible = false;
  128. LoginController.LoginTest(account).Coroutine();
  129. }
  130. else
  131. {
  132. ViewManager.Hide<ModalStatusView>();
  133. //尝试自动登录
  134. TryLogin();
  135. }
  136. }
  137. private void OnLoginSuccess(EventContext context)
  138. {
  139. _ui.m_btnLogout.visible = true;
  140. _ui.m_btnStart.visible = true;
  141. }
  142. private void OnSeverChangeListener(EventContext context)
  143. {
  144. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  145. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  146. }
  147. private void OnBtnChangeClick()
  148. {
  149. ViewManager.Show<ServerListView>();
  150. }
  151. private void OnClickBtnNotice()
  152. {
  153. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  154. {
  155. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  156. return;
  157. }
  158. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  159. }
  160. private void OnClickBtnStart()
  161. {
  162. TryLogin();
  163. }
  164. private void OnClickBtnLogout()
  165. {
  166. ResetLoginButton();
  167. QDManager.Logout(false);
  168. }
  169. private void OnClickBtnAge()
  170. {
  171. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  172. }
  173. private void TryLogin()
  174. {
  175. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", GameGlobal.cfgName);
  176. url = url + "?t=" + TimeHelper.ClientNow();
  177. HttpTool.Instance.Get(url, (string data) =>
  178. {
  179. //重新加载游戏配置
  180. GameConfig.InitData(data);
  181. if (GameConfig.serverStatus == 1)
  182. {
  183. if (string.IsNullOrEmpty(GameConfig.statusPrompt))
  184. {
  185. GameConfig.statusPrompt = "游戏正在更新维护中,请稍后再试。";
  186. }
  187. AlertSystem.Show(GameConfig.statusPrompt)
  188. .SetLeftButton(true, "知道了", (data) =>
  189. {
  190. Application.Quit();
  191. });
  192. return;
  193. }
  194. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  195. if (serverInfosComponent.ServerInfoList.Count <= 0)
  196. {
  197. QDManager.Login();
  198. }
  199. else
  200. {
  201. if (!_ui.m_btnAgree.selected)
  202. {
  203. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  204. return;
  205. }
  206. LoginController.GetRoles().Coroutine();
  207. }
  208. });
  209. }
  210. private void ResetLoginButton()
  211. {
  212. _ui.m_btnLogout.visible = false;
  213. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  214. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  215. }
  216. }
  217. }