mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-03 09:23:37 +00:00
* Saving of keymaps fully implemented
* Added Keymapper::cleanupGameKeymaps() with code to remove game keymaps from active stack svn-id: r33853
This commit is contained in:
parent
5ca906fbd7
commit
c1e8e340ff
@ -69,7 +69,7 @@ struct HardwareKey {
|
||||
class HardwareKeySet {
|
||||
public:
|
||||
|
||||
HardwareKeySet() {}
|
||||
HardwareKeySet() : _count(0) {}
|
||||
virtual ~HardwareKeySet() {
|
||||
List<const HardwareKey*>::iterator it;
|
||||
for (it = _keys.begin(); it != _keys.end(); it++)
|
||||
@ -79,6 +79,7 @@ public:
|
||||
void addHardwareKey(HardwareKey *key) {
|
||||
checkForKey(key);
|
||||
_keys.push_back(key);
|
||||
++_count;
|
||||
}
|
||||
|
||||
const HardwareKey *findHardwareKey(int32 id) const {
|
||||
@ -104,7 +105,7 @@ public:
|
||||
}
|
||||
|
||||
uint count() const {
|
||||
return _keys.size();
|
||||
return _count;
|
||||
}
|
||||
|
||||
|
||||
@ -121,6 +122,7 @@ private:
|
||||
}
|
||||
|
||||
List<const HardwareKey*> _keys;
|
||||
uint _count;
|
||||
};
|
||||
|
||||
|
||||
|
@ -73,6 +73,7 @@ void KeymapManager::registerGlobalKeymap(Keymap *map) {
|
||||
void KeymapManager::refreshGameDomain() {
|
||||
if (_gameDomain.getConfigDomain() != ConfMan.getActiveDomain()) {
|
||||
_gameDomain.deleteAllKeyMaps();
|
||||
|
||||
_gameDomain.setConfigDomain(ConfMan.getActiveDomain());
|
||||
}
|
||||
}
|
||||
@ -85,7 +86,8 @@ void KeymapManager::registerGameKeymap(Keymap *map) {
|
||||
|
||||
void KeymapManager::initKeymap(ConfigManager::Domain *domain,
|
||||
Keymap *map) {
|
||||
map->loadMappings(domain, _hardwareKeys);
|
||||
map->setConfigDomain(domain);
|
||||
map->loadMappings(_hardwareKeys);
|
||||
if (map->isComplete(_hardwareKeys) == false) {
|
||||
automaticMap(map);
|
||||
map->saveMappings(domain);
|
||||
@ -206,6 +208,8 @@ void KeymapManager::automaticMap(Keymap *map) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
map->saveMappings();
|
||||
ConfMan.flushToDisk();
|
||||
}
|
||||
|
||||
Action *KeymapManager::getParentMappedAction(Keymap *map, KeyState key) {
|
||||
@ -221,10 +225,13 @@ Action *KeymapManager::getParentMappedAction(Keymap *map, KeyState key) {
|
||||
}
|
||||
}
|
||||
|
||||
Keymap *KeymapManager::getKeymap(const String& name) {
|
||||
Keymap *KeymapManager::getKeymap(const String& name, bool *global) {
|
||||
Keymap *keymap = _gameDomain.getKeymap(name);
|
||||
if (!keymap)
|
||||
*global = false;
|
||||
if (!keymap) {
|
||||
keymap = _globalDomain.getKeymap(name);
|
||||
*global = true;
|
||||
}
|
||||
return keymap;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
void refreshGameDomain();
|
||||
void registerGameKeymap(Keymap *map);
|
||||
|
||||
Keymap *getKeymap(const String& name);
|
||||
Keymap *getKeymap(const String& name, bool *global);
|
||||
|
||||
Domain& getGlobalDomain() { return _globalDomain; }
|
||||
Domain& getGameDomain() { return _gameDomain; }
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
namespace Common {
|
||||
|
||||
Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap() {
|
||||
Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap(), _configDomain(0) {
|
||||
List<Action*>::iterator it;
|
||||
for (it = _actions.begin(); it != _actions.end(); it++) {
|
||||
const HardwareKey *hwKey = (*it)->getMappedKey();
|
||||
@ -94,10 +94,15 @@ Action *Keymap::getMappedAction(const KeyState& ks) const {
|
||||
return it->_value;
|
||||
}
|
||||
|
||||
void Keymap::loadMappings(ConfigManager::Domain *domain, const HardwareKeySet *hwKeys) {
|
||||
void Keymap::setConfigDomain(ConfigManager::Domain *dom) {
|
||||
_configDomain = dom;
|
||||
}
|
||||
|
||||
void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
|
||||
if (!_configDomain) return;
|
||||
ConfigManager::Domain::iterator it;
|
||||
String prefix = "km_" + _name + "_";
|
||||
for (it = domain->begin(); it != domain->end(); it++) {
|
||||
for (it = _configDomain->begin(); it != _configDomain->end(); it++) {
|
||||
const String& key = it->_key;
|
||||
if (!key.hasPrefix(prefix.c_str()))
|
||||
continue;
|
||||
@ -114,6 +119,7 @@ void Keymap::loadMappings(ConfigManager::Domain *domain, const HardwareKeySet *h
|
||||
if (!ua) {
|
||||
warning("'%s' keymap does not contain Action with ID %d",
|
||||
_name.c_str(), (int)actionId);
|
||||
_configDomain->erase(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -126,6 +132,7 @@ void Keymap::loadMappings(ConfigManager::Domain *domain, const HardwareKeySet *h
|
||||
const HardwareKey *hwKey = hwKeys->findHardwareKey(hwKeyId);
|
||||
if (!hwKey) {
|
||||
warning("HardwareKey with ID %d not known", (int)hwKeyId);
|
||||
_configDomain->erase(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -133,8 +140,8 @@ void Keymap::loadMappings(ConfigManager::Domain *domain, const HardwareKeySet *h
|
||||
}
|
||||
}
|
||||
|
||||
void Keymap::saveMappings(ConfigManager::Domain *domain) {
|
||||
if (!domain) return;
|
||||
void Keymap::saveMappings() {
|
||||
if (!_configDomain) return;
|
||||
List<Action*>::const_iterator it;
|
||||
char buf[12];
|
||||
String prefix = "km_" + _name + "_";
|
||||
@ -145,7 +152,7 @@ void Keymap::saveMappings(ConfigManager::Domain *domain) {
|
||||
sprintf(buf, "%d", (*it)->getMappedKey()->id);
|
||||
else
|
||||
strcpy(buf, "");
|
||||
domain->setVal(key, buf);
|
||||
_configDomain->setVal(key, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,19 +81,20 @@ public:
|
||||
*/
|
||||
Action *getMappedAction(const KeyState& ks) const;
|
||||
|
||||
/**
|
||||
* Load this keymap's mappings from the given config domain and hardware key set
|
||||
* @param domain config domain to load keymap from
|
||||
* @param hwKeys the set to retrieve hardware key pointers from
|
||||
*/
|
||||
void loadMappings(ConfigManager::Domain *domain, const HardwareKeySet *hwKeys);
|
||||
void setConfigDomain(ConfigManager::Domain *dom);
|
||||
|
||||
/**
|
||||
* Save this keymap's mappings to the given config domain
|
||||
* @param domain config domain to save keymap to
|
||||
* Load this keymap's mappings from the config manager.
|
||||
* @param hwKeys the set to retrieve hardware key pointers from
|
||||
*/
|
||||
void loadMappings(const HardwareKeySet *hwKeys);
|
||||
|
||||
/**
|
||||
* Save this keymap's mappings to the config manager
|
||||
* @note Changes are *not* flushed to disk, to do so call ConfMan.flushToDisk()
|
||||
* @note Changes are *not* flushed to disk, to do so call ConfMan.flushToDisk()
|
||||
*/
|
||||
void saveMappings(ConfigManager::Domain *domain);
|
||||
void saveMappings();
|
||||
|
||||
/**
|
||||
* Returns true if all UserAction's in Keymap are mapped, or,
|
||||
@ -130,6 +131,7 @@ private:
|
||||
Keymap *_parent;
|
||||
List<Action*> _actions;
|
||||
HashMap<KeyState, Action*> _keymap;
|
||||
ConfigManager::Domain *_configDomain;
|
||||
|
||||
};
|
||||
|
||||
|
@ -52,20 +52,28 @@ void Keymapper::addGameKeymap(Keymap *keymap) {
|
||||
_keymapMan->registerGameKeymap(keymap);
|
||||
}
|
||||
|
||||
void Keymapper::cleanupGameKeymaps() {
|
||||
Stack<MapRecord> newStack;
|
||||
for (int i = 0; i < _activeMaps.size(); i++) {
|
||||
if (!_activeMaps[i].global)
|
||||
newStack.push(_activeMaps[i]);
|
||||
}
|
||||
_activeMaps = newStack;
|
||||
}
|
||||
|
||||
bool Keymapper::pushKeymap(const String& name, bool inherit) {
|
||||
Keymap *newMap = _keymapMan->getKeymap(name);
|
||||
bool global;
|
||||
Keymap *newMap = _keymapMan->getKeymap(name, &global);
|
||||
if (!newMap) {
|
||||
warning("Keymap '%s' not registered", name.c_str());
|
||||
return false;
|
||||
}
|
||||
pushKeymap(newMap, inherit);
|
||||
pushKeymap(newMap, inherit, global);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Keymapper::pushKeymap(Keymap *newMap, bool inherit) {
|
||||
MapRecord mr;
|
||||
mr.inherit = inherit;
|
||||
mr.keymap = newMap;
|
||||
void Keymapper::pushKeymap(Keymap *newMap, bool inherit, bool global) {
|
||||
MapRecord mr = {newMap, inherit, global};
|
||||
_activeMaps.push(mr);
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ public:
|
||||
struct MapRecord {
|
||||
Keymap* keymap;
|
||||
bool inherit;
|
||||
bool global;
|
||||
};
|
||||
|
||||
Keymapper(EventManager *eventMan);
|
||||
@ -61,12 +62,17 @@ public:
|
||||
void addGlobalKeymap(Keymap *keymap);
|
||||
|
||||
/**
|
||||
* Add a keymap to the game domain.
|
||||
* @see addGlobalKeyMap
|
||||
* @note initGame() should be called before any game keymaps are added.
|
||||
*/
|
||||
* Add a keymap to the game domain.
|
||||
* @see addGlobalKeyMap
|
||||
* @note initGame() should be called before any game keymaps are added.
|
||||
*/
|
||||
void addGameKeymap(Keymap *keymap);
|
||||
|
||||
/**
|
||||
* Should be called at end of game to tell Keymapper to deactivate and free
|
||||
* any game keymaps that are loaded.
|
||||
*/
|
||||
void cleanupGameKeymaps();
|
||||
/**
|
||||
* Push a new keymap to the top of the active stack, activating
|
||||
* it for use.
|
||||
@ -113,7 +119,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void pushKeymap(Keymap *newMap, bool inherit);
|
||||
void pushKeymap(Keymap *newMap, bool inherit, bool global);
|
||||
|
||||
typedef List<HardwareKey*>::iterator Iterator;
|
||||
|
||||
|
@ -51,9 +51,11 @@ RemapDialog::~RemapDialog() {
|
||||
}
|
||||
|
||||
void RemapDialog::open() {
|
||||
bool divider = false;
|
||||
_activeKeymaps = &_keymapper->getActiveStack();
|
||||
if (_activeKeymaps->size() > 0) {
|
||||
_kmPopUp->appendEntry(_activeKeymaps->top().keymap->getName() + " (Active)");
|
||||
divider = true;
|
||||
}
|
||||
|
||||
KeymapManager::Domain *_globalKeymaps = &_keymapper->getManager()->getGlobalDomain();
|
||||
@ -78,14 +80,15 @@ void RemapDialog::open() {
|
||||
KeymapManager::Domain::iterator it;
|
||||
uint32 idx = 0;
|
||||
if (_globalKeymaps) {
|
||||
_kmPopUp->appendEntry("");
|
||||
if (divider) _kmPopUp->appendEntry("");
|
||||
for (it = _globalKeymaps->begin(); it != _globalKeymaps->end(); it++) {
|
||||
_kmPopUp->appendEntry(it->_value->getName() + " (Global)", idx);
|
||||
_keymapTable[idx++] = it->_value;
|
||||
}
|
||||
divider = true;
|
||||
}
|
||||
if (_gameKeymaps) {
|
||||
_kmPopUp->appendEntry("");
|
||||
if (divider) _kmPopUp->appendEntry("");
|
||||
for (it = _gameKeymaps->begin(); it != _gameKeymaps->end(); it++) {
|
||||
_kmPopUp->appendEntry(it->_value->getName() + " (Game)", idx);
|
||||
_keymapTable[idx++] = it->_value;
|
||||
@ -93,10 +96,11 @@ void RemapDialog::open() {
|
||||
}
|
||||
|
||||
_changes = false;
|
||||
_kmPopUp->setSelected(0);
|
||||
loadKeymap();
|
||||
|
||||
Dialog::open();
|
||||
|
||||
_kmPopUp->setSelected(0);
|
||||
loadKeymap();
|
||||
}
|
||||
|
||||
void RemapDialog::close() {
|
||||
@ -105,7 +109,8 @@ void RemapDialog::close() {
|
||||
free(_keymapTable);
|
||||
_keymapTable = 0;
|
||||
}
|
||||
if (_changes) ConfMan.flushToDisk();
|
||||
if (_changes)
|
||||
ConfMan.flushToDisk();
|
||||
Dialog::close();
|
||||
}
|
||||
|
||||
@ -260,7 +265,9 @@ void RemapDialog::loadKeymap() {
|
||||
}
|
||||
|
||||
} else if (_kmPopUp->getSelected() != -1) {
|
||||
Keymap *km = _keymapTable[_kmPopUp->getSelectedTag()];
|
||||
uint32 select = _kmPopUp->getSelected();
|
||||
uint32 tag = _kmPopUp->getSelectedTag();
|
||||
Keymap *km = _keymapTable[tag];
|
||||
|
||||
List<Action*>::iterator it;
|
||||
for (it = km->getActions().begin(); it != km->getActions().end(); it++) {
|
||||
|
Binary file not shown.
@ -88,7 +88,11 @@ protected:
|
||||
public:
|
||||
Stack<T>() {}
|
||||
Stack<T>(const Array<T> &stackContent) : _stack(stackContent) {}
|
||||
|
||||
|
||||
Stack<T>& operator=(const Stack<T> &st) {
|
||||
_stack = st._stack;
|
||||
return *this;
|
||||
}
|
||||
bool empty() const {
|
||||
return _stack.empty();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user