The session HUD Razor panel. Draws Lua-provided HUD text lines and timed notifications from LuaHudModel, and shows a loading screen with stage, percent bar, recent completed steps, elapsed time and a rotating tip while LoadingProgress is active.
@using System
@using System.Linq
@using Sandbox
@using Sandbox.UI
@using RoleplayFramework.Core
@using RoleplayFramework.Net
@using RoleplayFramework.Players
@using RoleplayFramework.Scripting
@inherits PanelComponent
@namespace RoleplayFramework.UI
<root class="@(LoadingProgress.Active ? "is-loading" : "")">
@* No framework info box or pause menu: the HUD and the Escape menu belong to the gamemode (Lua; base has GM:Pause*). *@
@if ( LuaHudModel.Lines.Count > 0 )
{
<div class="lua-lines">
@foreach ( var line in LuaHudModel.Lines )
{
<label class="lua-line">@line.Text</label>
}
</div>
}
<div class="notifications">
@foreach ( var n in LuaHudModel.ActiveNotifications( RealTime.Now ) )
{
<label class="notification">@n.Text</label>
}
</div>
@if ( LoadingProgress.Active )
{
var pct = (int)MathF.Round( LoadingProgress.Fraction * 100 );
<div class="loading">
<div class="loading-glow"></div>
<div class="loading-info">
<label class="loading-kicker">@(Networking.IsActive && !Networking.IsHost ? "JOINING" : "STARTING")</label>
<label class="loading-title">@LoadingProgress.Title</label>
@if ( !string.IsNullOrEmpty( LoadingProgress.Subtitle ) )
{
<label class="loading-sub">@LoadingProgress.Subtitle</label>
}
</div>
<div class="loading-tip">
<label class="loading-tip-head">TIP</label>
<label class="loading-tip-text">@Tip</label>
</div>
<div class="loading-card">
@foreach ( var done in LoadingProgress.Done.Skip( Math.Max( 0, LoadingProgress.Done.Count - 4 ) ) )
{
<div class="loading-done">
<label class="loading-check">✓</label>
<label>@done</label>
</div>
}
<div class="loading-stage-row">
<label class="loading-stage">@LoadingProgress.Stage</label>
<label class="loading-pct">@(pct)%</label>
</div>
<label class="loading-detail">@LoadingProgress.Detail</label>
<div class="loading-bar">
<div class="loading-fill" style="width: @(pct)%"></div>
</div>
<label class="loading-time">@($"{(int)LoadingProgress.Since}s")</label>
</div>
</div>
}
</root>
@code
{
// Changes when a notification expires, so the HUD rebuilds and drops it.
int NotificationCount => LuaHudModel.ActiveNotifications( RealTime.Now ).Count();
static readonly string[] Tips =
{
"Hold Q for the spawn menu: props, weapons, entities and tools.",
"Z undoes the last prop or tool action.",
"Physics gun: hold left mouse, the wheel pulls things closer, E + mouse rotates, right click freezes.",
"Press H for help and every key you can use.",
"Content from sbox.game is downloaded once and then cached.",
"Escape opens the pause menu.",
};
string Tip => Tips[(int)(RealTime.Now / 6) % Tips.Length];
protected override void OnUpdate() => LoadingProgress.Tick();
// Loading: rebuild on every change, plus each second for the timer and tips.
protected override int BuildHash() => HashCode.Combine( LuaHudModel.Version, NotificationCount, LoadingProgress.Version,
LoadingProgress.Active ? (int)RealTime.Now : 0 );
}