Skip to content

Commit 8b3244c

Browse files
New optional inputBlocked argument for showChat (#2170)
* Add new optional argument inputBlocked to showChat function which allows to hide the chatbox while still being able to type * Make IsInputBlocked function const as suggested by Lpsd Co-authored-by: Lpsd <40902730+Lpsd@users.noreply.github.com> * Make IsInputVisible function const as suggested by Lpsd Co-authored-by: Lpsd <40902730+Lpsd@users.noreply.github.com> * Make sure all combinations of bVisible and bInputBlocked are correctly handled, switch to new argument parser * Add new function IsChatInputBlocked to accomodate the new showChat functionality, use new argument parser for isChatVisible * Move virtual IsChatInputBlocked to the bottom of CCoreInterface.h Co-authored-by: Lpsd <40902730+Lpsd@users.noreply.github.com>
1 parent a60f7a7 commit 8b3244c

25 files changed

+110
-95
lines changed

Client/core/CChat.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ CChat::CChat(CGUI* pManager, const CVector2D& vecPosition)
4141
m_bUseCEGUI = false;
4242
m_iCVarsRevision = -1;
4343
m_bVisible = false;
44+
m_bInputBlocked = false;
4445
m_bInputVisible = false;
4546
m_pFont = m_pManager->GetClearFont();
4647
m_pDXFont = NULL;
@@ -149,8 +150,8 @@ void CChat::LoadCVars()
149150
//
150151
void CChat::Draw(bool bUseCacheTexture, bool bAllowOutline)
151152
{
152-
// Are we visible?
153-
if (!m_bVisible)
153+
// Are we visible and is input blocked?
154+
if (!m_bVisible && m_bInputBlocked)
154155
return;
155156

156157
// Is it time to update all the chat related cvars?
@@ -164,6 +165,10 @@ void CChat::Draw(bool bUseCacheTexture, bool bAllowOutline)
164165
bool bUsingOutline = m_bTextBlackOutline && bAllowOutline && bUseCacheTexture;
165166
DrawInputLine(bUsingOutline);
166167

168+
// Are we visible?
169+
if (!m_bVisible)
170+
return;
171+
167172
// Get drawList for the chat box text
168173
SDrawList drawList;
169174
GetDrawList(drawList, bUsingOutline);
@@ -771,17 +776,18 @@ bool CChat::CharacterKeyHandler(CGUIKeyEventArgs KeyboardArgs)
771776
return true;
772777
}
773778

774-
void CChat::SetVisible(bool bVisible)
779+
void CChat::SetVisible(bool bVisible, bool bInputBlocked)
775780
{
776781
m_bVisible = bVisible;
777-
// If hiding chat, also reset chat input line
778-
if (!m_bVisible)
782+
m_bInputBlocked = bInputBlocked;
783+
784+
if (m_bInputBlocked)
779785
SetInputVisible(false);
780786
}
781787

782788
void CChat::SetInputVisible(bool bVisible)
783789
{
784-
if (!IsVisible())
790+
if (m_bInputBlocked)
785791
bVisible = false;
786792

787793
if (!bVisible)

Client/core/CChat.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ class CChat
166166
void SetDxFont(LPD3DXFONT pDXFont);
167167

168168
bool IsVisible() { return m_bVisible; }
169-
void SetVisible(bool bVisible);
170-
bool IsInputVisible() { return m_bVisible && m_bInputVisible; }
169+
void SetVisible(bool bVisible, bool bInputBlocked);
170+
bool IsInputBlocked() const { return m_bInputBlocked; }
171+
bool IsInputVisible() const { return !m_bInputBlocked && m_bInputVisible; }
171172
void SetInputVisible(bool bVisible);
172173

173174
bool CanTakeInput() { return !CLocalGUI::GetSingleton().GetConsole()->IsVisible() && IsInputVisible(); };
@@ -257,6 +258,7 @@ class CChat
257258
int m_iSelectedInputHistoryEntry;
258259

259260
bool m_bVisible;
261+
bool m_bInputBlocked;
260262
bool m_bInputVisible;
261263
int m_iScrollingBack; // Non zero if currently scrolling back
262264
float m_fCssStyleOverrideAlpha; // For fading out 'CssStyle' effect. (When entering text or scrolling back)

Client/core/CCore.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,11 @@ void CCore::ChatPrintfColor(const char* szFormat, bool bColorCoded, unsigned cha
438438
}
439439
}
440440

441-
void CCore::SetChatVisible(bool bVisible)
441+
void CCore::SetChatVisible(bool bVisible, bool bInputBlocked)
442442
{
443443
if (m_pLocalGUI)
444444
{
445-
m_pLocalGUI->SetChatBoxVisible(bVisible);
445+
m_pLocalGUI->SetChatBoxVisible(bVisible, bInputBlocked);
446446
}
447447
}
448448

@@ -455,6 +455,15 @@ bool CCore::IsChatVisible()
455455
return false;
456456
}
457457

