using System; using TMPro; using UnityEngine; using UnityEngine.UI; using Ashwild.Player; namespace Ashwild.Settings { /// /// One rebindable-key row: an action label, the current key (shown as a glyph when an icon is /// available, otherwise as text), a Rebind button and a Reset button. Pure UI — it holds the /// config entry's action name + binding index and raises callbacks; it knows nothing about the /// Input System. Mirrors SlotUI/RecipeButtonUI: the panel calls Initialize once, then RefreshDisplay. /// public class KeybindRowUI : MonoBehaviour { #region Serialized Fields [Header("References")] [SerializeField] private TMP_Text labelText; [SerializeField] private TMP_Text keyText; [SerializeField] private Image keyIcon; [SerializeField] private Button rebindButton; [SerializeField] private Button resetButton; #endregion #region State private string actionName; private int bindingIndex; private Action onRebind; private Action onReset; public string ActionName => actionName; public int BindingIndex => bindingIndex; #endregion #region Public API /// /// Binds this row to its config entry and the panel callbacks. Call once after Instantiate. /// public void Initialize(RebindableEntry entry, Action onRebind, Action onReset) { actionName = entry.ActionName; bindingIndex = entry.BindingIndex; this.onRebind = onRebind; this.onReset = onReset; if (labelText != null) labelText.text = entry.DisplayLabel; if (rebindButton != null) { rebindButton.onClick.RemoveAllListeners(); rebindButton.onClick.AddListener(() => this.onRebind?.Invoke(this)); } if (resetButton != null) { resetButton.onClick.RemoveAllListeners(); resetButton.onClick.AddListener(() => this.onReset?.Invoke(this)); } } /// /// Shows the current key as a glyph when an icon is supplied, otherwise as text. /// public void RefreshDisplay(string keyDisplay, Sprite icon) { bool hasIcon = icon != null; if (keyIcon != null) { keyIcon.enabled = hasIcon; if (hasIcon) keyIcon.sprite = icon; } if (keyText != null) { keyText.gameObject.SetActive(!hasIcon); keyText.text = keyDisplay; } } #endregion } }