Correctly restore and apply action edit dialog data
This commit is contained in:
1 parent
e69ac810bc
commit
35603aefa8
19 files changed
+207
-40
No files matched your search
@@ -26,6 +26,7 @@ INCLUDEPATH += \
|
||||
|
||||
HEADERS += \
|
||||
src/closeeventfilter.h \
|
||||
src/editor/dialogs/actions/actiondialogutils.h \
|
||||
src/editor/dialogs/actions/setgravitydialog.h \
|
||||
src/editor/dialogs/actions/speedhorizontaldialog.h \
|
||||
src/editor/dialogs/actions/movefreedialog.h \
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "projectcontainer.h"
|
||||
#include "widgets/objectselectorwidget.h"
|
||||
|
||||
template<typename Ui>
|
||||
void loadActionTarget(Ui &ui, const AppliesTo &target)
|
||||
{
|
||||
ui.radioButtonSelf->setChecked(std::holds_alternative<AppliesToSelf>(target));
|
||||
ui.radioButtonOther->setChecked(std::holds_alternative<AppliesToOther>(target));
|
||||
const auto *object = std::get_if<AppliesToObject>(&target);
|
||||
ui.radioButtonObject->setChecked(object != nullptr);
|
||||
if (object)
|
||||
ui.widgetObject->setObject(object->objectName);
|
||||
else
|
||||
ui.widgetObject->clearObject();
|
||||
ui.widgetObject->setVisible(object != nullptr);
|
||||
}
|
||||
|
||||
template<typename Ui>
|
||||
bool saveActionTarget(const Ui &ui, AppliesTo &target, QWidget *parent)
|
||||
{
|
||||
if (ui.radioButtonSelf->isChecked())
|
||||
target = AppliesToSelf{};
|
||||
else if (ui.radioButtonOther->isChecked())
|
||||
target = AppliesToOther{};
|
||||
else if (ui.radioButtonObject->isChecked() && !ui.widgetObject->objectName().isEmpty())
|
||||
target = AppliesToObject{ui.widgetObject->objectName()};
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(parent, QObject::tr("Select an object"),
|
||||
QObject::tr("Select an object for this action."));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "executecodedialog.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QRadioButton>
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "editorguiutils.h"
|
||||
#include "actiondialogutils.h"
|
||||
|
||||
MoveFixedDialog::MoveFixedDialog(MoveFixedAction &action, ProjectTreeModel *projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
@@ -23,6 +24,28 @@ MoveFixedDialog::MoveFixedDialog(MoveFixedAction &action, ProjectTreeModel *proj
|
||||
m_ui->widgetObject->setShowClearObjectAction(false);
|
||||
|
||||
improveButtonBox(m_ui->buttonBox);
|
||||
loadActionTarget(*m_ui, m_action.appliesTo);
|
||||
const std::array buttons{m_ui->pushButton, m_ui->pushButton_2, m_ui->pushButton_3,
|
||||
m_ui->pushButton_4, m_ui->pushButton_5, m_ui->pushButton_6,
|
||||
m_ui->pushButton_7, m_ui->pushButton_8, m_ui->pushButton_9};
|
||||
for (std::size_t i = 0; i < buttons.size(); ++i)
|
||||
buttons[i]->setChecked(m_action.directions[i]);
|
||||
m_ui->spinBox->setValue(m_action.speed);
|
||||
m_ui->checkBoxRelative->setChecked(m_action.relative);
|
||||
}
|
||||
|
||||
MoveFixedDialog::~MoveFixedDialog() = default;
|
||||
|
||||
void MoveFixedDialog::accept()
|
||||
{
|
||||
if (!saveActionTarget(*m_ui, m_action.appliesTo, this))
|
||||
return;
|
||||
const std::array buttons{m_ui->pushButton, m_ui->pushButton_2, m_ui->pushButton_3,
|
||||
m_ui->pushButton_4, m_ui->pushButton_5, m_ui->pushButton_6,
|
||||
m_ui->pushButton_7, m_ui->pushButton_8, m_ui->pushButton_9};
|
||||
for (std::size_t i = 0; i < buttons.size(); ++i)
|
||||
m_action.directions[i] = buttons[i]->isChecked();
|
||||
m_action.speed = m_ui->spinBox->value();
|
||||
m_action.relative = m_ui->checkBoxRelative->isChecked();
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class MoveFixedDialog : public QDialog
|
||||
public:
|
||||
explicit MoveFixedDialog(MoveFixedAction &action, ProjectTreeModel *projectModel, QWidget *parent = nullptr);
|
||||
~MoveFixedDialog() override;
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::MoveFixedDialog> m_ui;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "editorguiutils.h"
|
||||
#include "actiondialogutils.h"
|
||||
|
||||
MoveFreeDialog::MoveFreeDialog(MoveFreeAction &action, ProjectTreeModel *projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
@@ -23,6 +24,20 @@ MoveFreeDialog::MoveFreeDialog(MoveFreeAction &action, ProjectTreeModel *project
|
||||
m_ui->widgetObject->setShowClearObjectAction(false);
|
||||
|
||||
improveButtonBox(m_ui->buttonBox);
|
||||
loadActionTarget(*m_ui, m_action.appliesTo);
|
||||
m_ui->spinBoxDirection->setValue(m_action.direction);
|
||||
m_ui->spinBoxSpeed->setValue(m_action.speed);
|
||||
m_ui->checkBoxRelative->setChecked(m_action.relative);
|
||||
}
|
||||
|
||||
MoveFreeDialog::~MoveFreeDialog() = default;
|
||||
|
||||
void MoveFreeDialog::accept()
|
||||
{
|
||||
if (!saveActionTarget(*m_ui, m_action.appliesTo, this))
|
||||
return;
|
||||
m_action.direction = m_ui->spinBoxDirection->value();
|
||||
m_action.speed = m_ui->spinBoxSpeed->value();
|
||||
m_action.relative = m_ui->checkBoxRelative->isChecked();
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class MoveFreeDialog : public QDialog
|
||||
public:
|
||||
explicit MoveFreeDialog(MoveFreeAction &action, ProjectTreeModel *projectModel, QWidget *parent = nullptr);
|
||||
~MoveFreeDialog() override;
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::MoveFreeDialog> m_ui;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "editorguiutils.h"
|
||||
#include "actiondialogutils.h"
|
||||
|
||||
MoveTowardsDialog::MoveTowardsDialog(MoveTowardsAction &action, ProjectTreeModel *projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
@@ -23,6 +24,22 @@ MoveTowardsDialog::MoveTowardsDialog(MoveTowardsAction &action, ProjectTreeModel
|
||||
m_ui->widgetObject->setShowClearObjectAction(false);
|
||||
|
||||
improveButtonBox(m_ui->buttonBox);
|
||||
loadActionTarget(*m_ui, m_action.appliesTo);
|
||||
m_ui->spinBoxX->setValue(m_action.x);
|
||||
m_ui->spinBoxY->setValue(m_action.y);
|
||||
m_ui->spinBoxSpeed->setValue(m_action.speed);
|
||||
m_ui->checkBoxRelative->setChecked(m_action.relative);
|
||||
}
|
||||
|
||||
MoveTowardsDialog::~MoveTowardsDialog() = default;
|
||||
|
||||
void MoveTowardsDialog::accept()
|
||||
{
|
||||
if (!saveActionTarget(*m_ui, m_action.appliesTo, this))
|
||||
return;
|
||||
m_action.x = m_ui->spinBoxX->value();
|
||||
m_action.y = m_ui->spinBoxY->value();
|
||||
m_action.speed = m_ui->spinBoxSpeed->value();
|
||||
m_action.relative = m_ui->checkBoxRelative->isChecked();
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class MoveTowardsDialog : public QDialog
|
||||
public:
|
||||
explicit MoveTowardsDialog(MoveTowardsAction &action, ProjectTreeModel *projectModel, QWidget *parent = nullptr);
|
||||
~MoveTowardsDialog() override;
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::MoveTowardsDialog> m_ui;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "editorguiutils.h"
|
||||
#include "actiondialogutils.h"
|
||||
|
||||
SetGravityDialog::SetGravityDialog(SetGravityAction &action, ProjectTreeModel *projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
@@ -23,6 +24,20 @@ SetGravityDialog::SetGravityDialog(SetGravityAction &action, ProjectTreeModel *p
|
||||
m_ui->widgetObject->setShowClearObjectAction(false);
|
||||
|
||||
improveButtonBox(m_ui->buttonBox);
|
||||
loadActionTarget(*m_ui, m_action.appliesTo);
|
||||
m_ui->spinBoxDirection->setValue(m_action.direction);
|
||||
m_ui->spinBoxGravity->setValue(m_action.gravity);
|
||||
m_ui->checkBoxRelative->setChecked(m_action.relative);
|
||||
}
|
||||
|
||||
SetGravityDialog::~SetGravityDialog() = default;
|
||||
|
||||
void SetGravityDialog::accept()
|
||||
{
|
||||
if (!saveActionTarget(*m_ui, m_action.appliesTo, this))
|
||||
return;
|
||||
m_action.direction = m_ui->spinBoxDirection->value();
|
||||
m_action.gravity = m_ui->spinBoxGravity->value();
|
||||
m_action.relative = m_ui->checkBoxRelative->isChecked();
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class SetGravityDialog : public QDialog
|
||||
public:
|
||||
explicit SetGravityDialog(SetGravityAction &action, ProjectTreeModel *projectModel, QWidget *parent = nullptr);
|
||||
~SetGravityDialog() override;
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::SetGravityDialog> m_ui;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "editorguiutils.h"
|
||||
#include "actiondialogutils.h"
|
||||
|
||||
SpeedHorizontalDialog::SpeedHorizontalDialog(SpeedHorizontalAction &action, ProjectTreeModel *projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
@@ -23,6 +24,18 @@ SpeedHorizontalDialog::SpeedHorizontalDialog(SpeedHorizontalAction &action, Proj
|
||||
m_ui->widgetObject->setShowClearObjectAction(false);
|
||||
|
||||
improveButtonBox(m_ui->buttonBox);
|
||||
loadActionTarget(*m_ui, m_action.appliesTo);
|
||||
m_ui->spinBoxHorSpeed->setValue(m_action.speed);
|
||||
m_ui->checkBoxRelative->setChecked(m_action.relative);
|
||||
}
|
||||
|
||||
SpeedHorizontalDialog::~SpeedHorizontalDialog() = default;
|
||||
|
||||
void SpeedHorizontalDialog::accept()
|
||||
{
|
||||
if (!saveActionTarget(*m_ui, m_action.appliesTo, this))
|
||||
return;
|
||||
m_action.speed = m_ui->spinBoxHorSpeed->value();
|
||||
m_action.relative = m_ui->checkBoxRelative->isChecked();
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class SpeedHorizontalDialog : public QDialog
|
||||
public:
|
||||
explicit SpeedHorizontalDialog(SpeedHorizontalAction &action, ProjectTreeModel *projectModel, QWidget *parent = nullptr);
|
||||
~SpeedHorizontalDialog() override;
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::SpeedHorizontalDialog> m_ui;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "editorguiutils.h"
|
||||
#include "actiondialogutils.h"
|
||||
|
||||
SpeedVerticalDialog::SpeedVerticalDialog(SpeedVerticalAction &action, ProjectTreeModel *projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
@@ -23,6 +24,18 @@ SpeedVerticalDialog::SpeedVerticalDialog(SpeedVerticalAction &action, ProjectTre
|
||||
m_ui->widgetObject->setShowClearObjectAction(false);
|
||||
|
||||
improveButtonBox(m_ui->buttonBox);
|
||||
loadActionTarget(*m_ui, m_action.appliesTo);
|
||||
m_ui->spinBoxVertSpeed->setValue(m_action.speed);
|
||||
m_ui->checkBoxRelative->setChecked(m_action.relative);
|
||||
}
|
||||
|
||||
SpeedVerticalDialog::~SpeedVerticalDialog() = default;
|
||||
|
||||
void SpeedVerticalDialog::accept()
|
||||
{
|
||||
if (!saveActionTarget(*m_ui, m_action.appliesTo, this))
|
||||
return;
|
||||
m_action.speed = m_ui->spinBoxVertSpeed->value();
|
||||
m_action.relative = m_ui->checkBoxRelative->isChecked();
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class SpeedVerticalDialog : public QDialog
|
||||
public:
|
||||
explicit SpeedVerticalDialog(SpeedVerticalAction &action, ProjectTreeModel *projectModel, QWidget *parent = nullptr);
|
||||
~SpeedVerticalDialog() override;
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::SpeedVerticalDialog> m_ui;
|
||||
|
||||
@@ -32,7 +32,7 @@ void ActionDragWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
QByteArray encoded;
|
||||
QDataStream stream(&encoded, QDataStream::WriteOnly);
|
||||
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
||||
stream << m_action;
|
||||
mimeData->setData("custom", encoded);
|
||||
drag->setMimeData(mimeData);
|
||||
|
||||
+28
-13
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <variant>
|
||||
@@ -175,32 +176,46 @@ using AppliesTo = std::variant<
|
||||
AppliesToObject
|
||||
>;
|
||||
|
||||
struct MoveFixedAction {
|
||||
struct ActionBase {
|
||||
AppliesTo appliesTo{AppliesToSelf{}};
|
||||
};
|
||||
|
||||
struct MoveFreeAction {
|
||||
AppliesTo appliesTo{AppliesToSelf{}};
|
||||
struct MoveFixedAction : ActionBase {
|
||||
std::array<bool, 9> directions{};
|
||||
int speed{};
|
||||
bool relative{};
|
||||
};
|
||||
|
||||
struct MoveTowardsAction {
|
||||
AppliesTo appliesTo{AppliesToSelf{}};
|
||||
struct MoveFreeAction : ActionBase {
|
||||
int direction{};
|
||||
int speed{};
|
||||
bool relative{};
|
||||
};
|
||||
|
||||
struct SpeedHorizontalAction {
|
||||
AppliesTo appliesTo{AppliesToSelf{}};
|
||||
struct MoveTowardsAction : ActionBase {
|
||||
int x{};
|
||||
int y{};
|
||||
int speed{};
|
||||
bool relative{};
|
||||
};
|
||||
|
||||
struct SetGravityAction {
|
||||
AppliesTo appliesTo{AppliesToSelf{}};
|
||||
struct SpeedHorizontalAction : ActionBase {
|
||||
int speed{};
|
||||
bool relative{};
|
||||
};
|
||||
|
||||
struct SpeedVerticalAction {
|
||||
AppliesTo appliesTo{AppliesToSelf{}};
|
||||
struct SetGravityAction : ActionBase {
|
||||
int direction{};
|
||||
int gravity{};
|
||||
bool relative{};
|
||||
};
|
||||
|
||||
struct ExecuteCodeAction {
|
||||
AppliesTo appliesTo{AppliesToSelf{}};
|
||||
struct SpeedVerticalAction : ActionBase {
|
||||
int speed{};
|
||||
bool relative{};
|
||||
};
|
||||
|
||||
struct ExecuteCodeAction : ActionBase {
|
||||
QString script;
|
||||
};
|
||||
|
||||
|
||||
@@ -304,100 +304,108 @@ QDataStream &operator>>(QDataStream &ds, AppliesToObject &action)
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &ds, const ActionBase &action)
|
||||
{
|
||||
ds << action.appliesTo;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &ds, ActionBase &action)
|
||||
{
|
||||
ds >> action.appliesTo;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &ds, const MoveFixedAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds << action.appliesTo;
|
||||
ds << static_cast<const ActionBase &>(action)
|
||||
<< action.directions << action.speed << action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &ds, MoveFixedAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds >> action.appliesTo;
|
||||
ds >> static_cast<ActionBase &>(action)
|
||||
>> action.directions >> action.speed >> action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &ds, const MoveFreeAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds << action.appliesTo;
|
||||
ds << static_cast<const ActionBase &>(action)
|
||||
<< action.direction << action.speed << action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &ds, MoveFreeAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds >> action.appliesTo;
|
||||
ds >> static_cast<ActionBase &>(action)
|
||||
>> action.direction >> action.speed >> action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &ds, const MoveTowardsAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds << action.appliesTo;
|
||||
ds << static_cast<const ActionBase &>(action)
|
||||
<< action.x << action.y << action.speed << action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &ds, MoveTowardsAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds >> action.appliesTo;
|
||||
ds >> static_cast<ActionBase &>(action)
|
||||
>> action.x >> action.y >> action.speed >> action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &ds, const SpeedHorizontalAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds << action.appliesTo;
|
||||
ds << static_cast<const ActionBase &>(action) << action.speed << action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &ds, SpeedHorizontalAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds >> action.appliesTo;
|
||||
ds >> static_cast<ActionBase &>(action) >> action.speed >> action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &ds, const SpeedVerticalAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds << action.appliesTo;
|
||||
ds << static_cast<const ActionBase &>(action) << action.speed << action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &ds, SpeedVerticalAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds >> action.appliesTo;
|
||||
ds >> static_cast<ActionBase &>(action) >> action.speed >> action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &ds, const SetGravityAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds << action.appliesTo;
|
||||
ds << static_cast<const ActionBase &>(action)
|
||||
<< action.direction << action.gravity << action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &ds, SetGravityAction &action)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
ds >> action.appliesTo;
|
||||
ds >> static_cast<ActionBase &>(action)
|
||||
>> action.direction >> action.gravity >> action.relative;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &ds, const ExecuteCodeAction &action)
|
||||
{
|
||||
ds << action.appliesTo
|
||||
ds << static_cast<const ActionBase &>(action)
|
||||
<< action.script;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &ds, ExecuteCodeAction &action)
|
||||
{
|
||||
ds >> action.appliesTo
|
||||
ds >> static_cast<ActionBase &>(action)
|
||||
>> action.script;
|
||||
return ds;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ QDataStream &operator<<(QDataStream &ds, const AppliesToOther &action);
|
||||
QDataStream &operator>>(QDataStream &ds, AppliesToOther &action);
|
||||
QDataStream &operator<<(QDataStream &ds, const AppliesToObject &action);
|
||||
QDataStream &operator>>(QDataStream &ds, AppliesToObject &action);
|
||||
QDataStream &operator<<(QDataStream &ds, const ActionBase &action);
|
||||
QDataStream &operator>>(QDataStream &ds, ActionBase &action);
|
||||
QDataStream &operator<<(QDataStream &ds, const MoveFixedAction &action);
|
||||
QDataStream &operator>>(QDataStream &ds, MoveFixedAction &action);
|
||||
QDataStream &operator<<(QDataStream &ds, const MoveFreeAction &action);
|
||||
|
||||
Reference in new issue
Block a user