Adjusted spectator bottom-right box, broadcast network back-end, options to disable/mute it

This commit is contained in:
LordSk 2018-11-25 02:43:52 +01:00
parent af49073f55
commit dc449f84e5
9 changed files with 57 additions and 20 deletions

View file

@ -243,6 +243,10 @@ Messages = [
NetString("m_pMessage"),
]),
NetMessage("Sv_Broadcast", [
NetString("m_pMessage"),
]),
NetMessage("Sv_Chat", [
NetIntRange("m_Mode", 0, 'NUM_CHATS-1'),
NetIntRange("m_ClientID", -1, 'MAX_CLIENTS-1'),

View file

@ -24,6 +24,8 @@ MACRO_CONFIG_INT(ClAutoDemoMax, cl_auto_demo_max, 10, 0, 1000, CFGFLAG_SAVE|CFGF
MACRO_CONFIG_INT(ClAutoScreenshot, cl_auto_screenshot, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Automatically take game over screenshot")
MACRO_CONFIG_INT(ClAutoScreenshotMax, cl_auto_screenshot_max, 10, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Maximum number of automatically created screenshots (0 = no limit)")
MACRO_CONFIG_INT(ClShowServerBroadcast, cl_show_server_broadcast, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Show server broadcast")
MACRO_CONFIG_STR(BrFilterString, br_filter_string, 25, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Server browser filtering string")
MACRO_CONFIG_INT(BrSort, br_sort, 0, 0, 256, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")

View file

@ -44,9 +44,11 @@ inline bool IsCharANum(char c)
void CHud::OnMessage(int MsgType, void* pRawMsg)
{
if(MsgType == NETMSGTYPE_SV_CHAT)
// process server broadcast message
if(MsgType == NETMSGTYPE_SV_BROADCAST && g_Config.m_ClShowServerBroadcast &&
!m_pClient->m_MuteServerBroadcast)
{
CNetMsg_Sv_Chat *pMsg = (CNetMsg_Sv_Chat *)pRawMsg;
CNetMsg_Sv_Broadcast *pMsg = (CNetMsg_Sv_Broadcast *)pRawMsg;
// new broadcast message
int MsgLen = str_length(pMsg->m_pMessage);
@ -674,7 +676,8 @@ void CHud::RenderHealthAndAmmo(const CNetObj_Character *pCharacter)
void CHud::RenderSpectatorHud()
{
// draw the box
CUIRect Rect = {m_Width-180.0f, m_Height-15.0f, 180.0f, 15.0f};
const float Width = m_Width * 0.25f - 2.0f;
CUIRect Rect = {m_Width-Width, m_Height-15.0f, Width, 15.0f};
RenderTools()->DrawUIRect(&Rect, vec4(0.0f, 0.0f, 0.0f, 0.4f), CUI::CORNER_TL, 5.0f);
// draw the text
@ -685,7 +688,7 @@ void CHud::RenderSpectatorHud()
char aBuf[128];
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, m_Width-174.0f, m_Height-13.0f, 8.0f, TEXTFLAG_RENDER);
TextRender()->SetCursor(&Cursor, m_Width-Width+6.0f, m_Height-13.0f, 8.0f, TEXTFLAG_RENDER);
str_format(aBuf, sizeof(aBuf), "%s: ", Localize("Spectate"));
TextRender()->TextEx(&Cursor, aBuf, -1);
@ -777,6 +780,9 @@ inline bool IsCharWhitespace(char c)
void CHud::RenderBroadcast()
{
if(!g_Config.m_ClShowServerBroadcast || m_pClient->m_MuteServerBroadcast)
return;
const float DisplayDuration = 10.0f;
const float DisplayStartFade = 9.0f;
const float DeltaTime = Client()->LocalTime() - m_BroadcastReceivedTime;
@ -791,9 +797,6 @@ void CHud::RenderBroadcast()
const float Fade = 1.0f - max(0.0f, (DeltaTime - DisplayStartFade) / (DisplayDuration - DisplayStartFade));
CUIRect ScreenRect = {0, 0, m_Width, m_Height};
const bool IsSpecMode = m_pClient->m_Snap.m_SpecInfo.m_Active;
if(IsSpecMode)
ScreenRect.y -= 20.0f;
CUIRect BcView = ScreenRect;
BcView.x += m_Width * 0.25f;
@ -804,13 +807,12 @@ void CHud::RenderBroadcast()
float FontSize = 11.0f;
vec4 ColorTop(0, 0, 0, 0);
vec4 ColorBot(0, 0, 0, (IsSpecMode ? 0.2f : 0.4f) * Fade);
vec4 ColorBot(0, 0, 0, 0.4f * Fade);
CUIRect BgRect;
BcView.HSplitBottom(10.0f, 0, &BgRect);
RenderTools()->DrawUIRect4(&BgRect, ColorTop, ColorTop,
ColorBot, ColorBot, IsSpecMode ? CUI::CORNER_B:0,
IsSpecMode ? 2.0f:0);
ColorBot, ColorBot, 0, 0);
// server broadcast line
CUIRect TitleRect;

View file

@ -11,11 +11,11 @@ class CHud : public CComponent
float m_AverageFPS;
int64 m_WarmupHideTick;
// broadcast
// server broadcast
typedef unsigned char u8;
struct CBcColor
{
u8 m_R,m_G,m_B;
u8 m_R, m_G, m_B;
int m_CharPos;
};

View file

@ -363,6 +363,17 @@ void CMenus::RenderServerInfo(CUIRect MainView)
ServerBrowser()->AddFavorite(&CurrentServerInfo);
}
{
CUIRect Button;
ServerInfo.HSplitBottom(20.0f, &ServerInfo, &Button);
static int s_MuteBroadcast = 0;
if(DoButton_CheckBox(&s_MuteBroadcast, Localize("Mute broadcast"),
m_pClient->m_MuteServerBroadcast, &Button))
{
m_pClient->m_MuteServerBroadcast ^= 1;
}
}
// gameinfo
GameInfo.VSplitLeft(1.0f, 0, &GameInfo);
RenderTools()->DrawUIRect(&GameInfo, vec4(0.0, 0.0, 0.0, 0.25f), CUI::CORNER_ALL, 5.0f);

View file

@ -369,6 +369,7 @@ void CGameClient::OnReset()
m_DemoSpecMode = SPEC_FREEVIEW;
m_DemoSpecID = -1;
m_Tuning = CTuningParams();
m_MuteServerBroadcast = false;
}

View file

@ -194,6 +194,7 @@ public:
CClientData m_aClients[MAX_CLIENTS];
int m_LocalClientID;
int m_TeamCooldownTick;
bool m_MuteServerBroadcast;
struct CGameInfo
{

View file

@ -241,6 +241,13 @@ void CGameContext::SendChat(int ChatterClientID, int Mode, int To, const char *p
}
}
void CGameContext::SendBroadcast(const char* pText, int ClientID)
{
CNetMsg_Sv_Broadcast Msg;
Msg.m_pMessage = pText;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID);
}
void CGameContext::SendEmoticon(int ClientID, int Emoticon)
{
CNetMsg_Sv_Emoticon Msg;
@ -1094,6 +1101,12 @@ void CGameContext::ConSay(IConsole::IResult *pResult, void *pUserData)
pSelf->SendChat(-1, CHAT_ALL, -1, pResult->GetString(0));
}
void CGameContext::ConBroadcast(IConsole::IResult* pResult, void* pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->SendBroadcast(pResult->GetString(0), -1);
}
void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
@ -1381,6 +1394,7 @@ void CGameContext::OnConsoleInit()
Console()->Register("change_map", "?r", CFGFLAG_SERVER|CFGFLAG_STORE, ConChangeMap, this, "Change map");
Console()->Register("restart", "?i", CFGFLAG_SERVER|CFGFLAG_STORE, ConRestart, this, "Restart in x seconds (0 = abort)");
Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "Say in chat");
Console()->Register("broadcast", "r", CFGFLAG_SERVER, ConBroadcast, this, "Broadcast message");
Console()->Register("set_team", "ii?i", CFGFLAG_SERVER, ConSetTeam, this, "Set team of player to team");
Console()->Register("set_team_all", "i", CFGFLAG_SERVER, ConSetTeamAll, this, "Set team of all players to team");
Console()->Register("swap_teams", "", CFGFLAG_SERVER, ConSwapTeams, this, "Swap the current teams");

View file

@ -49,6 +49,7 @@ class CGameContext : public IGameServer
static void ConChangeMap(IConsole::IResult *pResult, void *pUserData);
static void ConRestart(IConsole::IResult *pResult, void *pUserData);
static void ConSay(IConsole::IResult *pResult, void *pUserData);
static void ConBroadcast(IConsole::IResult *pResult, void *pUserData);
static void ConSetTeam(IConsole::IResult *pResult, void *pUserData);
static void ConSetTeamAll(IConsole::IResult *pResult, void *pUserData);
static void ConSwapTeams(IConsole::IResult *pResult, void *pUserData);
@ -132,6 +133,7 @@ public:
// network
void SendChat(int ChatterClientID, int Mode, int To, const char *pText);
void SendBroadcast(const char *pText, int ClientID);
void SendEmoticon(int ClientID, int Emoticon);
void SendWeaponPickup(int ClientID, int Weapon);
void SendMotd(int ClientID);