mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-07-18 17:04:28 -05:00
Enable getting varaible values from conditions and actions
This commit is contained in:
parent
1fd6f75ee1
commit
42773790e4
|
|
@ -1,6 +1,11 @@
|
|||
#include "macro-action.hpp"
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
|
||||
MacroAction::MacroAction(Macro *m, bool supportsVariableValue)
|
||||
: MacroSegment(m, supportsVariableValue)
|
||||
{
|
||||
}
|
||||
|
||||
bool MacroAction::Save(obs_data_t *obj) const
|
||||
{
|
||||
MacroSegment::Save(obj);
|
||||
|
|
@ -19,11 +24,21 @@ void MacroAction::LogAction() const
|
|||
vblog(LOG_INFO, "performed action %s", GetId().c_str());
|
||||
}
|
||||
|
||||
MacroRefAction::MacroRefAction(Macro *m, bool supportsVariableValue)
|
||||
: MacroAction(m, supportsVariableValue)
|
||||
{
|
||||
}
|
||||
|
||||
void MacroRefAction::ResolveMacroRef()
|
||||
{
|
||||
_macro.UpdateRef();
|
||||
}
|
||||
|
||||
MultiMacroRefAction::MultiMacroRefAction(Macro *m, bool supportsVariableValue)
|
||||
: MacroAction(m, supportsVariableValue)
|
||||
{
|
||||
}
|
||||
|
||||
void MultiMacroRefAction::ResolveMacroRef()
|
||||
{
|
||||
for (auto &m : _macros) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
class MacroAction : public MacroSegment {
|
||||
public:
|
||||
MacroAction(Macro *m) : MacroSegment(m) {}
|
||||
MacroAction(Macro *m, bool supportsVariableValue = false);
|
||||
virtual ~MacroAction() = default;
|
||||
virtual bool PerformAction() = 0;
|
||||
virtual bool Save(obs_data_t *obj) const = 0;
|
||||
|
|
@ -14,14 +14,14 @@ public:
|
|||
|
||||
class MacroRefAction : virtual public MacroAction {
|
||||
public:
|
||||
MacroRefAction(Macro *m) : MacroAction(m) {}
|
||||
MacroRefAction(Macro *m, bool supportsVariableValue = false);
|
||||
void ResolveMacroRef();
|
||||
MacroRef _macro;
|
||||
};
|
||||
|
||||
class MultiMacroRefAction : virtual public MacroAction {
|
||||
public:
|
||||
MultiMacroRefAction(Macro *m) : MacroAction(m) {}
|
||||
MultiMacroRefAction(Macro *m, bool supportsVariableValue = false);
|
||||
void ResolveMacroRef();
|
||||
std::vector<MacroRef> _macros;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -68,6 +68,11 @@ void DurationModifier::Reset()
|
|||
_dur.Reset();
|
||||
}
|
||||
|
||||
MacroCondition::MacroCondition(Macro *m, bool supportsVariableValue)
|
||||
: MacroSegment(m, supportsVariableValue)
|
||||
{
|
||||
}
|
||||
|
||||
bool MacroCondition::Save(obs_data_t *obj) const
|
||||
{
|
||||
MacroSegment::Save(obj);
|
||||
|
|
@ -146,11 +151,22 @@ void MacroCondition::SetDuration(double seconds)
|
|||
_duration.SetValue(seconds);
|
||||
}
|
||||
|
||||
MacroRefCondition::MacroRefCondition(Macro *m, bool supportsVariableValue)
|
||||
: MacroCondition(m, supportsVariableValue)
|
||||
{
|
||||
}
|
||||
|
||||
void MacroRefCondition::ResolveMacroRef()
|
||||
{
|
||||
_macro.UpdateRef();
|
||||
}
|
||||
|
||||
MultiMacroRefCondtition::MultiMacroRefCondtition(Macro *m,
|
||||
bool supportsVariableValue)
|
||||
: MacroCondition(m, supportsVariableValue)
|
||||
{
|
||||
}
|
||||
|
||||
void MultiMacroRefCondtition::ResolveMacroRef()
|
||||
{
|
||||
for (auto &m : _macros) {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ private:
|
|||
|
||||
class MacroCondition : public MacroSegment {
|
||||
public:
|
||||
MacroCondition(Macro *m) : MacroSegment(m) {}
|
||||
MacroCondition(Macro *m, bool supportsVariableValue = false);
|
||||
virtual ~MacroCondition() = default;
|
||||
virtual bool CheckCondition() = 0;
|
||||
virtual bool Save(obs_data_t *obj) const = 0;
|
||||
|
|
@ -83,14 +83,14 @@ private:
|
|||
|
||||
class MacroRefCondition : virtual public MacroCondition {
|
||||
public:
|
||||
MacroRefCondition(Macro *m) : MacroCondition(m) {}
|
||||
MacroRefCondition(Macro *m, bool supportsVariableValue = false);
|
||||
void ResolveMacroRef();
|
||||
MacroRef _macro;
|
||||
};
|
||||
|
||||
class MultiMacroRefCondtition : virtual public MacroCondition {
|
||||
public:
|
||||
MultiMacroRefCondtition(Macro *m) : MacroCondition(m) {}
|
||||
MultiMacroRefCondtition(Macro *m, bool supportsVariableValue = false);
|
||||
void ResolveMacroRef();
|
||||
std::vector<MacroRef> _macros;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,11 @@
|
|||
#include <QLabel>
|
||||
#include <QScrollBar>
|
||||
|
||||
MacroSegment::MacroSegment(Macro *m, bool supportsVariableValue)
|
||||
: _supportsVariableValue(supportsVariableValue), _macro(m)
|
||||
{
|
||||
}
|
||||
|
||||
bool MacroSegment::Save(obs_data_t *obj) const
|
||||
{
|
||||
obs_data_set_bool(obj, "collapsed", static_cast<int>(_collapsed));
|
||||
|
|
@ -39,6 +44,37 @@ bool MacroSegment::Highlight()
|
|||
return false;
|
||||
}
|
||||
|
||||
std::string MacroSegment::GetVariableValue() const
|
||||
{
|
||||
if (_supportsVariableValue) {
|
||||
return _variableValue;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void MacroSegment::SetVariableValue(const std::string &value)
|
||||
{
|
||||
if (_variableRefs > 0) {
|
||||
_variableValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
void MacroSegment::IncrementVariableRef()
|
||||
{
|
||||
if (!_supportsVariableValue) {
|
||||
return;
|
||||
}
|
||||
_variableRefs++;
|
||||
}
|
||||
|
||||
void MacroSegment::DecrementVariableRef()
|
||||
{
|
||||
if (!_supportsVariableValue || _variableRefs == 0) {
|
||||
return;
|
||||
}
|
||||
_variableRefs--;
|
||||
}
|
||||
|
||||
MouseWheelWidgetAdjustmentGuard::MouseWheelWidgetAdjustmentGuard(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class Macro;
|
|||
|
||||
class MacroSegment {
|
||||
public:
|
||||
MacroSegment(Macro *m) : _macro(m) {}
|
||||
MacroSegment(Macro *m, bool supportsVariableValue);
|
||||
virtual ~MacroSegment() = default;
|
||||
Macro *GetMacro() const { return _macro; }
|
||||
void SetIndex(int idx) { _idx = idx; }
|
||||
|
|
@ -22,15 +22,28 @@ public:
|
|||
virtual std::string GetId() const = 0;
|
||||
void SetHighlight();
|
||||
bool Highlight();
|
||||
bool SupportsVariableValue() const { return _supportsVariableValue; }
|
||||
virtual std::string GetVariableValue() const;
|
||||
void IncrementVariableRef();
|
||||
void DecrementVariableRef();
|
||||
|
||||
protected:
|
||||
int _idx = 0;
|
||||
bool _collapsed = false;
|
||||
// UI helper
|
||||
bool _highlight = false;
|
||||
void SetVariableValue(const std::string &value);
|
||||
bool IsReferencedInVars() { return _variableRefs != 0; }
|
||||
|
||||
private:
|
||||
// Macro helpers
|
||||
Macro *_macro = nullptr;
|
||||
int _idx = 0;
|
||||
|
||||
// UI helper
|
||||
bool _highlight = false;
|
||||
bool _collapsed = false;
|
||||
|
||||
// Variable helpers
|
||||
const bool _supportsVariableValue = false;
|
||||
int _variableRefs = 0;
|
||||
std::string _variableValue;
|
||||
};
|
||||
|
||||
class Section;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user