A Razor UI panel for the Jumper gamemode. Only renders for the connection that owns the player, shows name, playtime, jumps, best height, falls and completions, and has Restart and Unstuck buttons. Also handles opening the menu with the menu/score inputs and shows the cursor while attack is held.
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@if (Network.OwnerConnection is Connection owner && owner == Connection.Local)
{
<root>
<div class="container">
<div class="header">
<label class="title">JUMPER</label>
</div>
<div class="rows">
<div class="row">
<label class="title">NAME</label>
<label class="stat">@Name</label>
</div>
<div class="row">
<label class="title">PLAYTIME</label>
<label class="stat">@YourSessionTime</label>
</div>
<div class="row">
<label class="title">JUMPS</label>
<label class="stat">@Jumps</label>
</div>
<div class="row">
<label class="title">BEST HEIGHT</label>
<label class="stat">@MaxHeight</label>
</div>
<div class="row">
<label class="title">FALLS</label>
<label class="stat">@Falls</label>
</div>
<div class="row">
<label class="title">COMPLETIONS</label>
<label class="stat">@Completions</label>
</div>
</div>
<button onclick="@Restart">Restart</button>
<button onclick="@Unstuck">Unstuck</button>
</div>
</root>
}
@code {
private string Name => GameObject.Network.OwnerConnection.DisplayName;
private float TimePlayed => GameObject.Components.Get<JumperPlayerStuff>(FindMode.EverythingInAncestors).TimePlayed;
private int? Jumps => GameObject.Components.Get<JumperPlayerStuff>(FindMode.EverythingInAncestors)?.TotalJumps;
private int? Falls => GameObject.Components.Get<JumperPlayerStuff>(FindMode.EverythingInAncestors)?.TotalFalls;
private int? Completions => GameObject.Components.Get<JumperPlayerStuff>(FindMode.EverythingInAncestors)?.Completions;
private float? MaxHeight => GameObject.Components.Get<JumperPlayerStuff>(FindMode.EverythingInAncestors)?.MaxHeight;
private string YourSessionTime;
// private JumperPawn Pawn => (Game.LocalPawn as JumperPawn);
private void Unstuck()
{
GameObject.Components.Get<PlayerInput>(FindMode.EverythingInAncestors)?.Unstuck();
}
private void Restart()
{
var spawnpoint = Scene.Components.GetAll<JumperSpawnPoint>().FirstOrDefault();
if (spawnpoint != null)
{
//Do some more stuff but for now just movew the play to spawn
GameObject.Parent.Transform.Position = spawnpoint.Transform.Position;
//JumperGame.SetPlayerPosition(spawnpoint.Position + Vector3.Up * 10);
//Pawn.ResetStats();
}
}
protected override void OnUpdate()
{
base.OnUpdate();
// Tab is bound to the "score" action, so open on either action
SetClass("open", Input.Down("menu") || Input.Down("score"));
if (!HasClass("open"))
{
RemoveClass("cursor");
}
else
{
if (Input.Down("attack1") || Input.Down("attack2"))
{
AddClass("cursor");
}
}
YourSessionTime = TimeSpan.FromSeconds((TimePlayed * 60).Clamp(0, float.MaxValue)).ToString(@"dd\:hh\:mm\:ss");
}
protected override int BuildHash()
{
return HashCode.Combine(Jumps, Falls, MaxHeight, YourSessionTime, Completions);
}
}