6075: Fix key reader text flashing for one frame, refactoring r=def- a=Robyt3

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.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


6076: Fix stored commands using original callback instead of the chain, fix client crash when launching with `screenshot` command r=def- a=Robyt3



## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2022-11-29 23:06:01 +00:00 committed by GitHub
commit 3012a42ea0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 21 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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);