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

78 lines
2.3 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>
2022-05-29 16:33:38 +00:00
#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(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
return;
RenderServerBroadcast();
}
void CBroadcast::RenderServerBroadcast()
{
2021-07-12 09:43:56 +00:00
if(m_pClient->m_Scoreboard.Active() || m_pClient->m_Motd.IsActive() || !g_Config.m_ClShowBroadcasts)
return;
const float Height = 300.0f;
const float Width = Height * Graphics()->ScreenAspect();
Graphics()->MapScreen(0.0f, 0.0f, Width, Height);
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 = Width - 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)
{
OnBroadcastMessage((CNetMsg_Sv_Broadcast *)pRawMsg);
}
}
void CBroadcast::OnBroadcastMessage(const CNetMsg_Sv_Broadcast *pMsg)
{
const float Height = 300.0f;
const float Width = Height * Graphics()->ScreenAspect();
Graphics()->MapScreen(0.0f, 0.0f, Width, Height);
str_copy(m_aBroadcastText, pMsg->m_pMessage);
m_BroadcastRenderOffset = Width / 2.0f - TextRender()->TextWidth(12.0f, m_aBroadcastText, -1, Width, TEXTFLAG_STOP_AT_END) / 2.0f;
m_BroadcastTick = Client()->GameTick(g_Config.m_ClDummy) + Client()->GameTickSpeed() * 10;
if(g_Config.m_ClPrintBroadcasts)
{
const char *pText = m_aBroadcastText;
char aLine[sizeof(m_aBroadcastText)];
while((pText = str_next_token(pText, "\n", aLine, sizeof(aLine))))
2014-09-23 17:06:25 +00:00
{
if(aLine[0] != '\0')
2014-09-23 17:06:25 +00:00
{
m_pClient->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "broadcast", aLine, color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClMessageHighlightColor)));
2014-09-23 17:06:25 +00:00
}
}
}
}