UI/JumperNameTag.razor
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@if (Network.OwnerConnection is Connection owner && owner != Connection.Local)
{
<root>
<div class="card">
<div class="avatar" style="background-image: url( avatar:@owner.SteamId )"></div>
<div class="name">@owner.DisplayName</div>
@if (IsVoicePlaying)
{
<div class="voice"></div>
}
</div>
</root>
}
@code
{
Sandbox.Voice voiceComponent;
protected override void OnEnabled()
{
base.OnEnabled();
voiceComponent = GameObject.Root.Components.GetInDescendantsOrSelf<Voice>();
}
public bool IsVoicePlaying
{
get
{
if (voiceComponent is null) return false;
return voiceComponent.LastPlayed < 0.5f;
}
}
/// <summary>
/// Rebuild if the owner connection changes
/// </summary>
protected override int BuildHash() => System.HashCode.Combine(Network.OwnerConnection, IsVoicePlaying);
}