mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-12 12:18:35 -05:00
Add action to switch preview scene
This commit is contained in:
@@ -158,6 +158,7 @@ set(advanced-scene-switcher_HEADERS
|
||||
src/headers/macro-action-macro.hpp
|
||||
src/headers/macro-action-media.hpp
|
||||
src/headers/macro-action-plugin-state.hpp
|
||||
src/headers/macro-action-preview-scene.hpp
|
||||
src/headers/macro-action-recording.hpp
|
||||
src/headers/macro-action-replay-buffer.hpp
|
||||
src/headers/macro-action-run.hpp
|
||||
@@ -241,6 +242,7 @@ set(advanced-scene-switcher_SOURCES
|
||||
src/macro-action-macro.cpp
|
||||
src/macro-action-media.cpp
|
||||
src/macro-action-plugin-state.cpp
|
||||
src/macro-action-preview-scene.cpp
|
||||
src/macro-action-recording.cpp
|
||||
src/macro-action-replay-buffer.cpp
|
||||
src/macro-action-run.cpp
|
||||
|
||||
@@ -296,6 +296,8 @@ AdvSceneSwitcher.action.file="File"
|
||||
AdvSceneSwitcher.action.file.type.write="Write"
|
||||
AdvSceneSwitcher.action.file.type.append="Append"
|
||||
AdvSceneSwitcher.action.file.entry="{{actions}} to {{filePath}} {{browseButton}}:"
|
||||
AdvSceneSwitcher.action.previewScene="Switch preview scene"
|
||||
AdvSceneSwitcher.action.previewScene.entry="Switch preview scene to {{scenes}}"
|
||||
|
||||
; Transition Tab
|
||||
AdvSceneSwitcher.transitionTab.title="Transition"
|
||||
|
||||
54
src/headers/macro-action-preview-scene.hpp
Normal file
54
src/headers/macro-action-preview-scene.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "scene-selection.hpp"
|
||||
|
||||
class MacroActionPreviewScene : public MacroAction {
|
||||
public:
|
||||
bool PerformAction();
|
||||
void LogAction();
|
||||
bool Save(obs_data_t *obj);
|
||||
bool Load(obs_data_t *obj);
|
||||
std::string GetShortDesc();
|
||||
std::string GetId() { return id; };
|
||||
static std::shared_ptr<MacroAction> Create()
|
||||
{
|
||||
return std::make_shared<MacroActionPreviewScene>();
|
||||
}
|
||||
|
||||
SceneSelection _scene;
|
||||
|
||||
private:
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
|
||||
class MacroActionPreviewSceneEdit : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroActionPreviewSceneEdit(
|
||||
QWidget *parent,
|
||||
std::shared_ptr<MacroActionPreviewScene> entryData = nullptr);
|
||||
void UpdateEntryData();
|
||||
static QWidget *Create(QWidget *parent,
|
||||
std::shared_ptr<MacroAction> action)
|
||||
{
|
||||
return new MacroActionPreviewSceneEdit(
|
||||
parent,
|
||||
std::dynamic_pointer_cast<MacroActionPreviewScene>(
|
||||
action));
|
||||
}
|
||||
|
||||
private slots:
|
||||
void SceneChanged(const SceneSelection &);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
protected:
|
||||
SceneSelectionWidget *_scenes;
|
||||
std::shared_ptr<MacroActionPreviewScene> _entryData;
|
||||
|
||||
private:
|
||||
QHBoxLayout *_mainLayout;
|
||||
bool _loading = true;
|
||||
};
|
||||
88
src/macro-action-preview-scene.cpp
Normal file
88
src/macro-action-preview-scene.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "headers/macro-action-preview-scene.hpp"
|
||||
#include "headers/advanced-scene-switcher.hpp"
|
||||
#include "headers/utility.hpp"
|
||||
|
||||
const std::string MacroActionPreviewScene::id = "preview_scene";
|
||||
|
||||
bool MacroActionPreviewScene::_registered = MacroActionFactory::Register(
|
||||
MacroActionPreviewScene::id,
|
||||
{MacroActionPreviewScene::Create, MacroActionPreviewSceneEdit::Create,
|
||||
"AdvSceneSwitcher.action.previewScene"});
|
||||
|
||||
bool MacroActionPreviewScene::PerformAction()
|
||||
{
|
||||
auto s = obs_weak_source_get_source(_scene.GetScene());
|
||||
obs_frontend_set_current_preview_scene(s);
|
||||
obs_source_release(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MacroActionPreviewScene::LogAction()
|
||||
{
|
||||
vblog(LOG_INFO, "set preview scene to \"%s\"",
|
||||
_scene.ToString().c_str());
|
||||
}
|
||||
|
||||
bool MacroActionPreviewScene::Save(obs_data_t *obj)
|
||||
{
|
||||
MacroAction::Save(obj);
|
||||
_scene.Save(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroActionPreviewScene::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroAction::Load(obj);
|
||||
_scene.Load(obj);
|
||||
const char *sourceName = obs_data_get_string(obj, "source");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string MacroActionPreviewScene::GetShortDesc()
|
||||
{
|
||||
return _scene.ToString();
|
||||
}
|
||||
|
||||
MacroActionPreviewSceneEdit::MacroActionPreviewSceneEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroActionPreviewScene> entryData)
|
||||
: QWidget(parent)
|
||||
{
|
||||
_scenes = new SceneSelectionWidget(window(), false, false, false);
|
||||
|
||||
QWidget::connect(_scenes, SIGNAL(SceneChanged(const SceneSelection &)),
|
||||
this, SLOT(SceneChanged(const SceneSelection &)));
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{scenes}}", _scenes},
|
||||
};
|
||||
placeWidgets(
|
||||
obs_module_text("AdvSceneSwitcher.action.previewScene.entry"),
|
||||
mainLayout, widgetPlaceholders);
|
||||
setLayout(mainLayout);
|
||||
|
||||
_entryData = entryData;
|
||||
UpdateEntryData();
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
void MacroActionPreviewSceneEdit::UpdateEntryData()
|
||||
{
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
_scenes->SetScene(_entryData->_scene);
|
||||
}
|
||||
|
||||
void MacroActionPreviewSceneEdit::SceneChanged(const SceneSelection &s)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_scene = s;
|
||||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
}
|
||||
Reference in New Issue
Block a user