Warn if multiple keys are bound to a key on removal

This commit is contained in:
Emma Broman
2020-10-09 18:52:38 +02:00
parent 37c45a10b6
commit ec1fbb09f8
4 changed files with 33 additions and 7 deletions
@@ -67,6 +67,9 @@ public:
std::vector<std::pair<KeyWithModifier, KeyInformation>> keyBinding(
const std::string& key) const;
std::vector<std::pair<KeyWithModifier, KeyInformation>> keyBinding(
const KeyWithModifier& key) const;
static scripting::LuaLibrary luaLibrary();
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
+1
View File
@@ -125,6 +125,7 @@ private:
const Keyframe<TimeKeyframeData>& future, double time);
void addDeltaTimesKeybindings();
void clearDeltaTimesKeybindings();
Timeline<TimeKeyframeData> _timeline;
SyncData<Time> _currentTime;
+8 -2
View File
@@ -156,11 +156,17 @@ void KeybindingManager::removeKeyBinding(const KeyWithModifier& key) {
std::vector<std::pair<KeyWithModifier, KeybindingManager::KeyInformation>>
KeybindingManager::keyBinding(const std::string& key) const
{
KeyWithModifier k = stringToKey(key);
return keyBinding(k);
}
std::vector<std::pair<KeyWithModifier, KeybindingManager::KeyInformation>>
KeybindingManager::keyBinding(const KeyWithModifier& key) const
{
std::vector<std::pair<KeyWithModifier, KeyInformation>> result;
KeyWithModifier k = stringToKey(key);
auto itRange = _keyLua.equal_range(k);
auto itRange = _keyLua.equal_range(key);
for (auto it = itRange.first; it != itRange.second; ++it) {
result.emplace_back(it->first, it->second);
}
+21 -5
View File
@@ -436,11 +436,7 @@ void TimeManager::addDeltaTimesKeybindings() {
Key::Num0
};
// First, clear any previous keybinds
for (const KeyWithModifier& kb : _deltaTimeStepKeybindings) {
global::keybindingManager.removeKeyBinding(kb);
}
_deltaTimeStepKeybindings.clear();
clearDeltaTimesKeybindings();
_deltaTimeStepKeybindings.reserve(_deltaTimeSteps.size());
// Find positive delta time steps
@@ -509,6 +505,26 @@ void TimeManager::addDeltaTimesKeybindings() {
}
}
void TimeManager::clearDeltaTimesKeybindings() {
for (const KeyWithModifier& kb : _deltaTimeStepKeybindings) {
// Check if there are multiple keys bound to the same key
auto bindings = global::keybindingManager.keyBinding(kb);
if (bindings.size() > 1) {
std::string names;
for (auto& b : bindings) {
names += fmt::format("'{}' ", b.second.name);
}
LWARNING(fmt::format(
"Updating keybindings for new delta time steps: More than one action "
"was bound to key '{}'. The following keybindings are removed: {}",
ghoul::to_string(kb), names
));
}
global::keybindingManager.removeKeyBinding(kb);
}
_deltaTimeStepKeybindings.clear();
}
size_t TimeManager::nKeyframes() const {
return _timeline.nKeyframes();
}