Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Implement hud_alpha #126

Closed
wants to merge 3 commits into from
Closed
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
18 changes: 12 additions & 6 deletions cl_dll/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,9 @@ int CHudAmmo::Draw(float flTime)

UnpackRGB(r,g,b, gHUD.m_iDefaultHUDColor);

ScaleColors(r, g, b, a );
gHUD.GetHudColorsWithAlpha(r, g, b, a);

//ScaleColors(r, g, b, a );

// Does this weapon have a clip?
y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight/2;
Expand All @@ -883,12 +885,14 @@ int CHudAmmo::Draw(float flTime)
if (gWR.HasAmmo(m_pWeapon))
{
UnpackRGB(r, g, b, gHUD.m_iDefaultHUDColor);
ScaleColors(r, g, b, 192);
// ScaleColors(r, g, b, 192);
gHUD.GetHudColorsWithAlpha(r, g, b, 192);
}
else
{
UnpackRGB(r, g, b, RGB_REDISH);
ScaleColors(r, g, b, 128);
// ScaleColors(r, g, b, 128);
gHUD.GetHudColorsWithAlpha(r, g, b, 128);
}

SPR_Set(m_pWeapon->hInactive, r, g, b);
Expand Down Expand Up @@ -919,14 +923,15 @@ int CHudAmmo::Draw(float flTime)
x += AmmoWidth/2;

UnpackRGB(r,g,b, gHUD.m_iDefaultHUDColor);
gHUD.GetHudColorsWithAlpha(r, g, b, a); // used for both number and bar

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

x += iBarWidth + AmmoWidth/2;;
x += iBarWidth + AmmoWidth/2;

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


Expand Down Expand Up @@ -1074,7 +1079,8 @@ int CHudAmmo::DrawWList(float flTime)
else
a = 192;

ScaleColors(r, g, b, 255);
//ScaleColors(r, g, b, 255);
gHUD.GetHudColorsWithAlpha(r, g, b);
SPR_Set(gHUD.GetSprite(m_HUD_bucket0 + i), r, g, b );

// make active slot wide enough to accomodate gun pictures
Expand Down
4 changes: 3 additions & 1 deletion cl_dll/ammo_secondary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ int CHudAmmoSecondary :: Draw(float flTime)
a = (int) max( MIN_ALPHA, m_fFade );
if (m_fFade > 0)
m_fFade -= (gHUD.m_flTimeDelta * 20); // slowly lower alpha to fade out icons
ScaleColors( r, g, b, a );

gHUD.GetHudColorsWithAlpha(r, g, b, a); // order is important here
//ScaleColors( r, g, b, a );

AmmoWidth = gHUD.GetSpriteRect(gHUD.m_HUD_number_0).right - gHUD.GetSpriteRect(gHUD.m_HUD_number_0).left;

Expand Down
3 changes: 2 additions & 1 deletion cl_dll/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ int CHudBattery::Draw(float flTime)
else
a = MIN_ALPHA;

ScaleColors(r, g, b, a );
//ScaleColors(r, g, b, a );
gHUD.GetHudColorsWithAlpha(r, g, b, a);

int iOffset = (m_prc1->bottom - m_prc1->top)/6;

Expand Down
6 changes: 5 additions & 1 deletion cl_dll/health.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ int CHudHealth::Draw(float flTime)
a = 255;

GetPainColor( r, g, b );
ScaleColors(r, g, b, a );
gHUD.GetHudColorsWithAlpha(r, g, b, a); // order is important here

// ScaleColors(r, g, b, a );

// Only draw health if we have the suit.
if (gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)))
Expand All @@ -226,6 +228,8 @@ int CHudHealth::Draw(float flTime)
int iWidth = HealthWidth/10;

UnpackRGB(r, g, b, gHUD.m_iDefaultHUDColor);

gHUD.GetHudColorsWithAlpha(r, g, b, a);
FillRGBA(x, y, iWidth, iHeight, r, g, b, a);
}

Expand Down
2 changes: 2 additions & 0 deletions cl_dll/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ void CHud :: Init( void )
m_pCvarViewheightMode = CVAR_CREATE("cl_viewheight_mode", "0", FCVAR_ARCHIVE);
m_pCvarHideCorpses = CVAR_CREATE("cl_hidecorpses", "0", FCVAR_ARCHIVE);
m_pCvarColor = CVAR_CREATE( "hud_color", "", FCVAR_ARCHIVE );
m_pCvarHudAlpha = CVAR_CREATE( "hud_alpha", "", FCVAR_ARCHIVE );

cl_lw = gEngfuncs.pfnGetCvarPointer( "cl_lw" );

