| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 | using FairyGUI;using UI.LuckyBox;using UI.CommonGame;using System;namespace GFGGame{    public class LuckyBoxView : BaseWindow    {        private UI_LuckyBoxUI _ui;        private ValueBarController _valueBarController;        public override void Dispose()        {            _valueBarController.Dispose();            _valueBarController = null;            base.Dispose();        }        protected override void OnInit()        {            base.OnInit();            packageName = UI_LuckyBoxUI.PACKAGE_NAME;            _ui = UI_LuckyBoxUI.Create();            this.viewCom = _ui.target;            isfullScreen = true;            _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_btnBuyOne.onClick.Add(OnClickBtnBuyOne);            _ui.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);            _ui.m_btnPreview.onClick.Add(OnClickBtnPreview);            _ui.m_btnExchange.onClick.Add(OnClickBtnExChange);            _ui.m_btnLeft.onClick.Add(() => { onClickChange(-1); });            _ui.m_btnRight.onClick.Add(() => { onClickChange(1); });            _ui.m_listBg.itemRenderer = RenderListBgItem;            _ui.m_c1.onChanged.Add(OnListBgScroll);//分页控制器            Reset();//初始默认值        }        protected override void OnShown()        {            base.OnShown();            EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateNormal);            EventAgent.AddEventListener(ConstMessage.MONEY_CHANGE, UpdateNormal);            _ui.m_listBg.numItems = 3;            int index = Array.IndexOf(LuckyBoxDataManager.Instance.luckyBoxIds, LuckyBoxBonusDataCache.currentBoxId);            // if (!GuideDataManager.CheckGuideIsCompletedAtThisLogin(ConstGuideId.MAIN_UI_BTN_ZHAI_XING))            // {            //     index = _ui.m_listBg.numItems - 1;            // }            _ui.m_listBg.ScrollToView(index);            _ui.m_listBg.scrollPane.decelerationRate = 0.8f;            Timers.inst.Add(1, 0, CheckTime);            _valueBarController.OnShown();            _valueBarController.Controller(4);            onClickChange(0);        }        private void RenderListBgItem(int index, GObject obj)        {            UI_ComListBgItem item = UI_ComListBgItem.Proxy(obj);            LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.luckyBoxIds[index]);            item.m_loaBg.url = string.Format("ui://LuckyBox/{0}", cfg.res);        }        private void CheckTime(object param = null)        {            int startTime = LuckyBoxDataManager.Instance.startTime;            int endTime = LuckyBoxDataManager.Instance.endTime;            int curTime = DateUtils.Instance.GetCurTime();            if (curTime < startTime || curTime >= endTime)            {                //抽奖活动未开启或已过时                if (_ui.m_c1.selectedIndex == 2)                {                    _ui.m_listBg.ScrollToView(0);                }                _ui.m_listBg.numItems = 2;                Timers.inst.Remove(CheckTime);                return;            }            UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(2)).m_txtTime.text = DateUtils.Instance.getFormatBySecond(endTime - curTime);        }        private void OnListBgScroll()        {            if (_ui.m_c1.selectedIndex == -1 || _ui.m_listBg.numChildren <= 0) return;            onClickChange(0);            UI_ComListBgItem item = UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(_ui.m_c1.selectedIndex));            item.m_c1.selectedIndex = _ui.m_c1.selectedIndex;            LuckyBoxBonusDataCache.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[_ui.m_c1.selectedIndex];            UpdateNormal();        }        private void UpdateNormal()        {            LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxBonusDataCache.currentBoxId);            _valueBarController.UpdateCJ(LuckyBoxBonusDataCache.currentBoxId);            _ui.m_comCostOne.m_txtCost.text = luckyBoxCfg.costNum.ToString();// string.Format("{0}",);            _ui.m_comCostTen.m_txtCost.text = luckyBoxCfg.costNumTen.ToString();// string.Format("{1}", );            _ui.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg.costID).res);            _ui.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg.costID).res);            // if (!GuideController.TryGuideByGuideId(_ui.m_btnBuyTen, ConstGuideId.MAIN_UI_BTN_ZHAI_XING, 1, true, "点击按钮,开始抽奖,可以抽到好看的服装哦"))            // {            //     GuideController.TryGuideByGuideId(_ui.m_btnBack, ConstGuideId.LUCKY_BOX_VIEW_BTN_BACK, 1, true, "点击按钮,返回主界面", 0, ConstGuideId.MAIN_UI_BTN_ZHAI_XING);            // }            // if (GuideDataManager.GetGuideCount(ConstGuideId.LUCKY_BOX_VIEW_BTN_BACK) <= 0)            // {            Timers.inst.AddUpdate(UpdateToCheckGuide);            // }            int count = LuckyBoxBonusDataCache.GetOwnedCount();            _ui.m_txtOwned.SetVar("v1", "" + count).FlushVars();        }        private void onClickChange(int count)        {            _ui.m_c1.selectedIndex = _ui.m_c1.selectedIndex + count;            if (_ui.m_c1.selectedIndex == _ui.m_listBg.numItems - 1)            {                _ui.m_btnRight.visible = false;            }            else            {                _ui.m_btnRight.visible = true;            }            if (_ui.m_c1.selectedIndex == 0)            {                _ui.m_btnLeft.visible = false;            }            else            {                _ui.m_btnLeft.visible = true;            }        }        private void OnClickBtnExChange()        {            int storeId = ConstStoreId.CLOTHING_STORE_ID;            if (_ui.m_c1.selectedIndex == 2 || _ui.m_c1.selectedIndex == 1 || _ui.m_c1.selectedIndex == -1)            {                storeId = ConstStoreId.LUCKY_BOX_STORE_ID;            }            else if (_ui.m_c1.selectedIndex == 0)            {                storeId = ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID;            }            ViewManager.Show(ViewName.CLOTHING_SHOP_VIEW, new object[] { storeId }, new object[] { ViewName.LUCKY_BOX_VIEW });            this.Hide();        }        private void OnClickBtnPreview()        {            ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW);        }        private void OnClickBtnBuyOne()        {            LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxBonusDataCache.currentBoxId);            LuckyBoxBonusDataCache.CheckItemEnough(luckyBoxCfg.costID, luckyBoxCfg.costNum, 1, () =>             {                 ItemDataManager.Remove(luckyBoxCfg.costID, luckyBoxCfg.costNum);                 LuckyBoxDataManager.Instance.RewardList = LuckyBoxBonusDataCache.GetBonusList(1);                 ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, _ui.m_c1.selectedIndex);             });        }        private void OnClickBtnBuyTen()        {            // bool result = GuideController.TryCompleteGuide(ConstGuideId.MAIN_UI_BTN_ZHAI_XING);            LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxBonusDataCache.currentBoxId);            if (GuideDataManager.GetGuideCount(ConstGuideId.MAIN_UI_BTN_ZHAI_XING) <= 0)            {                Timers.inst.AddUpdate(UpdateToCheckGuide);                ItemDataManager.Remove(luckyBoxCfg.costID, luckyBoxCfg.costNumTen);                LuckyBoxDataManager.Instance.RewardList = LuckyBoxBonusDataCache.GetBonusList(10, true);                ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, _ui.m_c1.selectedIndex);            }            else            {                //判断消耗                LuckyBoxBonusDataCache.CheckItemEnough(luckyBoxCfg.costID, luckyBoxCfg.costNumTen, 10, () =>                 {                     ItemDataManager.Remove(luckyBoxCfg.costID, luckyBoxCfg.costNumTen);                     LuckyBoxDataManager.Instance.RewardList = LuckyBoxBonusDataCache.GetBonusList(10, false);                     ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, _ui.m_c1.selectedIndex);                 });            }        }        private void UpdateToCheckGuide(object param)        {            if (this.viewCom.parent != null)            {                if (GRoot.inst.GetTopWindow() == this.viewCom)                {                    if (GuideController.TryGuideByGuideId(_ui.m_btnBuyTen, ConstGuideId.MAIN_UI_BTN_ZHAI_XING, 1, true, "点击摘取十次"))                    {                        Timers.inst.Remove(UpdateToCheckGuide);                    }                    else                    {                        if (GuideController.TryGuideByGuideId(_ui.m_btnBack, ConstGuideId.LUCKY_BOX_VIEW_BTN_BACK, 1, true, "获得一套完整的服装啦,马上去试穿一下", 0, ConstGuideId.MAIN_UI_BTN_ZHAI_XING))                        {                            Timers.inst.Remove(UpdateToCheckGuide);                        }                    }                }            }        }        protected override void OnHide()        {            base.OnHide();            _valueBarController.OnHide();            Timers.inst.Remove(UpdateToCheckGuide);            Timers.inst.Remove(CheckTime);            EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateNormal);            EventAgent.RemoveEventListener(ConstMessage.MONEY_CHANGE, UpdateNormal);        }        private void OnClickBtnBack()        {            GuideController.TryCompleteGuide(ConstGuideId.LUCKY_BOX_VIEW_BTN_BACK);            this.Hide();            // ViewManager.Show(ViewName.MAINUI_VIEW, null, new object[] { ViewName.LUCKY_BOX_VIEW });            Reset();            ViewManager.GoBackFrom(ViewName.LUCKY_BOX_VIEW);        }        private void OnClickBtnHome()        {            GameController.GoBackToMainView();            Reset();        }        private void Reset()        {            LuckyBoxBonusDataCache.currentBoxId = 1;            _ui.m_c1.selectedIndex = 0;        }    }}
 |