| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 | using System;using System.Collections.Generic;using System.Linq;using ET;using FairyGUI;using UI.CommonGame;using UI.EnduringGiftBox;namespace GFGGame{    //列表样式的限时礼包--3类型-列表样式:等级条件的数据    public class SpecialOfferGiftBoxView : BaseWindow    {        private UI_SpecialOfferGiftBoxUI _ui;        //private int _pageIndex; //当前页码,需要显示的数据的索引        private List<EffectUI> _effectUIList = new List<EffectUI>();        private List<EffectUI> _effect1UIList = new List<EffectUI>();                private EffectUI _effectUI1;        private EffectUI _effectUI2;        private EffectUI _effectUI3;        protected override void OnInit()        {            base.OnInit();            packageName = UI_SpecialOfferGiftBoxUI.PACKAGE_NAME;            _ui = UI_SpecialOfferGiftBoxUI.Create();            this.viewCom = _ui.target;            this.viewCom.Center();            this.modal = true;            viewAnimationType = EnumViewAnimationType.None;            _ui.m_listGift.itemRenderer = RenderListGiftItem;            _ui.m_back.onClick.Add(OnBtnCancelClick);            AddEffect();            //_ui.m_btnUp.onClick.Add(OnBtnPreviousClick);            //_ui.m_btnNext.onClick.Add(OnBtnNextClick);        }        public override void Dispose()        {            EffectUIPool.Recycle(_effectUI1);            _effectUI1 = null;            EffectUIPool.Recycle(_effectUI2);            _effectUI2 = null;            EffectUIPool.Recycle(_effectUI3);            _effectUI3 = null;            if (_ui != null)            {                _ui.Dispose();                _ui = null;            }            base.Dispose();        }        protected override void OnShown()        {            base.OnShown();            GameGlobal.AutoSpecialOfferGiftBoxView = false;            _ui.m_t0.Play();                       UpViewNone();            //InitPageInex();        }        private void OnBtnCancelClick()        {            this.Hide();        }        protected override void OnHide()        {            DestroyObjectFromView();            this.RemoveEventListener();            base.Hide();        }        private void DestroyObjectFromView()        {            for (int i = 0; i < _effectUIList.Count; i++)            {                EffectUIPool.Recycle(_effectUIList[i]);                _effectUIList[i] = null;            }            _effectUIList.Clear();            for (int i = 0; i < _effect1UIList.Count; i++)            {                EffectUIPool.Recycle(_effect1UIList[i]);                _effect1UIList[i] = null;            }            _effect1UIList.Clear();        }        private void UpViewNone()        {            var shopCfgIds = LimitedTimeGiftBoxDataManager.Instance.TryShopCfg();            DestroyObjectFromView();            _ui.m_listGift.numItems = shopCfgIds.Count;        }        private void RenderListGiftItem(int index, GObject obj)        {            UI_ComSpecialOfferGiftBoxItem uiItem = UI_ComSpecialOfferGiftBoxItem.Proxy(obj);            var shopCfgIds = LimitedTimeGiftBoxDataManager.Instance.TryShopCfg();            var shopCfgId = shopCfgIds[index];            var shopCfg = ShopCfgArray.Instance.GetCfg(shopCfgId);            var shopItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);            var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);            uiItem.m_txtGetJf.text = string.Empty;            string mTxtUrc = string.Empty;            string mTxtNewPrice;            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}";            else                mTxtUrc = $"永久限购{remainBuyNum}/{shopCfg.maxBuyNum}";            uiItem.m_btnBuy.m_txtOldPrice.text = shopCfg.originalPrice.ToString();            if (shopCfg.CostTypeReal == CostType.ITEM)            {                //货币                ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(shopCfg.CostIdReal);                mTxtNewPrice = shopCfg.Price.ToString();                uiItem.m_btnBuy.m_loaIcon.visible = true;                uiItem.m_btnBuy.m_txtNewPrice.x = 134;                uiItem.m_btnBuy.m_txtOldPrice.x = 21;                uiItem.m_btnBuy.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg);            }            else if (shopCfg.CostTypeReal == CostType.RMB)            {                //人民币                 mTxtNewPrice = $"{shopCfg.Price}元";                uiItem.m_btnBuy.m_txtNewPrice.align = AlignType.Left;                uiItem.m_btnBuy.m_txtNewPrice.x = 125;                uiItem.m_btnBuy.m_txtOldPrice.x = 30;                uiItem.m_txtGetJf.text = $"可获得{shopCfg.Price * 10}会员积分";            }            else            {                //免费                mTxtNewPrice = $"免费";                uiItem.m_btnBuy.m_txtOldPrice.text = "";                uiItem.m_btnBuy.m_txtNewPrice.align = AlignType.Left;                uiItem.m_btnBuy.m_txtNewPrice.x = 125;                uiItem.m_btnBuy.m_txtOldPrice.x = 30;            }            if (remainBuyNum == 0)            {                //已售完                uiItem.m_btnBuy.m_bagGrey.visible = true;                uiItem.m_btnBuy.m_txtSoldOut.text = "已售罄";                uiItem.m_btnBuy.m_txtSoldOut.visible = true;                uiItem.m_btnBuy.m_bagYellow.visible = false;                uiItem.m_btnBuy.m_txtOldPrice.visible = false;                uiItem.m_btnBuy.m_txtNewPrice.visible = false;                uiItem.m_btnBuy.m_loaIcon.visible = false;            }            else            {                //未售完                uiItem.m_btnBuy.m_txtSoldOut.text = "";                uiItem.m_btnBuy.m_txtSoldOut.visible = false;                uiItem.m_btnBuy.m_bagGrey.visible = false;                uiItem.m_btnBuy.m_bagYellow.visible = true;                uiItem.m_btnBuy.m_txtOldPrice.visible = true;                uiItem.m_btnBuy.m_txtNewPrice.visible = true;                uiItem.m_btnBuy.m_loaIcon.visible = true;                EffectUI _effectUI1 = EffectUIPool.CreateEffectUI(uiItem.m_holderBtn, "ui_Activity", "Prefer_button_buy");                _effect1UIList.Add(_effectUI1);            }            uiItem.m_comDiscount.m_txtDiscountNum.text =                NumberUtil.CalculateDiscount(shopCfg.originalPrice, shopCfg.Price);            uiItem.target.data = shopCfg;            uiItem.m_btnBuy.m_txtNewPrice.text = mTxtNewPrice;            uiItem.m_txtUrc.text = mTxtUrc;            uiItem.m_btnBuy.target.onClick.Add(OnBtnBuyClick);            uiItem.m_txtBoxItemName.text = shopCfg.itemName;            EffectUI _effectUI = EffectUIPool.CreateEffectUI(uiItem.m_holderZheKou, "ui_Activity", "Prefer_but_zhekou");            _effectUIList.Add(_effectUI);            uiItem.m_t0.Play();            ////子列表            if(uiItem.m_list.data == null)                uiItem.m_list.itemRenderer = ChildListItemRender;            uiItem.m_list.data = 1;            uiItem.m_list.onClickItem.Add(OnListSelectorItemClick);            uiItem.m_list.numItems = shopItemCfg.itemsArr.Length;            UI_ComSpecialOfferGiftBoxItem.ProxyEnd();        }        private void AddEffect()        {            if (_effectUI1 == null)                _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderBaby, "ui_Activity", "Prefer_person");            if (_effectUI2 == null)                _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderChiXuTx, "ui_Activity", "Prefer_chixu_tx");            if (_effectUI3 == null)                _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holderOneTx, "ui_Activity", "Prefer_one_tx");        }        protected override void AddEventListener()        {            base.AddEventListener();            EventAgent.AddEventListener(ConstMessage.ACTIVITY_REMOVE, UpViewNone);            EventAgent.AddEventListener(ConstMessage.ACTIVITY_ADD, UpViewNone);            EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpViewNone);            EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_TIME, UpTime);        }        protected override void RemoveEventListener()        {            EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_REMOVE, UpViewNone);            EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_ADD, UpViewNone);            EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpViewNone);            EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_TIME, UpTime);            base.RemoveEventListener();        }        //购买按钮点击事件        private void OnBtnBuyClick(EventContext context)        {            GObject sender = context.sender as GObject;            ShopCfg cfg = sender.parent.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);            }        }        private void ChildListItemRender(int index, GObject obj)        {            UI_ComItem uiItemChild = UI_ComItem.Proxy(obj);            var shopCfg = uiItemChild.target.parent.parent.data as ShopCfg;            var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);            int[][] result;            result = itemCfg.itemsArr;            var itemArr = result[index];            var itemCfgChild = ItemCfgArray.Instance.GetCfg(itemArr[0]);            uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild);            uiItemChild.m_txtCount.text = itemArr[1].ToString();            uiItemChild.target.data = itemCfgChild;            uiItemChild.m_QualityType.selectedIndex = itemCfgChild.rarity - 1;            UI_ComItem.ProxyEnd();        }        //弹出物品详细描述框        private void OnListSelectorItemClick(EventContext context)        {            GComponent item = context.data as GComponent;            ItemCfg itemCfg = item.data as ItemCfg;            GoodsItemTipsController.ShowItemTips(itemCfg.id);        }        public void UpTime()        {            var activityInfoByTypeList =                ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB1);            var list = activityInfoByTypeList                .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 InitPageInex()        //    {        //        _pageIndex = 0;        //    }        //    private void UpdateView(ListUtil.NavigateType type)        //    {        //        //筛选一条数据用来界面渲染        //var list = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData3;        //        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;        //        }        //        _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), data.EndTime);        //        _ui.m_list.data = data.ShopCfgIds;        //        _ui.m_list.itemRenderer = ListItemRender;        //        DestroyObjectFromView();        //        _ui.m_list.numItems = data.ShopCfgIds.Count;        //        _ui.m_list.visible = true;        //    }        //    private void UpViewNone()        //    {        //        LimitedTimeGiftBoxDataManager.Instance.UpLtgGbItemData3();        //        UpdateView(ListUtil.NavigateType.None);        //    }        //    //上一条        //    private void OnBtnPreviousClick()        //    {        //        UpdateView(ListUtil.NavigateType.Previous);        //    }        //    //下一条        //    private void OnBtnNextClick()        //    {        //        UpdateView(ListUtil.NavigateType.Next);        //    }    }}
 |