29e90a5008
Teaches the deep, interlocking loop — especially the inverted win condition (you win by CLEARING EXPEDITIONS, not by surviving base sieges; DR-042/DR-043). - OnboardingSystem: client-only observe-only PresentationSystemGroup overlay (own UIDocument @ sortingOrder 60), soft-gated 10-beat coach-mark sequence with a world-space ▶ pointer; never mutates sim / never destroys a ghost. - OnboardingStepMath: pure, unit-tested step machine (snapshot + IsSatisfied + scheme-aware prompts + pointer kinds + persisted-mask helpers). - HowToPlayPanel: tabbed reference card (Controls / The Loop / Build / Threats / Win-Lose), reachable from the main menu and the pause overlay. - Per-client client-local state in GameSettings (TutorialHints + OnboardingMask bitmask, additive) — a Join client keeps its own; a host save-wipe never re-teaches. Settings toggle + menu "Replay Tutorial". - Dev "Force Each Launch" toggle (GameSettings.ForceOnboardingEachLaunch): SettingsService.Boot wipes the mask + forces hints on in-memory every launch so the tutorial always replays fresh. - HudSystem suppresses its own location hint while onboarding is active (single prompt voice), via OnboardingState + [UpdateAfter(OnboardingSystem)]. Validated green: 20/20 EditMode; Play smoke confirmed overlay render, clean U+25B6 pointer glyph, no system sort-cycle, and the force-wipe end-to-end. Docs: DR-043 + session log; reusable lesson archived in the build-gotchas note. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
102 lines
3.6 KiB
C#
102 lines
3.6 KiB
C#
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;
|
|
VisualElement _howToPanel;
|
|
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("How to Play", ShowHowToPlay));
|
|
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 && _howToPanel != null) { _howToPanel.RemoveFromHierarchy(); _howToPanel = 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);
|
|
}
|
|
|
|
void ShowHowToPlay()
|
|
{
|
|
_pausePanel.style.display = DisplayStyle.None;
|
|
_howToPanel = HowToPlayPanel.Build(() =>
|
|
{
|
|
if (_howToPanel != null) { _howToPanel.RemoveFromHierarchy(); _howToPanel = null; }
|
|
_pausePanel.style.display = DisplayStyle.Flex;
|
|
});
|
|
_root.Add(_howToPanel);
|
|
}
|
|
|
|
static void Quit()
|
|
{
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
}
|
|
}
|
|
}
|