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: signals:
void modified(); void modified();
void mapDimensionsChanged(const QSize &size); void mapDimensionsChanged(const QSize &size);
void mapNeedsRedrawing();
void openScriptRequested(QString label); void openScriptRequested(QString label);
void connectionAdded(MapConnection*); void connectionAdded(MapConnection*);
void connectionRemoved(MapConnection*); void connectionRemoved(MapConnection*);

View file

@ -185,8 +185,6 @@ private slots:
void onLayoutChanged(Layout *layout); void onLayoutChanged(Layout *layout);
void onOpenConnectedMap(MapConnection*); void onOpenConnectedMap(MapConnection*);
void onMapNeedsRedrawing();
void onLayoutNeedsRedrawing();
void onTilesetsSaved(QString, QString); void onTilesetsSaved(QString, QString);
void openNewMapPopupWindow(); void openNewMapPopupWindow();
void onNewMapCreated(); void onNewMapCreated();
@ -355,7 +353,6 @@ private:
bool userSetLayout(QString layoutId); bool userSetLayout(QString layoutId);
bool userSetMap(QString); bool userSetMap(QString);
void redrawMapScene(); void redrawMapScene();
void redrawLayoutScene();
void refreshMapScene(); void refreshMapScene();
void setLayoutOnlyMode(bool layoutOnly); 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, ScriptEditLayout::ScriptEditLayout(Layout *layout,
QSize oldLayoutDimensions, QSize newLayoutDimensions, QSize oldLayoutDimensions, QSize newLayoutDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles, const Blockdata &oldMetatiles, const Blockdata &newMetatiles,

View file

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

View file

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

View file

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