[nostalgia/core/studio] Add NewPaletteWizard and implement NewTileSheetWizard
This commit is contained in:
parent
5cec2cf819
commit
64ee637b74
@ -3,6 +3,7 @@ add_library(
|
||||
imgconv.cpp
|
||||
import_tilesheet_wizard.cpp
|
||||
new_tilesheet_wizard.cpp
|
||||
newpalettewizard.cpp
|
||||
paletteeditor.cpp
|
||||
plugin.cpp
|
||||
tilesheeteditor.cpp
|
||||
|
@ -9,20 +9,42 @@
|
||||
#include <QBuffer>
|
||||
#include <QFile>
|
||||
|
||||
#include <nostalgia/core/consts.hpp>
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
|
||||
#include "consts.hpp"
|
||||
#include "new_tilesheet_wizard.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
NewTilesheetWizardPage::NewTilesheetWizardPage(const studio::Context *ctx) {
|
||||
m_ctx = ctx;
|
||||
addLineEdit(tr("&Tile Sheet Name:"), QString(TileSheetName) + "*", "", [](QString) {
|
||||
return 0;
|
||||
addLineEdit(tr("&Tile Sheet Name:"), QString(TileSheetName) + "*", "", [this](QString name) {
|
||||
auto path = QString(TileSheetDir) + name + FileExt_ng;
|
||||
auto err = m_ctx->project->exists(path);
|
||||
if (err) {
|
||||
showValidationError(tr("A tile sheet with this name already exists."));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
);
|
||||
m_palettePicker = addComboBox(tr("&Palette:"), QString(Palette) + "*", {""});
|
||||
m_ctx->project->subscribe(studio::ProjectEvent::FileRecognized, m_palettePicker, [this](QString path) {
|
||||
if (path.startsWith(PaletteDir) && path.endsWith(FileExt_npal)) {
|
||||
m_palettePicker->addItem(studio::filePathToName(path, PaletteDir, FileExt_npal), path);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int NewTilesheetWizardPage::accept() {
|
||||
auto tilesheetName = field(TileSheetName).toString();
|
||||
const auto tilesheetName = field(TileSheetName).toString();
|
||||
const auto palette = m_palettePicker->itemData(field(Palette).toInt()).toString();
|
||||
const auto outPath = TileSheetDir + tilesheetName + FileExt_ng;
|
||||
NostalgiaGraphic ng;
|
||||
ng.columns = 1;
|
||||
ng.rows = 1;
|
||||
ng.defaultPalette = palette.toUtf8().data();
|
||||
m_ctx->project->writeObj(outPath, &ng);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,9 @@ namespace nostalgia::core {
|
||||
|
||||
class NewTilesheetWizardPage: public studio::WizardFormPage {
|
||||
private:
|
||||
static constexpr auto TileSheetDir = "/TileSheets/";
|
||||
static constexpr auto TileSheetName = "projectName";
|
||||
static constexpr auto Palette = "palette";
|
||||
class QComboBox *m_palettePicker = nullptr;
|
||||
const studio::Context *m_ctx = nullptr;
|
||||
|
||||
public:
|
||||
|
40
src/nostalgia/core/studio/newpalettewizard.cpp
Normal file
40
src/nostalgia/core/studio/newpalettewizard.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2016 - 2020 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 <QBuffer>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
||||
#include <nostalgia/core/consts.hpp>
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
|
||||
#include "consts.hpp"
|
||||
#include "newpalettewizard.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
NewPaletteWizardPage::NewPaletteWizardPage(const studio::Context *ctx) {
|
||||
m_ctx = ctx;
|
||||
addLineEdit(tr("&Palette Name:"), QString(PaletteName) + "*", "", [this](QString) {
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
int NewPaletteWizardPage::accept() {
|
||||
const auto paletteName = field(PaletteName).toString();
|
||||
const auto path = PaletteDir + paletteName + FileExt_npal;
|
||||
if (m_ctx->project->exists(path)) {
|
||||
showValidationError(tr("A palette with this name already exists."));
|
||||
return 1;
|
||||
}
|
||||
NostalgiaPalette pal;
|
||||
m_ctx->project->writeObj(path, &pal);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
28
src/nostalgia/core/studio/newpalettewizard.hpp
Normal file
28
src/nostalgia/core/studio/newpalettewizard.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2016 - 2020 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 <nostalgia/studio/studio.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class NewPaletteWizardPage: public studio::WizardFormPage {
|
||||
private:
|
||||
static constexpr auto PaletteName = "paletteName";
|
||||
const studio::Context *m_ctx = nullptr;
|
||||
|
||||
public:
|
||||
NewPaletteWizardPage(const studio::Context *args);
|
||||
|
||||
int accept();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "new_tilesheet_wizard.hpp"
|
||||
#include "newpalettewizard.hpp"
|
||||
#include "import_tilesheet_wizard.hpp"
|
||||
#include "paletteeditor.hpp"
|
||||
#include "tilesheeteditor.hpp"
|
||||
@ -19,6 +20,14 @@ namespace nostalgia::core {
|
||||
|
||||
QVector<studio::WizardMaker> Plugin::newWizards(const studio::Context *ctx) {
|
||||
return {
|
||||
{
|
||||
tr("Palette"),
|
||||
[ctx]() {
|
||||
QVector<QWizardPage*> pgs;
|
||||
pgs.push_back(new NewPaletteWizardPage(ctx));
|
||||
return pgs;
|
||||
}
|
||||
},
|
||||
{
|
||||
tr("Tile Sheet"),
|
||||
[ctx]() {
|
||||
@ -26,7 +35,7 @@ QVector<studio::WizardMaker> Plugin::newWizards(const studio::Context *ctx) {
|
||||
pgs.push_back(new NewTilesheetWizardPage(ctx));
|
||||
return pgs;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -564,9 +564,7 @@ void TileSheetEditor::restoreState() {
|
||||
}
|
||||
|
||||
QString TileSheetEditor::paletteName(QString palettePath) const {
|
||||
const auto begin = ox_strlen(PaletteDir);
|
||||
const auto end = palettePath.size() - (ox_strlen(FileExt_npal) + ox_strlen(PaletteDir));
|
||||
return palettePath.mid(begin, end);
|
||||
return studio::filePathToName(palettePath, PaletteDir, FileExt_npal);
|
||||
}
|
||||
|
||||
QString TileSheetEditor::palettePath(QString paletteName) const {
|
||||
|
Loading…
x
Reference in New Issue
Block a user