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 _lcukyBoxCtrl = new Dictionary(); //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 DressUpObjUI _dressUpObjUIXiHe; //private GameObject _scenePrefab; //private GameObject _sceneObject; //private GoWrapper _wrapper4; //private DressUpObj _dressUpObj; private DressUpObjUI _dressUpObjUIChangXi; private bool isActiveBoxOpen = false; private int _activeBoxId = 0; private int _bgIndex = 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(_gameObject, _wrapper); //SceneController.DestroyObjectFromView(_gameObject1, _wrapper1); //SceneController.DestroyObjectFromView(_gameObject2, _wrapper2); //SceneController.DestroyObjectFromView(_gameObject3, _wrapper3); 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("jingzhongh_bg"); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, OnListBgScroll); EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, OnListBgScroll); } 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; OnListBgScroll(); updateBoxEffect(); Timers.inst.AddUpdate(CheckGuide); } private string GetListItemResource(int index) { if (index == 0 && _activeBoxId > 0) { return "UI://LuckyBox/ComBox"; } else { int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[index]; return string.Format("UI://LuckyBox/ComBox_{0}", boxId); } } private void RenderListBgItem(int index, GObject obj) { int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[index]; LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId); LuckyBoxDataManager.Instance.InitData(boxId); UI_ComBox comBox = UI_ComBox.Proxy(obj); comBox.m_comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(cfg.resArr[_bgIndex]); if (!_lcukyBoxCtrl.ContainsKey(boxId)) { _lcukyBoxCtrl.Add(boxId, new LuckyBoxController(comBox.m_comModel.target)); if (_ui.m_listBg.ChildIndexToItemIndex(0) == index) { _lcukyBoxCtrl[boxId].OnShown(boxId); } } comBox.m_btnPreview.m_c1.selectedIndex = boxId; 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); 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.target.data == null) { comBox.m_btnBuyOne.target.onClick.Add(OnClickBtnBuyOne); } comBox.m_btnBuyOne.target.data = boxId; if (comBox.m_btnBuyTen.target.data == null) { comBox.m_btnBuyTen.target.onClick.Add(OnClickBtnBuyTen); } comBox.m_btnBuyTen.target.data = boxId; if (comBox.m_btnPreview.target.data == null) { comBox.m_btnPreview.target.onClick.Add(OnClickBtnPreview); } comBox.m_btnPreview.target.data = boxId; obj.data = boxId; // if (comBox.m_grpLuckyBox != null) // { // comBox.m_grpLuckyBox.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); comBox.m_txtTime.text = string.Format("剩余{0}{1}", num, str); comBox.m_grpLuckyBox.visible = boxId == _activeBoxId; } UI_ComBox.ProxyEnd(); } // private void UpdateBg(object param) // { // string[] resArr = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.currentBoxId).resArr; // _bgIndex++; // if (_bgIndex >= resArr.Length) _bgIndex = 0; // GObject gObject = _ui.m_listBg.GetChildAt(0); // if (gObject == null) return; // GComponent item = gObject.asCom; // if (item.gameObjectName != "ComBox_2") return; // GLoader loaBg = item.GetChild("loaBg").asLoader; // loaBg.url = ResPathUtil.GetBgImgPath(resArr[_bgIndex]); // } private void OnBtnLeftClick() { int index = _curIndex - 1; // _curIndex--; index = Mathf.Max(0, index); _ui.m_listBg.ScrollToView(index, true); // OnListBgScroll(); } private void OnBtnRightClick() { int index = _curIndex + 1; // _curIndex++; index = Mathf.Min(_ui.m_listBg.numItems - 1, index); _ui.m_listBg.ScrollToView(index, true); // OnListBgScroll(); } private void OnListBgScroll() { _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnHide(); _curIndex = _ui.m_listBg.ChildIndexToItemIndex(0); LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex]; _bgIndex = 0; _valueBarController.UpdateCJ(); _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnShown(LuckyBoxDataManager.Instance.currentBoxId); _ui.m_btnLeft.grayed = _curIndex <= 0; _ui.m_btnRight.grayed = _curIndex >= _ui.m_listBg.numItems - 1; } 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; textField.asTextField.text = string.Format("剩余{0}{1}", num, str); } 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(EventContext context) // { // GObject obj = context.sender as GObject; // int boxId = (int)obj.data; // int storeId = boxId == 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, boxId }); // this.Hide(); // } 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, OnListBgScroll); EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, OnListBgScroll); } 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(0); 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(cfg.id, 2); } } }