From 8032dde0450d732e0f95a2503cfc81ef8af9ba5b Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 6 Jul 2024 17:24:42 +0200 Subject: [PATCH] Prevent users from accidentally enabling action cooldowns --- forms/advanced-scene-switcher.ui | 2 +- lib/advanced-scene-switcher.hpp | 1 + lib/general.cpp | 21 ++++++++++++++++++++- lib/switcher-data.hpp | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui index e10c6535..096fd97d 100644 --- a/forms/advanced-scene-switcher.ui +++ b/forms/advanced-scene-switcher.ui @@ -390,7 +390,7 @@ - + AdvSceneSwitcher.generalTab.generalBehavior.cooldown diff --git a/lib/advanced-scene-switcher.hpp b/lib/advanced-scene-switcher.hpp index f084d64e..e3819e78 100644 --- a/lib/advanced-scene-switcher.hpp +++ b/lib/advanced-scene-switcher.hpp @@ -53,6 +53,7 @@ public slots: void on_noMatchRandomSwitch_clicked(); void NoMatchDelayDurationChanged(const Duration &); void CooldownDurationChanged(const Duration &); + void on_enableCooldown_stateChanged(int state); void on_startupBehavior_currentIndexChanged(int index); void on_logLevel_currentIndexChanged(int index); void on_autoStartEvent_currentIndexChanged(int index); diff --git a/lib/general.cpp b/lib/general.cpp index 7fd23592..e0e40a2d 100644 --- a/lib/general.cpp +++ b/lib/general.cpp @@ -91,6 +91,17 @@ void AdvSceneSwitcher::CooldownDurationChanged(const Duration &dur) switcher->cooldown = dur; } +void AdvSceneSwitcher::on_enableCooldown_stateChanged(int state) +{ + if (loading) { + return; + } + + std::lock_guard lock(switcher->m); + switcher->enableCooldown = state; + ui->cooldownTime->setEnabled(state); +} + void AdvSceneSwitcher::on_startupBehavior_currentIndexChanged(int index) { if (loading) { @@ -505,6 +516,7 @@ void SwitcherData::SaveGeneralSettings(obs_data_t *obj) noMatchDelay.Save(obj, "noMatchDelay"); cooldown.Save(obj, "cooldown"); + obs_data_set_bool(obj, "enableCooldown", enableCooldown); obs_data_set_bool(obj, "active", sceneColletionStop ? true : !stop); sceneColletionStop = false; @@ -550,6 +562,11 @@ void SwitcherData::LoadGeneralSettings(obs_data_t *obj) noMatchDelay.Load(obj, "noMatchDelay"); cooldown.Load(obj, "cooldown"); + if (!obs_data_has_user_value(obj, "enableCooldown")) { + enableCooldown = cooldown.Seconds() != 0; + } else { + enableCooldown = obs_data_get_bool(obj, "enableCooldown"); + } obs_data_set_default_bool(obj, "active", true); stop = !obs_data_get_bool(obj, "active"); @@ -653,7 +670,7 @@ void SwitcherData::CheckNoMatchSwitch(bool &match, OBSWeakSource &scene, void SwitcherData::checkSwitchCooldown(bool &match) { - if (!match) { + if (!match || !enableCooldown) { return; } @@ -822,6 +839,8 @@ void AdvSceneSwitcher::SetupGeneralTab() ui->checkInterval->setValue(switcher->interval); + ui->enableCooldown->setChecked(switcher->enableCooldown); + ui->cooldownTime->setEnabled(switcher->enableCooldown); ui->cooldownTime->SetDuration(switcher->cooldown); ui->cooldownTime->setToolTip(obs_module_text( "AdvSceneSwitcher.generalTab.generalBehavior.cooldownHint")); diff --git a/lib/switcher-data.hpp b/lib/switcher-data.hpp index 7a4f8fb4..52541a4f 100644 --- a/lib/switcher-data.hpp +++ b/lib/switcher-data.hpp @@ -131,6 +131,7 @@ public: RECORINDG_OR_STREAMING }; AutoStart autoStartEvent = AutoStart::NEVER; + bool enableCooldown = false; Duration cooldown; bool showSystemTrayNotifications = false; bool transitionOverrideOverride = false;