458+
bool CCore::IsChatInputBlocked()
459+
{
460+
if (m_pLocalGUI)
461+
{
462+
return m_pLocalGUI->IsChatBoxInputBlocked();
463+
}
464+
return false;
465+
}
466+
458467
bool CCore::ClearChat()
459468
{
460469
if (m_pLocalGUI)

Client/core/CCore.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
119119
void ChatEchoColor(const char* szText, unsigned char R, unsigned char G, unsigned char B, bool bColorCoded = false);
120120
void ChatPrintf(const char* szFormat, bool bColorCoded, ...);
121121
void ChatPrintfColor(const char* szFormat, bool bColorCoded, unsigned char R, unsigned char G, unsigned char B, ...);
122-
void SetChatVisible(bool bVisible);
122+
void SetChatVisible(bool bVisible, bool bInputBlocked);
123123
bool IsChatVisible();
124+
bool IsChatInputBlocked();
124125
void EnableChatInput(char* szCommand, DWORD dwColor);
125126
bool IsChatInputEnabled();
126127
bool ClearChat();

Client/core/CGUI.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ CLocalGUI::CLocalGUI()
3535

3636
m_bForceCursorVisible = false;
3737
m_bChatboxVisible = true;
38+
m_bChatboxInputBlocked = false;
3839
m_pDebugViewVisible = false;
3940
m_bGUIHasInput = false;
4041
m_uiActiveCompositionSize = 0;
@@ -133,11 +134,11 @@ void CLocalGUI::CreateWindows(bool bGameIsAlreadyLoaded)
133134

134135
// Create chatbox
135136
m_pChat = new CChat(pGUI, CVector2D(0.0125f, 0.015f));
136-
m_pChat->SetVisible(false);
137+
m_pChat->SetVisible(false, true);
137138

138139
// Create the debug view
139140
m_pDebugView = new CDebugView(pGUI, CVector2D(0.23f, 0.785f));
140-
m_pDebugView->SetVisible(false);
141+
m_pDebugView->SetVisible(false, true);
141142

142143
// Create the overlayed version labels
143144
CVector2D ScreenSize = pGUI->GetResolution();
@@ -303,10 +304,10 @@ void CLocalGUI::Draw()
303304
// If we're ingame, make sure the chatbox is drawn
304305
bool bChatVisible = (SystemState == 9 /* GS_INGAME */ && m_pMainMenu->GetIsIngame() && m_bChatboxVisible && !CCore::GetSingleton().IsOfflineMod());
305306
if (m_pChat->IsVisible() != bChatVisible)
306-
m_pChat->SetVisible(bChatVisible);
307+
m_pChat->SetVisible(bChatVisible, !bChatVisible);
307308
bool bDebugVisible = (SystemState == 9 /* GS_INGAME */ && m_pMainMenu->GetIsIngame() && m_pDebugViewVisible && !CCore::GetSingleton().IsOfflineMod());
308309
if (m_pDebugView->IsVisible() != bDebugVisible)
309-
m_pDebugView->SetVisible(bDebugVisible);
310+
m_pDebugView->SetVisible(bDebugVisible, true);
310311

311312
// Make sure the cursor is displayed only when needed
312313
UpdateCursor();
@@ -455,13 +456,14 @@ CDebugView* CLocalGUI::GetDebugView()
455456
return m_pDebugView;
456457
}
457458

458-
void CLocalGUI::SetChatBoxVisible(bool bVisible)
459+
void CLocalGUI::SetChatBoxVisible(bool bVisible, bool bInputBlocked)
459460
{
460461
if (m_pChat)
461462
{
462-
if (m_pChat->IsVisible() != bVisible)
463-
m_pChat->SetVisible(bVisible);
463+
if (m_pChat->IsVisible() != bVisible || m_pChat->IsInputBlocked() != bInputBlocked)
464+
m_pChat->SetVisible(bVisible, bInputBlocked);
464465
m_bChatboxVisible = bVisible;
466+
m_bChatboxInputBlocked = bInputBlocked;
465467
}
466468
}
467469

@@ -470,7 +472,7 @@ void CLocalGUI::SetDebugViewVisible(bool bVisible)
470472
if (m_pDebugView)
471473
{
472474
if (m_pDebugView->IsVisible() != bVisible)
473-
m_pDebugView->SetVisible(bVisible);
475+
m_pDebugView->SetVisible(bVisible, true);
474476
m_pDebugViewVisible = bVisible;
475477
}
476478
}
@@ -484,6 +486,15 @@ bool CLocalGUI::IsChatBoxVisible()
484486
return false;
485487
}
486488

