From 001e20b1b8ca5b3348d0b26b75b8c470e1e037da Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 22 Mar 2024 20:12:06 -0400 Subject: [PATCH] Add game logo image to the login page This loads the A Realm Reborn logo (for now) from the game and displays in on the login page. --- external/CMakeLists.txt | 2 +- launcher/include/launchercore.h | 5 +++++ launcher/src/launchercore.cpp | 34 +++++++++++++++++++++++++++++++++ launcher/ui/Pages/LoginPage.qml | 16 ++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 7e914be..bcb8793 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -13,7 +13,7 @@ find_package(Corrosion REQUIRED) corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libphysis/Cargo.toml NO_DEFAULT_FEATURES - FEATURES game_install) + FEATURES game_install visual_data) # FIXME: split visual_data? we only need texture decompression add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libphysis/logger EXCLUDE_FROM_ALL) find_package(PkgConfig REQUIRED) diff --git a/launcher/include/launchercore.h b/launcher/include/launchercore.h index 75f3f25..bd27329 100755 --- a/launcher/include/launchercore.h +++ b/launcher/include/launchercore.h @@ -67,6 +67,7 @@ class LauncherCore : public QObject Q_PROPERTY(Headline *headline READ headline NOTIFY newsChanged) Q_PROPERTY(Profile *currentProfile READ currentProfile WRITE setCurrentProfile NOTIFY currentProfileChanged) Q_PROPERTY(Profile *autoLoginProfile READ autoLoginProfile WRITE setAutoLoginProfile NOTIFY autoLoginProfileChanged) + Q_PROPERTY(QString cachedLogoImage READ cachedLogoImage NOTIFY cachedLogoImageChanged) public: LauncherCore(); @@ -89,6 +90,7 @@ public: Q_INVOKABLE void clearAvatarCache(); Q_INVOKABLE void refreshNews(); + Q_INVOKABLE void refreshLogoImage(); [[nodiscard]] Profile *currentProfile() const; void setCurrentProfile(Profile *profile); @@ -111,6 +113,7 @@ public: [[nodiscard]] ProfileManager *profileManager(); [[nodiscard]] AccountManager *accountManager(); [[nodiscard]] Headline *headline() const; + [[nodiscard]] QString cachedLogoImage() const; Q_SIGNALS: void loadingFinished(); @@ -124,6 +127,7 @@ Q_SIGNALS: void newsChanged(); void currentProfileChanged(); void autoLoginProfileChanged(); + void cachedLogoImageChanged(); protected: friend class Patcher; @@ -149,6 +153,7 @@ private: Headline *m_headline = nullptr; LauncherSettings *m_settings = nullptr; GameRunner *m_runner = nullptr; + QString m_cachedLogoImage; int m_currentProfileIndex = 0; }; diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index a541dd0..202b311 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -122,6 +123,34 @@ void LauncherCore::refreshNews() fetchNews(); } +void LauncherCore::refreshLogoImage() +{ + const QDir cacheDir = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::CacheLocation).last(); + + QFileInfo logoImageFile(cacheDir.absoluteFilePath(QStringLiteral("logo.png"))); + if (logoImageFile.exists()) { + m_cachedLogoImage = logoImageFile.absoluteFilePath(); + Q_EMIT cachedLogoImageChanged(); + return; + } + + for (int i = 0; i < m_profileManager->numProfiles(); i++) { + auto profile = m_profileManager->getProfile(i); + if (profile->isGameInstalled() && profile->gameData()) { + auto file = physis_gamedata_extract_file(profile->gameData(), "ui/uld/Title_Logo.tex"); + auto tex = physis_texture_parse(file); + + QImage image(tex.rgba, tex.width, tex.height, QImage::Format_RGBA8888); + image.save(logoImageFile.absoluteFilePath()); + + m_cachedLogoImage = logoImageFile.absoluteFilePath(); + Q_EMIT cachedLogoImageChanged(); + + return; + } + } +} + Profile *LauncherCore::currentProfile() const { return m_profileManager->getProfile(m_currentProfileIndex); @@ -246,6 +275,11 @@ Headline *LauncherCore::headline() const return m_headline; } +QString LauncherCore::cachedLogoImage() const +{ + return m_cachedLogoImage; +} + QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info) { info.profile->account()->updateConfig(); diff --git a/launcher/ui/Pages/LoginPage.qml b/launcher/ui/Pages/LoginPage.qml index dc11c53..82a82e0 100644 --- a/launcher/ui/Pages/LoginPage.qml +++ b/launcher/ui/Pages/LoginPage.qml @@ -75,6 +75,7 @@ QQC2.Control { function onCurrentProfileChanged() { page.updateFields(); + LauncherCore.refreshLogoImage(); } } @@ -103,11 +104,25 @@ QQC2.Control { spacing: Kirigami.Units.largeSpacing + Image { + readonly property real aspectRatio: sourceSize.height / sourceSize.width + + fillMode: Image.PreserveAspectFit + source: "file://" + LauncherCore.cachedLogoImage + verticalAlignment: Image.AlignTop + sourceClipRect: Qt.rect(0, sourceSize.height / 2, sourceSize.width, sourceSize.height / 2) + + Component.onCompleted: LauncherCore.refreshLogoImage() + Layout.preferredWidth: parent.width + Layout.preferredHeight: width * aspectRatio + } + FormCard.FormCard { maximumWidth: Kirigami.Units.gridUnit * 25 visible: LauncherCore.profileManager.numProfiles > 1 Layout.fillWidth: true + Layout.fillHeight: true FormCard.FormButtonDelegate { id: currentProfileDelegate @@ -263,6 +278,7 @@ QQC2.Control { FormCard.FormDelegateSeparator { above: loginButton below: forgotPasswordButton + visible: !LauncherCore.currentProfile.account.isSapphire } FormCard.FormButtonDelegate {