UI/MainMenuPanel.razor

Razor UI component for the main menu. It inherits NavigationHost, renders a root container with a navigator canvas and a LobbyStatusOverlay, and exposes a static Instance plus logic to set the default navigation URL based on whether a network session is active.

Networking
@using Sandbox;
@using Sandbox.UI;
@using Sandbox.UI.Navigation;

@namespace Machines.UI
@inherits NavigationHost

<root class="main-menu main-bg">
    <div class="navigator-canvas" slot="navigator-canvas"></div>
    <LobbyStatusOverlay />
</root>

@code
{
    /// <summary>
    /// Live navigator instance; lets systems check the current page via <see cref="Sandbox.UI.Navigation.NavigationHost.CurrentUrl"/>.
    /// </summary>
    public static MainMenuPanel Instance { get; private set; }

    public MainMenuPanel()
    {
        Instance = this;

        DefaultUrl = "/";
    }

    protected override void OnParametersSet()
    {
        // If already in a session (e.g. invite), open on /play; otherwise /home.
        if ( CurrentUrl == null )
            DefaultUrl = Sandbox.Networking.IsActive ? "/play" : "/";

        base.OnParametersSet();
    }

    public override void OnDeleted()
    {
        base.OnDeleted();

        if ( Instance == this )
            Instance = null;
    }
}