using System; using System.Collections.Generic; using System.Linq; using ET; using FairyGUI; using UI.EnduringGiftBox; using UnityEngine; namespace GFGGame { public class EnduringGiftBoxView : BaseWindow { private UI_EnduringGiftBoxUI _ui; private int _itemId; //道具id,该页面目前只给:体力,金币使用 private int _count; //本次购买次数 private int _buyTimes = 0; //已购次数 private int _type = 0; //0从别的地方跳转过来. 1从点击TOP菜单栏icon跳转过来 private Action _onSuccess; private int _maxTimes = 0; private string _message = ""; private List _shopCfgList = new List(); private GameObject _gameObject1; private GameObject _gameObject2; private GameObject _gameObject3; private GameObject _gameObject4; private GoWrapper _wrapper1; private GoWrapper _wrapper2; private GoWrapper _wrapper3; private GoWrapper _wrapper4; protected override void OnInit() { base.OnInit(); packageName = UI_EnduringGiftBoxUI.PACKAGE_NAME; _ui = UI_EnduringGiftBoxUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; viewAnimationType = EnumViewAnimationType.None; _ui.m_btnSure.onClick.Add(OnClickBtnSure); _ui.m_btnCancel.onClick.Add(OnClickBtnCancel); _ui.m_btnBack.onClick.Add(OnClickBtnCancel); } public override void Dispose() { SceneController.DestroyObjectFromView(_gameObject1, _wrapper1); SceneController.DestroyObjectFromView(_gameObject2, _wrapper2); SceneController.DestroyObjectFromView(_gameObject3, _wrapper3); SceneController.DestroyObjectFromView(_gameObject4, _wrapper4); if (_ui != null) { _ui.Dispose(); _ui = null; } EnduringGiftBoxController.Dispose(); base.Dispose(); } protected override void OnShown() { base.OnShown(); AddEffect(); _ui.m_t1.Play(); _ui.m_t2.Play(); _ui.m_t3.Play(CheckGuide); UpdateView(); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT_SHOP_BUY, UpDayRebateAndView); EventAgent.AddEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT, UpdateView); } protected override void RemoveEventListener() { EventAgent.RemoveEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT_SHOP_BUY, UpDayRebateAndView); EventAgent.RemoveEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT, UpdateView); base.RemoveEventListener(); } private void AddEffect() { string resPath3; if (_itemId == ConstItemID.POWER) { resPath3 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_people02"); } else { resPath3 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_people01"); } //小人 SceneController.AddObjectToView(null, null, _ui.m_holderBaby, resPath3, out _gameObject3, out _wrapper3); //爆发,大泡泡 string resPath1 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_baofa"); SceneController.AddObjectToView(null, null, _ui.m_holderPaoMax, resPath1, out _gameObject1, out _wrapper1); //持续的小泡泡 string resPath2 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_chixu"); SceneController.AddObjectToView(null, null, _ui.m_holderPaoMin, resPath2, out _gameObject2, out _wrapper2); //爆发时候的发光 string resPath4 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_glow"); SceneController.AddObjectToView(null, null, _ui.m_holderFg, resPath4, out _gameObject4, out _wrapper4); } public void SetParams(int itemId, int count, Action onSuccess, string message = "", int type = 0) { _itemId = itemId; _count = count; _onSuccess = onSuccess; _message = message; _type = type; } private void UpdateView() { _buyTimes = ItemDataManager.GetItemExchangeTimes(_itemId); ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, _buyTimes, _count, out int costId, out int coustNum, out int buyNum); ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId); ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(costId); _ui.m_txtNeed.text = string.Format("是否花费{0}{1} 购买{2}{3}", coustNum, costCfg.name, buyNum, itemCfg.name); _maxTimes = ItemExchangeCfgArray.Instance.GetCfg(_itemId).maxLimit; string showTxt = string.Empty; _shopCfgList.Clear(); //常驻礼包 if (_itemId == ConstItemID.POWER) { //体力礼包 _shopCfgList = ShopCfgArray.Instance .GetCfgsBymenu1Andmenu2(ConstStoreTabId.ENDURING_GIFT_BOX, ConstStoreSubId.ENDURING_GIFT_BOX_POWER) .OrderBy(a => a.refreshType).ToList(); _ui.m_txtNeed.align = AlignType.Center; int maxLimit = ItemExchangeCfgArray.Instance.GetCfg(ConstItemID.POWER).maxLimit; int lastBuyCount = maxLimit - ItemDataManager.GetItemExchangeTimes(ConstItemID.POWER); showTxt = string.Format("每5分钟回复1点体力\n今日剩余购买次数{0}/{1}次", lastBuyCount, maxLimit); } else { //金币礼包 _shopCfgList = ShopCfgArray.Instance .GetCfgsBymenu1Andmenu2(ConstStoreTabId.ENDURING_GIFT_BOX, ConstStoreSubId.ENDURING_GIFT_BOX_GOLD) .OrderBy(a => a.refreshType).ToList(); _ui.m_txtNeed.align = AlignType.Right; if (_maxTimes != 0) { showTxt = string.Format("今日剩余购买次数{0}/{1}", _maxTimes - _buyTimes, _maxTimes); } } _ui.m_txtNum.text = showTxt; _ui.m_txtPromptExt.text = string.Format("除了上述购买{0}的途径,我们还提供了更多的优惠礼包选择", itemCfg.name); _ui.m_list.itemRenderer = ListItemRender; _ui.m_list.numItems = _shopCfgList.Count; _ui.m_list.visible = true; } // ReSharper disable Unity.PerformanceAnalysis private void ListItemRender(int index, GObject obj) { ShopCfg shopCfg = _shopCfgList[index]; ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); //购买的物品-礼包 UI_ComCurSupplyItem item = UI_ComCurSupplyItem.Proxy(obj); 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.m_loaIcon.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; //是否需要领取 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.numItems = numItems; } //领取按钮点击事件 // 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 (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); } } // ReSharper disable Unity.PerformanceAnalysis private void ChildListItemRender(int index, GObject obj) { UI_ComRewardIconItem uiItemChild = UI_ComRewardIconItem.Proxy(obj); var shopCfg = uiItemChild.target.parent.data as ShopCfg; var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); // uiItemChild.m_showRreceives.visible = false; //var curGiftBoxState = EnduringGiftBoxDataManager.GiftBoxStateDic[shopCfg.id]; int[][] result; if (shopCfg.refreshType == RefreshType.DAY) { result = itemCfg.itemsArr; uiItemChild.m_bagYellow.visible = false; uiItemChild.m_bagBlue.visible = true; uiItemChild.m_bagYellowEx.visible = false; uiItemChild.m_bagBlueEx.visible = true; } else { //周刷 result = itemCfg.param1Arr; uiItemChild.m_bagYellow.visible = true; uiItemChild.m_bagBlue.visible = false; uiItemChild.m_bagYellowEx.visible = true; uiItemChild.m_bagBlueEx.visible = false; } // if (curGiftBoxState == EnduringGiftBoxBuyStatus.YesGet) // { // uiItemChild.m_showRreceives.visible = true; // } // else if (curGiftBoxState == EnduringGiftBoxBuyStatus.NoGet) // { // uiItemChild.m_showRreceives.visible = false; // } var itemArr = result[index]; var itemCfgChild = ItemCfgArray.Instance.GetCfg(itemArr[0]); uiItemChild.m_loaIcon.onClick.Add(OnListSelectorItemClick); uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild); uiItemChild.m_num.text = itemArr[1].ToString(); uiItemChild.target.data = itemCfgChild; UI_ComRewardIconItem.ProxyEnd(); } //弹出物品详细描述框 private void OnListSelectorItemClick(EventContext context) { GObject sender = context.sender as GObject; GObject obj = sender.parent; ItemCfg itemCfg = obj.data as ItemCfg; GoodsItemTipsController.ShowItemTips(itemCfg.id); } // ReSharper disable Unity.PerformanceAnalysis // ReSharper disable Unity.PerformanceAnalysis private async void OnClickBtnSure() { if (_maxTimes > 0 && (_buyTimes + _count) > _maxTimes) { PromptController.Instance.ShowFloatTextPrompt("购买次数不足"); return; } ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, _buyTimes, _count, out int costId, out int coustNum, out int buyNum); Debug.Log(costId + "数量:" + ItemDataManager.GetItemNum(costId)); if (ItemDataManager.GetItemNum(costId) < coustNum) { ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(costId); if (_itemId == ConstItemID.DIAMOND_PURPLE) { PromptController.Instance.ShowFloatTextPrompt(string.Format("{0}不足,请前往商城选购", costCfg.name)); } else { AlertUI.Show(costCfg.name + "不足,是否前往购买?").SetLeftButton(true).SetRightButton(true, "确认", (AlertWindow.AlertCallback)((object data) => { long costNeedCount = coustNum - ItemDataManager.GetItemNum(costId); BuyItemConteoller.Show(costId, costNeedCount, ConstBuyType.TYPE_ITEM, null, true, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED); })); OnClickBtnCancel(); } return; } bool result = await ItemExchangeSProxy.ItemExchange(_itemId, _count); if (result) { PromptController.Instance.ShowFloatTextPrompt("购买成功", MessageType.SUCCESS); if (_onSuccess != null) { _onSuccess(); } } UpdateView(); //判断一下是不是从主要界面进来的 if (_type == 0) { this.Hide(); } } //购买连续礼包之后,更新数据+更新界面 // ReSharper disable Unity.PerformanceAnalysis private void UpDayRebateAndView(EventContext context) { ShopCfg shopCfg = context.data as ShopCfg; var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); if (itemCfg.itemType == ConstItemType.USEABLE && itemCfg.funType == ConstItemFuncType.CONTINUOUS_REWARD_GIFT) { int dayNum = EnduringGiftBoxDataManager.Instance.GetItemRebateDay(itemCfg.id); int totalDayNum = dayNum + itemCfg.param2Arr[0]; EnduringGiftBoxDataManager.Instance.UpDayAllRebateItemDic(itemCfg.id, totalDayNum); EnduringGiftBoxDataManager.Instance.AddDayRebateItemIds(itemCfg.id); } UpdateView(); } protected override void OnHide() { this.RemoveEventListener(); Dispose(); base.Hide(); _onSuccess = null; Timers.inst.Remove(CheckGuide); } private void OnClickBtnCancel() { // Dispose(); this.Hide(); } private void CheckGuide() { Timers.inst.AddUpdate(CheckGuide); } private void CheckGuide(object param) { if (GuideDataManager.IsGuideFinish(ConstGuideId.BUY_POWER) <= 0) { UpdateToCheckGuide(null); } else { Timers.inst.Remove(CheckGuide); } } protected override void UpdateToCheckGuide(object param) { if (!ViewManager.CheckIsTopView(this.viewCom)) return; GuideController.TryGuide(_ui.m_list.GetChildAt(1).asCom.GetChild("btnCurReceive").asButton, ConstGuideId.BUY_POWER, 1, "花点小钱可以购买体力超值返利包,每天都能领体力哦~"); } } }