mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Add support for else actions to MacroSegmentSelection
This commit is contained in:
parent
f93175db77
commit
b8b0682aaf
|
|
@ -102,7 +102,7 @@ bool MacroConditionMacro::CheckActionStateCondition()
|
|||
if (!macro) {
|
||||
return false;
|
||||
}
|
||||
if (!IsValidMacroSegmentIndex(macro.get(), _actionIndex - 1, false)) {
|
||||
if (!IsValidActionIndex(macro.get(), _actionIndex - 1)) {
|
||||
return false;
|
||||
}
|
||||
if (_type == Type::ACTION_DISABLED) {
|
||||
|
|
|
|||
|
|
@ -21,13 +21,13 @@ static void appendNestedMacros(std::deque<std::shared_ptr<Macro>> ¯os,
|
|||
for (const auto &action : actions) {
|
||||
const auto nestedMacroAction =
|
||||
dynamic_cast<MacroActionMacro *>(action.get());
|
||||
if (nestedMacroAction) {
|
||||
macros.push_back(
|
||||
nestedMacroAction->_nestedMacro);
|
||||
appendNestedMacros(
|
||||
macros,
|
||||
nestedMacroAction->_nestedMacro.get());
|
||||
if (!nestedMacroAction) {
|
||||
continue;
|
||||
}
|
||||
|
||||
macros.push_back(nestedMacroAction->_nestedMacro);
|
||||
appendNestedMacros(
|
||||
macros, nestedMacroAction->_nestedMacro.get());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -53,11 +53,13 @@ std::deque<std::shared_ptr<Macro>> GetAllMacros()
|
|||
for (const auto &topLevelMacro : macros) {
|
||||
appendNestedMacros(macros, topLevelMacro.get());
|
||||
}
|
||||
|
||||
const auto &tempMacros = GetTemporaryMacros();
|
||||
macros.insert(macros.end(), tempMacros.begin(), tempMacros.end());
|
||||
for (const auto &topLevelMacro : tempMacros) {
|
||||
appendNestedMacros(macros, topLevelMacro.get());
|
||||
for (const auto &tempMacro : tempMacros) {
|
||||
appendNestedMacros(macros, tempMacro.get());
|
||||
}
|
||||
|
||||
return macros;
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +72,15 @@ GetMacroActions(Macro *macro)
|
|||
return macro->Actions();
|
||||
}
|
||||
|
||||
std::optional<std::deque<std::shared_ptr<MacroAction>>>
|
||||
GetMacroElseActions(Macro *macro)
|
||||
{
|
||||
if (!macro) {
|
||||
return {};
|
||||
}
|
||||
return macro->ElseActions();
|
||||
}
|
||||
|
||||
std::optional<std::deque<std::shared_ptr<MacroCondition>>>
|
||||
GetMacroConditions(Macro *macro)
|
||||
{
|
||||
|
|
@ -197,20 +208,42 @@ void ResetMacroRunCount(Macro *macro)
|
|||
macro->ResetRunCount();
|
||||
}
|
||||
|
||||
bool IsValidMacroSegmentIndex(const Macro *m, const int idx, bool isCondition)
|
||||
bool IsValidActionIndex(const Macro *m, const int idx)
|
||||
{
|
||||
if (!m || idx < 0) {
|
||||
return false;
|
||||
}
|
||||
if (isCondition) {
|
||||
if (idx >= (int)m->Conditions().size()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (idx >= (int)m->Actions().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (idx >= (int)m->Actions().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsValidElseActionIndex(const Macro *m, const int idx)
|
||||
{
|
||||
if (!m || idx < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (idx >= (int)m->ElseActions().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsValidConditionIndex(const Macro *m, const int idx)
|
||||
{
|
||||
if (!m || idx < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (idx >= (int)m->Conditions().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ EXPORT std::deque<std::shared_ptr<Macro>> GetAllMacros();
|
|||
|
||||
EXPORT std::optional<std::deque<std::shared_ptr<MacroAction>>>
|
||||
GetMacroActions(Macro *);
|
||||
EXPORT std::optional<std::deque<std::shared_ptr<MacroAction>>>
|
||||
GetMacroElseActions(Macro *);
|
||||
EXPORT std::optional<std::deque<std::shared_ptr<MacroCondition>>>
|
||||
GetMacroConditions(Macro *);
|
||||
|
||||
|
|
@ -70,6 +72,8 @@ EXPORT void InvalidateMacroTempVarValues();
|
|||
EXPORT void ResetMacroConditionTimers(Macro *);
|
||||
EXPORT void ResetMacroRunCount(Macro *);
|
||||
|
||||
bool IsValidMacroSegmentIndex(const Macro *m, const int idx, bool isCondition);
|
||||
bool IsValidActionIndex(const Macro *m, const int idx);
|
||||
bool IsValidElseActionIndex(const Macro *m, const int idx);
|
||||
bool IsValidConditionIndex(const Macro *m, const int idx);
|
||||
|
||||
} // namespace advss
|
||||
|
|
|
|||
|
|
@ -73,35 +73,46 @@ void MacroSegmentSelection::MacroSegmentOrderChanged()
|
|||
}
|
||||
|
||||
static QString GetMacroSegmentDescription(Macro *macro, int idx,
|
||||
bool isCondition)
|
||||
MacroSegmentSelection::Type type)
|
||||
{
|
||||
if (!macro) {
|
||||
return "";
|
||||
}
|
||||
if (!IsValidMacroSegmentIndex(macro, idx, isCondition)) {
|
||||
|
||||
MacroSegment *segment;
|
||||
|
||||
switch (type) {
|
||||
case MacroSegmentSelection::Type::CONDITION:
|
||||
if (!IsValidConditionIndex(macro, idx)) {
|
||||
return "";
|
||||
}
|
||||
segment = GetMacroConditions(macro)->at(idx).get();
|
||||
break;
|
||||
case MacroSegmentSelection::Type::ACTION:
|
||||
if (!IsValidActionIndex(macro, idx)) {
|
||||
return "";
|
||||
}
|
||||
segment = GetMacroActions(macro)->at(idx).get();
|
||||
break;
|
||||
case MacroSegmentSelection::Type::ELSE_ACTION:
|
||||
if (!IsValidElseActionIndex(macro, idx)) {
|
||||
return "";
|
||||
}
|
||||
segment = GetMacroElseActions(macro)->at(idx).get();
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
||||
MacroSegment *segment;
|
||||
if (isCondition) {
|
||||
segment = GetMacroConditions(macro)->at(idx).get();
|
||||
} else {
|
||||
segment = GetMacroActions(macro)->at(idx).get();
|
||||
}
|
||||
const auto idToName = type == MacroSegmentSelection::Type::CONDITION
|
||||
? MacroConditionFactory::GetConditionName
|
||||
: MacroActionFactory::GetActionName;
|
||||
const QString typeStr =
|
||||
obs_module_text(idToName(segment->GetId()).c_str());
|
||||
const QString description =
|
||||
QString::fromStdString(segment->GetShortDesc());
|
||||
|
||||
QString description = QString::fromStdString(segment->GetShortDesc());
|
||||
QString type;
|
||||
if (isCondition) {
|
||||
type = obs_module_text(MacroConditionFactory::GetConditionName(
|
||||
segment->GetId())
|
||||
.c_str());
|
||||
} else {
|
||||
type = obs_module_text(
|
||||
MacroActionFactory::GetActionName(segment->GetId())
|
||||
.c_str());
|
||||
}
|
||||
|
||||
QString result = type;
|
||||
QString result = typeStr;
|
||||
if (!description.isEmpty()) {
|
||||
result += ": " + description;
|
||||
}
|
||||
|
|
@ -123,11 +134,25 @@ void MacroSegmentSelection::SetupDescription() const
|
|||
return;
|
||||
}
|
||||
|
||||
bool validIndex = false;
|
||||
switch (_type) {
|
||||
case Type::CONDITION:
|
||||
validIndex = IsValidConditionIndex(_macro, index - 1);
|
||||
break;
|
||||
case Type::ACTION:
|
||||
validIndex = IsValidActionIndex(_macro, index - 1);
|
||||
break;
|
||||
case Type::ELSE_ACTION:
|
||||
validIndex = IsValidElseActionIndex(_macro, index - 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
QString description;
|
||||
if (IsValidMacroSegmentIndex(_macro, index - 1,
|
||||
_type == Type::CONDITION)) {
|
||||
description = GetMacroSegmentDescription(
|
||||
_macro, index - 1, _type == Type::CONDITION);
|
||||
if (validIndex) {
|
||||
description =
|
||||
GetMacroSegmentDescription(_macro, index - 1, _type);
|
||||
} else {
|
||||
description = obs_module_text(
|
||||
"AdvSceneSwitcher.macroSegmentSelection.invalid");
|
||||
|
|
@ -165,8 +190,23 @@ void MacroSegmentSelection::MarkSelectedSegment()
|
|||
if (index.GetType() == IntVariable::Type::VARIABLE) {
|
||||
return;
|
||||
}
|
||||
if (!IsValidMacroSegmentIndex(_macro, index - 1,
|
||||
_type == Type::CONDITION)) {
|
||||
|
||||
bool validIndex = false;
|
||||
switch (_type) {
|
||||
case Type::CONDITION:
|
||||
validIndex = IsValidConditionIndex(_macro, index - 1);
|
||||
break;
|
||||
case Type::ACTION:
|
||||
validIndex = IsValidActionIndex(_macro, index - 1);
|
||||
break;
|
||||
case Type::ELSE_ACTION:
|
||||
validIndex = IsValidElseActionIndex(_macro, index - 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!validIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class Macro;
|
|||
class MacroSegmentSelection : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class Type { CONDITION, ACTION };
|
||||
enum class Type { CONDITION, ACTION, ELSE_ACTION };
|
||||
|
||||
MacroSegmentSelection(QWidget *parent, Type type,
|
||||
bool allowVariables = true);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user