Files
Emberwild/Assets/GAME/Script/UI/Panels/PausePanel.cs
T
2026-06-24 14:04:12 +02:00

98 lines
3.1 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Ashwild.Player;
using Ashwild.Settings;
namespace Ashwild.UI
{
/// <summary>
/// The in-game pause menu, now a regular panel driven by <see cref="GameUIManager"/>. 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.
/// </summary>
public class PausePanel : UIPanel
{
#region Panel Kind
/// <summary>
/// The pause menu freezes the game while open.
/// </summary>
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
/// <summary>
/// The active game manager (the shared Instance is always a GameUIManager in gameplay).
/// </summary>
private GameUIManager Game => UIManager.Instance as GameUIManager;
#endregion
#region Unity Lifecycle
/// <summary>
/// Wires the buttons; runs once.
/// </summary>
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<SettingsPanel>());
}
#endregion
#region Panel Visibility
/// <summary>
/// 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.
/// </summary>
public override void Show()
{
base.Show();
RefreshRoomCode();
}
#endregion
#region Internal Helpers
/// <summary>
/// Writes the current shareable session code into the label, falling back to the offline
/// placeholder when no online session is active.
/// </summary>
private void RefreshRoomCode()
{
if (roomCodeLabel == null) return;
string code = PlayerEvents.SessionCode;
roomCodeLabel.text = string.IsNullOrEmpty(code) ? offlinePlaceholder : code;
}
#endregion
}
}