LoginView.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  45. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  46. }
  47. protected override void OnShown()
  48. {
  49. base.OnShown();
  50. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  51. if (_sceneObject == null)
  52. {
  53. _sceneObject = GameObject.Instantiate(_scenePrefab);
  54. }
  55. SceneController.UpdateLoginScene(_sceneObject);
  56. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  57. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  58. UpdateServer(recentlyServerInfo);
  59. _ui.m_btnStart.visible = false;
  60. _ui.m_btnTapLogin.visible = false;
  61. InitLoginStatus(serverInfosComponent).Coroutine();
  62. }
  63. protected override void OnHide()
  64. {
  65. if (_sceneObject != null)
  66. {
  67. GameObject.Destroy(_sceneObject);
  68. _sceneObject = null;
  69. }
  70. base.OnHide();
  71. }
  72. private async ETTask InitLoginStatus(ServerInfosComponent serverInfosComponent)
  73. {
  74. if (PlatformManager.IsTaptap)//taptap平台
  75. {
  76. TDSUser currentUser = await TDSUser.GetCurrent();
  77. if (null == currentUser)
  78. {
  79. _ui.m_btnTapLogin.visible = true;
  80. }
  81. else
  82. {
  83. LoginController.LoginTest(currentUser.ObjectId).Coroutine();
  84. }
  85. }
  86. //else//自有登录
  87. //{
  88. _ui.m_btnStart.visible = true;
  89. //尝试自动登录
  90. if (serverInfosComponent.ServerInfoList.Count <= 0)
  91. {
  92. OnClickBtnStart();
  93. }
  94. if (!_ui.m_btnLogout.visible)
  95. {
  96. ViewManager.Show<LoginInputView>();
  97. }
  98. //}
  99. }
  100. private void OnClickBtnTabLogin()
  101. {
  102. OnClickBtnTabLoginAsync().Coroutine();
  103. }
  104. private async ETTask OnClickBtnTabLoginAsync()
  105. {
  106. try
  107. {
  108. var tdsUser = await TDSUser.LoginWithTapTap();
  109. Log.Debug($"login Success:{tdsUser}");
  110. LoginController.LoginTest(tdsUser.ObjectId).Coroutine();
  111. }
  112. catch (Exception e)
  113. {
  114. if (e is TapException error)
  115. {
  116. Log.Error($"Login Error:{error.code} message:{error.message}");
  117. PromptController.Instance.ShowFloatTextPrompt(error.message);
  118. }
  119. else
  120. {
  121. Log.Error($"Login Error:{e}");
  122. PromptController.Instance.ShowFloatTextPrompt("登录异常");
  123. }
  124. }
  125. }
  126. private void UpdateServer(ServerInfo info)
  127. {
  128. //登录成功后更新注销按钮显示
  129. _ui.m_btnLogout.visible = GameController.CheckLoginCache(false);
  130. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  131. if (serverInfosComponent.ServerInfoList.Count == 0)
  132. {
  133. _ui.m_btnChange.visible = false;
  134. return;
  135. }
  136. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  137. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  138. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  139. }
  140. private void OnSeverChangeListener(EventContext context)
  141. {
  142. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  143. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  144. }
  145. private void OnBtnChangeClick()
  146. {
  147. ViewManager.Show<ServerListView>();
  148. }
  149. private void OnClickBtnNotice()
  150. {
  151. if (NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  152. {
  153. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  154. return;
  155. }
  156. ViewManager.Show<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
  157. }
  158. private async void OnClickBtnStart()
  159. {
  160. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  161. if (serverInfosComponent.ServerInfoList.Count <= 0)
  162. {
  163. if (!GameController.CheckLoginCache(true))
  164. {
  165. ViewManager.Show<LoginInputView>();
  166. }
  167. }
  168. else
  169. {
  170. await LoginController.GetRoles();
  171. }
  172. }
  173. private void OnClickBtnLogout()
  174. {
  175. GameController.QuitToLoginView(true);
  176. }
  177. private void OnClickBtnAge()
  178. {
  179. ViewManager.Show<SystemNoticeView>(new object[] { LoginController.ageTipsTitle, LoginController.ageTips });
  180. }
  181. }
  182. }