2472: Add function to show health and armor in nameplates. (mainly for server demo) r=def- a=sirius1242

The effect is as follows:
![effect image](https://user-images.githubusercontent.com/32300858/86894538-c6be2900-c135-11ea-832c-d4beaae36724.png)
- use `cl_nameplates_ha` to switch on-off. (default is off)
- use `cl_nameplates_ha_size` to adjust size of health and armor nameplates.

Mainly for server-side-recorded demos. If it can't get health and armor data, this will not be rendered.

Co-authored-by: sirius <sirius.ustc@gmail.com>
This commit is contained in:
bors[bot] 2020-07-16 13:19:01 +00:00 committed by GitHub
commit 127e4e643d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View file

@ -154,6 +154,48 @@ void CNamePlates::RenderNameplatePos(vec2 Position, const CNetObj_PlayerInfo *pP
TextRender()->Text(0, Position.x-tw_id/2.0f, Position.y-Offset-38.0f, 28.0f, aBuf, -1.0f);
}
if(g_Config.m_ClNameplatesHA) // render health and armor in nameplate
{
int Health = m_pClient->m_Snap.m_aCharacters[ClientID].m_Cur.m_Health;
if(Health > 0)
{
int Armor = m_pClient->m_Snap.m_aCharacters[ClientID].m_Cur.m_Armor;
float HFontSize = 5.0f + 20.0f * g_Config.m_ClNameplatesHASize / 100.0f;
float AFontSize = 6.0f + 24.0f * g_Config.m_ClNameplatesHASize / 100.0f;
char aHealth[40] = "\0";
char aArmor[40] = "\0";
for(int i = 0; i < Health; i++)
str_append(aHealth, "", sizeof(aHealth));
for(int i = Health; i < 10; i++)
str_append(aHealth, "", sizeof(aHealth));
str_append(aHealth, "\0", sizeof(aHealth));
for(int i = 0; i < Armor; i++)
str_append(aArmor, "", sizeof(aArmor));
for(int i = Armor; i < 10; i++)
str_append(aArmor, "", sizeof(aArmor));
str_append(aArmor, "\0", sizeof(aArmor));
float Offset;
if(g_Config.m_ClNameplatesClan && (g_Config.m_Debug || g_Config.m_ClNameplatesIDs))
Offset = (FontSize * 3 + FontSizeClan);
else if (g_Config.m_ClNameplatesClan)
Offset = (FontSize * 2 + FontSizeClan);
else if (g_Config.m_Debug || g_Config.m_ClNameplatesIDs)
Offset = (FontSize * 3);
else
Offset = (FontSize * 2);
float PosHealth = TextRender()->TextWidth(0, HFontSize, aHealth, -1, -1.0f);
TextRender()->TextColor(ColorRGBA(1.0f, 0.0f, 0.0f));
TextRender()->Text(0, Position.x-PosHealth/2.0f, Position.y-Offset-HFontSize-AFontSize, HFontSize, aHealth, -1);
float PosArmor = TextRender()->TextWidth(0, AFontSize, aArmor, -1, -1.0f);
TextRender()->TextColor(ColorRGBA(1.0f, 1.0f, 0.0f));
TextRender()->Text(0, Position.x-PosArmor/2.0f, Position.y-Offset-AFontSize-3.0f, AFontSize, aArmor, -1);
}
}
TextRender()->TextColor(1,1,1,1);
TextRender()->TextOutlineColor(0.0f, 0.0f, 0.0f, 0.3f);

View file

@ -23,6 +23,8 @@ MACRO_CONFIG_INT(ClNameplatesSize, cl_nameplates_size, 50, 0, 100, CFGFLAG_CLIEN
MACRO_CONFIG_INT(ClNameplatesClan, cl_nameplates_clan, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show clan in name plates")
MACRO_CONFIG_INT(ClNameplatesClanSize, cl_nameplates_clan_size, 30, 0, 100, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Size of the clan plates from 0 to 100%")
MACRO_CONFIG_INT(ClNameplatesIDs, cl_nameplates_ids, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show IDs in name plates")
MACRO_CONFIG_INT(ClNameplatesHA, cl_nameplates_ha, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show Health and Armor in name plates")
MACRO_CONFIG_INT(ClNameplatesHASize, cl_nameplates_ha_size, 50, 0, 100, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Size of the health and armor nameplates from 0 to 100%")
MACRO_CONFIG_INT(ClNameplatesOwn, cl_nameplates_own, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show own name plate (useful for demo recording)")
MACRO_CONFIG_INT(ClTextEntities, cl_text_entities, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Render textual entity data")
MACRO_CONFIG_INT(ClTextEntitiesSize, cl_text_entities_size, 100, 0, 100, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Size of textual entity data from 0 to 100%")