code cleanup: finish rme update core

This commit is contained in:
garak 2022-04-28 21:42:47 -04:00 committed by garakmon
parent aeb56e579c
commit c76f6a8049
6 changed files with 66 additions and 300 deletions

View file

@ -62,8 +62,6 @@ public:
void save();
void saveTilemap();
void saveLayout();
void saveConfig();// ? or do this in the editor only?
void saveOptions(int id, QString sec, QString name, int x, int y);
void resizeTilemap(int width, int height, bool update = true);
void resetSquare(int index);
@ -93,12 +91,8 @@ public:
QString palPath();
QString pngPath();
QString cityTilesPath();
QString entriesPath() { return this->entries_path; }
QVector<uint8_t> getTiles();
void setTiles(QVector<uint8_t> tileIds);
QByteArray getTilemap();
void setTilemap(QByteArray newTilemap);
@ -181,7 +175,6 @@ private:
bool layout_uses_layers = false;
QStringList layout_constants;
QString layout_qualifiers;
QString layout_type;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QVector<shared_ptr<TilemapTile>> tilemap;

View file

@ -345,7 +345,7 @@ private:
QPointer<RegionMapEditor> regionMapEditor = nullptr;
QPointer<ShortcutsEditor> shortcutsEditor = nullptr;
QPointer<MapImageExporter> mapImageExporter = nullptr;
QPointer<NewMapPopup> newmapprompt = nullptr;
QPointer<NewMapPopup> newMapPrompt = nullptr;
QPointer<PreferenceEditor> preferenceEditor = nullptr;
FilterChildrenProxyModel *mapListProxyModel;
QStandardItemModel *mapListModel;

View file

@ -30,10 +30,8 @@ public:
tsl::ordered_map<QString, RegionMap *> region_maps;
bool load();
bool loadCityMaps();
void onRegionMapTileSelectorSelectedTileChanged(unsigned id);
void onCityMapTileSelectorSelectedTileChanged(unsigned id);
void onRegionMapTileSelectorHoveredTileChanged(unsigned id);
void onRegionMapTileSelectorHoveredTileCleared();
@ -64,7 +62,6 @@ private:
unsigned selectedImageTile;
QString activeEntry;
bool hasUnsavedChanges = false;
bool cityMapFirstDraw = true;
bool regionMapFirstDraw = true;
bool entriesFirstDraw = true;
@ -95,7 +92,6 @@ private:
bool buildConfigDialog();
poryjson::Json configRegionMapDialog();
void buildUpdateConfigDialog();
poryjson::Json buildDefaultJson();
bool verifyConfig(poryjson::Json cfg);
@ -110,14 +106,10 @@ private:
void updateRegionMapLayoutOptions(int index);
void displayRegionMapTileSelector();
void updateLayerDisplayed();
void displayCityMapTileSelector();
void displayCityMap(QString name);
void displayRegionMapEntryOptions();
void updateRegionMapEntryOptions(QString);
void setRegionMap(RegionMap *map);
bool createCityMap(QString name);
void restoreWindowState();
void closeEvent(QCloseEvent* event);
@ -144,15 +136,12 @@ private slots:
void on_spinBox_tilePalette_valueChanged(int);
void on_checkBox_tileHFlip_stateChanged(int);
void on_checkBox_tileVFlip_stateChanged(int);
void on_pushButton_CityMap_add_clicked();
void on_verticalSlider_Zoom_Map_Image_valueChanged(int);
void on_verticalSlider_Zoom_Image_Tiles_valueChanged(int);
void on_comboBox_CityMap_picker_currentTextChanged(const QString &);
void on_lineEdit_RM_MapName_textEdited(const QString &);
void onHoveredRegionMapTileChanged(int x, int y);
void onHoveredRegionMapTileCleared();
void mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPixmapItem *item);
void mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item);
};
#endif // REGIONMAPEDITOR_H

View file

