diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/common/keymap-manager.cpp | 50 | ||||
-rw-r--r-- | backends/common/keymap-manager.h | 14 | ||||
-rw-r--r-- | backends/common/keymap.cpp | 15 | ||||
-rw-r--r-- | backends/common/keymap.h | 6 | ||||
-rw-r--r-- | backends/common/keymapper.cpp | 34 | ||||
-rw-r--r-- | backends/common/keymapper.h | 12 |
6 files changed, 57 insertions, 74 deletions
diff --git a/backends/common/keymap-manager.cpp b/backends/common/keymap-manager.cpp index d2d6fa223e..471bef43fb 100644 --- a/backends/common/keymap-manager.cpp +++ b/backends/common/keymap-manager.cpp @@ -43,11 +43,14 @@ void KeymapManager::Domain::addKeymap(const String& name, Keymap *map) { void KeymapManager::Domain::deleteAllKeyMaps() { KeymapMap::iterator it; for (it = _keymaps.begin(); it != _keymaps.end(); it++) { - //it->_value->saveMappings() + it->_value->saveMappings(_configDomain, it->_key); delete it->_value; } _keymaps.clear(); - delete _defaultKeymap; + if (_defaultKeymap) { + _defaultKeymap->saveMappings(_configDomain, "default"); + delete _defaultKeymap; + } } Keymap *KeymapManager::Domain::getDefaultKeymap() { @@ -64,13 +67,13 @@ Keymap *KeymapManager::Domain::getKeymap(const String& name) { KeymapManager::KeymapManager() { _hardwareKeys = 0; + _globalDomain.setConfigDomain(ConfMan.getDomain(ConfigManager::kApplicationDomain)); } KeymapManager::~KeymapManager() { delete _hardwareKeys; } - void KeymapManager::registerHardwareKeySet(HardwareKeySet *keys) { if (_hardwareKeys) error("Hardware key set already registered!"); @@ -80,6 +83,7 @@ void KeymapManager::registerHardwareKeySet(HardwareKeySet *keys) { void KeymapManager::registerDefaultGlobalKeymap(Keymap *map) { ConfigManager::Domain *dom = ConfMan.getDomain(ConfigManager::kApplicationDomain); assert(dom); + initKeymap(dom, "default", map); _globalDomain.setDefaultKeymap(map); } @@ -92,19 +96,22 @@ void KeymapManager::registerGlobalKeymap(const String& name, Keymap *map) { _globalDomain.addKeymap(name, map); } -void KeymapManager::registerDefaultGameKeymap(Keymap *map) { - ConfigManager::Domain *dom = ConfMan.getActiveDomain(); - assert(dom); +void KeymapManager::refreshGameDomain() { + if (_gameDomain.getConfigDomain() != ConfMan.getActiveDomain()) { + _gameDomain.deleteAllKeyMaps(); + _gameDomain.setConfigDomain(ConfMan.getActiveDomain()); + } +} - initKeymap(dom, "default", map); +void KeymapManager::registerDefaultGameKeymap(Keymap *map) { + refreshGameDomain(); + initKeymap(_gameDomain.getConfigDomain(), "default", map); _gameDomain.setDefaultKeymap(map); } void KeymapManager::registerGameKeymap(const String& name, Keymap *map) { - ConfigManager::Domain *dom = ConfMan.getActiveDomain(); - assert(dom); - - initKeymap(dom, name, map); + refreshGameDomain(); + initKeymap(_gameDomain.getConfigDomain(), name, map); _gameDomain.addKeymap(name, map); } @@ -112,25 +119,10 @@ void KeymapManager::initKeymap(ConfigManager::Domain *domain, const String& name, Keymap *map) { map->loadMappings(domain, name, _hardwareKeys); - if (isMapComplete(map) == false) + if (map->isComplete(_hardwareKeys) == false) automaticMap(map); } -bool KeymapManager::isMapComplete(const Keymap *map) { - const List<Action*>& actions = map->getActions(); - List<Action*>::const_iterator it; - bool allMapped = true; - uint numberMapped = 0; - for (it = actions.begin(); it != actions.end(); it++) { - if ((*it)->getMappedKey()) { - numberMapped++; - } else { - allMapped = false; - } - } - return allMapped || (numberMapped == _hardwareKeys->count()); -} - void KeymapManager::automaticMap(Keymap *map) { List<Action*> actions(map->getActions()), unmapped; List<Action*>::iterator actIt; @@ -166,10 +158,6 @@ void KeymapManager::automaticMap(Keymap *map) { } -void KeymapManager::unregisterAllGameKeymaps() { - _gameDomain.deleteAllKeyMaps(); -} - Keymap *KeymapManager::getKeymap(const String& name) { Keymap *keymap = _gameDomain.getKeymap(name); if (!keymap) diff --git a/backends/common/keymap-manager.h b/backends/common/keymap-manager.h index b8ab1c7998..136d9a33b9 100644 --- a/backends/common/keymap-manager.h +++ b/backends/common/keymap-manager.h @@ -38,9 +38,16 @@ public: class Domain { public: - Domain() : _defaultKeymap(0) {} + Domain() : _defaultKeymap(0), _configDomain(0) {} ~Domain() { deleteAllKeyMaps(); } + void setConfigDomain(ConfigManager::Domain *confDom) { + _configDomain = confDom; + } + ConfigManager::Domain *getConfigDomain() { + return _configDomain; + } + void setDefaultKeymap(Keymap *map); void addKeymap(const String& name, Keymap *map); @@ -53,6 +60,7 @@ public: typedef HashMap<String, Keymap*, IgnoreCase_Hash, IgnoreCase_EqualTo> KeymapMap; + ConfigManager::Domain *_configDomain; Keymap *_defaultKeymap; KeymapMap _keymaps; }; @@ -65,18 +73,16 @@ public: void registerDefaultGlobalKeymap(Keymap *map); void registerGlobalKeymap(const String& name, Keymap *map); + void refreshGameDomain(); void registerDefaultGameKeymap(Keymap *map); void registerGameKeymap(const String& name, Keymap *map); - void unregisterAllGameKeymaps(); - Keymap *getKeymap(const String& name); private: void initKeymap(ConfigManager::Domain *domain, const String& name, Keymap *keymap); void automaticMap(Keymap *map); - bool isMapComplete(const Keymap *map); Domain _globalDomain; Domain _gameDomain; diff --git a/backends/common/keymap.cpp b/backends/common/keymap.cpp index 72457d35a4..ba6f758caa 100644 --- a/backends/common/keymap.cpp +++ b/backends/common/keymap.cpp @@ -132,6 +132,7 @@ void Keymap::loadMappings(ConfigManager::Domain *domain, const String& name, con } void Keymap::saveMappings(ConfigManager::Domain *domain, const String& name) { + if (!domain) return; List<Action*>::const_iterator it; char buf[11]; for (it = _actions.begin(); it != _actions.end(); it++) { @@ -146,4 +147,18 @@ void Keymap::saveMappings(ConfigManager::Domain *domain, const String& name) { } } +bool Keymap::isComplete(const HardwareKeySet *hwKeys) { + List<Action*>::iterator it; + bool allMapped = true; + uint numberMapped = 0; + for (it = _actions.begin(); it != _actions.end(); it++) { + if ((*it)->getMappedKey()) { + numberMapped++; + } else { + allMapped = false; + } + } + return allMapped || (numberMapped == hwKeys->count()); +} + } // end of namespace Common diff --git a/backends/common/keymap.h b/backends/common/keymap.h index 55e5c598d8..d0829b8d29 100644 --- a/backends/common/keymap.h +++ b/backends/common/keymap.h @@ -96,6 +96,12 @@ public: */ void saveMappings(ConfigManager::Domain *domain, const String& name); + /** + * Returns true if all UserAction's in Keymap are mapped, or, + * all HardwareKey'ss from the given set have been used up. + */ + bool isComplete(const HardwareKeySet *hwKeys); + private: friend struct Action; /** diff --git a/backends/common/keymapper.cpp b/backends/common/keymapper.cpp index 70664b80d9..59fb796187 100644 --- a/backends/common/keymapper.cpp +++ b/backends/common/keymapper.cpp @@ -50,38 +50,18 @@ void Keymapper::setDefaultGlobalKeymap(Keymap *keymap) { } void Keymapper::addGameKeymap(const String& name, Keymap *keymap) { - if (checkGameInit()) - _keymapMan->registerGameKeymap(name, keymap); + if (ConfMan.getActiveDomain() == 0) + error("Call to Keymapper::initGame when no game loaded"); + + _keymapMan->registerGameKeymap(name, keymap); } void Keymapper::setDefaultGameKeymap(Keymap *keymap) { - if (checkGameInit()) { - _keymapMan->registerDefaultGameKeymap(keymap); - pushKeymap(keymap, true); - } -} - -bool Keymapper::checkGameInit() { - if (_gameId.empty()) { - initGame(); - if (_gameId.empty()) - return false; - } - return true; -} - -void Keymapper::initGame() { if (ConfMan.getActiveDomain() == 0) error("Call to Keymapper::initGame when no game loaded"); - - if (_gameId.size() > 0) - cleanupGame(); - _gameId = ConfMan.getActiveDomainName(); -} - -void Keymapper::cleanupGame() { - _keymapMan->unregisterAllGameKeymaps(); - _gameId.clear(); + + _keymapMan->registerDefaultGameKeymap(keymap); + pushKeymap(keymap, true); } bool Keymapper::pushKeymap(const String& name, bool inherit) { diff --git a/backends/common/keymapper.h b/backends/common/keymapper.h index ff9e476739..c2113d5ca4 100644 --- a/backends/common/keymapper.h +++ b/backends/common/keymapper.h @@ -73,16 +73,6 @@ public: void setDefaultGameKeymap(Keymap *keymap); /** - * Initialise the keymapper for a new game - */ - void initGame(); - - /** - * Cleanup the keymapper after a game has ended - */ - void cleanupGame(); - - /** * Push a new keymap to the top of the active stack, activating it for use. * @param name name of the keymap to push * @param inherit if true @@ -120,14 +110,12 @@ public: private: void pushKeymap(Keymap *newMap, bool inherit); - bool checkGameInit(); typedef List<HardwareKey*>::iterator Iterator; EventManager *_eventMan; KeymapManager *_keymapMan; - String _gameId; struct MapRecord { Keymap* keymap; |