3406: Recreate kill messages if required r=def- a=Jupeyy

fixes #3125

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2020-12-13 10:11:09 +00:00 committed by GitHub
commit 79fb5dd7fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;