Allow 'bind x' to be used like 'binds x'

This commit is contained in:
ArijanJ 2023-06-27 09:46:32 +02:00
parent 67ddd93401
commit 7e3ad335be

View file

@ -255,7 +255,7 @@ void CBinds::OnConsoleInit()
if(pConfigManager)
pConfigManager->RegisterCallback(ConfigSaveCallback, this);
Console()->Register("bind", "s[key] r[command]", CFGFLAG_CLIENT, ConBind, this, "Bind key to execute the command");
Console()->Register("bind", "s[key] ?r[command]", CFGFLAG_CLIENT, ConBind, this, "Bind key to execute a command or view keybindings");
Console()->Register("binds", "?s[key]", CFGFLAG_CLIENT, ConBinds, this, "Print command executed by this keybinding or all binds");
Console()->Register("unbind", "s[key]", CFGFLAG_CLIENT, ConUnbind, this, "Unbind key");
Console()->Register("unbindall", "", CFGFLAG_CLIENT, ConUnbindAll, this, "Unbind all keys");
@ -279,6 +279,20 @@ void CBinds::ConBind(IConsole::IResult *pResult, void *pUserData)
return;
}
if(pResult->NumArguments() == 1)
{
char aBuf[256];
const char *pKeyName = pResult->GetString(0);
if(!pBinds->m_aapKeyBindings[Modifier][KeyID])
str_format(aBuf, sizeof(aBuf), "%s (%d) is not bound", pKeyName, KeyID);
else
str_format(aBuf, sizeof(aBuf), "%s (%d) = %s", pKeyName, KeyID, pBinds->m_aapKeyBindings[Modifier][KeyID]);
pBinds->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "binds", aBuf, gs_BindPrintColor);
return;
}
pBinds->Bind(KeyID, pResult->GetString(1), false, Modifier);
}