using System.Text.RegularExpressions; using ET; using FairyGUI; using UI.League; using UnityEngine; namespace GFGGame { //创建联盟 public class LeagueCreatView : BaseWindow { private UI_LeagueCreatUI _ui; public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_LeagueCreatUI.PACKAGE_NAME; _ui = UI_LeagueCreatUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; viewAnimationType = EnumViewAnimationType.ZOOM_CENTER; _ui.m_btnClose.onClick.Add(Hide); _ui.m_btnCreat.onClick.Add(OnBtnCreatClick); _ui.m_listIcon.itemRenderer = RenderListItem; } protected override void AddEventListener() { base.AddEventListener(); } protected override void OnShown() { base.OnShown(); _ui.m_listIcon.numItems = GlobalCfgArray.globalCfg.badgeResArr.Length; _ui.m_listIcon.selectedIndex = 0; _ui.m_txtName.text = ""; ItemUtil.UpdateItemNeedNum(_ui.m_comCost, GlobalCfgArray.globalCfg.consumeCreateArr[0][0], GlobalCfgArray.globalCfg.consumeCreateArr[0][1]); } protected override void OnHide() { base.OnHide(); } protected override void RemoveEventListener() { base.RemoveEventListener(); } private async void OnBtnCreatClick() { string leagueName = _ui.m_txtName.text; if (string.IsNullOrEmpty(leagueName)) { PromptController.Instance.ShowFloatTextPrompt("雅集名字不能为空"); return; } if (leagueName.Length > GFGGame.GlobalConst.MaxNameLen) { PromptController.Instance.ShowFloatTextPrompt("雅集名字最多七个字"); return; } if (!Regex.IsMatch(leagueName, @"^[\u4e00-\u9fa5_0-9]+$"))//角色起名仅允许汉字、数字、底划线 { PromptController.Instance.ShowFloatTextPrompt("雅集名字仅允许汉字、数字、下划线"); return; } long hasCount = ItemDataManager.GetItemNum(GlobalCfgArray.globalCfg.consumeCreateArr[0][0]); long needCount = GlobalCfgArray.globalCfg.consumeCreateArr[0][1]; if (hasCount < needCount) { ItemUtil.BuyCurrency(GlobalCfgArray.globalCfg.consumeCreateArr[0][0], needCount - hasCount); return; } bool result = await LeagueSproxy.ReqCreateLeague(leagueName, GlobalCfgArray.globalCfg.badgeResArr[_ui.m_listIcon.selectedIndex]); if (result) { ViewManager.Show(null, new object[] { typeof(MainUIView).FullName, null }, true); } } private void RenderListItem(int index, GObject obj) { UI_ListIconItem item = UI_ListIconItem.Proxy(obj); item.m_loaIcon.url = ResPathUtil.GetLeagueIconPath(GlobalCfgArray.globalCfg.badgeResArr[index]); UI_ListIconItem.ProxyEnd(); } } }