using FairyGUI; using UI.ActivityMain; using System.Collections; using System.Collections.Generic; using ET; using static GFGGame.ShopSProxy; using UI.CommonGame; using System.Text.RegularExpressions; namespace GFGGame { class WeeklyGiftTipsView : BaseWindow { private UI_WeeklyGiftTipsUI _ui; private int giftShopId = 0; private EffectUI _effectUI1; private EffectUI _effectUI2; public override void Dispose() { EffectUIPool.Recycle(_effectUI1); _effectUI1 = null; EffectUIPool.Recycle(_effectUI2); _effectUI2 = null; if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_WeeklyGiftTipsUI.PACKAGE_NAME; _ui = UI_WeeklyGiftTipsUI.Create(); this.viewCom = _ui.target; modal = true; this.viewCom.Center(); //邊框左上角特效 _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up"); //邊框右下角特效 _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down"); viewAnimationType = EnumViewAnimationType.ZOOM_CENTER; _ui.m_rewardList.itemRenderer = ListItemRender; _ui.m_rewardList.onClickItem.Add(OnListSelectorItemClick); _ui.m_backBtn.onClick.Add(OnClickChange); _ui.m_buyBtn.onClick.Add(OnClickBuy); } protected override void OnShown() { base.OnShown(); ActivityOpenCfg activityCfg = ActivityOpenCfgArray.Instance.GetCfg(ActivityDataManager.Instance.GetCurOpenActiveByType(101)); giftShopId = activityCfg.paramsArr[0]; if (giftShopId != 0) { var shopCfg = ShopCfgArray.Instance.GetCfg(giftShopId); ItemCfg item = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); _ui.m_rewardList.numItems = item.itemsArr.Length; } else { _ui.m_rewardList.numItems = 0; } string pattern = @"\[([^\[\]]+)\]"; // 正则表达式模式 // 创建Regex对象 Regex regex = new Regex(pattern); // 匹配文本中的所有结果 MatchCollection matchesOpen = regex.Matches(activityCfg.openTime); MatchCollection matchesEnd = regex.Matches(activityCfg.endTime); string openTime = matchesOpen[0].Groups[1].Value +"." + matchesOpen[1].Groups[1].Value + "." + matchesOpen[2].Groups[1].Value; string endTime = matchesEnd[0].Groups[1].Value + "." + matchesEnd[1].Groups[1].Value + "." + matchesEnd[2].Groups[1].Value; _ui.m_timeText.text = string.Format("本期特供时间:{0}-{1}", openTime, endTime); UpdateBtn(); } protected override void OnHide() { base.OnHide(); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateBtn); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateBtn); } private void OnClickChange() { this.Hide(); } private void ListItemRender(int index, GObject obj) { UI_ComItem uiItemChild = UI_ComItem.Proxy(obj); var shopCfg = ShopCfgArray.Instance.GetCfg(giftShopId); var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); int[][] result; result = itemCfg.itemsArr; var itemArr = result[index]; var itemCfgChild = ItemCfgArray.Instance.GetCfg(itemArr[0]); uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild); uiItemChild.m_txtCount.text = itemArr[1].ToString(); uiItemChild.target.data = itemCfgChild; uiItemChild.m_QualityType.selectedIndex = itemCfgChild.rarity - 1; UI_ComItem.ProxyEnd(); } //弹出物品详细描述框 private void OnListSelectorItemClick(EventContext context) { GComponent item = context.data as GComponent; ItemCfg itemCfg = item.data as ItemCfg; GoodsItemTipsController.ShowItemTips(itemCfg.id); } private async void OnClickBuy() { if(giftShopId == 0) { return; } await ReqShopBuy(giftShopId); } private void UpdateBtn() { ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(giftShopId); var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id); if (remainBuyNum == 0) { //已售完 _ui.m_buyBtn.visible = false; } else { //未售完 _ui.m_buyBtn.visible = true; } _ui.m_descText.text = string.Format("已购买次数:{0}/{1}", ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id) ,shopCfg.maxBuyNum); } } }