97 lines
2.4 KiB
C#
97 lines
2.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using System;
|
|
namespace BrewMonster.Scripts.UI
|
|
{
|
|
public class AwardItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image img;
|
|
[SerializeField] private Button btn;
|
|
[SerializeField] private string txtHint;
|
|
[SerializeField] private bool isOn;
|
|
private bool _bShowHint = false;
|
|
|
|
private Vector2Int _position;
|
|
|
|
public Vector2Int Position => _position;
|
|
|
|
public void SetPositionIndex(int row, int column)
|
|
{
|
|
_position = new Vector2Int(row, column);
|
|
this.gameObject.name = "Item_" + row + "_" + column;
|
|
}
|
|
|
|
|
|
public void SetImage(Sprite sprite)
|
|
{
|
|
if (img == null)
|
|
{
|
|
return;
|
|
}
|
|
img.enabled = sprite != null;
|
|
img.sprite = sprite;
|
|
}
|
|
|
|
public void SetText(string text)
|
|
{
|
|
// TODO: Add a Text component and set its text
|
|
|
|
}
|
|
|
|
public void SetColor(Color color)
|
|
{
|
|
if (img == null)
|
|
{
|
|
return;
|
|
}
|
|
img.color = color;
|
|
}
|
|
|
|
public void SetHint(string text)
|
|
{
|
|
txtHint = text;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset slot when this cell has no award (e.g. dialog reopened with fewer items).
|
|
/// 清空格子:再次打开奖励界面时清除上一轮的图标与点击逻辑。
|
|
/// </summary>
|
|
public void ClearCover()
|
|
{
|
|
if (img != null)
|
|
{
|
|
img.sprite = null;
|
|
img.enabled = false;
|
|
img.color = Color.white;
|
|
}
|
|
if (btn != null)
|
|
{
|
|
btn.onClick.RemoveAllListeners();
|
|
}
|
|
txtHint = string.Empty;
|
|
isOn = false;
|
|
}
|
|
|
|
public void Show(bool show)
|
|
{
|
|
gameObject.SetActive(show);
|
|
}
|
|
|
|
private void HintBehaviour()
|
|
{
|
|
}
|
|
|
|
public void SetOnClick(Action<string, bool, AwardItem> action)
|
|
{
|
|
btn.onClick.RemoveAllListeners();
|
|
btn.onClick.AddListener(() => {
|
|
action?.Invoke(txtHint, !isOn, this);
|
|
});
|
|
}
|
|
public void HideHint()
|
|
{
|
|
isOn = false;
|
|
}
|
|
}
|
|
} |