KEYMAPPER: Skip GUI keymap when displaying active keymap in keymapper dialog

This fixes a problem where opening the keymapper dialog would cause the current game
keymap to be displayed as the active keymap but then changing the keymap selection
back to it would cause the GUI keymap to be displayed as the active one. The GUI keymap
was indeed at the top of the stack but that's not the desired effect.

Also move the pushing and popping of the keymap to Dialog::Open/Close
Also constantify the GUI keymap name
This commit is contained in:
Tarek Soliman 2011-10-21 22:54:33 -05:00
parent ac85d134b3
commit a5082ffa5d
5 changed files with 31 additions and 20 deletions

View File

@ -36,6 +36,8 @@
namespace Common {
const char *const kGuiKeymapName = "gui";
class Keymapper : public Common::EventMapper, private Common::ArtificialEventSource {
public:

View File

@ -307,8 +307,14 @@ void RemapDialog::loadKeymap() {
List<const HardwareKey*> freeKeys(_keymapper->getHardwareKeys());
int topIndex = activeKeymaps.size() - 1;
// skip all gui maps
// TODO: Don't use the keymap name as a way to discriminate GUI maps
while (topIndex > 0 && activeKeymaps[topIndex].keymap->getName().equals(kGuiKeymapName))
--topIndex;
// add most active keymap's keys
Keymapper::MapRecord top = activeKeymaps.top();
Keymapper::MapRecord top = activeKeymaps[topIndex];
List<Action*>::iterator actIt;
debug(3, "RemapDialog::loadKeymap top keymap: %s", top.keymap->getName().c_str());
for (actIt = top.keymap->getActions().begin(); actIt != top.keymap->getActions().end(); ++actIt) {
@ -322,8 +328,8 @@ void RemapDialog::loadKeymap() {
}
// loop through remaining finding mappings for unmapped keys
if (top.inherit) {
for (int i = activeKeymaps.size() - 2; i >= 0; --i) {
if (top.inherit && topIndex >= 0) {
for (int i = topIndex - 1; i >= 0; --i) {
Keymapper::MapRecord mr = activeKeymaps[i];
debug(3, "RemapDialog::loadKeymap keymap: %s", mr.keymap->getName().c_str());
List<const HardwareKey*>::iterator keyIt = freeKeys.begin();

View File

@ -75,7 +75,6 @@ int Dialog::runModal() {
}
void Dialog::open() {
_result = 0;
_visible = true;
g_gui.openDialog(this);
@ -87,6 +86,10 @@ void Dialog::open() {
}
setFocusWidget(w);
#ifdef ENABLE_KEYMAPPER
g_gui.initKeymap();
g_gui.pushKeymap();
#endif
}
void Dialog::close() {
@ -98,6 +101,10 @@ void Dialog::close() {
}
releaseFocus();
g_gui.closeTopDialog();
#ifdef ENABLE_KEYMAPPER
g_gui.popKeymap();
#endif
}
void Dialog::reflowLayout() {

View File

@ -107,11 +107,11 @@ void GuiManager::initKeymap() {
Keymapper *mapper = _system->getEventManager()->getKeymapper();
// Do not try to recreate same keymap over again
if (mapper->getKeymap("gui", tmp) != 0)
if (mapper->getKeymap(kGuiKeymapName, tmp) != 0)
return;
Action *act;
Keymap *guiMap = new Keymap("gui");
Keymap *guiMap = new Keymap(kGuiKeymapName);
act = new Action(guiMap, "CLOS", _("Close"), kGenericActionType, kStartKeyType);
act->addKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0));
@ -127,6 +127,14 @@ void GuiManager::initKeymap() {
mapper->addGlobalKeymap(guiMap);
}
void GuiManager::pushKeymap() {
_system->getEventManager()->getKeymapper()->pushKeymap(Common::kGuiKeymapName);
}
void GuiManager::popKeymap() {
_system->getEventManager()->getKeymapper()->popKeymap();
}
#endif
bool GuiManager::loadNewTheme(Common::String id, ThemeEngine::GraphicsMode gfx, bool forced) {
@ -270,16 +278,6 @@ void GuiManager::runLoop() {
uint32 lastRedraw = 0;
const uint32 waitTime = 1000 / 45;
#ifdef ENABLE_KEYMAPPER
// Due to circular reference with event manager and GUI
// we cannot init keymap on the GUI creation. Thus, let's
// try to do it on every launch, checking whether the
// map is already existing
initKeymap();
eventMan->getKeymapper()->pushKeymap("gui");
#endif
bool tooltipCheck = false;
while (!_dialogStack.empty() && activeDialog == getTopDialog()) {
@ -391,10 +389,6 @@ void GuiManager::runLoop() {
_system->delayMillis(10);
}
#ifdef ENABLE_KEYMAPPER
eventMan->getKeymapper()->popKeymap();
#endif
if (didSaveState) {
_theme->disable();
restoreState();

View File

@ -126,6 +126,8 @@ protected:
byte _cursor[2048];
void initKeymap();
void pushKeymap();
void popKeymap();
void saveState();
void restoreState();