A UI Razor component that displays a player dive/attack prompt with an input glyph and cooldown text. It reads a PlayerLeap component to show either "Dive" when ready, a cooldown number, or a dash when currently leaping, and disables itself during spectator or victory result screens.
@using System; @using Sandbox; @using Sandbox.UI; @inherits PanelComponent <root> <span class="prompt"> <Image class="glyph" [email protected]("Attack1", InputGlyphSize.Medium, GlyphStyle.Light) /> <span class="text @(divePromptClass)">@DivePrompt</span> </span> </root> @code { [Property] public PlayerLeap PlayerLeap { get; set; } public string DivePrompt; private String divePromptClass = "Ready"; protected override void OnUpdate() { if (PlayerLeap == null) { return; } if (SpectatorMode.Current != null && SpectatorMode.Current.IsActive) { Enabled = false; } if (VictoryManager.Current != null && VictoryManager.Current.IsShowingResults) { Enabled = false; } if (PlayerLeap.IsLeaping) { DivePrompt = "-"; divePromptClass = "OnCooldown"; } else { DivePrompt = Math.Floor(PlayerLeap.LeapCooldownTime + 1).ToString(); if (PlayerLeap.LeapCooldownTime < 0.01) { DivePrompt = "Dive"; divePromptClass = "Ready"; } } } protected override int BuildHash() { return System.HashCode.Combine(DivePrompt); } }