mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-14 03:58:18 +00:00
72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
/* (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. */
|
|
#include <engine/shared/config.h>
|
|
#include <engine/graphics.h>
|
|
#include <engine/textrender.h>
|
|
#include <game/generated/protocol.h>
|
|
#include <game/generated/client_data.h>
|
|
|
|
#include <game/client/gameclient.h>
|
|
|
|
#include <game/client/components/motd.h>
|
|
#include <game/client/components/scoreboard.h>
|
|
|
|
#include "broadcast.h"
|
|
|
|
void CBroadcast::OnReset()
|
|
{
|
|
m_BroadcastTime = 0;
|
|
}
|
|
|
|
void CBroadcast::OnRender()
|
|
{
|
|
if(m_pClient->m_pScoreboard->Active() || m_pClient->m_pMotd->IsActive())
|
|
return;
|
|
|
|
Graphics()->MapScreen(0, 0, 300*Graphics()->ScreenAspect(), 300);
|
|
|
|
if(time_get() < m_BroadcastTime)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
void CBroadcast::OnMessage(int MsgType, void *pRawMsg)
|
|
{
|
|
if(MsgType == NETMSGTYPE_SV_BROADCAST)
|
|
{
|
|
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_BroadcastTime = time_get()+time_freq()*10;
|
|
if (g_Config.m_ClPrintBroadcasts)
|
|
{
|
|
char aBuf[1024];
|
|
int i, ii;
|
|
for (i = 0, ii = 0; i < str_length(m_aBroadcastText); i++)
|
|
{
|
|
if (m_aBroadcastText[i] == '\n')
|
|
{
|
|
aBuf[ii] = '\0';
|
|
ii = 0;
|
|
m_pClient->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "broadcast", aBuf, true);
|
|
}
|
|
else
|
|
{
|
|
aBuf[ii] = m_aBroadcastText[i];
|
|
ii++;
|
|
}
|
|
}
|
|
aBuf[ii] = '\0';
|
|
m_pClient->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "broadcast", aBuf, true);
|
|
}
|
|
}
|
|
}
|