Console improvements and new command

* Commented "ImGui::SetItemDefaultFocus()", this seems to somewhat fix the issue where the input field does not claim focus on console invocation.
* Added command "con_removeline" (removes lines from start to end index).
This commit is contained in:
Kawe Mazidjatari 2022-10-18 02:11:52 +02:00
parent ad844269b8
commit d113774a6d
5 changed files with 69 additions and 2 deletions

View File

@ -149,7 +149,7 @@ void CConsole::Think(void)
{
if (m_bActivate)
{
if (m_flFadeAlpha <= 1.f)
if (m_flFadeAlpha < 1.f)
{
m_flFadeAlpha += .1f;
}
@ -254,7 +254,7 @@ void CConsole::DrawSurface(void)
}
// Auto-focus on window apparition.
ImGui::SetItemDefaultFocus();
//ImGui::SetItemDefaultFocus();
// Auto-focus previous widget.
if (m_bReclaimFocus)
@ -915,6 +915,48 @@ void CConsole::AddLog(const ImVec4& color, const char* fmt, ...) IM_FMTARGS(2)
m_Logger.InsertText(ConLog_t(Strdup(buf), color));
}
//-----------------------------------------------------------------------------
// Purpose: removes lines from console with sanitized start and end indices
// input : nStart -
// nEnd -
//-----------------------------------------------------------------------------
void CConsole::RemoveLog(int nStart, int nEnd)
{
int nLines = m_Logger.GetTotalLines();
if (nEnd >= nLines)
{
// Sanitize for last array elem.
nEnd = (nLines - 1);
}
if (nStart >= nEnd)
{
if (nEnd > 0)
{
nStart = (nEnd - 1);
}
else
{
// First elem cannot be removed!
return;
}
}
else if (nStart < 0)
{
nStart = 0;
}
// User wants to remove everything.
if (nLines <= (nStart - nEnd))
{
ClearLog();
return;
}
std::lock_guard<std::mutex> l(m_Mutex);
m_Logger.RemoveLine(nStart, nEnd);
}
//-----------------------------------------------------------------------------
// Purpose: clears the entire log vector
//-----------------------------------------------------------------------------

View File

@ -47,6 +47,7 @@ private:
///////////////////////////////////////////////////////////////////////////
public:
void AddLog(const ConLog_t& conLog);
void RemoveLog(int nStart, int nEnd);
private:
void AddLog(const ImVec4& color, const char* fmt, ...) IM_FMTARGS(2);

View File

@ -351,6 +351,7 @@ void ConCommand::Init(void)
ConCommand::Create("cl_showbrowser", "Opens the server browser.", FCVAR_CLIENTDLL | FCVAR_RELEASE, ServerBrowser_Invoke_f, nullptr);
ConCommand::Create("rcon", "Forward RCON query to remote server. | Usage: rcon \"<query>\".", FCVAR_CLIENTDLL | FCVAR_RELEASE, RCON_CmdQuery_f, nullptr);
ConCommand::Create("rcon_disconnect", "Disconnect from RCON server.", FCVAR_CLIENTDLL | FCVAR_RELEASE, RCON_Disconnect_f, nullptr);
ConCommand::Create("con_removeline", "Removes a range of lines from the console.", FCVAR_CLIENTDLL | FCVAR_RELEASE, CON_RemoveLine_f, nullptr);
//-------------------------------------------------------------------------
// UI DLL |
ConCommand::Create("script_ui", "Run input code as UI script on the VM.", FCVAR_CLIENTDLL | FCVAR_CHEAT, SQVM_UIScript_f, nullptr);

View File

@ -628,6 +628,28 @@ void NET_UseRandomKeyChanged_f(IConVar* pConVar, const char* pOldString, float f
}
}
#ifndef DEDICATED
/*
=====================
CON_RemoveLine_f
Removes a range of lines
from the console.
=====================
*/
void CON_RemoveLine_f(const CCommand& args)
{
if (args.ArgC() < 3)
{
DevMsg(eDLL_T::CLIENT, "Usage 'con_removeline': start(int) end(int)\n");
return;
}
int start = atoi(args[1]);
int end = atoi(args[2]);
g_pConsole->RemoveLog(start, end);
}
/*
=====================
RCON_CmdQuery_f

View File

@ -38,6 +38,7 @@ void NET_SetKey_f(const CCommand& args);
void NET_GenerateKey_f(const CCommand& args);
void NET_UseRandomKeyChanged_f(IConVar* pConVar, const char* pOldString, float flOldValue);
#ifndef DEDICATED
void CON_RemoveLine_f(const CCommand& args);
void RCON_CmdQuery_f(const CCommand& args);
void RCON_Disconnect_f(const CCommand& args);
#endif // !DEDICATED