Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sr2echa/TF2-Source-Code/llms.txt

Use this file to discover all available pages before exploring further.

TF2’s user interface is built on VGUI2 (Valve GUI 2), a retained-mode panel system declared in public/vgui/ and implemented in vgui2/. All HUD elements — health, ammo, objectives, charge meters — and menus are VGUI2 panels. The game-specific HUD lives in game/client/tf/ and game/client/hud_*.cpp.

VGUI2 panel system

Every UI element inherits from vgui::Panel (or a subclass). Panels form a tree; each panel owns its children and is responsible for layout and painting.
// public/vgui/Panel.h (simplified)
namespace vgui
{
class Panel : public IClientPanel
{
public:
    Panel( Panel *parent, const char *panelName );
    virtual void Paint();           // draw the panel content
    virtual void PerformLayout();   // compute size/position of children
    virtual void OnCommand( const char *command );
    virtual void ApplySchemeSettings( IScheme *pScheme );
};
}
Common base classes used in TF2:
ClassFileUsage
EditablePanelvgui_controls/EditablePanel.hContainer panels loaded from .res files
Framevgui_controls/Frame.hMovable dialog windows
ImagePanelvgui_controls/ImagePanel.hTexture display
Labelvgui_controls/Label.hText display
Buttonvgui_controls/Button.hClickable buttons
RichTextvgui_controls/RichText.hMulti-line formatted text

HUD element system

TF2 HUD elements inherit from CHudElement (game/client/hudelement.h). They register with GetHud() via the DECLARE_HUDELEMENT macro and receive ShouldDraw(), Init(), Reset(), and Paint() callbacks each frame.
// game/client/hudelement.h
class CHudElement
{
public:
    CHudElement( const char *pElementName );
    virtual bool ShouldDraw() { return true; }
    virtual void Init() {}
    virtual void Reset() {}
    virtual void OnTick() {}
    virtual void ProcessInput() {}
    virtual void SetActive( bool bActive );
};

// Registration macro
DECLARE_HUDELEMENT( CHudAmmoStatus );

TF2-specific HUD components

CTFHudPlayerHealth and CTFHudAmmoWeapons (in game/client/tf/) read from the local player’s networked health and ammo variables and draw the corresponding numeric and icon panels.
Medi Gun ÜberCharge, Bonk energy, and similar meters use CTFHudItemEffectMeter — a generic charge bar that reads an item attribute or condition value from CTFPlayerShared.
CHudControlPointIcons (game/client/hud_controlpointicons.cpp) reads from CTFObjectiveResource (replicated from server) to display capping progress, team ownership icons, and lock states.
CHudDeathNotice displays the kill feed. Floating damage numbers are drawn by CTFHudDamageAccount using world-to-screen projection of the damage position.
CTFHudMannVsMachineStatus displays wave progress, robot counts, and the money collected tracker. It reads from CTFObjectiveResource network variables populated by the MvM game logic.

Schemes and fonts

VGUI2 schemes (.res files in resource/) define fonts, colors, and border styles. Game code retrieves scheme values via IScheme:
// Applying scheme in a panel
void CMyPanel::ApplySchemeSettings( IScheme *pScheme )
{
    BaseClass::ApplySchemeSettings( pScheme );
    SetFont( pScheme->GetFont( "HudFontMedium", IsProportional() ) );
    SetFgColor( pScheme->GetColor( "TFOrange", Color( 255, 128, 0, 255 ) ) );
}

.res layout files

Panel layout is driven by KeyValues .res files loaded at runtime, so UI can be resized and repositioned without recompilation. EditablePanel::LoadControlSettings() parses the file and applies xpos, ypos, wide, tall, and labelText keys to child controls.
HUD .res files are loaded from scripts/HudLayout.res and per-panel files in resource/ui/. Custom HUDs mod these files to rearrange or restyle TF2’s interface.

Build docs developers (and LLMs) love