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>
|
2020-09-26 19:41:58 +00:00
|
|
|
#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
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <game/generated/protocol.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/client/gameclient.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2011-01-17 12:46:59 +00:00
|
|
|
#include <game/client/components/motd.h>
|
2011-01-12 00:18:07 +00:00
|
|
|
#include <game/client/components/scoreboard.h>
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "broadcast.h"
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CBroadcast::OnReset()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2019-04-02 21:28:10 +00:00
|
|
|
m_BroadcastTick = 0;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CBroadcast::OnRender()
|
2023-05-06 08:26:52 +00:00
|
|
|
{
|
2023-05-06 08:28:13 +00:00
|
|
|
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
|
|
|
return;
|
|
|
|
|
2023-05-06 08:26:52 +00:00
|
|
|
RenderServerBroadcast();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBroadcast::RenderServerBroadcast()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2021-07-12 09:43:56 +00:00
|
|
|
if(m_pClient->m_Scoreboard.Active() || m_pClient->m_Motd.IsActive() || !g_Config.m_ClShowBroadcasts)
|
2011-01-12 00:18:07 +00:00
|
|
|
return;
|
|
|
|
|
2023-05-06 08:39:06 +00:00
|
|
|
const float Height = 300.0f;
|
|
|
|
const float Width = Height * Graphics()->ScreenAspect();
|
|
|
|
Graphics()->MapScreen(0.0f, 0.0f, Width, Height);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-02-19 10:24:58 +00:00
|
|
|
if(Client()->GameTick(g_Config.m_ClDummy) < m_BroadcastTick)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-12-16 02:17:16 +00:00
|
|
|
CTextCursor Cursor;
|
2020-09-26 19:41:58 +00:00
|
|
|
TextRender()->SetCursor(&Cursor, m_BroadcastRenderOffset, 40.0f, 12.0f, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
|
2023-05-06 08:39:06 +00:00
|
|
|
Cursor.m_LineWidth = Width - m_BroadcastRenderOffset;
|
2010-12-16 02:17:16 +00:00
|
|
|
TextRender()->TextEx(&Cursor, m_aBroadcastText, -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CBroadcast::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_BROADCAST)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2023-05-06 08:25:09 +00:00
|
|
|
OnBroadcastMessage((CNetMsg_Sv_Broadcast *)pRawMsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBroadcast::OnBroadcastMessage(const CNetMsg_Sv_Broadcast *pMsg)
|
|
|
|
{
|
2023-05-06 08:39:06 +00:00
|
|
|
const float Height = 300.0f;
|
|
|
|
const float Width = Height * Graphics()->ScreenAspect();
|
|
|
|
Graphics()->MapScreen(0.0f, 0.0f, Width, Height);
|
|
|
|
|
2023-05-06 08:25:09 +00:00
|
|
|
str_copy(m_aBroadcastText, pMsg->m_pMessage);
|
2023-05-06 08:39:06 +00:00
|
|
|
m_BroadcastRenderOffset = Width / 2.0f - TextRender()->TextWidth(12.0f, m_aBroadcastText, -1, Width, TEXTFLAG_STOP_AT_END) / 2.0f;
|
2023-05-06 08:25:09 +00:00
|
|
|
m_BroadcastTick = Client()->GameTick(g_Config.m_ClDummy) + Client()->GameTickSpeed() * 10;
|
2023-05-06 12:22:40 +00:00
|
|
|
|
2023-05-06 08:25:09 +00:00
|
|
|
if(g_Config.m_ClPrintBroadcasts)
|
|
|
|
{
|
2023-05-06 12:22:40 +00:00
|
|
|
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
|
|
|
{
|
2023-05-06 12:22:40 +00:00
|
|
|
if(aLine[0] != '\0')
|
2014-09-23 17:06:25 +00:00
|
|
|
{
|
2023-05-06 12:22:40 +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
|
|
|
}
|
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|