mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-12 14:29:42 -05:00
Remove the registered actions before updating the delta time keybindings (closes #2764)
This commit is contained in:
@@ -75,7 +75,9 @@ namespace {
|
||||
};
|
||||
|
||||
constexpr std::string_view DeltaTimeStepsGuiPath = "/Time/Simulation Speed/Steps";
|
||||
}
|
||||
|
||||
constexpr std::string_view DeltaTimeActionPrefix = "core.time.delta_time";
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -466,6 +468,7 @@ void TimeManager::setDeltaTimeSteps(std::vector<double> deltaTimes) {
|
||||
_deltaTimeSteps = std::move(deltaTimes);
|
||||
_deltaTimeStepsChanged = true;
|
||||
|
||||
clearDeltaTimesKeybindings();
|
||||
addDeltaTimesKeybindings();
|
||||
}
|
||||
|
||||
@@ -500,7 +503,7 @@ void TimeManager::addDeltaTimesKeybindings() {
|
||||
auto addDeltaTimeKeybind = [this](Key key, KeyModifier mod, double step) {
|
||||
const std::string s = fmt::format("{:.0f}", step);
|
||||
|
||||
std::string identifier = fmt::format("core.time.delta_time.{}", s);
|
||||
std::string identifier = fmt::format("{}.{}", DeltaTimeActionPrefix, s);
|
||||
interaction::Action action;
|
||||
action.identifier = identifier;
|
||||
action.command = fmt::format("openspace.time.interpolateDeltaTime({})", s);
|
||||
@@ -551,6 +554,15 @@ void TimeManager::addDeltaTimesKeybindings() {
|
||||
}
|
||||
|
||||
void TimeManager::clearDeltaTimesKeybindings() {
|
||||
// Iterate over all of the registered actions with the common prefix that we created
|
||||
// in the addDeltaTimesKeybindings function
|
||||
std::vector<interaction::Action> actions = global::actionManager->actions();
|
||||
for (const interaction::Action& action : actions) {
|
||||
if (action.identifier.starts_with(DeltaTimeActionPrefix)) {
|
||||
global::actionManager->removeAction(action.identifier);
|
||||
}
|
||||
}
|
||||
|
||||
for (const KeyWithModifier& kb : _deltaTimeStepKeybindings) {
|
||||
// Check if there are multiple keys bound to the same key
|
||||
auto bindings = global::keybindingManager->keyBinding(kb);
|
||||
|
||||
Reference in New Issue
Block a user