KEYMAPPER: Add failsafe code for popping into Keymapper itself
Thanks LordHoto
This commit is contained in:
parent
d143872be6
commit
37d77253cf
3 changed files with 18 additions and 13 deletions
|
@ -163,9 +163,19 @@ void Keymapper::pushKeymap(Keymap *newMap, bool transparent, bool global) {
|
|||
_activeMaps.push(mr);
|
||||
}
|
||||
|
||||
void Keymapper::popKeymap() {
|
||||
if (!_activeMaps.empty())
|
||||
_activeMaps.pop();
|
||||
void Keymapper::popKeymap(const char *name) {
|
||||
if (!_activeMaps.empty()) {
|
||||
if (name) {
|
||||
String topKeymapName = _activeMaps.top().keymap->getName();
|
||||
if (topKeymapName.equals(name))
|
||||
_activeMaps.pop();
|
||||
else
|
||||
warning("An attempt to pop wrong keymap was blocked (expected %s but was %s)", name, topKeymapName.c_str());
|
||||
} else {
|
||||
_activeMaps.pop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Keymapper::notifyEvent(const Common::Event &ev) {
|
||||
|
|
|
@ -131,8 +131,11 @@ public:
|
|||
|
||||
/**
|
||||
* Pop the top keymap off the active stack.
|
||||
* @param name (optional) name of keymap expected to be popped
|
||||
* if provided, will not pop unless name is the same
|
||||
* as the top keymap
|
||||
*/
|
||||
void popKeymap();
|
||||
void popKeymap(const char *name = 0);
|
||||
|
||||
// Implementation of the EventMapper interface
|
||||
bool notifyEvent(const Common::Event &ev);
|
||||
|
|
|
@ -132,15 +132,7 @@ void GuiManager::pushKeymap() {
|
|||
}
|
||||
|
||||
void GuiManager::popKeymap() {
|
||||
Common::Keymapper *keymapper = _system->getEventManager()->getKeymapper();
|
||||
if (!keymapper->getActiveStack().empty()) {
|
||||
Common::Keymapper::MapRecord topKeymap = keymapper->getActiveStack().top();
|
||||
// TODO: Don't use the keymap name as a way to discriminate GUI maps
|
||||
if(topKeymap.keymap->getName().equals(Common::kGuiKeymapName))
|
||||
keymapper->popKeymap();
|
||||
else
|
||||
warning("An attempt to pop non-gui keymap %s was blocked", topKeymap.keymap->getName().c_str());
|
||||
}
|
||||
_system->getEventManager()->getKeymapper()->popKeymap(Common::kGuiKeymapName);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue