Skip to content
This repository has been archived by the owner on Jun 26, 2019. It is now read-only.

Commit

Permalink
Server broadcast console only
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Dec 3, 2018
1 parent 62050bb commit 2f13fee
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 277 deletions.
2 changes: 1 addition & 1 deletion datasrc/languages
Submodule languages updated 36 files
+639 −383 belarusian.json
+1 −18 brazilian_portuguese.json
+0 −1,101 breton.json
+1 −8 bulgarian.json
+0 −1,101 catalan.json
+0 −1,101 chinese.json
+1 −1 chuvash.json
+622 −313 czech.json
+636 −385 dutch.json
+0 −1,101 esperanto.json
+0 −932 estonian.json
+588 −415 finnish.json
+622 −510 french.json
+10 −10 gaelic_scottish.json
+0 −1,101 galician.json
+353 −415 german.json
+600 −344 greek.json
+642 −519 hungarian.json
+0 −45 index.json
+0 −1,101 irish.json
+609 −353 italian.json
+608 −252 japanese.json
+436 −180 kyrgyz.json
+0 −1,237 lithuanian.json
+651 −535 norwegian.json
+682 −562 polish.json
+1 −10 portuguese.json
+619 −365 romanian.json
+1 −18 russian.json
+625 −370 serbian.json
+1 −4 simplified_chinese.json
+0 −1,101 slovenian.json
+1 −4 spanish.json
+606 −203 swedish.json
+626 −422 turkish.json
+2 −9 ukrainian.json
2 changes: 1 addition & 1 deletion datasrc/maps
284 changes: 11 additions & 273 deletions src/game/client/components/broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <generated/client_data.h>

#include <game/client/gameclient.h>
#include <stdio.h>

#include "broadcast.h"
#include "chat.h"
Expand Down Expand Up @@ -44,192 +45,16 @@ void CBroadcast::RenderServerBroadcast()
if(!g_Config.m_ClShowServerBroadcast || m_pClient->m_MuteServerBroadcast)
return;

const bool ColoredBroadcastEnabled = g_Config.m_ClColoredBroadcast;
const float Height = 300;
const float Width = Height*Graphics()->ScreenAspect();

const float DisplayDuration = 10.0f;
const float DisplayStartFade = 9.0f;
const float DeltaTime = Client()->LocalTime() - m_SrvBroadcastReceivedTime;

if(m_aSrvBroadcastMsg[0] == 0 || DeltaTime > DisplayDuration)
if(m_aSrvBroadcastMsg[0] == 0)
return;

if(m_pClient->m_pChat->IsActive() || m_pClient->Client()->State() != IClient::STATE_ONLINE)
if(m_pClient->m_pChat->IsActive())
return;

const float Fade = 1.0f - max(0.0f, (DeltaTime - DisplayStartFade) / (DisplayDuration - DisplayStartFade));

CUIRect ScreenRect = {0, 0, Width, Height};

CUIRect BcView = ScreenRect;
BcView.x += Width * 0.25f;
BcView.y += Height * 0.8f;
BcView.w *= 0.5f;
BcView.h *= 0.2f;

vec4 ColorTop(0, 0, 0, 0);
vec4 ColorBot(0, 0, 0, 0.4f * Fade);
CUIRect BgRect;
BcView.HSplitBottom(10.0f, 0, &BgRect);
BcView.HSplitBottom(6.0f, &BcView, 0);

// draw bottom bar
const float CornerWidth = 10.0f;
const float CornerHeight = BgRect.h;
BgRect.VMargin(CornerWidth, &BgRect);

Graphics()->TextureClear();
Graphics()->QuadsBegin();

// make round corners
enum { CORNER_MAX_QUADS=4 };
IGraphics::CFreeformItem LeftCornerQuads[CORNER_MAX_QUADS];
IGraphics::CFreeformItem RightCornerQuads[CORNER_MAX_QUADS];
const float AngleStep = (pi * 0.5f)/(CORNER_MAX_QUADS * 2);

for(int q = 0; q < CORNER_MAX_QUADS; q++)
{
const float Angle = AngleStep * q * 2;
const float ca = cosf(Angle);
const float ca1 = cosf(Angle + AngleStep);
const float ca2 = cosf(Angle + AngleStep * 2);
const float sa = sinf(Angle);
const float sa1 = sinf(Angle + AngleStep);
const float sa2 = sinf(Angle + AngleStep * 2);

IGraphics::CFreeformItem LQuad(
BgRect.x + ca * -CornerWidth,
BgRect.y + CornerHeight + sa * -CornerHeight,

BgRect.x, BgRect.y + CornerHeight,

BgRect.x + ca1 * -CornerWidth,
BgRect.y + CornerHeight + sa1 * -CornerHeight,

BgRect.x + ca2 * -CornerWidth,
BgRect.y + CornerHeight + sa2 *- CornerHeight
);
LeftCornerQuads[q] = LQuad;

IGraphics::CFreeformItem RQuad(
BgRect.x + BgRect.w + ca * CornerWidth,
BgRect.y + CornerHeight + sa * -CornerHeight,

BgRect.x + BgRect.w, BgRect.y + CornerHeight,

BgRect.x + BgRect.w + ca1 * CornerWidth,
BgRect.y + CornerHeight + sa1 * -CornerHeight,

BgRect.x + BgRect.w + ca2 * CornerWidth,
BgRect.y + CornerHeight + sa2 *- CornerHeight
);
RightCornerQuads[q] = RQuad;
}

