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; using cfg.GfgCfg; 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(); //邊框左上角特效 EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up", onComplete: (effect) => { if (effect != null) { _effectUI1 = effect; } }); //邊框右下角特效 EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down", onComplete: (effect) => { if (effect != null) { _effectUI2 = effect; } }); 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 = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault( ActivityDataManager.Instance.GetCurOpenActiveByType(101)); giftShopId = activityCfg.Params1[0]; if (giftShopId != 0) { var shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(giftShopId); ItemCfg item = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.ItemId); _ui.m_rewardList.numItems = item.Items.Count; } 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 = CommonDataManager.Tables.TblShopCfg.GetOrDefault(giftShopId); var itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.ItemId); List result = itemCfg.Items.ToGfgGameItemParam(); var itemArr = result[index]; var itemCfgChild = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemArr.ItemId); uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild); uiItemChild.m_txtCount.text = itemArr.Count.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 = CommonDataManager.Tables.TblShopCfg.GetOrDefault(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); } } }