mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-10-01 13:59:31 -05:00
Cleanup wait action
* Add HeaderInfoChanged() * Move enum definition
This commit is contained in:
@@ -15,9 +15,11 @@ bool MacroActionWait::_registered = MacroActionFactory::Register(
|
|||||||
{MacroActionWait::Create, MacroActionWaitEdit::Create,
|
{MacroActionWait::Create, MacroActionWaitEdit::Create,
|
||||||
"AdvSceneSwitcher.action.wait"});
|
"AdvSceneSwitcher.action.wait"});
|
||||||
|
|
||||||
const static std::map<WaitType, std::string> waitTypes = {
|
static const std::map<MacroActionWait::Type, std::string> waitTypes = {
|
||||||
{WaitType::FIXED, "AdvSceneSwitcher.action.wait.type.fixed"},
|
{MacroActionWait::Type::FIXED,
|
||||||
{WaitType::RANDOM, "AdvSceneSwitcher.action.wait.type.random"},
|
"AdvSceneSwitcher.action.wait.type.fixed"},
|
||||||
|
{MacroActionWait::Type::RANDOM,
|
||||||
|
"AdvSceneSwitcher.action.wait.type.random"},
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::random_device rd;
|
static std::random_device rd;
|
||||||
@@ -37,7 +39,7 @@ static void waitHelper(std::unique_lock<std::mutex> *lock, Macro *macro,
|
|||||||
bool MacroActionWait::PerformAction()
|
bool MacroActionWait::PerformAction()
|
||||||
{
|
{
|
||||||
double sleepDuration;
|
double sleepDuration;
|
||||||
if (_waitType == WaitType::FIXED) {
|
if (_waitType == Type::FIXED) {
|
||||||
sleepDuration = _duration.Seconds();
|
sleepDuration = _duration.Seconds();
|
||||||
} else {
|
} else {
|
||||||
double min = (_duration.Seconds() < _duration2.Seconds())
|
double min = (_duration.Seconds() < _duration2.Seconds())
|
||||||
@@ -84,25 +86,33 @@ bool MacroActionWait::Load(obs_data_t *obj)
|
|||||||
_duration2.SetUnit(static_cast<Duration::Unit>(
|
_duration2.SetUnit(static_cast<Duration::Unit>(
|
||||||
obs_data_get_int(obj, "displayUnit2")));
|
obs_data_get_int(obj, "displayUnit2")));
|
||||||
}
|
}
|
||||||
_waitType = static_cast<WaitType>(obs_data_get_int(obj, "waitType"));
|
_waitType = static_cast<Type>(obs_data_get_int(obj, "waitType"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MacroActionWait::GetShortDesc() const
|
||||||
|
{
|
||||||
|
if (_waitType == Type::FIXED) {
|
||||||
|
return _duration.ToString();
|
||||||
|
}
|
||||||
|
return _duration.ToString() + " - " + _duration2.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
static inline void populateTypeSelection(QComboBox *list)
|
static inline void populateTypeSelection(QComboBox *list)
|
||||||
{
|
{
|
||||||
for (auto entry : waitTypes) {
|
for (const auto &entry : waitTypes) {
|
||||||
list->addItem(obs_module_text(entry.second.c_str()));
|
list->addItem(obs_module_text(entry.second.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroActionWaitEdit::MacroActionWaitEdit(
|
MacroActionWaitEdit::MacroActionWaitEdit(
|
||||||
QWidget *parent, std::shared_ptr<MacroActionWait> entryData)
|
QWidget *parent, std::shared_ptr<MacroActionWait> entryData)
|
||||||
: QWidget(parent)
|
: QWidget(parent),
|
||||||
|
_duration(new DurationSelection()),
|
||||||
|
_duration2(new DurationSelection()),
|
||||||
|
_waitType(new QComboBox()),
|
||||||
|
_mainLayout(new QHBoxLayout())
|
||||||
{
|
{
|
||||||
_duration = new DurationSelection();
|
|
||||||
_duration2 = new DurationSelection();
|
|
||||||
_waitType = new QComboBox();
|
|
||||||
|
|
||||||
populateTypeSelection(_waitType);
|
populateTypeSelection(_waitType);
|
||||||
|
|
||||||
QWidget::connect(_duration, SIGNAL(DurationChanged(const Duration &)),
|
QWidget::connect(_duration, SIGNAL(DurationChanged(const Duration &)),
|
||||||
@@ -112,7 +122,6 @@ MacroActionWaitEdit::MacroActionWaitEdit(
|
|||||||
QWidget::connect(_waitType, SIGNAL(currentIndexChanged(int)), this,
|
QWidget::connect(_waitType, SIGNAL(currentIndexChanged(int)), this,
|
||||||
SLOT(TypeChanged(int)));
|
SLOT(TypeChanged(int)));
|
||||||
|
|
||||||
_mainLayout = new QHBoxLayout;
|
|
||||||
setLayout(_mainLayout);
|
setLayout(_mainLayout);
|
||||||
|
|
||||||
_entryData = entryData;
|
_entryData = entryData;
|
||||||
@@ -126,7 +135,7 @@ void MacroActionWaitEdit::UpdateEntryData()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_entryData->_waitType == WaitType::FIXED) {
|
if (_entryData->_waitType == MacroActionWait::Type::FIXED) {
|
||||||
SetupFixedDurationEdit();
|
SetupFixedDurationEdit();
|
||||||
} else {
|
} else {
|
||||||
SetupRandomDurationEdit();
|
SetupRandomDurationEdit();
|
||||||
@@ -177,15 +186,17 @@ void MacroActionWaitEdit::TypeChanged(int value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
WaitType type = static_cast<WaitType>(value);
|
auto type = static_cast<MacroActionWait::Type>(value);
|
||||||
|
|
||||||
if (type == WaitType::FIXED) {
|
if (type == MacroActionWait::Type::FIXED) {
|
||||||
SetupFixedDurationEdit();
|
SetupFixedDurationEdit();
|
||||||
} else {
|
} else {
|
||||||
SetupRandomDurationEdit();
|
SetupRandomDurationEdit();
|
||||||
}
|
}
|
||||||
|
|
||||||
_entryData->_waitType = type;
|
_entryData->_waitType = type;
|
||||||
|
emit HeaderInfoChanged(
|
||||||
|
QString::fromStdString(_entryData->GetShortDesc()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroActionWaitEdit::DurationChanged(const Duration &dur)
|
void MacroActionWaitEdit::DurationChanged(const Duration &dur)
|
||||||
@@ -196,6 +207,8 @@ void MacroActionWaitEdit::DurationChanged(const Duration &dur)
|
|||||||
|
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
_entryData->_duration = dur;
|
_entryData->_duration = dur;
|
||||||
|
emit HeaderInfoChanged(
|
||||||
|
QString::fromStdString(_entryData->GetShortDesc()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroActionWaitEdit::Duration2Changed(const Duration &dur)
|
void MacroActionWaitEdit::Duration2Changed(const Duration &dur)
|
||||||
@@ -206,6 +219,8 @@ void MacroActionWaitEdit::Duration2Changed(const Duration &dur)
|
|||||||
|
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
_entryData->_duration2 = dur;
|
_entryData->_duration2 = dur;
|
||||||
|
emit HeaderInfoChanged(
|
||||||
|
QString::fromStdString(_entryData->GetShortDesc()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace advss
|
} // namespace advss
|
||||||
|
|||||||
@@ -7,17 +7,13 @@
|
|||||||
|
|
||||||
namespace advss {
|
namespace advss {
|
||||||
|
|
||||||
enum class WaitType {
|
|
||||||
FIXED,
|
|
||||||
RANDOM,
|
|
||||||
};
|
|
||||||
|
|
||||||
class MacroActionWait : public MacroAction {
|
class MacroActionWait : public MacroAction {
|
||||||
public:
|
public:
|
||||||
MacroActionWait(Macro *m) : MacroAction(m) {}
|
MacroActionWait(Macro *m) : MacroAction(m) {}
|
||||||
bool PerformAction();
|
bool PerformAction();
|
||||||
bool Save(obs_data_t *obj) const;
|
bool Save(obs_data_t *obj) const;
|
||||||
bool Load(obs_data_t *obj);
|
bool Load(obs_data_t *obj);
|
||||||
|
std::string GetShortDesc() const;
|
||||||
std::string GetId() const { return id; };
|
std::string GetId() const { return id; };
|
||||||
static std::shared_ptr<MacroAction> Create(Macro *m)
|
static std::shared_ptr<MacroAction> Create(Macro *m)
|
||||||
{
|
{
|
||||||
@@ -25,7 +21,12 @@ public:
|
|||||||
}
|
}
|
||||||
Duration _duration;
|
Duration _duration;
|
||||||
Duration _duration2;
|
Duration _duration2;
|
||||||
WaitType _waitType = WaitType::FIXED;
|
|
||||||
|
enum class Type {
|
||||||
|
FIXED,
|
||||||
|
RANDOM,
|
||||||
|
};
|
||||||
|
Type _waitType = Type::FIXED;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool _registered;
|
static bool _registered;
|
||||||
@@ -55,14 +56,16 @@ private slots:
|
|||||||
void Duration2Changed(const Duration &value);
|
void Duration2Changed(const Duration &value);
|
||||||
void TypeChanged(int value);
|
void TypeChanged(int value);
|
||||||
|
|
||||||
protected:
|
signals:
|
||||||
|
void HeaderInfoChanged(const QString &);
|
||||||
|
|
||||||
|
private:
|
||||||
DurationSelection *_duration;
|
DurationSelection *_duration;
|
||||||
DurationSelection *_duration2;
|
DurationSelection *_duration2;
|
||||||
QComboBox *_waitType;
|
QComboBox *_waitType;
|
||||||
std::shared_ptr<MacroActionWait> _entryData;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QHBoxLayout *_mainLayout;
|
QHBoxLayout *_mainLayout;
|
||||||
|
|
||||||
|
std::shared_ptr<MacroActionWait> _entryData;
|
||||||
bool _loading = true;
|
bool _loading = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user