[HL25] Backport HUD changes

This commit is contained in:
Joël Troch 2024-08-27 23:12:49 +02:00
parent edbae22970
commit 246c1d575e
8 changed files with 75 additions and 43 deletions

View file

@ -73,10 +73,14 @@ void WeaponsResource::LoadWeaponSprites(WEAPON* pWeapon)
{
int i, iRes;
if (ScreenWidth < 640)
iRes = 320;
else
if (ScreenWidth > 2560 && ScreenHeight > 1600)
iRes = 2560;
else if (ScreenWidth >= 1280 && ScreenHeight > 720)
iRes = 1280;
else if (ScreenWidth >= 640)
iRes = 640;
else
iRes = 320;
char sz[256];
@ -323,16 +327,17 @@ bool CHudAmmo::VidInit()
// If we've already loaded weapons, let's get new sprites
gWR.LoadAllWeaponSprites();
if (ScreenWidth >= 640)
{
giABWidth = 20;
giABHeight = 4;
}
else
{
giABWidth = 10;
giABHeight = 2;
}
int nScale = 1;
if (ScreenWidth > 2560 && ScreenHeight > 1600)
nScale = 4;
else if (ScreenWidth >= 1280 && ScreenHeight > 720)
nScale = 3;
else if (ScreenWidth >= 640)
nScale = 2;
giABWidth = 10 * nScale;
giABHeight = 2 * nScale;
return true;
}
@ -867,8 +872,8 @@ bool CHudAmmo::Draw(float flTime)
ScaleColors(r, g, b, a);
// Does this weapon have a clip?
y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
y += (int)(gHUD.m_iFontHeight * 0.2f);
// Does weapon have any ammo at all?
if (m_pWeapon->iAmmoType > 0)
@ -1183,7 +1188,7 @@ client_sprite_t* GetSpriteList(client_sprite_t* pList, const char* psz, int iRes
while (0 != i--)
{
if ((0 == strcmp(psz, p->szName)) && (p->iRes == iRes))
if ((p->iRes == iRes) && (0 == strcmp(psz, p->szName)))
return p;
p++;
}

View file

@ -130,7 +130,7 @@ bool HistoryResource::DrawAmmoHistory(float flTime)
// Draw the pic
int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i));
int xpos = ScreenWidth - 24;
int xpos = ScreenWidth - (rcPic.right - rcPic.left) - 4;
if (spr && 0 != *spr) // weapon isn't loaded yet so just don't draw the pic
{ // the dll has to make sure it has sent info the weapons you need
SPR_Set(*spr, r, g, b);

View file

@ -113,7 +113,11 @@ bool CHudBattery::Draw(float flTime)
int iOffset = (m_prc1->bottom - m_prc1->top) / 6;
y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
x = ScreenWidth / 4;
int width = (m_prc1->right - m_prc1->left);
// this used to just be ScreenWidth/5 (4 on Updated) but that caused real issues at higher resolutions. Instead, base it on the width of this sprite.
x = 3 * width;
// make sure we have the right sprite handles
if (0 == m_hSprite1)
@ -130,7 +134,8 @@ bool CHudBattery::Draw(float flTime)
SPR_DrawAdditive(0, x, y - iOffset + (rc.top - m_prc2->top), &rc);
}
x += (m_prc1->right - m_prc1->left);
x += width;
y += (int)(gHUD.m_iFontHeight * 0.2f);
x = gHUD.DrawHudNumber(x, y, DHN_3DIGITS | DHN_DRAWZERO, m_iBat, r, g, b);
return true;

View file

