Skip to content

Add custom VGUI2 HUD - #280

Merged
tmp64 merged 17 commits into
tmp64:masterfrom
rtxa:hud-health-vgui2
Aug 3, 2025
Merged

Add custom VGUI2 HUD#280
tmp64 merged 17 commits into
tmp64:masterfrom
rtxa:hud-health-vgui2

Conversation

@rtxa

@rtxa rtxa commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

Custom VGUI2 HUD for health, battery and ammo. You can enable it with hud_custom 1.

Extra commands have been added to improve coloring of the HUD when health/ammo is very low or to use one main color for the HUD without changing all hud_color1/2/3 values.

Commands:

  • hud_custom 1 - Enables/disables the custom VGUI2 HUD. Disabled by default.
  • hud_dim 1 - Enables/disables dimming of the hud. Enabled by default.
  • hud_color4 "255 0 0" - HUD color when health/ammo is very low (0%; 25%).
  • hud_color_override 1 - Disables HUD coloring of health/ammo according to amount. Disabled by default.
  • hud_reloadscheme - This reload the .res files of the HUD. This will refresh the HUD and display your modifications.

I recommend using these colors for the new HUD when hud coloring by amount is enabled due to the defaults ones being too dark.

hud_color1 "100 255 100"
hud_color2 "255 182 59"
hud_color3 "255 129 59"
hud_color4 "255 65 65"

Resources being used:

  • Health and battery icons are from Half-Life 2.
  • Ammo icons are from Black Mesa: Blue Shift.
  • Font typeface being used is Hemi Head 426.
Screenshots

203BBC~1
20A3F9~1
hud-colors

Thanks and I hope you like the new HUD and gets into the official client, people's feedback has been good so far.

rtxa and others added 3 commits June 20, 2025 15:44
Custom HUD for health, battery and ammo.
Conflicts:
	src/game/client/vgui/CMakeLists.txt
@tmp64

tmp64 commented Jun 28, 2025

Copy link
Copy Markdown
Owner

Merged master and fixed conflicts: rtxa#1

@rtxa

rtxa commented Jun 28, 2025

Copy link
Copy Markdown
Contributor Author

Thanks, but I'm not sure if the history is gonna be clean, hope you can manage this or perhaps I can open a new PR and cherry-pick the commit with latest master changes and conflict resolved.

@tmp64 tmp64 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This looks really cool! Great work!

  1. I don't think this works with WeaponMod, which can can add custom sprites. You can use the code from CHudDeathNoticePanel::PaintBackground to draw sprites in VGUI.

  2. I don't like the wrapper methods in CClientViewport (like ShowHealthPanel, HideHealthPanel, etc). I think it would be better to add getters for the panels and call methods directly on them.

  3. I don't like that old sprite HUD updates the visibility of new VGUI HUD. I think it's better to move all visibility updates to CHud::Redraw. Do something like this:

    if (g_pViewport)
    {
        g_pViewport->GetHudAmmo()->ShowPanel(
            hud_draw.GetFloat() > 0 &&
            m_iWeaponBits & (1 << (WEAPON_SUIT)) &&
            !(m_iHideHUDDisplay & HIDEHUD_ALL | HIDEHUD_WEAPONS))
        // ... other panels ...
    }

    Ideally, HUD code needs to be reworked to better support VGUI panels, but that's beyond the scope of this PR.

