diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 1cae4792a..68bb0bd08 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -739,6 +739,7 @@ AdvSceneSwitcher.action.variable.type.findAndReplace="Find and replace in curren AdvSceneSwitcher.action.variable.type.mathExpression="Mathematical expression" AdvSceneSwitcher.action.variable.type.askForValue="Get user input" AdvSceneSwitcher.action.variable.type.environmentVariable="Set to environment variable value" +AdvSceneSwitcher.action.variable.type.sceneItemCount="Set to scene item count of scene" AdvSceneSwitcher.action.variable.askForValuePromptDefault="Assign value to variable \"%1\":" AdvSceneSwitcher.action.variable.askForValuePrompt="Assign value to variable:" AdvSceneSwitcher.action.variable.mathExpression.example="( 1 + 2 * 3 ) / 4" @@ -750,7 +751,7 @@ AdvSceneSwitcher.action.variable.invalidSelection="Invalid selection!" AdvSceneSwitcher.action.variable.actionNoVariableSupport="Getting variable values from %1 actions is not supported!" AdvSceneSwitcher.action.variable.conditionNoVariableSupport="Getting variable values from %1 conditions is not supported!" AdvSceneSwitcher.action.variable.currentSegmentValue="Current value:" -AdvSceneSwitcher.action.variable.entry="{{actions}}{{variables}}{{variables2}}{{strValue}}{{numValue}}{{segmentIndex}}{{mathExpression}}{{envVariableName}}" +AdvSceneSwitcher.action.variable.entry="{{actions}}{{variables}}{{variables2}}{{strValue}}{{numValue}}{{segmentIndex}}{{mathExpression}}{{envVariableName}}{{scenes}}" AdvSceneSwitcher.action.variable.entry.substringIndex="Substring start:{{subStringStart}}Substring size:{{subStringSize}}" AdvSceneSwitcher.action.variable.entry.substringRegex="Assign value of{{regexMatchIdx}}match using regular expression:" AdvSceneSwitcher.action.variable.entry.findAndReplace="{{findStr}}{{replaceStr}}" diff --git a/src/macro-core/macro-action-variable.cpp b/src/macro-core/macro-action-variable.cpp index 5b025bbc3..17f6daaed 100644 --- a/src/macro-core/macro-action-variable.cpp +++ b/src/macro-core/macro-action-variable.cpp @@ -43,6 +43,8 @@ const static std::map actionTypes = { "AdvSceneSwitcher.action.variable.type.askForValue"}, {MacroActionVariable::Type::ENV_VARIABLE, "AdvSceneSwitcher.action.variable.type.environmentVariable"}, + {MacroActionVariable::Type::SCENE_ITEM_COUNT, + "AdvSceneSwitcher.action.variable.type.sceneItemCount"}, }; static void apppend(Variable &var, const std::string &value) @@ -232,6 +234,10 @@ bool MacroActionVariable::PerformAction() var->SetValue(std::getenv(_envVariableName.c_str())); return true; } + case Type::SCENE_ITEM_COUNT: { + var->SetValue(GetSceneItemCount(_scene.GetScene(false))); + return true; + } } return true; @@ -261,6 +267,7 @@ bool MacroActionVariable::Save(obs_data_t *obj) const obs_data_set_bool(obj, "useInputPlaceholder", _useInputPlaceholder); _inputPlaceholder.Save(obj, "inputPlaceholder"); _envVariableName.Save(obj, "environmentVariableName"); + _scene.Save(obj); return true; } @@ -288,6 +295,7 @@ bool MacroActionVariable::Load(obs_data_t *obj) _useInputPlaceholder = obs_data_get_bool(obj, "useInputPlaceholder"); _inputPlaceholder.Load(obj, "inputPlaceholder"); _envVariableName.Load(obj, "environmentVariableName"); + _scene.Load(obj); return true; } @@ -413,7 +421,8 @@ MacroActionVariableEdit::MacroActionVariableEdit( _placeholderLayout(new QHBoxLayout()), _useInputPlaceholder(new QCheckBox()), _inputPlaceholder(new VariableLineEdit(this)), - _envVariable(new VariableLineEdit(this)) + _envVariable(new VariableLineEdit(this)), + _scenes(new SceneSelectionWidget(this, true, false, true, true, true)) { _numValue->setMinimum(-9999999999); _numValue->setMaximum(9999999999); @@ -474,6 +483,8 @@ MacroActionVariableEdit::MacroActionVariableEdit( SLOT(InputPlaceholderChanged())); QWidget::connect(_envVariable, SIGNAL(editingFinished()), this, SLOT(EnvVariableChanged())); + QWidget::connect(_scenes, SIGNAL(SceneChanged(const SceneSelection &)), + this, SLOT(SceneChanged(const SceneSelection &))); std::unordered_map widgetPlaceholders = { {"{{variables}}", _variables}, @@ -493,6 +504,7 @@ MacroActionVariableEdit::MacroActionVariableEdit( {"{{useInputPlaceholder}}", _useInputPlaceholder}, {"{{inputPlaceholder}}", _inputPlaceholder}, {"{{envVariableName}}", _envVariable}, + {"{{scenes}}", _scenes}, }; auto entryLayout = new QHBoxLayout; PlaceWidgets(obs_module_text("AdvSceneSwitcher.action.variable.entry"), @@ -585,6 +597,7 @@ void MacroActionVariableEdit::UpdateEntryData() _useInputPlaceholder->setChecked(_entryData->_useInputPlaceholder); _inputPlaceholder->setText(_entryData->_inputPlaceholder); _envVariable->setText(_entryData->_envVariableName); + _scenes->SetScene(_entryData->_scene); SetWidgetVisibility(); } @@ -902,6 +915,16 @@ void MacroActionVariableEdit::EnvVariableChanged() _entryData->_envVariableName = _envVariable->text().toStdString(); } +void MacroActionVariableEdit::SceneChanged(const SceneSelection &scene) +{ + if (_loading || !_entryData) { + return; + } + + auto lock = LockContext(); + _entryData->_scene = scene; +} + void MacroActionVariableEdit::SetWidgetVisibility() { if (!_entryData) { @@ -976,6 +999,8 @@ void MacroActionVariableEdit::SetWidgetVisibility() } _envVariable->setVisible(_entryData->_type == MacroActionVariable::Type::ENV_VARIABLE); + _scenes->setVisible(_entryData->_type == + MacroActionVariable::Type::SCENE_ITEM_COUNT); adjustSize(); updateGeometry(); } diff --git a/src/macro-core/macro-action-variable.hpp b/src/macro-core/macro-action-variable.hpp index 6d8583933..f2c03430d 100644 --- a/src/macro-core/macro-action-variable.hpp +++ b/src/macro-core/macro-action-variable.hpp @@ -3,6 +3,7 @@ #include "macro-segment-selection.hpp" #include "regex-config.hpp" #include "resizing-text-edit.hpp" +#include "scene-selection.hpp" #include "variable-line-edit.hpp" namespace advss { @@ -38,6 +39,7 @@ class MacroActionVariable : public MacroAction { MATH_EXPRESSION, USER_INPUT, ENV_VARIABLE, + SCENE_ITEM_COUNT, }; Type _type = Type::SET_FIXED_VALUE; @@ -67,6 +69,7 @@ class MacroActionVariable : public MacroAction { #else StringVariable _envVariableName = "HOME"; #endif + SceneSelection _scene; private: void DecrementCurrentSegmentVariableRef(); @@ -119,6 +122,7 @@ private slots: void UseInputPlaceholderChanged(int); void InputPlaceholderChanged(); void EnvVariableChanged(); + void SceneChanged(const SceneSelection &); signals: void HeaderInfoChanged(const QString &); @@ -155,6 +159,7 @@ private slots: QCheckBox *_useInputPlaceholder; VariableLineEdit *_inputPlaceholder; VariableLineEdit *_envVariable; + SceneSelectionWidget *_scenes; std::shared_ptr _entryData; QTimer _timer;