Skip to content
简体中文

Implement nested pause menus ​

  1. Create one PauseStackManager in the host and register a GodotPauseHandler.
  2. Set PauseWhileVisible for the pause and settings routes. Use the same manager to apply UI pause policy to the scene tree.
  3. Start the game, open Pause, and then open Settings. Close Settings and check that gameplay stays paused.
  4. Return to gameplay and check that it resumes. Stop the UI before disposing the pause service on exit.
csharp
// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0

using System;
using GFramework.Game.Abstractions.UI;

namespace DodgeTheCreeps;

/// <summary>Typed definitions shared by registration and business operations.</summary>
internal static class DodgeRoutes
{
    /// <summary>Main menu navigation page.</summary>
    internal static UiRoute<bool> Menu { get; } = new("menu", new UiRouteOptions { Layer = 10, AllowBack = false, BlocksWorldActionInput = true, BlocksWorldPointerInput = true });
    /// <summary>Gameplay HUD stays visible under menus without owning input.</summary>
    internal static UiRoute<int> Hud { get; } = new("hud", new UiRouteOptions { Kind = UiRouteKind.Window, Layer = 5, AllowBack = false, CapturedActions = UiInputActionMask.None });
    /// <summary>Gameplay pause window owns one pause request.</summary>
    internal static UiRoute<int> Pause { get; } = new("pause", Modal(20));
    /// <summary>Settings owns a separate pause request, including while opened over pause.</summary>
    internal static UiRoute<bool> Settings { get; } = new("settings", Modal(30));
    /// <summary>Unsaved settings use an explicit apply, discard or keep-editing result.</summary>
    internal static UiDialogRoute<bool, SettingsCloseChoice> SettingsUnsaved { get; } = new("settings-unsaved", Modal(40));
    /// <summary>Game-over page carries the completed score.</summary>
    internal static UiRoute<int> GameOver { get; } = new("game-over", new UiRouteOptions { Layer = 10, AllowBack = false, BlocksWorldActionInput = true });
    /// <summary>Unsaved progress confirmation returns an explicit business choice.</summary>
    internal static UiDialogRoute<Func<string>, bool> Confirm { get; } = new("confirm", Modal(40));
    /// <summary>Content selection remains accessible even when the active package plan failed.</summary>
    internal static UiRoute<bool> Content { get; } = new("content", Modal(30));
    /// <summary>Content repair requires an explicit player decision before backup and downgrade.</summary>
    internal static UiDialogRoute<Func<string>, bool> Recover { get; } = new("recover", Modal(40));
    /// <summary>Executing an installed DLL requires a separate explicit authorization decision.</summary>
    internal static UiDialogRoute<Func<string>, bool> CodePermission { get; } = new("code-permission", Modal(40));

    /// <summary>Declares input and pause behavior independently of visual ordering.</summary>
    private static UiRouteOptions Modal(int layer) => new()
    {
        Kind = UiRouteKind.Window,
        Layer = layer,
        Modal = true,
        BlocksWorldActionInput = true,
        BlocksWorldPointerInput = true,
        PauseWhileVisible = true,
        ContinueProcessingWhenPaused = true,
    };
}

See Godot pause for host setup.

Apache License 2.0