using FairyGUI; using UI.LuckyBox; using System.Collections.Generic; using System.Collections; using cfg.GfgCfg; using ET; using System; using UnityEngine; namespace GFGGame { public class LuckyBoxBonusShowView : BaseWindow { private UI_LuckBoxBonusShowUI _ui; private List _rewardList = new List(); private List _rewardItemList = new List(); private Dictionary> _effListTen = new Dictionary>(); private Dictionary _effList = new Dictionary(); private Dictionary _itemHasNew = new Dictionary(); private Dictionary _itemIdList = new Dictionary(); private Dictionary _itemObjList = new Dictionary(); private List _recordOpenIndex = new List(); //记录打开过得item位置 private List _recordTurnIndex = new List(); //记录播放过item位置 private int _chooseIndex = -1; //当前选中的index private int _countShow = 0; //第几次展示 private bool _handClick = false; //手动点击开启 private bool _AnimationWait = true; //抽卡动画等待加载完毕 bool _touchLoaBg = true; //防止点击背景事件太快 private EffectUI _effectUI1; private EffectUI _effectUI2; private EffectUI _effectUI3; private Dictionary _effectUIDic = new Dictionary(); private bool _allEffectsLoaded = false; private int _loadingEffectCount = 0; public override void Dispose() { try { EffectUIPool.Recycle(_effectUI1); _effectUI1 = null; EffectUIPool.Recycle(_effectUI2); _effectUI2 = null; EffectUIPool.Recycle(_effectUI3); _effectUI3 = null; ClearAllEffects(); if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } catch (Exception e) { Debug.LogError(e); } } private void ClearAllEffects() { try { for (int key = 0; key < _effListTen.Count; key++) { if (_effListTen.ContainsKey(key)) { for (int key1 = 0; key1 < _effListTen[key].Count; key1++) { if (_effListTen[key].ContainsKey(key1)) { EffectUIPool.Recycle(_effListTen[key][key1]); _effListTen[key][key1] = null; } } } } _effListTen.Clear(); for (int key = 0; key < _effList.Count; key++) { if (_effList.ContainsKey(key)) { EffectUIPool.Recycle(_effList[key]); _effList[key] = null; } } _effList.Clear(); foreach (var v in _effectUIDic) { EffectUIPool.Recycle(v.Value); } _effectUIDic.Clear(); } catch (Exception e) { Debug.LogError(e); } } protected override void OnInit() { try { base.OnInit(); packageName = UI_LuckBoxBonusShowUI.PACKAGE_NAME; _ui = UI_LuckBoxBonusShowUI.Create(); this.viewCom = _ui.target; isfullScreen = true; _ui.m_loaBg.onClick.Add(OnClickLoaBg); _ui.m_BtnPass.onClick.Add(OnClickBtnPass); } catch (Exception e) { Debug.LogError(e); } } protected override void AddEventListener() { try { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_REWARD_SHOW, ReferNextShow); EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_ANIMATION_WAIT, SetAnimationWait); EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_SHOW_VIEW_CLOSE, OthershowViewClose); } catch (Exception e) { Debug.LogError(e); } } protected override void RemoveEventListener() { try { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_REWARD_SHOW, ReferNextShow); EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_ANIMATION_WAIT, SetAnimationWait); EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_SHOW_VIEW_CLOSE, OthershowViewClose); } catch (Exception e) { Debug.LogError(e); } } protected override void OnShown() { try { base.OnShown(); _allEffectsLoaded = false; _touchLoaBg = false; _rewardList.Clear(); _rewardList.AddRange(this.viewData as List); _itemIdList.Clear(); _itemObjList.Clear(); _recordOpenIndex.Clear(); _recordTurnIndex.Clear(); _itemHasNew.Clear(); _ui.m_BtnPass.visible = false; _ui.m_touchFlipOpen.touchable = false; _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg"); // 异步加载所有特效 Timers.inst.StartCoroutine(LoadAllEffects(() => { _allEffectsLoaded = true; SetupViewAfterEffectsLoaded(); })); } catch (Exception e) { Debug.LogError(e); } } private IEnumerator LoadAllEffects(Action onComplete) { // 加载背景特效 EffectUIPool.CreateEffectUI(_ui.m_holder_star, "ui_LuckyBox", "bg_liuxing", onComplete: (effect) => { if (effect != null) { _effectUI1 = effect; } }); EffectUIPool.CreateEffectUI(_ui.m_holder_bg, "ui_LuckyBox", "CK_UI", onComplete: (effect) => { if (effect != null) { _effectUI2 = effect; } }); EffectUIPool.CreateEffectUI(_ui.m_holder_cloud, "ui_LuckyBox", "bg_cloud", onComplete: (effect) => { if (effect != null) { _effectUI3 = effect; } }); // 等待所有背景特效加载完成 while (_effectUI1.GetObj() == null || _effectUI2.GetObj() == null || _effectUI3.GetObj() == null) { yield return null; } onComplete?.Invoke(); } private void SetupViewAfterEffectsLoaded() { try { if (!_allEffectsLoaded) return; if (_rewardList.Count == 1) { _ui.m_c1.selectedIndex = 0; UpdateItem(_ui.m_itemOne.target, 0, 1); } else { _ui.m_c1.selectedIndex = 1; for (int i = 0; i < _rewardList.Count; i++) { UpdateItem(_ui.target.GetChild("item" + i).asCom, i, 10); } } // 修改,因为加了抽奖动画,在进入后就直接筛选掉所有不是新的 for (int i = 0; i < _rewardList.Count; i++) { UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[i]); if (!item.m_comIcon.m_imgNew.visible) { _recordTurnIndex.Add(i); _recordOpenIndex.Add(i); } UI_LuckyBoxBonusShowItem.ProxyEnd(); } if (GetSuitItemController.isAuto) { OnClickBtnPass(); } Timers.inst.Add(0.5f, 1, UpDataTimeTouchLoaBg); } catch (Exception e) { Debug.LogError(e); } } protected override void OnHide() { try { _rewardList.Clear(); base.OnHide(); Timers.inst.Remove(UpDataTime); Timers.inst.Remove(UpClickDataTime); Timers.inst.Remove(touchFlipOpen); Timers.inst.Remove(UpDataTimeTouchLoaBg); GetSuitItemController.isAuto = false; _touchLoaBg = true; EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_BONUS_VIEW_CLOSE); } catch (Exception e) { Debug.LogError(e); } } private void UpdateItem(GComponent com, int index, int countType) { try { if (!_allEffectsLoaded) return; UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com); ItemData itemData = _rewardList[index]; ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemData.id); item.m_comIcon.m_c1.selectedIndex = itemCfg.Rarity; item.m_comIcon.m_txtName.text = itemCfg.Name; item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg); item.m_comIcon.m_FlipOpenType.selectedIndex = 0; item.m_comIcon.m_t1.Play(); // 圆盘出现时等待玩家点击的特效 switch (itemCfg.Rarity) { case 3: if (!_effectUIDic.ContainsKey("CK_Loop_Wait_Chen" + index)) { EffectUIPool.CreateEffectUI(item.m_waitClick_eff, "ui_LuckyBox", "CK_Loop_Wait_Chen", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_Loop_Wait_Chen" + index, effect); } }); } break; case 4: if (!_effectUIDic.ContainsKey("CK_Loop_Wait_GS" + index)) { EffectUIPool.CreateEffectUI(item.m_waitClick_eff, "ui_LuckyBox", "CK_Loop_Wait_GS", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_Loop_Wait_GS" + index, effect); } }); } break; case 5: if (!_effectUIDic.ContainsKey("CK_Loop_Wait_Jin" + index)) { EffectUIPool.CreateEffectUI(item.m_waitClick_eff, "ui_LuckyBox", "CK_Loop_Wait_Jin", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_Loop_Wait_Jin" + index, effect); } }); } break; } int count = 0; bool isFirst = false; for (int i = 0; i < _rewardList.Count; i++) { if (_rewardList[i].id == itemData.id) count++; if (count == 1 && i == index) isFirst = true; } item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst; if (_itemHasNew.ContainsKey(index)) _itemHasNew[index] = item.m_comIcon.m_imgNew.visible; else _itemHasNew.Add(index, item.m_comIcon.m_imgNew.visible); item.m_t0.Play(); if (item.target.data == null) { item.target.onClick.Add(ShowItemTips); } item.target.data = index; _itemIdList.Add(index, itemCfg.Id); _itemObjList.Add(index, com); UI_LuckyBoxBonusShowItem.ProxyEnd(); } catch (Exception e) { Debug.LogError(e); } } private void ShowItemTips(EventContext context) { try { if (!_allEffectsLoaded || !_touchLoaBg) return; _touchLoaBg = false; Timers.inst.Add(0.5f, 1, UpDataTimeTouchLoaBg); GObject obj = context.sender as GObject; int index = (int)obj.data; _chooseIndex = index; GoodsItemTipsController.ShowItemTips(_itemIdList[index]); } catch (Exception e) { Debug.LogError(e); } } private void HandClickItem(int index) { try { if (!_allEffectsLoaded) return; _ui.m_touchFlipOpen.touchable = true; _handClick = true; ClickItem(index); //翻牌动画 Timers.inst.Add(1f, 1, UpClickDataTime, index); } catch (Exception e) { Debug.LogError(e); } } private void UpClickDataTime(object param = null) { try { if (!_allEffectsLoaded) return; int index = (int)param; Timers.inst.Remove(UpClickDataTime); if (_recordTurnIndex.Contains(index) && _recordOpenIndex.Contains(index)) { HideOtherShowWindow(); _ui.m_touchFlipOpen.touchable = false; } else ClickItem(index); } catch (Exception e) { Debug.LogError(e); } } void ClickItem(int index) { try { if (!_allEffectsLoaded) return; if (_recordOpenIndex.Count >= _rewardList.Count) _ui.m_BtnPass.visible = false; if (!_recordOpenIndex.Contains(index)) { TurnItem(index); } else { if (!_recordTurnIndex.Contains(index)) ShowTurnItem(index); else GoodsItemTipsController.ShowItemTips(_itemIdList[index]); } } catch (Exception e) { Debug.LogError(e); } } private void UpDataTimeTouchLoaBg(object param = null) { try { _touchLoaBg = true; } catch (Exception e) { Debug.LogError(e); } } private void OnClickLoaBg(EventContext context) { try { if (!_allEffectsLoaded || !_touchLoaBg) return; _touchLoaBg = false; Timers.inst.Add(0.5f, 1, UpDataTimeTouchLoaBg); if (_recordOpenIndex.Count >= _rewardList.Count) { _chooseIndex = -1; this.Hide(); } else { for (int index = 0; index < _rewardList.Count; index++) { if (!_recordOpenIndex.Contains(index)) { _chooseIndex = index; HandClickItem(index); break; } } } } catch (Exception e) { Debug.LogError(e); } } private void OnClickBtnPass() { try { if (!_allEffectsLoaded) return; for (int index = 0; index < _rewardList.Count; index++) { if (!_recordOpenIndex.Contains(index)) { int count = 0; bool isFirst = false; for (int i = 0; i < _rewardList.Count; i++) { if (_rewardList[i].id == _rewardList[index].id) count++; if (count == 1 && i == index) isFirst = true; } bool open = count == ItemDataManager.GetItemNum(_rewardList[index].id) && isFirst; if (!open) { _chooseIndex = -1; ClickItem(index); } } } ClickPass(); } catch (Exception e) { Debug.LogError(e); } } private void ClickPass() { try { if (!_allEffectsLoaded) return; GetSuitItemController.isAuto = true; _ui.m_touchFlipOpen.touchable = true; _ui.m_BtnPass.visible = false; for (int i = 0; i < _rewardList.Count; i++) { TurnItem(i); } //展示获得物品 Timers.inst.Add(LuckyBoxDataManager.ANIMATION_TIME, 0, UpDataTime); } catch (Exception e) { Debug.LogError(e); } } private void UpDataTime(object param = null) { try { if (!_allEffectsLoaded) return; _ui.m_touchFlipOpen.touchable = true; if (_recordTurnIndex.Count >= _rewardList.Count) { Timers.inst.Remove(UpDataTime); HideOtherShowWindow(); _ui.m_touchFlipOpen.touchable = false; GetSuitItemController.isAuto = false; } for (int i = 0; i < _rewardList.Count; i++) { if (!_recordTurnIndex.Contains(i)) { ShowTurnItem(i); break; } } } catch (Exception e) { Debug.LogError(e); } } private void ShowTurnItem(int index) { try { if (!_allEffectsLoaded || !_AnimationWait) return; UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]); if (!item.m_comIcon.m_imgNew.visible) { _recordTurnIndex.Add(index); _ui.m_touchFlipOpen.touchable = false; UI_LuckyBoxBonusShowItem.ProxyEnd(); return; } _countShow += 1; //判断是否有套装需要展示 int suitId = SuitCfgArray.Instance.GetSuitIdOfItem(_itemIdList[index]); ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_itemIdList[index]); if (suitId > 0 && itemCfg.ItemType != ConstItemType.CARD) { if (_countShow == 1) { ViewManager.Hide(); ViewManager.Hide(); ViewManager.Hide(); _rewardItemList.Clear(); _rewardItemList.Add(_rewardList[index]); ViewManager.Show(_rewardItemList); } else { ViewManager.Hide(); ViewManager.Hide(); int count = 0; int totalCount = 0; DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount); if (_countShow == 2) //展示进度条界面 { int countSuitId = 0; for (int i = index + 1; i < _rewardList.Count; i++) { _itemHasNew.TryGetValue(i, out bool isNew); var itemRewardCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_rewardList[i].id); if (isNew && itemRewardCfg.ItemType == ConstItemType.DRESS_UP && itemRewardCfg.SuitId == suitId) { countSuitId++; } } count = count - countSuitId; ViewManager.Show(new object[] { suitId, countSuitId }); } else if (_countShow == 3) //展示集齐套装界面 { ViewManager.Hide(); ViewManager.Show(suitId); _AnimationWait = false; } //判断是否需要显示集齐套装界面(需要的时候晚3个定时器时间) if (count <= 0 || totalCount <= 0 || count < totalCount || (count >= totalCount && _countShow > 5)) { _recordTurnIndex.Add(index); _countShow = 0; if (_handClick) { _handClick = false; _ui.m_touchFlipOpen.touchable = false; } } } } else { //词牌和不是套装进这里 ViewManager.Hide(); ViewManager.Hide(); ViewManager.Hide(); _rewardItemList.Clear(); _rewardItemList.Add(_rewardList[index]); ViewManager.Show(_rewardItemList); _recordTurnIndex.Add(index); _countShow = 0; Timers.inst.Add(1.5f, 1, touchFlipOpen); //防止点击太快 } UI_LuckyBoxBonusShowItem.ProxyEnd(); } catch (Exception e) { Debug.LogError(e); } } private void TurnItem(int index) { try { if (!_allEffectsLoaded || _recordOpenIndex.Contains(index)) return; // 删除 "等待翻开" 的特效 if (_effectUIDic.ContainsKey("CK_Loop_Wait_Chen" + index)) { EffectUIPool.Recycle(_effectUIDic["CK_Loop_Wait_Chen" + index]); _effectUIDic.Remove("CK_Loop_Wait_Chen" + index); } if (_effectUIDic.ContainsKey("CK_Loop_Wait_GS" + index)) { EffectUIPool.Recycle(_effectUIDic["CK_Loop_Wait_GS" + index]); _effectUIDic.Remove("CK_Loop_Wait_GS" + index); } if (_effectUIDic.ContainsKey("CK_Loop_Wait_Jin" + index)) { EffectUIPool.Recycle(_effectUIDic["CK_Loop_Wait_Jin" + index]); _effectUIDic.Remove("CK_Loop_Wait_Jin" + index); } UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]); if (!item.m_comIcon.m_imgNew.visible && !_recordTurnIndex.Contains(index)) { _recordTurnIndex.Add(index); } ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_itemIdList[index]); // 点击特效 if (!_effectUIDic.ContainsKey("CK_Cirle_DJ" + index)) { EffectUIPool.CreateEffectUI(item.m_comIcon.m_click_eff, "ui_LuckyBox", "CK_Cirle_DJ", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_Cirle_DJ" + index, effect); } }); } else { EffectUIPool.CreateEffectUI(item.m_comIcon.m_click_eff, "ui_LuckyBox", "CK_Cirle_DJ", onComplete: (effect) => { if (effect != null) { _effectUIDic["CK_Cirle_DJ" + index] = effect; } }); } // 翻开特效 switch (itemCfg.Rarity) { case 1: EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_HuiLan_UI", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_LanHui_UI" + index, effect); } }); EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_LanHui_TX", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_LanHui_TX" + index, effect); } }); break; case 2: EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_LanHui_UI", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_LanHui_UI" + index, effect ); } }); EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_LanHui_TX", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_LanHui_TX" + index, effect ); } }); break; case 3: EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_Chen_UI", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_Chen_UI" + index, effect); } }); EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_Chen_TX", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_Chen_TX" + index, effect); } }); break; case 4: EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_GS_UI", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_GS_UI" + index, effect); } }); EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_GS_TX", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_GS_TX" + index, effect); } }); break; case 5: EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_Jin_UI", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_Jin_UI" + index, effect); } }); EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_Jin_TX", onComplete: (effect) => { if (effect != null) { _effectUIDic.Add("CK_OpenAfter_Jin_TX" + index, effect); } }); break; } _recordOpenIndex.Add(index); UI_LuckyBoxBonusShowItem.ProxyEnd(); } catch (Exception e) { Debug.LogError(e); } } private void touchFlipOpen(object param) { try { Timers.inst.Remove(touchFlipOpen); _ui.m_touchFlipOpen.touchable = false; } catch (Exception e) { Debug.LogError(e); } } protected void OthershowViewClose() { try { _ui.m_touchFlipOpen.touchable = false; } catch (Exception e) { Debug.LogError(e); } } protected void ReferNextShow() { try { if (!_allEffectsLoaded || GetSuitItemController.isAuto) return; int suitId = 0; if (_itemIdList.ContainsKey(_chooseIndex)) suitId = SuitCfgArray.Instance.GetSuitIdOfItem(_itemIdList[_chooseIndex]); if (_chooseIndex != -1 && suitId > 0) ClickItem(_chooseIndex); else { if (_handClick) { _handClick = false; _ui.m_touchFlipOpen.touchable = false; } } } catch (Exception e) { Debug.LogError(e); } } protected void SetAnimationWait() { try { _AnimationWait = true; } catch (Exception e) { Debug.LogError(e); } } private void HideOtherShowWindow() { try { ViewManager.Hide(); ViewManager.Hide(); ViewManager.Hide(); ViewManager.Hide(); } catch (Exception e) { Debug.LogError(e); } } } }