LoginInputView.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using UI.Login;
  2. using FairyGUI;
  3. using UnityEngine;
  4. using System.ComponentModel;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace GFGGame
  8. {
  9. public class LoginInputView : BaseWindow
  10. {
  11. private UI_LoginInputUI _ui;
  12. public override void Dispose()
  13. {
  14. if (_ui != null)
  15. {
  16. _ui.Dispose();
  17. _ui = null;
  18. }
  19. base.Dispose();
  20. }
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. packageName = UI_LoginInputUI.PACKAGE_NAME;
  25. _ui = UI_LoginInputUI.Create();
  26. this.viewCom = _ui.target;
  27. this.viewCom.Center();
  28. this.modal = true;
  29. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  30. _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
  31. _ui.m_btnRegister.onClick.Add(OnClickBtnRegister);
  32. _ui.m_inputAccount.restrict = "[0-9A-Za-z_]";
  33. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  34. {
  35. _ui.m_inputPassword.promptText = "[color=#B8A492]当前支持免密登录[/color]";
  36. }
  37. InitChanelBox();
  38. }
  39. protected override void OnShown()
  40. {
  41. base.OnShown();
  42. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY);
  43. if (account != null)
  44. {
  45. _ui.m_inputAccount.text = account;
  46. }
  47. UpdateChannelBox(false);
  48. }
  49. protected override void OnHide()
  50. {
  51. base.OnHide();
  52. }
  53. protected override void AddEventListener()
  54. {
  55. base.AddEventListener();
  56. EventAgent.AddEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  57. }
  58. protected override void RemoveEventListener()
  59. {
  60. base.RemoveEventListener();
  61. EventAgent.RemoveEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  62. }
  63. private void OnClickBtnSure()
  64. {
  65. var account = _ui.m_inputAccount.text;
  66. var password = _ui.m_inputPassword.text;
  67. if (string.IsNullOrEmpty(account))
  68. {
  69. PromptController.Instance.ShowFloatTextPrompt("请输入账号");
  70. return;
  71. }
  72. if (!string.IsNullOrEmpty(password))
  73. {
  74. LoginController.Login(account, password).Coroutine();
  75. }
  76. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  77. {
  78. LoginController.LoginTest(account).Coroutine();
  79. }
  80. else
  81. {
  82. PromptController.Instance.ShowFloatTextPrompt("请输入密码");
  83. }
  84. }
  85. private void OnClickBtnCancel()
  86. {
  87. this.Hide();
  88. }
  89. private void OnClickBtnRegister()
  90. {
  91. ViewManager.Show<RegisterView>();
  92. }
  93. private void OnLoginFail(EventContext context)
  94. {
  95. string account = (string)context.data;
  96. _ui.m_inputAccount.text = account;
  97. }
  98. private void InitChanelBox()
  99. {
  100. #if !UNITY_EDITOR
  101. _ui.m_boxChooseCanal.visible = false;
  102. return;
  103. #endif
  104. _ui.m_boxChooseCanal.visible = LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL;
  105. if (!_ui.m_boxChooseCanal.visible) return;
  106. var enumType = typeof(ChannelID);
  107. var arr = Enum.GetValues(enumType);
  108. List<string> items = new List<string>();
  109. List<string> numbers = new List<string>();
  110. foreach (var value in arr)
  111. {
  112. var fieldInfo = enumType.GetField((value).ToString());
  113. if (fieldInfo != null && Attribute.IsDefined(fieldInfo, typeof(DescriptionAttribute)))
  114. {
  115. DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute));
  116. items.Add(attribute.Description);
  117. numbers.Add(Convert.ToInt32(value).ToString());
  118. }
  119. }
  120. _ui.m_boxChooseCanal.items = items.ToArray();
  121. _ui.m_boxChooseCanal.values = numbers.ToArray();
  122. _ui.m_boxChooseCanal.value = LauncherConfig.ChannelId + "";
  123. _ui.m_boxChooseCanal.onChanged.Add(onBoxChannelChanged);
  124. }
  125. private void onBoxChannelChanged()
  126. {
  127. UpdateChannelBox(true);
  128. }
  129. private void UpdateChannelBox(bool showAlert = true)
  130. {
  131. if (!_ui.m_boxChooseCanal.visible) return;
  132. LauncherConfig.ChannelId = int.Parse(_ui.m_boxChooseCanal.value);
  133. ET.Log.Debug("打印测试======选择的渠道==========" + (_ui.m_boxChooseCanal.value));
  134. if (_ui.m_boxChooseCanal.value == (int)ChannelID.Test + "")
  135. {
  136. if (showAlert)
  137. {
  138. AlertSystem.Show("切换其他渠道后不支持切回测试渠道,请重启游戏!");
  139. }
  140. }
  141. else
  142. {
  143. GameConfig.LoginAddress = "http://10.108.64.127:10005";
  144. }
  145. ET.Log.Debug($"===选择的渠道=== {_ui.m_boxChooseCanal.value} {GameConfig.LoginAddress}");
  146. }
  147. }
  148. }