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.
This commit is contained in:
Robert Müller 2022-11-29 22:23:58 +01:00
parent d76755db06
commit 0688355d7b
2 changed files with 9 additions and 15 deletions

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