diff --git a/CHANGELOG.md b/CHANGELOG.md index 67e9a0b3..2a687aad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Fix config files being written before the project is opened successfully. - Fix the map and other project info still displaying if a new project fails to open. - Fix unsaved changes being ignored when quitting (such as with Cmd+Q on macOS). +- New maps are now always inserted in map dropdowns at the correct position, rather than at the bottom of the list until the project is reloaded. ## [5.4.1] - 2024-03-21 ### Fixed diff --git a/include/editor.h b/include/editor.h index 6d1f88d4..2c566abc 100644 --- a/include/editor.h +++ b/include/editor.h @@ -174,7 +174,8 @@ private: void clearBorderMetatiles(); void clearCurrentMetatilesSelection(); void clearMapEvents(); - //void clearMapConnections(); + void clearMapConnections(); + void clearConnectionMask(); void clearMapBorder(); void clearMapGrid(); void clearWildMonTables(); diff --git a/src/editor.cpp b/src/editor.cpp index de28ebe0..f427676b 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1546,16 +1546,13 @@ void Editor::clearMap() { clearBorderMetatiles(); clearCurrentMetatilesSelection(); clearMapEvents(); - //clearMapConnections(); + clearMapConnections(); clearMapBorder(); clearMapGrid(); clearWildMonTables(); + clearConnectionMask(); - // TODO: Handle connections after redesign PR. - selected_connection_item = nullptr; - connection_items.clear(); - connection_mask = nullptr; - + // Clear pointers to objects deleted elsewhere current_view = nullptr; map = nullptr; @@ -1804,7 +1801,7 @@ DraggablePixmapItem *Editor::addMapEvent(Event *event) { return object; } -void Editor::displayMapConnections() { +void Editor::clearMapConnections() { for (ConnectionPixmapItem* item : connection_items) { if (item->scene()) { item->scene()->removeItem(item); @@ -1813,13 +1810,13 @@ void Editor::displayMapConnections() { } selected_connection_item = nullptr; connection_items.clear(); +} + +void Editor::displayMapConnections() { + clearMapConnections(); const QSignalBlocker blocker1(ui->comboBox_DiveMap); const QSignalBlocker blocker2(ui->comboBox_EmergeMap); - ui->comboBox_DiveMap->clear(); - ui->comboBox_EmergeMap->clear(); - ui->comboBox_DiveMap->addItems(project->mapNames); - ui->comboBox_EmergeMap->addItems(project->mapNames); ui->comboBox_DiveMap->setCurrentText(""); ui->comboBox_EmergeMap->setCurrentText(""); @@ -1864,8 +1861,7 @@ void Editor::createConnectionItem(MapConnection* connection) { addConnectionToList(item); } -// Hides connected map tiles that cannot be seen from the current map (beyond BORDER_DISTANCE). -void Editor::maskNonVisibleConnectionTiles() { +void Editor::clearConnectionMask() { if (connection_mask) { if (connection_mask->scene()) { connection_mask->scene()->removeItem(connection_mask); @@ -1873,6 +1869,11 @@ void Editor::maskNonVisibleConnectionTiles() { delete connection_mask; connection_mask = nullptr; } +} + +// Hides connected map tiles that cannot be seen from the current map (beyond BORDER_DISTANCE). +void Editor::maskNonVisibleConnectionTiles() { + clearConnectionMask(); QPainterPath mask; mask.addRect(scene->itemsBoundingRect().toRect()); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f08ce4b3..fc7c72f3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1031,6 +1031,8 @@ bool MainWindow::setProjectUI() { const QSignalBlocker blocker5(ui->comboBox_Weather); const QSignalBlocker blocker6(ui->comboBox_BattleScene); const QSignalBlocker blocker7(ui->comboBox_Type); + const QSignalBlocker blocker8(ui->comboBox_DiveMap); + const QSignalBlocker blocker9(ui->comboBox_EmergeMap); // Set up project comboboxes ui->comboBox_Song->clear(); @@ -1047,6 +1049,10 @@ bool MainWindow::setProjectUI() { ui->comboBox_BattleScene->addItems(project->mapBattleScenes); ui->comboBox_Type->clear(); ui->comboBox_Type->addItems(project->mapTypes); + ui->comboBox_DiveMap->clear(); + ui->comboBox_DiveMap->addItems(project->mapNames); + ui->comboBox_EmergeMap->clear(); + ui->comboBox_EmergeMap->addItems(project->mapNames); sortMapList(); @@ -1088,6 +1094,8 @@ void MainWindow::clearProjectUI() { const QSignalBlocker blocker5(ui->comboBox_Weather); const QSignalBlocker blocker6(ui->comboBox_BattleScene); const QSignalBlocker blocker7(ui->comboBox_Type); + const QSignalBlocker blocker8(ui->comboBox_DiveMap); + const QSignalBlocker blocker9(ui->comboBox_EmergeMap); ui->comboBox_Song->clear(); ui->comboBox_Location->clear(); @@ -1096,6 +1104,8 @@ void MainWindow::clearProjectUI() { ui->comboBox_Weather->clear(); ui->comboBox_BattleScene->clear(); ui->comboBox_Type->clear(); + ui->comboBox_DiveMap->clear(); + ui->comboBox_EmergeMap->clear(); // Clear map list mapListModel->clear(); @@ -1301,6 +1311,16 @@ void MainWindow::onNewMapCreated() { sortMapList(); setMap(newMapName, true); + // Refresh any combo box that displays map names and persists between maps + // (others combo boxes like for warp destinations are repopulated when the map changes). + int index = this->editor->project->mapNames.indexOf(newMapName); + if (index >= 0) { + const QSignalBlocker blocker1(ui->comboBox_DiveMap); + const QSignalBlocker blocker2(ui->comboBox_EmergeMap); + ui->comboBox_DiveMap->insertItem(index, newMapName); + ui->comboBox_EmergeMap->insertItem(index, newMapName); + } + if (newMap->needsHealLocation) { addNewEvent(Event::Type::HealLocation); editor->project->saveHealLocations(newMap); diff --git a/src/project.cpp b/src/project.cpp index 6764839b..42487269 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1819,18 +1819,22 @@ bool Project::readMapGroups() { } Map* Project::addNewMapToGroup(QString mapName, int groupNum, Map *newMap, bool existingLayout, bool importedMap) { - mapNames.append(mapName); - mapGroups.insert(mapName, groupNum); - groupedMapNames[groupNum].append(mapName); + int mapNamePos = 0; + for (int i = 0; i <= groupNum; i++) + mapNamePos += this->groupedMapNames.value(i).length(); + + this->mapNames.insert(mapNamePos, mapName); + this->mapGroups.insert(mapName, groupNum); + this->groupedMapNames[groupNum].append(mapName); newMap->isPersistedToFile = false; newMap->setName(mapName); - mapConstantsToMapNames.insert(newMap->constantName, newMap->name); - mapNamesToMapConstants.insert(newMap->name, newMap->constantName); + this->mapConstantsToMapNames.insert(newMap->constantName, newMap->name); + this->mapNamesToMapConstants.insert(newMap->name, newMap->constantName); if (!existingLayout) { - mapLayouts.insert(newMap->layoutId, newMap->layout); - mapLayoutsTable.append(newMap->layoutId); + this->mapLayouts.insert(newMap->layoutId, newMap->layout); + this->mapLayoutsTable.append(newMap->layoutId); if (!importedMap) { setNewMapBlockdata(newMap); }