From 0688355d7b8e28eace82e469959f6b63183ad7ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 29 Nov 2022 22:23:58 +0100 Subject: [PATCH 1/3] Fix key reader text flashing for one frame, refactoring The key reader was displaying the old key for a frame. It now shows the new key immediately without flashing the old one after changing a bind. Refactoring: - The if-branches are restructured to be the same as on upstream. - The function `GetKeyBindModifiersName` can be called without an additional check, because it returns an empty string when no modifier is pressed. - The unused parameter `Checked` of the `DoButton_KeySelect` function is removed. From teeworlds/teeworlds#2877. --- src/game/client/components/menus.cpp | 22 ++++++++-------------- src/game/client/components/menus.h | 2 +- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 5ed16a4b8..3bfc271d1 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -184,7 +184,7 @@ int CMenus::DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, return UI()->DoButtonLogic(pButtonContainer, Checked, pRect); } -void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect) +void CMenus::DoButton_KeySelect(const void *pID, const char *pText, const CUIRect *pRect) { pRect->Draw(ColorRGBA(1, 1, 1, 0.5f * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 5.0f); CUIRect Temp; @@ -644,22 +644,16 @@ int CMenus::DoKeyReader(void *pID, const CUIRect *pRect, int Key, int ModifierCo // draw if(UI()->CheckActiveItem(pID) && s_ButtonUsed == 0) - DoButton_KeySelect(pID, "???", 0, pRect); + DoButton_KeySelect(pID, "???", pRect); + else if(NewKey == 0) + DoButton_KeySelect(pID, "", pRect); else { - if(Key) - { - char aBuf[64]; - if(*pNewModifierCombination) - str_format(aBuf, sizeof(aBuf), "%s%s", CBinds::GetKeyBindModifiersName(*pNewModifierCombination), Input()->KeyName(Key)); - else - str_copy(aBuf, Input()->KeyName(Key)); - - DoButton_KeySelect(pID, aBuf, 0, pRect); - } - else - DoButton_KeySelect(pID, "", 0, pRect); + char aBuf[64]; + str_format(aBuf, sizeof(aBuf), "%s%s", CBinds::GetKeyBindModifiersName(*pNewModifierCombination), Input()->KeyName(NewKey)); + DoButton_KeySelect(pID, aBuf, pRect); } + return NewKey; } diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index e271a0c58..86b637b20 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -94,7 +94,7 @@ class CMenus : public CComponent int DoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, bool UseScroll, int Current, int Min, int Max, int Step, float Scale, bool IsHex, float Round, ColorRGBA *pColor); int DoButton_GridHeader(const void *pID, const char *pText, int Checked, const CUIRect *pRect); - void DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect); + void DoButton_KeySelect(const void *pID, const char *pText, const CUIRect *pRect); int DoKeyReader(void *pID, const CUIRect *pRect, int Key, int ModifierCombination, int *pNewModifierCombination); void DoSettingsControlsButtons(int Start, int Stop, CUIRect View); From e07bd45e27ea453115c32aa54c4094d071eaccdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 29 Nov 2022 22:39:23 +0100 Subject: [PATCH 2/3] Fix stored commands using original callback instead of the chain When stored commands (`CFGFLAG_STORE`) were executed with `CConsole::StoreCommands(false)`, the associated chained commands were not properly executed, if they were chained after the command has been stored (e.g. in `CMenus::OnInit`). Storing the command saves the current callback and userdata, which were overridden by the chain callback and userdata, but the stored callback and userdata were not updated. This is fixed by storing a pointer to the command itself, which will be updated when it is chained. From teeworlds/teeworlds#2572. --- src/engine/shared/console.cpp | 5 ++--- src/engine/shared/console.h | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index c467331c2..9dd0b6663 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -504,8 +504,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, bo else if(m_StoreCommands && pCommand->m_Flags & CFGFLAG_STORE) { m_ExecutionQueue.AddEntry(); - m_ExecutionQueue.m_pLast->m_pfnCommandCallback = pCommand->m_pfnCallback; - m_ExecutionQueue.m_pLast->m_pCommandUserData = pCommand->m_pUserData; + m_ExecutionQueue.m_pLast->m_pCommand = pCommand; m_ExecutionQueue.m_pLast->m_Result = Result; } else @@ -1249,7 +1248,7 @@ void CConsole::StoreCommands(bool Store) if(!Store) { for(CExecutionQueue::CQueueEntry *pEntry = m_ExecutionQueue.m_pFirst; pEntry; pEntry = pEntry->m_pNext) - pEntry->m_pfnCommandCallback(&pEntry->m_Result, pEntry->m_pCommandUserData); + pEntry->m_pCommand->m_pfnCallback(&pEntry->m_Result, pEntry->m_pCommand->m_pUserData); m_ExecutionQueue.Reset(); } m_StoreCommands = Store; diff --git a/src/engine/shared/console.h b/src/engine/shared/console.h index f55f77e5b..2a80d0ba5 100644 --- a/src/engine/shared/console.h +++ b/src/engine/shared/console.h @@ -164,8 +164,7 @@ class CConsole : public IConsole struct CQueueEntry { CQueueEntry *m_pNext; - FCommandCallback m_pfnCommandCallback; - void *m_pCommandUserData; + CCommand *m_pCommand; CResult m_Result; } * m_pFirst, *m_pLast; From 2e2cb47674e47f8ecee16893818f40d3356b5b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 29 Nov 2022 23:08:52 +0100 Subject: [PATCH 3/3] Fix client crash when launching with `screenshot` command The client crashes when launching with `screenshot` in the command line, as the graphics are not available when the command is executed. This is fixed by storing the command, so it's executed when everything is ready. --- src/engine/client/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 875ffdec3..ee14f18f5 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -4371,7 +4371,7 @@ void CClient::RegisterCommands() m_pConsole->Register("connect", "r[host|ip]", CFGFLAG_CLIENT, Con_Connect, this, "Connect to the specified host/ip"); m_pConsole->Register("disconnect", "", CFGFLAG_CLIENT, Con_Disconnect, this, "Disconnect from the server"); m_pConsole->Register("ping", "", CFGFLAG_CLIENT, Con_Ping, this, "Ping the current server"); - m_pConsole->Register("screenshot", "", CFGFLAG_CLIENT, Con_Screenshot, this, "Take a screenshot"); + m_pConsole->Register("screenshot", "", CFGFLAG_CLIENT | CFGFLAG_STORE, Con_Screenshot, this, "Take a screenshot"); m_pConsole->Register("reset", "s[config-name]", CFGFLAG_CLIENT | CFGFLAG_STORE, Con_Reset, this, "Reset a config its default value"); #if defined(CONF_VIDEORECORDER)