diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index b6310975..6b97ade3 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -207,6 +207,10 @@ AdvSceneSwitcher.macroTab.currentUseCustomConditionCheckInterval="Check conditio AdvSceneSwitcher.macroTab.currentUseCustomConditionCheckIntervalWarning="⚠️ The selected value is lower than the interval configured on the General tab.\nThe configured value not have any effect!" AdvSceneSwitcher.macroTab.currentSkipExecutionOnStartup="Skip execution of actions of current macro on startup" AdvSceneSwitcher.macroTab.currentStopActionsIfNotDone="Stop and rerun actions of the currently selected macro, if the actions are still running, when a new execution is triggered" +AdvSceneSwitcher.macroTab.pauseStateSaveBehavior="On startup set the pause state of the current macro to:" +AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.persist="The state the macro was last in" +AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.pause="Paused" +AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.unpause="Unpaused" AdvSceneSwitcher.macroTab.currentRegisterDock="Register dock widget to control the pause state of selected macro or run it manually" AdvSceneSwitcher.macroTab.currentDockAddRunButton="Add button to run the macro" AdvSceneSwitcher.macroTab.currentDockAddPauseButton="Add button to pause or unpause the macro" diff --git a/lib/macro/macro-settings.cpp b/lib/macro/macro-settings.cpp index 6663013d..5cb84ae6 100644 --- a/lib/macro/macro-settings.cpp +++ b/lib/macro/macro-settings.cpp @@ -78,6 +78,7 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent, new DurationSelection(this, true, 0.01)), _currentCustomConditionCheckIntervalWarning(new QLabel(obs_module_text( "AdvSceneSwitcher.macroTab.currentUseCustomConditionCheckIntervalWarning"))), + _currentPauseSaveBehavior(new QComboBox(this)), _currentSkipOnStartup(new QCheckBox(obs_module_text( "AdvSceneSwitcher.macroTab.currentSkipExecutionOnStartup"))), _currentStopActionsIfNotDone(new QCheckBox(obs_module_text( @@ -113,6 +114,19 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent, _currentUseShortCircuitEvaluation->setToolTip(obs_module_text( "AdvSceneSwitcher.macroTab.shortCircuit.tooltip")); + _currentPauseSaveBehavior->addItem( + obs_module_text( + "AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.persist"), + static_cast(Macro::PauseStateSaveBehavior::PERSIST)); + _currentPauseSaveBehavior->addItem( + obs_module_text( + "AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.pause"), + static_cast(Macro::PauseStateSaveBehavior::PAUSE)); + _currentPauseSaveBehavior->addItem( + obs_module_text( + "AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.unpause"), + static_cast(Macro::PauseStateSaveBehavior::UNPAUSE)); + auto highlightOptions = new QGroupBox( obs_module_text("AdvSceneSwitcher.macroTab.highlightSettings")); auto highlightLayout = new QVBoxLayout; @@ -145,8 +159,15 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent, customConditionIntervalLayout->addLayout(durationLayout); customConditionIntervalLayout->addWidget( _currentCustomConditionCheckIntervalWarning); - generalLayout->addLayout(customConditionIntervalLayout); + + auto pauseStateSaveBehavorLayout = new QHBoxLayout(); + pauseStateSaveBehavorLayout->addWidget(new QLabel(obs_module_text( + "AdvSceneSwitcher.macroTab.pauseStateSaveBehavior"))); + pauseStateSaveBehavorLayout->addWidget(_currentPauseSaveBehavior); + pauseStateSaveBehavorLayout->addStretch(); + generalLayout->addLayout(pauseStateSaveBehavorLayout); + generalOptions->setLayout(generalLayout); auto inputOptions = new QGroupBox( @@ -266,6 +287,7 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent, _currentStopActionsIfNotDone->hide(); _currentUseShortCircuitEvaluation->hide(); SetLayoutVisible(customConditionIntervalLayout, false); + SetLayoutVisible(pauseStateSaveBehavorLayout, false); inputOptions->hide(); _dockOptions->hide(); @@ -282,6 +304,9 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent, _currentCustomConditionCheckInterval->setEnabled( macro->CustomConditionCheckIntervalEnabled()); SetCustomConditionIntervalWarningVisibility(); + _currentPauseSaveBehavior->setCurrentIndex( + _currentPauseSaveBehavior->findData( + static_cast(macro->GetPauseStateSaveBehavior()))); _currentSkipOnStartup->setChecked(macro->SkipExecOnStart()); _currentStopActionsIfNotDone->setChecked(macro->StopActionsIfNotDone()); _currentInputs->SetInputs(macro->GetInputVariables()); @@ -424,6 +449,10 @@ bool MacroSettingsDialog::AskForSettings(QWidget *parent, dialog._currentUseCustomConditionCheckInterval->isChecked()); macro->SetCustomConditionCheckInterval( dialog._currentCustomConditionCheckInterval->GetDuration()); + macro->SetPauseStateSaveBehavior( + static_cast( + dialog._currentPauseSaveBehavior->currentData() + .toInt())); macro->SetSkipExecOnStart(dialog._currentSkipOnStartup->isChecked()); macro->SetStopActionsIfNotDone( dialog._currentStopActionsIfNotDone->isChecked()); diff --git a/lib/macro/macro-settings.hpp b/lib/macro/macro-settings.hpp index dd51a7ee..f8910631 100644 --- a/lib/macro/macro-settings.hpp +++ b/lib/macro/macro-settings.hpp @@ -61,6 +61,7 @@ private: QCheckBox *_currentUseCustomConditionCheckInterval; DurationSelection *_currentCustomConditionCheckInterval; QLabel *_currentCustomConditionCheckIntervalWarning; + QComboBox *_currentPauseSaveBehavior; QCheckBox *_currentSkipOnStartup; QCheckBox *_currentStopActionsIfNotDone; MacroInputSelection *_currentInputs; diff --git a/lib/macro/macro.cpp b/lib/macro/macro.cpp index f00492e7..9209449d 100644 --- a/lib/macro/macro.cpp +++ b/lib/macro/macro.cpp @@ -481,6 +481,16 @@ void Macro::AddHelperThread(std::thread &&newThread) _helperThreads.push_back(std::move(newThread)); } +void Macro::SetPauseStateSaveBehavior(PauseStateSaveBehavior behavior) +{ + _pauseSaveBehavior = behavior; +} + +Macro::PauseStateSaveBehavior Macro::GetPauseStateSaveBehavior() const +{ + return _pauseSaveBehavior; +} + void Macro::Stop() { _stop = true; @@ -690,6 +700,8 @@ bool Macro::Save(obs_data_t *obj, bool saveForCopy) const return true; } + obs_data_set_int(obj, "pauseSaveBehavior", + static_cast(_pauseSaveBehavior)); obs_data_set_bool(obj, "pause", _paused); obs_data_set_bool(obj, "parallel", _runInParallel); obs_data_set_bool(obj, "onChange", _performActionsOnChange); @@ -760,7 +772,22 @@ bool Macro::Load(obs_data_t *obj) return true; } - _paused = obs_data_get_bool(obj, "pause"); + _pauseSaveBehavior = static_cast( + obs_data_get_int(obj, "pauseSaveBehavior")); + switch (_pauseSaveBehavior) { + case PauseStateSaveBehavior::PERSIST: + _paused = obs_data_get_bool(obj, "pause"); + break; + case PauseStateSaveBehavior::PAUSE: + _paused = true; + break; + case PauseStateSaveBehavior::UNPAUSE: + _paused = false; + break; + default: + _paused = obs_data_get_bool(obj, "pause"); + break; + } _runInParallel = obs_data_get_bool(obj, "parallel"); _performActionsOnChange = obs_data_get_bool(obj, "onChange"); _skipExecOnStart = obs_data_get_bool(obj, "skipExecOnStart"); diff --git a/lib/macro/macro.hpp b/lib/macro/macro.hpp index e1abacb7..727728e5 100644 --- a/lib/macro/macro.hpp +++ b/lib/macro/macro.hpp @@ -25,6 +25,8 @@ class Macro { using TimePoint = std::chrono::high_resolution_clock::time_point; public: + enum class PauseStateSaveBehavior { PERSIST, PAUSE, UNPAUSE }; + Macro(const std::string &name = "", const bool addHotkey = false, const bool shortCircuitEvaluation = false); ~Macro(); @@ -45,6 +47,9 @@ public: bool Paused() const { return _paused; } bool WasPausedSince(const TimePoint &) const; + void SetPauseStateSaveBehavior(PauseStateSaveBehavior); + PauseStateSaveBehavior GetPauseStateSaveBehavior() const; + void Stop(); bool GetStop() const { return _stop; } void ResetTimers(); @@ -211,6 +216,9 @@ private: obs_hotkey_id _unpauseHotkey = OBS_INVALID_HOTKEY_ID; obs_hotkey_id _togglePauseHotkey = OBS_INVALID_HOTKEY_ID; + PauseStateSaveBehavior _pauseSaveBehavior = + PauseStateSaveBehavior::PERSIST; + MacroInputVariables _inputVariables; // UI helpers