LoginInputView.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. private List<AccountPasswordModel> _accountPasswordList;
  13. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. _ui = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. packageName = UI_LoginInputUI.PACKAGE_NAME;
  26. _ui = UI_LoginInputUI.Create();
  27. this.viewCom = _ui.target;
  28. this.viewCom.Center();
  29. this.modal = true;
  30. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  31. _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
  32. _ui.m_btnRegister.onClick.Add(OnClickBtnRegister);
  33. _ui.m_btnSkipUpInfo.onClick.Add(OnClickBtnOpenZhAccount);
  34. _ui.m_comAccount.m_selBtin.onClick.Add(OnClickOpenAccountListBtn);
  35. _ui.m_comAccount.m_txtAccount.restrict = "[0-9A-Za-z_]";
  36. _ui.m_comAccount.m_list.itemRenderer = RenderListItem;
  37. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  38. {
  39. _ui.m_inputPassword.promptText = "[color=#B8A492]当前支持免密登录[/color]";
  40. }
  41. InitChanelBox();
  42. }
  43. protected override void OnShown()
  44. {
  45. base.OnShown();
  46. _accountPasswordList = AccountManager.Instance.GetAccounts();
  47. string account = null;
  48. string password = null;
  49. if (_accountPasswordList != null && _accountPasswordList.Count > 0)
  50. {
  51. account = _accountPasswordList[0].Account;
  52. password = _accountPasswordList[0].Password;
  53. }
  54. if (account != null)
  55. {
  56. _ui.m_comAccount.m_txtAccount.text = account;
  57. }
  58. if (password != null)
  59. {
  60. _ui.m_inputPassword.text = password;
  61. }
  62. UpdateChannelBox(false);
  63. }
  64. protected override void OnHide()
  65. {
  66. base.OnHide();
  67. }
  68. protected override void AddEventListener()
  69. {
  70. base.AddEventListener();
  71. EventAgent.AddEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  72. }
  73. protected override void RemoveEventListener()
  74. {
  75. base.RemoveEventListener();
  76. EventAgent.RemoveEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  77. }
  78. private void OnClickBtnOpenZhAccount()
  79. {
  80. ViewManager.Show<ZhaoHuiAccountView>();
  81. }
  82. private void OnClickBtnOpenZhUpPassword(string account)
  83. {
  84. ViewManager.Show<ZhaoHuiPasswordView>(account);
  85. }
  86. private void OnClickBtnSure()
  87. {
  88. var account = _ui.m_comAccount.m_txtAccount.text;
  89. var password = _ui.m_inputPassword.text;
  90. if (string.IsNullOrEmpty(account))
  91. {
  92. PromptController.Instance.ShowFloatTextPrompt("请输入账号");
  93. return;
  94. }
  95. if (!string.IsNullOrEmpty(password))
  96. {
  97. LoginController.Login(account, password).Coroutine();
  98. }
  99. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  100. {
  101. LoginController.LoginTest(account).Coroutine();
  102. }
  103. else
  104. {
  105. PromptController.Instance.ShowFloatTextPrompt("请输入密码");
  106. }
  107. }
  108. private void OnClickBtnCancel()
  109. {
  110. this.Hide();
  111. }
  112. private void OnClickBtnRegister()
  113. {
  114. ViewManager.Show<RegisterView>();
  115. }
  116. private void OnClickOpenAccountListBtn()
  117. {
  118. if (_accountPasswordList.Count == 0)
  119. {
  120. _ui.m_comAccount.m_list.selectedIndex = 0;
  121. return;
  122. }
  123. if (_ui.m_comAccount.m_c1.selectedIndex == 0)
  124. {
  125. //显示账号缓存列表
  126. OnShowAccountList();
  127. }
  128. else
  129. {
  130. //隐藏账号缓存列表
  131. OnHideAccountList();
  132. }
  133. }
  134. //显示账号缓存列表
  135. private void OnShowAccountList()
  136. {
  137. _accountPasswordList = AccountManager.Instance.GetAccounts();
  138. _ui.m_comAccount.m_list.numItems = _accountPasswordList.Count;
  139. _ui.m_comAccount.m_c1.selectedIndex = 1;
  140. }
  141. //隐藏账号缓存列表
  142. private void OnHideAccountList()
  143. {
  144. _ui.m_comAccount.m_c1.selectedIndex = 0;
  145. }
  146. //绑定数据到账号缓存列表
  147. private void RenderListItem(int index, GObject obj)
  148. {
  149. AccountPasswordModel accountPassword = _accountPasswordList[index];
  150. UI_ButAccountItem item = UI_ButAccountItem.Proxy(obj);
  151. item.m_txtAccountItem.text = accountPassword.Account;
  152. item.target.data = accountPassword;
  153. item.target.onClick.Add(OnClickSelAccount);
  154. item.m_btnDel.data = accountPassword.Account;
  155. item.m_btnDel.onClick.Add(OnClickDelAccountCache);
  156. UI_ButAccountItem.ProxyEnd();
  157. }
  158. //从账号缓存列表中选择账号
  159. private void OnClickSelAccount(EventContext context)
  160. {
  161. GObject obj = context.sender as GObject;
  162. AccountPasswordModel accountPassword = obj.data as AccountPasswordModel;
  163. _ui.m_comAccount.m_txtAccount.text = accountPassword?.Account;
  164. _ui.m_inputPassword.text = accountPassword?.Password;
  165. OnHideAccountList();
  166. }
  167. //删除账号缓存列表
  168. private void OnClickDelAccountCache(EventContext context)
  169. {
  170. GObject obj = context.sender as GObject;
  171. string account = obj.data.ToString();
  172. AccountManager.Instance.DeleteAccount(account);
  173. _accountPasswordList = AccountManager.Instance.GetAccounts();
  174. _ui.m_comAccount.m_list.numItems = _accountPasswordList.Count;
  175. if (_accountPasswordList.Count == 0)
  176. {
  177. _ui.m_comAccount.m_list.selectedIndex = 0;
  178. }
  179. if (_accountPasswordList.Count == 0)
  180. {
  181. _ui.m_comAccount.m_txtAccount.text = null;
  182. _ui.m_inputPassword.text = null;
  183. }
  184. else
  185. {
  186. _ui.m_comAccount.m_txtAccount.text = _accountPasswordList[0].Account;
  187. _ui.m_inputPassword.text = _accountPasswordList[0].Password;
  188. }
  189. }
  190. private void OnLoginFail(EventContext context)
  191. {
  192. string account = (string)context.data;
  193. _ui.m_comAccount.m_txtAccount.text = account;
  194. }
  195. private void InitChanelBox()
  196. {
  197. #if !UNITY_EDITOR
  198. _ui.m_boxChooseCanal.visible = false;
  199. return;
  200. #endif
  201. _ui.m_boxChooseCanal.visible = LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL;
  202. if (!_ui.m_boxChooseCanal.visible) return;
  203. var enumType = typeof(ChannelID);
  204. var arr = Enum.GetValues(enumType);
  205. List<string> items = new List<string>();
  206. List<string> numbers = new List<string>();
  207. foreach (var value in arr)
  208. {
  209. var fieldInfo = enumType.GetField((value).ToString());
  210. if (fieldInfo != null && Attribute.IsDefined(fieldInfo, typeof(DescriptionAttribute)))
  211. {
  212. DescriptionAttribute attribute =
  213. (DescriptionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute));
  214. items.Add(attribute.Description);
  215. numbers.Add(Convert.ToInt32(value).ToString());
  216. }
  217. }
  218. _ui.m_boxChooseCanal.items = items.ToArray();
  219. _ui.m_boxChooseCanal.values = numbers.ToArray();
  220. _ui.m_boxChooseCanal.value = LauncherConfig.ChannelId + "";
  221. _ui.m_boxChooseCanal.onChanged.Add(onBoxChannelChanged);
  222. }
  223. private void onBoxChannelChanged()
  224. {
  225. UpdateChannelBox(true);
  226. }
  227. private void UpdateChannelBox(bool showAlert = true)
  228. {
  229. if (!_ui.m_boxChooseCanal.visible) return;
  230. LauncherConfig.ChannelId = int.Parse(_ui.m_boxChooseCanal.value);
  231. ET.Log.Debug("打印测试======选择的渠道==========" + (_ui.m_boxChooseCanal.value));
  232. if (_ui.m_boxChooseCanal.value == (int)ChannelID.Test + "")
  233. {
  234. if (showAlert)
  235. {
  236. AlertSystem.Show("切换其他渠道后不支持切回测试渠道,请重启游戏!");
  237. }
  238. }
  239. else
  240. {
  241. GameConfig.LoginAddress = "http://10.108.64.127:10005";
  242. }
  243. ET.Log.Debug($"===选择的渠道=== {_ui.m_boxChooseCanal.value} {GameConfig.LoginAddress}");
  244. }
  245. }
  246. }