Skip to content

Commit

Permalink
Client: HUD: Ammo: Fix custom sprites on scaled HUDs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmp64 committed Nov 25, 2023
1 parent 16688b0 commit fd72b49
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/game/client/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
#define HUD_INTERMISSION 2
#define HUD_DRAW_ALWAYS 4 //!< Draw even if hud_draw = 0

//! Fallback sprite resolution if the current one can't be found.
constexpr int HUD_FALLBACK_RES = 640;

namespace vgui2
{
class IScheme;
Expand Down
25 changes: 18 additions & 7 deletions src/game/client/hud/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ int WeaponsResource::HasAmmo(WEAPON *p)

void WeaponsResource::LoadWeaponSprites(WEAPON *pWeapon)
{
int i, iRes;

if (ScreenWidth < 640)
iRes = 320;
else
iRes = 640;
int i = 0;
int iRes = gHUD.m_iRes;

char sz[256];

Expand Down Expand Up @@ -1259,12 +1255,27 @@ client_sprite_t *GetSpriteFromList(client_sprite_t *pList, const char *pszNameSt

int len = strlen(pszNameStart);
client_sprite_t *p = pList;
client_sprite_t *pFallback = nullptr; //!< Fallback sprite if can't find for current HUD scale
while (iCount--)
{
if (!strncmp(pszNameStart, p->szName, len))
{
if (p->iRes == iRes)
{
// Found the requested sprite
return p;
}
else if (p->iRes == HUD_FALLBACK_RES)
{
// At least found a fallbcak
pFallback = p;
}
}
if (p->iRes == iRes && !strncmp(pszNameStart, p->szName, len))
return p;
p++;
}

return NULL;
// Return the fallback. It may be null but that's fine.
return pFallback;
}

0 comments on commit fd72b49

Please sign in to comment.