diff --git a/CMakeLists.txt b/CMakeLists.txt index 0be4b545..271bf4bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,6 +247,7 @@ set(advanced-scene-switcher_HEADERS src/headers/macro-condition-window.hpp src/headers/macro.hpp src/headers/macro-list-entry-widget.hpp + src/headers/macro-properties.hpp src/headers/macro-segment.hpp src/headers/macro-segment-list.hpp src/headers/macro-selection.hpp @@ -350,6 +351,7 @@ set(advanced-scene-switcher_SOURCES src/macro-condition-window.cpp src/macro.cpp src/macro-list-entry-widget.cpp + src/macro-properties.cpp src/macro-segment.cpp src/macro-segment-list.cpp src/macro-selection.cpp diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 6af59ece..66cf8396 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -31,7 +31,6 @@ AdvSceneSwitcher.generalTab.generalBehavior.saveWindowGeo="Save window position AdvSceneSwitcher.generalTab.generalBehavior.showTrayNotifications="Show system tray notifications" AdvSceneSwitcher.generalTab.generalBehavior.disableUIHints="Disable UI hints" AdvSceneSwitcher.generalTab.generalBehavior.hideLegacyTabs="Hide tabs which can be represented via macros" -AdvSceneSwitcher.generalTab.generalBehavior.highlightExecutedMacros="Highlight recently executed macros" AdvSceneSwitcher.generalTab.priority="Priority" AdvSceneSwitcher.generalTab.priority.description="Switching methods priority (Highest priority is at the top)" AdvSceneSwitcher.generalTab.priority.threadPriority="Use thread priority" @@ -80,6 +79,9 @@ AdvSceneSwitcher.macroTab.expandAll="Expand all" AdvSceneSwitcher.macroTab.collapseAll="Collapse all" AdvSceneSwitcher.macroTab.maximize="Maximize" AdvSceneSwitcher.macroTab.minimize="Minimize" +AdvSceneSwitcher.macroTab.highlightExecutedMacros="Highlight recently executed macros" +AdvSceneSwitcher.macroTab.highlightTrueConditions="Highlight conditions of currently selected macro that evaluated to true recently" +AdvSceneSwitcher.macroTab.highlightPerformedActions="Highlight recently performed actions of currently selected macro" ; Macro Logic AdvSceneSwitcher.logic.none="Ignore entry" diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui index a46e25e8..9a1575af 100644 --- a/forms/advanced-scene-switcher.ui +++ b/forms/advanced-scene-switcher.ui @@ -325,30 +325,6 @@ - - - - - - AdvSceneSwitcher.generalTab.generalBehavior.highlightExecutedMacros - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - @@ -750,9 +726,9 @@ AdvSceneSwitcher.macroTab.edit - + - + @@ -785,7 +761,7 @@ - + Qt::Horizontal @@ -797,6 +773,25 @@ + + + + + 22 + 22 + + + + + + + true + + + propertiesIconSmall + + + diff --git a/src/general.cpp b/src/general.cpp index 39930fb7..8529d303 100644 --- a/src/general.cpp +++ b/src/general.cpp @@ -192,16 +192,6 @@ void AdvSceneSwitcher::on_uiHintsDisable_stateChanged(int state) switcher->disableHints = state; } -void AdvSceneSwitcher::on_highlightExecutedMacros_stateChanged(int state) -{ - if (loading) { - return; - } - - switcher->highlightExecutedMacros = state; - emit HighlightMacrosChanged(switcher->highlightExecutedMacros); -} - bool isLegacyTab(const QString &name) { return name == obs_module_text( @@ -587,8 +577,6 @@ void SwitcherData::saveGeneralSettings(obs_data_t *obj) obs_data_set_bool(obj, "showSystemTrayNotifications", showSystemTrayNotifications); obs_data_set_bool(obj, "disableHints", disableHints); - obs_data_set_bool(obj, "highlightExecutedMacros", - highlightExecutedMacros); obs_data_set_bool(obj, "hideLegacyTabs", hideLegacyTabs); obs_data_set_int(obj, "priority0", functionNamesByPriority[0]); @@ -663,8 +651,6 @@ void SwitcherData::loadGeneralSettings(obs_data_t *obj) showSystemTrayNotifications = obs_data_get_bool(obj, "showSystemTrayNotifications"); disableHints = obs_data_get_bool(obj, "disableHints"); - highlightExecutedMacros = - obs_data_get_bool(obj, "highlightExecutedMacros"); hideLegacyTabs = obs_data_get_bool(obj, "hideLegacyTabs"); obs_data_set_default_int(obj, "priority0", default_priority_0); @@ -879,8 +865,6 @@ void AdvSceneSwitcher::setupGeneralTab() ui->showTrayNotifications->setChecked( switcher->showSystemTrayNotifications); ui->uiHintsDisable->setChecked(switcher->disableHints); - ui->highlightExecutedMacros->setChecked( - switcher->highlightExecutedMacros); ui->hideLegacyTabs->setChecked(switcher->hideLegacyTabs); for (int p : switcher->functionNamesByPriority) { diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp index b6a640c1..55e58db3 100644 --- a/src/headers/advanced-scene-switcher.hpp +++ b/src/headers/advanced-scene-switcher.hpp @@ -93,6 +93,8 @@ signals: void MacroRemoved(const QString &name); void MacroRenamed(const QString &oldName, const QString newName); void HighlightMacrosChanged(bool value); + void HighlightActionsChanged(bool value); + void HighlightConditionsChanged(bool value); void SceneGroupAdded(const QString &name); void SceneGroupRemoved(const QString &name); void SceneGroupRenamed(const QString &oldName, const QString newName); @@ -161,6 +163,7 @@ public slots: void HighlightControls(); void MacroDragDropReorder(QModelIndex, int, int, QModelIndex, int); void HighlightOnChange(); + void on_macroProperties_clicked(); void on_screenRegionSwitches_currentRowChanged(int idx); void on_showFrame_clicked(); @@ -191,7 +194,6 @@ public slots: void on_saveWindowGeo_stateChanged(int state); void on_showTrayNotifications_stateChanged(int state); void on_uiHintsDisable_stateChanged(int state); - void on_highlightExecutedMacros_stateChanged(int state); void on_hideLegacyTabs_stateChanged(int state); void on_exportSettings_clicked(); diff --git a/src/headers/macro-properties.hpp b/src/headers/macro-properties.hpp new file mode 100644 index 00000000..91940952 --- /dev/null +++ b/src/headers/macro-properties.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include +#include + +class MacroProperties { +public: + void Save(obs_data_t *obj); + void Load(obs_data_t *obj); + + bool _highlightExecuted = false; + bool _highlightConditions = false; + bool _highlightActions = false; +}; + +class MacroPropertiesDialog : public QDialog { + Q_OBJECT + +public: + MacroPropertiesDialog(QWidget *parent, const MacroProperties &); + static bool AskForSettings(QWidget *parent, MacroProperties &userInput); + +private: + QCheckBox *_executed; + QCheckBox *_conditions; + QCheckBox *_actions; +}; diff --git a/src/headers/switcher-data-structs.hpp b/src/headers/switcher-data-structs.hpp index a67db717..7033417b 100644 --- a/src/headers/switcher-data-structs.hpp +++ b/src/headers/switcher-data-structs.hpp @@ -26,6 +26,7 @@ #include "switch-network.hpp" #include "macro.hpp" +#include "macro-properties.hpp" #include "duration-control.hpp" constexpr auto default_interval = 300; @@ -88,7 +89,6 @@ struct SwitcherData { bool verbose = false; bool disableHints = false; bool hideLegacyTabs = false; - bool highlightExecutedMacros = false; bool showSystemTrayNotifications = false; bool showFrame = false; bool transitionOverrideOverride = false; @@ -121,6 +121,7 @@ struct SwitcherData { Duration cooldown; std::chrono::high_resolution_clock::time_point lastMatchTime; + MacroProperties macroProperties; std::deque> macros; std::condition_variable macroWaitCv; std::atomic_bool abortMacroWait = {false}; diff --git a/src/macro-action-edit.cpp b/src/macro-action-edit.cpp index 847c762f..4bbcda47 100644 --- a/src/macro-action-edit.cpp +++ b/src/macro-action-edit.cpp @@ -63,7 +63,7 @@ static inline void populateActionSelection(QComboBox *list) MacroActionEdit::MacroActionEdit(QWidget *parent, std::shared_ptr *entryData, const std::string &id) - : MacroSegmentEdit(switcher->highlightExecutedMacros, parent), + : MacroSegmentEdit(switcher->macroProperties._highlightActions, parent), _entryData(entryData) { _actionSelection = new QComboBox(); @@ -71,6 +71,8 @@ MacroActionEdit::MacroActionEdit(QWidget *parent, QWidget::connect(_actionSelection, SIGNAL(currentTextChanged(const QString &)), this, SLOT(ActionSelectionChanged(const QString &))); + QWidget::connect(window(), SIGNAL(HighlightActionsChanged(bool)), this, + SLOT(EnableHighlight(bool))); populateActionSelection(_actionSelection); diff --git a/src/macro-condition-edit.cpp b/src/macro-condition-edit.cpp index e357a306..a417effc 100644 --- a/src/macro-condition-edit.cpp +++ b/src/macro-condition-edit.cpp @@ -92,7 +92,8 @@ static inline void populateConditionSelection(QComboBox *list) MacroConditionEdit::MacroConditionEdit( QWidget *parent, std::shared_ptr *entryData, const std::string &id, bool root) - : MacroSegmentEdit(switcher->highlightExecutedMacros, parent), + : MacroSegmentEdit(switcher->macroProperties._highlightConditions, + parent), _entryData(entryData), _isRoot(root) { @@ -112,6 +113,8 @@ MacroConditionEdit::MacroConditionEdit( QWidget::connect(_dur, SIGNAL(ConditionChanged(DurationCondition)), this, SLOT(DurationConditionChanged(DurationCondition))); + QWidget::connect(window(), SIGNAL(HighlightConditionsChanged(bool)), + this, SLOT(EnableHighlight(bool))); populateLogicSelection(_logicSelection, root); populateConditionSelection(_conditionSelection); diff --git a/src/macro-properties.cpp b/src/macro-properties.cpp new file mode 100644 index 00000000..9b887561 --- /dev/null +++ b/src/macro-properties.cpp @@ -0,0 +1,79 @@ +#include "headers/macro-properties.hpp" + +#include +#include +#include + +void MacroProperties::Save(obs_data_t *obj) +{ + auto data = obs_data_create(); + obs_data_set_bool(data, "highlightExecuted", _highlightExecuted); + obs_data_set_bool(data, "highlightConditions", _highlightConditions); + obs_data_set_bool(data, "highlightActions", _highlightActions); + obs_data_set_obj(obj, "macroProperties", data); + obs_data_release(data); +} + +void MacroProperties::Load(obs_data_t *obj) +{ + auto data = obs_data_get_obj(obj, "macroProperties"); + // TODO: Remove in future version + if (obs_data_has_user_value(obj, "highlightExecutedMacros")) { + _highlightExecuted = + obs_data_get_bool(obj, "highlightExecutedMacros"); + } else { + _highlightExecuted = + obs_data_get_bool(data, "highlightExecuted"); + } + _highlightConditions = obs_data_get_bool(data, "highlightConditions"); + _highlightActions = obs_data_get_bool(data, "highlightActions"); + obs_data_release(data); +} + +MacroPropertiesDialog::MacroPropertiesDialog(QWidget *parent, + const MacroProperties &prop) + : QDialog(parent), + _executed(new QCheckBox(obs_module_text( + "AdvSceneSwitcher.macroTab.highlightExecutedMacros"))), + _conditions(new QCheckBox(obs_module_text( + "AdvSceneSwitcher.macroTab.highlightTrueConditions"))), + _actions(new QCheckBox(obs_module_text( + "AdvSceneSwitcher.macroTab.highlightPerformedActions"))) +{ + setModal(true); + setWindowModality(Qt::WindowModality::WindowModal); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + setFixedWidth(555); + setMinimumHeight(100); + + _executed->setChecked(prop._highlightExecuted); + _conditions->setChecked(prop._highlightConditions); + _actions->setChecked(prop._highlightActions); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(_executed); + layout->addWidget(_conditions); + layout->addWidget(_actions); + setLayout(layout); + + QDialogButtonBox *buttonbox = new QDialogButtonBox( + QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + layout->addWidget(buttonbox); + buttonbox->setCenterButtons(true); + connect(buttonbox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonbox, &QDialogButtonBox::rejected, this, &QDialog::reject); +} + +bool MacroPropertiesDialog::AskForSettings(QWidget *parent, + MacroProperties &userInput) +{ + MacroPropertiesDialog dialog(parent, userInput); + dialog.setWindowTitle(obs_module_text("AdvSceneSwitcher.windowTitle")); + if (dialog.exec() != DialogCode::Accepted) { + return false; + } + userInput._highlightExecuted = dialog._executed->isChecked(); + userInput._highlightConditions = dialog._conditions->isChecked(); + userInput._highlightActions = dialog._actions->isChecked(); + return true; +} diff --git a/src/macro-segment.cpp b/src/macro-segment.cpp index 66fa4382..84ca6ef3 100644 --- a/src/macro-segment.cpp +++ b/src/macro-segment.cpp @@ -98,9 +98,6 @@ MacroSegmentEdit::MacroSegmentEdit(bool highlight, QWidget *parent) SIGNAL(SceneGroupRenamed(const QString &, const QString)), this, SIGNAL(SceneGroupRenamed(const QString &, const QString))); - QWidget::connect(parent, SIGNAL(HighlightMacrosChanged(bool)), this, - SLOT(EnableHighlight(bool))); - _timer.setInterval(1500); connect(&_timer, SIGNAL(timeout()), this, SLOT(Highlight())); _timer.start(); diff --git a/src/macro-tab.cpp b/src/macro-tab.cpp index b133f234..69be9a5c 100644 --- a/src/macro-tab.cpp +++ b/src/macro-tab.cpp @@ -4,6 +4,7 @@ #include "headers/macro-condition-edit.hpp" #include "headers/advanced-scene-switcher.hpp" #include "headers/name-dialog.hpp" +#include "headers/macro-properties.hpp" #include "headers/utility.hpp" #include @@ -68,7 +69,7 @@ QListWidgetItem *AddNewMacroListEntry(QListWidget *list, QListWidgetItem *item = new QListWidgetItem(list); item->setData(Qt::UserRole, QString::fromStdString(macro->Name())); auto listEntry = new MacroListEntryWidget( - macro, switcher->highlightExecutedMacros, list); + macro, switcher->macroProperties._highlightExecuted, list); item->setSizeHint(listEntry->minimumSizeHint()); list->setItemWidget(item, listEntry); return item; @@ -416,13 +417,26 @@ void AdvSceneSwitcher::HighlightOnChange() return; } - if (switcher->highlightExecutedMacros && + if (switcher->macroProperties._highlightExecuted && macro->OnChangePreventedActionsRecently()) { PulseWidget(ui->runMacroOnChange, Qt::yellow, Qt::transparent, true); } } +void AdvSceneSwitcher::on_macroProperties_clicked() +{ + MacroProperties prop = switcher->macroProperties; + bool accepted = MacroPropertiesDialog::AskForSettings(this, prop); + if (!accepted) { + return; + } + switcher->macroProperties = prop; + emit HighlightMacrosChanged(prop._highlightExecuted); + emit HighlightActionsChanged(prop._highlightActions); + emit HighlightConditionsChanged(prop._highlightConditions); +} + void AdvSceneSwitcher::setupMacroTab() { const QSignalBlocker signalBlocker(ui->macros); diff --git a/src/macro.cpp b/src/macro.cpp index fa9f37f6..bb8c75f9 100644 --- a/src/macro.cpp +++ b/src/macro.cpp @@ -600,6 +600,8 @@ void MacroAction::LogAction() void SwitcherData::saveMacros(obs_data_t *obj) { + switcher->macroProperties.Save(obj); + obs_data_array_t *macroArray = obs_data_array_create(); for (auto &m : macros) { obs_data_t *array_obj = obs_data_create(); @@ -615,8 +617,9 @@ void SwitcherData::saveMacros(obs_data_t *obj) void SwitcherData::loadMacros(obs_data_t *obj) { - macros.clear(); + switcher->macroProperties.Load(obj); + macros.clear(); obs_data_array_t *macroArray = obs_data_get_array(obj, "macros"); size_t count = obs_data_array_count(macroArray);