using System; using System.Collections.Generic; using System.Linq; using ET; using FairyGUI; using UI.EnduringGiftBox; using UnityEngine; namespace GFGGame { //圆形样式的限时礼包 // 4类型-圆形样式:等级条件的数据 // 5类型-圆形样式:时间条件的数据 public class RushSaleGiftBoxView : BaseWindow { private UI_RushSaleGiftBoxUI _ui; private int _type; //决定数据的类型 --等级条件的数据,时间条件的数据 private int _pageIndex; //当前页码,需要显示的数据的索引 private List _graphList = new List(); private List _gameObjectList = new List(); private GameObject _gameObject1; private GameObject _gameObject2; private GameObject _gameObject3; private GameObject _gameObject4; private GameObject _gameObject5; private List _wrapperList = new List(); private GoWrapper _wrapper1; private GoWrapper _wrapper2; private GoWrapper _wrapper3; private GoWrapper _wrapper4; private GoWrapper _wrapper5; protected override void OnInit() { base.OnInit(); packageName = UI_RushSaleGiftBoxUI.PACKAGE_NAME; _ui = UI_RushSaleGiftBoxUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; viewAnimationType = EnumViewAnimationType.None; _ui.m_btnUp.onClick.Add(OnBtnPreviousClick); _ui.m_btnNext.onClick.Add(OnBtnNextClick); _ui.m_btnBack.onClick.Add(OnBtnCancelClick); _ui.m_btnBuyPink.target.onClick.Add(OnBtnBuyClick); } protected override void OnShown() { base.OnShown(); _type = (int)(this.viewData as object[])[0]; //ConstActivityType AddEffect(); _ui.m_t3.Play(); LimitedTimeGiftBoxDataManager.Instance.UpLtgGbItemData4(); LimitedTimeGiftBoxDataManager.Instance.UpLtgGbItemData5(); InitPageInex(); UpViewNone(); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.ACTIVITY_REMOVE, UpViewNone); EventAgent.AddEventListener(ConstMessage.ACTIVITY_ADD, UpViewNone); EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpViewNone); } protected override void RemoveEventListener() { EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_REMOVE, UpViewNone); EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_ADD, UpViewNone); EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpViewNone); base.RemoveEventListener(); } private void AddEffect() { string resPath1 = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_pepole"); SceneController.AddObjectToView(null, null, _ui.m_holderPaoBaby, resPath1, out _gameObject1, out _wrapper1); string resPath3 = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_discount_chixu"); SceneController.AddObjectToView(null, null, _ui.m_holderZheKouChiXu, resPath3, out _gameObject3, out _wrapper3); Timers.inst.Add(0.8f, 1, (obj) => { string resPath4 = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_discount_baofa"); SceneController.AddObjectToView(null, null, _ui.m_holderZheKou, resPath4, out _gameObject4, out _wrapper4); string resPath2 = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_button"); SceneController.AddObjectToView(null, null, _ui.m_holderBtnBy, resPath2, out _gameObject2, out _wrapper2); } ); string resPath5 = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_star"); SceneController.AddObjectToView(null, null, _ui.m_holderStar, resPath5, out _gameObject5, out _wrapper5); } //实例化索引 private void InitPageInex() { if (_type == ActivityType.XSLB2) { //4 var data4 = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4 .FirstOrDefault(a => a.IndexType == 1); _pageIndex = data4 == null ? 0 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4.IndexOf(data4); } else if (_type == ActivityType.XSLB3) { //5 var data5 = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5 .FirstOrDefault(a => a.IndexType == 1); _pageIndex = data5 == null ? 0 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5.IndexOf(data5); } } public void UpTime() { //筛选一条数据用来界面渲染 var list = _type == ActivityType.XSLB2 ? LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5; list = list.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList(); if (list.Count == 0) { PromptController.Instance.ShowFloatTextPrompt("活动已结束"); this.Hide(); return; } _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime); } private void UpdateView(ListUtil.NavigateType type) { var list = _type == ActivityType.XSLB2 ? LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5; list = list.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList(); if (list.Count == 0) { PromptController.Instance.ShowFloatTextPrompt("活动已结束"); this.Hide(); return; } var data = ListUtil.Navigate(list, type, _pageIndex, out int newIndex); _pageIndex = newIndex; _ui.m_btnUp.visible = true; _ui.m_btnNext.visible = true; if (list.Count == 1) { _ui.m_btnUp.visible = false; _ui.m_btnNext.visible = false; } else { //翻页翻到了最后一条数据 if (list.Count == _pageIndex + 1) { _ui.m_btnNext.visible = false; } if (_pageIndex == 0) { _ui.m_btnUp.visible = false; } } var shopCfg = ShopCfgArray.Instance.GetCfg(data.ShopCfgId); var boxItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id); string mTxtUrc = string.Empty; if (shopCfg.refreshType == RefreshType.DAY) { mTxtUrc = $"今日限购{remainBuyNum}/{shopCfg.maxBuyNum}"; } else if (shopCfg.refreshType == RefreshType.WEEK) { mTxtUrc = $"本周限购{remainBuyNum}/{shopCfg.maxBuyNum}"; } else if (shopCfg.refreshType == RefreshType.MONTH) { mTxtUrc = $"本月限购{remainBuyNum}/{shopCfg.maxBuyNum}"; } if (remainBuyNum == 0) { //已售完 _ui.m_btnBuyPink.m_bagGrey.visible = true; _ui.m_btnBuyPink.m_bagPink.visible = false; } else { //未售完 _ui.m_btnBuyPink.m_bagGrey.visible = false; _ui.m_btnBuyPink.m_bagPink.visible = true; } string mTxtNewPrice; _ui.m_txtLrc.text = string.Empty; _ui.m_btnBuyPink.m_loaIcon.visible = false; _ui.m_btnBuyPink.m_txtOldPrice.text = shopCfg.originalPrice.ToString(); if (shopCfg.costType == CostType.ITEM) { //货币 ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(shopCfg.costId); mTxtNewPrice = shopCfg.price.ToString(); _ui.m_btnBuyPink.m_loaIcon.visible = true; _ui.m_btnBuyPink.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg); //_ui.m_btnBuyPink.m_txtNewPrice.x = 166; } else if (shopCfg.costType == CostType.RMB) { //人民币 mTxtNewPrice = $"{shopCfg.price}元"; //_ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left; //_ui.m_btnBuyPink.m_txtNewPrice.x = 166; _ui.m_txtLrc.text = $"可获得{shopCfg.price * 10}充值经验"; } else { //免费 mTxtNewPrice = $"免费"; _ui.m_btnBuyPink.m_txtOldPrice.text = ""; //_ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left; // _ui.m_btnBuyPink.m_txtNewPrice.x = 166; } _ui.m_txtBoxItemName.text = shopCfg.itemName; //这个B时间需要在一个地方统一处理,然后广播事件,不然可能会存在不同步的问题,最后做 _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), data.EndTime); _ui.m_txtUrc.text = mTxtUrc; _ui.m_comDiscount.m_txtDiscountNum.text = NumberUtil.CalculateDiscount(shopCfg.originalPrice, shopCfg.price); _ui.m_btnBuyPink.m_txtNewPrice.text = mTxtNewPrice; _ui.m_btnBuyPink.target.data = shopCfg; _ui.m_list.data = boxItemCfg; _ui.m_list.itemRenderer = ListItemRender; _ui.m_list.numItems = boxItemCfg.itemsArr.Length; _ui.m_list.visible = true; } private void ListItemRender(int index, GObject obj) { UI_ComRsGifBoxIconItem uiItem = UI_ComRsGifBoxIconItem.Proxy(obj); var boxItemCfg = uiItem.target.parent.data as ItemCfg; var itemKv = boxItemCfg.itemsArr[index]; ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemKv[0]); uiItem.m_txtItemName.text = itemCfg.name; uiItem.target.data = itemCfg; uiItem.m_comRewardIconItem.m_bagBlue.visible = false; uiItem.m_comRewardIconItem.m_bagBlueEx.visible = false; uiItem.m_comRewardIconItem.m_num.text = itemKv[1].ToString(); uiItem.m_comRewardIconItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg); uiItem.m_comRewardIconItem.target.onClick.Add(OnListSelectorItemClick); if (!_graphList.Contains(uiItem.m_holderItem)) { string resPath = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_kuang"); SceneController.AddObjectToView(null, null, uiItem.m_holderItem, resPath, out var gameObject, out var wrapper); _graphList.Add(uiItem.m_holderItem); _gameObjectList.Add(gameObject); _wrapperList.Add(wrapper); } } private void UpViewNone() { UpdateView(ListUtil.NavigateType.None); } //上一条 private void OnBtnPreviousClick() { UpdateView(ListUtil.NavigateType.Previous); } //下一条 private void OnBtnNextClick() { UpdateView(ListUtil.NavigateType.Next); } //购买按钮点击事件 private void OnBtnBuyClick(EventContext context) { GObject sender = context.sender as GObject; //GObject obj = sender.parent; ShopCfg cfg = sender.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); } } private void DestroyObjectFromView() { foreach (var itemGameObject in _gameObjectList) { if (itemGameObject != null) { GameObject.DestroyImmediate(itemGameObject); } } _gameObjectList.Clear(); foreach (var itemWrapper in _wrapperList) { if (itemWrapper != null) { itemWrapper.Dispose(); } } _wrapperList.Clear(); _graphList.Clear(); } protected override void OnHide() { SceneController.DestroyObjectFromView(_gameObject1, _wrapper1); SceneController.DestroyObjectFromView(_gameObject2, _wrapper2); SceneController.DestroyObjectFromView(_gameObject3, _wrapper3); SceneController.DestroyObjectFromView(_gameObject4, _wrapper4); SceneController.DestroyObjectFromView(_gameObject5, _wrapper5); DestroyObjectFromView(); this.RemoveEventListener(); //Dispose(); base.Hide(); } private void OnBtnCancelClick() { this.Hide(); } //弹出物品详细描述框 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); } } }