Skip to content
Open
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
52 changes: 48 additions & 4 deletions cl_dll/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ int CHudAmmo::MsgFunc_AmmoX(const char *pszName, int iSize, void *pbuf)

gWR.SetAmmo( iIndex, abs(iCount) );

m_fFade = FADE_TIME;

return 1;
}

Expand Down Expand Up @@ -891,6 +893,8 @@ int CHudAmmo::Draw(float flTime)
else
a = MIN_ALPHA;

float alphaDim = a;

a *= gHUD.GetHudTransparency();
gHUD.GetHudColor(0, 0, r, g, b);
ScaleColors(r, g, b, a );
Expand Down Expand Up @@ -920,8 +924,11 @@ int CHudAmmo::Draw(float flTime)

if (pw->iClip >= 0)
{
a = alphaDim * gHUD.GetHudTransparency();
gHUD.GetHudAmmoColor(pw->iClip, GetMaxClip(pw->szName), r, g, b);
ScaleColors(r, g, b, a);

// room for the number and the '|' and the current ammo

x = ScreenWidth - (8 * AmmoWidth) - iIconWidth;
x = gHUD.DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pw->iClip, r, g, b);

Expand All @@ -935,21 +942,22 @@ int CHudAmmo::Draw(float flTime)

x += AmmoWidth/2;

gHUD.GetHudColor(0, 0, r, g, b);

// draw the | bar
FillRGBA(x, y, iBarWidth, gHUD.m_iFontHeight, r, g, b, a);

x += iBarWidth + AmmoWidth/2;;

// GL Seems to need this
ScaleColors(r, g, b, a );
x = gHUD.DrawHudNumber(x, y, iFlags | DHN_3DIGITS, gWR.CountAmmo(pw->iAmmoType), r, g, b);


}
else
{
a = alphaDim * gHUD.GetHudTransparency();
gHUD.GetHudAmmoColor(gWR.CountAmmo(pw->iAmmoType), pw->iMax1, r, g, b);
ScaleColors(r, g, b, a);

// SPR_Draw a bullets only line
x = ScreenWidth - 4 * AmmoWidth - iIconWidth;
x = gHUD.DrawHudNumber(x, y, iFlags | DHN_3DIGITS, gWR.CountAmmo(pw->iAmmoType), r, g, b);
Expand All @@ -969,6 +977,10 @@ int CHudAmmo::Draw(float flTime)
// Do we have secondary ammo?
if ((pw->iAmmo2Type != 0) && (gWR.CountAmmo(pw->iAmmo2Type) > 0))
{
a = alphaDim * gHUD.GetHudTransparency();
gHUD.GetHudAmmoColor(pw->iClip, GetMaxClip(pw->szName), r, g, b);
ScaleColors(r, g, b, a);

y -= gHUD.m_iFontHeight + gHUD.m_iFontHeight/4;
x = ScreenWidth - 4 * AmmoWidth - iIconWidth;
x = gHUD.DrawHudNumber(x, y, iFlags|DHN_3DIGITS, gWR.CountAmmo(pw->iAmmo2Type), r, g, b);
Expand Down Expand Up @@ -1220,6 +1232,38 @@ int CHudAmmo::DrawWList(float flTime)

}

// m_iMaxClip is never sended to the client, until i figure out another way, this is the best thing we can use
int CHudAmmo::GetMaxClip(char *weaponname)
{
if (!strcmp(weaponname, "weapon_9mmhandgun"))
{
return 17;
}
else if (!strcmp(weaponname, "weapon_9mmAR"))
{
return 50;
}
else if (!strcmp(weaponname, "weapon_shotgun"))
{
return 8;
}
else if (!strcmp(weaponname, "weapon_crossbow"))
{
return 5;
}
else if (!strcmp(weaponname, "weapon_rpg"))
{
return 1;
}
else if (!strcmp(weaponname, "weapon_357"))
{
return 6;
}
else // if you are using custom weapons, then custom colors for ammo hud aren't going to be used..
{
return -1;
}
}

/* =================================
GetSpriteFromList
Expand Down
31 changes: 31 additions & 0 deletions cl_dll/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,37 @@ void CHud::GetHudColor( int hudPart, int value, int &r, int &g, int &b )
b = c->b;
}

void CHud::GetHudAmmoColor(int value, int maxvalue, int &r, int &g, int &b)
{
RGBA *c;
if (maxvalue == -1) // if you are using custom weapons, then default colors are going to be used....
{
ParseColor(m_pCvarColor->string, m_hudColor); c = &m_hudColor;
}
else if ((value * 100) / maxvalue > 90)
{
ParseColor(m_pCvarColor1->string, m_hudColor1); c = &m_hudColor1;
}
else if ((value * 100) / maxvalue > 50)
{
ParseColor(m_pCvarColor2->string, m_hudColor2); c = &m_hudColor2;
}
else if ((value * 100) / maxvalue > 20)
{
ParseColor(m_pCvarColor3->string, m_hudColor3); c = &m_hudColor3;
}
else
{
r = 255;
g = 0;
b = 0;
return;
}
r = c->r;
g = c->g;
b = c->b;
}

float CHud::GetHudTransparency()
{
float hud_draw = m_pCvarDraw->value;
Expand Down
4 changes: 3 additions & 1 deletion cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class CHudAmmo: public CHudBase
int MsgFunc_ItemPickup( const char *pszName, int iSize, void *pbuf );
int MsgFunc_HideWeapon( const char *pszName, int iSize, void *pbuf );

int GetMaxClip(char* weaponname);
int GetMaxSlot(void) { return m_iMaxSlot; }
void SlotInput( int iSlot );
void _cdecl UserCmd_Slot1( void );
Expand Down Expand Up @@ -744,7 +745,8 @@ class CHud
int GetNumWidth(int iNumber, int iFlags);
int GetHudCharWidth(int c);
int CalculateCharWidth(int c);
void GetHudColor( int hudPart, int value, int &r, int &g, int &b );
void GetHudColor(int hudPart, int value, int &r, int &g, int &b);
void GetHudAmmoColor(int value, int maxvalue, int &r, int &g, int &b);
float GetHudTransparency();

private:
Expand Down