using UI.Login; using FairyGUI; using UnityEngine; using System.ComponentModel; using System; using System.Collections.Generic; namespace GFGGame { public class LoginInputView : BaseWindow { private UI_LoginInputUI _ui; private List _accountPasswordList; public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_LoginInputUI.PACKAGE_NAME; _ui = UI_LoginInputUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; _ui.m_btnSure.onClick.Add(OnClickBtnSure); _ui.m_btnCancel.onClick.Add(OnClickBtnCancel); _ui.m_btnRegister.onClick.Add(OnClickBtnRegister); _ui.m_btnSkipAccount.onClick.Add(OnClickBtnOpenZhAccount); _ui.m_btnSkipPasword.onClick.Add(OnClickBtnOpenZhUpPassword); _ui.m_comAccount.m_selBtin.onClick.Add(OnClickOpenAccountListBtn); _ui.m_comAccount.m_txtAccount.restrict = "[0-9A-Za-z_]"; _ui.m_comAccount.m_list.itemRenderer = RenderListItem; if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL) { _ui.m_inputPassword.promptText = "[color=#B8A492]当前支持免密登录[/color]"; } InitChanelBox(); } protected override void OnShown() { base.OnShown(); _accountPasswordList = AccountManager.Instance.GetAccounts(); string account = null; string password = null; if (_accountPasswordList != null && _accountPasswordList.Count > 0) { account = _accountPasswordList[0].Account; password = _accountPasswordList[0].Password; } if (account != null) { _ui.m_comAccount.m_txtAccount.text = account; } if (password != null) { _ui.m_inputPassword.text = password; } UpdateChannelBox(false); } protected override void OnHide() { base.OnHide(); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail); } private void OnClickBtnOpenZhAccount() { ViewManager.Show(); } private void OnClickBtnOpenZhUpPassword(EventContext context) { string account = context.data as string; ViewManager.Show(account); } private void OnClickBtnSure() { var account = _ui.m_comAccount.m_txtAccount.text; var password = _ui.m_inputPassword.text; if (string.IsNullOrEmpty(account)) { PromptController.Instance.ShowFloatTextPrompt("请输入账号"); return; } if (!string.IsNullOrEmpty(password)) { LoginController.Login(account, password).Coroutine(); } else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL) { LoginController.Login(account, password).Coroutine(); } else { PromptController.Instance.ShowFloatTextPrompt("请输入密码"); } } private void OnClickBtnCancel() { this.Hide(); } private void OnClickBtnRegister() { ViewManager.Show(); } private void OnClickOpenAccountListBtn() { if (_accountPasswordList.Count == 0) { _ui.m_comAccount.m_list.selectedIndex = 0; return; } if (_ui.m_comAccount.m_c1.selectedIndex == 0) { //显示账号缓存列表 OnShowAccountList(); } else { //隐藏账号缓存列表 OnHideAccountList(); } } //显示账号缓存列表 private void OnShowAccountList() { _accountPasswordList = AccountManager.Instance.GetAccounts(); _ui.m_comAccount.m_list.numItems = _accountPasswordList.Count; _ui.m_comAccount.m_c1.selectedIndex = 1; } //隐藏账号缓存列表 private void OnHideAccountList() { _ui.m_comAccount.m_c1.selectedIndex = 0; } //绑定数据到账号缓存列表 private void RenderListItem(int index, GObject obj) { AccountPasswordModel accountPassword = _accountPasswordList[index]; UI_ButAccountItem item = UI_ButAccountItem.Proxy(obj); item.m_txtAccountItem.text = accountPassword.Account; item.target.data = accountPassword; item.target.onClick.Add(OnClickSelAccount); item.m_btnDel.data = accountPassword.Account; item.m_btnDel.onClick.Add(OnClickDelAccountCache); UI_ButAccountItem.ProxyEnd(); } //从账号缓存列表中选择账号 private void OnClickSelAccount(EventContext context) { GObject obj = context.sender as GObject; AccountPasswordModel accountPassword = obj.data as AccountPasswordModel; _ui.m_comAccount.m_txtAccount.text = accountPassword?.Account; _ui.m_inputPassword.text = accountPassword?.Password; OnHideAccountList(); } //删除账号缓存列表 private void OnClickDelAccountCache(EventContext context) { GObject obj = context.sender as GObject; string account = obj.data.ToString(); AccountManager.Instance.DeleteAccount(account); _accountPasswordList = AccountManager.Instance.GetAccounts(); _ui.m_comAccount.m_list.numItems = _accountPasswordList.Count; if (_accountPasswordList.Count == 0) { _ui.m_comAccount.m_list.selectedIndex = 0; } if (_accountPasswordList.Count == 0) { _ui.m_comAccount.m_txtAccount.text = null; _ui.m_inputPassword.text = null; } else { _ui.m_comAccount.m_txtAccount.text = _accountPasswordList[0].Account; _ui.m_inputPassword.text = _accountPasswordList[0].Password; } } private void OnLoginFail(EventContext context) { string account = (string)context.data; _ui.m_comAccount.m_txtAccount.text = account; } private void InitChanelBox() { #if !UNITY_EDITOR _ui.m_boxChooseCanal.visible = false; return; #endif _ui.m_boxChooseCanal.visible = LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL; if (!_ui.m_boxChooseCanal.visible) return; var enumType = typeof(ChannelID); var arr = Enum.GetValues(enumType); List items = new List(); List numbers = new List(); foreach (var value in arr) { var fieldInfo = enumType.GetField((value).ToString()); if (fieldInfo != null && Attribute.IsDefined(fieldInfo, typeof(DescriptionAttribute))) { DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute)); items.Add(attribute.Description); numbers.Add(Convert.ToInt32(value).ToString()); } } _ui.m_boxChooseCanal.items = items.ToArray(); _ui.m_boxChooseCanal.values = numbers.ToArray(); _ui.m_boxChooseCanal.value = LauncherConfig.ChannelId + ""; _ui.m_boxChooseCanal.onChanged.Add(onBoxChannelChanged); } private void onBoxChannelChanged() { UpdateChannelBox(true); } private void UpdateChannelBox(bool showAlert = true) { if (!_ui.m_boxChooseCanal.visible) return; LauncherConfig.ChannelId = int.Parse(_ui.m_boxChooseCanal.value); ET.Log.Debug("打印测试======选择的渠道==========" + (_ui.m_boxChooseCanal.value)); if (_ui.m_boxChooseCanal.value == (int)ChannelID.Test + "") { if (showAlert) { AlertSystem.Show("切换其他渠道后不支持切回测试渠道,请重启游戏!"); } } else { GameConfig.LoginAddress = "http://10.108.64.127:10005"; } ET.Log.Debug($"===选择的渠道=== {_ui.m_boxChooseCanal.value} {GameConfig.LoginAddress}"); } } }