using UnityEngine; using UnityEngine.UI; using TMPro; using Ashwild.Player; using Ashwild.Settings; namespace Ashwild.UI { /// /// The in-game pause menu, now a regular panel driven by . Wires its /// buttons to the game manager (resume / invite / quit) and to the shared settings panel. Every /// button is optional — leave a reference empty to omit it. /// public class PausePanel : UIPanel { #region Panel Kind /// /// The pause menu freezes the game while open. /// public override PanelKind Kind => PanelKind.Pause; #endregion #region Serialized Fields [Header("Buttons")] [SerializeField] private Button resumeButton; [SerializeField] private Button settingsButton; [SerializeField] private Button inviteButton; [SerializeField] private Button quitButton; [Header("Session")] [Tooltip("Displays the shareable room code (host SteamID-derived) of the current session.")] [SerializeField] private TMP_Text roomCodeLabel; [Tooltip("Shown in place of the code when no online session is active.")] [SerializeField] private string offlinePlaceholder = "—"; #endregion #region State /// /// The active game manager (the shared Instance is always a GameUIManager in gameplay). /// private GameUIManager Game => UIManager.Instance as GameUIManager; #endregion #region Unity Lifecycle /// /// Wires the buttons; runs once. /// protected override void Awake() { base.Awake(); if (resumeButton != null) resumeButton.onClick.AddListener(() => Game?.Resume()); if (inviteButton != null) inviteButton.onClick.AddListener(() => Game?.InviteFriend()); if (quitButton != null) quitButton.onClick.AddListener(() => Game?.QuitToMenu()); if (settingsButton != null) settingsButton.onClick.AddListener(() => UIManager.Instance.OpenPanel()); } #endregion #region Panel Visibility /// /// Refreshes the room code each time the pause menu opens, so it always reflects the /// session that is live at that moment rather than a value cached at spawn. /// public override void Show() { base.Show(); RefreshRoomCode(); } #endregion #region Internal Helpers /// /// Writes the current shareable session code into the label, falling back to the offline /// placeholder when no online session is active. /// private void RefreshRoomCode() { if (roomCodeLabel == null) return; string code = PlayerEvents.SessionCode; roomCodeLabel.text = string.IsNullOrEmpty(code) ? offlinePlaceholder : code; } #endregion } }