Skip to content

Commit d2eab39

Browse files
committed
CInfoMessages: Apply infc damage texture aspect ratio
1 parent 4c4c792 commit d2eab39

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/game/client/components/infomessages.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,23 +433,35 @@ void CInfoMessages::RenderKillMsg(const CInfoMsg &InfoMsg, float x, float y)
433433
}
434434

435435
// render weapon
436-
x -= 32.0f;
437436
int VanillaWeapon = InfoMsg.m_Weapon;
438437
if(InfoMsg.m_InfDamageType >= 0)
439438
{
440439
int Index = InfoMsg.m_InfDamageType;
441440
EDamageType DamageType = static_cast<EDamageType>(InfoMsg.m_InfDamageType);
441+
float AspectRatio = GameClient()->GetAspectTextureRatio(DamageType);
442442
IGraphics::CTextureHandle DamageTypeTexture = GameClient()->GetInfclassTextureForDamageType(DamageType);
443443
if(DamageTypeTexture.IsValid())
444444
{
445+
float ExtraOffset = 0;
446+
static const float DefaultMetric = 32.0;
447+
if(AspectRatio >= 1)
448+
{
449+
AspectRatio = 1;
450+
}
451+
else
452+
{
453+
ExtraOffset = (1 - AspectRatio) / 2;
454+
}
445455
Graphics()->TextureSet(DamageTypeTexture);
446-
Graphics()->RenderQuadContainerAsSprite(m_SpriteQuadContainerIndex, m_InfWeaponOffset + Index, x, y + 20);
456+
x -= DefaultMetric * AspectRatio;
457+
Graphics()->RenderQuadContainerAsSprite(m_SpriteQuadContainerIndex, m_InfWeaponOffset + Index, x - ExtraOffset * DefaultMetric, y + 20);
447458
VanillaWeapon = -1;
448459
}
449460
}
450461

451462
if(VanillaWeapon >= 0)
452463
{
464+
x -= 32.0f;
453465
Graphics()->TextureSet(GameClient()->m_GameSkin.m_aSpriteWeapons[InfoMsg.m_Weapon]);
454466
Graphics()->RenderQuadContainerAsSprite(m_SpriteQuadContainerIndex, 4 + InfoMsg.m_Weapon, x, y + 28);
455467
}

src/game/client/gameclient.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,6 +4402,21 @@ int CGameClient::GetInfclassSpriteForDamageType(EDamageType DamageType)
44024402
}
44034403
}
44044404

4405+
float CGameClient::GetAspectTextureRatio(EDamageType DamageType)
4406+
{
4407+
int SpriteIndex = GetInfclassSpriteForDamageType(DamageType);
4408+
if(SpriteIndex < 0)
4409+
return 1;
4410+
4411+
float H = g_pData->m_aSprites[SpriteIndex].m_H;
4412+
float W = g_pData->m_aSprites[SpriteIndex].m_W;
4413+
if(W <= 0)
4414+
{
4415+
return 0;
4416+
}
4417+
return W / H;
4418+
}
4419+
44054420
IGraphics::CTextureHandle *CGameClient::GetInfclassTexturePtrForDamageType(EDamageType DamageType)
44064421
{
44074422
switch(DamageType)

src/game/client/gameclient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ class CGameClient : public IGameClient
806806
IGraphics::CTextureHandle *GetInfclassTexturePtrForDamageType(EDamageType DamageType);
807807
IGraphics::CTextureHandle GetInfclassTextureForDamageType(EDamageType DamageType);
808808
int GetInfclassSpriteForDamageType(EDamageType DamageType);
809+
float GetAspectTextureRatio(EDamageType DamageType);
809810

810811
struct SClientParticlesSkin
811812
{

0 commit comments

Comments
 (0)