mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Fade out broadcast in last second, use text container
Fade the broadcast alpha to zero in the last second that the broadcast is shown. Use text container to support the fade out and to make broadcast rendering more efficient.
This commit is contained in:
parent
74c1f38ca0
commit
5c78093da4
|
@ -16,6 +16,12 @@
|
|||
void CBroadcast::OnReset()
|
||||
{
|
||||
m_BroadcastTick = 0;
|
||||
TextRender()->DeleteTextContainer(m_TextContainerIndex);
|
||||
}
|
||||
|
||||
void CBroadcast::OnWindowResize()
|
||||
{
|
||||
TextRender()->DeleteTextContainer(m_TextContainerIndex);
|
||||
}
|
||||
|
||||
void CBroadcast::OnRender()
|
||||
|
@ -30,17 +36,32 @@ void CBroadcast::RenderServerBroadcast()
|
|||
{
|
||||
if(m_pClient->m_Scoreboard.Active() || m_pClient->m_Motd.IsActive() || !g_Config.m_ClShowBroadcasts)
|
||||
return;
|
||||
const float SecondsRemaining = (m_BroadcastTick - Client()->GameTick(g_Config.m_ClDummy)) / (float)Client()->GameTickSpeed();
|
||||
if(SecondsRemaining <= 0.0f)
|
||||
{
|
||||
TextRender()->DeleteTextContainer(m_TextContainerIndex);
|
||||
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)
|
||||
if(!m_TextContainerIndex.Valid())
|
||||
{
|
||||
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);
|
||||
TextRender()->CreateTextContainer(m_TextContainerIndex, &Cursor, m_aBroadcastText);
|
||||
}
|
||||
if(m_TextContainerIndex.Valid())
|
||||
{
|
||||
const float Alpha = SecondsRemaining >= 1.0f ? 1.0f : SecondsRemaining;
|
||||
ColorRGBA TextColor = TextRender()->DefaultTextColor();
|
||||
TextColor.a *= Alpha;
|
||||
ColorRGBA OutlineColor = TextRender()->DefaultTextOutlineColor();
|
||||
OutlineColor.a *= Alpha;
|
||||
TextRender()->RenderTextContainer(m_TextContainerIndex, TextColor, OutlineColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +82,7 @@ void CBroadcast::OnBroadcastMessage(const CNetMsg_Sv_Broadcast *pMsg)
|
|||
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;
|
||||
TextRender()->DeleteTextContainer(m_TextContainerIndex);
|
||||
|
||||
if(g_Config.m_ClPrintBroadcasts)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef GAME_CLIENT_COMPONENTS_BROADCAST_H
|
||||
#define GAME_CLIENT_COMPONENTS_BROADCAST_H
|
||||
|
||||
#include <engine/textrender.h>
|
||||
|
||||
#include <game/client/component.h>
|
||||
|
||||
class CBroadcast : public CComponent
|
||||
|
@ -10,6 +13,7 @@ class CBroadcast : public CComponent
|
|||
char m_aBroadcastText[1024];
|
||||
int m_BroadcastTick;
|
||||
float m_BroadcastRenderOffset;
|
||||
STextContainerIndex m_TextContainerIndex;
|
||||
|
||||
void RenderServerBroadcast();
|
||||
void OnBroadcastMessage(const CNetMsg_Sv_Broadcast *pMsg);
|
||||
|
@ -17,6 +21,7 @@ class CBroadcast : public CComponent
|
|||
public:
|
||||
virtual int Sizeof() const override { return sizeof(*this); }
|
||||
virtual void OnReset() override;
|
||||
virtual void OnWindowResize() override;
|
||||
virtual void OnRender() override;
|
||||
virtual void OnMessage(int MsgType, void *pRawMsg) override;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue