LoginInputView.cs 9.3 KB

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