123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using ET;
- using FairyGUI;
- using UI.CommonGame;
- 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<ShopCfg> _shopCfgList = new List<ShopCfg>();
- private EffectUI _effectUI1;
- private EffectUI _effectUI2;
- private EffectUI _effectUI3;
- private EffectUI _effectUI4;
- 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()
- {
- 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()
- {
- //小人
- if (_itemId == ConstItemID.POWER)
- {
- _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderBaby, "ui_Activity", "Activity_people02");
- }
- else
- {
- _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderBaby, "ui_Activity", "Activity_people01");
- }
- //爆发,大泡泡
- _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderPaoMax, "ui_Activity", "Activity_baofa");
- //持续的小泡泡
- _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holderPaoMin, "ui_Activity", "Activity_chixu");
- //爆发时候的发光
- _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_holderFg, "ui_Activity", "Activity_glow");
- }
- 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.CostTypeReal == CostType.ITEM)
- {
- //货币
- ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(shopCfg.CostIdReal);
- item.m_btnBuy.m_loaIcon.visible = true;
- item.m_btnBuy.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg);
- }
- else if (shopCfg.CostTypeReal == 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();
- }
- //领取按钮点击事件
- // 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.CostTypeReal == CostType.FREE)
- {
- ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine();
- LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
- }
- else
- {
- ViewManager.Show<ItemExchangeView>(cfg.id);
- }
- }
- // 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);
- // 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.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
- // 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()
- {
- EffectUIPool.Recycle(_effectUI1);
- _effectUI1 = null;
- EffectUIPool.Recycle(_effectUI2);
- _effectUI2 = null;
- EffectUIPool.Recycle(_effectUI3);
- _effectUI3 = null;
- EffectUIPool.Recycle(_effectUI4);
- _effectUI4 = null;
- this.RemoveEventListener();
- 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;
- if (_itemId == ConstItemID.POWER)
- {
- GuideController.TryGuide(_ui.m_list.GetChildAt(1).asCom.GetChild("btnCurReceive").asButton,
- ConstGuideId.BUY_POWER, 1, "这里可以购买体力超值返利包,每天都能领体力哦~");
- }
- }
- }
- }
|