IGraphics::CColorVertex aColorVert[4] = {
IGraphics::CColorVertex(0, 0,0,0, 0.0f),
IGraphics::CColorVertex(1, 0,0,0, 0.4f * Fade),
IGraphics::CColorVertex(2, 0,0,0, 0.0f),
IGraphics::CColorVertex(3, 0,0,0, 0.0f)
};

Graphics()->SetColorVertex(aColorVert, 4);
Graphics()->QuadsDrawFreeform(LeftCornerQuads, CORNER_MAX_QUADS);
Graphics()->QuadsDrawFreeform(RightCornerQuads, CORNER_MAX_QUADS);

Graphics()->QuadsEnd();

RenderTools()->DrawUIRect4(&BgRect, ColorTop, ColorTop,
ColorBot, ColorBot, 0, 0);


BcView.VMargin(5.0f, &BcView);
BcView.HSplitBottom(2.0f, &BcView, 0);

// draw lines
const float FontSize = m_SrvBroadcastFontSize;
const int LineCount = m_SrvBroadcastLineCount;
const char* pBroadcastMsg = m_aSrvBroadcastMsg;
CTextCursor Cursor;

const vec2 ShadowOff(1.0f, 2.0f);
const vec4 ShadowColorBlack(0, 0, 0, 0.9f * Fade);
const vec4 TextColorWhite(1, 1, 1, Fade);
float y = BcView.y + BcView.h - LineCount * FontSize;

for(int l = 0; l < LineCount; l++)
{
const CBcLineInfo& Line = m_aSrvBroadcastLines[l];
TextRender()->SetCursor(&Cursor, BcView.x + (BcView.w - Line.m_Width) * 0.5f, y,
FontSize, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = BcView.w;

// draw colored text
if(ColoredBroadcastEnabled)
{
int DrawnStrLen = 0;
int ThisCharPos = Line.m_pStrStart - pBroadcastMsg;
while(DrawnStrLen < Line.m_StrLen)
{
int StartColorID = -1;
int ColorStrLen = -1;

// find color
for(int j = 0; j < m_SrvBroadcastColorCount; j++)
{
if((ThisCharPos+DrawnStrLen) >= m_aSrvBroadcastColorList[j].m_CharPos)
{
StartColorID = j;
}
else if(StartColorID >= 0)
{
ColorStrLen = m_aSrvBroadcastColorList[j].m_CharPos -
max(m_aSrvBroadcastColorList[StartColorID].m_CharPos, ThisCharPos);
break;
}
}

dbg_assert(StartColorID >= 0, "This should not be -1, color not found");

if(ColorStrLen < 0)
ColorStrLen = Line.m_StrLen-DrawnStrLen;
ColorStrLen = min(ColorStrLen, Line.m_StrLen-DrawnStrLen);

const CBcColor& TextColor = m_aSrvBroadcastColorList[StartColorID];
float r = TextColor.m_R/255.f;
float g = TextColor.m_G/255.f;
float b = TextColor.m_B/255.f;
float AvgLum = 0.2126*r + 0.7152*g + 0.0722*b;

if(AvgLum < 0.25f)
{
TextRender()->TextOutlineColor(1, 1, 1, 0.6f);
TextRender()->TextColor(r, g, b, Fade);
TextRender()->TextEx(&Cursor, Line.m_pStrStart+DrawnStrLen, ColorStrLen);
}
else
{
vec4 TextColor(r, g, b, Fade);
vec4 ShadowColor(r * 0.15f, g * 0.15f, b * 0.15f, 0.9f * Fade);
TextRender()->TextShadowed(&Cursor, Line.m_pStrStart+DrawnStrLen, ColorStrLen,
ShadowOff, ShadowColor, TextColor);
}

DrawnStrLen += ColorStrLen;
}
}
else
{
TextRender()->TextShadowed(&Cursor, Line.m_pStrStart, Line.m_StrLen,
ShadowOff, ShadowColorBlack, TextColorWhite);
}

y += FontSize;
}

TextRender()->TextColor(1, 1, 1, 1);
TextRender()->TextOutlineColor(0, 0, 0, 0.3f);
// printf("broadcast: %s", pBroadcastMsg);
}

