2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/graphics.h>
|
|
|
|
#include <engine/textrender.h>
|
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/generated/client_data.h>
|
2014-01-15 14:25:13 +00:00
|
|
|
#include <engine/shared/config.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/client/gameclient.h>
|
|
|
|
#include <game/client/animstate.h>
|
|
|
|
#include "killmessages.h"
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2018-03-21 14:53:29 +00:00
|
|
|
void CKillMessages::OnWindowResize()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < MAX_KILLMSGS; i++)
|
|
|
|
{
|
|
|
|
if(m_aKillmsgs[i].m_VictimTextContainerIndex != -1)
|
|
|
|
TextRender()->DeleteTextContainer(m_aKillmsgs[i].m_VictimTextContainerIndex);
|
|
|
|
if(m_aKillmsgs[i].m_KillerTextContainerIndex != -1)
|
|
|
|
TextRender()->DeleteTextContainer(m_aKillmsgs[i].m_KillerTextContainerIndex);
|
|
|
|
m_aKillmsgs[i].m_VictimTextContainerIndex = m_aKillmsgs[i].m_KillerTextContainerIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CKillMessages::OnReset()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_KillmsgCurrent = 0;
|
2018-03-21 14:53:29 +00:00
|
|
|
for (int i = 0; i < MAX_KILLMSGS; i++)
|
2018-03-13 20:55:47 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_aKillmsgs[i].m_Tick = -100000;
|
2018-03-13 20:55:47 +00:00
|
|
|
|
|
|
|
if(m_aKillmsgs[i].m_VictimTextContainerIndex != -1)
|
|
|
|
TextRender()->DeleteTextContainer(m_aKillmsgs[i].m_VictimTextContainerIndex);
|
|
|
|
|
|
|
|
if(m_aKillmsgs[i].m_KillerTextContainerIndex != -1)
|
|
|
|
TextRender()->DeleteTextContainer(m_aKillmsgs[i].m_KillerTextContainerIndex);
|
|
|
|
|
|
|
|
|
|
|
|
m_aKillmsgs[i].m_VictimTextContainerIndex = m_aKillmsgs[i].m_KillerTextContainerIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKillMessages::OnInit()
|
|
|
|
{
|
|
|
|
Graphics()->SetColor(1.f, 1.f, 1.f, 1.f);
|
|
|
|
m_SpriteQuadContainerIndex = Graphics()->CreateQuadContainer();
|
|
|
|
|
|
|
|
RenderTools()->SelectSprite(SPRITE_FLAG_RED);
|
|
|
|
RenderTools()->QuadContainerAddSprite(m_SpriteQuadContainerIndex, 0.f, 0.f, 28.f, 56.f);
|
|
|
|
RenderTools()->SelectSprite(SPRITE_FLAG_BLUE);
|
|
|
|
RenderTools()->QuadContainerAddSprite(m_SpriteQuadContainerIndex, 0.f, 0.f, 28.f, 56.f);
|
|
|
|
|
|
|
|
RenderTools()->SelectSprite(SPRITE_FLAG_RED, SPRITE_FLAG_FLIP_X);
|
|
|
|
RenderTools()->QuadContainerAddSprite(m_SpriteQuadContainerIndex, 0.f, 0.f, 28.f, 56.f);
|
|
|
|
RenderTools()->SelectSprite(SPRITE_FLAG_BLUE, SPRITE_FLAG_FLIP_X);
|
|
|
|
RenderTools()->QuadContainerAddSprite(m_SpriteQuadContainerIndex, 0.f, 0.f, 28.f, 56.f);
|
|
|
|
|
|
|
|
for(int i = 0; i < NUM_WEAPONS; ++i)
|
|
|
|
{
|
|
|
|
RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[i].m_pSpriteBody);
|
|
|
|
RenderTools()->QuadContainerAddSprite(m_SpriteQuadContainerIndex, 96.f);
|
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CKillMessages::OnMessage(int MsgType, void *pRawMsg)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(MsgType == NETMSGTYPE_SV_KILLMSG)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetMsg_Sv_KillMsg *pMsg = (CNetMsg_Sv_KillMsg *)pRawMsg;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
// unpack messages
|
2010-05-29 07:25:38 +00:00
|
|
|
CKillMsg Kill;
|
2010-06-06 13:38:03 +00:00
|
|
|
Kill.m_VictimID = pMsg->m_Victim;
|
|
|
|
Kill.m_VictimTeam = m_pClient->m_aClients[Kill.m_VictimID].m_Team;
|
2015-04-12 13:19:47 +00:00
|
|
|
Kill.m_VictimDDTeam = m_pClient->m_Teams.Team(Kill.m_VictimID);
|
2010-06-06 13:38:03 +00:00
|
|
|
str_copy(Kill.m_aVictimName, m_pClient->m_aClients[Kill.m_VictimID].m_aName, sizeof(Kill.m_aVictimName));
|
|
|
|
Kill.m_VictimRenderInfo = m_pClient->m_aClients[Kill.m_VictimID].m_RenderInfo;
|
2019-07-29 14:36:44 +00:00
|
|
|
|
2010-06-06 13:38:03 +00:00
|
|
|
Kill.m_KillerID = pMsg->m_Killer;
|
|
|
|
Kill.m_KillerTeam = m_pClient->m_aClients[Kill.m_KillerID].m_Team;
|
|
|
|
str_copy(Kill.m_aKillerName, m_pClient->m_aClients[Kill.m_KillerID].m_aName, sizeof(Kill.m_aKillerName));
|
|
|
|
Kill.m_KillerRenderInfo = m_pClient->m_aClients[Kill.m_KillerID].m_RenderInfo;
|
2019-07-29 14:36:44 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Kill.m_Weapon = pMsg->m_Weapon;
|
|
|
|
Kill.m_ModeSpecial = pMsg->m_ModeSpecial;
|
|
|
|
Kill.m_Tick = Client()->GameTick();
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2019-07-29 14:36:44 +00:00
|
|
|
Kill.m_FlagCarrierBlue = m_pClient->m_Snap.m_pGameDataObj ? m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierBlue : -1;
|
|
|
|
|
2018-03-13 20:55:47 +00:00
|
|
|
Kill.m_VitctimTextWidth = Kill.m_KillerTextWidth = 0.f;
|
|
|
|
|
|
|
|
float Width = 400 * 3.0f*Graphics()->ScreenAspect();
|
|
|
|
float Height = 400 * 3.0f;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
CTextCursor Cursor;
|
|
|
|
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_RENDER);
|
|
|
|
Cursor.m_LineWidth = -1;
|
|
|
|
|
|
|
|
Kill.m_KillerTextContainerIndex = TextRender()->CreateTextContainer(&Cursor, Kill.m_aKillerName);
|
|
|
|
}
|
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
// add the message
|
2010-05-29 07:25:38 +00:00
|
|
|
m_KillmsgCurrent = (m_KillmsgCurrent+1)%MAX_KILLMSGS;
|
2018-03-13 20:55:47 +00:00
|
|
|
|
|
|
|
if(m_aKillmsgs[m_KillmsgCurrent].m_VictimTextContainerIndex != -1)
|
|
|
|
{
|
|
|
|
TextRender()->DeleteTextContainer(m_aKillmsgs[m_KillmsgCurrent].m_VictimTextContainerIndex);
|
|
|
|
m_aKillmsgs[m_KillmsgCurrent].m_VictimTextContainerIndex = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_aKillmsgs[m_KillmsgCurrent].m_KillerTextContainerIndex != -1)
|
|
|
|
{
|
|
|
|
TextRender()->DeleteTextContainer(m_aKillmsgs[m_KillmsgCurrent].m_KillerTextContainerIndex);
|
|
|
|
m_aKillmsgs[m_KillmsgCurrent].m_KillerTextContainerIndex = -1;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_aKillmsgs[m_KillmsgCurrent] = Kill;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CKillMessages::OnRender()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2018-03-13 20:55:47 +00:00
|
|
|
if(!g_Config.m_ClShowKillMessages)
|
2014-01-15 14:25:13 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float Width = 400*3.0f*Graphics()->ScreenAspect();
|
|
|
|
float Height = 400*3.0f;
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Graphics()->MapScreen(0, 0, Width*1.5f, Height*1.5f);
|
2018-03-13 20:55:47 +00:00
|
|
|
Graphics()->SetColor(1.f, 1.f, 1.f, 1.f);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float StartX = Width*1.5f-10.0f;
|
2017-10-20 20:27:53 +00:00
|
|
|
float y = 30.0f + 100.0f * ((g_Config.m_ClShowfps ? 1 : 0) + g_Config.m_ClShowpred);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-12-25 22:43:05 +00:00
|
|
|
for(int i = 1; i <= MAX_KILLMSGS; i++)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-12-25 22:43:05 +00:00
|
|
|
int r = (m_KillmsgCurrent+i)%MAX_KILLMSGS;
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Client()->GameTick() > m_aKillmsgs[r].m_Tick+50*10)
|
2008-08-27 15:48:50 +00:00
|
|
|
continue;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float x = StartX;
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2018-03-13 20:55:47 +00:00
|
|
|
STextRenderColor TColor(1.f, 1.f, 1.f, 1.f);
|
|
|
|
STextRenderColor TOutlineColor(0.f, 0.f, 0.f, 0.3f);
|
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
// render victim name
|
2018-03-13 20:55:47 +00:00
|
|
|
x -= m_aKillmsgs[r].m_VitctimTextWidth;
|
2015-04-12 13:19:47 +00:00
|
|
|
if(m_aKillmsgs[r].m_VictimID >= 0 && g_Config.m_ClChatTeamColors && m_aKillmsgs[r].m_VictimDDTeam)
|
|
|
|
{
|
2019-04-26 12:06:32 +00:00
|
|
|
ColorRGBA rgb = color_cast<ColorRGBA>(ColorHSLA(m_aKillmsgs[r].m_VictimDDTeam / 64.0f, 1.0f, 0.75f));
|
2019-07-08 21:08:42 +00:00
|
|
|
TColor.Set(rgb.r, rgb.g, rgb.b, 1.0f);
|
2015-04-12 13:19:47 +00:00
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2018-03-13 20:55:47 +00:00
|
|
|
if(m_aKillmsgs[r].m_VictimTextContainerIndex != -1)
|
2018-04-11 10:19:30 +00:00
|
|
|
TextRender()->RenderTextContainer(m_aKillmsgs[r].m_VictimTextContainerIndex, &TColor, &TOutlineColor, x, y + (46.f - 36.f) / 2.f);
|
2019-04-26 12:06:32 +00:00
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
// render victim tee
|
|
|
|
x -= 24.0f;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-04 16:08:10 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_FLAGS)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_aKillmsgs[r].m_ModeSpecial&1)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
|
2018-03-13 20:55:47 +00:00
|
|
|
int QuadOffset = 0;
|
2019-07-29 14:36:44 +00:00
|
|
|
if(m_aKillmsgs[r].m_VictimID == m_aKillmsgs[r].m_FlagCarrierBlue)
|
2018-03-13 20:55:47 +00:00
|
|
|
++QuadOffset;
|
|
|
|
|
|
|
|
Graphics()->RenderQuadContainerAsSprite(m_SpriteQuadContainerIndex, QuadOffset, x, y-16);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-06-06 13:38:03 +00:00
|
|
|
RenderTools()->RenderTee(CAnimState::GetIdle(), &m_aKillmsgs[r].m_VictimRenderInfo, EMOTE_PAIN, vec2(-1,0), vec2(x, y+28));
|
2008-08-27 15:48:50 +00:00
|
|
|
x -= 32.0f;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
// render weapon
|
|
|
|
x -= 44.0f;
|
2018-03-13 20:55:47 +00:00
|
|
|
if(m_aKillmsgs[r].m_Weapon >= 0)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
|
2018-03-13 20:55:47 +00:00
|
|
|
Graphics()->RenderQuadContainerAsSprite(m_SpriteQuadContainerIndex, 4 + m_aKillmsgs[r].m_Weapon, x, y + 28);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
x -= 52.0f;
|
|
|
|
|
2010-06-06 13:38:03 +00:00
|
|
|
if(m_aKillmsgs[r].m_VictimID != m_aKillmsgs[r].m_KillerID)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-03-04 16:08:10 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_FLAGS)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_aKillmsgs[r].m_ModeSpecial&2)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2018-03-13 20:55:47 +00:00
|
|
|
int QuadOffset = 2;
|
2019-07-29 14:36:44 +00:00
|
|
|
if(m_aKillmsgs[r].m_KillerID == m_aKillmsgs[r].m_FlagCarrierBlue)
|
2018-03-13 20:55:47 +00:00
|
|
|
++QuadOffset;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2018-03-13 20:55:47 +00:00
|
|
|
Graphics()->RenderQuadContainerAsSprite(m_SpriteQuadContainerIndex, QuadOffset, x - 56, y - 16);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
}
|
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
// render killer tee
|
|
|
|
x -= 24.0f;
|
2010-06-06 13:38:03 +00:00
|
|
|
RenderTools()->RenderTee(CAnimState::GetIdle(), &m_aKillmsgs[r].m_KillerRenderInfo, EMOTE_ANGRY, vec2(1,0), vec2(x, y+28));
|
2008-08-27 15:48:50 +00:00
|
|
|
x -= 32.0f;
|
|
|
|
|
|
|
|
// render killer name
|
2018-03-13 20:55:47 +00:00
|
|
|
x -= m_aKillmsgs[r].m_KillerTextWidth;
|
|
|
|
|
|
|
|
if(m_aKillmsgs[r].m_KillerTextContainerIndex != -1)
|
2018-04-11 10:19:30 +00:00
|
|
|
TextRender()->RenderTextContainer(m_aKillmsgs[r].m_KillerTextContainerIndex, &TColor, &TOutlineColor, x, y + (46.f - 36.f) / 2.f);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2011-04-02 18:14:57 +00:00
|
|
|
y += 46.0f;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|