A Razor UI panel component that displays various Game API properties for debugging and reflects the start menu paused state. It reads Game static properties into the UI and polls a StartMenu component to set an isPaused flag.
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox
<root>
<div class="body @(isPaused?"fadeNow":"")">
<p>`Game` API</p>
<p>AppId = @Game.AppId</p>
<p>InGame = @Game.InGame</p>
<p>IsEditor = @Game.IsEditor</p>
<p>Ident = @Game.Ident</p>
<p>IsMainMenuVisible = @Game.IsMainMenuVisible</p>
<p>IsRecordingVideo = @Game.IsRecordingVideo</p>
<p>IsClosing (Get-Set) = @Game.IsClosing</p>
<p>IsRunningInVR = @Game.IsRunningInVR</p>
<p>IsRunningOnHandheld (Get-InternalSet) = @Game.IsRunningOnHandheld</p>
<p>Random = @Game.Random (a class, use it such as `new System.Random.*()`)</p>
<p>SteamId = ***** (Sorry, that'd reveal yours!)</p>
<p>CheatsEnabled (Get-Set) = @Game.CheatsEnabled (cvar `sv_cheats`)</p>
<p>IsPlaying (Get-InternalSet) = @Game.IsPlaying</p>
<p>IsPaused = @Game.IsPaused</p>
<!--<p>Overlay.IsOpen = @IsOpen</p>-->
<!--<p>Overlay.IsPauseMenuOpen = @IsPauseMenuOpen</p>-->
<p>Usage: `Game.*`, where `*` is one of the above variables.</p>
<p> see: </p>
<p>https://github.com/Facepunch/sbox-public/blob/master/engine/Sandbox.Engine/Game/Game/Game.cs</p>
<p> & also there's extra methods beside this file. </p>
</div>
</root>
@code
{
[Property, TextArea] public string MyStringValue { get; set; } = "Hello World!";
[Property] protected StartMenu? theMenu {get;set;}
public bool isPaused {get; internal set;}
protected override void OnStart()
{
if(!theMenu.IsValid())
{
theMenu = Scene.Directory.FindByName( "ScreenMenu" ).First().GetComponent<StartMenu>();
}
if(theMenu.IsValid())
{
//TODO: subscribe to pause signal
}
}
protected override void OnUpdate()
{
//TODO: use ala-Godot signal system instead to subscribe and listen paused event
if(theMenu.IsValid())
{
// IDEA: make this more elegant! only change when that change! idk how!
if(theMenu.isPaused)
{
if(!isPaused) isPaused = true;
} else
{
if(isPaused) isPaused = false;
}
}
}
/// <summary>
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
/// </summary>
protected override int BuildHash() => System.HashCode.Combine(
Game.AppId,
Game.InGame,
Game.IsEditor,
Game.Ident,
Game.IsMainMenuVisible,
Game.IsRecordingVideo,
Game.IsClosing,
""
);
// https://github.com/Facepunch/sbox-public/blob/master/engine/Sandbox.Engine/Game/Game/Game.Overlay.cs
}