CBroadcast::CBroadcast()
Expand All @@ -240,11 +65,6 @@ CBroadcast::CBroadcast()
void CBroadcast::DoBroadcast(const char *pText)
{
str_copy(m_aBroadcastText, pText, 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 = Client()->LocalTime() + 10.0f;
}

Expand Down Expand Up @@ -317,94 +137,11 @@ void CBroadcast::OnMessage(int MsgType, void* pRawMsg)
m_aSrvBroadcastMsg[m_aSrvBroadcastMsgLen++] = *c;
}

// last user defined line
if(LastUserLineStartPoint > 0 && UserLineCount < 3)
{
CBcLineInfo Line = { m_aSrvBroadcastMsg+LastUserLineStartPoint,
m_aSrvBroadcastMsgLen-LastUserLineStartPoint, 0 };
if(Line.m_StrLen > 0)
UserLines[UserLineCount++] = Line;
}

const float Height = 300;
const float Width = Height*Graphics()->ScreenAspect();
const float LineMaxWidth = Width * 0.5f - 10.0f;

// process boradcast message
const char* pBroadcastMsg = m_aSrvBroadcastMsg;
const int MsgLen = m_aSrvBroadcastMsgLen;

CTextCursor Cursor;
Graphics()->MapScreen(0, 0, Width, Height);

// one line == big font
// 2+ lines == small font
m_SrvBroadcastLineCount = 0;
float FontSize = BROADCAST_FONTSIZE_BIG;

if(UserLineCount <= 1) // auto mode
{
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, 0);
Cursor.m_LineWidth = LineMaxWidth;
TextRender()->TextEx(&Cursor, pBroadcastMsg, MsgLen);

// can't fit on one line, reduce size
Cursor.m_LineCount = min(Cursor.m_LineCount, (int)MAX_BROADCAST_LINES);
FontSize = mix(BROADCAST_FONTSIZE_BIG, BROADCAST_FONTSIZE_SMALL,
Cursor.m_LineCount/(float)MAX_BROADCAST_LINES);
// const int MsgLen = m_aSrvBroadcastMsgLen;

// make lines
int CurCharCount = 0;
while(CurCharCount < MsgLen && m_SrvBroadcastLineCount < MAX_BROADCAST_LINES)
{
const char* RemainingMsg = pBroadcastMsg + CurCharCount;

TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = LineMaxWidth;

TextRender()->TextEx(&Cursor, RemainingMsg, -1);
int StrLen = Cursor.m_CharCount;

// don't cut words
if(CurCharCount + StrLen < MsgLen)
{
const int WorldLen = WordLengthBack(RemainingMsg + StrLen, StrLen);
if(WorldLen > 0 && WorldLen < StrLen)
{
StrLen -= WorldLen;
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = LineMaxWidth;
TextRender()->TextEx(&Cursor, RemainingMsg, StrLen);
}
}

const float TextWidth = Cursor.m_X-Cursor.m_StartX;

CBcLineInfo Line = { RemainingMsg, StrLen, TextWidth };
m_aSrvBroadcastLines[m_SrvBroadcastLineCount++] = Line;
CurCharCount += StrLen;
}
}
else // user defined lines mode
{
FontSize = mix(BROADCAST_FONTSIZE_BIG, BROADCAST_FONTSIZE_SMALL,
UserLineCount/(float)MAX_BROADCAST_LINES);

for(int i = 0; i < UserLineCount && m_SrvBroadcastLineCount < MAX_BROADCAST_LINES; i++)
{
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = LineMaxWidth;
TextRender()->TextEx(&Cursor, UserLines[i].m_pStrStart, UserLines[i].m_StrLen);

const float TextWidth = Cursor.m_X-Cursor.m_StartX;
const int StrLen = Cursor.m_CharCount;

CBcLineInfo Line = { UserLines[i].m_pStrStart, StrLen, TextWidth };
m_aSrvBroadcastLines[m_SrvBroadcastLineCount++] = Line;
}
}

m_SrvBroadcastFontSize = FontSize;
printf("broadcastMSG: %s\n", pBroadcastMsg);
}
}

Expand All @@ -417,14 +154,15 @@ void CBroadcast::OnRender()
if(m_pClient->m_pScoreboard->Active() || m_pClient->m_pMotd->IsActive())
return;

<<<<<<< HEAD
Graphics()->MapScreen(0, 0, 300*Graphics()->ScreenAspect(), 300);

=======
// client broadcast
>>>>>>> Server broadcast console only
if(Client()->LocalTime() < 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);
printf("client_broadcast: %s", m_aBroadcastText);
}
}

2 changes: 0 additions & 2 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,6 @@ void CGameClient::OnConnected()
m_Layers.Init(Kernel());
m_Collision.Init(Layers());

RenderTools()->RenderTilemapGenerateSkip(Layers());

for(int i = 0; i < m_All.m_Num; i++)
{
m_All.m_paComponents[i]->OnMapLoad();
Expand Down

0 comments on commit 2f13fee

Please sign in to comment.