mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-07-02 00:22:10 -05:00
Add option to disable individual actions of macros
This commit is contained in:
parent
1d7ce510f7
commit
371b4ae05d
|
|
@ -3,8 +3,11 @@
|
|||
#include "macro-action-edit.hpp"
|
||||
#include "macro-action-scene-switch.hpp"
|
||||
#include "section.hpp"
|
||||
#include "switch-button.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QGraphicsOpacityEffect>
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::map<std::string, MacroActionInfo> &MacroActionFactory::GetMap()
|
||||
|
|
@ -79,16 +82,20 @@ MacroActionEdit::MacroActionEdit(QWidget *parent,
|
|||
const std::string &id)
|
||||
: MacroSegmentEdit(switcher->macroProperties._highlightActions, parent),
|
||||
_actionSelection(new FilterComboBox()),
|
||||
_enable(new SwitchButton()),
|
||||
_entryData(entryData)
|
||||
{
|
||||
QWidget::connect(_actionSelection,
|
||||
SIGNAL(currentTextChanged(const QString &)), this,
|
||||
SLOT(ActionSelectionChanged(const QString &)));
|
||||
QWidget::connect(_enable, SIGNAL(checked(bool)), this,
|
||||
SLOT(ActionEnableChanged(bool)));
|
||||
QWidget::connect(window(), SIGNAL(HighlightActionsChanged(bool)), this,
|
||||
SLOT(EnableHighlight(bool)));
|
||||
|
||||
populateActionSelection(_actionSelection);
|
||||
|
||||
_section->AddHeaderWidget(_enable);
|
||||
_section->AddHeaderWidget(_actionSelection);
|
||||
_section->AddHeaderWidget(_headerInfo);
|
||||
|
||||
|
|
@ -140,6 +147,9 @@ void MacroActionEdit::UpdateEntryData(const std::string &id)
|
|||
{
|
||||
_actionSelection->setCurrentText(
|
||||
obs_module_text(MacroActionFactory::GetActionName(id).c_str()));
|
||||
const bool enabled = (*_entryData)->Enabled();
|
||||
_enable->setChecked(enabled);
|
||||
SetDisableEffect(!enabled);
|
||||
auto widget = MacroActionFactory::CreateWidget(id, this, *_entryData);
|
||||
QWidget::connect(widget, SIGNAL(HeaderInfoChanged(const QString &)),
|
||||
this, SLOT(HeaderInfoChanged(const QString &)));
|
||||
|
|
@ -154,6 +164,28 @@ void MacroActionEdit::SetEntryData(std::shared_ptr<MacroAction> *data)
|
|||
_entryData = data;
|
||||
}
|
||||
|
||||
void advss::MacroActionEdit::SetDisableEffect(bool value)
|
||||
{
|
||||
if (value) {
|
||||
auto effect = new QGraphicsOpacityEffect(this);
|
||||
effect->setOpacity(0.5);
|
||||
_section->setGraphicsEffect(effect);
|
||||
} else {
|
||||
_section->setGraphicsEffect(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionEdit::ActionEnableChanged(bool value)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
(*_entryData)->SetEnabled(value);
|
||||
SetDisableEffect(!value);
|
||||
}
|
||||
|
||||
std::shared_ptr<MacroSegment> MacroActionEdit::Data()
|
||||
{
|
||||
return *_entryData;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
namespace advss {
|
||||
|
||||
class SwitchButton;
|
||||
|
||||
struct MacroActionInfo {
|
||||
using TCreateMethod = std::shared_ptr<MacroAction> (*)(Macro *m);
|
||||
using TCreateWidgetMethod = QWidget *(*)(QWidget *parent,
|
||||
|
|
@ -44,11 +46,14 @@ public:
|
|||
|
||||
private slots:
|
||||
void ActionSelectionChanged(const QString &text);
|
||||
void ActionEnableChanged(bool);
|
||||
|
||||
private:
|
||||
std::shared_ptr<MacroSegment> Data();
|
||||
void SetDisableEffect(bool);
|
||||
|
||||
FilterComboBox *_actionSelection;
|
||||
SwitchButton *_enable;
|
||||
|
||||
std::shared_ptr<MacroAction> *_entryData;
|
||||
bool _loading = true;
|
||||
|
|
|
|||
|
|
@ -11,12 +11,15 @@ bool MacroAction::Save(obs_data_t *obj) const
|
|||
{
|
||||
MacroSegment::Save(obj);
|
||||
obs_data_set_string(obj, "id", GetId().c_str());
|
||||
obs_data_set_bool(obj, "enabled", _enabled);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroAction::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroSegment::Load(obj);
|
||||
obs_data_set_default_bool(obj, "enabled", true);
|
||||
_enabled = obs_data_get_bool(obj, "enabled");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +28,16 @@ void MacroAction::LogAction() const
|
|||
vblog(LOG_INFO, "performed action %s", GetId().c_str());
|
||||
}
|
||||
|
||||
void MacroAction::SetEnabled(bool value)
|
||||
{
|
||||
_enabled = value;
|
||||
}
|
||||
|
||||
bool MacroAction::Enabled() const
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
MacroRefAction::MacroRefAction(Macro *m, bool supportsVariableValue)
|
||||
: MacroAction(m, supportsVariableValue)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ public:
|
|||
virtual bool Save(obs_data_t *obj) const = 0;
|
||||
virtual bool Load(obs_data_t *obj) = 0;
|
||||
virtual void LogAction() const;
|
||||
void SetEnabled(bool);
|
||||
bool Enabled() const;
|
||||
|
||||
private:
|
||||
bool _enabled = true;
|
||||
};
|
||||
|
||||
class MacroRefAction : virtual public MacroAction {
|
||||
|
|
|
|||
|
|
@ -255,13 +255,20 @@ void Macro::RunActions(bool &retVal, bool ignorePause)
|
|||
{
|
||||
bool ret = true;
|
||||
for (auto &a : _actions) {
|
||||
a->LogAction();
|
||||
ret = ret && a->PerformAction();
|
||||
if (a->Enabled()) {
|
||||
a->LogAction();
|
||||
ret = ret && a->PerformAction();
|
||||
} else {
|
||||
vblog(LOG_INFO, "skipping disabled action %s",
|
||||
a->GetId().c_str());
|
||||
}
|
||||
if (!ret || (_paused && !ignorePause) || _stop || _die) {
|
||||
retVal = ret;
|
||||
break;
|
||||
}
|
||||
a->SetHighlight();
|
||||
if (a->Enabled()) {
|
||||
a->SetHighlight();
|
||||
}
|
||||
}
|
||||
_done = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user