Refactor "no match scene" handling

This commit is contained in:
WarmUpTill 2025-10-18 22:02:45 +02:00 committed by WarmUpTill
parent 602675b3b3
commit a82662c8f4
6 changed files with 28 additions and 53 deletions

View File

@ -489,16 +489,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="noMatchSwitchScene">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<widget class="advss::SceneSelectionWidget" name="noMatchSwitchScene">
</widget>
</item>
</layout>

View File

@ -45,7 +45,6 @@ protected:
/* --- Begin of general tab section --- */
public:
void SetupGeneralTab();
void UpdateNonMatchingScene(const QString &name);
void SetDeprecationWarnings();
public slots:
@ -58,7 +57,6 @@ public slots:
void on_startupBehavior_currentIndexChanged(int index);
void on_logLevel_currentIndexChanged(int index);
void on_autoStartEvent_currentIndexChanged(int index);
void on_noMatchSwitchScene_currentTextChanged(const QString &text);
void on_checkInterval_valueChanged(int value);
void on_tabWidget_currentChanged(int index);
void on_exportSettings_clicked();

View File

@ -26,15 +26,6 @@ void AdvSceneSwitcher::reject()
close();
}
void AdvSceneSwitcher::UpdateNonMatchingScene(const QString &name)
{
OBSSourceAutoRelease scene =
obs_get_source_by_name(name.toUtf8().constData());
OBSWeakSourceAutoRelease ws = obs_source_get_weak_source(scene);
switcher->nonMatchingScene = ws;
}
void AdvSceneSwitcher::on_noMatchDontSwitch_clicked()
{
if (loading) {
@ -56,7 +47,6 @@ void AdvSceneSwitcher::on_noMatchSwitch_clicked()
std::lock_guard<std::mutex> lock(switcher->m);
switcher->switchIfNotMatching = NoMatchBehavior::SWITCH;
ui->noMatchSwitchScene->setEnabled(true);
UpdateNonMatchingScene(ui->noMatchSwitchScene->currentText());
ui->randomDisabledWarning->setVisible(true);
}
@ -132,17 +122,6 @@ void AdvSceneSwitcher::on_autoStartEvent_currentIndexChanged(int index)
switcher->autoStartEvent = static_cast<SwitcherData::AutoStart>(index);
}
void AdvSceneSwitcher::on_noMatchSwitchScene_currentTextChanged(
const QString &text)
{
if (loading) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
UpdateNonMatchingScene(text);
}
void AdvSceneSwitcher::on_checkInterval_valueChanged(int value)
{
if (loading) {
@ -522,9 +501,9 @@ void SwitcherData::SaveGeneralSettings(obs_data_t *obj)
{
obs_data_set_int(obj, "interval", interval);
std::string nonMatchingSceneName = GetWeakSourceName(nonMatchingScene);
obs_data_set_string(obj, "non_matching_scene",
nonMatchingSceneName.c_str());
OBSDataAutoRelease noMatchScene = obs_data_create();
nonMatchingScene.Save(noMatchScene);
obs_data_set_obj(obj, "noMatchScene", noMatchScene);
obs_data_set_int(obj, "switch_if_not_matching",
static_cast<int>(switchIfNotMatching));
noMatchDelay.Save(obj, "noMatchDelay");
@ -578,9 +557,14 @@ void SwitcherData::LoadGeneralSettings(obs_data_t *obj)
static_cast<int>(NoMatchBehavior::NO_SWITCH));
switchIfNotMatching = static_cast<NoMatchBehavior>(
obs_data_get_int(obj, "switch_if_not_matching"));
std::string nonMatchingSceneName =
obs_data_get_string(obj, "non_matching_scene");
nonMatchingScene = GetWeakSourceByName(nonMatchingSceneName.c_str());
if (obs_data_has_user_value(obj, "noMatchScene")) {
OBSDataAutoRelease noMatchScene =
obs_data_get_obj(obj, "noMatchScene");
nonMatchingScene.Load(noMatchScene);
} else {
nonMatchingScene.Load(obj, "non_matching_scene");
}
noMatchDelay.Load(obj, "noMatchDelay");
cooldown.Load(obj, "cooldown");
@ -689,10 +673,10 @@ void SwitcherData::CheckNoMatchSwitch(bool &match, OBSWeakSource &scene,
return;
}
if (switchIfNotMatching == NoMatchBehavior::SWITCH &&
nonMatchingScene) {
auto noMatchScene = nonMatchingScene.GetScene(false);
if (switchIfNotMatching == NoMatchBehavior::SWITCH && noMatchScene) {
match = true;
scene = nonMatchingScene;
scene = noMatchScene;
transition = nullptr;
}
if (switchIfNotMatching == NoMatchBehavior::RANDOM_SWITCH) {
@ -887,8 +871,6 @@ void AdvSceneSwitcher::SetCheckIntervalTooLowVisibility() const
void AdvSceneSwitcher::SetupGeneralTab()
{
PopulateSceneSelection(ui->noMatchSwitchScene, false);
if (switcher->switchIfNotMatching == NoMatchBehavior::SWITCH) {
ui->noMatchSwitch->setChecked(true);
ui->noMatchSwitchScene->setEnabled(true);
@ -900,8 +882,17 @@ void AdvSceneSwitcher::SetupGeneralTab()
ui->noMatchRandomSwitch->setChecked(true);
ui->noMatchSwitchScene->setEnabled(false);
}
ui->noMatchSwitchScene->setCurrentText(
GetWeakSourceName(switcher->nonMatchingScene).c_str());
ui->noMatchSwitchScene->SetScene(switcher->nonMatchingScene);
ui->noMatchSwitchScene->LockToMainCanvas();
connect(ui->noMatchSwitchScene, &SceneSelectionWidget::SceneChanged,
this, [this](const SceneSelection &scene) {
if (loading) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switcher->nonMatchingScene = scene;
});
DurationSelection *noMatchDelay = new DurationSelection();
noMatchDelay->SetDuration(switcher->noMatchDelay);

View File

@ -44,11 +44,6 @@ void SwitcherData::Prune()
}
}
if (nonMatchingScene && !WeakSourceValid(nonMatchingScene)) {
switchIfNotMatching = NoMatchBehavior::NO_SWITCH;
nonMatchingScene = nullptr;
}
for (size_t i = 0; i < randomSwitches.size(); i++) {
RandomSwitch &s = randomSwitches[i];
if (!s.valid()) {

View File

@ -109,7 +109,7 @@ public:
/* --- Start of General tab section --- */
int interval = default_interval;
OBSWeakSource nonMatchingScene;
SceneSelection nonMatchingScene;
NoMatchBehavior switchIfNotMatching = NoMatchBehavior::NO_SWITCH;
Duration noMatchDelay;
enum class StartupBehavior { PERSIST = 0, START = 1, STOP = 2 };

View File

@ -238,7 +238,7 @@ NoMatchBehavior GetPluginNoMatchBehavior()
void SetNoMatchScene(const OBSWeakSource &scene)
{
GetSwitcher()->nonMatchingScene = scene;
GetSwitcher()->nonMatchingScene.SetScene(scene);
}
std::string ForegroundWindowTitle()