ui/LeaderboardRunInfoPanel.razor

A UI Razor component for s&box that displays detailed info about a leaderboard run. It reads a Manager.Instance.RunEntryToShow, extracts fields (score, date, run time, player level, kills, heals, teammates, perks) and renders player icons, perk icons and teammate entries, with a HidePerks method to clear the shown entry.

Networking
@namespace Sandbox
@using Sandbox;
@using Sandbox.UI;
@using System;
@using System.Text.Json;
@inherits Panel
@attribute [StyleSheet("LeaderboardRunInfoPanel.razor.scss")]

<root>
	@{
		var entry = Manager.Instance.RunEntryToShow;
	}

	@if(entry == null)
		return;

	@{
		var isVictory = entry.score > 99999f;

		int playerLevel = Utils.GetIntFromDictionary( entry.data, "player_level", -1 );
		int enemiesKilled = Utils.GetIntFromDictionary( entry.data, "num_kills", -1 );
		int hpHealed = Utils.GetIntFromDictionary( entry.data, "hp_healed", -1 );

		int numPlayers = Utils.GetIntFromDictionary( entry.data, "num_players", 1 );

		LeaderboardPlayerIcon.LeaderboardIconType iconType = isVictory ? LeaderboardPlayerIcon.LeaderboardIconType.Victory : LeaderboardPlayerIcon.LeaderboardIconType.Defeat;
	}

	<div class="header">
		<i>directions_run</i>
		<label>Run Info</label>
		<div class="sub-info">
			<i>calendar_today</i>
			<label class="date">@entry.dateString</label>
			<label>-</label>
			<i>timer</i>
			<label>@Utils.FormatTime( Utils.GetFloatFromDictionary( entry.data, "run_time" ) )</label>
		</div>
	</div>

	<div class="player-entry">
		<div class="player-info">
			<LeaderboardPlayerIcon PlayerInfo=@(new PlayerInfo( entry.displayName, entry.steamId, playerLevel )) Icon=@iconType />
			<div class="info">
				<label class="display-name">@entry.displayName</label>
				@if ( enemiesKilled >= 0 )
				{
					<div class="info-row numKills">
						<div><i>location_searching</i>Enemies Killed</div>
						<label>@enemiesKilled</label>
					</div>
				}

				@if ( hpHealed >= 0 )
				{
					<div class="info-row hpHealed">
						<div><i>medical_services</i>HP Healed</div>
						<label>@hpHealed</label>
					</div>
				}

				@if ( numPlayers > 1 )
				{
					int numDeaths = Utils.GetIntFromDictionary( entry.data, "num_deaths", 0 );
					<div class="info-row numDeaths">
						<div><i>sentiment_very_dissatisfied</i>Deaths</div>
						<label>@numDeaths</label>
					</div>
				}
			</div>
		</div>
		@if ( entry.data.TryGetValue( "perks", out var perksObj ) )
		{
			Dictionary<int, int> perks = Utils.JsonObjectToIntDictionary( perksObj );

			<div class="itemlist">
				@foreach ( var pair in perks )
				{
					var typeIdent = pair.Key;
					var perkType = PerkManager.IdentityToType( typeIdent );

					var perkLevel = pair.Value;

					<PerkIconStatic PerkType=@perkType Level=@perkLevel />
				}
			</div>
		}
	</div>

	@if ( numPlayers > 1 )
	{
		<div class="teammates">
			<i>group</i>
			<label>Teammates</label>
		</div>

		<div class="players-container">
			@{
				long otherPlayerId0 = 0;
				long otherPlayerId1 = 0;

				if ( numPlayers > 1 )
				{
					otherPlayerId0 = Utils.GetLongFromDictionary( entry.data, "other_player_id_0", 0 );
					otherPlayerId1 = Utils.GetLongFromDictionary( entry.data, "other_player_id_1", 0 );
				}
			}

			@if ( numPlayers > 1 )
			{
				@if ( otherPlayerId0 > 0 )
				{
					string otherPlayerName0 = Utils.GetStringFromDictionary( entry.data, "other_player_name_0", "" );
					int otherPlayerLevel0 = Utils.GetIntFromDictionary( entry.data, "other_player_level_0", -1 );

					<div class="player-entry">
						<div class="player-info">
							<LeaderboardPlayerIcon PlayerInfo=@(new PlayerInfo( otherPlayerName0, otherPlayerId0, otherPlayerLevel0 )) Icon=@iconType />
							<div class="info">
								<label class="display-name">@otherPlayerName0</label>
							</div>
						</div>
					</div>
				}

				@if ( otherPlayerId1 > 0 )
				{
					string otherPlayerName1 = Utils.GetStringFromDictionary( entry.data, "other_player_name_1", "" );
					int otherPlayerLevel1 = Utils.GetIntFromDictionary( entry.data, "other_player_level_1", -1 );

					<div class="player-entry">
						<div class="player-info">
							<LeaderboardPlayerIcon PlayerInfo=@(new PlayerInfo( otherPlayerName1, otherPlayerId1, otherPlayerLevel1 )) Icon=@iconType />
							<div class="info">
								<label class="display-name">@otherPlayerName1</label>
							</div>
						</div>
					</div>
				}
			}
		</div>
	}

	<div class="hide_button" onclick=@(() => HidePerks())>close</div>
</root>

@code
{

	// protected override int BuildHash()
	// {
	// 	return HashCode.Combine(
	// 		LeaderboardName
	// 	);
	// }

	public void HidePerks()
	{
		Manager.Instance.RunEntryToShow = null;
	}
}