70 lines
1.6 KiB
C#
70 lines
1.6 KiB
C#
using GeometryTD.CustomEvent;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.UI
|
|
{
|
|
public class RepoItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text _titleText;
|
|
[SerializeField] private Image _highlightImage;
|
|
|
|
private static readonly Color NormalColor = new Color32(40, 40, 40, 180);
|
|
private static readonly Color SelectedColor = new Color32(255, 216, 102, 255);
|
|
|
|
private RepoItemContext _context;
|
|
|
|
public void OnInit(RepoItemContext context)
|
|
{
|
|
if (context == null)
|
|
{
|
|
OnReset();
|
|
return;
|
|
}
|
|
|
|
_context = context;
|
|
|
|
if (_titleText != null)
|
|
{
|
|
_titleText.text = context.Title ?? string.Empty;
|
|
}
|
|
|
|
SetSelected(false);
|
|
}
|
|
|
|
public void OnReset()
|
|
{
|
|
_context = null;
|
|
|
|
if (_titleText != null)
|
|
{
|
|
_titleText.text = string.Empty;
|
|
}
|
|
|
|
SetSelected(false);
|
|
}
|
|
|
|
public void SetSelected(bool isSelected)
|
|
{
|
|
if (_highlightImage == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_highlightImage.color = isSelected ? SelectedColor : NormalColor;
|
|
}
|
|
|
|
public void OnClick()
|
|
{
|
|
if (_context == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameEntry.Event.Fire(this, RepoItemSelectedEventArgs.Create(_context.InstanceId));
|
|
}
|
|
}
|
|
}
|