Add project close option

This commit is contained in:
GriffinR 2024-07-16 16:26:59 -04:00
parent 9efe67a72f
commit 4c25813bd3
9 changed files with 214 additions and 51 deletions

View file

@ -3061,6 +3061,7 @@
<addaction name="action_Open_Project"/> <addaction name="action_Open_Project"/>
<addaction name="menuOpen_Recent_Project"/> <addaction name="menuOpen_Recent_Project"/>
<addaction name="action_Reload_Project"/> <addaction name="action_Reload_Project"/>
<addaction name="action_Close_Project"/>
<addaction name="action_Save"/> <addaction name="action_Save"/>
<addaction name="action_Save_Project"/> <addaction name="action_Save_Project"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -3415,6 +3416,14 @@
<enum>QAction::ApplicationSpecificRole</enum> <enum>QAction::ApplicationSpecificRole</enum>
</property> </property>
</action> </action>
<action name="action_Close_Project">
<property name="text">
<string>Close Project</string>
</property>
<property name="shortcut">
<string>Ctrl+W</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>

View file

@ -54,6 +54,7 @@ public:
} }
virtual void reset() override { virtual void reset() override {
this->recentProjects.clear(); this->recentProjects.clear();
this->projectManuallyClosed = false;
this->reopenOnLaunch = true; this->reopenOnLaunch = true;
this->mapSortOrder = MapSortOrder::Group; this->mapSortOrder = MapSortOrder::Group;
this->prettyCursors = true; this->prettyCursors = true;
@ -99,6 +100,7 @@ public:
QMap<QString, QByteArray> getCustomScriptsEditorGeometry(); QMap<QString, QByteArray> getCustomScriptsEditorGeometry();
bool reopenOnLaunch; bool reopenOnLaunch;
bool projectManuallyClosed;
MapSortOrder mapSortOrder; MapSortOrder mapSortOrder;
bool prettyCursors; bool prettyCursors;
int collisionOpacity; int collisionOpacity;

View file

@ -107,13 +107,13 @@ public:
void updateWarpEventWarnings(); void updateWarpEventWarnings();
bool eventLimitReached(Map *, Event::Type); bool eventLimitReached(Map *, Event::Type);
QGraphicsScene *scene = nullptr; QPointer<QGraphicsScene> scene = nullptr;
QGraphicsPixmapItem *current_view = nullptr; QGraphicsPixmapItem *current_view = nullptr;
MapPixmapItem *map_item = nullptr; QPointer<MapPixmapItem> map_item = nullptr;
ConnectionPixmapItem* selected_connection_item = nullptr; ConnectionPixmapItem* selected_connection_item = nullptr;
QList<ConnectionPixmapItem*> connection_items; QList<ConnectionPixmapItem*> connection_items;
QGraphicsPathItem *connection_mask = nullptr; QGraphicsPathItem *connection_mask = nullptr;
CollisionPixmapItem *collision_item = nullptr; QPointer<CollisionPixmapItem> collision_item = nullptr;
QGraphicsItemGroup *events_group = nullptr; QGraphicsItemGroup *events_group = nullptr;
QList<QGraphicsPixmapItem*> borderItems; QList<QGraphicsPixmapItem*> borderItems;
QList<QGraphicsLineItem*> gridLines; QList<QGraphicsLineItem*> gridLines;
@ -121,16 +121,15 @@ public:
CursorTileRect *cursorMapTileRect = nullptr; CursorTileRect *cursorMapTileRect = nullptr;
MapRuler *map_ruler = nullptr; MapRuler *map_ruler = nullptr;
QGraphicsScene *scene_metatiles = nullptr; QPointer<QGraphicsScene> scene_metatiles = nullptr;
QGraphicsScene *scene_current_metatile_selection = nullptr; QPointer<QGraphicsScene> scene_current_metatile_selection = nullptr;
QGraphicsScene *scene_selected_border_metatiles = nullptr; QPointer<QGraphicsScene> scene_selected_border_metatiles = nullptr;
QGraphicsScene *scene_collision_metatiles = nullptr; QPointer<QGraphicsScene> scene_collision_metatiles = nullptr;
QGraphicsScene *scene_elevation_metatiles = nullptr; QPointer<MetatileSelector> metatile_selector_item = nullptr;
MetatileSelector *metatile_selector_item = nullptr;
BorderMetatilesPixmapItem *selected_border_metatiles_item = nullptr; QPointer<BorderMetatilesPixmapItem> selected_border_metatiles_item = nullptr;
CurrentSelectedMetatilesPixmapItem *current_metatile_selection_item = nullptr; CurrentSelectedMetatilesPixmapItem *current_metatile_selection_item = nullptr;
MovementPermissionsSelector *movement_permissions_selector_item = nullptr; QPointer<MovementPermissionsSelector> movement_permissions_selector_item = nullptr;
QList<DraggablePixmapItem *> *selected_events = nullptr; QList<DraggablePixmapItem *> *selected_events = nullptr;
@ -168,6 +167,18 @@ private:
const QImage collisionPlaceholder = QImage(":/images/collisions_unknown.png"); const QImage collisionPlaceholder = QImage(":/images/collisions_unknown.png");
QPixmap collisionSheetPixmap; QPixmap collisionSheetPixmap;
void clearMap();
void clearMetatileSelector();
void clearMovementPermissionSelector();
void clearMapMetatiles();
void clearMapMovementPermissions();
void clearBorderMetatiles();
void clearCurrentMetatilesSelection();
void clearMapEvents();
//void clearMapConnections();
void clearMapBorder();
void clearMapGrid();
void clearWildMonTables();
void setConnectionItemsVisible(bool); void setConnectionItemsVisible(bool);
void setBorderItemsVisible(bool, qreal = 1); void setBorderItemsVisible(bool, qreal = 1);
void setConnectionEditControlValues(MapConnection*); void setConnectionEditControlValues(MapConnection*);

View file

@ -167,6 +167,7 @@ public slots:
private slots: private slots:
void on_action_Open_Project_triggered(); void on_action_Open_Project_triggered();
void on_action_Reload_Project_triggered(); void on_action_Reload_Project_triggered();
void on_action_Close_Project_triggered();
void on_mapList_activated(const QModelIndex &index); void on_mapList_activated(const QModelIndex &index);
void on_action_Save_Project_triggered(); void on_action_Save_Project_triggered();
void openWarpMap(QString map_name, int event_id, Event::Group event_group); void openWarpMap(QString map_name, int event_id, Event::Group event_group);
@ -347,10 +348,11 @@ private:
bool checkProjectSanity(); bool checkProjectSanity();
bool loadProjectData(); bool loadProjectData();
bool setProjectUI(); bool setProjectUI();
void clearProjectUI();
void sortMapList(); void sortMapList();
void openSubWindow(QWidget * window); void openSubWindow(QWidget * window);
QString getExistingDirectory(QString); QString getExistingDirectory(QString);
bool openProject(const QString &dir, bool initial = false); bool openProject(QString dir, bool initial = false);
bool closeProject(); bool closeProject();
void showProjectOpenFailure(); void showProjectOpenFailure();
void saveGlobalConfigs(); void saveGlobalConfigs();

View file

@ -30,6 +30,7 @@ class Scripting
{ {
public: public:
Scripting(MainWindow *mainWindow); Scripting(MainWindow *mainWindow);
static void stop();
static void init(MainWindow *mainWindow); static void init(MainWindow *mainWindow);
static void populateGlobalObject(MainWindow *mainWindow); static void populateGlobalObject(MainWindow *mainWindow);
static QJSEngine *getEngine(); static QJSEngine *getEngine();

View file

@ -198,9 +198,9 @@ KeyValueConfigBase::~KeyValueConfigBase() {
void KeyValueConfigBase::load() { void KeyValueConfigBase::load() {
reset(); reset();
QFile file(this->getConfigFilepath()); QFile file(this->getConfigFilepath());
if (!file.exists()) if (!file.exists()) {
this->init(); this->init();
else if (!file.open(QIODevice::ReadOnly)) { } else if (!file.open(QIODevice::ReadOnly)) {
logError(QString("Could not open config file '%1': ").arg(this->getConfigFilepath()) + file.errorString()); logError(QString("Could not open config file '%1': ").arg(this->getConfigFilepath()) + file.errorString());
} }
@ -306,6 +306,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
if (key == "recent_project") { if (key == "recent_project") {
this->recentProjects = value.split(",", Qt::SkipEmptyParts); this->recentProjects = value.split(",", Qt::SkipEmptyParts);
this->recentProjects.removeDuplicates(); this->recentProjects.removeDuplicates();
} else if (key == "project_manually_closed") {
this->projectManuallyClosed = getConfigBool(key, value);
} else if (key == "reopen_on_launch") { } else if (key == "reopen_on_launch") {
this->reopenOnLaunch = getConfigBool(key, value); this->reopenOnLaunch = getConfigBool(key, value);
} else if (key == "pretty_cursors") { } else if (key == "pretty_cursors") {
@ -417,6 +419,7 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
QMap<QString, QString> PorymapConfig::getKeyValueMap() { QMap<QString, QString> PorymapConfig::getKeyValueMap() {
QMap<QString, QString> map; QMap<QString, QString> map;
map.insert("recent_project", this->recentProjects.join(",")); map.insert("recent_project", this->recentProjects.join(","));
map.insert("project_manually_closed", this->projectManuallyClosed ? "1" : "0");
map.insert("reopen_on_launch", this->reopenOnLaunch ? "1" : "0"); map.insert("reopen_on_launch", this->reopenOnLaunch ? "1" : "0");
map.insert("pretty_cursors", this->prettyCursors ? "1" : "0"); map.insert("pretty_cursors", this->prettyCursors ? "1" : "0");
map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder)); map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder));
@ -882,7 +885,7 @@ void ProjectConfig::init() {
baseGameVersionComboBox->addItem("pokeemerald", BaseGameVersion::pokeemerald); baseGameVersionComboBox->addItem("pokeemerald", BaseGameVersion::pokeemerald);
form.addRow(new QLabel("Game Version"), baseGameVersionComboBox); form.addRow(new QLabel("Game Version"), baseGameVersionComboBox);
// TODO: Advanced button to open the project settings window (with some settings disabled) // TODO: Add an 'Advanced' button to open the project settings window (with some settings disabled)
QDialogButtonBox buttonBox(QDialogButtonBox::Ok, Qt::Horizontal, &dialog); QDialogButtonBox buttonBox(QDialogButtonBox::Ok, Qt::Horizontal, &dialog);
QObject::connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); QObject::connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
@ -891,7 +894,7 @@ void ProjectConfig::init() {
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
this->baseGameVersion = static_cast<BaseGameVersion>(baseGameVersionComboBox->currentData().toInt()); this->baseGameVersion = static_cast<BaseGameVersion>(baseGameVersionComboBox->currentData().toInt());
} else { } else {
// TODO: If user closes window Porymap assumes pokeemerald; it should instead abort project opening logWarn(QString("No base_game_version selected, using default '%1'").arg(getBaseGameVersionString(this->baseGameVersion)));
} }
} }
this->setUnreadKeys(); // Initialize version-specific options this->setUnreadKeys(); // Initialize version-specific options

View file

@ -81,8 +81,9 @@ void Editor::saveUiFields() {
void Editor::closeProject() { void Editor::closeProject() {
if (!this->project) if (!this->project)
return; return;
Scripting::cb_ProjectClosed(this->project->root); Scripting::cb_ProjectClosed(this->project->root);
Scripting::stop();
clearMap();
delete this->project; delete this->project;
} }
@ -204,9 +205,8 @@ void Editor::setEditingConnections() {
this->cursorMapTileRect->setActive(false); this->cursorMapTileRect->setActive(false);
} }
void Editor::displayWildMonTables() { void Editor::clearWildMonTables() {
QStackedWidget *stack = ui->stackedWidget_WildMons; QStackedWidget *stack = ui->stackedWidget_WildMons;
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
// delete widgets from previous map data if they exist // delete widgets from previous map data if they exist
while (stack->count()) { while (stack->count()) {
@ -215,18 +215,24 @@ void Editor::displayWildMonTables() {
delete oldWidget; delete oldWidget;
} }
labelCombo->clear(); ui->comboBox_EncounterGroupLabel->clear();
}
void Editor::displayWildMonTables() {
clearWildMonTables();
// Don't try to read encounter data if it doesn't exist on disk for this map. // Don't try to read encounter data if it doesn't exist on disk for this map.
if (!project->wildMonData.contains(map->constantName)) { if (!project->wildMonData.contains(map->constantName)) {
return; return;
} }
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
for (auto groupPair : project->wildMonData[map->constantName]) for (auto groupPair : project->wildMonData[map->constantName])
labelCombo->addItem(groupPair.first); labelCombo->addItem(groupPair.first);
labelCombo->setCurrentText(labelCombo->itemText(0)); labelCombo->setCurrentText(labelCombo->itemText(0));
QStackedWidget *stack = ui->stackedWidget_WildMons;
int labelIndex = 0; int labelIndex = 0;
for (auto labelPair : project->wildMonData[map->constantName]) { for (auto labelPair : project->wildMonData[map->constantName]) {
@ -1337,6 +1343,35 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
} }
} }
// On project close we want to leave the editor view empty.
// Otherwise a map is normally only cleared when a new one is being displayed.
void Editor::clearMap() {
clearMetatileSelector();
clearMovementPermissionSelector();
clearMapMetatiles();
clearMapMovementPermissions();
clearBorderMetatiles();
clearCurrentMetatilesSelection();
clearMapEvents();
//clearMapConnections();
clearMapBorder();
clearMapGrid();
clearWildMonTables();
// TODO: Handle connections after redesign PR.
selected_connection_item = nullptr;
connection_items.clear();
connection_mask = nullptr;
current_view = nullptr;
map = nullptr;
// These are normally preserved between map displays, we only delete them now.
delete scene;
delete metatile_selector_item;
delete movement_permissions_selector_item;
}
bool Editor::displayMap() { bool Editor::displayMap() {
if (!scene) { if (!scene) {
scene = new QGraphicsScene; scene = new QGraphicsScene;
@ -1346,12 +1381,6 @@ bool Editor::displayMap() {
scene->installEventFilter(this->map_ruler); scene->installEventFilter(this->map_ruler);
} }
if (map_item && scene) {
scene->removeItem(map_item);
delete map_item;
scene->removeItem(this->map_ruler);
}
displayMetatileSelector(); displayMetatileSelector();
displayMovementPermissionSelector(); displayMovementPermissionSelector();
displayMapMetatiles(); displayMapMetatiles();
@ -1379,11 +1408,16 @@ bool Editor::displayMap() {
return true; return true;
} }
void Editor::displayMetatileSelector() { void Editor::clearMetatileSelector() {
if (metatile_selector_item && metatile_selector_item->scene()) { if (metatile_selector_item && metatile_selector_item->scene()) {
metatile_selector_item->scene()->removeItem(metatile_selector_item); metatile_selector_item->scene()->removeItem(metatile_selector_item);
delete scene_metatiles; delete scene_metatiles;
} }
}
void Editor::displayMetatileSelector() {
clearMetatileSelector();
scene_metatiles = new QGraphicsScene; scene_metatiles = new QGraphicsScene;
if (!metatile_selector_item) { if (!metatile_selector_item) {
metatile_selector_item = new MetatileSelector(8, map); metatile_selector_item = new MetatileSelector(8, map);
@ -1408,7 +1442,17 @@ void Editor::displayMetatileSelector() {
scene_metatiles->addItem(metatile_selector_item); scene_metatiles->addItem(metatile_selector_item);
} }
void Editor::clearMapMetatiles() {
if (map_item && scene) {
scene->removeItem(map_item);
delete map_item;
scene->removeItem(this->map_ruler);
}
}
void Editor::displayMapMetatiles() { void Editor::displayMapMetatiles() {
clearMapMetatiles();
map_item = new MapPixmapItem(map, this->metatile_selector_item, this->settings); map_item = new MapPixmapItem(map, this->metatile_selector_item, this->settings);
connect(map_item, &MapPixmapItem::mouseEvent, this, &Editor::mouseEvent_map); connect(map_item, &MapPixmapItem::mouseEvent, this, &Editor::mouseEvent_map);
connect(map_item, &MapPixmapItem::startPaint, this, &Editor::onMapStartPaint); connect(map_item, &MapPixmapItem::startPaint, this, &Editor::onMapStartPaint);
@ -1429,11 +1473,16 @@ void Editor::displayMapMetatiles() {
); );
} }
void Editor::displayMapMovementPermissions() { void Editor::clearMapMovementPermissions() {
if (collision_item && scene) { if (collision_item && scene) {
scene->removeItem(collision_item); scene->removeItem(collision_item);
delete collision_item; delete collision_item;
} }
}
void Editor::displayMapMovementPermissions() {
clearMapMovementPermissions();
collision_item = new CollisionPixmapItem(map, ui->spinBox_SelectedCollision, ui->spinBox_SelectedElevation, collision_item = new CollisionPixmapItem(map, ui->spinBox_SelectedCollision, ui->spinBox_SelectedElevation,
this->metatile_selector_item, this->settings, &this->collisionOpacity); this->metatile_selector_item, this->settings, &this->collisionOpacity);
connect(collision_item, &CollisionPixmapItem::mouseEvent, this, &Editor::mouseEvent_collision); connect(collision_item, &CollisionPixmapItem::mouseEvent, this, &Editor::mouseEvent_collision);
@ -1446,11 +1495,16 @@ void Editor::displayMapMovementPermissions() {
scene->addItem(collision_item); scene->addItem(collision_item);
} }
void Editor::displayBorderMetatiles() { void Editor::clearBorderMetatiles() {
if (selected_border_metatiles_item && selected_border_metatiles_item->scene()) { if (selected_border_metatiles_item && selected_border_metatiles_item->scene()) {
selected_border_metatiles_item->scene()->removeItem(selected_border_metatiles_item); selected_border_metatiles_item->scene()->removeItem(selected_border_metatiles_item);
delete selected_border_metatiles_item; delete selected_border_metatiles_item;
delete scene_selected_border_metatiles;
} }
}
void Editor::displayBorderMetatiles() {
clearBorderMetatiles();
scene_selected_border_metatiles = new QGraphicsScene; scene_selected_border_metatiles = new QGraphicsScene;
selected_border_metatiles_item = new BorderMetatilesPixmapItem(map, this->metatile_selector_item); selected_border_metatiles_item = new BorderMetatilesPixmapItem(map, this->metatile_selector_item);
@ -1465,11 +1519,17 @@ void Editor::displayBorderMetatiles() {
this, &Editor::onBorderMetatilesChanged); this, &Editor::onBorderMetatilesChanged);
} }
void Editor::displayCurrentMetatilesSelection() { void Editor::clearCurrentMetatilesSelection() {
if (current_metatile_selection_item && current_metatile_selection_item->scene()) { if (current_metatile_selection_item && current_metatile_selection_item->scene()) {
current_metatile_selection_item->scene()->removeItem(current_metatile_selection_item); current_metatile_selection_item->scene()->removeItem(current_metatile_selection_item);
delete current_metatile_selection_item; delete current_metatile_selection_item;
current_metatile_selection_item = nullptr;
delete scene_current_metatile_selection;
} }
}
void Editor::displayCurrentMetatilesSelection() {
clearCurrentMetatilesSelection();
scene_current_metatile_selection = new QGraphicsScene; scene_current_metatile_selection = new QGraphicsScene;
current_metatile_selection_item = new CurrentSelectedMetatilesPixmapItem(map, this->metatile_selector_item); current_metatile_selection_item = new CurrentSelectedMetatilesPixmapItem(map, this->metatile_selector_item);
@ -1485,11 +1545,15 @@ void Editor::redrawCurrentMetatilesSelection() {
} }
} }
void Editor::displayMovementPermissionSelector() { void Editor::clearMovementPermissionSelector() {
if (movement_permissions_selector_item && movement_permissions_selector_item->scene()) { if (movement_permissions_selector_item && movement_permissions_selector_item->scene()) {
movement_permissions_selector_item->scene()->removeItem(movement_permissions_selector_item); movement_permissions_selector_item->scene()->removeItem(movement_permissions_selector_item);
delete scene_collision_metatiles; delete scene_collision_metatiles;
} }
}
void Editor::displayMovementPermissionSelector() {
clearMovementPermissionSelector();
scene_collision_metatiles = new QGraphicsScene; scene_collision_metatiles = new QGraphicsScene;
if (!movement_permissions_selector_item) { if (!movement_permissions_selector_item) {
@ -1507,7 +1571,7 @@ void Editor::displayMovementPermissionSelector() {
scene_collision_metatiles->addItem(movement_permissions_selector_item); scene_collision_metatiles->addItem(movement_permissions_selector_item);
} }
void Editor::displayMapEvents() { void Editor::clearMapEvents() {
if (events_group) { if (events_group) {
for (QGraphicsItem *child : events_group->childItems()) { for (QGraphicsItem *child : events_group->childItems()) {
events_group->removeFromGroup(child); events_group->removeFromGroup(child);
@ -1519,9 +1583,13 @@ void Editor::displayMapEvents() {
} }
delete events_group; delete events_group;
events_group = nullptr;
} }
selected_events->clear(); selected_events->clear();
}
void Editor::displayMapEvents() {
clearMapEvents();
events_group = new QGraphicsItemGroup; events_group = new QGraphicsItemGroup;
scene->addItem(events_group); scene->addItem(events_group);
@ -1626,7 +1694,7 @@ void Editor::maskNonVisibleConnectionTiles() {
connection_mask = scene->addPath(mask, pen, brush); connection_mask = scene->addPath(mask, pen, brush);
} }
void Editor::displayMapBorder() { void Editor::clearMapBorder() {
for (QGraphicsPixmapItem* item : borderItems) { for (QGraphicsPixmapItem* item : borderItems) {
if (item->scene()) { if (item->scene()) {
item->scene()->removeItem(item); item->scene()->removeItem(item);
@ -1634,6 +1702,10 @@ void Editor::displayMapBorder() {
delete item; delete item;
} }
borderItems.clear(); borderItems.clear();
}
void Editor::displayMapBorder() {
clearMapBorder();
int borderWidth = map->getBorderWidth(); int borderWidth = map->getBorderWidth();
int borderHeight = map->getBorderHeight(); int borderHeight = map->getBorderHeight();
@ -1646,7 +1718,7 @@ void Editor::displayMapBorder() {
item->setX(x * 16); item->setX(x * 16);
item->setY(y * 16); item->setY(y * 16);
item->setZValue(-3); item->setZValue(-3);
scene->addItem(item); scene->addItem(item); // TODO: If the scene is taking ownership here is a double-free possible?
borderItems.append(item); borderItems.append(item);
} }
} }
@ -1689,11 +1761,15 @@ void Editor::onToggleGridClicked(bool checked) {
ui->graphicsView_Map->scene()->update(); ui->graphicsView_Map->scene()->update();
} }
void Editor::displayMapGrid() { void Editor::clearMapGrid() {
for (QGraphicsLineItem* item : gridLines) { for (QGraphicsLineItem* item : gridLines) {
if (item) delete item; if (item) delete item;
} }
gridLines.clear(); gridLines.clear();
}
void Editor::displayMapGrid() {
clearMapGrid();
ui->checkBox_ToggleGrid->disconnect(); ui->checkBox_ToggleGrid->disconnect();
int pixelWidth = map->getWidth() * 16; int pixelWidth = map->getWidth() * 16;

View file

@ -70,7 +70,7 @@ MainWindow::MainWindow(QWidget *parent) :
logInfo(QString("Launching Porymap v%1").arg(QCoreApplication::applicationVersion())); logInfo(QString("Launching Porymap v%1").arg(QCoreApplication::applicationVersion()));
this->initWindow(); this->initWindow();
if (porymapConfig.reopenOnLaunch && this->openProject(porymapConfig.getRecentProject(), true)) if (porymapConfig.reopenOnLaunch && !porymapConfig.projectManuallyClosed && this->openProject(porymapConfig.getRecentProject(), true))
on_toolButton_Paint_clicked(); on_toolButton_Paint_clicked();
// there is a bug affecting macOS users, where the trackpad deilveres a bad touch-release gesture // there is a bug affecting macOS users, where the trackpad deilveres a bad touch-release gesture
@ -498,7 +498,7 @@ void MainWindow::setTheme(QString theme) {
} }
} }
bool MainWindow::openProject(const QString &dir, bool initial) { bool MainWindow::openProject(QString dir, bool initial) {
if (dir.isNull() || dir.length() <= 0) { if (dir.isNull() || dir.length() <= 0) {
// If this happened on startup it's because the user has no recent projects, which is fine. // If this happened on startup it's because the user has no recent projects, which is fine.
// This shouldn't happen otherwise, but if it does then display an error. // This shouldn't happen otherwise, but if it does then display an error.
@ -526,7 +526,7 @@ bool MainWindow::openProject(const QString &dir, bool initial) {
// The above checks can fail and the user will be allowed to continue with their currently-opened project (if there is one). // The above checks can fail and the user will be allowed to continue with their currently-opened project (if there is one).
// We close the current project below, after which either the new project will open successfully or the window will be disabled. // We close the current project below, after which either the new project will open successfully or the window will be disabled.
if (!this->closeProject()) { if (!closeProject()) {
logInfo("Aborted project open."); logInfo("Aborted project open.");
return false; return false;
} }
@ -577,6 +577,7 @@ bool MainWindow::openProject(const QString &dir, bool initial) {
showWindowTitle(); showWindowTitle();
this->statusBar()->showMessage(QString("Opened %1").arg(projectString)); this->statusBar()->showMessage(QString("Opened %1").arg(projectString));
porymapConfig.projectManuallyClosed = false;
porymapConfig.addRecentProject(dir); porymapConfig.addRecentProject(dir);
refreshRecentProjectsMenu(); refreshRecentProjectsMenu();
@ -600,12 +601,14 @@ bool MainWindow::checkProjectSanity() {
if (editor->project->sanityCheck()) if (editor->project->sanityCheck())
return true; return true;
logWarn(QString("The directory '%1' failed the project sanity check.").arg(editor->project->root));
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setText(QString("The selected directory appears to be invalid.")); msgBox.setText(QString("The selected directory appears to be invalid."));
msgBox.setInformativeText(QString("The directory '%1' is missing key files.\n\n" msgBox.setInformativeText(QString("The directory '%1' is missing key files.\n\n"
"Make sure you selected the correct project directory " "Make sure you selected the correct project directory "
"(the one used to make your <b>.gba</b> file, e.g. 'pokeemerald').").arg(editor->project->root)); "(the one used to make your .gba file, e.g. 'pokeemerald').").arg(editor->project->root));
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok);
auto tryAnyway = msgBox.addButton("Try Anyway", QMessageBox::ActionRole); auto tryAnyway = msgBox.addButton("Try Anyway", QMessageBox::ActionRole);
@ -721,6 +724,11 @@ void MainWindow::on_action_Reload_Project_triggered() {
openProject(editor->project->root); openProject(editor->project->root);
} }
void MainWindow::on_action_Close_Project_triggered() {
closeProject();
porymapConfig.projectManuallyClosed = true;
}
bool MainWindow::setMap(QString map_name, bool scrollTreeView) { bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
logInfo(QString("Setting map to '%1'").arg(map_name)); logInfo(QString("Setting map to '%1'").arg(map_name));
if (map_name.isEmpty()) { if (map_name.isEmpty()) {
@ -1047,6 +1055,29 @@ bool MainWindow::setProjectUI() {
return true; return true;
} }
void MainWindow::clearProjectUI() {
// Block signals to the comboboxes while they are being modified
const QSignalBlocker blocker1(ui->comboBox_Song);
const QSignalBlocker blocker2(ui->comboBox_Location);
const QSignalBlocker blocker3(ui->comboBox_PrimaryTileset);
const QSignalBlocker blocker4(ui->comboBox_SecondaryTileset);
const QSignalBlocker blocker5(ui->comboBox_Weather);
const QSignalBlocker blocker6(ui->comboBox_BattleScene);
const QSignalBlocker blocker7(ui->comboBox_Type);
ui->comboBox_Song->clear();
ui->comboBox_Location->clear();
ui->comboBox_PrimaryTileset->clear();
ui->comboBox_SecondaryTileset->clear();
ui->comboBox_Weather->clear();
ui->comboBox_BattleScene->clear();
ui->comboBox_Type->clear();
// Clear map list
mapListModel->clear();
mapGroupItemsList->clear();
}
void MainWindow::sortMapList() { void MainWindow::sortMapList() {
Project *project = editor->project; Project *project = editor->project;
@ -2514,8 +2545,12 @@ void MainWindow::importMapFromAdvanceMap1_92()
void MainWindow::showExportMapImageWindow(ImageExporterMode mode) { void MainWindow::showExportMapImageWindow(ImageExporterMode mode) {
if (!editor->project) return; if (!editor->project) return;
if (!this->mapImageExporter) // If the user is requesting this window again we assume it's for a new
this->mapImageExporter = new MapImageExporter(this, this->editor, mode); // window (the map/mode may have changed), so delete the old window.
if (this->mapImageExporter)
delete this->mapImageExporter;
this->mapImageExporter = new MapImageExporter(this, this->editor, mode);
openSubWindow(this->mapImageExporter); openSubWindow(this->mapImageExporter);
} }
@ -2972,24 +3007,41 @@ bool MainWindow::askToFixRegionMapEditor() {
} }
// Attempt to close any open sub-windows of the main window, giving each a chance to abort the process. // Attempt to close any open sub-windows of the main window, giving each a chance to abort the process.
// Each of these are expected to be a QPointer to a widget with WA_DeleteOnClose set, so manually deleting // Each of these windows is a widget with WA_DeleteOnClose set, so manually deleting them isn't necessary.
// and nullifying the pointer members is not necessary here. // Because they're tracked with QPointers nullifying them shouldn't be necessary either, but it seems the
// delete is happening too late and some of the pointers haven't been cleared by the time we need them to,
// so we nullify them all here anyway.
bool MainWindow::closeSupplementaryWindows() { bool MainWindow::closeSupplementaryWindows() {
if (this->tilesetEditor && !this->tilesetEditor->close()) if (this->tilesetEditor && !this->tilesetEditor->close())
return false; return false;
this->tilesetEditor = nullptr;
if (this->regionMapEditor && !this->regionMapEditor->close()) if (this->regionMapEditor && !this->regionMapEditor->close())
return false; return false;
this->regionMapEditor = nullptr;
if (this->mapImageExporter && !this->mapImageExporter->close()) if (this->mapImageExporter && !this->mapImageExporter->close())
return false; return false;
this->mapImageExporter = nullptr;
if (this->newMapPrompt && !this->newMapPrompt->close()) if (this->newMapPrompt && !this->newMapPrompt->close())
return false; return false;
this->newMapPrompt = nullptr;
if (this->shortcutsEditor && !this->shortcutsEditor->close()) if (this->shortcutsEditor && !this->shortcutsEditor->close())
return false; return false;
this->shortcutsEditor = nullptr;
if (this->preferenceEditor && !this->preferenceEditor->close()) if (this->preferenceEditor && !this->preferenceEditor->close())
return false; return false;
this->preferenceEditor = nullptr;
if (this->customScriptsEditor && !this->customScriptsEditor->close()) if (this->customScriptsEditor && !this->customScriptsEditor->close())
return false; return false;
this->customScriptsEditor = nullptr;
if (this->projectSettingsEditor) this->projectSettingsEditor->closeQuietly(); if (this->projectSettingsEditor) this->projectSettingsEditor->closeQuietly();
this->projectSettingsEditor = nullptr;
return true; return true;
} }
@ -3014,8 +3066,10 @@ bool MainWindow::closeProject() {
return false; return false;
} }
} }
clearProjectUI();
editor->closeProject(); editor->closeProject();
setWindowDisabled(true); setWindowDisabled(true);
setWindowTitle(QCoreApplication::applicationName());
return true; return true;
} }

View file

@ -21,14 +21,19 @@ QMap<CallbackType, QString> callbackFunctions = {
Scripting *instance = nullptr; Scripting *instance = nullptr;
void Scripting::stop() {
if (!instance) return;
instance->engine->setInterrupted(true);
instance->scriptUtility->clearActions();
qDeleteAll(instance->imageCache);
delete instance;
instance = nullptr;
}
void Scripting::init(MainWindow *mainWindow) { void Scripting::init(MainWindow *mainWindow) {
mainWindow->ui->graphicsView_Map->clearOverlayMap(); if (mainWindow->ui->graphicsView_Map)
if (instance) { mainWindow->ui->graphicsView_Map->clearOverlayMap();
instance->engine->setInterrupted(true); Scripting::stop();
instance->scriptUtility->clearActions();
qDeleteAll(instance->imageCache);
delete instance;
}
instance = new Scripting(mainWindow); instance = new Scripting(mainWindow);
} }