From bae42b9284852b47a393dcbee70452d0977b4e5e Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sun, 13 Dec 2020 01:08:34 +0100 Subject: [PATCH] Recreate kill messages if required --- src/game/client/components/killmessages.cpp | 51 ++++++++++++--------- src/game/client/components/killmessages.h | 4 ++ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/game/client/components/killmessages.cpp b/src/game/client/components/killmessages.cpp index 8ac49134c..8273ee0e0 100644 --- a/src/game/client/components/killmessages.cpp +++ b/src/game/client/components/killmessages.cpp @@ -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) { if(MsgType == NETMSGTYPE_SV_KILLMSG) @@ -97,28 +123,7 @@ void CKillMessages::OnMessage(int MsgType, void *pRawMsg) Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); Graphics()->MapScreen(0, 0, Width * 1.5f, Height * 1.5f); - float FontSize = 36.0f; - 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); - } + CreateKillmessageNamesIfNotCreated(Kill); // add the message m_KillmsgCurrent = (m_KillmsgCurrent + 1) % MAX_KILLMSGS; @@ -173,6 +178,8 @@ void CKillMessages::OnRender() TColor.Set(rgb.r, rgb.g, rgb.b, 1.0f); } + CreateKillmessageNamesIfNotCreated(m_aKillmsgs[r]); + if(m_aKillmsgs[r].m_VictimTextContainerIndex != -1) TextRender()->RenderTextContainer(m_aKillmsgs[r].m_VictimTextContainerIndex, &TColor, &TOutlineColor, x, y + (46.f - 36.f) / 2.f); diff --git a/src/game/client/components/killmessages.h b/src/game/client/components/killmessages.h index 5a29b8422..74c51c6c3 100644 --- a/src/game/client/components/killmessages.h +++ b/src/game/client/components/killmessages.h @@ -44,6 +44,10 @@ public: MAX_KILLMSGS = 5, }; +private: + void CreateKillmessageNamesIfNotCreated(CKillMsg &Kill); + +public: CKillMsg m_aKillmsgs[MAX_KILLMSGS]; int m_KillmsgCurrent;