using UI.Store; using UI.CommonGame; using FairyGUI; using System.Collections.Generic; using ET; namespace GFGGame { public class StoreGiftBagAddRebateView : BaseWindow { private UI_StoreGiftBagAddRebateUI _ui; private ValueBarController _valueBarController; private List _shopCfgs; private int menu2; private int _itemId; //道具id,该页面目前只给:体力,金币使用 public override void Dispose() { if (_valueBarController != null) { _valueBarController.Dispose(); _valueBarController = null; } if (_ui != null) { _ui.Dispose(); } _ui = null; base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_StoreGiftBagUI.PACKAGE_NAME; _ui = UI_StoreGiftBagAddRebateUI.Create(); this.viewCom = _ui.target; isfullScreen = true; this.clickBlankToClose = false; this.bringToFontOnClick = false; _ui.m_rebateList.itemRenderer = ListItemRenderer; _valueBarController = new ValueBarController(_ui.m_valueBar); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView); } protected override void OnShown() { base.OnShown(); menu2 = (int)this.viewData; _shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_GIFT_BAG, menu2); _shopCfgs = ShopDataManager.Instance.RemoveNotOpenCfg(_shopCfgs); _valueBarController.OnShown(); _valueBarController.UpdateList(ShopDataManager.Instance.GetShopCostIds(_shopCfgs)); _ui.m_rebateList.scrollPane.ScrollTop(); UpdateView(); } protected override void OnHide() { base.OnHide(); ShopViewManager.Instance.ClearItemEff(); _valueBarController.OnHide(); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateView); } private void UpdateView() { _shopCfgs = ShopDataManager.Instance.SortShopGoodsCfgs(_shopCfgs); _ui.m_rebateList.numItems = _shopCfgs.Count; } private void ListItemRenderer(int index, GObject obj) { ShopCfg shopCfg = _shopCfgs[index]; UI_ComCurSupplyItem item = UI_ComCurSupplyItem.Proxy(obj); ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); item.target.data = shopCfg; //返利包 item.m_txtTitle.text = itemCfg.name; item.m_txtWeekPrompt.visible = false; item.m_btnIcoWeekPromptTag.visible = false; if (itemCfg.param2Arr.Length != 0) { item.m_txtWeekPrompt.visible = true; item.m_btnIcoWeekPromptTag.visible = true; item.m_txtWeekPrompt.text = string.Format("连续{0}天每日获得", itemCfg.param2Arr[0]); } int numItems; var childItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id); item.m_comLeftGiftBox.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg); item.m_btnBuy.m_txtOldPrice.text = $"{shopCfg.originalPrice}"; item.m_btnBuy.m_loaIcon.visible = false; string mTxtOldPrice = string.Empty; if (shopCfg.costType == CostType.ITEM) { //货币 ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(shopCfg.costId); item.m_btnBuy.m_loaIcon.visible = true; item.m_btnBuy.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg); } else if (shopCfg.costType == CostType.RMB) { //人民币 mTxtOldPrice = "元"; } else { //免费 mTxtOldPrice = $"免费"; item.m_btnBuy.m_txtOldPrice.text = ""; item.m_btnBuy.m_txtNewPrice.align = AlignType.Left; item.m_btnBuy.m_txtNewPrice.x = 90; } item.m_btnBuy.m_txtNewPrice.text = $"{shopCfg.price + mTxtOldPrice}"; item.m_comLeftGiftBox.target.data = itemCfg; item.m_comLeftGiftBox.target.onClick.Add(OnListSelectorItemClick); if (shopCfg.originalPrice != shopCfg.price) { var roundedNumStr = NumberUtil.CalculateDiscount(shopCfg.originalPrice, shopCfg.price); item.m_comLeftGiftBox.m_comDiscount.target.visible = true; item.m_comLeftGiftBox.m_comDiscount.m_txtDiscountNum.text = $"{roundedNumStr}折"; //之后再计算赋值 } else { item.m_comLeftGiftBox.m_comDiscount.target.visible = false; } if (shopCfg.refreshType == RefreshType.DAY) //也可以换成人民币来做条件 { //日刷 item.m_comLeftGiftBox.m_comGouMaiGetText.target.visible = false; item.m_txtUrc.text = string.Format("今日剩余{0}/{1}", remainBuyNum, shopCfg.maxBuyNum); item.m_txtLrc.text = string.Format("可获得{0}会员积分", shopCfg.price * 10); item.m_txtWeekPrompt.visible = false; item.m_btnIcoWeekPromptTag.visible = false; numItems = childItemCfg.itemsArr.Length; if (remainBuyNum == 0) { //已售完 item.m_btnBuy.target.visible = true; item.m_btnCurReceive.target.visible = false; item.m_btnBuy.m_bagYellow.visible = false; item.m_btnBuy.m_bagGrey.visible = true; } else { //未售完 item.m_btnBuy.target.visible = true; item.m_btnCurReceive.target.visible = false; item.m_btnBuy.m_bagYellow.visible = true; item.m_btnBuy.m_bagGrey.visible = false; } } else { //周刷 var weekGiftBoxState = EnduringGiftBoxDataManager.Instance.DayIsRebateGiftBox(shopCfg.itemId); item.m_comLeftGiftBox.m_comGouMaiGetText.target.visible = true; var itemArr = itemCfg.itemsArr[0]; ItemCfg getItemCfg = ItemCfgArray.Instance.GetCfg(itemArr[0]); //及时获得的物品,读取第一个显示ICON item.m_comLeftGiftBox.m_comGouMaiGetText.m_loaIcon.url = ResPathUtil.GetIconPath(getItemCfg); item.m_comLeftGiftBox.m_comGouMaiGetText.m_txtGetGold.text = itemArr[1].ToString(); item.m_txtUrc.text = string.Format("每周限购{0}/{1}", remainBuyNum, shopCfg.maxBuyNum); int rebateDay = EnduringGiftBoxDataManager.Instance.GetItemRebateDay(itemCfg.id); string mTxtLrc = string.Empty; if (rebateDay != 0) { mTxtLrc = string.Format("剩余{0}天", rebateDay); } item.m_txtLrc.text = mTxtLrc; item.m_txtWeekPrompt.visible = true; item.m_txtWeekPrompt.text = string.Format("连续{0}天每日获得", itemCfg.param2Arr[0] + 1); //NumberUtil.GetChiniseNumberText(itemCfg.param2Arr[0]) item.m_btnIcoWeekPromptTag.visible = true; numItems = childItemCfg.param1Arr.Length; //领取加红点 RedDotController.Instance.SetComRedDot(item.m_btnCurReceive.target, weekGiftBoxState); //是否需要领取 if (weekGiftBoxState) { item.m_btnBuy.target.visible = false; item.m_btnCurReceive.target.visible = true; item.m_btnCurReceive.m_receive.visible = true; item.m_btnCurReceive.m_received.visible = false; item.m_btnCurReceive.m_txtRec.text = "领取"; } else { //是否能购买 if (remainBuyNum == 0) { //已经领取 if (EnduringGiftBoxDataManager.Instance.DayRebateItemIds.Contains(shopCfg.itemId)) { item.m_btnBuy.target.visible = false; item.m_btnCurReceive.target.visible = true; item.m_btnCurReceive.m_receive.visible = false; item.m_btnCurReceive.m_received.visible = true; item.m_btnCurReceive.m_txtRec.text = "已领取"; } else { item.m_btnCurReceive.target.visible = false; item.m_btnBuy.target.visible = true; item.m_btnBuy.m_bagGrey.visible = true; item.m_btnBuy.m_bagYellow.visible = false; } } else { //未售完 item.m_btnBuy.target.visible = true; item.m_btnBuy.m_bagGrey.visible = false; item.m_btnBuy.m_bagYellow.visible = true; item.m_btnCurReceive.target.visible = false; } } } item.m_btnIcoWeekPromptTag.onClick.Add(RuleController.ShowRuleView); item.m_btnIcoWeekPromptTag.data = 300013; //领取按钮点击事件 item.m_btnCurReceive.target.onClick.Add(OnBtnCurReceiveClick); //购买按钮点击事件 item.m_btnBuy.target.onClick.Add(OnBtnBuyClick); item.m_list.data = shopCfg; item.m_list.itemRenderer = ChildListItemRender; //item.m_list.onClickItem.Add(OnListSelectorItemClick); item.m_list.numItems = numItems; UI_ComCurSupplyItem.ProxyEnd(); RedDotController.Instance.SetComRedDot(obj.asCom, menu2 == ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY && shopCfg.price == 0 && ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id) < shopCfg.maxBuyNum, "", 5, 76); } // ReSharper disable Unity.PerformanceAnalysis private void ChildListItemRender(int index, GObject obj) { UI_ComItem uiItemChild = UI_ComItem.Proxy(obj); var shopCfg = uiItemChild.target.parent.data as ShopCfg; var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); int[][] result; if (shopCfg.refreshType == RefreshType.DAY) { result = itemCfg.itemsArr; } else { //周刷 result = itemCfg.param1Arr; } var itemArr = result[index]; var itemCfgChild = ItemCfgArray.Instance.GetCfg(itemArr[0]); uiItemChild.target.data = itemCfgChild; uiItemChild.target.onClick.Add(OnListSelectorItemClick); uiItemChild.m_txtCount.text = itemArr[1].ToString(); uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild); uiItemChild.m_QualityType.selectedIndex = itemCfgChild.rarity - 1; UI_ComItem.ProxyEnd(); } //弹出物品详细描述框 private void OnListSelectorItemClick(EventContext context) { GObject item = context.sender as GObject; ItemCfg itemCfg = item.data as ItemCfg; GoodsItemTipsController.ShowItemTips(itemCfg.id); } //领取按钮点击事件 // ReSharper disable Unity.PerformanceAnalysis private void OnBtnCurReceiveClick(EventContext context) { GObject sender = context.sender as GObject; GObject obj = sender.parent; ShopCfg cfg = obj.data as ShopCfg; bool isSellOut = EnduringGiftBoxDataManager.Instance.DayIsRebateGiftBox(cfg.itemId); if (isSellOut) { EnduringGiftBoxSProxy.ReqGetGiftBagRebate(cfg.id).Coroutine(); } else { PromptController.Instance.ShowFloatTextPrompt("无法领取"); } } //购买按钮点击事件 // ReSharper disable Unity.PerformanceAnalysis private void OnBtnBuyClick(EventContext context) { //if (_itemId == ConstItemID.POWER && GuideDataManager.IsGuideFinish(ConstGuideId.BUY_POWER) <= 0) //{ // GuideController.TryCompleteGuideIndex(ConstGuideId.BUY_POWER, 1); // GuideController.TryCompleteGuide(ConstGuideId.BUY_POWER, 1); //} GObject sender = context.sender as GObject; GObject obj = sender.parent; ShopCfg cfg = obj.data as ShopCfg; bool isSellOut = cfg.maxBuyNum > 0 && cfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.id) <= 0; if (isSellOut) { PromptController.Instance.ShowFloatTextPrompt("已售罄"); return; } if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.id)) { PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.id)); return; } if (cfg.costType == CostType.FREE) { ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine(); LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2); } else { ViewManager.Show(cfg.id); } } } }