mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Port CUI::ConsumeHotkey
from upstream
Move hotkey/input handling from `CMenus` to `CUI`. Using the `ConsumeHotkey` method ensures that each hotkey is only handled once. By also handling the mouse scroll wheel as hotkeys, this fixes the scroll keys activating scroll regions while the controls binder is active.
This commit is contained in:
parent
59db32e9c2
commit
e7c3ce186f
|
@ -72,9 +72,6 @@ CMenus::CMenus()
|
|||
m_MenuActive = true;
|
||||
m_ShowStart = true;
|
||||
|
||||
m_EscapePressed = false;
|
||||
m_EnterPressed = false;
|
||||
m_DeletePressed = false;
|
||||
m_NumInputEvents = 0;
|
||||
|
||||
str_copy(m_aCurrentDemoFolder, "demos");
|
||||
|
@ -1070,7 +1067,7 @@ bool CMenus::CanDisplayWarning()
|
|||
|
||||
void CMenus::RenderColorPicker()
|
||||
{
|
||||
if(m_EscapePressed)
|
||||
if(UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
{
|
||||
ms_ColorPicker.m_Active = false;
|
||||
ms_ValueSelectorTextMode = false;
|
||||
|
@ -1347,7 +1344,7 @@ int CMenus::Render()
|
|||
{
|
||||
Screen.HSplitTop(24.0f, &TabBar, &MainView);
|
||||
|
||||
if(Client()->State() == IClient::STATE_OFFLINE && m_EscapePressed)
|
||||
if(Client()->State() == IClient::STATE_OFFLINE && UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
{
|
||||
m_ShowStart = true;
|
||||
}
|
||||
|
@ -1670,11 +1667,11 @@ int CMenus::Render()
|
|||
No.VMargin(20.0f, &No);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_NONE;
|
||||
|
||||
static CButtonContainer s_ButtonTryAgain;
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
m_Popup = POPUP_NONE;
|
||||
Client()->Quit();
|
||||
|
@ -1693,11 +1690,11 @@ int CMenus::Render()
|
|||
No.VMargin(20.0f, &No);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_NONE;
|
||||
|
||||
static CButtonContainer s_ButtonTryAgain;
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
Client()->Disconnect();
|
||||
}
|
||||
else if(m_Popup == POPUP_DISCONNECT_DUMMY)
|
||||
|
@ -1713,11 +1710,11 @@ int CMenus::Render()
|
|||
No.VMargin(20.0f, &No);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_NONE;
|
||||
|
||||
static CButtonContainer s_ButtonTryAgain;
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
Client()->DummyDisconnect(0);
|
||||
m_Popup = POPUP_NONE;
|
||||
|
@ -1738,11 +1735,11 @@ int CMenus::Render()
|
|||
Abort.VMargin(20.0f, &Abort);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_NONE;
|
||||
|
||||
static CButtonContainer s_ButtonTryAgain;
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
Client()->Connect(g_Config.m_UiServerAddress, g_Config.m_Password);
|
||||
}
|
||||
|
@ -1767,7 +1764,7 @@ int CMenus::Render()
|
|||
Part.VMargin(120.0f, &Part);
|
||||
|
||||
static CButtonContainer s_Button;
|
||||
if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || (m_EnterPressed && m_Popup != POPUP_CONNECTING))
|
||||
if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
{
|
||||
Client()->Disconnect();
|
||||
m_Popup = POPUP_NONE;
|
||||
|
@ -1837,7 +1834,7 @@ int CMenus::Render()
|
|||
Part.VMargin(120.0f, &Part);
|
||||
|
||||
static CButtonContainer s_Button;
|
||||
if(DoButton_Menu(&s_Button, Localize("Ok"), 0, &Part) || m_EscapePressed || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_Button, Localize("Ok"), 0, &Part) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
m_Popup = POPUP_FIRST_LAUNCH;
|
||||
}
|
||||
else if(m_Popup == POPUP_COUNTRY)
|
||||
|
@ -1885,14 +1882,14 @@ int CMenus::Render()
|
|||
Part.VMargin(120.0f, &Part);
|
||||
|
||||
static CButtonContainer s_Button;
|
||||
if(DoButton_Menu(&s_Button, Localize("Ok"), 0, &Part) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_Button, Localize("Ok"), 0, &Part) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
g_Config.m_BrFilterCountryIndex = CurSelection;
|
||||
Client()->ServerBrowserUpdate();
|
||||
m_Popup = POPUP_NONE;
|
||||
}
|
||||
|
||||
if(m_EscapePressed)
|
||||
if(UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
{
|
||||
CurSelection = g_Config.m_BrFilterCountryIndex;
|
||||
m_Popup = POPUP_NONE;
|
||||
|
@ -1911,11 +1908,11 @@ int CMenus::Render()
|
|||
No.VMargin(20.0f, &No);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_NONE;
|
||||
|
||||
static CButtonContainer s_ButtonTryAgain;
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
m_Popup = POPUP_NONE;
|
||||
// delete demo
|
||||
|
@ -1946,11 +1943,11 @@ int CMenus::Render()
|
|||
Abort.VMargin(20.0f, &Abort);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_NONE;
|
||||
|
||||
static CButtonContainer s_ButtonOk;
|
||||
if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
m_Popup = POPUP_NONE;
|
||||
// rename demo
|
||||
|
@ -2005,11 +2002,11 @@ int CMenus::Render()
|
|||
Abort.VMargin(20.0f, &Abort);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_NONE;
|
||||
|
||||
static CButtonContainer s_ButtonOk;
|
||||
if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
m_Popup = POPUP_NONE;
|
||||
// name video
|
||||
|
@ -2125,11 +2122,11 @@ int CMenus::Render()
|
|||
No.VMargin(20.0f, &No);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_RENDER_DEMO;
|
||||
|
||||
static CButtonContainer s_ButtonTryAgain;
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
m_Popup = POPUP_NONE;
|
||||
// render video
|
||||
|
@ -2154,11 +2151,11 @@ int CMenus::Render()
|
|||
No.VMargin(20.0f, &No);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_NONE;
|
||||
|
||||
static CButtonContainer s_ButtonTryAgain;
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
m_Popup = POPUP_NONE;
|
||||
// remove friend
|
||||
|
@ -2183,7 +2180,7 @@ int CMenus::Render()
|
|||
Join.VMargin(20.0f, &Join);
|
||||
|
||||
static CButtonContainer s_JoinTutorialButton;
|
||||
if(DoButton_Menu(&s_JoinTutorialButton, Localize("Join Tutorial Server"), 0, &Join) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_JoinTutorialButton, Localize("Join Tutorial Server"), 0, &Join) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
m_JoinTutorial = true;
|
||||
Client()->RequestDDNetInfo();
|
||||
|
@ -2191,7 +2188,7 @@ int CMenus::Render()
|
|||
}
|
||||
|
||||
static CButtonContainer s_SkipTutorialButton;
|
||||
if(DoButton_Menu(&s_SkipTutorialButton, Localize("Skip Tutorial"), 0, &Skip) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_SkipTutorialButton, Localize("Skip Tutorial"), 0, &Skip) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
{
|
||||
m_JoinTutorial = false;
|
||||
Client()->RequestDDNetInfo();
|
||||
|
@ -2236,11 +2233,11 @@ int CMenus::Render()
|
|||
No.VMargin(20.0f, &No);
|
||||
|
||||
static CButtonContainer s_ButtonNo;
|
||||
if(DoButton_Menu(&s_ButtonNo, Localize("No"), 0, &No) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonNo, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_Popup = POPUP_FIRST_LAUNCH;
|
||||
|
||||
static CButtonContainer s_ButtonYes;
|
||||
if(DoButton_Menu(&s_ButtonYes, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonYes, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
m_Popup = POPUP_NONE;
|
||||
}
|
||||
else if(m_Popup == POPUP_WARNING)
|
||||
|
@ -2250,7 +2247,7 @@ int CMenus::Render()
|
|||
Part.VMargin(120.0f, &Part);
|
||||
|
||||
static CButtonContainer s_Button;
|
||||
if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed || (time_get_nanoseconds() - m_PopupWarningLastTime >= m_PopupWarningDuration))
|
||||
if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER) || (time_get_nanoseconds() - m_PopupWarningLastTime >= m_PopupWarningDuration))
|
||||
{
|
||||
m_Popup = POPUP_NONE;
|
||||
SetActive(false);
|
||||
|
@ -2269,14 +2266,14 @@ int CMenus::Render()
|
|||
No.VMargin(20.0f, &No);
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
{
|
||||
m_Popup = POPUP_NONE;
|
||||
m_aNextServer[0] = '\0';
|
||||
}
|
||||
|
||||
static CButtonContainer s_ButtonTryAgain;
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
Client()->Connect(m_aNextServer);
|
||||
}
|
||||
else
|
||||
|
@ -2286,7 +2283,7 @@ int CMenus::Render()
|
|||
Part.VMargin(120.0f, &Part);
|
||||
|
||||
static CButtonContainer s_Button;
|
||||
if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
if(m_Popup == POPUP_DISCONNECTED && Client()->m_ReconnectTime > 0)
|
||||
Client()->m_ReconnectTime = 0;
|
||||
|
@ -2429,33 +2426,20 @@ bool CMenus::OnCursorMove(float x, float y, IInput::ECursorType CursorType)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CMenus::OnInput(IInput::CEvent e)
|
||||
bool CMenus::OnInput(IInput::CEvent Event)
|
||||
{
|
||||
// special handle esc and enter for popup purposes
|
||||
if(e.m_Flags & IInput::FLAG_PRESS)
|
||||
if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE)
|
||||
{
|
||||
if(e.m_Key == KEY_ESCAPE)
|
||||
{
|
||||
m_EscapePressed = true;
|
||||
if(m_Popup == POPUP_NONE)
|
||||
SetActive(!IsActive());
|
||||
return true;
|
||||
}
|
||||
SetActive(!IsActive());
|
||||
UI()->OnInput(Event);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(IsActive())
|
||||
{
|
||||
if(e.m_Flags & IInput::FLAG_PRESS)
|
||||
{
|
||||
// special for popups
|
||||
if(e.m_Key == KEY_RETURN || e.m_Key == KEY_KP_ENTER)
|
||||
m_EnterPressed = true;
|
||||
else if(e.m_Key == KEY_DELETE)
|
||||
m_DeletePressed = true;
|
||||
}
|
||||
|
||||
if(m_NumInputEvents < MAX_INPUTEVENTS)
|
||||
m_aInputEvents[m_NumInputEvents++] = e;
|
||||
m_aInputEvents[m_NumInputEvents++] = Event;
|
||||
UI()->OnInput(Event);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -2526,11 +2510,9 @@ void CMenus::OnRender()
|
|||
|
||||
if(!IsActive())
|
||||
{
|
||||
m_EscapePressed = false;
|
||||
m_EnterPressed = false;
|
||||
m_DeletePressed = false;
|
||||
m_NumInputEvents = 0;
|
||||
UI()->FinishCheck();
|
||||
UI()->ClearHotkeys();
|
||||
m_NumInputEvents = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2581,10 +2563,7 @@ void CMenus::OnRender()
|
|||
}
|
||||
|
||||
UI()->FinishCheck();
|
||||
|
||||
m_EscapePressed = false;
|
||||
m_EnterPressed = false;
|
||||
m_DeletePressed = false;
|
||||
UI()->ClearHotkeys();
|
||||
m_NumInputEvents = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -348,11 +348,6 @@ protected:
|
|||
bool m_NeedSendDummyinfo;
|
||||
int m_SettingPlayerPage;
|
||||
|
||||
//
|
||||
bool m_EscapePressed;
|
||||
bool m_EnterPressed;
|
||||
bool m_DeletePressed;
|
||||
|
||||
// for map download popup
|
||||
int64_t m_DownloadLastCheckTime;
|
||||
int m_DownloadLastCheckSize;
|
||||
|
|
|
@ -188,12 +188,10 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
|
|||
|
||||
s_ScrollValue = UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue);
|
||||
|
||||
if(Input()->KeyPress(KEY_TAB) && m_pClient->m_GameConsole.IsClosed())
|
||||
if(UI()->ConsumeHotkey(CUI::HOTKEY_TAB))
|
||||
{
|
||||
if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT))
|
||||
g_Config.m_UiToolboxPage = (g_Config.m_UiToolboxPage + 3 - 1) % 3;
|
||||
else
|
||||
g_Config.m_UiToolboxPage = (g_Config.m_UiToolboxPage + 3 + 1) % 3;
|
||||
const int Direction = Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT) ? -1 : 1;
|
||||
g_Config.m_UiToolboxPage = (g_Config.m_UiToolboxPage + 3 + Direction) % 3;
|
||||
}
|
||||
|
||||
if(HandleListInputs(View, s_ScrollValue, 3.0f, &m_ScrollOffset, s_aCols[0].m_Rect.h, m_SelectedIndex, NumServers))
|
||||
|
@ -658,7 +656,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
|
|||
|
||||
if(DoButtonMenu(
|
||||
m_ConnectButton, &s_JoinButton, []() -> const char * { return Localize("Connect"); }, 0, &ButtonConnect, false, false, IGraphics::CORNER_ALL, 5, 0, vec4(0.7f, 1, 0.7f, 0.1f), vec4(0.7f, 1, 0.7f, 0.2f)) ||
|
||||
m_EnterPressed)
|
||||
UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
|
||||
{
|
||||
|
@ -667,7 +665,6 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
|
|||
}
|
||||
else
|
||||
Client()->Connect(g_Config.m_UiServerAddress);
|
||||
m_EnterPressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1311,7 +1308,7 @@ void CMenus::RenderServerbrowserFriends(CUIRect View)
|
|||
m_FriendlistSelectedIndex = UiDoListboxEnd(&s_ScrollValue, &Activated);
|
||||
|
||||
// activate found server with friend
|
||||
if(Activated && !m_EnterPressed && m_vFriends[m_FriendlistSelectedIndex].m_NumFound)
|
||||
if(Activated && m_vFriends[m_FriendlistSelectedIndex].m_NumFound)
|
||||
{
|
||||
bool Found = false;
|
||||
int NumServers = ServerBrowser()->NumSortedServers();
|
||||
|
|
|
@ -154,11 +154,11 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
|||
static int s_RemoveChat = 0;
|
||||
|
||||
static CButtonContainer s_ButtonAbort;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed)
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
|
||||
m_DemoPlayerState = DEMOPLAYER_NONE;
|
||||
|
||||
static CButtonContainer s_ButtonOk;
|
||||
if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || m_EnterPressed)
|
||||
if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
||||
{
|
||||
if(str_comp(m_vDemos[m_DemolistSelectedIndex].m_aFilename, m_aCurrentDemoFile) == 0)
|
||||
str_copy(m_aDemoPlayerPopupHint, Localize("Please use a different name"));
|
||||
|
@ -705,7 +705,7 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected,
|
|||
{
|
||||
gs_ListBoxDoneEvents = 1;
|
||||
|
||||
if(m_EnterPressed || (DoubleClickable && Input()->MouseDoubleClick()))
|
||||
if(UI()->ConsumeHotkey(CUI::HOTKEY_ENTER) || (DoubleClickable && Input()->MouseDoubleClick()))
|
||||
{
|
||||
gs_ListBoxItemActivated = true;
|
||||
UI()->SetActiveItem(nullptr);
|
||||
|
@ -1264,7 +1264,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
|||
UI()->ClipDisable();
|
||||
|
||||
bool Activated = false;
|
||||
if(m_EnterPressed || (DoubleClicked && Input()->MouseDoubleClick()))
|
||||
if(UI()->ConsumeHotkey(CUI::HOTKEY_ENTER) || (DoubleClicked && Input()->MouseDoubleClick()))
|
||||
{
|
||||
UI()->SetActiveItem(nullptr);
|
||||
Activated = true;
|
||||
|
@ -1334,7 +1334,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
|||
if(!m_DemolistSelectedIsDir)
|
||||
{
|
||||
static CButtonContainer s_DeleteButton;
|
||||
if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed || (Input()->KeyPress(KEY_D) && m_pClient->m_GameConsole.IsClosed()))
|
||||
if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || UI()->ConsumeHotkey(CUI::HOTKEY_DELETE) || (Input()->KeyPress(KEY_D) && m_pClient->m_GameConsole.IsClosed()))
|
||||
{
|
||||
if(m_DemolistSelectedIndex >= 0)
|
||||
{
|
||||
|
|
|
@ -116,9 +116,10 @@ void CMenus::RenderStartMenu(CUIRect MainView)
|
|||
|
||||
Menu.HSplitBottom(40.0f, &Menu, &Button);
|
||||
static CButtonContainer s_QuitButton;
|
||||
if(DoButton_Menu(&s_QuitButton, Localize("Quit"), 0, &Button, 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || m_EscapePressed || CheckHotKey(KEY_Q))
|
||||
bool UsedEscape = false;
|
||||
if(DoButton_Menu(&s_QuitButton, Localize("Quit"), 0, &Button, 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || (UsedEscape = UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE)) || CheckHotKey(KEY_Q))
|
||||
{
|
||||
if(m_EscapePressed || m_pClient->Editor()->HasUnsavedData() || (Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0))
|
||||
if(UsedEscape || m_pClient->Editor()->HasUnsavedData() || (Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0))
|
||||
{
|
||||
m_Popup = POPUP_QUIT;
|
||||
}
|
||||
|
@ -192,7 +193,7 @@ void CMenus::RenderStartMenu(CUIRect MainView)
|
|||
Menu.HSplitBottom(5.0f, &Menu, 0); // little space
|
||||
Menu.HSplitBottom(40.0f, &Menu, &Button);
|
||||
static CButtonContainer s_PlayButton;
|
||||
if(DoButton_Menu(&s_PlayButton, Localize("Play", "Start menu"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "play_game" : 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || m_EnterPressed || CheckHotKey(KEY_P))
|
||||
if(DoButton_Menu(&s_PlayButton, Localize("Play", "Start menu"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "play_game" : 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER) || CheckHotKey(KEY_P))
|
||||
{
|
||||
NewPage = g_Config.m_UiPage >= PAGE_INTERNET && g_Config.m_UiPage <= PAGE_KOG ? g_Config.m_UiPage : PAGE_DDNET;
|
||||
}
|
||||
|
|
|
@ -244,6 +244,42 @@ void CUI::ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType)
|
|||
*pY *= Factor;
|
||||
}
|
||||
|
||||
bool CUI::ConsumeHotkey(EHotkey Hotkey)
|
||||
{
|
||||
const bool Pressed = m_HotkeysPressed & Hotkey;
|
||||
m_HotkeysPressed &= ~Hotkey;
|
||||
return Pressed;
|
||||
}
|
||||
|
||||
bool CUI::OnInput(const IInput::CEvent &Event)
|
||||
{
|
||||
if(!Enabled())
|
||||
return false;
|
||||
|
||||
if(Event.m_Flags & IInput::FLAG_PRESS)
|
||||
{
|
||||
unsigned LastHotkeysPressed = m_HotkeysPressed;
|
||||
if(Event.m_Key == KEY_RETURN || Event.m_Key == KEY_KP_ENTER)
|
||||
m_HotkeysPressed |= HOTKEY_ENTER;
|
||||
else if(Event.m_Key == KEY_ESCAPE)
|
||||
m_HotkeysPressed |= HOTKEY_ESCAPE;
|
||||
else if(Event.m_Key == KEY_TAB && !Input()->KeyIsPressed(KEY_LALT) && !Input()->KeyIsPressed(KEY_RALT))
|
||||
m_HotkeysPressed |= HOTKEY_TAB;
|
||||
else if(Event.m_Key == KEY_DELETE)
|
||||
m_HotkeysPressed |= HOTKEY_DELETE;
|
||||
else if(Event.m_Key == KEY_UP)
|
||||
m_HotkeysPressed |= HOTKEY_UP;
|
||||
else if(Event.m_Key == KEY_DOWN)
|
||||
m_HotkeysPressed |= HOTKEY_DOWN;
|
||||
else if(Event.m_Key == KEY_MOUSE_WHEEL_UP)
|
||||
m_HotkeysPressed |= HOTKEY_SCROLL_UP;
|
||||
else if(Event.m_Key == KEY_MOUSE_WHEEL_DOWN)
|
||||
m_HotkeysPressed |= HOTKEY_SCROLL_DOWN;
|
||||
return LastHotkeysPressed != m_HotkeysPressed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
float CUI::ButtonColorMul(const void *pID)
|
||||
{
|
||||
if(CheckActiveItem(pID))
|
||||
|
|
|
@ -197,6 +197,7 @@ class CUI
|
|||
|
||||
IInput::CEvent *m_pInputEventsArray;
|
||||
int *m_pInputEventCount;
|
||||
unsigned m_HotkeysPressed = 0;
|
||||
|
||||
bool m_MouseIsPress = false;
|
||||
bool m_HasSelection = false;
|
||||
|
@ -240,6 +241,18 @@ public:
|
|||
CUI();
|
||||
~CUI();
|
||||
|
||||
enum EHotkey : unsigned
|
||||
{
|
||||
HOTKEY_ENTER = 1 << 0,
|
||||
HOTKEY_ESCAPE = 1 << 1,
|
||||
HOTKEY_UP = 1 << 2,
|
||||
HOTKEY_DOWN = 1 << 3,
|
||||
HOTKEY_DELETE = 1 << 4,
|
||||
HOTKEY_TAB = 1 << 5,
|
||||
HOTKEY_SCROLL_UP = 1 << 6,
|
||||
HOTKEY_SCROLL_DOWN = 1 << 7,
|
||||
};
|
||||
|
||||
void ResetUIElement(CUIElement &UIElement);
|
||||
|
||||
CUIElement *GetNewUIElement(int RequestedRectCount);
|
||||
|
@ -305,6 +318,10 @@ public:
|
|||
void ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType) const;
|
||||
void ResetMouseSlow() { m_MouseSlow = false; }
|
||||
|
||||
bool ConsumeHotkey(EHotkey Hotkey);
|
||||
void ClearHotkeys() { m_HotkeysPressed = 0; }
|
||||
bool OnInput(const IInput::CEvent &Event);
|
||||
|
||||
float ButtonColorMulActive() { return 0.5f; }
|
||||
float ButtonColorMulHot() { return 1.5f; }
|
||||
float ButtonColorMulDefault() { return 1.0f; }
|
||||
|
|
|
@ -73,13 +73,13 @@ void CScrollRegion::End()
|
|||
{
|
||||
const bool IsPageScroll = Input()->KeyIsPressed(KEY_LALT) || Input()->KeyIsPressed(KEY_RALT);
|
||||
const float ScrollUnit = IsPageScroll ? m_ClipRect.h : m_Params.m_ScrollUnit;
|
||||
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP))
|
||||
if(UI()->ConsumeHotkey(CUI::HOTKEY_SCROLL_UP))
|
||||
{
|
||||
m_AnimTime = AnimationDuration;
|
||||
m_AnimInitScrollY = m_ScrollY;
|
||||
m_AnimTargetScrollY -= ScrollUnit;
|
||||
}
|
||||
else if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN))
|
||||
else if(UI()->ConsumeHotkey(CUI::HOTKEY_SCROLL_DOWN))
|
||||
{
|
||||
m_AnimTime = AnimationDuration;
|
||||
m_AnimInitScrollY = m_ScrollY;
|
||||
|
|
|
@ -6385,6 +6385,7 @@ void CEditor::OnRender()
|
|||
}
|
||||
|
||||
UI()->FinishCheck();
|
||||
UI()->ClearHotkeys();
|
||||
Input()->Clear();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue