UI/ScoreboardRow.razor
@using Sandbox;
@using Sandbox.UI;
@inherits Panel
<root class="row player">
@if ( Entry is not null && Entry.Connection is not null )
{
var steamId = Entry.Connection.SteamId;
bool isMuted = SandboxVoice.IsMuted( steamId );
<img class="avatar" src="avatar:@steamId" />
<div class="name">@Entry.DisplayName</div>
<div class="stat">@Entry.Kills</div>
<div class="stat">@Entry.Deaths</div>
<div class="stat">@(Entry.Ping.CeilToInt())</div>
@if ( !Entry.IsMe )
{
<div class="mute-btn @(isMuted ? "muted" : "")" onclick="@( () => SandboxVoice.Mute( steamId ) )">
<i>@(isMuted ? "volume_off" : "volume_up")</i>
</div>
}
else
{
<div class="mute-spacer"></div>
}
}
</root>
@code
{
public PlayerData Entry { get; set; }
public override void Tick()
{
if ( Entry is null ) return;
SetClass( "me", Entry.IsMe );
if ( Entry.Connection is not null )
SetClass( "friend", new Friend( Entry.Connection.SteamId ).IsFriend );
}
protected override int BuildHash()
{
if (Entry is null) return 0;
return System.HashCode.Combine( Entry.DisplayName, Entry.Kills, Entry.Deaths, Entry.Ping );
}
protected override void OnRightClick( MousePanelEvent e )
{
if ( Entry is null || Entry.Connection is null ) return;
var steamId = Entry.Connection.SteamId;
var menu = Sandbox.MenuPanel.Open( this );
menu.AddOption( "content_copy", "Copy Steam ID", () =>
{
Clipboard.SetText( steamId.ToString() );
Notices.AddNotice( "copy_all", Color.Cyan, $"Copied {Entry.Connection.DisplayName}'s SteamID to your clipboard", 5 );
} );
if ( !Entry.IsMe )
{
bool isMuted = SandboxVoice.IsMuted( steamId );
menu.AddOption( isMuted ? "volume_up" : "volume_off", isMuted ? "Unmute" : "Mute", () => SandboxVoice.Mute( steamId ) );
if ( Connection.Local?.HasPermission( "admin" ) == true )
{
menu.AddSpacer();
menu.AddOption( "person_remove", "Kick", () => OpenKickConfirm( Entry ) );
menu.AddOption( "gavel", "Ban", () => OpenBanConfirm( Entry ) );
}
}
e.StopPropagation();
}
void OpenKickConfirm( PlayerData entry )
{
var popup = new StringQueryPopup
{
Title = "Kick Player",
Prompt = $"Why do you want to kick {entry.DisplayName}?",
ConfirmLabel = "Kick",
OnConfirm = x =>
{
GameManager.RpcKickPlayer( entry.Connection, x );
}
};
popup.Parent = FindPopupPanel();
}
void OpenBanConfirm( PlayerData entry )
{
var popup = new StringQueryPopup
{
Title = "Ban Player",
Prompt = $"Why do you want to ban {entry.DisplayName}?",
ConfirmLabel = "Ban",
OnConfirm = x => BanSystem.RpcBanPlayer( entry.Connection, x )
};
popup.Parent = FindPopupPanel();
}
}