using SLSUtilities.UI; using TMPro; using UnityEngine; using UnityEngine.UI; namespace Cielonos.UI { /// /// 交互选项列表中单个条目的 UI 组件。 /// 由 InteractionUIPage 生成并驱动。 /// 支持三种视觉状态:普通、高亮(选中)、不可用(灰色)。 /// public class InteractionChoiceItem : UIElementBase { [SerializeField] private TMP_Text labelText; [Tooltip("普通状态下的背景(可选)。")] [SerializeField] private Image backgroundImage; [Tooltip("高亮指示器,例如左侧箭头图标(当选中时显示)。")] [SerializeField] private GameObject highlightIndicator; [Header("颜色配置")] [SerializeField] private Color normalColor = Color.white; [SerializeField] private Color highlightedColor = new Color(0.4f, 1f, 1f); // 青色 [SerializeField] private Color disabledColor = new Color(0.45f, 0.45f, 0.45f); // 灰色 private bool _isInteractable = true; // ==================================================================== // 对外接口 // ==================================================================== /// /// 初始化条目内容。由 InteractionUIPage 在 Show() 时调用。 /// /// 选项名称。 /// false 时以灰色显示且不可高亮。 public void Setup(string choiceName, bool isInteractable) { _isInteractable = isInteractable; if (labelText != null) { labelText.text = choiceName; labelText.color = isInteractable ? normalColor : disabledColor; } if (highlightIndicator != null) { highlightIndicator.SetActive(false); } } /// /// 设置高亮状态。由 InteractionUIPage.UpdateHighlight() 调用。 /// 不可交互的选项不会显示高亮。 /// public void SetHighlighted(bool highlighted) { bool showHighlight = highlighted && _isInteractable; if (highlightIndicator != null) { highlightIndicator.SetActive(showHighlight); } if (labelText != null) { if (!_isInteractable) { labelText.color = disabledColor; } else { labelText.color = showHighlight ? highlightedColor : normalColor; } } } } }