LoginView.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Login;
  4. using ET;
  5. using GFGGame.Launcher;
  6. using System;
  7. namespace GFGGame
  8. {
  9. public class LoginView : BaseView
  10. {
  11. private UI_LoginUI _ui;
  12. private GameObject _sceneObject;
  13. private bool autoLogined;
  14. public override void Dispose()
  15. {
  16. if (_sceneObject != null)
  17. {
  18. GameObject.DestroyImmediate(_sceneObject);
  19. _sceneObject = null;
  20. }
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void Init()
  29. {
  30. base.Init();
  31. packageName = UI_LoginUI.PACKAGE_NAME;
  32. _ui = UI_LoginUI.Create();
  33. viewCom = _ui.target;
  34. isfullScreen = true;
  35. }
  36. protected override void OnInit()
  37. {
  38. base.OnInit();
  39. _ui.m_txtVersion.text = GameGlobal.version;
  40. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  41. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  42. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  43. _ui.m_btnAge.onClick.Add(OnClickBtnAge);
  44. _ui.m_btnTapLogin.onClick.Add(OnClickBtnStart);
  45. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  46. _ui.m_loaEventa.onClick.Add(() => { FullScreenTextController.Show("event:a"); });
  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_LOGINED, OnPlatformLogined);
  57. EventAgent.AddEventListener(ConstMessage.OUT_LOGIN, OnOutLoginSuccess);
  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 =
  66. PrefabManager.Instance.InstantiateSync(ResPathUtil.GetLoginResPath("LoginSkin1/SceneLogin"));
  67. }
  68. // SceneController.UpdateLoginScene(_sceneObject);
  69. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  70. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  71. UpdateServer(recentlyServerInfo);
  72. _ui.m_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false);
  73. _ui.m_btnAgree.selected = true;
  74. if (GameConfig.openTime > TimeHelper.ClientNow())
  75. {
  76. var date = DateTimeUtil.LongTimeStampToDateTime(GameConfig.openTime);
  77. string minuteText = "";
  78. if (date.Minute > 0)
  79. {
  80. minuteText = date.Minute + "分";
  81. }
  82. AlertUI.Show($" 亲爱的研究员,万世镜将于{date.Year}年{date.Month}月{date.Day}日{date.Hour}点{minuteText}开放,敬请期待!")
  83. .SetLeftButton(true, "好的", (obj) => { Application.Quit(); });
  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. EventAgent.RemoveEventListener(ConstMessage.OUT_LOGIN, OnOutLoginSuccess);
  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 =
  121. string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  122. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  123. }
  124. private void OnPlatformLogined(EventContext context)
  125. {
  126. var account = (string)context.data;
  127. if (!string.IsNullOrEmpty(account))
  128. {
  129. _ui.m_btnTapLogin.visible = false;
  130. LoginController.LoginTest(account).Coroutine();
  131. }
  132. else
  133. {
  134. ViewManager.Hide<ModalStatusView>();
  135. //尝试自动登录
  136. TryLogin();
  137. }
  138. }
  139. private void OnLoginSuccess(EventContext context)
  140. {
  141. _ui.m_btnLogout.visible = true;
  142. _ui.m_btnStart.visible = true;
  143. }
  144. private void OnSeverChangeListener(EventContext context)
  145. {
  146. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  147. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  148. }
  149. private void OnBtnChangeClick()
  150. {
  151. ViewManager.Show<ServerListView>();
  152. }
  153. private void OnClickBtnNotice()
  154. {
  155. if (NoticeDataManager.Instance.LastNoticeInfo == null ||
  156. NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  157. {
  158. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  159. return;
  160. }
  161. ViewManager.Show<SystemNoticeView>(new object[]
  162. { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  163. }
  164. private void OnClickBtnStart()
  165. {
  166. TryLogin();
  167. }
  168. private void OnClickBtnLogout()
  169. {
  170. ResetLoginButton();
  171. switch (LauncherConfig.ChannelId)
  172. {
  173. case (int)ChannelID.Test:
  174. break;
  175. case (int)ChannelID.DouYou:
  176. QDDouYouManager.Instance.LoginOutBefore();
  177. break;
  178. default:
  179. break;
  180. }
  181. QDManager.Logout();
  182. }
  183. private void OnClickBtnAge()
  184. {
  185. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  186. }
  187. private void TryLogin()
  188. {
  189. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", LauncherConfig.cfgName);
  190. url = url + "?t=" + DateTime.Now.Ticks;
  191. HttpTool.Instance.Get(url, (string json) =>
  192. {
  193. LauncherConfig.InitPlatform(json);
  194. if (LauncherConfig.serverStatus == 1)
  195. {
  196. if (string.IsNullOrEmpty(LauncherConfig.statusPrompt))
  197. {
  198. LauncherConfig.statusPrompt = "游戏正在更新维护中,请稍后再试。";
  199. }
  200. AlertSystem.Show(LauncherConfig.statusPrompt)
  201. .SetLeftButton(true, "知道了", (data) => { Application.Quit(); });
  202. return;
  203. }
  204. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  205. if (serverInfosComponent.ServerInfoList.Count <= 0)
  206. {
  207. QDManager.Login();
  208. }
  209. else
  210. {
  211. if (!_ui.m_btnAgree.selected)
  212. {
  213. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  214. return;
  215. }
  216. LoginController.GetRoles().Coroutine();
  217. }
  218. });
  219. }
  220. private void OnOutLoginSuccess(EventContext context)
  221. {
  222. ResetLoginButton();
  223. }
  224. private void ResetLoginButton()
  225. {
  226. _ui.m_btnLogout.visible = false;
  227. _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
  228. _ui.m_btnStart.visible = !QDManager.IsTaptap;
  229. }
  230. private void OnBtnAgreeCklick()
  231. {
  232. LocalCache.SetBool(LauncherConfig.LAST_LOGIN_IS_AGREE_KEY, _ui.m_btnAgree.selected);
  233. }
  234. }
  235. }