LoginView.cs 10 KB

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