ui/PerkUnlockResultPanel.razor

A UI Razor component that displays one or two perk choices for the player to unlock. It builds small info rows from a PerkAttribute, renders PerkChoice child components, handles click and input confirmation, and invokes OnClose with the selected TypeDescription.

Reflection
@namespace Sandbox
@using Sandbox;
@using Sandbox.UI;
@using System;
@using System.Linq;
@using System.Collections.Generic;
@inherits Panel
@attribute [StyleSheet("PerkUnlockResultPanel.razor.scss")]

@{
	if ( Picks == null || Picks.Count == 0 ) return;

	var isSingle = Picks.Count == 1;
	var tooltipLevel = 1;
	var isChoice = false;

	List<string> infoRowsA = null;
	List<string> infoRowsB = null;

	if ( isSingle )
	{
		infoRowsA = BuildInfoRows( Picks[0] );
	}
	else
	{
		infoRowsA = BuildInfoRows( Picks[0] );
		infoRowsB = BuildInfoRows( Picks[1] );
	}

}

<root>
	<div class="overlay_backdrop"></div>
	<div class="content_panel">
		<label class="header_label">Choose a perk to unlock!</label>
		@if ( isSingle )
		{
			<div class="single_card_container">
				<div class="card_wrapper" onclick=@(() => Confirm( Picks[0] ))>
					<PerkChoice PerkType=@Picks[0] IsChoice=@isChoice TooltipLevel=@tooltipLevel Slot=@(0) InfoRows=@infoRowsA />
				</div>
			</div>
		}
		else
		{
			<div class="dual_card_row">
				<div class="card_wrapper" onclick=@(() => Confirm( Picks[0] ))>
					<PerkChoice PerkType=@Picks[0] IsChoice=@isChoice TooltipLevel=@tooltipLevel Slot=@(0) InfoRows=@infoRowsA />
				</div>
				<div class="card_wrapper" onclick=@(() => Confirm( Picks[1] ))>
					<PerkChoice PerkType=@Picks[1] IsChoice=@isChoice TooltipLevel=@tooltipLevel Slot=@(1) InfoRows=@infoRowsB />
				</div>
			</div>
		}
	</div>
</root>

@code {
	public List<TypeDescription> Picks { get; set; }
	public Action<TypeDescription> OnClose { get; set; }

	private List<string> BuildInfoRows( TypeDescription perkType )
	{
		var attrib = perkType.GetAttribute<PerkAttribute>();
		var rows = new List<string>();
		if ( attrib.MultiplayerMode == MultiplayerMode.OnlyMultiplayer )
			rows.Add( "Multiplayer only" );
		if ( attrib.OnlyUnpausedChoosing )
			rows.Add( "Unpaused choosing only" );
		return rows.Count > 0 ? rows : null;
	}

	public override void Tick()
	{
		base.Tick();
		if ( Picks == null || Picks.Count == 0 ) return;
		if ( Input.Pressed( "Slot1" ) ) Confirm( Picks[0] );
		else if ( Picks.Count > 1 && Input.Pressed( "Slot2" ) ) Confirm( Picks[1] );
	}

	private void Confirm( TypeDescription pick )
	{
		OnClose?.Invoke( pick );
	}

	protected override int BuildHash()
		=> HashCode.Combine( Picks?.Count ?? 0, ProgressManager.StateVersion );
}