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 GameObject _gameObject; private GoWrapper _wrapper; private GameObject _gameObject1; private GoWrapper _wrapper1; private GameObject _gameObject2; private GoWrapper _wrapper2; private GameObject _gameObject3; private GoWrapper _wrapper3; private bool isActiveBoxOpen = false; private int bgIndex = 0; public override void Dispose() { if (_valueBarController != null) { _valueBarController.Dispose(); _valueBarController = 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; _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.target.onClick.Add(OnClickBtnBuyOne); _ui.m_btnBuyTen.target.onClick.Add(OnClickBtnBuyTen); _ui.m_btnPreview.target.onClick.Add(OnClickBtnPreview); _ui.m_btnExchange.target.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 AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateNormal); EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNormal); } protected override void OnShown() { base.OnShown(); int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[0]; if (this.viewData != null) { object[] datas = (this.viewData as object[]); if (datas != null && datas.Length > 1) { boxId = (int)datas[1]; } else { boxId = (int)this.viewData; } } LuckyBoxDataManager.Instance.currentBoxId = boxId; isActiveBoxOpen = Array.IndexOf(LuckyBoxDataManager.Instance.luckyBoxIds, LuckyBoxDataManager.BOX_ID_1) >= 0; bgIndex = 0; int index = Array.IndexOf(LuckyBoxDataManager.Instance.luckyBoxIds, LuckyBoxDataManager.Instance.currentBoxId); _ui.m_listBg.numItems = LuckyBoxDataManager.Instance.luckyBoxIds.Length; _ui.m_listBg.ScrollToView(index); _ui.m_listBg.scrollPane.decelerationRate = 0.8f; if (isActiveBoxOpen) { Timers.inst.Add(1, 0, CheckTime); } _valueBarController.OnShown(); _valueBarController.Controller(4); // onClickChange(0); // UpdateNormal(); OnListBgScroll(); updateBoxEffect(); Timers.inst.Add(8, 0, UpdateBg); Timers.inst.AddUpdate(CheckGuide); } private void RenderListBgItem(int index, GObject obj) { UI_ComListBgItem item = UI_ComListBgItem.Proxy(obj); int id = LuckyBoxDataManager.Instance.luckyBoxIds[index]; LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(id); item.m_loaBg.url = ResPathUtil.GetBgImgPath(cfg.resArr[0]); item.target.data = id; UI_ComListBgItem.ProxyEnd(); } private void CheckTime(object param = null) { if (!isActiveBoxOpen) { //活动未开启 LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[0]; Timers.inst.Remove(CheckTime); return; } int endTime = LuckyBoxDataManager.Instance.endTime; int curTime = TimeHelper.ServerNowSecs; TimeUtil.FormattingTime(curTime, endTime, out int num, out string str); UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(0)).m_txtTime.text = string.Format("{0}", num); UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(0)).m_txtTimeStr.text = string.Format("{0}", str); UI_ComListBgItem.ProxyEnd(); } private void OnListBgScroll() { UI_ComListBgItem item = UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(_ui.m_c1.selectedIndex)); LuckyBoxDataManager.Instance.currentBoxId = (int)item.target.data;// LuckyBoxDataManager.Instance.luckyBoxIds[_ui.m_c1.selectedIndex]; item.m_grpTime.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1; item.m_imgTitle.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1; item.m_holder.visible = isActiveBoxOpen && LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1; item.m_holder1.visible = isActiveBoxOpen && LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1; item.m_loaImg.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_3; onClickChange(0); UpdateNormal(); } private void UpdateNormal() { LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.currentBoxId); _valueBarController.UpdateCJ(LuckyBoxDataManager.Instance.currentBoxId); _ui.m_comCostOne.m_txtCost.text = luckyBoxCfg.costNum.ToString(); _ui.m_comCostTen.m_txtCost.text = luckyBoxCfg.costNumTen.ToString(); _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); _ui.m_btnPreview.m_c1.selectedIndex = _ui.m_c1.selectedIndex; _ui.m_btnExchange.m_c1.selectedIndex = _ui.m_c1.selectedIndex; int count = LuckyBoxDataManager.Instance.GetOwnedCount(); _ui.m_txtOwned.SetVar("v1", "" + count).FlushVars(); } private void onClickChange(int count) { _ui.m_c1.selectedIndex = _ui.m_c1.selectedIndex + count; _ui.m_imgSpecial.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1; _ui.m_btnRight.visible = _ui.m_c1.selectedIndex != _ui.m_listBg.numItems - 1; _ui.m_btnLeft.visible = _ui.m_c1.selectedIndex != 0; _ui.m_btnBuyOne.m_holder.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1; _ui.m_btnBuyTen.m_holder.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1; } private void updateBoxEffect() { if (isActiveBoxOpen) { int index = Array.IndexOf(LuckyBoxDataManager.Instance.luckyBoxIds, LuckyBoxDataManager.BOX_ID_1); UI_ComListBgItem item = UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(index)); string resPath = ResPathUtil.GetViewEffectPath("ui_cj", "ui_cj_bt"); SceneController.AddObjectToView(_gameObject, _wrapper, item.m_holder, resPath, out _gameObject, out _wrapper); string resPath3 = ResPathUtil.GetDressUpAnimationPath("dz_jiyuet"); SceneController.AddObjectToView(_gameObject3, _wrapper3, item.m_holder1, resPath3, out _gameObject3, out _wrapper3, 120); string resPath1 = ResPathUtil.GetViewEffectPath("ui_cj", "ui_cj_sl"); SceneController.AddObjectToView(_gameObject1, _wrapper1, _ui.m_btnBuyOne.m_holder, resPath1, out _gameObject1, out _wrapper1); SceneController.AddObjectToView(_gameObject2, _wrapper2, _ui.m_btnBuyTen.m_holder, resPath1, out _gameObject2, out _wrapper2); UI_ComListBgItem.ProxyEnd(); } } private void OnClickBtnExChange() { int storeId = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1 ? ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID : ConstStoreId.LUCKY_BOX_STORE_ID; ViewManager.Show(ViewName.CLOTHING_SHOP_VIEW, new object[] { storeId }, new object[] { ViewName.LUCKY_BOX_VIEW, LuckyBoxDataManager.Instance.currentBoxId }); this.Hide(); } private void OnClickBtnPreview() { ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW); } private void OnClickBtnBuyOne() { LuckyBoxDataManager.Instance.CheckItemEnough(LuckyBoxDataManager.Instance.currentBoxId, LuckyBoxDataManager.ONCE_TIME, async () => { bool result = await LuckyBoxSProxy.ReqGetBonus(LuckyBoxDataManager.Instance.currentBoxId, LuckyBoxDataManager.ONCE_TIME); if (result) { ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, null, new object[] { ViewName.LUCKY_BOX_VIEW, LuckyBoxDataManager.Instance.currentBoxId }); LogServerHelper.SendNodeLog((int)PlayParticipationEnum.ZAI_XING, 2); } }); } private void OnClickBtnBuyTen() { LuckyBoxDataManager.Instance.CheckItemEnough(LuckyBoxDataManager.Instance.currentBoxId, LuckyBoxDataManager.TEN_TIME, async () => { bool result = await LuckyBoxSProxy.ReqGetBonus(LuckyBoxDataManager.Instance.currentBoxId, LuckyBoxDataManager.TEN_TIME); if (result) { ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, null, new object[] { ViewName.LUCKY_BOX_VIEW, LuckyBoxDataManager.Instance.currentBoxId }); LogServerHelper.SendNodeLog((int)PlayParticipationEnum.ZAI_XING, 2); } }); } private void UpdateBg(object param) { int index = Array.IndexOf(LuckyBoxDataManager.Instance.luckyBoxIds, LuckyBoxDataManager.Instance.currentBoxId); UI_ComListBgItem item = UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(index)); int id = (int)item.target.data; string[] resArr = LuckyBoxCfgArray.Instance.GetCfg(id).resArr; bgIndex++; if (bgIndex >= resArr.Length) bgIndex = 0; item.m_loaBg.url = ResPathUtil.GetBgImgPath(resArr[bgIndex]); UI_ComListBgItem.ProxyEnd(); } protected override void OnHide() { base.OnHide(); _valueBarController.OnHide(); Timers.inst.Remove(CheckTime); Timers.inst.Remove(UpdateBg); Timers.inst.Remove(CheckGuide); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateNormal); EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNormal); } private void OnClickBtnBack() { this.Hide(); Reset(); ViewManager.GoBackFrom(ViewName.LUCKY_BOX_VIEW); } private void OnClickBtnHome() { GameController.GoBackToMainView(); // Reset(); } private void Reset() { LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.BOX_ID_1; } private void CheckGuide(object param) { if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0 || GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0) { UpdateToCheckGuide(null); } else { Timers.inst.Remove(CheckGuide); } } protected override void UpdateToCheckGuide(object param) { if (!ViewManager.CheckIsTopView(this.viewCom)) return; GuideController.TryGuide(_ui.m_btnBuyTen.target, ConstGuideId.LUCKY_BOX, 3, "点击摘取十次"); GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.FREEDOM_DRESS, 1, "获得一套完整的服装啦,马上去试穿一下"); } } }