Fix crash on tileset save, bugs with map resizing

This commit is contained in:
GriffinR 2024-10-29 15:56:02 -04:00
parent 3bd5ddbf2f
commit 2ce5c3fcc5
6 changed files with 26 additions and 43 deletions

View file

@ -114,7 +114,6 @@ private:
signals:
void modified();
void mapDimensionsChanged(const QSize &size);
void mapNeedsRedrawing();
void openScriptRequested(QString label);
void connectionAdded(MapConnection*);
void connectionRemoved(MapConnection*);

View file

@ -185,8 +185,6 @@ private slots:
void onLayoutChanged(Layout *layout);
void onOpenConnectedMap(MapConnection*);
void onMapNeedsRedrawing();
void onLayoutNeedsRedrawing();
void onTilesetsSaved(QString, QString);
void openNewMapPopupWindow();
void onNewMapCreated();
@ -355,7 +353,6 @@ private:
bool userSetLayout(QString layoutId);
bool userSetMap(QString);
void redrawMapScene();
void redrawLayoutScene();
void refreshMapScene();
void setLayoutOnlyMode(bool layoutOnly);

View file

@ -486,6 +486,7 @@ int EventPaste::id() const {
************************************************************************
******************************************************************************/
// TODO: Undo/redo for script edits to layout dimensions doesn't render correctly.
ScriptEditLayout::ScriptEditLayout(Layout *layout,
QSize oldLayoutDimensions, QSize newLayoutDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,

View file

@ -1280,6 +1280,7 @@ bool Editor::setMap(QString map_name) {
if (!displayMap()) {
return false;
}
displayWildMonTables();
connect(map, &Map::openScriptRequested, this, &Editor::openScript);
connect(map, &Map::connectionAdded, this, &Editor::displayConnection);
@ -1551,10 +1552,11 @@ void Editor::clearMap() {
}
bool Editor::displayMap() {
if (!this->map)
return false;
displayMapEvents();
displayMapConnections();
displayWildMonTables();
maskNonVisibleConnectionTiles();
if (events_group) {
@ -1564,6 +1566,9 @@ bool Editor::displayMap() {
}
bool Editor::displayLayout() {
if (!this->layout)
return false;
if (!scene) {
scene = new QGraphicsScene;
MapSceneEventFilter *filter = new MapSceneEventFilter(scene);
@ -1826,10 +1831,8 @@ void Editor::clearMapConnections() {
void Editor::displayMapConnections() {
clearMapConnections();
if (map) {
for (auto connection : map->getConnections())
displayConnection(connection);
}
for (auto connection : map->getConnections())
displayConnection(connection);
if (!connection_items.isEmpty())
setSelectedConnectionItem(connection_items.first());

View file

@ -839,6 +839,7 @@ bool MainWindow::setMap(QString map_name) {
return false;
}
// TODO: Redundant?
if (editor->map && !editor->map->name.isNull()) {
ui->mapList->setExpanded(groupListProxyModel->mapFromSource(mapGroupModel->indexOf(map_name)), false);
}
@ -851,11 +852,10 @@ bool MainWindow::setMap(QString map_name) {
updateWindowTitle();
resetMapListFilters();
connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing, Qt::UniqueConnection);
connect(editor->map, &Map::modified, this, &MainWindow::markMapEdited, Qt::UniqueConnection);
connect(editor->layout, &Layout::layoutChanged, this, &MainWindow::onLayoutChanged, Qt::UniqueConnection);
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing, Qt::UniqueConnection);
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::redrawMapScene, Qt::UniqueConnection);
userConfig.recentMapOrLayout = map_name;
@ -911,7 +911,7 @@ bool MainWindow::setLayout(QString layoutId) {
updateWindowTitle();
resetMapListFilters();
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing, Qt::UniqueConnection);
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::redrawMapScene, Qt::UniqueConnection);
updateTilesetEditor();
@ -921,17 +921,9 @@ bool MainWindow::setLayout(QString layoutId) {
}
void MainWindow::redrawMapScene() {
if (!editor->displayMap())
return;
this->refreshMapScene();
}
void MainWindow::redrawLayoutScene() {
if (!editor->displayLayout())
return;
this->refreshMapScene();
editor->displayMap();
editor->displayLayout();
refreshMapScene();
}
void MainWindow::refreshMapScene() {
@ -2837,31 +2829,22 @@ void MainWindow::onLayoutChanged(Layout *) {
updateMapList();
}
void MainWindow::onMapNeedsRedrawing() {
redrawMapScene();
}
void MainWindow::onLayoutNeedsRedrawing() {
redrawLayoutScene();
}
void MainWindow::onMapLoaded(Map *map) {
connect(map, &Map::modified, [this, map] { this->markSpecificMapEdited(map); });
}
// TODO: editor->layout below? and redrawLayoutScene?
void MainWindow::onTilesetsSaved(QString primaryTilesetLabel, QString secondaryTilesetLabel) {
// If saved tilesets are currently in-use, update them and redraw
// Otherwise overwrite the cache for the saved tileset
bool updated = false;
if (primaryTilesetLabel == this->editor->map->layout->tileset_primary_label) {
if (primaryTilesetLabel == this->editor->layout->tileset_primary_label) {
this->editor->updatePrimaryTileset(primaryTilesetLabel, true);
Scripting::cb_TilesetUpdated(primaryTilesetLabel);
updated = true;
} else {
this->editor->project->getTileset(primaryTilesetLabel, true);
}
if (secondaryTilesetLabel == this->editor->map->layout->tileset_secondary_label) {
if (secondaryTilesetLabel == this->editor->layout->tileset_secondary_label) {
this->editor->updateSecondaryTileset(secondaryTilesetLabel, true);
Scripting::cb_TilesetUpdated(secondaryTilesetLabel);
updated = true;
@ -3012,7 +2995,7 @@ void MainWindow::on_comboBox_PrimaryTileset_currentTextChanged(const QString &ti
{
if (editor->project->primaryTilesetLabels.contains(tilesetLabel) && editor->layout) {
editor->updatePrimaryTileset(tilesetLabel);
redrawLayoutScene();
redrawMapScene();
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
updateTilesetEditor();
prefab.updatePrefabUi(editor->layout);
@ -3024,7 +3007,7 @@ void MainWindow::on_comboBox_SecondaryTileset_currentTextChanged(const QString &
{
if (editor->project->secondaryTilesetLabels.contains(tilesetLabel) && editor->layout) {
editor->updateSecondaryTileset(tilesetLabel);
redrawLayoutScene();
redrawMapScene();
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
updateTilesetEditor();
prefab.updatePrefabUi(editor->layout);
@ -3289,7 +3272,7 @@ void MainWindow::reloadScriptEngine() {
// Lying to the scripts here, simulating a project reload
Scripting::cb_ProjectOpened(projectConfig.projectDir);
if (editor && editor->map)
Scripting::cb_MapOpened(editor->map->name);
Scripting::cb_MapOpened(editor->map->name); // TODO: API should have equivalent for layout
}
void MainWindow::on_pushButton_AddCustomHeaderField_clicked()

View file

@ -231,7 +231,7 @@ void MainWindow::setDimensions(int width, int height) {
return;
this->editor->layout->setDimensions(width, height);
this->tryCommitMapChanges(true);
this->onMapNeedsRedrawing();
this->redrawMapScene();
}
void MainWindow::setWidth(int width) {
@ -241,7 +241,7 @@ void MainWindow::setWidth(int width) {
return;
this->editor->layout->setDimensions(width, this->editor->layout->getHeight());
this->tryCommitMapChanges(true);
this->onMapNeedsRedrawing();
this->redrawMapScene();
}
void MainWindow::setHeight(int height) {
@ -251,7 +251,7 @@ void MainWindow::setHeight(int height) {
return;
this->editor->layout->setDimensions(this->editor->layout->getWidth(), height);
this->tryCommitMapChanges(true);
this->onMapNeedsRedrawing();
this->redrawMapScene();
}
//=====================
@ -301,7 +301,7 @@ void MainWindow::setBorderDimensions(int width, int height) {
return;
this->editor->layout->setBorderDimensions(width, height);
this->tryCommitMapChanges(true);
this->onMapNeedsRedrawing();
this->redrawMapScene();
}
void MainWindow::setBorderWidth(int width) {
@ -311,7 +311,7 @@ void MainWindow::setBorderWidth(int width) {
return;
this->editor->layout->setBorderDimensions(width, this->editor->layout->getBorderHeight());
this->tryCommitMapChanges(true);
this->onMapNeedsRedrawing();
this->redrawMapScene();
}
void MainWindow::setBorderHeight(int height) {
@ -321,7 +321,7 @@ void MainWindow::setBorderHeight(int height) {
return;
this->editor->layout->setBorderDimensions(this->editor->layout->getBorderWidth(), height);
this->tryCommitMapChanges(true);
this->onMapNeedsRedrawing();
this->redrawMapScene();
}
//======================