1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-06-07 22:47:46 +00:00

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.
This commit is contained in:
Joshua Goins 2024-03-22 20:12:06 -04:00
parent f97204a422
commit 001e20b1b8
4 changed files with 56 additions and 1 deletions

View file

@ -13,7 +13,7 @@ find_package(Corrosion REQUIRED)
corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libphysis/Cargo.toml corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libphysis/Cargo.toml
NO_DEFAULT_FEATURES 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) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libphysis/logger EXCLUDE_FROM_ALL)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)

View file

@ -67,6 +67,7 @@ class LauncherCore : public QObject
Q_PROPERTY(Headline *headline READ headline NOTIFY newsChanged) Q_PROPERTY(Headline *headline READ headline NOTIFY newsChanged)
Q_PROPERTY(Profile *currentProfile READ currentProfile WRITE setCurrentProfile NOTIFY currentProfileChanged) Q_PROPERTY(Profile *currentProfile READ currentProfile WRITE setCurrentProfile NOTIFY currentProfileChanged)
Q_PROPERTY(Profile *autoLoginProfile READ autoLoginProfile WRITE setAutoLoginProfile NOTIFY autoLoginProfileChanged) Q_PROPERTY(Profile *autoLoginProfile READ autoLoginProfile WRITE setAutoLoginProfile NOTIFY autoLoginProfileChanged)
Q_PROPERTY(QString cachedLogoImage READ cachedLogoImage NOTIFY cachedLogoImageChanged)
public: public:
LauncherCore(); LauncherCore();
@ -89,6 +90,7 @@ public:
Q_INVOKABLE void clearAvatarCache(); Q_INVOKABLE void clearAvatarCache();
Q_INVOKABLE void refreshNews(); Q_INVOKABLE void refreshNews();
Q_INVOKABLE void refreshLogoImage();
[[nodiscard]] Profile *currentProfile() const; [[nodiscard]] Profile *currentProfile() const;
void setCurrentProfile(Profile *profile); void setCurrentProfile(Profile *profile);
@ -111,6 +113,7 @@ public:
[[nodiscard]] ProfileManager *profileManager(); [[nodiscard]] ProfileManager *profileManager();
[[nodiscard]] AccountManager *accountManager(); [[nodiscard]] AccountManager *accountManager();
[[nodiscard]] Headline *headline() const; [[nodiscard]] Headline *headline() const;
[[nodiscard]] QString cachedLogoImage() const;
Q_SIGNALS: Q_SIGNALS:
void loadingFinished(); void loadingFinished();
@ -124,6 +127,7 @@ Q_SIGNALS:
void newsChanged(); void newsChanged();
void currentProfileChanged(); void currentProfileChanged();
void autoLoginProfileChanged(); void autoLoginProfileChanged();
void cachedLogoImageChanged();
protected: protected:
friend class Patcher; friend class Patcher;
@ -149,6 +153,7 @@ private:
Headline *m_headline = nullptr; Headline *m_headline = nullptr;
LauncherSettings *m_settings = nullptr; LauncherSettings *m_settings = nullptr;
GameRunner *m_runner = nullptr; GameRunner *m_runner = nullptr;
QString m_cachedLogoImage;
int m_currentProfileIndex = 0; int m_currentProfileIndex = 0;
}; };

View file

@ -5,6 +5,7 @@
#include <KLocalizedString> #include <KLocalizedString>
#include <QDir> #include <QDir>
#include <QImage>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QStandardPaths> #include <QStandardPaths>
#include <algorithm> #include <algorithm>
@ -122,6 +123,34 @@ void LauncherCore::refreshNews()
fetchNews(); 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 Profile *LauncherCore::currentProfile() const
{ {
return m_profileManager->getProfile(m_currentProfileIndex); return m_profileManager->getProfile(m_currentProfileIndex);
@ -246,6 +275,11 @@ Headline *LauncherCore::headline() const
return m_headline; return m_headline;
} }
QString LauncherCore::cachedLogoImage() const
{
return m_cachedLogoImage;
}
QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info) QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info)
{ {
info.profile->account()->updateConfig(); info.profile->account()->updateConfig();

View file

@ -75,6 +75,7 @@ QQC2.Control {
function onCurrentProfileChanged() { function onCurrentProfileChanged() {
page.updateFields(); page.updateFields();
LauncherCore.refreshLogoImage();
} }
} }
@ -103,11 +104,25 @@ QQC2.Control {
spacing: Kirigami.Units.largeSpacing 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 { FormCard.FormCard {
maximumWidth: Kirigami.Units.gridUnit * 25 maximumWidth: Kirigami.Units.gridUnit * 25
visible: LauncherCore.profileManager.numProfiles > 1 visible: LauncherCore.profileManager.numProfiles > 1
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true
FormCard.FormButtonDelegate { FormCard.FormButtonDelegate {
id: currentProfileDelegate id: currentProfileDelegate
@ -263,6 +278,7 @@ QQC2.Control {
FormCard.FormDelegateSeparator { FormCard.FormDelegateSeparator {
above: loginButton above: loginButton
below: forgotPasswordButton below: forgotPasswordButton
visible: !LauncherCore.currentProfile.account.isSapphire
} }
FormCard.FormButtonDelegate { FormCard.FormButtonDelegate {