m_pSpriteList = NULL;
Expand Down
2 changes: 2 additions & 0 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ class CHud
cvar_t *m_pCvarAutostop;
cvar_t *m_pCvarViewheightMode;
cvar_t *m_pCvarHideCorpses;
cvar_t *m_pCvarHudAlpha;

int m_iFontHeight;

Expand All @@ -604,6 +605,7 @@ class CHud
int DrawHudNumber(int x, int y, int iFlags, int iNumber, int r, int g, int b);
int DrawHudNumber(int x, int y, int number, int r, int g, int b);
int DrawHudNumberCentered(int x, int y, int number, int r, int g, int b);
void GetHudColorsWithAlpha(int &r, int &g, int &b, int a = 255);
int DrawHudString(int x, int y, int iMaxX, const char *szString, int r, int g, int b );
int DrawHudStringReverse( int xpos, int ypos, int iMinX, const char *szString, int r, int g, int b );
int DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int r, int g, int b );
Expand Down
22 changes: 22 additions & 0 deletions cl_dll/hud_redraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,24 @@ void CHud::UpdateDefaultHUDColor()
}
}

void CHud :: GetHudColorsWithAlpha( int &r, int &g, int &b, int a )
{
// scales the colors by a, only if hud_alpha is a non-empty and is an integer
// if a is not given, defaults to 255

if ( sscanf(m_pCvarHudAlpha->string, "%d", &a) == 1)
{
a = m_pCvarHudAlpha->value;
a = (int) max(a, 1);
a = (int) min(a, 255);
}

ScaleColors( r, g, b, a );
}

int CHud :: DrawHudString(int xpos, int ypos, int iMaxX, const char *szIt, int r, int g, int b )
{
GetHudColorsWithAlpha(r, g, b);
return xpos + gEngfuncs.pfnDrawString( xpos, ypos, szIt, r, g, b);
}

Expand All @@ -296,6 +312,7 @@ int CHud :: DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int

int CHud :: DrawHudNumberStringFixed( int xpos, int ypos, int iNumber, int r, int g, int b )
{
GetHudColorsWithAlpha(r, g, b);
char szString[32];
sprintf( szString, "%d", iNumber );
return DrawHudStringRightAligned( xpos, ypos, szString, r, g, b );
Expand All @@ -304,6 +321,7 @@ int CHud :: DrawHudNumberStringFixed( int xpos, int ypos, int iNumber, int r, in
// draws a string from right to left (right-aligned)
int CHud :: DrawHudStringReverse( int xpos, int ypos, int iMinX, const char *szString, int r, int g, int b )
{
GetHudColorsWithAlpha(r, g, b);
return xpos - gEngfuncs.pfnDrawStringReverse( xpos, ypos, szString, r, g, b);
}

Expand Down Expand Up @@ -409,6 +427,7 @@ int CHud::DrawHudNumberCentered(int x, int y, int number, int r, int g, int b)
{
auto digit_width = GetSpriteRect(m_HUD_number_0).right - GetSpriteRect(m_HUD_number_0).left;
auto digit_count = count_digits(number);
GetHudColorsWithAlpha(r, g, b);

return DrawHudNumber(x - (digit_width * digit_count) / 2, y, number, r, g, b);
}
Expand Down Expand Up @@ -442,12 +461,14 @@ int CHud::GetNumWidth( int iNumber, int iFlags )
int CHud::DrawHudStringCentered(int x, int y, const char* string, int r, int g, int b)
{
auto width = GetHudStringWidth(string);
GetHudColorsWithAlpha(r, g, b);
return x + gEngfuncs.pfnDrawString(x - width / 2, y, string, r, g, b);
}

int CHud::DrawHudStringRightAligned(int x, int y, const char* string, int r, int g, int b)
{
auto width = GetHudStringWidth(string);
GetHudColorsWithAlpha(r, g, b);
gEngfuncs.pfnDrawString(x - width, y, string, r, g, b);
return x;
}
Expand All @@ -466,6 +487,7 @@ int CHud::DrawHudStringWithColorTags(int x, int y, char* string, int default_r,
b = default_b;
}

GetHudColorsWithAlpha(r, g, b);
x += gEngfuncs.pfnDrawString(x, y, string, r, g, b);
});

Expand Down
2 changes: 2 additions & 0 deletions cl_dll/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ void CHudMessage::MessageScanNextChar( void )

if (gHUD.m_Rainbow.IsEnabled())
gHUD.m_Rainbow.GetRainbowColor(m_parms.x, m_parms.y, srcRed, srcGreen, srcBlue);
else
gHUD.GetHudColorsWithAlpha(srcRed, srcGreen, srcBlue);

switch( m_parms.pMessage->effect )
{
Expand Down