1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Implementation of (very basic) shortcuts system

- Added EShortcut enumeration that contains all in-game shortcuts
- CIntObject::keyPressed now receive values from hotkey enumeration
- On keypress, SDL key code will be translated to shortcut ID
- Removed access to SDL key codes from most of engine
This commit is contained in:
Ivan Savenko
2023-04-27 20:21:06 +03:00
parent ac09f78c67
commit 832e56e005
57 changed files with 920 additions and 553 deletions

View File

@@ -17,6 +17,7 @@
#include "../PlayerLocalState.h"
#include "../ClientCommandManager.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../render/Colors.h"
#include "../../CCallback.h"
@@ -108,30 +109,29 @@ void CInGameConsole::print(const std::string & txt)
GH.totalRedraw(); // FIXME: ingame console has no parent widget set
}
void CInGameConsole::keyPressed (const SDL_Keycode & key)
void CInGameConsole::keyPressed (EShortcut key)
{
if (LOCPLINT->cingconsole != this)
return;
if(!captureAllKeys && key != SDLK_TAB)
if(!captureAllKeys && key != EShortcut::GAME_ACTIVATE_CONSOLE)
return; //because user is not entering any text
switch(key)
{
case SDLK_TAB:
case SDLK_ESCAPE:
{
if(captureAllKeys)
{
endEnteringText(false);
}
else if(SDLK_TAB == key)
{
startEnteringText();
}
break;
}
case SDLK_RETURN: //enter key
case EShortcut::GLOBAL_CANCEL:
if(captureAllKeys)
endEnteringText(false);
break;
case EShortcut::GAME_ACTIVATE_CONSOLE:
if(captureAllKeys)
endEnteringText(false);
else
startEnteringText();
break;
case EShortcut::GLOBAL_CONFIRM:
{
if(!enteredText.empty() && captureAllKeys)
{
@@ -145,7 +145,7 @@ void CInGameConsole::keyPressed (const SDL_Keycode & key)
}
break;
}
case SDLK_BACKSPACE:
case EShortcut::GLOBAL_BACKSPACE:
{
if(enteredText.size() > 1)
{
@@ -155,7 +155,7 @@ void CInGameConsole::keyPressed (const SDL_Keycode & key)
}
break;
}
case SDLK_UP: //up arrow
case EShortcut::SELECT_UP:
{
if(previouslyEntered.empty())
break;
@@ -174,7 +174,7 @@ void CInGameConsole::keyPressed (const SDL_Keycode & key)
}
break;
}
case SDLK_DOWN: //down arrow
case EShortcut::SELECT_DOWN:
{
if(prevEntDisp != -1 && prevEntDisp+1 < previouslyEntered.size())
{
@@ -190,10 +190,6 @@ void CInGameConsole::keyPressed (const SDL_Keycode & key)
}
break;
}
default:
{
break;
}
}
}