123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- 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;
- 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_inputAccount.restrict = "[0-9A-Za-z_]";
- if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
- {
- _ui.m_inputPassword.promptText = "[color=#B8A492]当前支持免密登录[/color]";
- }
- }
- protected override void OnShown()
- {
- base.OnShown();
- string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY);
- if (account != null)
- {
- _ui.m_inputAccount.text = account;
- }
- InitChanelBox();
- }
- 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 onChangedCanal()
- {
- LauncherConfig.ChannelId = int.Parse(_ui.m_boxChooseCanal.value);
- ET.Log.Debug("打印测试======选择的渠道==========" + (_ui.m_boxChooseCanal.value));
- if(_ui.m_boxChooseCanal.value == (int)ChannelID.Test + "")
- {
- AlertSystem.Show("切换其他渠道后不支持切回测试渠道,请重启游戏!")
- .SetRightButton(true, "退出游戏", (obj) => { Application.Quit(); });
- }
- else
- {
- GameConfig.LoginAddress = "http://10.108.64.127:10005";
- }
- ET.Log.Debug($"===选择的渠道=== {_ui.m_boxChooseCanal.value} {GameConfig.LoginAddress}");
- }
- private void OnClickBtnSure()
- {
- var account = _ui.m_inputAccount.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.LoginTest(account).Coroutine();
- }
- else
- {
- PromptController.Instance.ShowFloatTextPrompt("请输入密码");
- }
- }
- private void OnClickBtnCancel()
- {
- this.Hide();
- }
- private void OnClickBtnRegister()
- {
- ViewManager.Show<RegisterView>();
- }
- private void OnLoginFail(EventContext context)
- {
- string account = (string)context.data;
- _ui.m_inputAccount.text = account;
- }
- private void InitChanelBox()
- {
- _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<string> items = new List<string>();
- List<string> numbers = new List<string>();
- 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(onChangedCanal);
- }
- }
- }
|