More loading screen messages, include map.json files

This commit is contained in:
GriffinR
2025-05-01 13:42:13 -04:00
parent 6d6b006620
commit 3876b63836
7 changed files with 77 additions and 29 deletions

View File

@@ -3,7 +3,7 @@
<class>LoadingScreen</class>
<widget class="QWidget" name="LoadingScreen">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
<enum>Qt::WindowModality::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
@@ -17,7 +17,7 @@
<cursorShape>BusyCursor</cursorShape>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
<enum>Qt::ContextMenuPolicy::NoContextMenu</enum>
</property>
<property name="windowTitle">
<string>Form</string>
@@ -35,7 +35,7 @@
<string>porymap</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</item>
@@ -50,14 +50,14 @@
<string>Version X.x.x</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -70,16 +70,16 @@
<item>
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -105,7 +105,7 @@
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -121,7 +121,7 @@
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -134,23 +134,16 @@
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
<enum>QFrame::Shadow::Plain</enum>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelLoading">
<property name="text">
<string>Loading.....</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="labelText">
<property name="text">
<string>TextLabel</string>
<string>Loading....</string>
</property>
</widget>
</item>

View File

@@ -44,6 +44,7 @@ class ParseUtil
public:
ParseUtil();
void setRoot(const QString &dir) { this->root = dir; }
void setUpdatesSplashScreen(bool updates) { this->updatesSplashScreen = updates; }
static QString readTextFile(const QString &path, QString *error = nullptr);
bool cacheFile(const QString &path, QString *error = nullptr);
void clearFileCache() { this->fileCache.clear(); }
@@ -105,6 +106,8 @@ private:
QHash<QString, int> globalDefineValues;
QHash<QString, QString> globalDefineExpressions;
bool updatesSplashScreen = false;
int evaluateDefine(const QString &identifier, bool *ok = nullptr);
int evaluateExpression(const QString &expression);
QList<Token> tokenizeExpression(QString expression);
@@ -114,6 +117,7 @@ private:
void recordErrors(const QStringList &errors);
void logRecordedErrors();
QString createErrorMessage(const QString &message, const QString &expression);
void updateSplashScreen(QString path);
struct ParsedDefines {
QHash<QString,QString> expressions; // Map of all define names encountered to their expressions

View File

@@ -18,8 +18,10 @@ public:
explicit PorymapLoadingScreen(QWidget *parent = nullptr);
~PorymapLoadingScreen();
void setPixmap(QPixmap pixmap);
void showMessage(QString text);
void setPixmap(const QPixmap &pixmap);
void showMessage(const QString &text);
void showMessage(const QString &prefix, const QString &text);
void showLoadingMessage(const QString &text);
void start();
void stop ();

View File

@@ -56,9 +56,17 @@ QString ParseUtil::createErrorMessage(const QString &message, const QString &exp
return QString("%1:%2:%3: %4").arg(this->file).arg(lineNum).arg(colNum).arg(message);
}
void ParseUtil::updateSplashScreen(QString path) {
if (!this->updatesSplashScreen)
return;
if (path.startsWith(this->root)) {
path.remove(0, this->root.length());
}
porysplash->showLoadingMessage(path);
}
QString ParseUtil::readTextFile(const QString &path, QString *error) {
// splash screen message
porysplash->showMessage(path);
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
if (error) *error = file.errorString();
@@ -80,6 +88,8 @@ QString ParseUtil::readTextFile(const QString &path, QString *error) {
// Note that this doesn't insert any parsed files into the file cache, and we don't
// want it to (we read a lot of files only once, storing them all is a waste of memory).
QString ParseUtil::loadTextFile(const QString &path, QString *error) {
updateSplashScreen(path);
auto it = this->fileCache.constFind(path);
if (it != this->fileCache.constEnd()) {
// Load text file from cache
@@ -89,6 +99,8 @@ QString ParseUtil::loadTextFile(const QString &path, QString *error) {
}
bool ParseUtil::cacheFile(const QString &path, QString *error) {
updateSplashScreen(path);
this->fileCache.insert(path, readTextFile(pathWithRoot(path), error));
return !error || error->isEmpty();
}
@@ -732,6 +744,8 @@ QStringList ParseUtil::getLabelValues(const QList<QStringList> &list, const QStr
}
bool ParseUtil::tryParseJsonFile(QJsonDocument *out, const QString &filepath, QString *error) {
updateSplashScreen(filepath);
QFile file(pathWithRoot(filepath));
if (!file.open(QIODevice::ReadOnly)) {
if (error) *error = file.errorString();

View File

@@ -657,13 +657,15 @@ bool MainWindow::openProject(QString dir, bool initial) {
this->statusBar()->showMessage(openMessage);
logInfo(openMessage);
porysplash->start();
porysplash->showLoadingMessage("config");
userConfig.projectDir = dir;
userConfig.load();
projectConfig.projectDir = dir;
projectConfig.load();
porysplash->start();
porysplash->showLoadingMessage("custom scripts");
Scripting::init(this);
// Create the project
@@ -681,6 +683,7 @@ bool MainWindow::openProject(QString dir, bool initial) {
this->editor->setProject(project);
// Make sure project looks reasonable before attempting to load it
porysplash->showMessage("Verifying project");
if (!checkProjectSanity()) {
delete this->editor->project;
porysplash->stop();
@@ -719,6 +722,7 @@ bool MainWindow::openProject(QString dir, bool initial) {
}
bool MainWindow::loadProjectData() {
porysplash->showLoadingMessage("project");
bool success = editor->project->load();
Scripting::populateGlobalObject(this);
return success;
@@ -745,6 +749,12 @@ bool MainWindow::checkProjectSanity() {
}
void MainWindow::showProjectOpenFailure() {
if (!this->isVisible()){
// The main window is not visible during the initial project open; the splash screen is busy providing visual feedback.
// If project opening fails we can immediately display the empty main window (which we need anyway to parent messages to).
restoreWindowState();
show();
}
RecentErrorMessage::show(QStringLiteral("There was an error opening the project."), this);
}
@@ -766,6 +776,8 @@ bool MainWindow::isProjectOpen() {
}
bool MainWindow::setInitialMap() {
porysplash->showMessage("Opening initial map");
const QString recent = userConfig.recentMapOrLayout;
if (editor->project->mapNames.contains(recent)) {
// User recently had a map open that still exists.
@@ -1184,6 +1196,8 @@ void MainWindow::onLayoutSelectorEditingFinished() {
// Update the UI using information we've read from the user's project files.
bool MainWindow::setProjectUI() {
porysplash->showLoadingMessage("project UI");
Project *project = editor->project;
this->mapHeaderForm->setProject(project);

View File

@@ -76,6 +76,7 @@ bool Project::sanityCheck() {
}
bool Project::load() {
this->parser.setUpdatesSplashScreen(true);
resetFileCache();
this->disabledSettingsNames.clear();
bool success = readGlobalConstants()
@@ -116,6 +117,7 @@ bool Project::load() {
initNewMapSettings();
applyParsedLimits();
}
this->parser.setUpdatesSplashScreen(false);
return success;
}

View File

@@ -43,18 +43,37 @@ void PorymapLoadingScreen::stop () {
this->hide();
}
void PorymapLoadingScreen::setPixmap(QPixmap pixmap) {
void PorymapLoadingScreen::setPixmap(const QPixmap &pixmap) {
if (!this->isVisible()) return;
this->ui->labelPixmap->setPixmap(pixmap);
}
void PorymapLoadingScreen::showMessage(QString text) {
// Displays the message 'prefixtext...'. The 'text' portion may be elided if it's too long.
void PorymapLoadingScreen::showMessage(const QString &prefix, const QString &text) {
if (!this->isVisible()) return;
this->ui->labelText->setText(text.mid(text.lastIndexOf("/") + 1));
// Limit text (excluding prefix) to avoid increasing the splash screen's width.
static const QFontMetrics fontMetrics = this->ui->labelText->fontMetrics();
static const int maxWidth = this->ui->labelText->width() + 1;
int prefixWidth = fontMetrics.horizontalAdvance(prefix);
QString message = fontMetrics.elidedText(text + QStringLiteral("..."), Qt::ElideLeft, qMax(maxWidth - prefixWidth, 0));
message.prepend(prefix);
this->ui->labelText->setText(message);
QApplication::processEvents();
}
// Displays the message 'text...'
void PorymapLoadingScreen::showMessage(const QString &text) {
showMessage("", text);
}
// Displays the message 'Loading text...'
void PorymapLoadingScreen::showLoadingMessage(const QString &text) {
showMessage(QStringLiteral("Loading "), text);
}
void PorymapLoadingScreen::updateFrame() {
this->frame = (this->frame + 1) % this->splashImage.frameCount();
this->setPixmap(QPixmap::fromImage(this->splashImage.frame(this->frame)));