| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769 | using FairyGUI;using UI.LuckyBox;using UI.CommonGame;using System;using System.Collections.Generic;using UnityEngine;using ET;using System.Linq;namespace GFGGame{    public class LuckyBoxView : BaseWindow    {        private UI_LuckyBoxUI _ui;        private ValueBarController _valueBarController;        private Dictionary<int, LuckyBoxController> _luckyBoxCtrl = new Dictionary<int, LuckyBoxController>();        private Dictionary<string, EffectUI> _effectUIDic = new Dictionary<string, EffectUI>();        private DressUpObjUI _dressUpObjUIXiHe;        private DressUpObjUI _dressUpObjUIChangXi;        private string activityEndTime = "[2024][2][2][00:00]";        Dictionary<int,GObject> _listActivityBtnObj = new Dictionary<int, GObject>();        private Dictionary<string, GGraph> effectNameDic = new Dictionary<string, GGraph>() { };         private int _activeBoxId = 0;        private int _curIndex = 0;        private int _activityId = 0;        private bool scrollTouch = true;  //左右箭头点击等滑动完成后才可以再次点击        private EffectUI _effectUI1;        private EffectUI _effectUI2;        private EffectUI _effectUI3;        private EffectUI _effectUI4;        public override void Dispose()        {            // Clear Effect            foreach (var v in _effectUIDic)            {                EffectUIPool.Recycle(v.Value);            }            EffectUIPool.Recycle(_effectUI1);            _effectUI1 = null;            EffectUIPool.Recycle(_effectUI2);            _effectUI2 = null;            EffectUIPool.Recycle(_effectUI3);            _effectUI3 = null;            EffectUIPool.Recycle(_effectUI4);            _effectUI4 = null;            _effectUIDic.Clear();            if (_valueBarController != null)            {                _valueBarController.Dispose();                _valueBarController = null;            }            foreach (int key in _luckyBoxCtrl.Keys)            {                _luckyBoxCtrl[key].Dispose();            }            _luckyBoxCtrl.Clear();            if (_dressUpObjUIXiHe != null)            {                _dressUpObjUIXiHe.Dispose();                _dressUpObjUIXiHe = null;            }            if (_dressUpObjUIChangXi != null)            {                _dressUpObjUIChangXi.Dispose();                _dressUpObjUIChangXi = null;            }            if (_ui != null)            {                _ui.Dispose();                _ui = null;            }            base.Dispose();        }        protected override void OnInit()        {            base.OnInit();            packageName = UI_LuckyBoxUI.PACKAGE_NAME;            _ui = UI_LuckyBoxUI.Create();            this.viewCom = _ui.target;            isfullScreen = true;            isReturnView = true;            _dressUpObjUIXiHe = new DressUpObjUI("SceneDressUp");            _dressUpObjUIChangXi = new DressUpObjUI("SceneDressUp");            _valueBarController = new ValueBarController(_ui.m_valueBar);            _ui.m_btnBack.onClick.Add(OnClickBtnBack);            _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);            _ui.m_btnRight.onClick.Add(OnBtnRightClick);            _ui.m_listBg.itemRenderer = RenderListBgItem;            _ui.m_listBg.SetVirtualAndLoop();  //虚拟循环列表            _ui.m_listBg.scrollPane.onScrollEnd.Add(OnScrollEnd);            _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");            effectNameDic.Add("zx_zwy_ll", _ui.m_effectZWH);            effectNameDic.Add("zx_twy_cx", _ui.m_effectTWH);            effectNameDic.Add("zx_twy_xh", _ui.m_effectTWH2);            effectNameDic.Add("zx_zwy_yjzh", _ui.m_effectZWH2);            _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_effectTWH, "ui_LuckyBox", "CK_TWH_01");            _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_effectZWH, "ui_LuckyBox", "CK_ZWH_01");            _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_effectTWH2, "ui_LuckyBox", "CK_TWH_02");            _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_effectZWH2, "ui_LuckyBox", "CK_ZWH_02");            AdaptScreen();        }        protected override void AddEventListener()        {            base.AddEventListener();            EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);            EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);            EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);            EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);            EventAgent.AddEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateBtnReward);            EventAgent.AddEventListener(ConstMessage.LUCKY_EFFECT_UPDATE, UpdateEffectVisible);        }        protected override void OnShown()        {            base.OnShown();                        Debug.Log("OnShown:LuckyBoxView");            //防止引导检测之前触发点击事件            GRoot.inst.touchable = false;            _valueBarController.OnShown();            _valueBarController.Controller(4);            LuckyBoxDataManager.Instance.luckyBoxIds.Clear();            LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_2);            LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_3);            _activeBoxId = 0;            _activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);            //第一个活动可能为轮换活动            if (LuckyBoxDataManager.Instance.RotatingId > 0)            {                RotatingLuckyBoxCfg rotatingLuckyBox = RotatingLuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.RotatingId);                _activeBoxId = rotatingLuckyBox.luckyBoxId;                LuckyBoxDataManager.Instance.endTime = TimeUtil.GetTimestamp(rotatingLuckyBox.endTime);                LuckyBoxDataManager.Instance.luckyBoxIds.Insert(0, _activeBoxId);            }            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];  //默认跳转进来是第一个活动            if (this.viewData != null)            {                int index = (int)this.viewData;  //传入的值为第几个活动,不是活动id                boxId = LuckyBoxDataManager.Instance.luckyBoxIds[index - 1];//是1的时候,就使用轮换活动,不是1就是传入的固定活动            }            //新手引导选中第一个活动            if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)                 boxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];            //第二个活动会有许愿活动出现            if (_activityId > 0 && boxId == LuckyBoxDataManager.BOX_ID_2)                GetWishingPoolInfo(_activityId);            LuckyBoxDataManager.Instance.currentBoxId = boxId;            _curIndex = LuckyBoxDataManager.Instance.luckyBoxIds.IndexOf(boxId);            LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;            _listActivityBtnObj.Clear();            _ui.m_listBg.numItems = LuckyBoxDataManager.Instance.luckyBoxIds.Count;            _ui.m_listBg.ScrollToView(_curIndex);            _ui.m_listBg.scrollPane.decelerationRate = 0.8f;            OnListBgScroll();            bool actLimitTsyOpen = LuckyBoxDataManager.Instance.GetActLimitTsyOpen();            //时间倒计时            if (_activeBoxId > 0)                Timers.inst.Add(1, 0, CheckTime);            //第二个活动的倒计时            if (actLimitTsyOpen)// && LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_2                Timers.inst.Add(1, 0, UpdateTime);            //第二个活动的模拟活动倒计时            if (!actLimitTsyOpen && boxId == LuckyBoxDataManager.BOX_ID_2)                Timers.inst.Add(1, 0, UpdateImitateTime);            Timers.inst.AddUpdate(CheckGuide);        }        private void RenderListBgItem(int index, GObject obj)        {            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[index];            UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);            LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            LuckyBoxDataManager.Instance.InitData(boxId);            if(!_listActivityBtnObj.ContainsKey(boxId))                _listActivityBtnObj.Add(boxId,obj);            else                _listActivityBtnObj[boxId] = obj;            comBox.m_ImgUp.visible = index == 0;            int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);            if (activityId > 0 && boxId == LuckyBoxDataManager.BOX_ID_2)            {                comBox.m_showActivityType.selectedIndex = 1;                UpGiftBox(comBox);            }            else if (boxId == LuckyBoxDataManager.BOX_ID_2) {                 long endTime = TimeUtil.DateTimeToTimestamp(activityEndTime);                if (endTime < TimeHelper.ServerNow())                    comBox.m_showActivityType.selectedIndex = 0;                else {                     comBox.m_showActivityType.selectedIndex = 2;                    long curTime = TimeHelper.ServerNow();                    if (endTime >= curTime)                        comBox.m_txtHasTime.text = "剩余时间: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);                }            }            else                comBox.m_showActivityType.selectedIndex = 0;            if (cfg.costNumfifty > 0)                comBox.m_comLuckBoxBtn.m_btnNumberType.selectedIndex = 1;            else                comBox.m_comLuckBoxBtn.m_btnNumberType.selectedIndex = 0;            if (_luckyBoxCtrl.ContainsKey(boxId))            {                _luckyBoxCtrl[boxId].OnHide();                _luckyBoxCtrl[boxId].Dispose();                _luckyBoxCtrl.Remove(boxId);            }            _luckyBoxCtrl.Add(boxId, new LuckyBoxController(comBox.m_comModel.target));            //comBox.m_comLuckBoxBtn.m_holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;            comBox.m_comLuckBoxBtn.m_comCostOne.m_txtCost.text = cfg.costNum.ToString();            comBox.m_comLuckBoxBtn.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);            comBox.m_comLuckBoxBtn.m_comCostTen.m_txtCost.text = cfg.costNumTen.ToString();            comBox.m_comLuckBoxBtn.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);            comBox.m_comLuckBoxBtn.m_comCostFifty.m_txtCost.text = cfg.costNumfifty.ToString();            comBox.m_comLuckBoxBtn.m_comCostFifty.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);            if (comBox.m_comLuckBoxBtn.m_btnBuyOne.data == null)                comBox.m_comLuckBoxBtn.m_btnBuyOne.onClick.Add(OnClickBtnBuyOne);            comBox.m_comLuckBoxBtn.m_btnBuyOne.data = boxId;            if (comBox.m_comLuckBoxBtn.m_btnBuyTen.data == null)            {                if (boxId != LuckyBoxDataManager.BOX_ID_3) {                     if (!_effectUIDic.ContainsKey("Button_Text_DianCang" + boxId))                        _effectUIDic.Add("Button_Text_DianCang" + boxId, EffectUIPool.CreateEffectUI(comBox.m_comLuckBoxBtn.m_Special_eff, "ui_LuckyBox", "Button_Text_DianCang"));                    if(!_effectUIDic.ContainsKey("Button_public" + boxId))                        _effectUIDic.Add("Button_public" + boxId, EffectUIPool.CreateEffectUI(comBox.m_comLuckBoxBtn.m_btnBuyTen_eff, "ui_LuckyBox", "Button_public"));                }                comBox.m_comLuckBoxBtn.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);            }            comBox.m_comLuckBoxBtn.m_btnBuyTen.data = boxId;            if (comBox.m_comLuckBoxBtn.m_btnBuyFifty.data == null)                comBox.m_comLuckBoxBtn.m_btnBuyFifty.onClick.Add(OnClickBtnBuyFifty);            comBox.m_comLuckBoxBtn.m_btnBuyFifty.data = boxId;            if (comBox.m_btnPreview.data == null)                comBox.m_btnPreview.onClick.Add(OnClickBtnPreview);            comBox.m_btnPreview.data = boxId;            if (comBox.m_btnReward.target.data == null)            {                comBox.m_btnReward.target.onClick.Add(OnClikcBtnReward);                comBox.m_btnShop.target.onClick.Add(OnClikcBtnShop);                comBox.m_btnGiftBag.target.onClick.Add(OnClikcBtnGiftBag);            }            comBox.m_btnReward.target.data = boxId;            obj.data = boxId;            comBox.m_grpTime.visible = (boxId == _activeBoxId);            if (boxId == _activeBoxId)            {                long endTime = LuckyBoxDataManager.Instance.endTime;                long curTime = TimeHelper.ServerNow();                long time = endTime - curTime;                string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);                comBox.m_txtTime.text = string.Format("轮换倒计时:{0}", strTime);            }            UI_ComBox1.ProxyEnd();        }        private async void GetWishingPoolInfo(int activityId)        {            bool result = await LuckyBoxSProxy.ReqGetWishingPoolInfo();            if (result)            {                int index = LuckyBoxDataManager.Instance.KsActivityId.IndexOf(activityId);                if (index < 0 || !LuckyBoxDataManager.Instance.VsStatus[index])                    ViewManager.Show<LuckyBoxWishView>(ConstLimitTimeActivityType.ActLimitTsy);            }        }        private void OnBtnLeftClick()        {            if (!scrollTouch) return;            scrollTouch = false;            int index = _curIndex - 1;            _ui.m_listBg.ScrollToView(index, true);            if (_activityId > 0 && index + 1 == LuckyBoxDataManager.BOX_ID_2)                GetWishingPoolInfo(_activityId);        }        private void OnBtnRightClick()        {            if (!scrollTouch) return;            scrollTouch = false;            int index = _curIndex + 1;            _ui.m_listBg.ScrollToView(index, true);            if (_activityId > 0 && index + 1 == LuckyBoxDataManager.BOX_ID_2)                GetWishingPoolInfo(_activityId);        }        private void OnScrollEnd()        {            scrollTouch = true;            // 未更新滚动位置的时候,不更新,防止不停的播放渐入动画            int index = _ui.m_listBg.GetFirstChildInView();            if (index == _curIndex)            {                return;            }            OnListBgScroll();        }        private void OnListBgScroll()        {            LuckyBoxController valueBox;            _luckyBoxCtrl.TryGetValue(LuckyBoxDataManager.Instance.currentBoxId, out valueBox);            if (valueBox != null)                _luckyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnHide();            _curIndex = _ui.m_listBg.GetFirstChildInView();            LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];            if (LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_3) {                _valueBarController.Controller(3);            }            else {                _valueBarController.Controller(4);            }            _valueBarController.UpdateCJ();            _luckyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnShown(LuckyBoxDataManager.Instance.currentBoxId);            LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;            UpdateFreeInfo();            UpdateListItemData();            UpdateEffect();        }        private void UpdateEffect()        {            //LuckyBoxCfg luckybox = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.currentBoxId);            //if(luckybox.name == "紫薇垣")            //{            //    _ui.m_effectZWH.visible = true;            //    _ui.m_effectTWH.visible = false;            //}            //else if (luckybox.name == "太微垣")            //{            //    _ui.m_effectZWH.visible = false;            //    _ui.m_effectTWH.visible = true;            //}            //else            //{            //    _ui.m_effectZWH.visible = false;            //    _ui.m_effectTWH.visible = false;            //}        }        private void UpdateBtnReward()        {            if (_curIndex == 1) {                int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];                GObject obj = _listActivityBtnObj[boxId];                UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);                RedDotController.Instance.SetComRedDot(comBox.m_btnReward.target, RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy), "", -21, 18);                comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();                UI_ComBox1.ProxyEnd();            }        }        private void OnClikcBtnReward()        {            ViewManager.Show<ActivityThemeLuckyBoxBonusView>(ConstLimitTimeActivityType.ActLimitTsy);        }        private void OnClikcBtnShop()        {            //ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_TSY });        }        //刷新摘星活动期间的数据        private void UpGiftBox(UI_ComBox1 comBox)        {            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];            LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();            comBox.m_txtCount.SetVar("name", cfg.name).FlushVars();            int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);            var activityInfoByTypeList = ActivityGlobalDataManager.Instance.GetActivityInfoByTypeAndID(ActivityType.XSLB3, activityId);            var list = activityInfoByTypeList.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();            if (list.Count == 0)            {                comBox.m_comBagTime.target.visible = false;                comBox.m_btnGiftBag.target.visible = false;            }            else            {                bool isSoldOut = true;                foreach (var activityInfo in list)                {                    ActivityOpenCfg activityOpenCfg = ActivityOpenCfgArray.Instance.GetCfg(activityInfo.ActivityId);                    var paramsArr = activityOpenCfg.paramsArr;                    foreach (var shopCfgId in paramsArr)                    {                        var shopCfg = ShopCfgArray.Instance.GetCfg(shopCfgId);                        var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfgId);                        //只要有一个商品还能购买,就不是售罄                        if (remainBuyNum > 0)                        {                            isSoldOut = false;                            break;                        }                    }                }                if (isSoldOut)                {                    comBox.m_comBagTime.target.visible = false;                    comBox.m_btnGiftBag.target.visible = false;                }                else                {                    comBox.m_comBagTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);                    comBox.m_comBagTime.target.visible = true;                    comBox.m_btnGiftBag.target.visible = true;                }            }            UpdateBtnReward();        }        //限时礼包按钮点击执行方法        private void OnClikcBtnGiftBag()        {            var activityInfoByTypeList =                ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);            var list = activityInfoByTypeList                .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();            if (list.Count == 0)                PromptController.Instance.ShowFloatTextPrompt("活动已结束");            else                ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });        }        private void UpdateListItemData()        {            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];            LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            GObject obj = _listActivityBtnObj[boxId];            UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);            LuckyBoxDataManager.Instance.GetOwnedCount(boxId, out int count, out int totalCount);            comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();            comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();            int boughtCount = GameGlobal.myNumericComponent.GetAsInt(cfg.numericType);            comBox.m_comLuckBoxBtn.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", cfg.maxCount - boughtCount);            UI_ComBox1.ProxyEnd();        }        private void CheckTime(object param = null)        {            if (LuckyBoxDataManager.Instance.currentBoxId != _activeBoxId) return;            long endTime = LuckyBoxDataManager.Instance.endTime;            long curTime = TimeHelper.ServerNow();            TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];            GObject item = _listActivityBtnObj[boxId];            if (item == null) return;            GObject textField = item.asCom.GetChild("txtTime");            if (textField == null) return;            long time = endTime - curTime;            string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);            textField.asTextField.text = string.Format("轮换倒计时:{0}", strTime);        }        private void UpdateImitateTime(object param = null)        {            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[1];            GObject item = _listActivityBtnObj[boxId];            GObject textField = item.asCom.GetChild("txtHasTime");            if (textField == null) return;            long curTime = TimeHelper.ServerNow();            long endTime = TimeUtil.DateTimeToTimestamp(activityEndTime);            if (endTime < curTime)            {                Timers.inst.Remove(UpdateImitateTime);                endTime = curTime;            }            textField.asTextField.text = "剩余时间: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);        }        private void UpdateTime(object param = null)        {            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[1];            GObject item = _listActivityBtnObj[boxId];            if (item == null) return;            GObject textField = item.asCom.GetChild("txtTsyTime");            if (textField == null) return;            int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);            var activityCfg = ActivityOpenCfgArray.Instance.GetCfg(activityId);            long endTime = 0;            if (activityCfg != null)                endTime = TimeUtil.DateTimeToTimestamp(activityCfg.endTime);            long curTime = TimeHelper.ServerNow();            if (endTime < curTime)            {                PromptController.Instance.ShowFloatTextPrompt("活动已结束");                Timers.inst.Remove(UpdateTime);                endTime = curTime;            }            TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);            textField.asTextField.text = "概率提升剩余: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);            //=====限时礼包倒计时            //UpGiftBox();            //EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_TIME);            //=====限时礼包倒计时END        }        private void OnClickBtnPreview(EventContext context)        {            GObject obj = context.sender as GObject;            int boxId = (int)obj.data;            ViewManager.Show<LuckyBoxPreShowView>(boxId);        }        private void OnClickBtnBuyOne(EventContext context)        {            GetSuitItemController.showSingle = true;            GObject obj = context.sender as GObject;            int boxId = (int)obj.data;            LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);            int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);            if (boughtCount + LuckyBoxDataManager.ONCE_TIME > luckyBoxCfg.maxCount)            {                PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");                return;            }            LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.ONCE_TIME, async () =>             {                 int activityId = 0;                 if (boxId == LuckyBoxDataManager.BOX_ID_2) {                     activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);                 }                 bool freeType = (freeTime > 0 && freeTime < TimeHelper.ServerNow());                 bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME, freeType, activityId);                 if (result)                 {                     ViewManager.Show<LuckyBoxStarView>();                     LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);                     GetSuitItemController.showSingle = false;                 }             });        }        private void OnClickBtnBuyTen(EventContext context)        {            GetSuitItemController.showSingle = true;            GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);            if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0                 && (GuideDataManager.currentGuideId == 0                 || (GuideDataManager.currentGuideId == cfg.id && GuideDataManager.currentGuideIdIndex != 2)))            {                //防止点击太快,在引导开启前就被点击到,导致引导卡死                return;            }            GObject obj = context.sender as GObject;            int boxId = (int)obj.data;            LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);            if (boughtCount + LuckyBoxDataManager.TEN_TIME > luckyBoxCfg.maxCount)            {                PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");                return;            }            LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.TEN_TIME, async () =>            {                int activityId = 0;                if (boxId == LuckyBoxDataManager.BOX_ID_2)                {                    activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);                }                bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.TEN_TIME,false, activityId);                if (result)                {                    ViewManager.Show<LuckyBoxStarView>();                    LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);                    GetSuitItemController.showSingle = false;                }            });        }        private void OnClickBtnBuyFifty(EventContext context)        {            GetSuitItemController.showSingle = true;            GObject obj = context.sender as GObject;            int boxId = (int)obj.data;            LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);            if (boughtCount + LuckyBoxDataManager.FIFTY_TIME > luckyBoxCfg.maxCount)            {                PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");                return;            }            LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.FIFTY_TIME, async () =>            {                bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.FIFTY_TIME, false, 0);                if (result)                {                    BonusController.TryShowBonusList(LuckyBoxDataManager.Instance.RewardList);                    LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 3);                    GetSuitItemController.showSingle = false;                }            });        }        protected override void OnHide()        {            base.OnHide();            GRoot.inst.touchable = true;            _valueBarController.OnHide();            foreach (int key in _luckyBoxCtrl.Keys)            {                _luckyBoxCtrl[key].OnHide();            }            Timers.inst.Remove(CheckTime);            Timers.inst.Remove(UpdateTime);            Timers.inst.Remove(UpdateImitateTime);            Timers.inst.Remove(CheckGuide);            Debug.Log("OnHide:  LuckyBoxView");        }        protected override void RemoveEventListener()        {            base.RemoveEventListener();            EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);            EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);            EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);            EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);            EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateBtnReward);            EventAgent.RemoveEventListener(ConstMessage.LUCKY_EFFECT_UPDATE, UpdateEffectVisible);        }        private void OnClickBtnBack()        {            Reset();            ViewManager.GoBackFrom(typeof(LuckyBoxView).FullName);        }        private void Reset()        {            LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];        }        private void CheckGuide(object param)        {            GRoot.inst.touchable = true;            if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)                UpdateToCheckGuide(null);            else                Timers.inst.Remove(CheckGuide);        }        protected override void UpdateToCheckGuide(object param)        {            if (!ViewManager.CheckIsTopView(this.viewCom)) return;            if (_curIndex > 0) return;            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];            GObject gObject = _listActivityBtnObj[boxId];            if (gObject == null) return;             GButton btnBuyTen = gObject.asCom.GetChild("comLuckBoxBtn").asCom.GetChild("btnBuyTen").asButton;            GuideController.TryGuide(null, ConstGuideId.LUCKY_BOX, 1, "“摘星”里可以通过星辰的力量获得服饰。", -1, true, _ui.target.height - 600);            GuideController.TryGuide(btnBuyTen, ConstGuideId.LUCKY_BOX, 2, "点击摘取十次。");            GuideController.TryCompleteGuide( ConstGuideId.LUCKY_BOX, 2);        }        protected override void TryCompleteGuide()        {            base.TryCompleteGuide();            GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);            GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 2);        }        private void UpdateFreeInfo()        {            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];            long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);            GObject obj = _listActivityBtnObj[boxId];            UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);            if (freeTime > 0)            {                long timeDifference = freeTime - TimeHelper.ServerNow();                if (freeTime > TimeHelper.ServerNow())                {                    comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;                    comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = true;                    string strFreeTime = TimeUtil.FormattingTimeTo_DDHHmm(timeDifference);                    comBox.m_comLuckBoxBtn.m_txtFreeTime.text = string.Format("{0}后免费", strFreeTime);                }                else                {                    comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 1;                    comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;                }            }            else            {                comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;                comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;            }            RedDotController.Instance.SetComRedDot(comBox.m_comLuckBoxBtn.m_btnBuyOne, comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex == 1, "", -29, 9);            RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, LuckyBoxDataManager.Instance.RedBtnLeft(_curIndex));            RedDotController.Instance.SetComRedDot(_ui.m_btnRight, LuckyBoxDataManager.Instance.RedBtnRight(_curIndex), "", -60, 70);            UI_ComBox1.ProxyEnd();        }        private void AdaptScreen()        {            float offsetY = _ui.m_grpTop.y + ViewGlobal.GetRealTopOffset();            _ui.m_grpTop.SetXY(_ui.m_grpTop.x, offsetY);        }        private void UpdateEffectVisible(EventContext eventContext)        {            var resStr = (string)eventContext.data;            foreach(var item in effectNameDic)            {                if(item.Key == resStr)                {                    item.Value.visible = true;                }                else                {                    item.Value.visible = false;                }            }        }    }}
 |