Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add name labels to players in spectator mode #64

Merged
merged 1 commit into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions mp/game/dab/resource/clientscheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,54 @@ Scheme
}
// fonts listed later in the order will only be used if they fulfill a range not already filled
// if a font fails to load then the subsequent fonts will replace
SpectatorNames
{
"1"
{
"name" "Verdana"
"tall" "9"
"weight" "700"
"antialias" "1"
"yres" "1 599"
"outline" "1"
}
"2"
{
"name" "Verdana"
"tall" "12"
"weight" "700"
"antialias" "1"
"yres" "600 767"
"outline" "1"
}
"3"
{
"name" "Verdana"
"tall" "14"
"weight" "900"
"antialias" "1"
"yres" "768 1023"
"outline" "1"
}
"4"
{
"name" "Verdana"
"tall" "20"
"weight" "900"
"antialias" "1"
"yres" "1024 1199"
"outline" "1"
}
"5"
{
"name" "Verdana"
"tall" "24"
"weight" "900"
"antialias" "1"
"yres" "1200 10000"
"outline" "1"
}
}
Default
{
"1"
Expand Down
53 changes: 53 additions & 0 deletions mp/src/game/client/sdk/vgui/sdk_spectatorgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,59 @@ void CSDKSpectatorGUI::Paint()
surface()->DrawSetTextFont( vgui::scheme()->GetIScheme(vgui::scheme()->GetScheme( "ClientScheme" ))->GetFont( "Default" ) ); //reset the font, draw icon can change it
surface()->DrawUnicodeString( sButtons.c_str(), vgui::FONT_DRAW_NONADDITIVE );
}

int spec = pLocalPlayer->GetObserverMode();
if (ShouldShowPlayerLabel(spec) || spec == OBS_MODE_ROAMING)
{
// The color to be used
surface()->DrawSetTextColor(Color(255, 255, 255, 128));

// The font to be used
vgui::HFont font = vgui::scheme()->GetIScheme(vgui::scheme()->GetScheme("ClientScheme"))->GetFont("SpectatorNames");
surface()->DrawSetTextFont(font);

for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CSDKPlayer* pPlayer = ToSDKPlayer(UTIL_PlayerByIndex(i));
if (!pPlayer)
continue;

if (pPlayer == pLocalPlayer)
continue;

if (spec != OBS_MODE_ROAMING && pPlayer == pObserved)
continue;

if (!pPlayer->IsVisible())
continue;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if player is alive?

Copy link
Collaborator Author

@TomyLobo TomyLobo Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, gotta check if you can see spectators with this :D
Otherwise, it's probably covered by the visibility check

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be covered by the visibility check.

// retrieve base position
Vector basePosition = pPlayer->EyePosition() + Vector(0, 0, 16);

trace_t tr;
UTIL_TraceLine(pLocalPlayer->EyePosition(), basePosition, MASK_OPAQUE, NULL, COLLISION_GROUP_NONE, &tr);

if ((tr.endpos - basePosition).Length() > 10)
continue;

// Retrieve name and convert to unicode
wchar_t wszName[MAX_PLAYER_NAME_LENGTH];
const char *pszName = pPlayer->GetPlayerName();
g_pVGuiLocalize->ConvertANSIToUnicode(pszName, wszName, sizeof(wszName));

// transform base position
int iX, iY;
GetVectorInHudSpace(basePosition, iX, iY);

// Calculate text size
int wide, tall;
surface()->GetTextSize(font, wszName, wide, tall);

// Draw name label, with its bottom center at the basePosition
surface()->DrawSetTextPos(iX - wide/2, iY - tall);
surface()->DrawUnicodeString(wszName, vgui::FONT_DRAW_NONADDITIVE);
}
}
}

//-----------------------------------------------------------------------------
Expand Down