diff --git a/.gitignore b/.gitignore index a676324e..54eb9296 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ build/gba build/*-release build/*-debug tags +nostalgia.gba +nostalgia.sav +nostalgia_media.oxfs +media_header.txt diff --git a/src/studio/lib/CMakeLists.txt b/src/studio/lib/CMakeLists.txt index 4054d306..2de10374 100644 --- a/src/studio/lib/CMakeLists.txt +++ b/src/studio/lib/CMakeLists.txt @@ -8,6 +8,7 @@ set(CMAKE_AUTOMOC ON) add_library( NostalgiaStudioStatic newwizard.cpp + oxfstreeview.cpp project.cpp ) @@ -29,13 +30,15 @@ target_link_libraries( add_library( NostalgiaStudio SHARED + newwizard.cpp + oxfstreeview.cpp + project.cpp ) target_link_libraries( NostalgiaStudio Qt5::Core Qt5::Widgets - NostalgiaStudioStatic OxFS OxStd ) @@ -43,6 +46,7 @@ target_link_libraries( install( FILES newwizard.hpp + oxfstreeview.hpp project.hpp DESTINATION include/nostalgia/studio/lib diff --git a/src/studio/lib/oxfstreeview.cpp b/src/studio/lib/oxfstreeview.cpp new file mode 100644 index 00000000..157abd7c --- /dev/null +++ b/src/studio/lib/oxfstreeview.cpp @@ -0,0 +1,17 @@ +/* + * Copyright 2016-2017 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "oxfstreeview.hpp" + +namespace nostalgia { +namespace studio { + + + +} +} diff --git a/src/studio/lib/oxfstreeview.hpp b/src/studio/lib/oxfstreeview.hpp new file mode 100644 index 00000000..4254b009 --- /dev/null +++ b/src/studio/lib/oxfstreeview.hpp @@ -0,0 +1,39 @@ +/* + * Copyright 2016-2017 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include +#include +#include + +namespace nostalgia { +namespace studio { + +class OxFSFile { + private: + QList m_childItems; + QList m_itemData; + OxFSFile *m_parentItem; + + public: + explicit OxFSFile(const QList &data, OxFSFile *parentItem = 0); + ~OxFSFile(); + + void appendChild(OxFSFile *child); + + OxFSFile *child(int row); + int childCount() const; + int columnCount() const; + QVariant data(int column) const; + int row() const; + OxFSFile *parentItem(); +}; + +} +} diff --git a/src/studio/lib/project.cpp b/src/studio/lib/project.cpp index c2b4abe8..51f13284 100644 --- a/src/studio/lib/project.cpp +++ b/src/studio/lib/project.cpp @@ -22,22 +22,14 @@ Project::Project(QString path) { } Project::~Project() { - if (m_fs) { - delete m_fs; - m_fs = nullptr; - } - if (m_romBuff) { - delete m_romBuff; - m_romBuff = nullptr; - } } void Project::create() { QDir().mkpath(m_path); - m_romBuff = new QByteArray(1024, 0); + m_romBuff = QSharedPointer(new QByteArray(1024, 0)); FileSystem32::format(m_romBuff->data(), m_romBuff->size(), true); - m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size()); + m_fs = QSharedPointer(createFileSystem(m_romBuff->data(), m_romBuff->size())); m_fs->mkdir("/Tilesets"); @@ -49,13 +41,17 @@ void Project::create() { int Project::open() { QFile file(m_path + ROM_FILE); - m_romBuff = new QByteArray(file.size(), 0); - file.open(QIODevice::ReadOnly); - if (file.read(m_romBuff->data(), file.size()) > 0) { - m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size()); - return 0; + m_romBuff = QSharedPointer(new QByteArray(file.size(), 0)); + if (file.exists()) { + file.open(QIODevice::ReadOnly); + if (file.read(m_romBuff->data(), file.size()) > 0) { + m_fs = QSharedPointer(createFileSystem(m_romBuff->data(), m_romBuff->size())); + return 0; + } else { + return 1; + } } else { - return 1; + return 2; } } diff --git a/src/studio/lib/project.hpp b/src/studio/lib/project.hpp index 414ce63f..25c0bbab 100644 --- a/src/studio/lib/project.hpp +++ b/src/studio/lib/project.hpp @@ -8,6 +8,8 @@ #pragma once +#include + #include namespace nostalgia { @@ -20,8 +22,8 @@ class Project: public QObject { static QString ROM_FILE; QString m_path = ""; - QByteArray *m_romBuff = nullptr; - ox::fs::FileSystem *m_fs = nullptr; + QSharedPointer m_romBuff; + QSharedPointer m_fs; public: Project(QString path); diff --git a/src/studio/main.cpp b/src/studio/main.cpp index abc07038..aeefb4ec 100644 --- a/src/studio/main.cpp +++ b/src/studio/main.cpp @@ -31,7 +31,7 @@ int run(int argc, char **args) { } QApplication app(argc, args); - app.setApplicationName(config.app_name); + app.setApplicationName(config.appName); MainWindow w(config); w.show(); diff --git a/src/studio/mainwindow.cpp b/src/studio/mainwindow.cpp index 26f1a3ac..09569a8b 100644 --- a/src/studio/mainwindow.cpp +++ b/src/studio/mainwindow.cpp @@ -14,7 +14,9 @@ #include #include #include +#include #include + #include "lib/newwizard.hpp" #include "lib/project.hpp" #include "mainwindow.hpp" @@ -31,9 +33,13 @@ MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) { move(-x(), -y()); move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2); - setWindowTitle(config.app_name); + setWindowTitle(config.appName); + + auto tabbar = new QTabBar(this); + setCentralWidget(tabbar); setupMenu(); + setupProjectExplorer(); } MainWindow::~MainWindow() { @@ -45,6 +51,7 @@ MainWindow::~MainWindow() { void MainWindow::setupMenu() { auto menu = menuBar(); auto fileMenu = menu->addMenu(tr("&File")); + m_viewMenu = menu->addMenu(tr("&View")); // New... addAction( @@ -56,6 +63,16 @@ void MainWindow::setupMenu() { SLOT(showNewWizard()) ); + // Open Project + addAction( + fileMenu, + tr("&Open Project"), + tr(""), + QKeySequence::Open, + this, + SLOT(openProject()) + ); + // Exit addAction( fileMenu, @@ -64,16 +81,22 @@ void MainWindow::setupMenu() { QKeySequence::Quit, QApplication::quit ); +} +void MainWindow::setupProjectExplorer() { + // setup dock + auto dock = new QDockWidget(tr("&Project"), this); + dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + addDockWidget(Qt::LeftDockWidgetArea, dock); + resizeDocks({dock}, {(int) (width() * 0.25)}, Qt::Horizontal); - addAction( - fileMenu, - tr("Open &Project"), - tr(""), - QKeySequence::Open, - this, - SLOT(openProject()) - ); + // setup tree view +} + +void MainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockWidget) { + QMainWindow::addDockWidget(area, dockWidget); + m_viewMenu->addAction(dockWidget->toggleViewAction()); + m_dockWidgets.push_back(dockWidget); } void MainWindow::addAction(QMenu *menu, QString text, QString toolTip, @@ -100,9 +123,11 @@ void MainWindow::addAction(QMenu *menu, QString text, QString toolTip, void MainWindow::openProject() { auto p = QFileDialog::getExistingDirectory(this, tr("Select Project Directory..."), QDir::homePath()); - auto project = new Project(p); - project->open(); - m_project = project; + auto project = QSharedPointer(new Project(p)); + auto err = project->open(); + if (err == 0) { + m_project = project; + } } void MainWindow::showNewWizard() { diff --git a/src/studio/mainwindow.hpp b/src/studio/mainwindow.hpp index 70eeb512..19616ee0 100644 --- a/src/studio/mainwindow.hpp +++ b/src/studio/mainwindow.hpp @@ -8,9 +8,12 @@ #pragma once -#include +#include #include +#include #include +#include +#include #include #include #include @@ -22,14 +25,26 @@ namespace nostalgia { namespace studio { +struct NostalgiaStudioState { + QString currentProjectPath; +}; + +template +int ioOp(T *io, NostalgiaStudioState *obj) { + ox::Error err = 0; + err |= io->op("current_project_path", &obj->currentProjectPath); + return err; +} + + struct NostalgiaStudioProfile { - QString app_name; + QString appName; }; template int ioOp(T *io, NostalgiaStudioProfile *obj) { ox::Error err = 0; - err |= io->op("app_name", &obj->app_name); + err |= io->op("app_name", &obj->appName); return err; } @@ -41,11 +56,14 @@ class MainWindow: public QMainWindow { static const QString AppTitle; private: - Project *m_project = nullptr; + QSharedPointer m_project; + QPointer m_viewMenu; QVector> m_cleanupTasks; + QVector> m_dockWidgets; public: MainWindow(NostalgiaStudioProfile config, QWidget *parent = 0); + virtual ~MainWindow(); void openProject(QString); @@ -55,6 +73,10 @@ class MainWindow: public QMainWindow { void setupMenu(); + void setupProjectExplorer(); + + void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget); + void addAction(QMenu *menu, QString text, QString toolTip, QKeySequence::StandardKey key, const QObject *tgt, const char *cb);