Skip to content

Commit

Permalink
Add name labels to spectator mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TomyLobo committed Jun 14, 2016
1 parent eda4e57 commit 645b8ef
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
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;

// 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

0 comments on commit 645b8ef

Please sign in to comment.