diff --git a/forms/regionmapeditor.ui b/forms/regionmapeditor.ui
index a631c19d..45e43bff 100644
--- a/forms/regionmapeditor.ui
+++ b/forms/regionmapeditor.ui
@@ -50,42 +50,6 @@
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- Crop View to Map Size
-
-
- false
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
-
@@ -196,7 +160,7 @@
0
0
466
- 350
+ 351
@@ -317,7 +281,7 @@
0
0
466
- 350
+ 351
@@ -438,7 +402,7 @@
0
0
466
- 350
+ 351
@@ -588,7 +552,7 @@
8
0
278
- 341
+ 342
@@ -1126,6 +1090,7 @@
File
+
diff --git a/forms/regionmappropertiesdialog.ui b/forms/regionmappropertiesdialog.ui
index 7b627774..85f54f9c 100644
--- a/forms/regionmappropertiesdialog.ui
+++ b/forms/regionmappropertiesdialog.ui
@@ -7,7 +7,7 @@
0
0
564
- 1016
+ 902
@@ -43,27 +43,7 @@
- -
-
-
- color: #ff5c33
-
-
-
-
-
-
- -
-
-
- color: #ff5c33
-
-
-
-
-
-
- -
+
-
Tilemap Properties
@@ -112,25 +92,6 @@
- -
-
-
-
- 0
- 0
-
-
-
-
- 75
- 0
-
-
-
- 255
-
-
-
-
@@ -167,16 +128,6 @@
- -
-
-
- color: #ff5c33
-
-
-
-
-
-
-
@@ -292,6 +243,13 @@
+ -
+
+
+ palette path
+
+
+
-
@@ -326,17 +284,39 @@
- -
-
+
-
+
+
+ color: #ff5c33
+
- palette path
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 75
+ 0
+
+
+
+ 255
- -
+
-
Layout Properties
@@ -620,7 +600,7 @@
- -
+
-
Qt::Horizontal
@@ -633,7 +613,7 @@
- -
+
-
Qt::Horizontal
@@ -643,52 +623,6 @@
- -
-
-
- width
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 75
- 0
-
-
-
-
- -
-
-
- height
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 75
- 0
-
-
-
-
diff --git a/include/core/regionmap.h b/include/core/regionmap.h
index c231e0b5..7a29c2a8 100644
--- a/include/core/regionmap.h
+++ b/include/core/regionmap.h
@@ -38,8 +38,9 @@ struct MapSectionEntry
bool valid = false;
};
-class RegionMap
+class RegionMap : public QObject
{
+ Q_OBJECT
public:
RegionMap() = delete;
RegionMap(Project *);
@@ -64,7 +65,7 @@ public:
void saveConfig();// ? or do this in the editor only?
void saveOptions(int id, QString sec, QString name, int x, int y);
- void resize(int width, int height);
+ void resizeTilemap(int width, int height, bool update = true);
void resetSquare(int index);
void clearLayout();
void clearImage();
@@ -86,6 +87,9 @@ public:
void setTile(int index, TilemapTile &tile);
void setTileData(int index, unsigned id, bool hFlip, bool vFlip, int palette);
int getMapSquareIndex(int x, int y);
+
+ QString getAlias() { return this->alias; }
+ poryjson::Json::object config();
QString palPath();
QString pngPath();
@@ -141,6 +145,11 @@ public:
void undo();
void redo();
+ void emitDisplay();
+
+signals:
+ void mapNeedsDisplaying();
+
private:
// TODO: defaults needed?
tsl::ordered_map *region_map_entries = nullptr;
@@ -150,9 +159,6 @@ private:
int tilemap_width;
int tilemap_height;
- int region_width;
- int region_height;
-
int layout_width;
int layout_height;
diff --git a/include/core/regionmapeditcommands.h b/include/core/regionmapeditcommands.h
index ea9f1e43..7f25d938 100644
--- a/include/core/regionmapeditcommands.h
+++ b/include/core/regionmapeditcommands.h
@@ -14,6 +14,9 @@ enum RMCommandId {
ID_EditLayout,
ID_ResizeLayout,
ID_EditEntry,
+ ID_RemoveEntry,
+ ID_AddEntry,
+ ID_ResizeTilemap,
};
@@ -28,7 +31,7 @@ public:
bool mergeWith(const QUndoCommand *command) override;
int id() const override { return RMCommandId::ID_EditTilemap; }
-private:
+protected:
RegionMap *map;
QByteArray oldTilemap;
@@ -110,6 +113,8 @@ public:
void undo() override;
void redo() override;
+
+ int id() const override { return RMCommandId::ID_RemoveEntry; }
};
@@ -120,10 +125,28 @@ public:
void undo() override;
void redo() override;
+
+ int id() const override { return RMCommandId::ID_AddEntry; }
};
-// ResizeTilemap
-// ResizeMap
+/// ResizeTilemap
+class ResizeTilemap : public EditTilemap {
+public:
+ ResizeTilemap(RegionMap *map, QByteArray oldTilemap, QByteArray newTilemap,
+ int oldWidth, int oldHeight, int newWidth, int newHeight, QUndoCommand *parent = nullptr);
+
+ void undo() override;
+ void redo() override;
+
+ int id() const override { return RMCommandId::ID_ResizeTilemap; }
+
+private:
+ int oldWidth;
+ int oldHeight;
+ int newWidth;
+ int newHeight;
+};
+
#endif // REGIONMAPEDITCOMMANDS_H
diff --git a/include/ui/regionmapeditor.h b/include/ui/regionmapeditor.h
index 88d06d22..84f16f0f 100644
--- a/include/ui/regionmapeditor.h
+++ b/include/ui/regionmapeditor.h
@@ -44,7 +44,7 @@ public:
void onRegionMapEntriesSelectedTileChanged(QString) {};
void onRegionMapEntryDragged(int, int);
- void resize(int width, int height);
+ void resizeTilemap(int width, int height);
QObjectList shortcutableObjects() const;
@@ -87,6 +87,8 @@ private:
RegionMapPixmapItem *region_map_item = nullptr;
CityMapPixmapItem *city_map_item = nullptr;
+ bool saveRegionMap(RegionMap *map);
+ void saveConfig();
bool loadRegionMapEntries();
bool saveRegionMapEntries();
tsl::ordered_map region_map_entries;
@@ -122,6 +124,7 @@ private:
private slots:
void on_action_RegionMap_Save_triggered();
+ void on_actionSave_All_triggered();
void on_action_RegionMap_Resize_triggered();
void on_action_RegionMap_ClearImage_triggered();
void on_action_RegionMap_ClearLayout_triggered();
diff --git a/include/ui/regionmappixmapitem.h b/include/ui/regionmappixmapitem.h
index 2f8bc9af..1856a8bb 100644
--- a/include/ui/regionmappixmapitem.h
+++ b/include/ui/regionmappixmapitem.h
@@ -17,7 +17,7 @@ public:
this->tile_selector = tile_selector;
setAcceptHoverEvents(true);
}
- RegionMap *region_map;
+ RegionMap *region_map = nullptr;
TilemapTileSelector *tile_selector;
virtual void paint(QGraphicsSceneMouseEvent *);
diff --git a/resources/text/region_map_default_emerald.json b/resources/text/region_map_default_emerald.json
index 77de6032..2d37e159 100644
--- a/resources/text/region_map_default_emerald.json
+++ b/resources/text/region_map_default_emerald.json
@@ -2,8 +2,6 @@
"region_maps": [
{
"alias": "hoenn",
- "width": 32,
- "height": 20,
"tilemap": {
"width": 64,
"height": 64,
@@ -22,8 +20,6 @@
},
{
"alias": "pokedex area screen",
- "width": 32,
- "height": 20,
"tilemap": {
"width": 32,
"height": 32,
diff --git a/resources/text/region_map_default_firered.json b/resources/text/region_map_default_firered.json
index c9518705..bf1cb179 100644
--- a/resources/text/region_map_default_firered.json
+++ b/resources/text/region_map_default_firered.json
@@ -2,8 +2,6 @@
"region_maps": [
{
"alias": "kanto",
- "width": 30,
- "height": 20,
"tilemap": {
"width": 30,
"height": 20,
@@ -23,8 +21,6 @@
},
{
"alias": "sevii_123",
- "width": 30,
- "height": 20,
"tilemap": {
"width": 30,
"height": 20,
@@ -44,8 +40,6 @@
},
{
"alias": "sevii_45",
- "width": 30,
- "height": 20,
"tilemap": {
"width": 30,
"height": 20,
@@ -65,8 +59,6 @@
},
{
"alias": "sevii_67",
- "width": 30,
- "height": 20,
"tilemap": {
"width": 30,
"height": 20,
diff --git a/src/core/regionmap.cpp b/src/core/regionmap.cpp
index d354d878..6297b63e 100644
--- a/src/core/regionmap.cpp
+++ b/src/core/regionmap.cpp
@@ -31,8 +31,6 @@ bool RegionMap::loadMapData(poryjson::Json data) {
poryjson::Json::object mapObject = data.object_items();
this->alias = mapObject["alias"].string_value();
- this->region_width = mapObject["width"].int_value();
- this->region_height = mapObject["height"].int_value();
poryjson::Json tilemapJson = mapObject["tilemap"];
poryjson::Json layoutJson = mapObject["layout"];
@@ -260,6 +258,41 @@ void RegionMap::save() {
saveLayout();
}
+poryjson::Json::object RegionMap::config() {
+ poryjson::Json::object config;
+
+ config["alias"] = this->alias;
+
+ poryjson::Json::object tilemapObject;
+ tilemapObject["width"] = this->tilemap_width;
+ tilemapObject["height"] = this->tilemap_height;
+
+ QMap tilemapFormatMap = { {TilemapFormat::Plain, "plain"}, {TilemapFormat::BPP_4, "4bpp"}, {TilemapFormat::BPP_8, "8bpp"} };
+ tilemapObject["format"] = tilemapFormatMap[this->tilemap_format];
+ tilemapObject["tileset_path"] = this->tileset_path;
+ tilemapObject["tilemap_path"] = this->tilemap_path;
+ if (!this->palette_path.isEmpty()) {
+ tilemapObject["palette"] = this->palette_path;
+ }
+ config["tilemap"] = tilemapObject;
+
+ if (this->layout_format != LayoutFormat::None) {
+ poryjson::Json::object layoutObject;
+ layoutObject["width"] = this->layout_width;
+ layoutObject["height"] = this->layout_height;
+ layoutObject["offset_left"] = this->offset_left;
+ layoutObject["offset_top"] = this->offset_top;
+ QMap layoutFormatMap = { {LayoutFormat::Binary, "binary"}, {LayoutFormat::CArray, "C array"} };
+ layoutObject["format"] = layoutFormatMap[this->layout_format];
+ layoutObject["path"] = this->layout_path;
+ config["layout"] = layoutObject;
+ } else {
+ config["layout"] = nullptr;
+ }
+
+ return config;
+}
+
void RegionMap::saveTilemap() {
QFile tilemapFile(fullPath(this->tilemap_path));
if (!tilemapFile.open(QIODevice::WriteOnly)) {
@@ -354,9 +387,52 @@ void RegionMap::replaceSection(QString oldSection, QString newSection) {
}
}
-void RegionMap::resize(int newWidth, int newHeight) {
- // TODO
+void RegionMap::resizeTilemap(int newWidth, int newHeight, bool update) {
+ auto tilemapCopy = this->tilemap;
+ int oldWidth = this->tilemap_width;
+ int oldHeight = this->tilemap_height;
+ this->tilemap_width = newWidth;
+ this->tilemap_height = newHeight;
+ if (update) {
+ QByteArray tilemapArray;
+ QDataStream dataStream(&tilemapArray, QIODevice::WriteOnly);
+ dataStream.setByteOrder(QDataStream::LittleEndian);
+ switch (this->tilemap_format) {
+ case TilemapFormat::Plain:
+ for (int y = 0; y < newHeight; y++)
+ for (int x = 0; x < newWidth; x++) {
+ if (y < oldHeight && x < oldWidth) {
+ int i = x + y * oldWidth;
+ uint8_t tile = tilemapCopy[i]->raw();
+ dataStream << tile;
+ } else {
+ uint8_t tile = 0;
+ dataStream << tile;
+ }
+ }
+ break;
+ case TilemapFormat::BPP_4:
+ case TilemapFormat::BPP_8:
+ for (int y = 0; y < newHeight; y++)
+ for (int x = 0; x < newWidth; x++) {
+ if (y < oldHeight && x < oldWidth) {
+ int i = x + y * oldWidth;
+ uint16_t tile = tilemapCopy[i]->raw();
+ dataStream << tile;
+ } else {
+ uint16_t tile = 0;
+ dataStream << tile;
+ }
+ }
+ break;
+ }
+ setTilemap(tilemapArray);
+ }
+}
+
+void RegionMap::emitDisplay() {
+ emit mapNeedsDisplaying();
}
QByteArray RegionMap::getTilemap() {
diff --git a/src/core/regionmapeditcommands.cpp b/src/core/regionmapeditcommands.cpp
index f59bc006..654a73b4 100644
--- a/src/core/regionmapeditcommands.cpp
+++ b/src/core/regionmapeditcommands.cpp
@@ -225,4 +225,37 @@ void RemoveEntry::undo() {
QUndoCommand::undo();
}
+///
+
+ResizeTilemap::ResizeTilemap(RegionMap *map, QByteArray oldTilemap, QByteArray newTilemap,
+ int oldWidth, int oldHeight, int newWidth, int newHeight, QUndoCommand *parent)
+ : EditTilemap(map, oldTilemap, newTilemap, -1, parent) {
+ setText("Resize Tilemap");
+
+ this->oldWidth = oldWidth;
+ this->oldHeight = oldHeight;
+ this->newWidth = newWidth;
+ this->newHeight = newHeight;
+}
+
+void ResizeTilemap::redo() {
+ QUndoCommand::redo();
+
+ if (!map) return;
+
+ map->resizeTilemap(this->newWidth, this->newHeight, false);
+ map->setTilemap(this->newTilemap);
+ map->emitDisplay();
+}
+
+void ResizeTilemap::undo() {
+ if (!map) return;
+
+ map->resizeTilemap(this->oldWidth, this->oldHeight, false);
+ map->setTilemap(this->oldTilemap);
+ map->emitDisplay();
+
+ QUndoCommand::undo();
+}
+
diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp
index ea795c22..6b8cc02f 100644
--- a/src/ui/regionmapeditor.cpp
+++ b/src/ui/regionmapeditor.cpp
@@ -22,21 +22,19 @@
using OrderedJson = poryjson::Json;
using OrderedJsonDoc = poryjson::JsonDoc;
-RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project_) :
+RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project) :
QMainWindow(parent),
ui(new Ui::RegionMapEditor)
{
this->ui->setupUi(this);
- this->project = project_;
- this->ui->action_RegionMap_Resize->setVisible(false);
+ this->project = project;
this->initShortcuts();
this->restoreWindowState();
- //on_verticalSlider_Zoom_Map_Image_valueChanged(50);
}
RegionMapEditor::~RegionMapEditor()
{
- delete ui;
+ this->region_map = nullptr;
// deletion must be done in this order else crashes
auto stacks = this->history.stacks();
for (auto *stack : stacks) {
@@ -55,6 +53,7 @@ RegionMapEditor::~RegionMapEditor()
delete scene_city_map_image;
delete scene_region_map_layout;
delete scene_region_map_tiles;
+ delete ui;
}
void RegionMapEditor::restoreWindowState() {
@@ -81,10 +80,6 @@ void RegionMapEditor::initShortcuts() {
ui->menuEdit->addAction(undoAction);
ui->menuEdit->addAction(redoAction);
- connect(&(this->history), &QUndoGroup::indexChanged, [this](int) {
- on_tabWidget_Region_Map_currentChanged(this->ui->tabWidget_Region_Map->currentIndex());
- });
-
shortcutsConfig.load();
shortcutsConfig.setDefaultShortcuts(shortcutableObjects());
applyUserShortcuts();
@@ -433,6 +428,10 @@ bool RegionMapEditor::load() {
newMap->setEntries(&this->region_map_entries);
newMap->loadMapData(o);
+ connect(newMap, &RegionMap::mapNeedsDisplaying, [this]() {
+ displayRegionMap();
+ });
+
region_maps[alias] = newMap;
this->history.addStack(&(newMap->editHistory));
@@ -448,6 +447,10 @@ bool RegionMapEditor::load() {
setRegionMap(region_maps.begin()->second);
}
+ connect(&(this->history), &QUndoGroup::indexChanged, [this](int) {
+ on_tabWidget_Region_Map_currentChanged(this->ui->tabWidget_Region_Map->currentIndex());
+ });
+
return true;
}
@@ -477,23 +480,56 @@ bool RegionMapEditor::loadCityMaps() {
return false;
}
-void RegionMapEditor::on_action_RegionMap_Save_triggered() {
- // TODO: add "Save All" to save all region maps
- this->region_map->save();
+bool RegionMapEditor::saveRegionMap(RegionMap *map) {
+ //
+ if (!map) return false;
- // save entries
- saveRegionMapEntries();
+ map->save();
- // save config
+ return true;
+}
+
+void RegionMapEditor::saveConfig() {
+ OrderedJson::array mapArray;
+ for (auto it : this->region_maps) {
+ OrderedJson::object obj = it.second->config();
+ mapArray.append(obj);
+ }
+
+ OrderedJson::object mapsObject;
+ mapsObject["region_maps"] = mapArray;
+
+ OrderedJson newConfigJson(mapsObject);
QString filepath = QString("%1/src/data/region_map/porymap_config.json").arg(this->project->root);
QFile file(filepath);
if (!file.open(QIODevice::WriteOnly)) {
logError(QString("Error: Could not open %1 for writing").arg(filepath));
return;
}
- OrderedJsonDoc jsonDoc(&(this->rmConfigJson));
+ OrderedJsonDoc jsonDoc(&newConfigJson);
jsonDoc.dump(&file);
file.close();
+}
+
+void RegionMapEditor::on_action_RegionMap_Save_triggered() {
+ // TODO: add "Save All" to save all region maps
+ saveRegionMap(this->region_map);
+
+ // save entries
+ saveRegionMapEntries();
+
+ // save config
+ saveConfig();
+
+ this->hasUnsavedChanges = false;
+}
+
+void RegionMapEditor::on_actionSave_All_triggered() {
+ for (auto it : this->region_maps) {
+ saveRegionMap(it.second);
+ }
+ saveRegionMapEntries();
+ saveConfig();
this->hasUnsavedChanges = false;
}
@@ -520,7 +556,6 @@ void RegionMapEditor::updateLayerDisplayed() {
}
void RegionMapEditor::on_comboBox_regionSelector_textActivated(const QString ®ion) {
- //
if (this->region_maps.contains(region)) {
setRegionMap(region_maps.at(region));
}
@@ -596,6 +631,8 @@ void RegionMapEditor::updateRegionMapLayoutOptions(int index) {
this->ui->comboBox_RM_ConnectedMap->setCurrentText(this->region_map->squareMapSection(index));
this->ui->comboBox_RM_ConnectedMap->blockSignals(false);
+ this->ui->pushButton_RM_Options_delete->setEnabled(this->region_map->squareHasMap(index));
+
this->ui->spinBox_RM_LayoutWidth->blockSignals(true);
this->ui->spinBox_RM_LayoutHeight->blockSignals(true);
this->ui->spinBox_RM_LayoutWidth->setMinimum(1);
@@ -910,6 +947,8 @@ void RegionMapEditor::onHoveredRegionMapTileCleared() {
}
void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPixmapItem *item) {
+ static unsigned actionId_ = 0;
+
QPointF pos = event->pos();
int x = static_cast(pos.x()) / 8;
int y = static_cast(pos.y()) / 8;
@@ -920,9 +959,17 @@ void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, Reg
item->select(event);
//} else if (event->buttons() & Qt::MiddleButton) {// TODO
} else {
- item->paint(event);
- this->region_map_layout_item->draw();
- this->hasUnsavedChanges = true;
+ if (event->type() == QEvent::GraphicsSceneMouseRelease) {
+ actionId_++;
+ } else {
+ QByteArray oldTilemap = this->region_map->getTilemap();
+ item->paint(event);
+ QByteArray newTilemap = this->region_map->getTilemap();
+ EditTilemap *command = new EditTilemap(this->region_map, oldTilemap, newTilemap, actionId_);
+ this->region_map->commit(command);
+ //this->region_map_layout_item->draw();
+ this->hasUnsavedChanges = true;
+ }
}
}
@@ -960,7 +1007,7 @@ void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityM
void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) {
this->ui->stackedWidget_RM_Options->setCurrentIndex(index);
- if (!region_map) return;
+ if (!this->region_map) return;
switch (index)
{
case 0:
@@ -1019,8 +1066,6 @@ void RegionMapEditor::on_comboBox_layoutLayer_textActivated(const QString &text)
}
void RegionMapEditor::on_spinBox_RM_Entry_x_valueChanged(int x) {
- //tryInsertNewMapEntry(activeEntry);
- qDebug() << "spinBox_RM_Entry_x valueChanged" << x;
if (!this->region_map_entries.contains(activeEntry)) return;
MapSectionEntry oldEntry = this->region_map_entries[activeEntry];
this->region_map_entries[activeEntry].x = x;
@@ -1036,7 +1081,6 @@ void RegionMapEditor::on_spinBox_RM_Entry_x_valueChanged(int x) {
}
void RegionMapEditor::on_spinBox_RM_Entry_y_valueChanged(int y) {
- //tryInsertNewMapEntry(activeEntry);
if (!this->region_map_entries.contains(activeEntry)) return;
MapSectionEntry oldEntry = this->region_map_entries[activeEntry];
this->region_map_entries[activeEntry].y = y;
@@ -1052,7 +1096,6 @@ void RegionMapEditor::on_spinBox_RM_Entry_y_valueChanged(int y) {
}
void RegionMapEditor::on_spinBox_RM_Entry_width_valueChanged(int width) {
- //tryInsertNewMapEntry(activeEntry);
if (!this->region_map_entries.contains(activeEntry)) return;
MapSectionEntry oldEntry = this->region_map_entries[activeEntry];
this->region_map_entries[activeEntry].width = width;
@@ -1064,7 +1107,6 @@ void RegionMapEditor::on_spinBox_RM_Entry_width_valueChanged(int width) {
}
void RegionMapEditor::on_spinBox_RM_Entry_height_valueChanged(int height) {
- //tryInsertNewMapEntry(activeEntry);
if (!this->region_map_entries.contains(activeEntry)) return;
MapSectionEntry oldEntry = this->region_map_entries[activeEntry];
this->region_map_entries[activeEntry].height = height;
@@ -1076,7 +1118,6 @@ void RegionMapEditor::on_spinBox_RM_Entry_height_valueChanged(int height) {
}
void RegionMapEditor::on_spinBox_RM_LayoutWidth_valueChanged(int value) {
- //
if (this->region_map) {
int oldWidth = this->region_map->layoutWidth();
int oldHeight = this->region_map->layoutHeight();
@@ -1179,23 +1220,21 @@ void RegionMapEditor::on_pushButton_CityMap_add_clicked() {
}
void RegionMapEditor::on_action_RegionMap_Resize_triggered() {
- // TODO: this whole feature
- /*
QDialog popup(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
- popup.setWindowTitle("New Region Map Dimensions");
+ popup.setWindowTitle("New Tilemap Dimensions");
popup.setWindowModality(Qt::NonModal);
QFormLayout form(&popup);
- QSpinBox *widthSpinBox = new QSpinBox();
- QSpinBox *heightSpinBox = new QSpinBox();
- widthSpinBox->setMinimum(32);
- heightSpinBox->setMinimum(20);
- widthSpinBox->setMaximum(128);// TODO: find real limits... 128
+ // TODO: limits do not go smaller than layout
+ QSpinBox *widthSpinBox = new QSpinBox;
+ QSpinBox *heightSpinBox = new QSpinBox;
+ widthSpinBox->setMinimum(16);
+ heightSpinBox->setMinimum(16);
+ widthSpinBox->setMaximum(128);
heightSpinBox->setMaximum(128);
- // TODO width, height
- widthSpinBox->setValue(this->region_map->width());
- heightSpinBox->setValue(this->region_map->height());
+ widthSpinBox->setValue(this->region_map->tilemapWidth());
+ heightSpinBox->setValue(this->region_map->tilemapHeight());
form.addRow(new QLabel("Width"), widthSpinBox);
form.addRow(new QLabel("Height"), heightSpinBox);
@@ -1206,24 +1245,25 @@ void RegionMapEditor::on_action_RegionMap_Resize_triggered() {
connect(&buttonBox, &QDialogButtonBox::accepted, &popup, &QDialog::accept);
if (popup.exec() == QDialog::Accepted) {
- resize(widthSpinBox->value(), heightSpinBox->value());
- RegionMapHistoryItem *commit = new RegionMapHistoryItem(
- RegionMapEditorBox::BackgroundImage, this->region_map->getTiles(), widthSpinBox->value(), heightSpinBox->value()
- );
- history.push(commit);
+ resizeTilemap(widthSpinBox->value(), heightSpinBox->value());
}
-
- this->hasUnsavedChanges = true;
- */
return;
}
-void RegionMapEditor::resize(int w, int h) {
- this->region_map->resize(w, h);
- this->currIndex = this->region_map->padLeft() * w + this->region_map->padTop();
- displayRegionMapImage();
- displayRegionMapLayout();
- displayRegionMapLayoutOptions();
+void RegionMapEditor::resizeTilemap(int width, int height) {
+ QByteArray oldTilemap = this->region_map->getTilemap();
+ int oldWidth = this->region_map->tilemapWidth();
+ int oldHeight = this->region_map->tilemapHeight();
+ this->region_map->resizeTilemap(width, height);
+ QByteArray newTilemap = this->region_map->getTilemap();
+ int newWidth = this->region_map->tilemapWidth();
+ int newHeight = this->region_map->tilemapHeight();
+ ResizeTilemap *commit = new ResizeTilemap(this->region_map, oldTilemap, newTilemap, oldWidth, oldHeight, newWidth, newHeight);
+ this->region_map->editHistory.push(commit);
+ this->currIndex = this->region_map->padLeft() * width + this->region_map->padTop();
+ //displayRegionMapImage();
+ //displayRegionMapLayout();
+ //displayRegionMapLayoutOptions();
}
void RegionMapEditor::on_action_Swap_triggered() {
diff --git a/src/ui/regionmappixmapitem.cpp b/src/ui/regionmappixmapitem.cpp
index ba1cdcc9..a93e271a 100644
--- a/src/ui/regionmappixmapitem.cpp
+++ b/src/ui/regionmappixmapitem.cpp
@@ -1,8 +1,6 @@
#include "regionmappixmapitem.h"
#include "regionmapeditcommands.h"
-static unsigned actionId_ = 0;
-
void RegionMapPixmapItem::draw() {
if (!region_map) return;
@@ -23,25 +21,17 @@ void RegionMapPixmapItem::draw() {
void RegionMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
if (region_map) {
- if (event->type() == QEvent::GraphicsSceneMouseRelease) {
- actionId_++;
- } else {
- QPointF pos = event->pos();
- int x = static_cast(pos.x()) / 8;
- int y = static_cast(pos.y()) / 8;
- int index = x + y * region_map->tilemapWidth();
- QByteArray oldTilemap = this->region_map->getTilemap();
- this->region_map->setTileData(index,
- this->tile_selector->selectedTile,
- this->tile_selector->tile_hFlip,
- this->tile_selector->tile_vFlip,
- this->tile_selector->tile_palette
- );
- QByteArray newTilemap = this->region_map->getTilemap();
- EditTilemap *command = new EditTilemap(this->region_map, oldTilemap, newTilemap, actionId_);
- this->region_map->commit(command);
- draw();
- }
+ QPointF pos = event->pos();
+ int x = static_cast(pos.x()) / 8;
+ int y = static_cast(pos.y()) / 8;
+ int index = x + y * region_map->tilemapWidth();
+ this->region_map->setTileData(index,
+ this->tile_selector->selectedTile,
+ this->tile_selector->tile_hFlip,
+ this->tile_selector->tile_vFlip,
+ this->tile_selector->tile_palette
+ );
+ draw();
}
}
diff --git a/src/ui/regionmappropertiesdialog.cpp b/src/ui/regionmappropertiesdialog.cpp
index 36078a07..99c3ef93 100644
--- a/src/ui/regionmappropertiesdialog.cpp
+++ b/src/ui/regionmappropertiesdialog.cpp
@@ -17,8 +17,6 @@ RegionMapPropertiesDialog::~RegionMapPropertiesDialog()
void RegionMapPropertiesDialog::hideMessages() {
ui->message_alias->setVisible(false);
- ui->message_width->setVisible(false);
- ui->message_height->setVisible(false);
ui->message_tilemapFormat->setVisible(false);
ui->message_tilemapWidth->setVisible(false);
ui->message_tilemapHeight->setVisible(false);
@@ -48,8 +46,6 @@ void RegionMapPropertiesDialog::setProperties(poryjson::Json json) {
// Region Map Properties
ui->config_alias->setText(object["alias"].string_value());
- ui->config_width->setValue(object["width"].int_value());
- ui->config_height->setValue(object["height"].int_value());
// Tilemap properties
poryjson::Json::object tilemap = object["tilemap"].object_items();
@@ -82,8 +78,6 @@ poryjson::Json RegionMapPropertiesDialog::saveToJson() {
// TODO: make sure next comment is not a lie
// data should already be verified and valid at this point
config["alias"] = ui->config_alias->text();
- config["width"] = ui->config_width->value();
- config["height"] = ui->config_height->value();
poryjson::Json::object tilemapObject;
tilemapObject["width"] = ui->config_tilemapWidth->value();