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

@ -242,6 +242,10 @@ Messages = [
NetMessage("Sv_Motd", [ NetMessage("Sv_Motd", [
NetString("m_pMessage"), NetString("m_pMessage"),
]), ]),
NetMessage("Sv_Broadcast", [
NetString("m_pMessage"),
]),
NetMessage("Sv_Chat", [ NetMessage("Sv_Chat", [
NetIntRange("m_Mode", 0, 'NUM_CHATS-1'), NetIntRange("m_Mode", 0, 'NUM_CHATS-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(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(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_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, "") 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) 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 // new broadcast message
int MsgLen = str_length(pMsg->m_pMessage); int MsgLen = str_length(pMsg->m_pMessage);
@ -674,7 +676,8 @@ void CHud::RenderHealthAndAmmo(const CNetObj_Character *pCharacter)
void CHud::RenderSpectatorHud() void CHud::RenderSpectatorHud()
{ {
// draw the box // 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); RenderTools()->DrawUIRect(&Rect, vec4(0.0f, 0.0f, 0.0f, 0.4f), CUI::CORNER_TL, 5.0f);
// draw the text // draw the text
@ -685,7 +688,7 @@ void CHud::RenderSpectatorHud()
char aBuf[128]; char aBuf[128];
CTextCursor Cursor; 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")); str_format(aBuf, sizeof(aBuf), "%s: ", Localize("Spectate"));
TextRender()->TextEx(&Cursor, aBuf, -1); TextRender()->TextEx(&Cursor, aBuf, -1);
@ -777,6 +780,9 @@ inline bool IsCharWhitespace(char c)
void CHud::RenderBroadcast() void CHud::RenderBroadcast()
{ {
if(!g_Config.m_ClShowServerBroadcast || m_pClient->m_MuteServerBroadcast)
return;
const float DisplayDuration = 10.0f; const float DisplayDuration = 10.0f;
const float DisplayStartFade = 9.0f; const float DisplayStartFade = 9.0f;
const float DeltaTime = Client()->LocalTime() - m_BroadcastReceivedTime; 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)); const float Fade = 1.0f - max(0.0f, (DeltaTime - DisplayStartFade) / (DisplayDuration - DisplayStartFade));
CUIRect ScreenRect = {0, 0, m_Width, m_Height}; 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; CUIRect BcView = ScreenRect;
BcView.x += m_Width * 0.25f; BcView.x += m_Width * 0.25f;
@ -804,13 +807,12 @@ void CHud::RenderBroadcast()
float FontSize = 11.0f; float FontSize = 11.0f;
vec4 ColorTop(0, 0, 0, 0); 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; CUIRect BgRect;
BcView.HSplitBottom(10.0f, 0, &BgRect); BcView.HSplitBottom(10.0f, 0, &BgRect);
RenderTools()->DrawUIRect4(&BgRect, ColorTop, ColorTop, RenderTools()->DrawUIRect4(&BgRect, ColorTop, ColorTop,
ColorBot, ColorBot, IsSpecMode ? CUI::CORNER_B:0, ColorBot, ColorBot, 0, 0);
IsSpecMode ? 2.0f:0);
// server broadcast line // server broadcast line
CUIRect TitleRect; CUIRect TitleRect;

View file

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

View file

@ -363,6 +363,17 @@ void CMenus::RenderServerInfo(CUIRect MainView)
ServerBrowser()->AddFavorite(&CurrentServerInfo); 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
GameInfo.VSplitLeft(1.0f, 0, &GameInfo); GameInfo.VSplitLeft(1.0f, 0, &GameInfo);
RenderTools()->DrawUIRect(&GameInfo, vec4(0.0, 0.0, 0.0, 0.25f), CUI::CORNER_ALL, 5.0f); RenderTools()->DrawUIRect(&GameInfo, vec4(0.0, 0.0, 0.0, 0.25f), CUI::CORNER_ALL, 5.0f);

View file

@ -249,7 +249,7 @@ void CGameClient::OnInit()
m_UI.SetGraphics(Graphics(), TextRender()); m_UI.SetGraphics(Graphics(), TextRender());
m_RenderTools.m_pGraphics = Graphics(); m_RenderTools.m_pGraphics = Graphics();
m_RenderTools.m_pUI = UI(); m_RenderTools.m_pUI = UI();
int64 Start = time_get(); int64 Start = time_get();
// set the language // set the language
@ -369,6 +369,7 @@ void CGameClient::OnReset()
m_DemoSpecMode = SPEC_FREEVIEW; m_DemoSpecMode = SPEC_FREEVIEW;
m_DemoSpecID = -1; m_DemoSpecID = -1;
m_Tuning = CTuningParams(); m_Tuning = CTuningParams();
m_MuteServerBroadcast = false;
} }
@ -633,7 +634,7 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
if(m_LocalClientID != -1 && !pMsg->m_Silent) if(m_LocalClientID != -1 && !pMsg->m_Silent)
{ {
DoEnterMessage(pMsg->m_pName, pMsg->m_ClientID, pMsg->m_Team); DoEnterMessage(pMsg->m_pName, pMsg->m_ClientID, pMsg->m_Team);
if(m_pDemoRecorder->IsRecording()) if(m_pDemoRecorder->IsRecording())
{ {
CNetMsg_De_ClientEnter Msg; CNetMsg_De_ClientEnter Msg;
@ -746,7 +747,7 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
if(pMsg->m_Silent == 0) if(pMsg->m_Silent == 0)
{ {
DoTeamChangeMessage(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_ClientID, pMsg->m_Team); DoTeamChangeMessage(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_ClientID, pMsg->m_Team);
} }
} }
else if(MsgId == NETMSGTYPE_SV_READYTOENTER) else if(MsgId == NETMSGTYPE_SV_READYTOENTER)
{ {
@ -983,7 +984,7 @@ void CGameClient::OnNewSnapshot()
m_ServerMode = SERVERMODE_PURE; m_ServerMode = SERVERMODE_PURE;
} }
} }
// network items // network items
if(Item.m_Type == NETOBJTYPE_PLAYERINFO) if(Item.m_Type == NETOBJTYPE_PLAYERINFO)
{ {
@ -1018,7 +1019,7 @@ void CGameClient::OnNewSnapshot()
// clamp ammo count for non ninja weapon // clamp ammo count for non ninja weapon
if(m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_Weapon != WEAPON_NINJA) if(m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_Weapon != WEAPON_NINJA)
m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_AmmoCount = clamp(m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_AmmoCount, 0, 10); m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_AmmoCount = clamp(m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_AmmoCount, 0, 10);
if(pOld) if(pOld)
{ {
m_Snap.m_aCharacters[Item.m_ID].m_Active = true; m_Snap.m_aCharacters[Item.m_ID].m_Active = true;
@ -1199,7 +1200,7 @@ void CGameClient::OnDemoRecSnap()
CNetObj_De_GameInfo *pGameInfo = static_cast<CNetObj_De_GameInfo *>(Client()->SnapNewItem(NETOBJTYPE_DE_GAMEINFO, 0, sizeof(CNetObj_De_GameInfo))); CNetObj_De_GameInfo *pGameInfo = static_cast<CNetObj_De_GameInfo *>(Client()->SnapNewItem(NETOBJTYPE_DE_GAMEINFO, 0, sizeof(CNetObj_De_GameInfo)));
if(!pGameInfo) if(!pGameInfo)
return; return;
pGameInfo->m_GameFlags = m_GameInfo.m_GameFlags; pGameInfo->m_GameFlags = m_GameInfo.m_GameFlags;
pGameInfo->m_ScoreLimit = m_GameInfo.m_ScoreLimit; pGameInfo->m_ScoreLimit = m_GameInfo.m_ScoreLimit;
pGameInfo->m_TimeLimit = m_GameInfo.m_TimeLimit; pGameInfo->m_TimeLimit = m_GameInfo.m_TimeLimit;

View file

@ -87,7 +87,7 @@ public:
const char *NetobjFailedOn() { return m_NetObjHandler.FailedObjOn(); }; const char *NetobjFailedOn() { return m_NetObjHandler.FailedObjOn(); };
int NetobjNumFailures() { return m_NetObjHandler.NumObjFailures(); }; int NetobjNumFailures() { return m_NetObjHandler.NumObjFailures(); };
const char *NetmsgFailedOn() { return m_NetObjHandler.FailedMsgOn(); }; const char *NetmsgFailedOn() { return m_NetObjHandler.FailedMsgOn(); };
bool m_SuppressEvents; bool m_SuppressEvents;
// TODO: move this // TODO: move this
@ -129,7 +129,7 @@ public:
const CNetObj_GameDataTeam *m_pGameDataTeam; const CNetObj_GameDataTeam *m_pGameDataTeam;
const CNetObj_GameDataFlag *m_pGameDataFlag; const CNetObj_GameDataFlag *m_pGameDataFlag;
int m_GameDataFlagSnapID; int m_GameDataFlagSnapID;
int m_NotReadyCount; int m_NotReadyCount;
int m_AliveCount[NUM_TEAMS]; int m_AliveCount[NUM_TEAMS];
@ -194,6 +194,7 @@ public:
CClientData m_aClients[MAX_CLIENTS]; CClientData m_aClients[MAX_CLIENTS];
int m_LocalClientID; int m_LocalClientID;
int m_TeamCooldownTick; int m_TeamCooldownTick;
bool m_MuteServerBroadcast;
struct CGameInfo 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) void CGameContext::SendEmoticon(int ClientID, int Emoticon)
{ {
CNetMsg_Sv_Emoticon Msg; 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)); 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) void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData)
{ {
CGameContext *pSelf = (CGameContext *)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("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("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("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", "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("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"); 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 ConChangeMap(IConsole::IResult *pResult, void *pUserData);
static void ConRestart(IConsole::IResult *pResult, void *pUserData); static void ConRestart(IConsole::IResult *pResult, void *pUserData);
static void ConSay(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 ConSetTeam(IConsole::IResult *pResult, void *pUserData);
static void ConSetTeamAll(IConsole::IResult *pResult, void *pUserData); static void ConSetTeamAll(IConsole::IResult *pResult, void *pUserData);
static void ConSwapTeams(IConsole::IResult *pResult, void *pUserData); static void ConSwapTeams(IConsole::IResult *pResult, void *pUserData);
@ -132,6 +133,7 @@ public:
// network // network
void SendChat(int ChatterClientID, int Mode, int To, const char *pText); 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 SendEmoticon(int ClientID, int Emoticon);
void SendWeaponPickup(int ClientID, int Weapon); void SendWeaponPickup(int ClientID, int Weapon);
void SendMotd(int ClientID); void SendMotd(int ClientID);