489+
bool CLocalGUI::IsChatBoxInputBlocked()
490+
{
491+
if (m_pChat)
492+
{
493+
return m_bChatboxInputBlocked;
494+
}
495+
return false;
496+
}
497+
487498
bool CLocalGUI::IsDebugViewVisible()
488499
{
489500
if (m_pDebugView)
@@ -505,7 +516,7 @@ bool CLocalGUI::IsChatBoxInputEnabled()
505516
{
506517
if (m_pChat)
507518
{
508-
return m_pChat->IsInputVisible() && m_bChatboxVisible;
519+
return m_pChat->IsInputVisible() && !m_pChat->IsInputBlocked();
509520
}
510521
return false;
511522
}

Client/core/CGUI.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ class CLocalGUI : public CSingleton<CLocalGUI>
6969
bool IsMainMenuVisible();
7070

7171
CChat* GetChat();
72-
void SetChatBoxVisible(bool bVisible);
72+
void SetChatBoxVisible(bool bVisible, bool bInputBlocked = true);
7373
bool IsChatBoxVisible();
74+
bool IsChatBoxInputBlocked();
7475
void SetChatBoxInputEnabled(bool bInputEnabled);
7576
bool IsChatBoxInputEnabled();
7677
void EchoChat(const char* szText, bool bColorCoded);
@@ -107,6 +108,7 @@ class CLocalGUI : public CSingleton<CLocalGUI>
107108

108109
bool m_bForceCursorVisible;
109110
bool m_bChatboxVisible;
111+
bool m_bChatboxInputBlocked;
110112
bool m_pDebugViewVisible;
111113
bool m_bGUIHasInput;
112114
int m_uiActiveCompositionSize;

Client/core/CModManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void CModManager::Unload()
207207
CLocalGUI::GetSingleton().SetChatBoxVisible(true);
208208

209209
// Reset the debugview status
210-
CLocalGUI::GetSingleton().GetDebugView()->SetVisible(false);
210+
CLocalGUI::GetSingleton().GetDebugView()->SetVisible(false, true);
211211
CLocalGUI::GetSingleton().GetDebugView()->Clear();
212212
CLocalGUI::GetSingleton().SetDebugViewVisible(false);
213213

Client/core/CScreenShot.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern CCore* g_pCore;
1616

1717
static char szScreenShotPath[MAX_PATH] = {0};
1818
static bool bIsChatVisible = false;
19+
static bool bIsChatInputBlocked = false;
1920
static bool bIsDebugVisible = false;
2021

2122
// Variables used for saving the screen shot file on a separate thread
@@ -30,12 +31,13 @@ static SString ms_strFileName;
3031
SString CScreenShot::PreScreenShot()
3132
{
3233
bIsChatVisible = g_pCore->IsChatVisible();
34+
bIsChatInputBlocked = g_pCore->IsChatInputBlocked();
3335
bIsDebugVisible = g_pCore->IsDebugVisible();
3436

3537
// make the chat and debug windows invisible
3638
if (ms_bHideChatBox)
3739
{
38-
g_pCore->SetChatVisible(false);
40+
g_pCore->SetChatVisible(false, true);
3941
g_pCore->SetDebugVisible(false);
4042
}
4143

@@ -51,7 +53,7 @@ void CScreenShot::PostScreenShot(const SString& strFileName)
5153
g_pCore->GetConsole()->Printf(_("Screenshot taken: '%s'"), *strFileName);
5254

5355
// make the chat and debug windows visible again
54-
g_pCore->SetChatVisible(bIsChatVisible);
56+
g_pCore->SetChatVisible(bIsChatVisible, bIsChatInputBlocked);
5557
g_pCore->SetDebugVisible(bIsDebugVisible);
5658
}
5759

Client/mods/deathmatch/CClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int CClient::ClientInitialize(const char* szArguments, CCoreInterface* pCore)
4949
pCore->SetOfflineMod(false);
5050

5151
// HACK FOR CHATBOX NOT VISIBLE. WILL CAUSE SAVING CHATBOX STATE NOT TO WORK
52-
g_pCore->SetChatVisible(true);
52+
g_pCore->SetChatVisible(true, false);
5353

5454
// Register our local commands
5555
g_pCore->GetCommands()->SetExecuteHandler(COMMAND_Executed);

Client/mods/deathmatch/ClientCommands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void COMMAND_ShowChat(const char* szCmdLine)
149149
{
150150
int iCmd = (szCmdLine && szCmdLine[0]) ? atoi(szCmdLine) : -1;
151151
bool bShow = (iCmd == 1) ? true : (iCmd == 0) ? false : !g_pCore->IsChatVisible();
152-
g_pCore->SetChatVisible(bShow);
152+
g_pCore->SetChatVisible(bShow, !bShow);
153153
}
154154

155155
void COMMAND_ShowNetstat(const char* szCmdLine)

Client/mods/deathmatch/logic/CRadarMap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ void CRadarMap::InternalSetRadarEnabled(bool bEnabled)
358358
if (bEnabled)
359359
{
360360
m_bChatVisible = g_pCore->IsChatVisible();
361+
m_bChatInputBlocked = g_pCore->IsChatInputBlocked();
361362
m_bDebugVisible = g_pCore->IsDebugVisible();
362363

363364
g_pGame->GetHud()->Disable(true);
@@ -369,7 +370,7 @@ void CRadarMap::InternalSetRadarEnabled(bool bEnabled)
369370
{
370371
g_pGame->GetHud()->Disable(false);
371372
g_pMultiplayer->HideRadar(false);
372-
g_pCore->SetChatVisible(m_bChatVisible);
373+
g_pCore->SetChatVisible(m_bChatVisible, m_bChatInputBlocked);
373374
g_pCore->SetDebugVisible(m_bDebugVisible);
374375
}
375376
}

Client/mods/deathmatch/logic/CRadarMap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class CRadarMap
113113

114114
bool m_bHudVisible;
115115
bool m_bChatVisible;
116+
bool m_bChatInputBlocked;
116117
bool m_bRadarVisible;
117118
bool m_bDebugVisible;
118119
bool m_bTextVisible;

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,6 @@ bool CStaticFunctionDefinitions::SetClipboard(SString& strText)
281281
return true;
282282
}
283283

