LoginView.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Login;
  4. using ET;
  5. namespace GFGGame
  6. {
  7. public class LoginView : BaseView
  8. {
  9. private UI_LoginUI _ui;
  10. private GameObject _scenePrefab;
  11. private GameObject _sceneObject;
  12. public override void Dispose()
  13. {
  14. _ui = null;
  15. if (_scenePrefab != null)
  16. {
  17. GameObject.Destroy(_scenePrefab);
  18. _scenePrefab = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void Init()
  23. {
  24. base.Init();
  25. packageName = UI_LoginUI.PACKAGE_NAME;
  26. _ui = UI_LoginUI.Create();
  27. viewCom = _ui.target;
  28. isfullScreen = true;
  29. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneMain"));
  30. }
  31. protected override void OnInit()
  32. {
  33. base.OnInit();
  34. _ui.m_txtVersion.text = GameGlobal.version;
  35. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  36. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  37. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  38. _ui.m_imgLogo.visible = LauncherConfig.netType != LauncherConfig.EnumNetType.TEMP;
  39. EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
  40. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  41. }
  42. protected override void OnShown()
  43. {
  44. base.OnShown();
  45. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  46. if (_sceneObject == null)
  47. {
  48. _sceneObject = GameObject.Instantiate(_scenePrefab);
  49. }
  50. SceneController.UpdateLoginScene(_sceneObject);
  51. if (!_ui.m_btnLogout.visible)
  52. {
  53. ViewManager.Show<LoginInputView>();
  54. }
  55. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  56. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  57. UpdateServer(recentlyServerInfo);
  58. //尝试自动登录
  59. if (serverInfosComponent.ServerInfoList.Count <= 0)
  60. {
  61. OnClickBtnStart();
  62. }
  63. }
  64. protected override void OnHide()
  65. {
  66. if (_sceneObject != null)
  67. {
  68. GameObject.Destroy(_sceneObject);
  69. _sceneObject = null;
  70. }
  71. base.OnHide();
  72. }
  73. private void UpdateServer(ServerInfo info)
  74. {
  75. _ui.m_btnLogout.visible = GameController.CheckLoginCache(false);
  76. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  77. if (serverInfosComponent.ServerInfoList.Count == 0)
  78. {
  79. _ui.m_btnChange.visible = false;
  80. return;
  81. }
  82. _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1;
  83. _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName);
  84. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
  85. }
  86. private void OnSeverChangeListener(EventContext context)
  87. {
  88. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  89. UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]);
  90. }
  91. private void OnBtnChangeClick()
  92. {
  93. ViewManager.Show<ServerListView>();
  94. }
  95. private void OnClickBtnNotice()
  96. {
  97. if (NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0)
  98. {
  99. PromptController.Instance.ShowFloatTextPrompt("暂无公告发布");
  100. return;
  101. }
  102. ViewManager.Show<SystemNoticeView>();
  103. }
  104. private async void OnClickBtnStart()
  105. {
  106. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  107. if (serverInfosComponent.ServerInfoList.Count <= 0)
  108. {
  109. if (!GameController.CheckLoginCache(true))
  110. {
  111. ViewManager.Show<LoginInputView>();
  112. }
  113. }
  114. else
  115. {
  116. await LoginController.GetRoles();
  117. }
  118. }
  119. private void OnClickBtnLogout()
  120. {
  121. GameController.QuitToLoginView(true);
  122. }
  123. }
  124. }