mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
GameUI: light console code cleanup and optimizations
Use static functions instead of an std::function for stuff that could've easily been a static or inline. This imposes less overhead to the runtime.
This commit is contained in:
parent
e05d137acd
commit
7febdde3d4
@ -406,6 +406,110 @@ void CConsole::DrawOptionsPanel(void)
|
|||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: returns flag texture index for CommandBase (must be aligned with resource.h!)
|
||||||
|
// in the future we should build the texture procedurally with use of popcnt.
|
||||||
|
// Input : nFlags -
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
static int GetFlagTextureIndex(const int flags)
|
||||||
|
{
|
||||||
|
switch (flags) // All indices for single/dual flag textures.
|
||||||
|
{
|
||||||
|
case FCVAR_DEVELOPMENTONLY:
|
||||||
|
return 9;
|
||||||
|
case FCVAR_GAMEDLL:
|
||||||
|
return 10;
|
||||||
|
case FCVAR_CLIENTDLL:
|
||||||
|
return 11;
|
||||||
|
case FCVAR_REPLICATED:
|
||||||
|
return 12;
|
||||||
|
case FCVAR_CHEAT:
|
||||||
|
return 13;
|
||||||
|
case FCVAR_RELEASE:
|
||||||
|
return 14;
|
||||||
|
case FCVAR_MATERIAL_SYSTEM_THREAD:
|
||||||
|
return 15;
|
||||||
|
case FCVAR_DEVELOPMENTONLY | FCVAR_GAMEDLL:
|
||||||
|
return 16;
|
||||||
|
case FCVAR_DEVELOPMENTONLY | FCVAR_CLIENTDLL:
|
||||||
|
return 17;
|
||||||
|
case FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED:
|
||||||
|
return 18;
|
||||||
|
case FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT:
|
||||||
|
return 19;
|
||||||
|
case FCVAR_DEVELOPMENTONLY | FCVAR_MATERIAL_SYSTEM_THREAD:
|
||||||
|
return 20;
|
||||||
|
case FCVAR_REPLICATED | FCVAR_CHEAT:
|
||||||
|
return 21;
|
||||||
|
case FCVAR_REPLICATED | FCVAR_RELEASE:
|
||||||
|
return 22;
|
||||||
|
case FCVAR_GAMEDLL | FCVAR_CHEAT:
|
||||||
|
return 23;
|
||||||
|
case FCVAR_GAMEDLL | FCVAR_RELEASE:
|
||||||
|
return 24;
|
||||||
|
case FCVAR_CLIENTDLL | FCVAR_CHEAT:
|
||||||
|
return 25;
|
||||||
|
case FCVAR_CLIENTDLL | FCVAR_RELEASE:
|
||||||
|
return 26;
|
||||||
|
case FCVAR_MATERIAL_SYSTEM_THREAD | FCVAR_CHEAT:
|
||||||
|
return 27;
|
||||||
|
case FCVAR_MATERIAL_SYSTEM_THREAD | FCVAR_RELEASE:
|
||||||
|
return 28;
|
||||||
|
case COMMAND_COMPLETION_MARKER:
|
||||||
|
return 29;
|
||||||
|
|
||||||
|
default: // Hit when flag is zero/non-indexed or 3+ bits are set.
|
||||||
|
|
||||||
|
const unsigned int v = __popcnt(flags);
|
||||||
|
switch (v)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return 0; // Pink checker texture (FCVAR_NONE)
|
||||||
|
case 1:
|
||||||
|
return 1; // Yellow checker texture (non-indexed).
|
||||||
|
default:
|
||||||
|
|
||||||
|
// If 3 or more bits are set, we test the flags
|
||||||
|
// and display the appropriate checker texture.
|
||||||
|
const bool mul = v > 2;
|
||||||
|
|
||||||
|
if (flags & FCVAR_DEVELOPMENTONLY)
|
||||||
|
{
|
||||||
|
return mul ? 4 : 3;
|
||||||
|
}
|
||||||
|
else if (flags & FCVAR_CHEAT)
|
||||||
|
{
|
||||||
|
return mul ? 6 : 5;
|
||||||
|
}
|
||||||
|
else if (flags & FCVAR_RELEASE && // RELEASE command but no context restriction.
|
||||||
|
!(flags & FCVAR_SERVER_CAN_EXECUTE) &&
|
||||||
|
!(flags & FCVAR_CLIENTCMD_CAN_EXECUTE))
|
||||||
|
{
|
||||||
|
return mul ? 8 : 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow checker texture (user needs to manually check flags).
|
||||||
|
// These commands are not restricted if ran from the same context.
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: adds an icon hint to the suggest panel
|
||||||
|
// Input : &cvarInfo -
|
||||||
|
// &flagIconHandles -
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
static void AddHint(const ConVarFlags::FlagDesc_t& cvarInfo, const vector<MODULERESOURCE>& flagIconHandles)
|
||||||
|
{
|
||||||
|
const int hintTexIdx = GetFlagTextureIndex(cvarInfo.bit);
|
||||||
|
const MODULERESOURCE& hintRes = flagIconHandles[hintTexIdx];
|
||||||
|
|
||||||
|
ImGui::Image(hintRes.m_idIcon, ImVec2(float(hintRes.m_nWidth), float(hintRes.m_nHeight)));
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("%s", cvarInfo.shortdesc);
|
||||||
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Purpose: draws the autocomplete panel with results based on user input
|
// Purpose: draws the autocomplete panel with results based on user input
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -450,16 +554,6 @@ void CConsole::DrawAutoCompletePanel(void)
|
|||||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_RectOnly) &&
|
if (ImGui::IsItemHovered(ImGuiHoveredFlags_RectOnly) &&
|
||||||
suggest.flags != COMMAND_COMPLETION_MARKER)
|
suggest.flags != COMMAND_COMPLETION_MARKER)
|
||||||
{
|
{
|
||||||
const std::function<void(const ConVarFlags::FlagDesc_t&)> fnAddHint = [&](const ConVarFlags::FlagDesc_t& cvarInfo)
|
|
||||||
{
|
|
||||||
const int hintTexIdx = GetFlagTextureIndex(cvarInfo.bit);
|
|
||||||
const MODULERESOURCE& hintRes = m_vecFlagIcons[hintTexIdx];
|
|
||||||
|
|
||||||
ImGui::Image(hintRes.m_idIcon, ImVec2(float(hintRes.m_nWidth), float(hintRes.m_nHeight)));
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Text("%s", cvarInfo.shortdesc);
|
|
||||||
};
|
|
||||||
|
|
||||||
ImGui::BeginTooltip();
|
ImGui::BeginTooltip();
|
||||||
bool isFlagSet = false;
|
bool isFlagSet = false;
|
||||||
|
|
||||||
@ -470,12 +564,12 @@ void CConsole::DrawAutoCompletePanel(void)
|
|||||||
if (suggest.flags & info.bit)
|
if (suggest.flags & info.bit)
|
||||||
{
|
{
|
||||||
isFlagSet = true;
|
isFlagSet = true;
|
||||||
fnAddHint(info);
|
AddHint(info, m_vecFlagIcons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isFlagSet) // Display the FCVAR_NONE flag if no flags are set.
|
if (!isFlagSet) // Display the FCVAR_NONE flag if no flags are set.
|
||||||
{
|
{
|
||||||
fnAddHint(g_ConVarFlags.m_FlagsToDesc[0]);
|
AddHint(g_ConVarFlags.m_FlagsToDesc[0], m_vecFlagIcons);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndTooltip();
|
ImGui::EndTooltip();
|
||||||
@ -623,6 +717,29 @@ void CConsole::ResetAutoCompleteData(void)
|
|||||||
m_vecSuggest.clear();
|
m_vecSuggest.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: format appends the value string
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
static void AppendValueString(string& targetString, const char* const toAppend)
|
||||||
|
{
|
||||||
|
targetString.append(" = ["); // Assign current value to string if its a ConVar.
|
||||||
|
targetString.append(toAppend);
|
||||||
|
targetString.append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: format appends the doc string
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
static void AppendDocString(string& targetString, const char* const toAppend)
|
||||||
|
{
|
||||||
|
if (VALID_CHARSTAR(toAppend))
|
||||||
|
{
|
||||||
|
targetString.append(" - \"");
|
||||||
|
targetString.append(toAppend);
|
||||||
|
targetString.append("\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Purpose: find ConVars/ConCommands from user input and add to vector
|
// Purpose: find ConVars/ConCommands from user input and add to vector
|
||||||
// - Ignores ConVars marked FCVAR_HIDDEN
|
// - Ignores ConVars marked FCVAR_HIDDEN
|
||||||
@ -658,28 +775,16 @@ void CConsole::CreateSuggestionsFromPartial(void)
|
|||||||
{
|
{
|
||||||
string docString;
|
string docString;
|
||||||
|
|
||||||
|
// Assign current value to string if its a ConVar.
|
||||||
if (!commandBase->IsCommand())
|
if (!commandBase->IsCommand())
|
||||||
{
|
{
|
||||||
const ConVar* conVar = reinterpret_cast<const ConVar*>(commandBase);
|
const ConVar* const conVar = reinterpret_cast<const ConVar*>(commandBase);
|
||||||
|
AppendValueString(docString, conVar->GetString());
|
||||||
docString = " = ["; // Assign current value to string if its a ConVar.
|
|
||||||
docString.append(conVar->GetString());
|
|
||||||
docString.append("]");
|
|
||||||
}
|
}
|
||||||
if (con_suggest_helptext.GetBool())
|
if (con_suggest_helptext.GetBool())
|
||||||
{
|
{
|
||||||
std::function<void(string& , const char*)> fnAppendDocString = [&](string& targetString, const char* toAppend)
|
AppendDocString(docString, commandBase->GetHelpText());
|
||||||
{
|
AppendDocString(docString, commandBase->GetUsageText());
|
||||||
if (VALID_CHARSTAR(toAppend))
|
|
||||||
{
|
|
||||||
targetString.append(" - \"");
|
|
||||||
targetString.append(toAppend);
|
|
||||||
targetString.append("\"");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fnAppendDocString(docString, commandBase->GetHelpText());
|
|
||||||
fnAppendDocString(docString, commandBase->GetUsageText());
|
|
||||||
}
|
}
|
||||||
m_vecSuggest.push_back(ConAutoCompleteSuggest_s(commandName + docString, commandBase->GetFlags()));
|
m_vecSuggest.push_back(ConAutoCompleteSuggest_s(commandName + docString, commandBase->GetFlags()));
|
||||||
}
|
}
|
||||||
@ -828,95 +933,6 @@ bool CConsole::LoadFlagIcons(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Purpose: returns flag texture index for CommandBase (must be aligned with resource.h!)
|
|
||||||
// in the future we should build the texture procedurally with use of popcnt.
|
|
||||||
// Input : nFlags -
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
int CConsole::GetFlagTextureIndex(const int flags) const
|
|
||||||
{
|
|
||||||
switch (flags) // All indices for single/dual flag textures.
|
|
||||||
{
|
|
||||||
case FCVAR_DEVELOPMENTONLY:
|
|
||||||
return 9;
|
|
||||||
case FCVAR_GAMEDLL:
|
|
||||||
return 10;
|
|
||||||
case FCVAR_CLIENTDLL:
|
|
||||||
return 11;
|
|
||||||
case FCVAR_REPLICATED:
|
|
||||||
return 12;
|
|
||||||
case FCVAR_CHEAT:
|
|
||||||
return 13;
|
|
||||||
case FCVAR_RELEASE:
|
|
||||||
return 14;
|
|
||||||
case FCVAR_MATERIAL_SYSTEM_THREAD:
|
|
||||||
return 15;
|
|
||||||
case FCVAR_DEVELOPMENTONLY | FCVAR_GAMEDLL:
|
|
||||||
return 16;
|
|
||||||
case FCVAR_DEVELOPMENTONLY | FCVAR_CLIENTDLL:
|
|
||||||
return 17;
|
|
||||||
case FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED:
|
|
||||||
return 18;
|
|
||||||
case FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT:
|
|
||||||
return 19;
|
|
||||||
case FCVAR_DEVELOPMENTONLY | FCVAR_MATERIAL_SYSTEM_THREAD:
|
|
||||||
return 20;
|
|
||||||
case FCVAR_REPLICATED | FCVAR_CHEAT:
|
|
||||||
return 21;
|
|
||||||
case FCVAR_REPLICATED | FCVAR_RELEASE:
|
|
||||||
return 22;
|
|
||||||
case FCVAR_GAMEDLL | FCVAR_CHEAT:
|
|
||||||
return 23;
|
|
||||||
case FCVAR_GAMEDLL | FCVAR_RELEASE:
|
|
||||||
return 24;
|
|
||||||
case FCVAR_CLIENTDLL | FCVAR_CHEAT:
|
|
||||||
return 25;
|
|
||||||
case FCVAR_CLIENTDLL | FCVAR_RELEASE:
|
|
||||||
return 26;
|
|
||||||
case FCVAR_MATERIAL_SYSTEM_THREAD | FCVAR_CHEAT:
|
|
||||||
return 27;
|
|
||||||
case FCVAR_MATERIAL_SYSTEM_THREAD | FCVAR_RELEASE:
|
|
||||||
return 28;
|
|
||||||
case COMMAND_COMPLETION_MARKER:
|
|
||||||
return 29;
|
|
||||||
|
|
||||||
default: // Hit when flag is zero/non-indexed or 3+ bits are set.
|
|
||||||
|
|
||||||
const unsigned int v = __popcnt(flags);
|
|
||||||
switch (v)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
return 0; // Pink checker texture (FCVAR_NONE)
|
|
||||||
case 1:
|
|
||||||
return 1; // Yellow checker texture (non-indexed).
|
|
||||||
default:
|
|
||||||
|
|
||||||
// If 3 or more bits are set, we test the flags
|
|
||||||
// and display the appropriate checker texture.
|
|
||||||
bool mul = v > 2;
|
|
||||||
|
|
||||||
if (flags & FCVAR_DEVELOPMENTONLY)
|
|
||||||
{
|
|
||||||
return mul ? 4 : 3;
|
|
||||||
}
|
|
||||||
else if (flags & FCVAR_CHEAT)
|
|
||||||
{
|
|
||||||
return mul ? 6 : 5;
|
|
||||||
}
|
|
||||||
else if (flags & FCVAR_RELEASE && // RELEASE command but no context restriction.
|
|
||||||
!(flags & FCVAR_SERVER_CAN_EXECUTE) &&
|
|
||||||
!(flags & FCVAR_CLIENTCMD_CAN_EXECUTE))
|
|
||||||
{
|
|
||||||
return mul ? 8 : 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rainbow checker texture (user needs to manually check flags).
|
|
||||||
// These commands are not restricted if ran from the same context.
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Purpose: console input box callback
|
// Purpose: console input box callback
|
||||||
// Input : *iData -
|
// Input : *iData -
|
||||||
|
@ -37,7 +37,6 @@ private:
|
|||||||
void DetermineAutoCompleteWindowRect(void);
|
void DetermineAutoCompleteWindowRect(void);
|
||||||
|
|
||||||
bool LoadFlagIcons(void);
|
bool LoadFlagIcons(void);
|
||||||
int GetFlagTextureIndex(const int flags) const;
|
|
||||||
|
|
||||||
int TextEditCallback(ImGuiInputTextCallbackData* pData);
|
int TextEditCallback(ImGuiInputTextCallbackData* pData);
|
||||||
static int TextEditCallbackStub(ImGuiInputTextCallbackData* pData);
|
static int TextEditCallbackStub(ImGuiInputTextCallbackData* pData);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user