ddnet/src/game/client/components/killmessages.cpp

142 lines
4.2 KiB
C++
Raw Normal View History

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>
2010-05-29 07:25:38 +00:00
#include <game/client/gameclient.h>
#include <game/client/animstate.h>
#include "killmessages.h"
2010-05-29 07:25:38 +00:00
void CKillMessages::OnReset()
{
2010-05-29 07:25:38 +00:00
m_KillmsgCurrent = 0;
for(int i = 0; i < MAX_KILLMSGS; i++)
m_aKillmsgs[i].m_Tick = -100000;
}
2010-05-29 07:25:38 +00:00
void CKillMessages::OnMessage(int MsgType, void *pRawMsg)
{
2010-05-29 07:25:38 +00:00
if(MsgType == NETMSGTYPE_SV_KILLMSG)
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_KillMsg *pMsg = (CNetMsg_Sv_KillMsg *)pRawMsg;
// unpack messages
2010-05-29 07:25:38 +00:00
CKillMsg Kill;
Kill.m_VictimID = pMsg->m_Victim;
Kill.m_VictimTeam = m_pClient->m_aClients[Kill.m_VictimID].m_Team;
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;
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;
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();
// add the message
2010-05-29 07:25:38 +00:00
m_KillmsgCurrent = (m_KillmsgCurrent+1)%MAX_KILLMSGS;
m_aKillmsgs[m_KillmsgCurrent] = Kill;
}
}
2010-05-29 07:25:38 +00:00
void CKillMessages::OnRender()
{
2010-05-29 07:25:38 +00:00
float Width = 400*3.0f*Graphics()->ScreenAspect();
float Height = 400*3.0f;
2010-05-29 07:25:38 +00:00
Graphics()->MapScreen(0, 0, Width*1.5f, Height*1.5f);
float StartX = Width*1.5f-10.0f;
float y = 20.0f;
2010-05-29 07:25:38 +00:00
for(int i = 0; i < MAX_KILLMSGS; i++)
{
2010-05-29 07:25:38 +00:00
int r = (m_KillmsgCurrent+i+1)%MAX_KILLMSGS;
if(Client()->GameTick() > m_aKillmsgs[r].m_Tick+50*10)
continue;
2010-05-29 07:25:38 +00:00
float FontSize = 36.0f;
float KillerNameW = TextRender()->TextWidth(0, FontSize, m_aKillmsgs[r].m_aKillerName, -1);
float VictimNameW = TextRender()->TextWidth(0, FontSize, m_aKillmsgs[r].m_aVictimName, -1);
2010-05-29 07:25:38 +00:00
float x = StartX;
// render victim name
2010-05-29 07:25:38 +00:00
x -= VictimNameW;
TextRender()->Text(0, x, y, FontSize, m_aKillmsgs[r].m_aVictimName, -1);
// render victim tee
x -= 24.0f;
2010-05-29 07:25:38 +00:00
if(m_pClient->m_Snap.m_pGameobj && m_pClient->m_Snap.m_pGameobj->m_Flags&GAMEFLAG_FLAGS)
{
2010-05-29 07:25:38 +00:00
if(m_aKillmsgs[r].m_ModeSpecial&1)
{
2009-10-27 14:38:53 +00:00
Graphics()->BlendNormal();
2010-05-29 07:25:38 +00:00
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsBegin();
if(m_aKillmsgs[r].m_VictimTeam == 0)
RenderTools()->SelectSprite(SPRITE_FLAG_BLUE);
else
RenderTools()->SelectSprite(SPRITE_FLAG_RED);
2010-05-29 07:25:38 +00:00
float Size = 56.0f;
IGraphics::CQuadItem QuadItem(x, y-16, Size/2, Size);
Graphics()->QuadsDrawTL(&QuadItem, 1);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
}
}
RenderTools()->RenderTee(CAnimState::GetIdle(), &m_aKillmsgs[r].m_VictimRenderInfo, EMOTE_PAIN, vec2(-1,0), vec2(x, y+28));
x -= 32.0f;
// render weapon
x -= 44.0f;
2010-05-29 07:25:38 +00:00
if (m_aKillmsgs[r].m_Weapon >= 0)
{
2010-05-29 07:25:38 +00:00
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsBegin();
2010-05-29 07:25:38 +00:00
RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[m_aKillmsgs[r].m_Weapon].m_pSpriteBody);
RenderTools()->DrawSprite(x, y+28, 96);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
}
x -= 52.0f;
if(m_aKillmsgs[r].m_VictimID != m_aKillmsgs[r].m_KillerID)
{
2010-05-29 07:25:38 +00:00
if(m_pClient->m_Snap.m_pGameobj && m_pClient->m_Snap.m_pGameobj->m_Flags&GAMEFLAG_FLAGS)
{
2010-05-29 07:25:38 +00:00
if(m_aKillmsgs[r].m_ModeSpecial&2)
{
2009-10-27 14:38:53 +00:00
Graphics()->BlendNormal();
2010-05-29 07:25:38 +00:00
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsBegin();
if(m_aKillmsgs[r].m_KillerTeam == 0)
RenderTools()->SelectSprite(SPRITE_FLAG_BLUE, SPRITE_FLAG_FLIP_X);
else
RenderTools()->SelectSprite(SPRITE_FLAG_RED, SPRITE_FLAG_FLIP_X);
2010-05-29 07:25:38 +00:00
float Size = 56.0f;
IGraphics::CQuadItem QuadItem(x-56, y-16, Size/2, Size);
Graphics()->QuadsDrawTL(&QuadItem, 1);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
}
}
// render killer tee
x -= 24.0f;
RenderTools()->RenderTee(CAnimState::GetIdle(), &m_aKillmsgs[r].m_KillerRenderInfo, EMOTE_ANGRY, vec2(1,0), vec2(x, y+28));
x -= 32.0f;
// render killer name
2010-05-29 07:25:38 +00:00
x -= KillerNameW;
TextRender()->Text(0, x, y, FontSize, m_aKillmsgs[r].m_aKillerName, -1);
}
y += 44;
}
}