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; isReturnWindow = 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 = CommonDataManager.Tables.TblGlobalCfg.BadgeRes.Count; _ui.m_listIcon.selectedIndex = 0; _ui.m_txtName.text = ""; ItemUtil.UpdateItemNeedNum(_ui.m_comCost, CommonDataManager.Tables.TblGlobalCfg.ConsumeCreate[0].ItemId,CommonDataManager.Tables.TblGlobalCfg.ConsumeCreate[0].Count); } 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 > GlobalConst.MaxNameLen) { PromptController.Instance.ShowFloatTextPrompt("雅集名字最多七个字"); return; } if (!Regex.IsMatch(leagueName, @"^[\u4e00-\u9fa5_0-9]+$"))//角色起名仅允许汉字、数字、底划线 { PromptController.Instance.ShowFloatTextPrompt("雅集名字仅允许汉字、数字、下划线"); return; } long hasCount = ItemDataManager.GetItemNum( CommonDataManager.Tables.TblGlobalCfg.ConsumeCreate[0].ItemId); long needCount = CommonDataManager.Tables.TblGlobalCfg.ConsumeCreate[0].Count; if (hasCount < needCount) { ItemUtil.BuyCurrency( CommonDataManager.Tables.TblGlobalCfg.ConsumeCreate[0].ItemId, needCount - hasCount); return; } bool result = await LeagueSproxy.ReqCreateLeague(leagueName, CommonDataManager.Tables.TblGlobalCfg.BadgeRes[_ui.m_listIcon.selectedIndex]); if (result) { this.Hide(); ViewManager.DeleteViewStackCountDown(null,1); ViewManager.Show(null, true); } } private void RenderListItem(int index, GObject obj) { UI_ListIconItem item = UI_ListIconItem.Proxy(obj); item.m_loaIcon.url = ResPathUtil.GetLeagueIconPath( CommonDataManager.Tables.TblGlobalCfg.BadgeRes[index]); UI_ListIconItem.ProxyEnd(); } } }