LoginInputView.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. }
  38. protected override void OnShown()
  39. {
  40. base.OnShown();
  41. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY);
  42. if (account != null)
  43. {
  44. _ui.m_inputAccount.text = account;
  45. }
  46. InitChanelBox();
  47. }
  48. protected override void OnHide()
  49. {
  50. base.OnHide();
  51. }
  52. protected override void AddEventListener()
  53. {
  54. base.AddEventListener();
  55. EventAgent.AddEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  56. }
  57. protected override void RemoveEventListener()
  58. {
  59. base.RemoveEventListener();
  60. EventAgent.RemoveEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  61. }
  62. private void onChangedCanal()
  63. {
  64. LauncherConfig.ChannelId = int.Parse(_ui.m_boxChooseCanal.value);
  65. ET.Log.Debug("打印测试======选择的渠道==========" + (_ui.m_boxChooseCanal.value));
  66. if(_ui.m_boxChooseCanal.value == (int)ChannelID.Test + "")
  67. {
  68. AlertSystem.Show("切换其他渠道后不支持切回测试渠道,请重启游戏!")
  69. .SetRightButton(true, "退出游戏", (obj) => { Application.Quit(); });
  70. }
  71. else
  72. {
  73. GameConfig.LoginAddress = "http://10.108.64.127:10005";
  74. }
  75. ET.Log.Debug($"===选择的渠道=== {_ui.m_boxChooseCanal.value} {GameConfig.LoginAddress}");
  76. }
  77. private void OnClickBtnSure()
  78. {
  79. var account = _ui.m_inputAccount.text;
  80. var password = _ui.m_inputPassword.text;
  81. if (string.IsNullOrEmpty(account))
  82. {
  83. PromptController.Instance.ShowFloatTextPrompt("请输入账号");
  84. return;
  85. }
  86. if (!string.IsNullOrEmpty(password))
  87. {
  88. LoginController.Login(account, password).Coroutine();
  89. }
  90. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  91. {
  92. LoginController.LoginTest(account).Coroutine();
  93. }
  94. else
  95. {
  96. PromptController.Instance.ShowFloatTextPrompt("请输入密码");
  97. }
  98. }
  99. private void OnClickBtnCancel()
  100. {
  101. this.Hide();
  102. }
  103. private void OnClickBtnRegister()
  104. {
  105. ViewManager.Show<RegisterView>();
  106. }
  107. private void OnLoginFail(EventContext context)
  108. {
  109. string account = (string)context.data;
  110. _ui.m_inputAccount.text = account;
  111. }
  112. private void InitChanelBox()
  113. {
  114. #if !UNITY_EDITOR
  115. _ui.m_boxChooseCanal.visible = false;
  116. return;
  117. #endif
  118. _ui.m_boxChooseCanal.visible = LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL;
  119. if (!_ui.m_boxChooseCanal.visible) return;
  120. var enumType = typeof(ChannelID);
  121. var arr = Enum.GetValues(enumType);
  122. List<string> items = new List<string>();
  123. List<string> numbers = new List<string>();
  124. foreach (var value in arr)
  125. {
  126. var fieldInfo = enumType.GetField((value).ToString());
  127. if (fieldInfo != null && Attribute.IsDefined(fieldInfo, typeof(DescriptionAttribute)))
  128. {
  129. DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute));
  130. items.Add(attribute.Description);
  131. numbers.Add(Convert.ToInt32(value).ToString());
  132. }
  133. }
  134. _ui.m_boxChooseCanal.items = items.ToArray();
  135. _ui.m_boxChooseCanal.values = numbers.ToArray();
  136. _ui.m_boxChooseCanal.value = LauncherConfig.ChannelId + "";
  137. _ui.m_boxChooseCanal.onChanged.Add(onChangedCanal);
  138. }
  139. }
  140. }