+
+NewProjectDialog::NewProjectDialog(QWidget *parent)
+ : QDialog{parent}
+{
+ m_ui.setupUi(this);
+
+ m_ui.imageFormatCombo->addItem(tr("BMP (compressed 4-bit palette)"), StoryProject::IMG_FORMAT_BMP_4BITS);
+ m_ui.imageFormatCombo->addItem(tr("QOIF (Quite Ok Image Format)"), StoryProject::IMG_FORMAT_QOIF);
+
+ m_ui.soundFormatCombo->addItem(tr("WAV"), StoryProject::SND_FORMAT_WAV);
+ m_ui.soundFormatCombo->addItem(tr("QOA (Quite Ok Audio)"), StoryProject::SND_FORMAT_QOAF);
+
+ m_ui.displaySizeCombo->addItem("320x240", QSize(320,240));
+
+ connect(m_ui.selectDirectoryButton, &QPushButton::clicked, this, [&]() {
+
+ m_dir = QFileDialog::getExistingDirectory(this, tr("Project Directory"),
+ QDir::homePath(),
+ QFileDialog::ShowDirsOnly
+ | QFileDialog::DontResolveSymlinks);
+ m_ui.directoryPath->setText(m_dir);
+
+ });
+
+ connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, [&]() {
+ QDir projDir(m_dir);
+ if (projDir.exists())
+ {
+ // Le répertoire doit être vide
+ bool empty = projDir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count() == 0;
+
+ if (empty)
+ {
+ // Test project name
+ if (!m_ui.projectName->text().isEmpty())
+ {
+ accept();
+ }
+ else
+ {
+ m_ui.errorMessage->setText(R"()" + tr("Error, project name empty.") + R"(
)");
+ }
+ }
+ else
+ {
+ m_ui.errorMessage->setText(R"()" + tr("Error, directory is not empty.") + R"(
)");
+ }
+ }
+ else
+ {
+ m_ui.errorMessage->setText(R"()" + tr("Error, directory does not exist.") + R"(
)");
+ }
+
+
+ });
+
+ connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, [&]() {
+
+ this->close();
+ });
+}
+
+QString NewProjectDialog::GetProjectFileName() const
+{
+ return m_dir + QDir::separator() + "project.json";
+}
+
+QString NewProjectDialog::GetProjectName() const { return m_ui.projectName->text(); }
+
+StoryProject::ImageFormat NewProjectDialog::GetImageFormat() const
+{
+ StoryProject::ImageFormat img{StoryProject::IMG_FORMAT_BMP_4BITS};
+ int idx = m_ui.imageFormatCombo->currentData().toInt();
+
+ if (idx < StoryProject::IMG_FORMAT_COUNT) {
+ img = static_cast(idx);
+ }
+
+ return img;
+}
+
+StoryProject::SoundFormat NewProjectDialog::GetSoundFormat() const
+{
+ StoryProject::SoundFormat img{StoryProject::SND_FORMAT_WAV};
+ int idx = m_ui.soundFormatCombo->currentData().toInt();
+
+ if (idx < StoryProject::IMG_FORMAT_COUNT) {
+ img = static_cast(idx);
+ }
+
+ return img;
+}
+
+QSize NewProjectDialog::GetDisplayFormat() const
+{
+ return m_ui.displaySizeCombo->currentData().toSize();
+}
+
+void NewProjectDialog::Initialize()
+{
+ m_ui.errorMessage->clear();
+ m_ui.directoryPath->clear();
+}
diff --git a/story-editor/src/new_project_dialog.h b/story-editor/src/new_project_dialog.h
new file mode 100644
index 0000000..e853f12
--- /dev/null
+++ b/story-editor/src/new_project_dialog.h
@@ -0,0 +1,32 @@
+#ifndef NEW_PROJECT_DIALOG_H
+#define NEW_PROJECT_DIALOG_H
+
+#include
+#include
+#include "ui_new-project.h"
+#include "story_project.h"
+
+class NewProjectDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ explicit NewProjectDialog(QWidget *parent = nullptr);
+
+ QString GetProjectFileName() const;
+ QString GetProjectName() const;
+
+ StoryProject::ImageFormat GetImageFormat() const;
+ StoryProject::SoundFormat GetSoundFormat() const;
+ QSize GetDisplayFormat() const;
+
+ void Initialize();
+signals:
+ void sigAccepted();
+
+private:
+ Ui::newProjectDialog m_ui;
+
+ QString m_dir;
+};
+
+#endif // NEW_PROJECT_DIALOG_H
diff --git a/story-editor/src/nodeeditor_dock.cpp b/story-editor/src/nodeeditor_dock.cpp
deleted file mode 100644
index 0d19d0a..0000000
--- a/story-editor/src/nodeeditor_dock.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "nodeeditor_dock.h"
-#include
-
-NodeEditorDock::NodeEditorDock(BasicGraphicsScene *scene)
- : DockWidgetBase(tr("Node editor"))
-{
- setObjectName("NodeEditorDock");
-
- m_view = new GraphicsView(scene);
- m_view->setScaleRange(0, 0);
- m_view->setViewport(new QOpenGLWidget());
-
- setAllowedAreas(Qt::AllDockWidgetAreas);
- setWidget(m_view);
-}
diff --git a/story-editor/src/nodeeditor_dock.h b/story-editor/src/nodeeditor_dock.h
deleted file mode 100644
index 53e0a53..0000000
--- a/story-editor/src/nodeeditor_dock.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef NODEEDITORDOCK_H
-#define NODEEDITORDOCK_H
-
-#include "dock_widget_base.h"
-#include
-#include
-using QtNodes::BasicGraphicsScene;
-using QtNodes::GraphicsView;
-
-
-class NodeEditorDock : public DockWidgetBase
-{
-public:
- NodeEditorDock(BasicGraphicsScene *scene);
-
-private:
- GraphicsView *m_view{nullptr};
-};
-
-#endif // NODEEDITORDOCK_H
diff --git a/story-editor/src/ost-editor.qrc b/story-editor/src/ost-editor.qrc
index 78d4e05..add32b2 100644
--- a/story-editor/src/ost-editor.qrc
+++ b/story-editor/src/ost-editor.qrc
@@ -6,5 +6,8 @@
../assets/build.png
../assets/volume-off.png
../assets/file-document-plus-outline.svg
+ ../assets/close-outline.svg
+ ../assets/folder-open-outline.svg
+ ../assets/welcome.png
diff --git a/story-editor/src/story_project.cpp b/story-editor/src/story_project.cpp
index 37de09c..f8a41d2 100644
--- a/story-editor/src/story_project.cpp
+++ b/story-editor/src/story_project.cpp
@@ -6,19 +6,31 @@
#include
#include "json.hpp"
-
-void StoryProject::Initialize()
+void StoryProject::New(const std::string &uuid, const std::string &file_path)
{
+ m_uuid = uuid;
+ Initialize(file_path);
+}
+
+
+void StoryProject::Initialize(const std::string &file_path)
+{
+ m_project_path = file_path;
+ std::filesystem::path p(file_path);
+ m_working_dir= p.parent_path();
+
// Frist try to create the working directory
- if (!std::filesystem::is_directory(working_dir))
+ if (!std::filesystem::is_directory(m_working_dir))
{
- std::filesystem::create_directories(working_dir);
+ std::filesystem::create_directories(m_working_dir);
}
- m_imagesPath = std::filesystem::path(working_dir) / "images";
- m_soundsPath = std::filesystem::path(working_dir) / "sounds";
+ m_imagesPath = std::filesystem::path(m_working_dir) / "images";
+ m_soundsPath = std::filesystem::path(m_working_dir) / "sounds";
std::filesystem::create_directories(m_imagesPath);
std::filesystem::create_directories(m_soundsPath);
+
+ m_initialized = true;
}
bool StoryProject::Load(const std::string &file_path)
@@ -27,9 +39,9 @@ bool StoryProject::Load(const std::string &file_path)
bool success = false;
std::filesystem::path p(file_path);
- working_dir= p.parent_path();
+ m_working_dir= p.parent_path();
- std::cout << "Working dir is: " << working_dir << std::endl;
+ std::cout << "Working dir is: " << m_working_dir << std::endl;
try {
@@ -89,7 +101,7 @@ bool StoryProject::Load(const std::string &file_path)
m_type = j["type"];
m_code = j["code"];
- m_name = j["name"];
+ name = j["name"];
success = true;
@@ -207,3 +219,29 @@ std::string StoryProject::Compile()
return chip32.str();
}
+void StoryProject::SetImageFormat(ImageFormat format)
+{
+ m_imageFormat = format;
+}
+
+void StoryProject::SetSoundFormat(SoundFormat format)
+{
+ m_soundFormat = format;
+}
+
+void StoryProject::SetDisplayFormat(int w, int h)
+{
+ m_display_w = w;
+ m_display_h = h;
+}
+
+std::string StoryProject::GetProjectFilePath() const
+{
+ return m_project_path;
+}
+
+std::string StoryProject::GetWorkingDir() const
+{
+ return m_working_dir;
+}
+
diff --git a/story-editor/src/story_project.h b/story-editor/src/story_project.h
index 610c61f..13e38ef 100644
--- a/story-editor/src/story_project.h
+++ b/story-editor/src/story_project.h
@@ -44,36 +44,40 @@ struct Resource
struct StoryProject
{
- std::string uuid;
- std::string working_dir; /// Temporary folder based on the uuid, where the archive is unzipped
- std::string file_path; /// project file (archive)
+ enum ImageFormat { IMG_FORMAT_BMP_4BITS, IMG_FORMAT_QOIF, IMG_FORMAT_COUNT };
+ enum SoundFormat { SND_FORMAT_WAV, SND_FORMAT_QOAF, SND_FORMAT_COUNT };
+ // Project properties and location
+ std::string name; /// human readable name
std::vector m_nodes;
std::string m_type;
std::string m_code;
- std::string m_name;
std::vector m_images;
std::vector m_sounds;
StoryNode *m_tree;
- // Initialize a project
- // The following parameters must be set before calling this method:
- // - uuid
- // - working_directory
- void Initialize();
bool Load(const std::string &file_path);
void CreateTree();
void Clear() {
+ m_uuid = "";
+ m_working_dir = "";
m_images.clear();
m_sounds.clear();
+
+ m_initialized = false;
}
std::string Compile();
+ void SetImageFormat(ImageFormat format);
+ void SetSoundFormat(SoundFormat format);
+ void SetDisplayFormat(int w, int h);
+ std::string GetProjectFilePath() const;
+ std::string GetWorkingDir() const;
std::filesystem::path ImagesPath() const { return m_imagesPath; }
std::filesystem::path SoundsPath() const { return m_soundsPath; }
@@ -83,11 +87,27 @@ struct StoryProject
static void ReplaceCharacter(std::string &theString, const std::string &toFind, const std::string &toReplace);
public:
+ // Initialize with an existing project
+ void Initialize(const std::string &file_path);
+ void New(const std::string &uuid, const std::string &file_path);
+
static void EraseString(std::string &theString, const std::string &toErase);
static std::string ToUpper(const std::string &input);
+
private:
+ std::string m_uuid;
std::filesystem::path m_imagesPath;
std::filesystem::path m_soundsPath;
+ bool m_initialized{false};
+
+ std::string m_working_dir; /// Temporary folder based on the uuid, where the archive is unzipped
+ std::string m_project_path; /// JSON project file
+
+ int m_display_w{320};
+ int m_display_h{240};
+
+ ImageFormat m_imageFormat{IMG_FORMAT_BMP_4BITS};
+ SoundFormat m_soundFormat{SND_FORMAT_WAV};
};
#endif // STORY_PROJECT_H
diff --git a/story-editor/src/toolbar.cpp b/story-editor/src/toolbar.cpp
index 101a781..3345bb7 100644
--- a/story-editor/src/toolbar.cpp
+++ b/story-editor/src/toolbar.cpp
@@ -12,7 +12,7 @@ void ToolBar::createActions(QMenuBar *menuBar)
// ------------ New
{
- const QIcon icon = QIcon::fromTheme("document-save", QIcon(":/assets/file-document-plus-outline.svg"));
+ QIcon icon(":/assets/file-document-plus-outline.svg");
QAction *act = new QAction(icon, tr("&New project"), this);
act->setShortcuts(QKeySequence::Save);
act->setStatusTip(tr("Create a new project"));
@@ -20,20 +20,19 @@ void ToolBar::createActions(QMenuBar *menuBar)
fileMenu->addAction(act);
addAction(act);
}
-
// ------------ Save
{
- const QIcon icon = QIcon::fromTheme("document-save", QIcon(":/assets/floppy.svg"));
- QAction *act = new QAction(icon, tr("&Save project"), this);
- act->setShortcuts(QKeySequence::Save);
- act->setStatusTip(tr("Save the current project"));
- connect(act, &QAction::triggered, this, &ToolBar::sigSave);
- fileMenu->addAction(act);
- addAction(act);
+ QIcon icon(":/assets/floppy.svg");
+ m_saveProjectAction = new QAction(icon, tr("&Save project"), this);
+ m_saveProjectAction->setShortcuts(QKeySequence::Save);
+ m_saveProjectAction->setStatusTip(tr("Save the current project"));
+ connect(m_saveProjectAction, &QAction::triggered, this, &ToolBar::sigSave);
+ fileMenu->addAction(m_saveProjectAction);
+ addAction(m_saveProjectAction);
}
// ------------ Open
{
- const QIcon icon = QIcon::fromTheme("document-open", QIcon(":/assets/folder-open.svg"));
+ QIcon icon(":/assets/folder-open-outline.svg");
QAction *act = new QAction(icon, tr("&Open project"), this);
act->setShortcuts(QKeySequence::Open);
act->setStatusTip(tr("Open an existing project"));
@@ -41,10 +40,20 @@ void ToolBar::createActions(QMenuBar *menuBar)
fileMenu->addAction(act);
addAction(act);
}
+ // ------------ Close
+ {
+ QIcon icon(":/assets/close-outline.svg");
+ m_closeProjectAction = new QAction(icon, tr("&Close project"), this);
+ m_closeProjectAction->setShortcuts(QKeySequence::Close);
+ m_closeProjectAction->setStatusTip(tr("Close current project"));
+ connect(m_closeProjectAction, &QAction::triggered, this, &ToolBar::sigClose);
+ fileMenu->addAction(m_closeProjectAction);
+ addAction(m_closeProjectAction);
+ }
fileMenu->addSeparator();
- QAction *quitAct = fileMenu->addAction(tr("&Quit"), this, &QWidget::close);
+ QAction *quitAct = fileMenu->addAction(tr("&Quit"), this, &ToolBar::sigExit);
quitAct->setShortcuts(QKeySequence::Quit);
quitAct->setStatusTip(tr("Quit the application"));
@@ -52,13 +61,51 @@ void ToolBar::createActions(QMenuBar *menuBar)
m_windowsMenu = menuBar->addMenu(tr("&Windows"));
+ auto act = m_windowsMenu->addAction(tr("Reset docks position"));
+ connect(act, &QAction::triggered, this, &ToolBar::sigDefaultDocksPosition);
+
+ m_closeAllDocksAction = m_windowsMenu->addAction(tr("Show/Hide all docks"));
+ m_closeAllDocksAction->setCheckable(true);
+ connect(m_closeAllDocksAction, &QAction::triggered, this, [=] (bool checked) {
+ SetAllDocks(checked);
+ });
+
+ m_windowsMenu->addSeparator();
+
QMenu *helpMenu = menuBar->addMenu(tr("&Help"));
QAction *aboutAct = helpMenu->addAction(tr("&About"), this, &ToolBar::sigAbout);
aboutAct->setStatusTip(tr("Show the application's About box"));
}
+void ToolBar::SetActionsActive(bool enable)
+{
+ for (auto d : m_actionDockList)
+ {
+ d->setEnabled(enable);
+ }
+ m_windowsMenu->setEnabled(enable);
+ m_closeProjectAction->setEnabled(enable);
+ m_saveProjectAction->setEnabled(enable);
+}
+
+void ToolBar::ShowAllDocks(bool enable)
+{
+ m_closeAllDocksAction->setEnabled(enable);
+ m_closeAllDocksAction->trigger();
+}
+
+void ToolBar::SetAllDocks(bool enable)
+{
+ for (auto d : m_actionDockList)
+ {
+ d->setChecked(!enable);
+ d->trigger();
+ }
+}
+
void ToolBar::AddDockToMenu(QAction *action)
{
m_windowsMenu->addAction(action);
+ m_actionDockList.push_back(action);
}
diff --git a/story-editor/src/toolbar.h b/story-editor/src/toolbar.h
index 6fb12a2..2c4afb4 100644
--- a/story-editor/src/toolbar.h
+++ b/story-editor/src/toolbar.h
@@ -11,17 +11,26 @@ class ToolBar : public QToolBar
public:
ToolBar();
void createActions(QMenuBar *menuBar);
-
void AddDockToMenu(QAction *action);
+ void SetAllDocks(bool enable);
+ void SetActionsActive(bool enable);
+ void ShowAllDocks(bool enable);
signals:
void sigNew();
void sigSave();
void sigOpen();
+ void sigClose();
+ void sigExit();
void sigAbout();
+ void sigDefaultDocksPosition();
private:
QMenu *m_windowsMenu;
+ QAction *m_closeAllDocksAction;
+ QAction *m_saveProjectAction;
+ QAction *m_closeProjectAction;
+ QList m_actionDockList;
};
#endif // TOOLBAR_H