mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-12 14:29:42 -05:00
Warn if multiple keys are bound to a key on removal
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -125,6 +125,7 @@ private:
|
||||
const Keyframe<TimeKeyframeData>& future, double time);
|
||||
|
||||
void addDeltaTimesKeybindings();
|
||||
void clearDeltaTimesKeybindings();
|
||||
|
||||
Timeline<TimeKeyframeData> _timeline;
|
||||
SyncData<Time> _currentTime;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user