284-
bool CStaticFunctionDefinitions::ShowChat(bool bShow)
285-
{
286-
g_pCore->SetChatVisible(bShow);
287-
return true;
288-
}
289-
290284
bool CStaticFunctionDefinitions::SetWindowFlashing(bool flash, uint count)
291285
{
292286
// Don't flash if the window is active

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class CStaticFunctionDefinitions
4040
// Output funcs
4141
static bool OutputConsole(const char* szText);
4242
static bool OutputChatBox(const char* szText, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, bool bColorCoded);
43-
static bool ShowChat(bool bShow);
4443
static bool SetClipboard(SString& strText);
4544
static bool SetWindowFlashing(bool flash, uint count);
4645
static bool ClearChatBox();

Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Output.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -97,35 +97,6 @@ int CLuaFunctionDefs::SetClipboard(lua_State* luaVM)
9797
return 1;
9898
}
9999

100-
int CLuaFunctionDefs::ShowChat(lua_State* luaVM)
101-
{
102-
bool bShow = false;
103-
CScriptArgReader argStream(luaVM);
104-
argStream.ReadBool(bShow);
105-
106-
if (!argStream.HasErrors())
107-
{
108-
if (CStaticFunctionDefinitions::ShowChat(bShow))
109-
{
110-
lua_pushboolean(luaVM, true);
111-
return 1;
112-
}
113-
}
114-
else
115-
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
116-
117-
// Failed
118-
lua_pushboolean(luaVM, false);
119-
return 1;
120-
}
121-
122-
int CLuaFunctionDefs::IsChatVisible(lua_State* luaVM)
123-
{
124-
// bool isChatVisible ()
125-
lua_pushboolean(luaVM, g_pCore->IsChatVisible());
126-
return 1;
127-
}
128-
129100
int CLuaFunctionDefs::OutputClientDebugString(lua_State* luaVM)
130101
{
131102
SString strText = "";

Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ class CLuaFunctionDefs
4747
// Output functions
4848
LUA_DECLARE(OutputConsole);
4949
LUA_DECLARE(OutputChatBox);
50-
LUA_DECLARE(ShowChat);
51-
LUA_DECLARE(IsChatVisible);
5250
LUA_DECLARE(OutputClientDebugString);
5351
LUA_DECLARE(SetClipboard);
5452
LUA_DECLARE(SetWindowFlashing);

Client/mods/deathmatch/logic/lua/CLuaManager.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ void CLuaManager::LoadCFunctions()
170170
// Output funcs
171171
{"outputConsole", CLuaFunctionDefs::OutputConsole},
172172
{"outputChatBox", CLuaFunctionDefs::OutputChatBox},
173-
{"showChat", CLuaFunctionDefs::ShowChat},
174-
{"isChatVisible", CLuaFunctionDefs::IsChatVisible},
175173
{"outputDebugString", CLuaFunctionDefs::OutputClientDebugString},
176174
{"setClipboard", CLuaFunctionDefs::SetClipboard},
177175
{"setWindowFlashing", CLuaFunctionDefs::SetWindowFlashing},

0 commit comments

Comments
 (0)