The presentation hub for the Sump game object. On start it adds and caches a ScreenPanel with the SumpHud, plus SumpAudio and SumpLighting components, and each frame it copies Sump.Prompt to ShownPrompt and clears the shared prompt so stale prompts disappear. Exposes static helpers for the running SumpFinale and its clamped HeartPulse.
using System;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Sound, lighting and the HUD for the whole Sump. The bootstrap adds this one component to the
/// Sump object; it then adds the rest next to itself: a <see cref="ScreenPanel"/> with the
/// <see cref="SumpUi.SumpHud"/> on it, <see cref="SumpAudio"/> and <see cref="SumpLighting"/>.
///
/// It reads the other modules and never writes to them, with one exception:
/// <see cref="Sump.Prompt"/> is taken down here late every frame (in OnPreRender, after every
/// module's OnUpdate), so a prompt nobody is asking for any more vanishes by itself. Modules
/// that want a prompt shown must therefore set it every frame, as they all do. What the HUD
/// draws is the copy kept in <see cref="ShownPrompt"/>.
/// </summary>
[Title( "Sump Presentation" ), Category( "Sump" ), Icon( "theaters" )]
public sealed class SumpPresentation : Component
{
public static SumpPresentation Current { get; private set; }
[Property] public bool UseHud { get; set; } = true;
[Property] public bool UseAudio { get; set; } = true;
[Property] public bool UseLighting { get; set; } = true;
/// <summary>Draw order of the Sump's HUD among the scene's screen panels.</summary>
[Property] public int HudZIndex { get; set; } = 100;
/// <summary>The prompt as it stood at the end of this frame's updates. The HUD draws this.</summary>
public string ShownPrompt { get; private set; }
public SumpUi.SumpHud Hud { get; private set; }
public SumpAudio Audio { get; private set; }
public SumpLighting Lighting { get; private set; }
protected override void OnStart()
{
if ( Scene.IsEditor ) return;
Current = this;
if ( UseHud )
{
try
{
var screen = Components.GetOrCreate<ScreenPanel>();
screen.ZIndex = HudZIndex;
Hud = Components.GetOrCreate<SumpUi.SumpHud>();
}
catch ( Exception e ) { Log.Warning( $"Sump HUD not started: {e.Message}" ); }
}
if ( UseAudio ) Audio = Components.GetOrCreate<SumpAudio>();
if ( UseLighting ) Lighting = Components.GetOrCreate<SumpLighting>();
}
protected override void OnPreRender()
{
if ( Scene.IsEditor ) return;
ShownPrompt = Sump.Prompt;
Sump.Prompt = null;
}
/// <summary>The running finale, or null.</summary>
public static SumpFinale Finale => SumpFinale.Current is { IsValid: true, Running: true } finale ? finale : null;
/// <summary>The planet's heartbeat from the finale, 0 between beats to 1 on the beat; 0 when no finale is running.</summary>
public static float HeartPulse => Finale is { } finale ? Math.Clamp( finale.HeartPulse, 0f, 1f ) : 0f;
protected override void OnDestroy()
{
if ( Current == this ) Current = null;
}
}