diff --git a/include/mainwindow.h b/include/mainwindow.h index fc277193..677bd89f 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -380,6 +380,7 @@ private: void redrawMapScene(); void redrawLayoutScene(); void refreshMapScene(); + void setLayoutOnlyMode(bool layoutOnly); bool checkProjectSanity(); bool loadProjectData(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4d3a72e7..dea3d210 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -425,12 +425,14 @@ void MainWindow::showWindowTitle() { ); } if (editor && editor->layout) { - ui->mainTabBar->setTabIcon(0, QIcon()); + // For some reason (perhaps on Qt < 6?) we had to clear the icon first here or mainTabBar wouldn't display correctly. + ui->mainTabBar->setTabIcon(MainTab::Map, QIcon()); + QPixmap pixmap = editor->layout->pixmap; if (!pixmap.isNull()) { - ui->mainTabBar->setTabIcon(0, QIcon(pixmap)); + ui->mainTabBar->setTabIcon(MainTab::Map, QIcon(pixmap)); } else { - ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico"))); + ui->mainTabBar->setTabIcon(MainTab::Map, QIcon(QStringLiteral(":/icons/map.ico"))); } } updateMapList(); @@ -801,14 +803,7 @@ void MainWindow::on_action_Close_Project_triggered() { void MainWindow::unsetMap() { this->editor->unsetMap(); - - // disable other tabs - this->ui->mainTabBar->setTabEnabled(1, false); - this->ui->mainTabBar->setTabEnabled(2, false); - this->ui->mainTabBar->setTabEnabled(3, false); - this->ui->mainTabBar->setTabEnabled(4, false); - - this->ui->comboBox_LayoutSelector->setEnabled(false); + setLayoutOnlyMode(true); } // setMap, but with a visible error message in case of failure. @@ -859,13 +854,7 @@ bool MainWindow::setMap(QString map_name, bool scroll) { ui->mapList->setExpanded(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(map_name)), false); } - this->ui->mainTabBar->setTabEnabled(1, true); - this->ui->mainTabBar->setTabEnabled(2, true); - this->ui->mainTabBar->setTabEnabled(3, true); - this->ui->mainTabBar->setTabEnabled(4, true); - - this->ui->comboBox_LayoutSelector->setEnabled(true); - + setLayoutOnlyMode(false); this->lastSelectedEvent.clear(); refreshMapScene(); @@ -891,6 +880,18 @@ bool MainWindow::setMap(QString map_name, bool scroll) { return true; } +// These parts of the UI only make sense when editing maps. +// When editing in layout-only mode they are disabled. +void MainWindow::setLayoutOnlyMode(bool layoutOnly) { + bool mapEditingEnabled = !layoutOnly; + this->ui->mainTabBar->setTabEnabled(MainTab::Events, mapEditingEnabled); + this->ui->mainTabBar->setTabEnabled(MainTab::Header, mapEditingEnabled); + this->ui->mainTabBar->setTabEnabled(MainTab::Connections, mapEditingEnabled); + this->ui->mainTabBar->setTabEnabled(MainTab::WildPokemon, mapEditingEnabled); + + this->ui->comboBox_LayoutSelector->setEnabled(mapEditingEnabled); +} + bool MainWindow::setLayout(QString layoutId) { if (this->editor->map) logInfo("Switching to a layout-only editing mode. Disabling map-related edits."); diff --git a/src/project.cpp b/src/project.cpp index 194f2ecd..32c61fed 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -2327,11 +2327,14 @@ bool Project::readRegionMapSections() { int Project::appendMapsec(QString name) { // This function assumes a valid and unique name. // Will return the new index. - int noneBefore = this->mapSectionNameToValue[projectConfig.getIdentifier(ProjectIdentifier::define_map_section_prefix) + "NONE"]; + const QString emptyMapsecName = projectConfig.getIdentifier(ProjectIdentifier::define_map_section_prefix) + + projectConfig.getIdentifier(ProjectIdentifier::define_map_section_empty); + + int noneBefore = this->mapSectionNameToValue[emptyMapsecName]; this->mapSectionNameToValue[name] = noneBefore; this->mapSectionValueToName[noneBefore] = name; - this->mapSectionNameToValue[projectConfig.getIdentifier(ProjectIdentifier::define_map_section_prefix) + "NONE"] = noneBefore + 1; - this->mapSectionValueToName[noneBefore + 1] = projectConfig.getIdentifier(ProjectIdentifier::define_map_section_prefix) + "NONE"; + this->mapSectionNameToValue[emptyMapsecName] = noneBefore + 1; + this->mapSectionValueToName[noneBefore + 1] = emptyMapsecName; return noneBefore; }