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; private BaseButton _button; private ChapterVo _chapterVo; public event Action Clicked; private void Awake() { _button = GetComponent(); _button.onClick.AddListener(HandleClick); if (canvasGroup == null) { canvasGroup = GetComponent(); } } 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.text = chapterVo.hasSaveFile ? "CHECK OK" : "PENDING"; } if (selectionFrame != null) { selectionFrame.gameObject.SetActive(selected); } if (canvasGroup != null) { canvasGroup.alpha = preview ? 0.45f : 1f; } } } }