@ -80,7 +80,7 @@ bool CHudDeathNotice::Init()
HOOK_MESSAGE(DeathMsg);
CVAR_CREATE("hud_deathnotice_time", "6", 0);
CVAR_CREATE("hud_deathnotice_time", "6", FCVAR_ARCHIVE);
return true;
}
@ -101,7 +101,12 @@ bool CHudDeathNotice::VidInit()
bool CHudDeathNotice::Draw(float flTime)
{
int x, y, r, g, b;
int x, y, r, g, b, texty;
int gap = 20;
Rect sprite = gHUD.GetSpriteRect(m_HUD_d_skull);
gap = sprite.bottom - sprite.top;
for (int i = 0; i < MAX_DEATHNOTICES; i++)
{
@ -122,10 +127,12 @@ bool CHudDeathNotice::Draw(float flTime)
if (gViewPort && gViewPort->AllowedToPrintText())
{
// Draw the death notice
y = DEATHNOTICE_TOP + 2 + (20 * i); //!!!
y = DEATHNOTICE_TOP + 2 + (gap * i);
texty = y + 4;
int id = (rgDeathNoticeList[i].iId == -1) ? m_HUD_d_skull : rgDeathNoticeList[i].iId;
x = ScreenWidth - ConsoleStringLen(rgDeathNoticeList[i].szVictim) - (gHUD.GetSpriteRect(id).right - gHUD.GetSpriteRect(id).left);
x = ScreenWidth - ConsoleStringLen(rgDeathNoticeList[i].szVictim) - (gHUD.GetSpriteRect(id).right - gHUD.GetSpriteRect(id).left) - 4;
if (!rgDeathNoticeList[i].iSuicide)
{
@ -134,7 +141,7 @@ bool CHudDeathNotice::Draw(float flTime)
// Draw killers name
if (rgDeathNoticeList[i].KillerColor)
gEngfuncs.pfnDrawSetTextColor(rgDeathNoticeList[i].KillerColor[0], rgDeathNoticeList[i].KillerColor[1], rgDeathNoticeList[i].KillerColor[2]);
x = 5 + DrawConsoleString(x, y, rgDeathNoticeList[i].szKiller);
x = 5 + DrawConsoleString(x, texty, rgDeathNoticeList[i].szKiller);
}
r = 255;
@ -158,7 +165,7 @@ bool CHudDeathNotice::Draw(float flTime)
{
if (rgDeathNoticeList[i].VictimColor)
gEngfuncs.pfnDrawSetTextColor(rgDeathNoticeList[i].VictimColor[0], rgDeathNoticeList[i].VictimColor[1], rgDeathNoticeList[i].VictimColor[2]);
x = DrawConsoleString(x, y, rgDeathNoticeList[i].szVictim);
x = DrawConsoleString(x, texty, rgDeathNoticeList[i].szVictim);
}
}
}

View file

@ -214,6 +214,7 @@ bool CHudHealth::Draw(float flTime)
SPR_DrawAdditive(0, x, y, &gHUD.GetSpriteRect(m_HUD_cross));
x = CrossWidth + HealthWidth / 2;
y += (int)(gHUD.m_iFontHeight * 0.2f);
//Reserve space for 3 digits by default, but allow it to expand
x += gHUD.GetHudNumberWidth(m_iHealth, 3, DHN_DRAWZERO);
@ -310,14 +311,14 @@ bool CHudHealth::DrawPain(float flTime)
if (m_fAttackFront > 0.4)
{
GetPainColor(r, g, b);
shade = a * V_max(m_fAttackFront, 0.5);
shade = a * V_max(m_fAttackFront, 0.5f);
ScaleColors(r, g, b, shade);
SPR_Set(m_hSprite, r, g, b);
x = ScreenWidth / 2 - SPR_Width(m_hSprite, 0) / 2;
y = ScreenHeight / 2 - SPR_Height(m_hSprite, 0) * 3;
SPR_DrawAdditive(0, x, y, NULL);
m_fAttackFront = V_max(0, m_fAttackFront - fFade);
m_fAttackFront = V_max(0.0f, m_fAttackFront - fFade);
}
else
m_fAttackFront = 0;
@ -325,14 +326,14 @@ bool CHudHealth::DrawPain(float flTime)
if (m_fAttackRight > 0.4)
{
GetPainColor(r, g, b);
shade = a * V_max(m_fAttackRight, 0.5);
shade = a * V_max(m_fAttackRight, 0.5f);
ScaleColors(r, g, b, shade);
SPR_Set(m_hSprite, r, g, b);
x = ScreenWidth / 2 + SPR_Width(m_hSprite, 1) * 2;
y = ScreenHeight / 2 - SPR_Height(m_hSprite, 1) / 2;
SPR_DrawAdditive(1, x, y, NULL);
m_fAttackRight = V_max(0, m_fAttackRight - fFade);
m_fAttackRight = V_max(0.0f, m_fAttackRight - fFade);
}
else
m_fAttackRight = 0;
@ -340,14 +341,14 @@ bool CHudHealth::DrawPain(float flTime)
if (m_fAttackRear > 0.4)
{
GetPainColor(r, g, b);
shade = a * V_max(m_fAttackRear, 0.5);
shade = a * V_max(m_fAttackRear, 0.5f);
ScaleColors(r, g, b, shade);
SPR_Set(m_hSprite, r, g, b);
x = ScreenWidth / 2 - SPR_Width(m_hSprite, 2) / 2;
y = ScreenHeight / 2 + SPR_Height(m_hSprite, 2) * 2;
SPR_DrawAdditive(2, x, y, NULL);
m_fAttackRear = V_max(0, m_fAttackRear - fFade);
m_fAttackRear = V_max(0.0f, m_fAttackRear - fFade);
}
else
m_fAttackRear = 0;
@ -355,7 +356,7 @@ bool CHudHealth::DrawPain(float flTime)
if (m_fAttackLeft > 0.4)
{
GetPainColor(r, g, b);
shade = a * V_max(m_fAttackLeft, 0.5);
shade = a * V_max(m_fAttackLeft, 0.5f);
ScaleColors(r, g, b, shade);
SPR_Set(m_hSprite, r, g, b);
@ -363,7 +364,7 @@ bool CHudHealth::DrawPain(float flTime)
y = ScreenHeight / 2 - SPR_Height(m_hSprite, 3) / 2;
SPR_DrawAdditive(3, x, y, NULL);
m_fAttackLeft = V_max(0, m_fAttackLeft - fFade);
m_fAttackLeft = V_max(0.0f, m_fAttackLeft - fFade);
}
else
m_fAttackLeft = 0;

View file

@ -426,10 +426,14 @@ void CHud::VidInit()
m_hsprLogo = 0;
m_hsprCursor = 0;
if (ScreenWidth < 640)
m_iRes = 320;
else
if (ScreenWidth > 2560 && ScreenHeight > 1600)
m_iRes = 2560;
else if (ScreenWidth >= 1280 && ScreenHeight > 720)
m_iRes = 1280;
else if (ScreenWidth >= 640)
m_iRes = 640;
else
m_iRes = 320;
// Only load this once
if (!m_pSpriteList)

View file

@ -144,6 +144,10 @@ bool CHudMenu::Draw(float flTime)
if (gViewPort && gViewPort->IsScoreBoardVisible())
return true;
SCREENINFO screenInfo;
screenInfo.iSize = sizeof( SCREENINFO );
gEngfuncs.pfnGetScreenInfo( &screenInfo );
// draw the menu, along the left-hand side of the screen
// count the number of newlines
@ -155,8 +159,10 @@ bool CHudMenu::Draw(float flTime)
nlc++;
}
int nFontHeight = V_max(12, screenInfo.iCharHeight);
// center it
int y = (ScreenHeight / 2) - ((nlc / 2) * 12) - 40; // make sure it is above the say text
int y = (ScreenHeight/2) - ((nlc/2)* nFontHeight) - (3 * nFontHeight + nFontHeight / 3); // make sure it is above the say text
menu_r = 255;
menu_g = 255;
@ -176,7 +182,7 @@ bool CHudMenu::Draw(float flTime)
{
menu_ralign = false;
menu_x = 20;
y += (12);
y += nFontHeight;
sptr++;
}

View file

@ -27,15 +27,19 @@
HSPRITE LoadSprite(const char* pszName)
{
int i;
char sz[256];
int iRes;
char sz[256];
if (ScreenWidth < 640)
i = 320;
if (ScreenWidth > 2560 && ScreenHeight > 1600)
iRes = 2560;
else if (ScreenWidth >= 1280 && ScreenHeight > 720)
iRes = 1280;
else if (ScreenWidth >= 640)
iRes = 640;
else
i = 640;
iRes = 320;
sprintf(sz, pszName, i);
sprintf(sz, pszName, iRes);
return SPR_Load(sz);
}