| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 | using FairyGUI;using UI.LuckyBox;using UI.CommonGame;using System;using System.Collections.Generic;using UnityEngine;using ET;namespace GFGGame{    public class LuckyBoxView : BaseView    {        private UI_LuckyBoxUI _ui;        private ValueBarController _valueBarController;        private Dictionary<int, LuckyBoxController> _lcukyBoxCtrl = new Dictionary<int, LuckyBoxController>();        private GameObject _gameObject0;        private GameObject _gameObject1;        private GoWrapper _wrapper0;        private GoWrapper _wrapper1;        private DressUpObjUI _dressUpObjUIXiHe;        private DressUpObjUI _dressUpObjUIChangXi;        private bool isActiveBoxOpen = false;        private int _activeBoxId = 0;        private int _curIndex = 0;        public override void Dispose()        {            if (_valueBarController != null)            {                _valueBarController.Dispose();                _valueBarController = null;            }            foreach (int key in _lcukyBoxCtrl.Keys)            {                _lcukyBoxCtrl[key].Dispose();            }            _lcukyBoxCtrl.Clear();            if (_dressUpObjUIXiHe != null)            {                _dressUpObjUIXiHe.Dispose();                _dressUpObjUIXiHe = null;            }            if (_dressUpObjUIChangXi != null)            {                _dressUpObjUIChangXi.Dispose();                _dressUpObjUIChangXi = null;            }            SceneController.DestroyObjectFromView(_gameObject0, _wrapper0);            SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);            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;            _dressUpObjUIXiHe = new DressUpObjUI("SceneDressUp");            _dressUpObjUIChangXi = new DressUpObjUI("SceneDressUp");            // _ui.m_txtRemainTimes.visible = false;            _valueBarController = new ValueBarController(_ui.m_valueBar);            _ui.m_btnBack.onClick.Add(OnClickBtnBack);            // _ui.m_btnHome.onClick.Add(OnClickBtnHome);            _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);            _ui.m_btnRight.onClick.Add(OnBtnRightClick);            // _ui.m_listBg.SetVirtual();            _ui.m_listBg.itemRenderer = RenderListBgItem;            // _ui.m_listBg.itemProvider = GetListItemResource;            _ui.m_listBg.scrollPane.onScrollEnd.Add(OnListBgScroll);            _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");        }        protected override void AddEventListener()        {            base.AddEventListener();            EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);            EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);        }        protected override void OnShown()        {            base.OnShown();            LuckyBoxDataManager.Instance.luckyBoxIds.Clear();            LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_2);            LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_3);            _activeBoxId = 0;            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)            {                boxId = (int)this.viewData;            }            if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0) boxId = LuckyBoxDataManager.BOX_ID_2;            LuckyBoxDataManager.Instance.currentBoxId = boxId;            if (_activeBoxId > 0) Timers.inst.Add(1, 0, CheckTime);            _valueBarController.OnShown();            _valueBarController.Controller(4);            _curIndex = LuckyBoxDataManager.Instance.luckyBoxIds.IndexOf(boxId);            _ui.m_listBg.numItems = LuckyBoxDataManager.Instance.luckyBoxIds.Count;            _ui.m_listBg.ScrollToView(_curIndex);            _ui.m_listBg.scrollPane.decelerationRate = 0.8f;            LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;            OnListBgScroll();            updateBoxEffect();            Timers.inst.AddUpdate(CheckGuide);        }        private void RenderListBgItem(int index, GObject obj)        {            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[index];        }        private void OnBtnLeftClick()        {            int index = _curIndex - 1;            if (index < 0) return;            _ui.m_listBg.ScrollToView(index, true);        }        private void OnBtnRightClick()        {            int index = _curIndex + 1;            // if (index >= LuckyBoxDataManager.Instance.luckyBoxIds.Count) return;            index = Mathf.Min(_ui.m_listBg.numItems - 1, index);            _ui.m_listBg.ScrollToView(index, true);        }        private void OnListBgScroll()        {            if (_lcukyBoxCtrl.ContainsKey(LuckyBoxDataManager.Instance.currentBoxId)) _lcukyBoxCtrl[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();            UpdateListItem();            _ui.m_btnLeft.grayed = _curIndex <= 0;            _ui.m_btnRight.grayed = _curIndex >= _ui.m_listBg.numItems - 1;            LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;        }        private void UpdateListItem()        {            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];            LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            LuckyBoxDataManager.Instance.InitData(boxId);            GObject obj = _ui.m_listBg.GetChildAt(_curIndex);            UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);            if (!_lcukyBoxCtrl.ContainsKey(boxId))            {                _lcukyBoxCtrl.Add(boxId, new LuckyBoxController(comBox.m_comModel.target));            }            _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnShown(LuckyBoxDataManager.Instance.currentBoxId);            comBox.m_imgSpecial.visible = boxId != LuckyBoxDataManager.BOX_ID_3;            GGraph holder = comBox.m_btnBuyTen.GetChild("holder").asGraph;            holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;            comBox.m_holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;            string resPath0 = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "Button_Glow");            SceneController.AddObjectToView(_gameObject0, _wrapper0, holder, resPath0, out _gameObject0, out _wrapper0);            string resPath1 = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "but_text_dc");            SceneController.AddObjectToView(_gameObject1, _wrapper1, comBox.m_holder, resPath1, out _gameObject1, out _wrapper1);            comBox.m_comCostOne.m_txtCost.text = cfg.costNum.ToString();            comBox.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);            comBox.m_comCostTen.m_txtCost.text = cfg.costNumTen.ToString();            comBox.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);            if (comBox.m_btnBuyOne.data == null)            {                comBox.m_btnBuyOne.onClick.Add(OnClickBtnBuyOne);            }            comBox.m_btnBuyOne.data = boxId;            if (comBox.m_btnBuyTen.data == null)            {                comBox.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);            }            comBox.m_btnBuyTen.data = boxId;            if (comBox.m_btnPreview.data == null)            {                comBox.m_btnPreview.onClick.Add(OnClickBtnPreview);            }            comBox.m_btnPreview.data = boxId;            obj.data = boxId;            comBox.m_grpTime.visible = boxId == _activeBoxId;            if (boxId == _activeBoxId)            {                long endTime = LuckyBoxDataManager.Instance.endTime;                long curTime = TimeHelper.ServerNow();                // TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);                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);                comBox.m_loaTitle.url = "ui://LuckyBox/zx_title_1";            }            else            {                comBox.m_loaTitle.url = string.Format("ui://LuckyBox/zx_title_{0}", boxId);            }            UI_ComBox1.ProxyEnd();            UpdateListItemData();        }        private void UpdateListItemData()        {            int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];            LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            GObject obj = _ui.m_listBg.GetChildAt(_curIndex);            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_txtRemainTimes.text = string.Format("今日剩余次数:{0}", cfg.maxCount - boughtCount);            UI_ComBox1.ProxyEnd();        }        private void UpdateEffect()        {        }        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);            GObject item = _ui.m_listBg.GetChildAt(0);            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 updateBoxEffect()        {            if (isActiveBoxOpen)            {            }        }        private void OnClickBtnPreview(EventContext context)        {            GObject obj = context.sender as GObject;            int boxId = (int)obj.data;            ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW, boxId);        }        private void OnClickBtnBuyOne(EventContext context)        {            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.ONCE_TIME > luckyBoxCfg.maxCount)            {                PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");                return;            }            LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.ONCE_TIME, async () =>             {                 bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME);                 if (result)                 {                     ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, null, new object[] { ViewName.LUCKY_BOX_VIEW, boxId });                     LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);                 }             });        }        private void OnClickBtnBuyTen(EventContext context)        {            GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);            if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0 && (GuideDataManager.currentGuideId == 0 || 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 () =>            {                bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.TEN_TIME);                if (result)                {                    ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, null, new object[] { ViewName.LUCKY_BOX_VIEW, boxId });                    LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);                }            });        }        protected override void OnHide()        {            base.OnHide();            _valueBarController.OnHide();            foreach (int key in _lcukyBoxCtrl.Keys)            {                _lcukyBoxCtrl[key].OnHide();            }            Timers.inst.Remove(CheckTime);            // Timers.inst.Remove(UpdateBg);            Timers.inst.Remove(CheckGuide);            // Timers.inst.Remove(UpdateTime);        }        protected override void RemoveEventListener()        {            base.RemoveEventListener();            EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);            EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);        }        private void OnClickBtnBack()        {            Reset();            ViewManager.GoBackFrom(ViewName.LUCKY_BOX_VIEW);        }        private void OnClickBtnHome()        {            GameController.GoBackToMainView();        }        private void Reset()        {            LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];        }        private void CheckGuide(object param)        {            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;            GObject gObject = _ui.m_listBg.GetChildAt(_curIndex);            if (gObject == null) return;            GButton btnBuyTen = gObject.asCom.GetChild("btnBuyTen").asButton;            GuideController.TryGuide(null, ConstGuideId.LUCKY_BOX, 1, "“摘星”里可以通过星辰的力量获得服饰。", -1, true, _ui.target.height - 600);            GuideController.TryGuide(btnBuyTen, ConstGuideId.LUCKY_BOX, 2, "点击摘取十次。");        }        protected override void TryCompleteGuide()        {            base.TryCompleteGuide();            GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);            GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 2);        }    }}
 |