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

74 lines
2.4 KiB
C++
Raw Normal View History

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/shared/config.h>
2010-05-29 07:25:38 +00:00
#include <engine/textrender.h>
#include <game/generated/client_data.h>
#include <game/generated/protocol.h>
2010-05-29 07:25:38 +00:00
#include <game/client/gameclient.h>
#include <game/client/components/motd.h>
#include <game/client/components/scoreboard.h>
2010-05-29 07:25:38 +00:00
#include "broadcast.h"
2010-05-29 07:25:38 +00:00
void CBroadcast::OnReset()
{
m_BroadcastTick = 0;
}
2010-05-29 07:25:38 +00:00
void CBroadcast::OnRender()
{
if(m_pClient->m_pScoreboard->Active() || m_pClient->m_pMotd->IsActive() || !g_Config.m_ClShowBroadcasts)
return;
Graphics()->MapScreen(0, 0, 300 * Graphics()->ScreenAspect(), 300);
if(Client()->GameTick(g_Config.m_ClDummy) < m_BroadcastTick)
{
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, m_BroadcastRenderOffset, 40.0f, 12.0f, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = 300 * Graphics()->ScreenAspect() - m_BroadcastRenderOffset;
TextRender()->TextEx(&Cursor, m_aBroadcastText, -1);
}
}
2010-05-29 07:25:38 +00:00
void CBroadcast::OnMessage(int MsgType, void *pRawMsg)
{
2010-05-29 07:25:38 +00:00
if(MsgType == NETMSGTYPE_SV_BROADCAST)
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_Broadcast *pMsg = (CNetMsg_Sv_Broadcast *)pRawMsg;
str_copy(m_aBroadcastText, pMsg->m_pMessage, sizeof(m_aBroadcastText));
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, 0, 0, 12.0f, TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = 300 * Graphics()->ScreenAspect();
TextRender()->TextEx(&Cursor, m_aBroadcastText, -1);
m_BroadcastRenderOffset = 150 * Graphics()->ScreenAspect() - Cursor.m_X / 2;
m_BroadcastTick = Client()->GameTick(g_Config.m_ClDummy) + Client()->GameTickSpeed() * 10;
if(g_Config.m_ClPrintBroadcasts)
2014-09-23 17:06:25 +00:00
{
char aBuf[1024];
int i, ii;
for(i = 0, ii = 0; i < str_length(m_aBroadcastText); i++)
2014-09-23 17:06:25 +00:00
{
if(m_aBroadcastText[i] == '\n')
2014-09-23 17:06:25 +00:00
{
aBuf[ii] = '\0';
ii = 0;
if(aBuf[0])
2021-03-08 00:08:38 +00:00
m_pClient->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "broadcast", aBuf, color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClMessageHighlightColor)));
2014-09-23 17:06:25 +00:00
}
else
{
aBuf[ii] = m_aBroadcastText[i];
ii++;
}
}
aBuf[ii] = '\0';
if(aBuf[0])
2021-03-08 00:08:38 +00:00
m_pClient->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "broadcast", aBuf, color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClMessageHighlightColor)));
2014-09-23 17:06:25 +00:00
}
}
}