492 lines
17 KiB
C#
492 lines
17 KiB
C#
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<GameObject> m_PourWaterEffectList = new List<GameObject>();
|
|
[SerializeField] private List<GameObject> m_JudgmentFailedEffectList = new List<GameObject>();
|
|
|
|
[SerializeField] private List<GameObject> m_AudioFlyList = new List<GameObject>();
|
|
|
|
[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<PotionGridUI> 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<PotionGridUI> btnCallback, PotionItem pItem, EventPotionDataManager pDataManager)
|
|
{
|
|
m_Index = gridIndex;
|
|
m_Callback = btnCallback;
|
|
m_PotionItem = pItem;
|
|
m_DataManager = pDataManager;
|
|
|
|
m_RectTransform = transform.GetComponent<RectTransform>();
|
|
|
|
m_Animation = transform.GetComponent<Animation>();
|
|
|
|
m_btn_gild = transform.Find("btn_gild").GetComponent<Button>();
|
|
m_btn_gild.onClick.RemoveAllListeners();
|
|
m_btn_gild.onClick.AddListener(OnBtnClickListener);
|
|
|
|
m_bg_nml = transform.Find("btn_gild/bg_nml").GetComponent<Image>();
|
|
m_bg_light = transform.Find("btn_gild/bg_light").GetComponent<Image>();
|
|
m_paint = transform.Find("btn_gild/paint").GetComponent<Image>();
|
|
m_icon = transform.Find("btn_gild/icon").gameObject;
|
|
m_spine_icon = transform.Find("btn_gild/icon/spine").GetComponent<SkeletonGraphic>();
|
|
|
|
CloseAudioFly();
|
|
}
|
|
public void SetRootPosition(Vector3 position)
|
|
{
|
|
transform.GetComponent<RectTransform>().localPosition = position;
|
|
}
|
|
public void ShowIcon()
|
|
{
|
|
m_icon.gameObject.SetActive(true);
|
|
}
|
|
public bool IsIconActive()
|
|
{
|
|
return m_icon.activeSelf;
|
|
}
|
|
public bool IsBtnGildActive()
|
|
{
|
|
return m_btn_gild.gameObject.activeSelf;
|
|
}
|
|
public bool IsActive()
|
|
{
|
|
return this.gameObject.activeSelf;
|
|
}
|
|
public void HideUpperUI()
|
|
{
|
|
m_icon.gameObject.SetActive(false);
|
|
m_paint.gameObject.SetActive(false);
|
|
}
|
|
public void HideNetherUI()
|
|
{
|
|
m_bg_nml.gameObject.SetActive(false);
|
|
m_bg_light.gameObject.SetActive(false);
|
|
}
|
|
public void ShowPaint()
|
|
{
|
|
m_icon.gameObject.SetActive(false);
|
|
m_paint.gameObject.SetActive(true);
|
|
}
|
|
public void SetPourWaterLeft()
|
|
{
|
|
GameObject gameObject = GetPourWaterEffectGameObject();
|
|
RectTransform rectTransform = gameObject.transform.GetComponent<RectTransform>();
|
|
if (rectTransform != null)
|
|
{
|
|
Vector3 localScale = rectTransform.localScale;
|
|
localScale.x = 1;
|
|
rectTransform.localScale = localScale;
|
|
}
|
|
}
|
|
public void SetPourWaterRight()
|
|
{
|
|
GameObject gameObject = GetPourWaterEffectGameObject();
|
|
RectTransform rectTransform = gameObject.transform.GetComponent<RectTransform>();
|
|
if (rectTransform != null)
|
|
{
|
|
Vector3 localScale = rectTransform.localScale;
|
|
localScale.x = -1;
|
|
rectTransform.localScale = localScale;
|
|
}
|
|
}
|
|
private GameObject GetPourWaterEffectGameObject()
|
|
{
|
|
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 count = m_PourWaterEffectList.Count;
|
|
if (res.TypeIndex >= 0 && res.TypeIndex < count)
|
|
{
|
|
return m_PourWaterEffectList[res.TypeIndex];
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
#endregion
|
|
|
|
#region 动画相关
|
|
public void PlayAnimation(string anim)
|
|
{
|
|
if (m_Animation == null || string.IsNullOrEmpty(anim) == true) return;
|
|
m_Animation.Play(anim);
|
|
}
|
|
#endregion
|
|
|
|
#region 展示区处理
|
|
public IEnumerator HandleShowStep(float delayTime, float waitforSpineTime, string spineAnim, float spineDurationTime, EventPotionGridState gridState)
|
|
{
|
|
yield return new WaitForSeconds(delayTime);
|
|
|
|
if (gridState == EventPotionGridState.GridState_Empty)
|
|
{
|
|
this.gameObject.SetActive(true);
|
|
PlayAnimation(EventPotionConfig.anim_gild_show);
|
|
PlaySpinAnimation(0, EventPotionConfig.spine_potion_idle, true);
|
|
|
|
yield return new WaitForSeconds(waitforSpineTime);
|
|
|
|
PlaySpinAnimation(0, spineAnim, true);
|
|
|
|
yield return new WaitForSeconds(spineDurationTime);
|
|
|
|
PlaySpinAnimation(0, EventPotionConfig.spine_potion_idle, true);
|
|
}
|
|
else
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
//public IEnumerator HandleShowStep2(float delayTime, EventPotionGridState gridState)
|
|
//{
|
|
// yield return new WaitForSeconds(delayTime);
|
|
// //PlaySpinAnimation(0, "potion_idle", true);
|
|
// PlaySpinAnimation(0, "potion_idle", true);
|
|
//}
|
|
#endregion
|
|
|
|
#region 引导相关
|
|
public void FirstWrongGuide()
|
|
{
|
|
Canvas canvas = gameObject.AddComponent<Canvas>();
|
|
canvas.overrideSorting = true;
|
|
canvas.sortingOrder = 10;
|
|
canvas.additionalShaderChannels = AdditionalCanvasShaderChannels.TexCoord1;
|
|
|
|
m_btn_gild.enabled = false;
|
|
}
|
|
public void ResumeFromGuide()
|
|
{
|
|
Canvas canvas = gameObject.GetComponent<Canvas>();
|
|
if (canvas != null)
|
|
{
|
|
Destroy(canvas);
|
|
}
|
|
m_btn_gild.enabled = true;
|
|
}
|
|
#endregion
|
|
|
|
#region 操作相关
|
|
private bool m_IsLocking = false;
|
|
public void LockOperation()
|
|
{
|
|
m_IsLocking = true;
|
|
}
|
|
public void UnlockOperation()
|
|
{
|
|
m_IsLocking = false;
|
|
}
|
|
public void SetTemporaryData(PotionGridUI src)
|
|
{
|
|
Clear();
|
|
IsIdle = false;
|
|
Copy(src, true);
|
|
//fromPotionGridUI = src;
|
|
SetFromGridUI(src);
|
|
LockOperation();
|
|
gameObject.SetActive(true);
|
|
//PlayAnimation(anim);
|
|
}
|
|
public void ChangeToSuccess(PotionGridUI item)
|
|
{
|
|
if (m_DataManager == null) return;
|
|
item.PlayAnimation("gild_success");
|
|
//int num = data.ItemTypeList.Count;
|
|
//EventPotionBlock potionBlock = m_DataManager.GetEventPotionBlock(num);
|
|
//if (data.ShelfTypeList[index] == EventPotionShelfType.Shelf_Success)
|
|
// bg_nml.sprite = m_DataManager.SpriteAtlas.GetSprite(potionBlock.ResourceLightList[index]);
|
|
}
|
|
#endregion
|
|
|
|
public void OnBtnClickListener()
|
|
{
|
|
if (m_Data == null || m_Data.isOver) return;
|
|
if (m_IsLocking == true) return;
|
|
if (m_Callback != null) m_Callback(this);
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
fromPotionGridUI = null;
|
|
IsIdle = true;
|
|
m_IsLocking = false;
|
|
CloseAudioFly();
|
|
}
|
|
}
|
|
}
|