LoginView.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Login;
  4. using ET;
  5. using TapTap.Bootstrap;
  6. using System;
  7. using TapTap.Common;
  8. namespace GFGGame
  9. {
  10. public class LoginView : BaseView
  11. {
  12. private UI_LoginUI _ui;
  13. private GameObject _scenePrefab;
  14. private GameObject _sceneObject;
  15. public override void Dispose()
  16. {
  17. _ui = null;
  18. if (_scenePrefab != null)
  19. {
  20. GameObject.Destroy(_scenePrefab);
  21. _scenePrefab = 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. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneMain"));
  33. }
  34. protected override void OnInit()
  35. {
  36. base.OnInit();
  37. _ui.m_txtVersion.text = GameGlobal.version;
  38. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  39. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  40. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  41. _ui.m_btnAge.onClick.Add(OnClickBtnAge);
  42. _ui.m_btnTapLogin.onClick.Add(OnClickBtnTabLogin);
  43. _ui.m_imgLogo.visible = LauncherConfig.netType != LauncherConfig.EnumNetType.TEMP;
  44. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();
  49. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  50. if (_sceneObject == null)
  51. {
  52. _sceneObject = GameObject.Instantiate(_scenePrefab);
  53. }
  54. SceneController.UpdateLoginScene(_sceneObject);
  55. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  56. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  57. UpdateServer(recentlyServerInfo);
  58. _ui.m_btnStart.visible = false;
  59. _ui.m_btnTapLogin.visible = false;
  60. _ui.m_btnLogout.visible = false;
  61. InitLoginStatus(serverInfosComponent).Coroutine();
  62. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  63. EventAgent.AddEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  64. }
  65. protected override void OnHide()
  66. {
  67. EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  68. EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
  69. if (_sceneObject != null)
  70. {
  71. GameObject.Destroy(_sceneObject);
  72. _sceneObject = null;
  73. }
  74. base.OnHide();
  75. }
  76. private async ETTask InitLoginStatus(ServerInfosComponent serverInfosComponent)
  77. {
  78. if (PlatformManager.IsTaptap)//taptap平台
  79. {
  80. var success = await PlatformTapManager.Instance.LoginCache();
  81. _ui.m_btnTapLogin.visible = !success;
  82. }
  83. else//自有登录
  84. {
  85. _ui.m_btnStart.visible = true;
  86. //尝试自动登录
  87. if (serverInfosComponent.ServerInfoList.Count <= 0)
  88. {
  89. OnClickBtnStart();
  90. }
  91. }
  92. }
  93. private void OnClickBtnTabLogin()
  94. {
  95. OnClickBtnTabLoginAsync().Coroutine();
  96. }
  97. private async ETTask OnClickBtnTabLoginAsync()
  98. {
  99. var success = await PlatformTapManager.Instance.Login();
  100. _ui.m_btnTapLogin.visible = !success;
  101. }
  102. private void UpdateServer(ServerInfo info)
  103. {
  104. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  105. if (serverInfosComponent.ServerInfoList.Count == 0)
  106. {
  107. _ui.m_btnChange.visible = false;
  108. return;
  109. }
  110. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  111. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  112. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  113. }
  114. private void OnLoginSuccess(EventContext context)
  115. {
  116. _ui.m_btnLogout.visible = true;
  117. _ui.m_btnStart.visible = true;
  118. }
  119. private void OnSeverChangeListener(EventContext context)
  120. {
  121. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  122. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  123. }
  124. private void OnBtnChangeClick()
  125. {
  126. ViewManager.Show<ServerListView>();
  127. }
  128. private void OnClickBtnNotice()
  129. {
  130. if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  131. {
  132. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  133. return;
  134. }
  135. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  136. }
  137. private void OnClickBtnStart()
  138. {
  139. if (PlatformManager.IsTaptap)//taptap平台
  140. {
  141. LoginController.GetRoles().Coroutine();
  142. }
  143. else
  144. {
  145. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  146. if (serverInfosComponent.ServerInfoList.Count <= 0)
  147. {
  148. bool login = GameController.CheckLoginCache(true);
  149. if (!login)
  150. {
  151. ViewManager.Show<LoginInputView>();
  152. }
  153. }
  154. else
  155. {
  156. LoginController.GetRoles().Coroutine();
  157. }
  158. }
  159. }
  160. private void OnClickBtnLogout()
  161. {
  162. GameController.QuitToLoginView(true);
  163. }
  164. private void OnClickBtnAge()
  165. {
  166. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  167. }
  168. }
  169. }