From 15e2d3cf05d388e4e9ca8420635e1930c87f6ef7 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 29 Apr 2025 23:40:03 -0400 Subject: [PATCH] Start fixing some of the Message UI deadlocks --- include/ui/message.h | 8 +++--- src/mainwindow.cpp | 61 +++++++++++++++++++++------------------- src/ui/loadingscreen.cpp | 4 +++ src/ui/message.cpp | 28 ++++++++++-------- 4 files changed, 56 insertions(+), 45 deletions(-) diff --git a/include/ui/message.h b/include/ui/message.h index 8e36372d..1756c48d 100644 --- a/include/ui/message.h +++ b/include/ui/message.h @@ -24,21 +24,21 @@ public: class ErrorMessage : public Message { public: ErrorMessage(const QString &message, QWidget *parent); - static int show(const QString &message, QWidget *parent); + static void show(const QString &message, QWidget *parent); }; // Basic warning message with an 'Ok' button. class WarningMessage : public Message { public: WarningMessage(const QString &message, QWidget *parent); - static int show(const QString &message, QWidget *parent); + static void show(const QString &message, QWidget *parent); }; // Basic informational message with a 'Close' button. class InfoMessage : public Message { public: InfoMessage(const QString &message, QWidget *parent); - static int show(const QString &message, QWidget *parent); + static void show(const QString &message, QWidget *parent); }; // Basic question message with a 'Yes' and 'No' button. @@ -53,7 +53,7 @@ public: class RecentErrorMessage : public ErrorMessage { public: RecentErrorMessage(const QString &message, QWidget *parent); - static int show(const QString &message, QWidget *parent); + static void show(const QString &message, QWidget *parent); }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7527e8c3..f9c9c5c5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -653,8 +653,6 @@ bool MainWindow::openProject(QString dir, bool initial) { return false; } - porysplash->start(); - const QString openMessage = QString("Opening %1").arg(projectString); this->statusBar()->showMessage(openMessage); logInfo(openMessage); @@ -664,6 +662,8 @@ bool MainWindow::openProject(QString dir, bool initial) { projectConfig.projectDir = dir; projectConfig.load(); + porysplash->start(); + Scripting::init(this); // Create the project @@ -730,7 +730,7 @@ bool MainWindow::checkProjectSanity() { logWarn(QString("The directory '%1' failed the project sanity check.").arg(editor->project->root)); - ErrorMessage msgBox(QStringLiteral("The selected directory appears to be invalid."), this); + ErrorMessage msgBox(QStringLiteral("The selected directory appears to be invalid."), porysplash); msgBox.setInformativeText(QString("The directory '%1' is missing key files.\n\n" "Make sure you selected the correct project directory " "(the one used to make your .gba file, e.g. 'pokeemerald').").arg(editor->project->root)); @@ -750,14 +750,15 @@ void MainWindow::showProjectOpenFailure() { // Alert the user that one or more maps have been excluded while loading the project. void MainWindow::showMapsExcludedAlert(const QStringList &excludedMapNames) { - RecentErrorMessage msgBox("", this); + auto msgBox = new RecentErrorMessage("", this); + msgBox->setAttribute(Qt::WA_DeleteOnClose); if (excludedMapNames.length() == 1) { - msgBox.setText(QString("Failed to load map '%1'. Saving will exclude this map from your project.").arg(excludedMapNames.first())); + msgBox->setText(QString("Failed to load map '%1'. Saving will exclude this map from your project.").arg(excludedMapNames.first())); } else { - msgBox.setText(QStringLiteral("Failed to load the maps listed below. Saving will exclude these maps from your project.")); - msgBox.setDetailedText(excludedMapNames.join("\n")); // Overwrites error details text, user will need to check the log. + msgBox->setText(QStringLiteral("Failed to load the maps listed below. Saving will exclude these maps from your project.")); + msgBox->setDetailedText(excludedMapNames.join("\n")); // Overwrites error details text, user will need to check the log. } - msgBox.exec(); + msgBox->open(); } bool MainWindow::isProjectOpen() { @@ -867,28 +868,28 @@ void MainWindow::showFileWatcherWarning() { path.remove(root); } - QuestionMessage msgBox("", this); + QPointer msgBox = new QuestionMessage("", this); if (modifiedFiles.count() == 1) { - msgBox.setText(QString("The file %1 has changed on disk. Would you like to reload the project?").arg(modifiedFiles.first())); + msgBox->setText(QString("The file %1 has changed on disk. Would you like to reload the project?").arg(modifiedFiles.first())); } else { - msgBox.setText(QStringLiteral("Some project files have changed on disk. Would you like to reload the project?")); - msgBox.setDetailedText(QStringLiteral("The following files have changed:\n") + modifiedFiles.join("\n")); + msgBox->setText(QStringLiteral("Some project files have changed on disk. Would you like to reload the project?")); + msgBox->setDetailedText(QStringLiteral("The following files have changed:\n") + modifiedFiles.join("\n")); } + msgBox->setCheckBox(new QCheckBox("Do not ask again.")); - QCheckBox showAgainCheck("Do not ask again."); - msgBox.setCheckBox(&showAgainCheck); - - auto reply = msgBox.exec(); - if (reply == QMessageBox::Yes) { - on_action_Reload_Project_triggered(); - } else if (reply == QMessageBox::No) { - if (showAgainCheck.isChecked()) { - porymapConfig.monitorFiles = false; - if (this->preferenceEditor) - this->preferenceEditor->updateFields(); + connect(msgBox, &QuestionMessage::accepted, this, &MainWindow::on_action_Reload_Project_triggered); + connect(msgBox, &QuestionMessage::finished, [this, msgBox] { + if (msgBox) { + if (msgBox->checkBox() && msgBox->checkBox()->isChecked()) { + porymapConfig.monitorFiles = false; + if (this->preferenceEditor) + this->preferenceEditor->updateFields(); + } + msgBox->deleteLater(); } - } - showing = false; + showing = false; + }); + msgBox->open(); } QString MainWindow::getExistingDirectory(QString dir) { @@ -903,7 +904,8 @@ void MainWindow::on_action_Open_Project_triggered() } void MainWindow::on_action_Reload_Project_triggered() { - openProject(editor->project->root); + if (this->editor && this->editor->project) + openProject(this->editor->project->root); } void MainWindow::on_action_Close_Project_triggered() { @@ -928,9 +930,10 @@ bool MainWindow::userSetMap(QString map_name) { } if (map_name == editor->project->getDynamicMapName()) { - WarningMessage msgBox(QString("Cannot open map '%1'.").arg(map_name), this); - msgBox.setInformativeText(QStringLiteral("This map name is a placeholder to indicate that the warp's map will be set programmatically.")); - msgBox.exec(); + auto msgBox = new WarningMessage(QString("Cannot open map '%1'.").arg(map_name), this); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->setInformativeText(QStringLiteral("This map name is a placeholder to indicate that the warp's map will be set programmatically.")); + msgBox->open(); return false; } diff --git a/src/ui/loadingscreen.cpp b/src/ui/loadingscreen.cpp index 37fa6357..9b60cf92 100644 --- a/src/ui/loadingscreen.cpp +++ b/src/ui/loadingscreen.cpp @@ -28,8 +28,12 @@ void PorymapLoadingScreen::start() { this->ui->labelVersion->setText(AboutPorymap::getVersionString()); shownVersion = true; } + this->frame = 0; this->ui->labelPixmap->setPixmap(QPixmap::fromImage(this->splashImage.frame(this->frame))); + + this->ui->labelText->setText(""); + this->timer.start(120); this->show(); } diff --git a/src/ui/message.cpp b/src/ui/message.cpp index d2d91f75..ce51f7c7 100644 --- a/src/ui/message.cpp +++ b/src/ui/message.cpp @@ -52,19 +52,22 @@ RecentErrorMessage::RecentErrorMessage(const QString &message, QWidget *parent) setDetailedText(getMostRecentError()); } -int RecentErrorMessage::show(const QString &message, QWidget *parent) { - RecentErrorMessage msgBox(message, parent); - return msgBox.exec(); +void RecentErrorMessage::show(const QString &message, QWidget *parent) { + auto msgBox = new RecentErrorMessage(message, parent); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->open(); }; -int ErrorMessage::show(const QString &message, QWidget *parent) { - ErrorMessage msgBox(message, parent); - return msgBox.exec(); +void ErrorMessage::show(const QString &message, QWidget *parent) { + auto msgBox = new ErrorMessage(message, parent); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->open(); }; -int WarningMessage::show(const QString &message, QWidget *parent) { - WarningMessage msgBox(message, parent); - return msgBox.exec(); +void WarningMessage::show(const QString &message, QWidget *parent) { + auto msgBox = new WarningMessage(message, parent); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->open(); }; int QuestionMessage::show(const QString &message, QWidget *parent) { @@ -72,7 +75,8 @@ int QuestionMessage::show(const QString &message, QWidget *parent) { return msgBox.exec(); }; -int InfoMessage::show(const QString &message, QWidget *parent) { - InfoMessage msgBox(message, parent); - return msgBox.exec(); +void InfoMessage::show(const QString &message, QWidget *parent) { + auto msgBox = new InfoMessage(message, parent); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->open(); };