@ -100,7 +100,6 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
return true;
}
// TODO: reset other values here
this->layout_constants.clear();
poryjson::Json::object layoutObject = layoutJson.object_items();
@ -121,7 +120,7 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
switch (this->layout_format) {
case LayoutFormat::Binary:
{
// TODO: only one layer supported for binary layouts (change or no?)
// only one layer supported for binary layouts
QFile binFile(fullPath(this->layout_path));
if (!binFile.open(QIODevice::ReadOnly)) {
logError(QString("Failed to read region map layout binary file %1").arg(this->layout_path));
@ -168,7 +167,6 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
// check for layers, extract info
QRegularExpressionMatch match = re.match(text);
if (match.hasMatch()) {
// TODO: keep track of labels and consts
QString qualifiers = match.captured("qual_1") + " " + match.captured("qual_2");
QString type = match.captured("type");
QString label = match.captured("label");
@ -203,7 +201,6 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
int x = 0;
for (QString section : rowSections) {
QString square_section_name = section.trimmed();
int square_index = get_tilemap_index(x, y);
LayoutSquare square;
square.map_section = square_section_name;
@ -223,14 +220,12 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
QRegularExpression reAlt("(?<qual_1>static)?\\s?(?<qual_2>const)?\\s?(?<type>[A-Za-z0-9_]+)?\\s+(?<label>[A-Za-z0-9_]+)\\[\\]");
QRegularExpressionMatch matchAlt = reAlt.match(text);
if (matchAlt.hasMatch()) {
// TODO: save type info
QString qualifiers = matchAlt.captured("qual_1") + " " + matchAlt.captured("qual_2");
QString type = matchAlt.captured("type");
QString label = matchAlt.captured("label");
this->layout_constants.append("");
this->layout_qualifiers = qualifiers + " " + type;
this->layout_array_label = label;
this->layout_type = type;
QRegularExpression reSec("(?<sec>MAPSEC_[A-Za-z0-9_]+)");
QRegularExpressionMatchIterator k = reSec.globalMatch(text);
@ -262,6 +257,9 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
}
break;
}
case LayoutFormat::None:
default:
break;
}
this->current_layer = this->layout_layers.first();
@ -273,12 +271,10 @@ void RegionMap::commit(QUndoCommand *command) {
}
void RegionMap::undo() {
//
editHistory.undo();
}
void RegionMap::redo() {
//
editHistory.redo();
}
@ -388,14 +384,12 @@ void RegionMap::saveLayout() {
this->project->saveTextFile(fullPath(this->layout_path), text);
break;
}
case LayoutFormat::None:
default:
break;
}
}
void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) {
// TODO
}
void RegionMap::resetSquare(int index) {
this->layouts[this->current_layer][index].map_section = "MAPSEC_NONE";
this->layouts[this->current_layer][index].has_map = false;
@ -546,16 +540,14 @@ void RegionMap::setAllLayouts(QMap<QString, QList<LayoutSquare>> newLayouts) {
}
void RegionMap::setLayoutDimensions(int width, int height, bool update) {
// for each layer!
// for each layer
if (update) {
for (QString layer : this->layout_layers) {
//
QList<LayoutSquare> oldLayout = this->getLayout(layer);
QList<LayoutSquare> newLayout;
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++) {
//
LayoutSquare newSquare;
if (x < this->layout_width && y < this->layout_height) {
// within old layout
@ -570,21 +562,6 @@ void RegionMap::setLayoutDimensions(int width, int height, bool update) {
this->layout_width = width;
this->layout_height = height;
// TODO: commit
}
QVector<uint8_t> RegionMap::getTiles() {
QVector<uint8_t> tileIds;
// unused? remove when redo history is fully transitioned
// TODO: change this to use TilemapTile instead of uint8_t
return tileIds;
}
void RegionMap::setTiles(QVector<uint8_t> tileIds) {
// TODO
}
// Layout coords to image index.
@ -712,12 +689,6 @@ QString RegionMap::pngPath() {
return this->project->root + "/" + this->tileset_path;
}
QString RegionMap::cityTilesPath() {
// TODO
return QString();
}
// From x, y of image.
int RegionMap::getMapSquareIndex(int x, int y) {
int index = (x + y * this->tilemap_width);

View file

@ -1166,11 +1166,11 @@ void MainWindow::onAddNewMapToLayoutClick(QAction* triggeredAction)
}
void MainWindow::onNewMapCreated() {
QString newMapName = this->newmapprompt->map->name;
int newMapGroup = this->newmapprompt->group;
Map *newMap = this->newmapprompt->map;
bool existingLayout = this->newmapprompt->existingLayout;
bool importedMap = this->newmapprompt->importedMap;
QString newMapName = this->newMapPrompt->map->name;
int newMapGroup = this->newMapPrompt->group;
Map *newMap = this->newMapPrompt->map;
bool existingLayout = this->newMapPrompt->existingLayout;
bool importedMap = this->newMapPrompt->importedMap;
newMap = editor->project->addNewMapToGroup(newMapName, newMapGroup, newMap, existingLayout, importedMap);
@ -1195,52 +1195,52 @@ void MainWindow::onNewMapCreated() {
editor->save();// required
}
disconnect(this->newmapprompt, &NewMapPopup::applied, this, &MainWindow::onNewMapCreated);
disconnect(this->newMapPrompt, &NewMapPopup::applied, this, &MainWindow::onNewMapCreated);
delete newMap;
}
void MainWindow::openNewMapPopupWindow(int type, QVariant data) {
if (!this->newmapprompt) {
this->newmapprompt = new NewMapPopup(this, this->editor->project);
if (!this->newMapPrompt) {
this->newMapPrompt = new NewMapPopup(this, this->editor->project);
}
if (!this->newmapprompt->isVisible()) {
this->newmapprompt->show();
if (!this->newMapPrompt->isVisible()) {
this->newMapPrompt->show();
} else {
this->newmapprompt->raise();
this->newmapprompt->activateWindow();
this->newMapPrompt->raise();
this->newMapPrompt->activateWindow();
}
switch (type)
{
case MapSortOrder::Group:
this->newmapprompt->init(type, data.toInt(), QString(), QString());
this->newMapPrompt->init(type, data.toInt(), QString(), QString());
break;
case MapSortOrder::Area:
this->newmapprompt->init(type, 0, data.toString(), QString());
this->newMapPrompt->init(type, 0, data.toString(), QString());
break;
case MapSortOrder::Layout:
this->newmapprompt->init(type, 0, QString(), data.toString());
this->newMapPrompt->init(type, 0, QString(), data.toString());
break;
}
connect(this->newmapprompt, &NewMapPopup::applied, this, &MainWindow::onNewMapCreated);
this->newmapprompt->setAttribute(Qt::WA_DeleteOnClose);
connect(this->newMapPrompt, &NewMapPopup::applied, this, &MainWindow::onNewMapCreated);
this->newMapPrompt->setAttribute(Qt::WA_DeleteOnClose);
}
void MainWindow::openNewMapPopupWindowImportMap(MapLayout *mapLayout) {
if (!this->newmapprompt) {
this->newmapprompt = new NewMapPopup(this, this->editor->project);
if (!this->newMapPrompt) {
this->newMapPrompt = new NewMapPopup(this, this->editor->project);
}
if (!this->newmapprompt->isVisible()) {
this->newmapprompt->show();
if (!this->newMapPrompt->isVisible()) {
this->newMapPrompt->show();
} else {
this->newmapprompt->raise();
this->newmapprompt->activateWindow();
this->newMapPrompt->raise();
this->newMapPrompt->activateWindow();
}
this->newmapprompt->initImportMap(mapLayout);
this->newMapPrompt->initImportMap(mapLayout);
connect(this->newmapprompt, SIGNAL(applied()), this, SLOT(onNewMapCreated()));
connect(this->newmapprompt, &QObject::destroyed, [=](QObject *) { this->newmapprompt = nullptr; });
this->newmapprompt->setAttribute(Qt::WA_DeleteOnClose);
connect(this->newMapPrompt, SIGNAL(applied()), this, SLOT(onNewMapCreated()));
connect(this->newMapPrompt, &QObject::destroyed, [=](QObject *) { this->newMapPrompt = nullptr; });
this->newMapPrompt->setAttribute(Qt::WA_DeleteOnClose);
}
void MainWindow::on_action_NewMap_triggered() {
@ -3164,16 +3164,26 @@ bool MainWindow::initRegionMapEditor() {
}
void MainWindow::closeSupplementaryWindows() {
if (this->tilesetEditor)
if (this->tilesetEditor) {
delete this->tilesetEditor;
if (this->regionMapEditor)
this->tilesetEditor = nullptr;
}
if (this->regionMapEditor) {
delete this->regionMapEditor;
if (this->mapImageExporter)
this->regionMapEditor = nullptr;
}
if (this->mapImageExporter) {
delete this->mapImageExporter;
if (this->newmapprompt)
delete this->newmapprompt;
if (this->shortcutsEditor)
this->mapImageExporter = nullptr;
}
if (this->newMapPrompt) {
delete this->newMapPrompt;
this->newMapPrompt = nullptr;
}
if (this->shortcutsEditor) {
delete this->shortcutsEditor;
this->shortcutsEditor = nullptr;
}
}
void MainWindow::closeEvent(QCloseEvent *event) {

View file

@ -135,6 +135,8 @@ bool RegionMapEditor::loadRegionMapEntries() {
entry.valid = true;
this->region_map_entries[entryMapSection] = entry;
}
return true;
}
bool RegionMapEditor::saveRegionMapEntries() {
@ -236,7 +238,7 @@ bool RegionMapEditor::buildConfigDialog() {
// lambda to update the current map list displayed in the config window with a
// widget item that contains that region map's json data
auto updateMapList = [this, regionMapList, &rmConfigJsonUpdate]() {
auto updateMapList = [regionMapList, &rmConfigJsonUpdate]() {
regionMapList->clear();
poryjson::Json::object mapsObject = rmConfigJsonUpdate.object_items();
for (auto o : mapsObject["region_maps"].array_items()) {
@ -276,8 +278,6 @@ bool RegionMapEditor::buildConfigDialog() {
rmConfigJsonUpdate = poryjson::Json(previousObj);
updateMapList();
} else {
// TODO: anything?
}
});
@ -289,8 +289,6 @@ bool RegionMapEditor::buildConfigDialog() {
poryjson::Json resultJson = configRegionMapDialog();
poryjson::Json::object resultObj = resultJson.object_items();
// TODO: check duplicate alias? other error-checking
QString resultStr;
int tab = 0;
resultJson.dump(resultStr, &tab);
@ -372,11 +370,6 @@ poryjson::Json RegionMapEditor::configRegionMapDialog() {
return poryjson::Json();
}
void RegionMapEditor::buildUpdateConfigDialog() {
// unused
// TODO: get rid of this function
}
bool RegionMapEditor::verifyConfig(poryjson::Json cfg) {
OrderedJson::object obj = cfg.object_items();
@ -479,7 +472,6 @@ bool RegionMapEditor::load() {
}
void RegionMapEditor::setRegionMap(RegionMap *map) {
//
this->region_map = map;
this->currIndex = this->region_map->firstLayoutIndex();
this->region_map->editHistory.setActive();
@ -497,13 +489,6 @@ void RegionMapEditor::setRegionMap(RegionMap *map) {
displayRegionMap();
}
bool RegionMapEditor::loadCityMaps() {
// unused
// TODO
return false;
}
bool RegionMapEditor::saveRegionMap(RegionMap *map) {
if (!map) return false;
@ -542,8 +527,6 @@ void RegionMapEditor::on_action_RegionMap_Save_triggered() {
// save config
saveConfig();
this->hasUnsavedChanges = false;
}
void RegionMapEditor::on_actionSave_All_triggered() {
@ -552,14 +535,10 @@ void RegionMapEditor::on_actionSave_All_triggered() {
}
saveRegionMapEntries();
saveConfig();
this->hasUnsavedChanges = false;
}
void RegionMapEditor::displayRegionMap() {
displayRegionMapTileSelector();
//< displayCityMapTileSelector();
displayRegionMapImage();
displayRegionMapLayout();
displayRegionMapLayoutOptions();
@ -567,8 +546,6 @@ void RegionMapEditor::displayRegionMap() {
displayRegionMapEntryOptions();
updateLayerDisplayed();
this->hasUnsavedChanges = false;
}
void RegionMapEditor::updateLayerDisplayed() {
@ -640,8 +617,10 @@ void RegionMapEditor::displayRegionMapLayout() {
void RegionMapEditor::displayRegionMapLayoutOptions() {
if (!this->region_map->layoutEnabled()) return;
this->ui->comboBox_RM_ConnectedMap->blockSignals(true);
this->ui->comboBox_RM_ConnectedMap->clear();
this->ui->comboBox_RM_ConnectedMap->addItems(this->project->mapSectionValueToName.values());
this->ui->comboBox_RM_ConnectedMap->blockSignals(false);
this->ui->frame_RM_Options->setEnabled(true);
@ -811,101 +790,10 @@ void RegionMapEditor::displayRegionMapTileSelector() {
this->mapsquare_selector_item->select(this->selectedImageTile);
}
void RegionMapEditor::displayCityMapTileSelector() {
return;
/*
if (!scene_city_map_tiles) {
this->scene_city_map_tiles = new QGraphicsScene;
}
if (city_map_selector_item && scene_city_map_tiles) {
scene_city_map_tiles->removeItem(city_map_selector_item);
delete city_map_selector_item;
}
this->city_map_selector_item = new TilemapTileSelector(QPixmap(this->region_map->cityTilesPath()));
this->city_map_selector_item->draw();
this->scene_city_map_tiles->addItem(this->city_map_selector_item);
connect(this->city_map_selector_item, &TilemapTileSelector::selectedTileChanged,
this, &RegionMapEditor::onCityMapTileSelectorSelectedTileChanged);
this->ui->graphicsView_City_Map_Tiles->setScene(this->scene_city_map_tiles);
on_verticalSlider_Zoom_City_Tiles_valueChanged(this->ui->verticalSlider_Zoom_City_Tiles->value());
this->city_map_selector_item->select(this->selectedCityTile);
*/
}
void RegionMapEditor::displayCityMap(QString f) {
return;
/*
QString file = this->project->root + "/graphics/pokenav/city_maps/" + f + ".bin";
if (!scene_city_map_image) {
scene_city_map_image = new QGraphicsScene;
}
if (city_map_item && scene_city_map_image) {
scene_city_map_image->removeItem(city_map_item);
delete city_map_item;
}
city_map_item = new CityMapPixmapItem(file, this->city_map_selector_item);
city_map_item->draw();
connect(this->city_map_item, &CityMapPixmapItem::mouseEvent,
this, &RegionMapEditor::mouseEvent_city_map);
scene_city_map_image->addItem(city_map_item);
scene_city_map_image->setSceneRect(this->scene_city_map_image->sceneRect());
this->ui->graphicsView_City_Map->setScene(scene_city_map_image);
on_verticalSlider_Zoom_City_Map_valueChanged(this->ui->verticalSlider_Zoom_City_Map->value());
*/
}
bool RegionMapEditor::createCityMap(QString name) {
return false;
/*
bool errored = false;
QString file = this->project->root + "/graphics/pokenav/city_maps/" + name + ".bin";
uint8_t filler = 0x30;
uint8_t border = 0x7;
uint8_t blank = 0x1;
QByteArray new_data(400, filler);
for (int i = 0; i < new_data.size(); i++) {
if (i % 2) continue;
int x = i % 20;
int y = i / 20;
if (y <= 1 || y >= 8 || x <= 3 || x >= 16)
new_data[i] = border;
else
new_data[i] = blank;
}
QFile binFile(file);
if (!binFile.open(QIODevice::WriteOnly)) errored = true;
binFile.write(new_data);
binFile.close();
loadCityMaps();
this->ui->comboBox_CityMap_picker->setCurrentText(name);
return !errored;
*/
}
void RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged(unsigned id) {
this->selectedImageTile = id;
}
void RegionMapEditor::onCityMapTileSelectorSelectedTileChanged(unsigned id) {
// TODO
//< this->selectedCityTile = id;
}
void RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged(unsigned tileId) {
QString message = QString("Tile: 0x") + QString("%1").arg(tileId, 4, 16, QChar('0')).toUpper();
this->ui->statusbar->showMessage(message);
@ -985,43 +873,10 @@ void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, Reg
EditTilemap *command = new EditTilemap(this->region_map, oldTilemap, newTilemap, actionId_);
this->region_map->commit(command);
//this->region_map_layout_item->draw();
this->hasUnsavedChanges = true;
}
}
}
void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item) {
return;
//< TODO: city maps
/*
if (cityMapFirstDraw) {
RegionMapHistoryItem *commit = new RegionMapHistoryItem(
RegionMapEditorBox::CityMapImage, this->city_map_item->getTiles(), this->city_map_item->file
);
history.push(commit);
cityMapFirstDraw = false;
}
if (event->buttons() & Qt::RightButton) {// TODO
//} else if (event->buttons() & Qt::MiddleButton) {// TODO
} else {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
RegionMapHistoryItem *current = history.current();
bool addToHistory = !(current && current->tiles == this->city_map_item->getTiles());
if (addToHistory) {
RegionMapHistoryItem *commit = new RegionMapHistoryItem(
RegionMapEditorBox::CityMapImage, this->city_map_item->getTiles(), this->city_map_item->file
);
history.push(commit);
}
} else {
item->paint(event);
this->hasUnsavedChanges = true;
}
}
//*/
}
void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) {
this->ui->stackedWidget_RM_Options->setCurrentIndex(index);
if (!this->region_map) return;
@ -1048,12 +903,7 @@ void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) {
void RegionMapEditor::on_comboBox_RM_ConnectedMap_textActivated(const QString &mapsec) {
QString layer = this->region_map->getLayer();
QList<LayoutSquare> oldLayout = this->region_map->getLayout(layer);
this->region_map->setSquareMapSection(this->currIndex, mapsec);
QList<LayoutSquare> newLayout = this->region_map->getLayout(layer);
EditLayout *command = new EditLayout(this->region_map, layer, this->currIndex, oldLayout, newLayout);
this->region_map->commit(command);
onRegionMapLayoutSelectedTileChanged(this->currIndex);// re-draw layout image
}
@ -1093,7 +943,6 @@ void RegionMapEditor::on_spinBox_RM_Entry_x_valueChanged(int x) {
this->region_map_entries_item->select(idx);
this->region_map_entries_item->draw();
this->ui->spinBox_RM_Entry_width->setMaximum(this->region_map->tilemapWidth() - this->region_map->padLeft() - this->region_map->padRight() - x);
this->hasUnsavedChanges = true;
}
void RegionMapEditor::on_spinBox_RM_Entry_y_valueChanged(int y) {
@ -1108,7 +957,6 @@ void RegionMapEditor::on_spinBox_RM_Entry_y_valueChanged(int y) {
this->region_map_entries_item->select(idx);
this->region_map_entries_item->draw();
this->ui->spinBox_RM_Entry_height->setMaximum(this->region_map->tilemapHeight() - this->region_map->padTop() - this->region_map->padBottom() - y);
this->hasUnsavedChanges = true;
}
void RegionMapEditor::on_spinBox_RM_Entry_width_valueChanged(int width) {
@ -1119,7 +967,6 @@ void RegionMapEditor::on_spinBox_RM_Entry_width_valueChanged(int width) {
EditEntry *commit = new EditEntry(this->region_map, activeEntry, oldEntry, newEntry);
this->region_map->editHistory.push(commit);
this->region_map_entries_item->draw();
this->hasUnsavedChanges = true;
}
void RegionMapEditor::on_spinBox_RM_Entry_height_valueChanged(int height) {
@ -1130,7 +977,6 @@ void RegionMapEditor::on_spinBox_RM_Entry_height_valueChanged(int height) {
EditEntry *commit = new EditEntry(this->region_map, activeEntry, oldEntry, newEntry);
this->region_map->editHistory.push(commit);
this->region_map_entries_item->draw();
this->hasUnsavedChanges = true;
}
void RegionMapEditor::on_spinBox_RM_LayoutWidth_valueChanged(int value) {
@ -1139,7 +985,7 @@ void RegionMapEditor::on_spinBox_RM_LayoutWidth_valueChanged(int value) {
int oldHeight = this->region_map->layoutHeight();
QMap<QString, QList<LayoutSquare>> oldLayouts = this->region_map->getAllLayouts();
this->region_map->setLayoutDimensions(this->ui->spinBox_RM_LayoutWidth->value(), this->ui->spinBox_RM_LayoutHeight->value());
this->region_map->setLayoutDimensions(value, this->ui->spinBox_RM_LayoutHeight->value());
int newWidth = this->region_map->layoutWidth();
int newHeight = this->region_map->layoutHeight();
@ -1151,13 +997,12 @@ void RegionMapEditor::on_spinBox_RM_LayoutWidth_valueChanged(int value) {
}
void RegionMapEditor::on_spinBox_RM_LayoutHeight_valueChanged(int value) {
//
if (this->region_map) {
int oldWidth = this->region_map->layoutWidth();
int oldHeight = this->region_map->layoutHeight();
QMap<QString, QList<LayoutSquare>> oldLayouts = this->region_map->getAllLayouts();
this->region_map->setLayoutDimensions(this->ui->spinBox_RM_LayoutWidth->value(), this->ui->spinBox_RM_LayoutHeight->value());
this->region_map->setLayoutDimensions(this->ui->spinBox_RM_LayoutWidth->value(), value);
int newWidth = this->region_map->layoutWidth();
int newHeight = this->region_map->layoutHeight();
@ -1170,8 +1015,11 @@ void RegionMapEditor::on_spinBox_RM_LayoutHeight_valueChanged(int value) {
void RegionMapEditor::on_lineEdit_RM_MapName_textEdited(const QString &text) {
if (!this->region_map_entries.contains(activeEntry)) return;
this->region_map_entries[this->ui->comboBox_RM_Entry_MapSection->currentText()].name = text;
this->hasUnsavedChanges = true;
MapSectionEntry oldEntry = this->region_map_entries[activeEntry];
this->region_map_entries[activeEntry].name = text;
MapSectionEntry newEntry = this->region_map_entries[activeEntry];
EditEntry *commit = new EditEntry(this->region_map, activeEntry, oldEntry, newEntry);
this->region_map->editHistory.push(commit);
}
void RegionMapEditor::on_pushButton_RM_Options_delete_clicked() {
@ -1188,7 +1036,6 @@ void RegionMapEditor::on_pushButton_RM_Options_delete_clicked() {
// ^ this line necessary?
}
// TODO: check value bounds for current palette?
void RegionMapEditor::on_spinBox_tilePalette_valueChanged(int value) {
this->mapsquare_selector_item->selectPalette(value);
}
@ -1201,40 +1048,6 @@ void RegionMapEditor::on_checkBox_tileVFlip_stateChanged(int state) {
this->mapsquare_selector_item->selectVFlip(state == Qt::Checked);
}
void RegionMapEditor::on_pushButton_CityMap_add_clicked() {
return;
//< TODO: city maps
/*
QDialog popup(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
popup.setWindowTitle("New City Map");
popup.setWindowModality(Qt::NonModal);
QFormLayout form(&popup);
QLineEdit *input = new QLineEdit();
input->setClearButtonEnabled(true);
form.addRow(new QLabel("Name:"), input);
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &popup);
QString name;
form.addRow(&buttonBox);
connect(&buttonBox, &QDialogButtonBox::rejected, &popup, &QDialog::reject);
connect(&buttonBox, &QDialogButtonBox::accepted, [&popup, &input, &name](){
name = input->text().remove(QRegularExpression("[^a-zA-Z0-9_]+"));
if (!name.isEmpty())
popup.accept();
});
if (popup.exec() == QDialog::Accepted) {
createCityMap(name);
}
this->hasUnsavedChanges = true;
//*/
}
void RegionMapEditor::on_action_RegionMap_Resize_triggered() {
QDialog popup(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
popup.setWindowTitle("New Tilemap Dimensions");
@ -1277,9 +1090,6 @@ void RegionMapEditor::resizeTilemap(int width, int height) {
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() {
@ -1301,7 +1111,7 @@ void RegionMapEditor::on_action_Swap_triggered() {
QString beforeSection, afterSection;
connect(&buttonBox, &QDialogButtonBox::rejected, &popup, &QDialog::reject);
connect(&buttonBox, &QDialogButtonBox::accepted, [this, &popup, &oldSecBox, &newSecBox, &beforeSection, &afterSection](){
connect(&buttonBox, &QDialogButtonBox::accepted, [&popup, &oldSecBox, &newSecBox, &beforeSection, &afterSection](){
beforeSection = oldSecBox->currentText();
afterSection = newSecBox->currentText();
if (!beforeSection.isEmpty() && !afterSection.isEmpty()) {
@ -1318,7 +1128,6 @@ void RegionMapEditor::on_action_Swap_triggered() {
this->region_map->editHistory.push(commit);
displayRegionMapLayout();
this->region_map_layout_item->select(this->region_map_layout_item->selectedTile);
this->hasUnsavedChanges = true;
}
}
@ -1357,14 +1166,8 @@ void RegionMapEditor::on_action_RegionMap_ClearLayout_triggered() {
}
}
void RegionMapEditor::on_comboBox_CityMap_picker_currentTextChanged(const QString &file) {
//< TODO: city maps
//< this->displayCityMap(file);
//< this->cityMapFirstDraw = true;
}
bool RegionMapEditor::modified() {
return this->hasUnsavedChanges || !this->history.isClean();
return !this->history.isClean();
}
void RegionMapEditor::closeEvent(QCloseEvent *event)