Comment thread src/game/client/hud.cpp Outdated
Comment thread src/game/client/hud/ammo.h Outdated
int m_HUD_selection;
int m_iMaxSlot; // There are 5 (0-4) slots by default and they can extend to 6. This will be used to draw additional weapon bucket(s) on a hud.
int m_iLastFOV = 0;
ConVarRef m_pHudCustom{"hud_custom"};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Add extern ConVar hud_custom to hud.h and use it directly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/game/client/hud/ammohistory.cpp Outdated
Comment thread src/game/client/hud/battery.cpp Outdated
Comment on lines +76 to +78
if (g_pViewport) {
g_pViewport->HideBatteryPanel();
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Move panel hiding to CHud::Redraw

Comment thread src/game/client/hud/battery.cpp Outdated
Comment thread src/game/client/vgui/client_viewport.cpp Outdated
Comment thread src/game/client/vgui/client_viewport.cpp Outdated
Comment thread src/game/client/vgui/client_viewport.cpp Outdated
Comment thread src/game/client/vgui/hud_health.h Outdated
Comment thread gamedir/ui/resource/ClientSchemeBase.res Outdated
@tmp64

tmp64 commented Jul 6, 2025

Copy link
Copy Markdown
Owner

On Linux, the text is clipped on the right-hand side. Probably because the font is italic and no one tested the game with such fonts.

image

@rtxa

rtxa commented Jul 7, 2025

Copy link
Copy Markdown
Contributor Author

Weird that the font looks like this, we need to check if other Linux users have the same issue. I'm not sure if manipulating textinset key values in HudHealth.res can help with it. In any case, there is an option to set a different font by platform in section Fallback fonts from this link: https://developer.valvesoftware.com/wiki/Authoring_and_Using_TrueType_Fonts

About WeaponMod, I didn't know you can draw sprites in the VGUI2 panel. Anyway, when using custom ammo icons, it would fallback to a default ammo texture with a dot.

2055A5~1

PD: By the way, why do we need to check g_pViewport all the time? Is there a way to ensure in class constructor that has been initialized, so we can remove the checks?

@rtxa

rtxa commented Jul 7, 2025

Copy link
Copy Markdown
Contributor Author

Seems like in Linux, glyphs that are outside their bounding box are clipped/not rendered. On Windows, they do render.
imagen
I'm using online tool to test the fonts https://www.glyphrstudio.com/app/

@rtxa
rtxa force-pushed the hud-health-vgui2 branch from b5d83dd to b1f341b Compare July 21, 2025 22:46
@tmp64

tmp64 commented Jul 27, 2025

Copy link
Copy Markdown
Owner

I changed the font to Arial on Linux as a workaround

image

@tmp64

tmp64 commented Jul 27, 2025

Copy link
Copy Markdown
Owner

By the way, why do we need to check g_pViewport all the time? Is there a way to ensure in class constructor that has been initialized, so we can remove the checks?

That's a remnant from VGUI1 code. In BHL, the viewport is created once during VGUI init. Most checks can be safely removed.

@tmp64

tmp64 commented Jul 27, 2025

Copy link
Copy Markdown
Owner

I added sprite rendering for unknown ammo types

image

@tmp64

tmp64 commented Jul 27, 2025

Copy link
Copy Markdown
Owner

Please, review my changes. I don't see a much better way to show/hide ammo panels, so I left it as it. If everything looks good, I'll merge this

@rtxa

rtxa commented Aug 2, 2025

Copy link
Copy Markdown
Contributor Author

Hi tmp64, thanks for adding the HUD sprite rendering for custom weapon, it's looks great with some weapons and still fits the style of the HUD.
imagen
imagen

Unfortunately, there are some minor issues that perhaps we can address in another PR, one of them is that the sprites don't scale well in lower resolutions. The lower the resolution, the bigger the sprite gets.

imagen imagen

Other minor issue is that sometimes it doesn't recognize the correct secondary ammo icon.
imagen
imagen

Or sometimes both primary and secondary. I couldn't figure out why yet.
imagen
imagen

@rtxa

rtxa commented Aug 2, 2025

Copy link
Copy Markdown
Contributor Author

I added some minor changes like: don't draw the hud when hud_draw is off or avoid overlapping of custom HUD with hud_weapon sprite. I also provided a Linux version for the font, it still looks almost the same, only required some tweaking on the width of the texts from the panels.

Font on Linux
7149BF~1

hud_weapon no longer overlaps with the ammo panel of the custom hud.
imagen

I think it's ready to get merged.

@tmp64
tmp64 self-requested a review August 3, 2025 05:53
@tmp64
tmp64 merged commit 44603fe into tmp64:master Aug 3, 2025
6 checks passed
@tmp64

tmp64 commented Aug 3, 2025

Copy link
Copy Markdown
Owner

Thanks!

@rtxa
rtxa deleted the hud-health-vgui2 branch August 16, 2025 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants