LoginView.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. Debug.Log($"ShowLogin Init");
  32. packageName = UI_LoginUI.PACKAGE_NAME;
  33. _ui = UI_LoginUI.Create();
  34. Debug.Log($"ShowLogin UI_LoginUI.Create()");
  35. viewCom = _ui.target;
  36. isfullScreen = true;
  37. }
  38. protected override void OnInit()
  39. {
  40. base.OnInit();
  41. _ui.m_txtVersion.text = GameGlobal.version;
  42. Debug.Log($"ShowLogin OnInit");
  43. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  44. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  45. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  46. _ui.m_btnAge.onClick.Add(OnClickBtnAge);
  47. _ui.m_btnTapLogin.onClick.Add(OnClickBtnStart);
  48. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  49. _ui.m_loaEventa.onClick.Add(() => { FullScreenTextController.Show("event:a"); });
  50. _ui.m_loaEventb.onClick.Add(() => { FullScreenTextController.Show("event:b"); });
  51. _ui.m_loaEventc.onClick.Add(() => { FullScreenTextController.Show("event:c"); });
  52. _ui.m_btnAgree.onClick.Add(OnBtnAgreeCklick);
  53. Debug.Log($"ShowLogin OnBtnAgreeCklick");
  54. }
  55. protected override void AddEventListener()
  56. {
  57. base.AddEventListener();
  58. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  59. EventAgent.AddEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  60. EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  61. EventAgent.AddEventListener(ConstMessage.OUT_LOGIN, OnOutLoginSuccess);
  62. }
  63. protected override void OnShown()
  64. {
  65. base.OnShown();
  66. Debug.Log($"ShowLogin OnShown");
  67. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  68. Debug.Log($"ShowLogin DEFAULT");
  69. if (_sceneObject == null)
  70. {
  71. PrefabManager.Instance.InstantiateAsync(
  72. ResPathUtil.GetLoginResPath("LoginSkin1/SceneLogin"),
  73. (go) =>
  74. {
  75. _sceneObject = go;
  76. if (_sceneObject != null)
  77. {
  78. // 场景对象加载完成后的后续初始化
  79. ContinueAfterSceneLoad();
  80. }
  81. else
  82. {
  83. Debug.LogError("Failed to instantiate login scene");
  84. }
  85. });
  86. }
  87. else
  88. {
  89. // 如果场景对象已存在,直接继续初始化
  90. ContinueAfterSceneLoad();
  91. }
  92. }
  93. private void ContinueAfterSceneLoad()
  94. {
  95. Debug.Log($"ShowLogin ContinueAfterSceneLoad");
  96. // SceneController.UpdateLoginScene(_sceneObject);
  97. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  98. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  99. UpdateServer(recentlyServerInfo);
  100. _ui.m_btnAgree.selected = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false);
  101. _ui.m_btnAgree.selected = true;
  102. if (GameConfig.openTime > TimeHelper.ClientNow())
  103. {
  104. var date = DateTimeUtil.LongTimeStampToDateTime(GameConfig.openTime);
  105. string minuteText = "";
  106. if (date.Minute > 0)
  107. {
  108. minuteText = date.Minute + "分";
  109. }
  110. AlertUI.Show($" 亲爱的研究员,万世镜将于{date.Year}年{date.Month}月{date.Day}日{date.Hour}点{minuteText}开放,敬请期待!")
  111. .SetLeftButton(true, "好的", (obj) => { Application.Quit(); });
  112. return;
  113. }
  114. if (!autoLogined)
  115. {
  116. autoLogined = true;
  117. ResetLoginButton();
  118. TryLogin();
  119. }
  120. }
  121. protected override void OnHide()
  122. {
  123. autoLogined = false;
  124. if (_sceneObject != null)
  125. {
  126. PrefabManager.Instance.Restore(_sceneObject);
  127. _sceneObject = null;
  128. }
  129. base.OnHide();
  130. }
  131. protected override void RemoveEventListener()
  132. {
  133. base.RemoveEventListener();
  134. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  135. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  136. EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
  137. EventAgent.RemoveEventListener(ConstMessage.OUT_LOGIN, OnOutLoginSuccess);
  138. }
  139. private void UpdateServer(ServerInfo info)
  140. {
  141. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  142. if (serverInfosComponent.ServerInfoList.Count == 0)
  143. {
  144. _ui.m_btnChange.visible = false;
  145. return;
  146. }
  147. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  148. _ui.m_btnChange.title =
  149. string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  150. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  151. }
  152. private void OnPlatformLogined(EventContext context)
  153. {
  154. var account = (string)context.data;
  155. if (!string.IsNullOrEmpty(account))
  156. {
  157. _ui.m_btnTapLogin.visible = false;
  158. LoginController.LoginTest(account).Coroutine();
  159. }
  160. else
  161. {
  162. ViewManager.Hide<ModalStatusView>();
  163. //尝试自动登录
  164. TryLogin();
  165. }
  166. }
  167. private void OnLoginSuccess(EventContext context)
  168. {
  169. _ui.m_btnLogout.visible = true;
  170. _ui.m_btnStart.visible = true;
  171. }
  172. private void OnSeverChangeListener(EventContext context)
  173. {
  174. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  175. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  176. }
  177. private void OnBtnChangeClick()
  178. {
  179. ViewManager.Show<ServerListView>();
  180. }
  181. private void OnClickBtnNotice()
  182. {
  183. if (NoticeDataManager.Instance.LastNoticeInfo == null ||
  184. NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  185. {
  186. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  187. return;
  188. }
  189. ViewManager.Show<SystemNoticeView>(new object[]
  190. { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  191. }
  192. private void OnClickBtnStart()
  193. {
  194. TryLogin();
  195. }
  196. private void OnClickBtnLogout()
  197. {
  198. ResetLoginButton();
  199. switch (LauncherConfig.ChannelId)
  200. {
  201. case (int)ChannelID.Test:
  202. break;
  203. case (int)ChannelID.DouYou:
  204. // QDDouYouManager.Instance.LoginOutBefore();
  205. break;
  206. case (int)ChannelID.DouYouDev:
  207. break;
  208. default:
  209. break;
  210. }
  211. QDManager.Logout();
  212. }
  213. private void OnClickBtnAge()
  214. {
  215. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  216. }
  217. private void TryLogin()
  218. {
  219. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", LauncherConfig.cfgName);
  220. url = url + "?t=" + DateTime.Now.Ticks;
  221. HttpTool.Instance.Get(url, (string json) =>
  222. {
  223. LauncherConfig.InitPlatform(json);
  224. if (LauncherConfig.serverStatus == 1)
  225. {
  226. if (string.IsNullOrEmpty(LauncherConfig.statusPrompt))
  227. {
  228. LauncherConfig.statusPrompt = "游戏正在更新维护中,请稍后再试。";
  229. }
  230. AlertSystem.Show(LauncherConfig.statusPrompt)
  231. .SetLeftButton(true, "知道了", (data) => { Application.Quit(); });
  232. return;
  233. }
  234. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  235. if (serverInfosComponent.ServerInfoList.Count <= 0)
  236. {
  237. QDManager.Login();
  238. }
  239. else
  240. {
  241. if (!_ui.m_btnAgree.selected)
  242. {
  243. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意游戏用户协议、隐私保护指引、儿童隐私政策");
  244. return;
  245. }
  246. LoginController.GetRoles().Coroutine();
  247. }
  248. });
  249. }
  250. private void OnOutLoginSuccess(EventContext context)
  251. {
  252. ResetLoginButton();
  253. }
  254. private void ResetLoginButton()
  255. {
  256. _ui.m_btnLogout.visible = false;
  257. _ui.m_btnTapLogin.visible = false;
  258. _ui.m_btnStart.visible = true;
  259. }
  260. private void OnBtnAgreeCklick()
  261. {
  262. LocalCache.SetBool(LauncherConfig.LAST_LOGIN_IS_AGREE_KEY, _ui.m_btnAgree.selected);
  263. }
  264. }
  265. }