mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-27 02:16:34 -05:00
add/remove map section entry in region map editor
This commit is contained in:
@@ -587,6 +587,10 @@ void RegionMap::setEntry(QString section, MapSectionEntry entry) {
|
||||
this->region_map_entries->operator[](section) = entry;
|
||||
}
|
||||
|
||||
void RegionMap::removeEntry(QString section) {
|
||||
this->region_map_entries->erase(section);
|
||||
}
|
||||
|
||||
QString RegionMap::palPath() {
|
||||
return this->palette_path.isEmpty() ? QString() : this->project->root + "/" + this->palette_path;
|
||||
}
|
||||
|
||||
228
src/core/regionmapeditcommands.cpp
Normal file
228
src/core/regionmapeditcommands.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
#include "regionmapeditcommands.h"
|
||||
|
||||
|
||||
|
||||
EditTilemap::EditTilemap(RegionMap *map, QByteArray oldTilemap, QByteArray newTilemap, unsigned actionId, QUndoCommand *parent)
|
||||
: QUndoCommand(parent) {
|
||||
setText("Edit Tilemap");
|
||||
|
||||
this->map = map;
|
||||
this->oldTilemap = oldTilemap;
|
||||
this->newTilemap = newTilemap;
|
||||
this->actionId = actionId;
|
||||
}
|
||||
|
||||
void EditTilemap::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
|
||||
map->setTilemap(this->newTilemap);
|
||||
}
|
||||
|
||||
void EditTilemap::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->setTilemap(this->oldTilemap);
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
bool EditTilemap::mergeWith(const QUndoCommand *command) {
|
||||
const EditTilemap *other = static_cast<const EditTilemap *>(command);
|
||||
|
||||
if (this->map != other->map)
|
||||
return false;
|
||||
|
||||
if (this->actionId != other->actionId)
|
||||
return false;
|
||||
|
||||
newTilemap = other->newTilemap;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
EditLayout::EditLayout(RegionMap *map, QString layer, int index, QList<LayoutSquare> oldLayout, QList<LayoutSquare> newLayout, QUndoCommand *parent)
|
||||
: QUndoCommand(parent) {
|
||||
setText("Edit Layout");
|
||||
|
||||
this->map = map;
|
||||
this->layer = layer;
|
||||
this->index = index;
|
||||
this->oldLayout = oldLayout;
|
||||
this->newLayout = newLayout;
|
||||
}
|
||||
|
||||
void EditLayout::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
|
||||
map->setLayout(this->layer, this->newLayout);
|
||||
}
|
||||
|
||||
void EditLayout::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->setLayout(this->layer, this->oldLayout);
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
bool EditLayout::mergeWith(const QUndoCommand *command) {
|
||||
const EditLayout *other = static_cast<const EditLayout *>(command);
|
||||
|
||||
if (this->map != other->map)
|
||||
return false;
|
||||
|
||||
if (this->text() != other->text())
|
||||
return false;
|
||||
|
||||
if (this->index != other->index)
|
||||
return false;
|
||||
|
||||
this->newLayout = other->newLayout;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
ResizeLayout::ResizeLayout(RegionMap *map, int oldWidth, int oldHeight, int newWidth, int newHeight,
|
||||
QMap<QString, QList<LayoutSquare>> oldLayouts, QMap<QString, QList<LayoutSquare>> newLayouts, QUndoCommand *parent)
|
||||
: QUndoCommand(parent) {
|
||||
setText("Change Layout Dimensions");
|
||||
|
||||
this->map = map;
|
||||
this->oldWidth = oldWidth;
|
||||
this->oldHeight = oldHeight;
|
||||
this->newWidth = newWidth;
|
||||
this->newHeight = newHeight;
|
||||
this->oldLayouts = oldLayouts;
|
||||
this->newLayouts = newLayouts;
|
||||
}
|
||||
|
||||
void ResizeLayout::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
|
||||
map->setLayoutDimensions(newWidth, newHeight, false);
|
||||
map->setAllLayouts(this->newLayouts);
|
||||
}
|
||||
|
||||
void ResizeLayout::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->setLayoutDimensions(oldWidth, oldHeight, false);
|
||||
map->setAllLayouts(this->oldLayouts);
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
bool ResizeLayout::mergeWith(const QUndoCommand *command) {
|
||||
const ResizeLayout *other = static_cast<const ResizeLayout *>(command);
|
||||
|
||||
if (this->map != other->map)
|
||||
return false;
|
||||
|
||||
// always allow consecutive dimension changes to merge
|
||||
|
||||
this->newWidth = other->newWidth;
|
||||
this->newHeight = other->newHeight;
|
||||
this->newLayouts = other->newLayouts;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
EditEntry::EditEntry(RegionMap *map, QString section, MapSectionEntry oldEntry, MapSectionEntry newEntry, QUndoCommand *parent)
|
||||
: QUndoCommand(parent) {
|
||||
setText("Change Entry for " + section);
|
||||
|
||||
this->map = map;
|
||||
this->section = section;
|
||||
this->oldEntry = oldEntry;
|
||||
this->newEntry = newEntry;
|
||||
}
|
||||
|
||||
void EditEntry::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
|
||||
map->setEntry(section, newEntry);
|
||||
}
|
||||
|
||||
void EditEntry::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->setEntry(section, oldEntry);
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
bool EditEntry::mergeWith(const QUndoCommand *command) {
|
||||
const EditEntry *other = static_cast<const EditEntry *>(command);
|
||||
|
||||
if (this->map != other->map)
|
||||
return false;
|
||||
|
||||
if (this->section != other->section)
|
||||
return false;
|
||||
|
||||
this->newEntry = other->newEntry;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
AddEntry::AddEntry(RegionMap *map, QString section, MapSectionEntry oldEntry, MapSectionEntry newEntry, QUndoCommand *parent)
|
||||
: EditEntry(map, section, oldEntry, newEntry, parent) {
|
||||
setText("Add Entry for " + section);
|
||||
}
|
||||
|
||||
void AddEntry::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
|
||||
map->setEntry(section, newEntry);
|
||||
}
|
||||
|
||||
void AddEntry::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->removeEntry(section);
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
RemoveEntry::RemoveEntry(RegionMap *map, QString section, MapSectionEntry oldEntry, MapSectionEntry newEntry, QUndoCommand *parent)
|
||||
: EditEntry(map, section, oldEntry, newEntry, parent) {
|
||||
setText("Remove Entry for " + section);
|
||||
}
|
||||
|
||||
void RemoveEntry::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
|
||||
map->removeEntry(section);
|
||||
}
|
||||
|
||||
void RemoveEntry::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->setEntry(section, oldEntry);
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
|
||||
@@ -646,6 +646,7 @@ void RegionMapEditor::updateRegionMapEntryOptions(QString section) {
|
||||
this->ui->spinBox_RM_Entry_y->setEnabled(enabled);
|
||||
this->ui->spinBox_RM_Entry_width->setEnabled(enabled);
|
||||
this->ui->spinBox_RM_Entry_height->setEnabled(enabled);
|
||||
this->ui->pushButton_entryActivate->setText(enabled ? "Remove" : "Add");
|
||||
|
||||
this->ui->lineEdit_RM_MapName->blockSignals(true);
|
||||
this->ui->spinBox_RM_Entry_x->blockSignals(true);
|
||||
@@ -672,6 +673,35 @@ void RegionMapEditor::updateRegionMapEntryOptions(QString section) {
|
||||
this->ui->spinBox_RM_Entry_height->blockSignals(false);
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_pushButton_entryActivate_clicked() {
|
||||
QString section = this->ui->comboBox_RM_Entry_MapSection->currentText();
|
||||
if (section == "MAPSEC_NONE") return;
|
||||
|
||||
if (this->region_map_entries.contains(section)) {
|
||||
// disable
|
||||
MapSectionEntry oldEntry = this->region_map->getEntry(section);
|
||||
this->region_map->removeEntry(section);
|
||||
MapSectionEntry newEntry = this->region_map->getEntry(section);
|
||||
RemoveEntry *commit = new RemoveEntry(this->region_map, section, oldEntry, newEntry);
|
||||
this->region_map->editHistory.push(commit);
|
||||
updateRegionMapEntryOptions(section);
|
||||
|
||||
this->ui->pushButton_entryActivate->setText("Add");
|
||||
} else {
|
||||
// enable
|
||||
MapSectionEntry oldEntry = this->region_map->getEntry(section);
|
||||
MapSectionEntry entry = MapSectionEntry();
|
||||
entry.valid = true;
|
||||
this->region_map->setEntry(section, entry);
|
||||
MapSectionEntry newEntry = this->region_map->getEntry(section);
|
||||
AddEntry *commit = new AddEntry(this->region_map, section, oldEntry, newEntry);
|
||||
this->region_map->editHistory.push(commit);
|
||||
updateRegionMapEntryOptions(section);
|
||||
|
||||
this->ui->pushButton_entryActivate->setText("Remove");
|
||||
}
|
||||
}
|
||||
|
||||
void RegionMapEditor::displayRegionMapTileSelector() {
|
||||
if (!scene_region_map_tiles) {
|
||||
this->scene_region_map_tiles = new QGraphicsScene;
|
||||
|
||||
Reference in New Issue
Block a user