88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream.UI.Terminal
|
|
{
|
|
[RequireComponent(typeof(BaseButton))]
|
|
public class TerminalChapterItemView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image coverImage;
|
|
[SerializeField] private TMP_Text titleText;
|
|
[SerializeField] private TMP_Text chapterText;
|
|
[SerializeField] private TMP_Text statusText;
|
|
[SerializeField] private Image selectionFrame;
|
|
[SerializeField] private CanvasGroup canvasGroup;
|
|
[SerializeField] private float selectedScale = 1.05f;
|
|
[SerializeField] private float previewScale = 1f;
|
|
|
|
private BaseButton _button;
|
|
private ChapterVo _chapterVo;
|
|
|
|
public event Action<ChapterVo> Clicked;
|
|
|
|
private void Awake()
|
|
{
|
|
_button = GetComponent<BaseButton>();
|
|
_button.onClick.AddListener(HandleClick);
|
|
if (canvasGroup == null)
|
|
{
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_button != null)
|
|
{
|
|
_button.onClick.RemoveListener(HandleClick);
|
|
}
|
|
}
|
|
|
|
private void HandleClick()
|
|
{
|
|
Clicked?.Invoke(_chapterVo);
|
|
}
|
|
|
|
public void Init(ChapterVo chapterVo, bool selected, bool preview)
|
|
{
|
|
_chapterVo = chapterVo;
|
|
|
|
if (coverImage != null)
|
|
{
|
|
coverImage.sprite = chapterVo.pic;
|
|
coverImage.enabled = chapterVo.pic != null;
|
|
}
|
|
|
|
if (titleText != null)
|
|
{
|
|
titleText.text = chapterVo.title;
|
|
}
|
|
|
|
if (chapterText != null)
|
|
{
|
|
chapterText.text = chapterVo.chapter;
|
|
}
|
|
|
|
if (statusText != null)
|
|
{
|
|
statusText.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (selectionFrame != null)
|
|
{
|
|
selectionFrame.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 1f;
|
|
}
|
|
|
|
var scaleMultiplier = selected ? selectedScale : previewScale;
|
|
transform.localScale = Vector3.one * scaleMultiplier;
|
|
}
|
|
}
|
|
}
|