using System; using System.Collections; using UnityEngine; using UI.LuckyBox; using System.Collections.Generic; using FairyGUI; using System.Linq; using cfg.GfgCfg; using ET; namespace GFGGame { public class LuckyBoxNewDressView : BaseWindow { private UI_LuckyBoxNewDressUI _ui; private List _rewardList = new List(); private List _rewardParamList = new List(); private List _newRewardList = new List(); private List _oldRewardList = new List(); // private List _showRewardList = new List(); // private int _type = 0;//弹窗类型:0可跳过,1:首次获得物品不可跳过,2首次获得物品不可跳过,不弹获得套装界面 private EffectUI _effectUI1; private EffectUI _effectUI2; private EffectUI _effectUI3; private EffectUI _effectUI4; private EffectUI _effectUI5; private EffectUI _effectUI6; private EffectUI _effectUI7; public override void Dispose() { EffectUIPool.Recycle(_effectUI1); _effectUI1 = null; EffectUIPool.Recycle(_effectUI2); _effectUI2 = null; EffectUIPool.Recycle(_effectUI3); _effectUI3 = null; EffectUIPool.Recycle(_effectUI4); _effectUI4 = null; if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { try { base.OnInit(); packageName = UI_LuckyBoxNewDressUI.PACKAGE_NAME; _ui = UI_LuckyBoxNewDressUI.Create(); if (_ui == null) { Debug.LogError("Failed to create UI_LuckyBoxNewDressUI!"); return; } this.viewCom = _ui.target; isfullScreen = true; this.modal = true; if (_ui.m_loaBg != null) { _ui.m_loaBg.onTouchBegin.Add(OnClickBg); } if (_ui.m_btnPass != null) { _ui.m_btnPass.onClick.Add(Hide); } if (_ui.m_loaBg != null) { _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg"); } UpdateEffect(); } catch (Exception e) { Debug.LogError(e); } } private void UpdateEffect() { EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_ck", "ui_ck_zs", onComplete: (effect) => { if (effect != null) { _effectUI1 = effect; } }); EffectUIPool.CreateEffectUI(_ui.m_holder_star, "ui_LuckyBox", "bg_liuxing", onComplete: (effect) => { if (effect != null) { _effectUI2 = effect; } }); EffectUIPool.CreateEffectUI(_ui.m_holder_bg, "ui_LuckyBox", "CK_UI", onComplete: (effect) => { if (effect != null) { _effectUI3 = effect; } }); EffectUIPool.CreateEffectUI(_ui.m_holder_cloud, "ui_LuckyBox", "bg_cloud", onComplete: (effect) => { if (effect != null) { _effectUI4 = effect; } }); } protected override void OnShown() { try { base.OnShown(); // 确保UI已经创建 if (_ui == null || _ui.m_t_open == null) { Debug.LogError("UI components not initialized properly!"); return; } _ui.m_loaBg.touchable = false; _rewardParamList.Clear(); _rewardList.Clear(); _rewardParamList.AddRange(this.viewData as List); _rewardList = this.viewData as List; _newRewardList.Clear(); _oldRewardList.Clear(); for (int i = 0; i < _rewardList.Count; i++) { long hasCount = ItemDataManager.GetItemNum(_rewardList[i].id); int thisCount = GetThisCount(_rewardList[i].id, _rewardList); bool isAddToNew = IsAddToNewRewardList(_rewardList[i].id); if (thisCount == Convert.ToInt32(hasCount) && !isAddToNew) { _newRewardList.Add(_rewardList[i]); } else { _oldRewardList.Add(_rewardList[i]); } } UpdateView(); OnTimerClick(1); } catch (Exception e) { Debug.LogError(e); } //Timers.inst.Add((float)0.5, 1, OnTimerClick); } private void UpdateView() { // 确保UI组件存在 if (_ui == null || _ui.m_comCard == null || _ui.m_comCard.m_holder == null || _ui.m_comCard.m_holder1 == null || _ui.m_comCard.m_holder_get == null) { Debug.LogError("UI components not initialized properly!"); return; } // 清理旧特效 EffectUIPool.Recycle(_effectUI5); _effectUI5 = null; EffectUIPool.Recycle(_effectUI6); _effectUI6 = null; EffectUIPool.Recycle(_effectUI7); _effectUI7 = null; _rewardList = _newRewardList.Count > 0 ? _newRewardList : _oldRewardList; if (_rewardList.Count - 1 < 0) { Debug.LogWarning("No rewards to show"); return; } ItemData itemdata = _rewardList[_rewardList.Count - 1]; ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemdata.id); if (itemCfg == null) { Debug.LogError($"Item config not found for id: {itemdata.id}"); return; } // 根据稀有度创建特效 switch (itemCfg.Rarity) { case ConstDressRarity.Rarity_TIANYI: EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Yellow_01", 100, (effect) => { _effectUI5 = effect; _ui.m_comCard.m_holder.visible = true; }); EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Yellow_01_top", 100, (effect) => { _effectUI6 = effect; _ui.m_comCard.m_holder1.visible = true; }); break; case ConstDressRarity.Rarity_GUOSE: EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_GS_012", 100, (effect) => { _effectUI5 = effect; _ui.m_comCard.m_holder.visible = true; }); break; case ConstDressRarity.Rarity_DIANCANG: EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Purple_02", 100, (effect) => { _effectUI5 = effect; _ui.m_comCard.m_holder.visible = true; }); EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Purple_02_top", 100, (effect) => { _effectUI6 = effect; _ui.m_comCard.m_holder1.visible = true; }); break; case ConstDressRarity.Rarity_ZHENXI: EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Bule_03", 100, (effect) => { _effectUI5 = effect; _ui.m_comCard.m_holder.visible = true; }); break; case ConstDressRarity.Rarity_FANPIN: EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_grey_04", 100, (effect) => { _effectUI5 = effect; _ui.m_comCard.m_holder.visible = true; }); break; } EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder_get, "ui_LuckyBox", "CK_OneBigCard_end", onComplete: (effect) => { if (effect != null) { _effectUI7 = effect; } }); // 更新UI显示 _ui.m_comCard.m_loaType.url = ResPathUtil.GetCommonGameResPath("hz_bq_shuxing_" + itemCfg.Rarity); _ui.m_comCard.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg); _ui.m_comCard.m_loaProperty.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.MainScore); _ui.m_comCard.m_txtName.text = itemCfg.Name; _ui.m_comCard.m_txtDiscribe.text = itemCfg.Desc; // 确保过渡动画对象存在 if (_ui.m_t_open != null) { if (itemCfg.ItemType == ConstItemType.CARD) { //_ui.m_t_open.Play(() => { ViewManager.Show(itemCfg.Id); }); ViewManager.Show(itemCfg.Id); } else { //_ui.m_t_open.Play(); } } else { Debug.LogError("Transition m_t_open is null!"); } if (LuckyBoxDataManager.Instance.FirstRewardList.ContainsKey(_rewardList.Count - 1)) { LuckyBoxDataManager.Instance.FirstRewardList.Remove(_rewardList.Count - 1); } _rewardList.RemoveAt(_rewardList.Count - 1); } private void OnTimerClick(object param) { _ui.m_loaBg.touchable = true; } private void OnClickBg() { //_ui.m_t_close.Play(() => //{ //_ui.m_comCard.m_holder.visible = false; //_ui.m_comCard.m_holder1.visible = false; //if (_newRewardList.Count == 0 && _oldRewardList.Count == 0) //{ if (!GetSuitItemController.isAuto) { this.Hide(); EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_REWARD_SHOW); } // } // else { // _ui.m_t_open.Play(); // UpdateView(); // } //}); } private int GetThisCount(int itemId, List rewards) { int count = 0; for (int i = 0; i < rewards.Count; i++) { if (rewards[i].id == itemId) { count++; } } return count; } private bool IsAddToNewRewardList(int itemId) { for (int i = 0; i < _newRewardList.Count; i++) { if (itemId == _newRewardList[i].id) { return true; } } return false; } protected override void OnHide() { EffectUIPool.Recycle(_effectUI5); _effectUI5 = null; EffectUIPool.Recycle(_effectUI6); _effectUI6 = null; _ui.m_t_close.Stop(true, false); _ui.m_t_open.Stop(true, false); _rewardList.Clear(); // Timers.inst.Remove(OnTimerClick); _ui.m_loaBg.touchable = true; base.OnHide(); //ViewManager.Show(_rewardParamList); } } }