mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-21 01:05:59 +00:00
KEYMAPPER: Allow multiple inputs bound to a keymap action as defaults (#4830)
This allows backeds to override a keymap action mapping with lists of mapped hardware inputs instead of just one hardware input id However, it will still be an overridding, so it will require all hardware input ids for a given keymap action to be added. In other words, if a backend uses addDefaultBinding() for a given action, it will not ADD to any existing mappings of the action, other than the ones that the backend itself has added (with addDefaultBinding())
This commit is contained in:
parent
397a73572c
commit
3565d0e312
@ -256,19 +256,13 @@ StringArray Keymap::getActionDefaultMappings(Action *action) {
|
||||
if (_backendDefaultBindings) {
|
||||
KeymapperDefaultBindings::const_iterator it = _backendDefaultBindings->findDefaultBinding(_id, action->id);
|
||||
if (it != _backendDefaultBindings->end()) {
|
||||
if (it->_value.empty()) {
|
||||
return StringArray();
|
||||
}
|
||||
return StringArray(1, it->_value);
|
||||
return it->_value;
|
||||
}
|
||||
|
||||
// If no keymap-specific default mapping was found, look for a standard action binding
|
||||
it = _backendDefaultBindings->findDefaultBinding(kStandardActionsKeymapName, action->id);
|
||||
if (it != _backendDefaultBindings->end()) {
|
||||
if (it->_value.empty()) {
|
||||
return StringArray();
|
||||
}
|
||||
return StringArray(1, it->_value);
|
||||
return it->_value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
namespace Common {
|
||||
|
||||
class KeymapperDefaultBindings : public HashMap<String, String> {
|
||||
class KeymapperDefaultBindings : public HashMap<String, StringArray> {
|
||||
public:
|
||||
/**
|
||||
* This sets a default hwInput for a given Keymap Action
|
||||
@ -37,12 +37,42 @@ public:
|
||||
* @param actionId String representing Action id (Action.id)
|
||||
* @param hwInputId String representing the HardwareInput id (HardwareInput.id)
|
||||
*/
|
||||
void setDefaultBinding(String keymapId, String actionId, String hwInputId) { setVal(keymapId + "_" + actionId, hwInputId); }
|
||||
void setDefaultBinding(String keymapId, String actionId, String hwInputId) {
|
||||
setVal(keymapId + "_" + actionId, hwInputId.empty() ? StringArray() : StringArray(1, hwInputId));
|
||||
}
|
||||
|
||||
/**
|
||||
* This adds a default hwInput for a given Keymap Action
|
||||
* @param keymapId String representing Keymap id (Keymap.name)
|
||||
* @param actionId String representing Action id (Action.id)
|
||||
* @param hwInputId String representing the HardwareInput id (HardwareInput.id)
|
||||
*/
|
||||
void addDefaultBinding(String keymapId, String actionId, String hwInputId) {
|
||||
// NOTE: addDefaultBinding() cannot be used to remove bindings;
|
||||
// use setDefaultBinding() with a nullptr or empty string as hwInputId instead.
|
||||
if (hwInputId.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
KeymapperDefaultBindings::iterator it = findDefaultBinding(keymapId, actionId);
|
||||
if (it != end()) {
|
||||
// Don't allow an input to map to the same action multiple times
|
||||
StringArray &itv = it->_value;
|
||||
|
||||
Array<String>::const_iterator found = Common::find(itv.begin(), itv.end(), hwInputId);
|
||||
if (found == itv.end()) {
|
||||
itv.push_back(hwInputId);
|
||||
}
|
||||
} else {
|
||||
setDefaultBinding(keymapId, actionId, hwInputId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This retrieves the assigned default hwKey for a given Keymap Action
|
||||
* @param keymapId String representing Keymap id (Keymap.name)
|
||||
* @param actionId String representing Action id (Action.id)
|
||||
* @return String representing the HardwareInput id (HardwareInput.id)
|
||||
* @return StringArray representing the list of HardwareInput ids (HardwareInput.id) that are mapped to Keymap Action
|
||||
*/
|
||||
const_iterator findDefaultBinding(String keymapId, String actionId) const {
|
||||
return find(keymapId + "_" + actionId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user