Recreate kill messages if required

This commit is contained in:
Jupeyy 2020-12-13 01:08:34 +01:00
parent 13762aa197
commit bae42b9284
2 changed files with 33 additions and 22 deletions

View file

@ -63,6 +63,32 @@ void CKillMessages::OnInit()
} }
} }
void CKillMessages::CreateKillmessageNamesIfNotCreated(CKillMsg &Kill)
{
const float FontSize = 36.0f;
if(Kill.m_VictimTextContainerIndex == -1 && Kill.m_aVictimName[0] != 0)
{
Kill.m_VitctimTextWidth = TextRender()->TextWidth(0, FontSize, Kill.m_aVictimName, -1, -1.0f);
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_RENDER);
Cursor.m_LineWidth = -1;
Kill.m_VictimTextContainerIndex = TextRender()->CreateTextContainer(&Cursor, Kill.m_aVictimName);
}
if(Kill.m_KillerTextContainerIndex == -1 && Kill.m_aKillerName[0] != 0)
{
Kill.m_KillerTextWidth = TextRender()->TextWidth(0, FontSize, Kill.m_aKillerName, -1, -1.0f);
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_RENDER);
Cursor.m_LineWidth = -1;
Kill.m_KillerTextContainerIndex = TextRender()->CreateTextContainer(&Cursor, Kill.m_aKillerName);
}
}
void CKillMessages::OnMessage(int MsgType, void *pRawMsg) void CKillMessages::OnMessage(int MsgType, void *pRawMsg)
{ {
if(MsgType == NETMSGTYPE_SV_KILLMSG) if(MsgType == NETMSGTYPE_SV_KILLMSG)
@ -97,28 +123,7 @@ void CKillMessages::OnMessage(int MsgType, void *pRawMsg)
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
Graphics()->MapScreen(0, 0, Width * 1.5f, Height * 1.5f); Graphics()->MapScreen(0, 0, Width * 1.5f, Height * 1.5f);
float FontSize = 36.0f; CreateKillmessageNamesIfNotCreated(Kill);
if(Kill.m_aVictimName[0] != 0)
{
Kill.m_VitctimTextWidth = TextRender()->TextWidth(0, FontSize, Kill.m_aVictimName, -1, -1.0f);
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_RENDER);
Cursor.m_LineWidth = -1;
Kill.m_VictimTextContainerIndex = TextRender()->CreateTextContainer(&Cursor, Kill.m_aVictimName);
}
if(Kill.m_aKillerName[0] != 0)
{
Kill.m_KillerTextWidth = TextRender()->TextWidth(0, FontSize, Kill.m_aKillerName, -1, -1.0f);
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_RENDER);
Cursor.m_LineWidth = -1;
Kill.m_KillerTextContainerIndex = TextRender()->CreateTextContainer(&Cursor, Kill.m_aKillerName);
}
// add the message // add the message
m_KillmsgCurrent = (m_KillmsgCurrent + 1) % MAX_KILLMSGS; m_KillmsgCurrent = (m_KillmsgCurrent + 1) % MAX_KILLMSGS;
@ -173,6 +178,8 @@ void CKillMessages::OnRender()
TColor.Set(rgb.r, rgb.g, rgb.b, 1.0f); TColor.Set(rgb.r, rgb.g, rgb.b, 1.0f);
} }
CreateKillmessageNamesIfNotCreated(m_aKillmsgs[r]);
if(m_aKillmsgs[r].m_VictimTextContainerIndex != -1) if(m_aKillmsgs[r].m_VictimTextContainerIndex != -1)
TextRender()->RenderTextContainer(m_aKillmsgs[r].m_VictimTextContainerIndex, &TColor, &TOutlineColor, x, y + (46.f - 36.f) / 2.f); TextRender()->RenderTextContainer(m_aKillmsgs[r].m_VictimTextContainerIndex, &TColor, &TOutlineColor, x, y + (46.f - 36.f) / 2.f);

View file

@ -44,6 +44,10 @@ public:
MAX_KILLMSGS = 5, MAX_KILLMSGS = 5,
}; };
private:
void CreateKillmessageNamesIfNotCreated(CKillMsg &Kill);
public:
CKillMsg m_aKillmsgs[MAX_KILLMSGS]; CKillMsg m_aKillmsgs[MAX_KILLMSGS];
int m_KillmsgCurrent; int m_KillmsgCurrent;