using cfg; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using Spine.Unity; using System; namespace game { public class PotionGridUI : MonoBehaviour { private int m_Index; public int Index { get { return m_Index; } } private int m_ColorType; public int ColorType { get { return m_ColorType; } } private bool m_IsIdle = false; public bool IsIdle { get { return m_IsIdle; } set { m_IsIdle = value; } } [SerializeField] private List m_PourWaterEffectList = new List(); [SerializeField] private List m_JudgmentFailedEffectList = new List(); [SerializeField] private List m_AudioFlyList = new List(); [NonSerialized] public PotionGridUI fromPotionGridUI = null; private PotionItemData m_Data; public PotionItemData ItemData { get { return m_Data; } } private PotionItem m_PotionItem; public PotionItem PotionItem { get => m_PotionItem; } private RectTransform m_RectTransform; private Button m_btn_gild; private Image m_bg_nml; private Image m_bg_light; private Image m_paint; private GameObject m_icon; private SkeletonGraphic m_spine_icon; private Animation m_Animation = null; private UnityAction m_Callback = null; private EventPotionDataManager m_DataManager; #region 音效相关 public void CloseAudioFly() { foreach (var gameObject in m_AudioFlyList) { gameObject.SetActive(false); } } public void OpenAudioFly() { foreach (var gameObject in m_AudioFlyList) { gameObject.SetActive(true); } } #endregion #region 数据相关 public void SetData(PotionItemData pData, int pIndex, EventPotionBlock potionBlock, bool isShow) { if (isShow == false) { m_Index = pIndex; gameObject.SetActive(false); return; } gameObject.SetActive(true); m_Data = pData; m_Index = pIndex; m_ColorType = m_Data.ColorTypeList[m_Index]; int itemType = m_ColorType; if (itemType > 100) { itemType = itemType % 100; m_icon.gameObject.SetActive(false); m_paint.gameObject.SetActive(true); } else if (itemType > 0) { m_icon.gameObject.SetActive(true); m_paint.gameObject.SetActive(false); } else { m_icon.gameObject.SetActive(false); m_paint.gameObject.SetActive(false); } EventPotionResource res = m_DataManager.GetPotionResource(itemType); if (!string.IsNullOrEmpty(res.PaintResName)) m_paint.sprite = m_DataManager.SpriteAtlas.GetSprite(res.PaintResName); if (!string.IsNullOrEmpty(res.ItemResName)) SetIconSkin(res.ItemResName); if (m_ColorType > 0 && m_ColorType < 100) { PlaySpinAnimation(0, EventPotionConfig.spine_potion_idle, true); } if (potionBlock != null) { int num = m_Data.ColorTypeList.Count; m_bg_nml.sprite = m_DataManager.SpriteAtlas.GetSprite(potionBlock.ResourceList[m_Index]); m_bg_light.sprite = m_DataManager.SpriteAtlas.GetSprite(potionBlock.ResourceLightList[m_Index]); if (m_Data.ShelfTypeList[m_Index] == EventPotionShelfType.Shelf_Success) { m_bg_nml.gameObject.SetActive(false); m_bg_light.gameObject.SetActive(true); } else { m_bg_nml.gameObject.SetActive(true); m_bg_light.gameObject.SetActive(false); } } } public void Copy(PotionGridUI potionGridUI, bool copyDataEntirely, bool copyPosition = true) { this.m_RectTransform.sizeDelta = potionGridUI.m_RectTransform.sizeDelta; this.m_RectTransform.localScale = potionGridUI.m_RectTransform.localScale; if (copyPosition) { this.m_RectTransform.position = potionGridUI.m_RectTransform.position; } this.m_ColorType = potionGridUI.m_ColorType; if (this.m_ColorType > 0 && this.m_ColorType < 100) { EventPotionResource res = m_DataManager.GetPotionResource(this.m_ColorType); if (!string.IsNullOrEmpty(res.PaintResName) && !string.IsNullOrEmpty(res.ItemResName)) { int typeIndex = res.TypeIndex; if (typeIndex >= 0 && typeIndex < res.TypeCount) { int count = m_PourWaterEffectList.Count; for (int i = 0; i < count; ++i) { if (i == typeIndex) { m_PourWaterEffectList[i].SetActive(true); } else { m_PourWaterEffectList[i].SetActive(false); } } count = m_JudgmentFailedEffectList.Count; for (int i = 0; i < count; ++i) { if (i == typeIndex) { m_JudgmentFailedEffectList[i].SetActive(true); } else { m_JudgmentFailedEffectList[i].SetActive(false); } } } } } this.m_paint.sprite = potionGridUI.m_paint.sprite; SetIconSkin(potionGridUI.GetIconSkin()); } public void ResetImageSprite() { m_ColorType = m_Data.ColorTypeList[m_Index]; if (m_ColorType <= 0) { return; } int itemType = m_ColorType; if (itemType > 100) { itemType = itemType % 100; } EventPotionResource res = m_DataManager.GetPotionResource(itemType); if (string.IsNullOrEmpty(res.PaintResName) == false) m_paint.sprite = m_DataManager.SpriteAtlas.GetSprite(res.PaintResName); if (string.IsNullOrEmpty(res.ItemResName) == false) SetIconSkin(res.ItemResName); int num = m_Data.ColorTypeList.Count; EventPotionBlock potionBlock = m_DataManager.GetEventPotionBlock(num); if (potionBlock != null) { m_bg_nml.sprite = m_DataManager.SpriteAtlas.GetSprite(potionBlock.ResourceList[m_Index]); m_bg_light.sprite = m_DataManager.SpriteAtlas.GetSprite(potionBlock.ResourceLightList[m_Index]); } } public string GetIconSkin() { return m_spine_icon.Skeleton.Skin.Name; } public void SetIconSkin(string skin) { m_spine_icon.Skeleton.SetSkin(skin); } public void PlaySpinAnimation(int trackIndex, string animationName, bool loop) { m_spine_icon.AnimationState.SetAnimation(trackIndex, animationName, loop); } public void SetFromGridUI(PotionGridUI gridUI) { if (gridUI == null) { this.fromPotionGridUI = null; return; } this.fromPotionGridUI = gridUI; SetFromDisplayAreaIndex(gridUI.Index); } public int GetColorType() { if (m_Data == null) return -1; return m_Data.GetColorType(Index); } public void SetColorType(int type) { if (m_Data == null) return; m_Data.SetColorType(m_Index, type); } public EventPotionShelfType GetShelfType() { if (m_Data == null) return EventPotionShelfType.Shelf_Default; return m_Data.ShelfTypeList[m_Index]; } public void SetShelfTypeSuccess() { if (m_Data == null) return; m_Data.ShelfTypeList[m_Index] = EventPotionShelfType.Shelf_Success; } public void SetShelfTypeDefault() { if (m_Data == null) return; m_Data.ShelfTypeList[m_Index] = EventPotionShelfType.Shelf_Default; } public EventPotionGridState GetGridState() { if (m_Data == null) return EventPotionGridState.GridState_Invalid; return m_Data.GetGridState(m_Index); } public void SetGridState(EventPotionGridState state) { if (m_Data == null) return; m_Data.SetGridState(m_Index, state); } public int GetFromDisplayAreaIndex() { if (m_Data == null) return -1; return m_Data.GetFromDisplayAreaIndex(m_Index); } public void SetFromDisplayAreaIndex(int value) { if (m_Data == null) return; m_Data.SetFromDisplayAreaIndex(m_Index, value); } public int ClearFromPotionGridUI() { fromPotionGridUI = null; SetFromDisplayAreaIndex(-1); return 0; } #endregion #region UI public void Init(int gridIndex, UnityAction btnCallback, PotionItem pItem, EventPotionDataManager pDataManager) { m_Index = gridIndex; m_Callback = btnCallback; m_PotionItem = pItem; m_DataManager = pDataManager; m_RectTransform = transform.GetComponent(); m_Animation = transform.GetComponent(); m_btn_gild = transform.Find("btn_gild").GetComponent