Frontend menu + settings + saves foundation
Netcode frontend pattern: UITK main menu / pause / settings (MenuUi + controllers), on-demand world lifecycle (WorldLauncher/SessionRunner), GameBootstrap menu branch; Graphics/Audio settings (SettingsService/GameVolume); single-slot save foundation (SaveData/SaveService, born-correct load at director spawn, autosave on Siege->Calm + quit); RuntimePanelSettings + theme; BuildTool menu; 10 EditMode tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace ProjectM.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// In-game pause overlay (UI Toolkit), spawned by <see cref="PauseMenuSystem"/> in the client world. Esc
|
||||
/// toggles it; Resume / Settings / Quit-to-Menu / Quit-to-Desktop. Quit-to-Menu hands off to
|
||||
/// <see cref="WorldLauncher.TeardownToMenu"/> (autosave + dispose worlds + load MainMenu). Builds its own
|
||||
/// UIDocument in code (shared PanelSettings from Resources) above the HUD; the scene swap on Quit-to-Menu
|
||||
/// destroys it.
|
||||
/// </summary>
|
||||
public class PauseMenuController : MonoBehaviour
|
||||
{
|
||||
UIDocument _doc;
|
||||
VisualElement _root;
|
||||
VisualElement _pausePanel;
|
||||
VisualElement _settingsPanel;
|
||||
bool _open;
|
||||
/// <summary>True while the pause overlay is shown (BuildSendSystem suspends build-clicks while paused).</summary>
|
||||
public static bool Open;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
MenuUi.EnsureEventSystem();
|
||||
_doc = gameObject.AddComponent<UIDocument>();
|
||||
_doc.panelSettings = MenuUi.LoadPanelSettings();
|
||||
_doc.sortingOrder = 100; // above the in-game HUD
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_root = _doc.rootVisualElement;
|
||||
Build();
|
||||
SetOpen(false);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
var kb = UnityEngine.InputSystem.Keyboard.current;
|
||||
if (kb != null && kb.escapeKey.wasPressedThisFrame)
|
||||
SetOpen(!_open);
|
||||
}
|
||||
|
||||
void Build()
|
||||
{
|
||||
_pausePanel = MenuUi.FullScreenRoot(false);
|
||||
_pausePanel.style.backgroundColor = new Color(0.02f, 0.03f, 0.05f, 0.72f);
|
||||
var card = MenuUi.Card("PAUSED");
|
||||
card.Add(MenuUi.Button("Resume", () => SetOpen(false)));
|
||||
card.Add(MenuUi.Button("Settings", ShowSettings));
|
||||
card.Add(MenuUi.Button("Quit to Menu", WorldLauncher.TeardownToMenu));
|
||||
card.Add(MenuUi.Button("Quit to Desktop", Quit));
|
||||
_pausePanel.Add(card);
|
||||
_root.Add(_pausePanel);
|
||||
}
|
||||
|
||||
void SetOpen(bool open)
|
||||
{
|
||||
_open = open;
|
||||
Open = open;
|
||||
if (_pausePanel != null) _pausePanel.style.display = open ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
if (!open && _settingsPanel != null) { _settingsPanel.RemoveFromHierarchy(); _settingsPanel = null; }
|
||||
if (open) { UnityEngine.Cursor.lockState = CursorLockMode.None; UnityEngine.Cursor.visible = true; }
|
||||
}
|
||||
|
||||
void ShowSettings()
|
||||
{
|
||||
_pausePanel.style.display = DisplayStyle.None;
|
||||
_settingsPanel = SettingsScreen.Build(() =>
|
||||
{
|
||||
if (_settingsPanel != null) { _settingsPanel.RemoveFromHierarchy(); _settingsPanel = null; }
|
||||
_pausePanel.style.display = DisplayStyle.Flex;
|
||||
});
|
||||
_root.Add(_settingsPanel);
|
||||
}
|
||||
|
||||
static void Quit()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user