UI/ToolInfo/ToolInfoPanel.razor

A UI Razor component that displays the currently equipped tool's information, including name, description and action hints for primary, secondary and reload. It queries the local player inventory for the active weapon and finds an IToolInfo provider, updates visibility each frame, and computes a hash for change detection.

Reflection
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox

@if ( Player.IsValid() && Player.WantsHideHud )
    return;

@if ( !HasAnyAction )
    return;

<root>
 <div class="panel">

  <div class="name">@Info?.Name</div>

  @if ( !string.IsNullOrEmpty( Info?.Description ) )
  {
   <div class="description">@Info.Description</div>
  }

  <div class="divider"></div>

        <div class="actions">
            @if (!string.IsNullOrEmpty(Info?.PrimaryAction))
            {
                <div class="action">
                    <InputHint Action="attack1" class="key" />
                    <span class="text">@Info.PrimaryAction</span>
                </div>
            }
            @if (!string.IsNullOrEmpty(Info?.SecondaryAction))
            {
                <div class="action">
                    <InputHint Action="attack2" class="key" />
                    <span class="text">@Info.SecondaryAction</span>
                </div>
            }
            @if (!string.IsNullOrEmpty(Info?.ReloadAction))
            {
                <div class="action">
                    <InputHint Action="reload" class="key" />
                    <span class="text">@Info.ReloadAction</span>
                </div>
            }
        </div>
 </div>
</root>

@code
{
	IToolInfo CurrentToolInfo
	{
		get
		{
			var inv = Player?.GetComponent<PlayerInventory>();
			
			if ( !inv.IsValid() || !inv.ActiveWeapon.IsValid() )
				return null;
			
			if ( inv.ActiveWeapon.GetComponentInChildren<IToolInfo>() is { IsValid: true } toolInfo )
				return toolInfo;

			return inv?.ActiveWeapon as IToolInfo;
		}
	}

	Player Player => Player.FindLocalPlayer();

	IToolInfo Info => CurrentToolInfo;

	bool HasAnyAction => !string.IsNullOrEmpty( Info?.PrimaryAction )
	                     || !string.IsNullOrEmpty( Info?.SecondaryAction )
	                     || !string.IsNullOrEmpty( Info?.ReloadAction );

	protected override void OnUpdate()
	{
		SetClass( "visible", CurrentToolInfo is not null );
	}

	protected override int BuildHash() => System.HashCode.Combine( Info?.Name, Info?.Description, Info?.PrimaryAction, Info?.SecondaryAction, Info?.ReloadAction, Player?.WantsHideHud );
}