UI/LoadingScreenHud.razor

A Razor UI component for the loading screen HUD. Renders a background image, title, shaded overlay and a progress bar using MapLoading state and places a host ScreenPanel in the scene via EnsureHost().

File Access
@using Sandbox;
@using Sandbox.UI;
@using NZombies;
@inherits PanelComponent

@*
    THE LOADING SCREEN (`MapLoading`) — the map's lobby image, its name, and a bar filling, between everyone ready and the
    spawn-in. On a screen panel of its own at ZIndex 105: over the lobby (100), under the screen fade (110), so the fade takes it to
    black and back. Hosted from `LobbyMenu.OnUpdate`, as the fade is.

    ⚠️ IN THE MAP'S LOOK where it has one (`HudTheme`): basalt's is Cinzel, bone and ember, with a white light strip for the bar.
*@

<root class="loading @HudTheme.Class @(MapLoading.Active ? "on" : "")">
    @if ( MapLoading.Active )
    {
        <div class="bg" style="background-image: url( @MapLoading.Background );"></div>
        <div class="shade"></div>
        <div class="band"></div>

        <div class="title">@MapLoading.Title</div>

        <div class="foot">
            <div class="label">LOADING</div>
            <div class="bar"><div class="fill" style="width: @(Css( MapLoading.Progress * 100f ))%"></div></div>
        </div>
    }
</root>

@code
{
    static GameObject _host;

    /// <summary>Its screen panel, made once — above the lobby, under the fade.</summary>
    public static void EnsureHost()
    {
        if ( _host.IsValid() ) return;

        var scene = Game.ActiveScene;
        if ( !scene.IsValid() ) return;

        _host = scene.CreateObject();
        _host.Name = "Loading Screen";
        _host.Flags |= GameObjectFlags.NotSaved;

        var screen = _host.Components.Create<ScreenPanel>();
        screen.ZIndex = 105;

        _host.Components.Create<LoadingScreenHud>();
    }

    /// <summary>⚠️ A POINT FOR THE DECIMAL, whatever the machine's language — this goes into a style.</summary>
    static string Css( float v ) => v.ToString( "0.#", System.Globalization.CultureInfo.InvariantCulture );

    /// <summary>⚠️ THE BAR IN 200 STEPS, so it rebuilds as it moves and not every frame.</summary>
    protected override int BuildHash() => System.HashCode.Combine( MapLoading.Active, (int)(MapLoading.Progress * 200f),
        MapLoading.Title, MapLoading.Background, HudTheme.Class );
}