| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 | 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<GGraph> _graphList = new List<GGraph>();        private List<GameObject> _gameObjectList = new List<GameObject>();        private List<GoWrapper> _wrapperList = new List<GoWrapper>();        private List<Transition> _transitionList = new List<Transition>();        private GameObject _gameObject1;        private GameObject _gameObject2;        // private GameObject _gameObject3;        private GameObject _gameObject4;        private GameObject _gameObject5;        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) =>                {                    //防止手速超快关了又开开了又关导致的特效重复加载,因为这里是通过Timers延时加载的                    if (ViewManager.isViewOpen(nameof(RushSaleGiftBoxView)))                    {                        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);                if (!LimitedTimeGiftBoxDataManager.Instance.IsOpenMeiRiTeHui)                {                    LimitedTimeGiftBoxDataManager.Instance.SetIsOpenMeiRiTeHui();                }            }        }        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}";            }            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;            }                        if (remainBuyNum == 0)            {                //已售完                _ui.m_btnBuyPink.m_bagGrey.visible = true;                _ui.m_btnBuyPink.m_bagPink.visible = false;                _ui.m_btnBuyPink.m_txtSoldOut.visible = true;                _ui.m_btnBuyPink.m_txtSoldOut.text = "已售罄";                _ui.m_holderBtnBy.visible = false;                _ui.m_btnBuyPink.m_loaIcon.visible = false;                _ui.m_btnBuyPink.m_txtOldPrice.visible = false;                _ui.m_btnBuyPink.m_txtNewPrice.visible = false;            }            else            {                //未售完                _ui.m_btnBuyPink.m_bagGrey.visible = false;                _ui.m_btnBuyPink.m_bagPink.visible = true;                _ui.m_btnBuyPink.m_txtSoldOut.visible = false;                _ui.m_btnBuyPink.m_txtSoldOut.text = "";               // _ui.m_holderBtnBy.visible = true;               _ui.m_btnBuyPink.m_loaIcon.visible = true;                _ui.m_btnBuyPink.m_txtOldPrice.visible = true;                _ui.m_btnBuyPink.m_txtNewPrice.visible = true;            }            _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);            }            uiItem.m_t1.Play();            UI_RushSaleGiftBoxUI.ProxyEnd();        }        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<ItemExchangeView>(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();                }            }            // foreach (var transition in _transitionList)            // {            //     if (transition != null)            //     {            //         transition.Stop(true, false);            //         transition.Dispose();            //         transition.PlayReverse();            //     }            // }            //  _transitionList.Clear();            _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);        }    }}
 |