Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into import
This commit is contained in:
commit
0b74b3833a
18
flake.lock
18
flake.lock
@ -21,11 +21,11 @@
|
|||||||
"nixpkgs-lib": "nixpkgs-lib"
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688254665,
|
"lastModified": 1688466019,
|
||||||
"narHash": "sha256-8FHEgBrr7gYNiS/NzCxIO3m4hvtLRW9YY1nYo1ivm3o=",
|
"narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "flake-parts",
|
"repo": "flake-parts",
|
||||||
"rev": "267149c58a14d15f7f81b4d737308421de9d7152",
|
"rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -91,11 +91,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688221086,
|
"lastModified": 1689413807,
|
||||||
"narHash": "sha256-cdW6qUL71cNWhHCpMPOJjlw0wzSRP0pVlRn2vqX/VVg=",
|
"narHash": "sha256-exuzOvOhGAEKWQKwDuZAL4N8a1I837hH5eocaTcIbLc=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "cd99c2b3c9f160cd004318e0697f90bbd5960825",
|
"rev": "46ed466081b9cad1125b11f11a2af5cc40b942c7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -138,11 +138,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688386108,
|
"lastModified": 1689328505,
|
||||||
"narHash": "sha256-Vffto9QaVonzYAcPlAzd0soqWYpPpKk60dfNLSIXcFA=",
|
"narHash": "sha256-9B3+OeUn1a/CvzE3GW6nWNwS5J7PDHTyHGlpL3wV5oA=",
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "pre-commit-hooks.nix",
|
"repo": "pre-commit-hooks.nix",
|
||||||
"rev": "42587d3414d1747999a5f71e92a83cf6547b62da",
|
"rev": "5e28316db471d1ac234beb70031b635437421dd6",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -1186,7 +1186,17 @@ QIcon Application::getThemedIcon(const QString& name)
|
|||||||
return QIcon::fromTheme(name);
|
return QIcon::fromTheme(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::openJsonEditor(const QString &filename)
|
QList<CatPack*> Application::getValidCatPacks()
|
||||||
|
{
|
||||||
|
return m_themeManager->getValidCatPacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Application::getCatPack(QString catName)
|
||||||
|
{
|
||||||
|
return m_themeManager->getCatPack(catName);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::openJsonEditor(const QString& filename)
|
||||||
{
|
{
|
||||||
const QString file = QDir::current().absoluteFilePath(filename);
|
const QString file = QDir::current().absoluteFilePath(filename);
|
||||||
if (m_settings->get("JsonEditor").toString().isEmpty())
|
if (m_settings->get("JsonEditor").toString().isEmpty())
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
#include <BaseInstance.h>
|
#include <BaseInstance.h>
|
||||||
|
|
||||||
#include "minecraft/launch/MinecraftServerTarget.h"
|
#include "minecraft/launch/MinecraftServerTarget.h"
|
||||||
|
#include "ui/themes/CatPack.h"
|
||||||
|
|
||||||
class LaunchController;
|
class LaunchController;
|
||||||
class LocalPeer;
|
class LocalPeer;
|
||||||
@ -126,9 +127,11 @@ public:
|
|||||||
|
|
||||||
void setApplicationTheme(const QString& name);
|
void setApplicationTheme(const QString& name);
|
||||||
|
|
||||||
shared_qobject_ptr<ExternalUpdater> updater() {
|
QList<CatPack*> getValidCatPacks();
|
||||||
return m_updater;
|
|
||||||
}
|
QString getCatPack(QString catName = "");
|
||||||
|
|
||||||
|
shared_qobject_ptr<ExternalUpdater> updater() { return m_updater; }
|
||||||
|
|
||||||
void triggerUpdateCheck();
|
void triggerUpdateCheck();
|
||||||
|
|
||||||
|
@ -766,6 +766,8 @@ SET(LAUNCHER_SOURCES
|
|||||||
ui/themes/SystemTheme.h
|
ui/themes/SystemTheme.h
|
||||||
ui/themes/ThemeManager.cpp
|
ui/themes/ThemeManager.cpp
|
||||||
ui/themes/ThemeManager.h
|
ui/themes/ThemeManager.h
|
||||||
|
ui/themes/CatPack.cpp
|
||||||
|
ui/themes/CatPack.h
|
||||||
|
|
||||||
# Processes
|
# Processes
|
||||||
LaunchController.h
|
LaunchController.h
|
||||||
|
@ -26,6 +26,7 @@ bool AuthSession::MakeOffline(QString offline_playername)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
session = "-";
|
session = "-";
|
||||||
|
access_token = "0";
|
||||||
player_name = offline_playername;
|
player_name = offline_playername;
|
||||||
status = PlayableOffline;
|
status = PlayableOffline;
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include "MinecraftAccount.h"
|
#include "MinecraftAccount.h"
|
||||||
|
|
||||||
|
#include <QCryptographicHash>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
@ -100,7 +101,7 @@ MinecraftAccountPtr MinecraftAccount::createOffline(const QString &username)
|
|||||||
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
||||||
account->data.minecraftEntitlement.ownsMinecraft = true;
|
account->data.minecraftEntitlement.ownsMinecraft = true;
|
||||||
account->data.minecraftEntitlement.canPlayMinecraft = true;
|
account->data.minecraftEntitlement.canPlayMinecraft = true;
|
||||||
account->data.minecraftProfile.id = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(QRegularExpression("[{}-]"));
|
||||||
account->data.minecraftProfile.name = username;
|
account->data.minecraftProfile.name = username;
|
||||||
account->data.minecraftProfile.validity = Katabasis::Validity::Certain;
|
account->data.minecraftProfile.validity = Katabasis::Validity::Certain;
|
||||||
return account;
|
return account;
|
||||||
@ -334,3 +335,32 @@ void MinecraftAccount::incrementUses()
|
|||||||
qWarning() << "Profile" << data.profileId() << "is now in use.";
|
qWarning() << "Profile" << data.profileId() << "is now in use.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QUuid MinecraftAccount::uuidFromUsername(QString username) {
|
||||||
|
auto input = QString("OfflinePlayer:%1").arg(username).toUtf8();
|
||||||
|
|
||||||
|
// basically a reimplementation of Java's UUID#nameUUIDFromBytes
|
||||||
|
QByteArray digest = QCryptographicHash::hash(input, QCryptographicHash::Md5);
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
auto bOr = [](QByteArray& array, int index, char value) {
|
||||||
|
array[index] = array.at(index) | value;
|
||||||
|
};
|
||||||
|
auto bAnd = [](QByteArray& array, int index, char value) {
|
||||||
|
array[index] = array.at(index) & value;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
auto bOr = [](QByteArray& array, qsizetype index, char value) {
|
||||||
|
array[index] |= value;
|
||||||
|
};
|
||||||
|
auto bAnd = [](QByteArray& array, qsizetype index, char value) {
|
||||||
|
array[index] &= value;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
bAnd(digest, 6, (char) 0x0f); // clear version
|
||||||
|
bOr(digest, 6, (char) 0x30); // set to version 3
|
||||||
|
bAnd(digest, 8, (char) 0x3f); // clear variant
|
||||||
|
bOr(digest, 8, (char) 0x80); // set to IETF variant
|
||||||
|
|
||||||
|
return QUuid::fromRfc4122(digest);
|
||||||
|
}
|
||||||
|
@ -98,6 +98,8 @@ public: /* construction */
|
|||||||
static MinecraftAccountPtr loadFromJsonV2(const QJsonObject &json);
|
static MinecraftAccountPtr loadFromJsonV2(const QJsonObject &json);
|
||||||
static MinecraftAccountPtr loadFromJsonV3(const QJsonObject &json);
|
static MinecraftAccountPtr loadFromJsonV3(const QJsonObject &json);
|
||||||
|
|
||||||
|
static QUuid uuidFromUsername(QString username);
|
||||||
|
|
||||||
//! Saves a MinecraftAccount to a JSON object and returns it.
|
//! Saves a MinecraftAccount to a JSON object and returns it.
|
||||||
QJsonObject saveToJson() const;
|
QJsonObject saveToJson() const;
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
#include <QAccessible>
|
#include <QAccessible>
|
||||||
|
|
||||||
#include "VisualGroup.h"
|
#include "VisualGroup.h"
|
||||||
#include "ui/themes/ThemeManager.h"
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@ -504,7 +503,7 @@ void InstanceView::setPaintCat(bool visible)
|
|||||||
{
|
{
|
||||||
m_catVisible = visible;
|
m_catVisible = visible;
|
||||||
if (visible)
|
if (visible)
|
||||||
m_catPixmap.load(QString(":/backgrounds/%1").arg(ThemeManager::getCatImage()));
|
m_catPixmap.load(APPLICATION->getCatPack());
|
||||||
else
|
else
|
||||||
m_catPixmap = QPixmap();
|
m_catPixmap = QPixmap();
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ void ThemeWizardPage::updateIcons()
|
|||||||
void ThemeWizardPage::updateCat()
|
void ThemeWizardPage::updateCat()
|
||||||
{
|
{
|
||||||
qDebug() << "Setting Cat";
|
qDebug() << "Setting Cat";
|
||||||
ui->catImagePreviewButton->setIcon(QIcon(QString(R"(:/backgrounds/%1)").arg(ThemeManager::getCatImage())));
|
ui->catImagePreviewButton->setIcon(QIcon(QString(R"(%1)").arg(APPLICATION->getCatPack())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeWizardPage::retranslate()
|
void ThemeWizardPage::retranslate()
|
||||||
|
117
launcher/ui/themes/CatPack.cpp
Normal file
117
launcher/ui/themes/CatPack.cpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following copyright and
|
||||||
|
* permission notice:
|
||||||
|
*
|
||||||
|
* Copyright 2013-2021 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ui/themes/CatPack.h"
|
||||||
|
#include <QDate>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "Json.h"
|
||||||
|
|
||||||
|
QString BasicCatPack::path()
|
||||||
|
{
|
||||||
|
const auto now = QDate::currentDate();
|
||||||
|
const auto birthday = QDate(now.year(), 11, 30);
|
||||||
|
const auto xmas = QDate(now.year(), 12, 25);
|
||||||
|
const auto halloween = QDate(now.year(), 10, 31);
|
||||||
|
|
||||||
|
QString cat = QString(":/backgrounds/%1").arg(m_id);
|
||||||
|
if (std::abs(now.daysTo(xmas)) <= 4) {
|
||||||
|
cat += "-xmas";
|
||||||
|
} else if (std::abs(now.daysTo(halloween)) <= 4) {
|
||||||
|
cat += "-spooky";
|
||||||
|
} else if (std::abs(now.daysTo(birthday)) <= 12) {
|
||||||
|
cat += "-bday";
|
||||||
|
}
|
||||||
|
return cat;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonCatPack::PartialDate partialDate(QJsonObject date)
|
||||||
|
{
|
||||||
|
auto month = Json::ensureInteger(date, "month", 1);
|
||||||
|
if (month > 12)
|
||||||
|
month = 12;
|
||||||
|
else if (month <= 0)
|
||||||
|
month = 1;
|
||||||
|
auto day = Json::ensureInteger(date, "day", 1);
|
||||||
|
if (day > 31)
|
||||||
|
day = 31;
|
||||||
|
else if (day <= 0)
|
||||||
|
day = 1;
|
||||||
|
return { month, day };
|
||||||
|
};
|
||||||
|
|
||||||
|
JsonCatPack::JsonCatPack(QFileInfo& manifestInfo) : BasicCatPack(manifestInfo.dir().dirName())
|
||||||
|
{
|
||||||
|
QString path = manifestInfo.path();
|
||||||
|
auto doc = Json::requireDocument(manifestInfo.absoluteFilePath(), "CatPack JSON file");
|
||||||
|
const auto root = doc.object();
|
||||||
|
m_name = Json::requireString(root, "name", "Catpack name");
|
||||||
|
m_defaultPath = FS::PathCombine(path, Json::requireString(root, "default", "Default Cat"));
|
||||||
|
auto variants = Json::ensureArray(root, "variants", QJsonArray(), "Catpack Variants");
|
||||||
|
for (auto v : variants) {
|
||||||
|
auto variant = Json::ensureObject(v, QJsonObject(), "Cat variant");
|
||||||
|
m_variants << Variant{ FS::PathCombine(path, Json::requireString(variant, "path", "Variant path")),
|
||||||
|
partialDate(Json::requireObject(variant, "startTime", "Variant startTime")),
|
||||||
|
partialDate(Json::requireObject(variant, "endTime", "Variant endTime")) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate ensureDay(int year, int month, int day)
|
||||||
|
{
|
||||||
|
QDate date(year, month, 1);
|
||||||
|
if (day > date.daysInMonth())
|
||||||
|
day = date.daysInMonth();
|
||||||
|
return QDate(year, month, day);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString JsonCatPack::path()
|
||||||
|
{
|
||||||
|
const QDate now = QDate::currentDate();
|
||||||
|
for (auto var : m_variants) {
|
||||||
|
QDate startDate = ensureDay(now.year(), var.startTime.month, var.startTime.day);
|
||||||
|
QDate endDate = ensureDay(now.year(), var.endTime.month, var.endTime.day);
|
||||||
|
if (startDate > endDate) { // it's spans over multiple years
|
||||||
|
if (endDate <= now) // end date is in the past so jump one year into the future for endDate
|
||||||
|
endDate = endDate.addYears(1);
|
||||||
|
else // end date is in the future so jump one year into the past for startDate
|
||||||
|
startDate = startDate.addYears(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startDate >= now && now >= endDate)
|
||||||
|
return var.path;
|
||||||
|
}
|
||||||
|
return m_defaultPath;
|
||||||
|
}
|
91
launcher/ui/themes/CatPack.h
Normal file
91
launcher/ui/themes/CatPack.h
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following copyright and
|
||||||
|
* permission notice:
|
||||||
|
*
|
||||||
|
* Copyright 2013-2021 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDate>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QList>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class CatPack {
|
||||||
|
public:
|
||||||
|
virtual ~CatPack() {}
|
||||||
|
virtual QString id() = 0;
|
||||||
|
virtual QString name() = 0;
|
||||||
|
virtual QString path() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BasicCatPack : public CatPack {
|
||||||
|
public:
|
||||||
|
BasicCatPack(QString id, QString name) : m_id(id), m_name(name) {}
|
||||||
|
BasicCatPack(QString id) : BasicCatPack(id, id) {}
|
||||||
|
virtual QString id() { return m_id; };
|
||||||
|
virtual QString name() { return m_name; };
|
||||||
|
virtual QString path();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString m_id;
|
||||||
|
QString m_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileCatPack : public BasicCatPack {
|
||||||
|
public:
|
||||||
|
FileCatPack(QString id, QFileInfo& fileInfo) : BasicCatPack(id), m_path(fileInfo.absoluteFilePath()) {}
|
||||||
|
FileCatPack(QFileInfo& fileInfo) : FileCatPack(fileInfo.baseName(), fileInfo) {}
|
||||||
|
virtual QString path() { return m_path; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_path;
|
||||||
|
};
|
||||||
|
|
||||||
|
class JsonCatPack : public BasicCatPack {
|
||||||
|
public:
|
||||||
|
struct PartialDate {
|
||||||
|
int month;
|
||||||
|
int day;
|
||||||
|
};
|
||||||
|
struct Variant {
|
||||||
|
QString path;
|
||||||
|
PartialDate startTime;
|
||||||
|
PartialDate endTime;
|
||||||
|
};
|
||||||
|
JsonCatPack(QFileInfo& manifestInfo);
|
||||||
|
virtual QString path();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_defaultPath;
|
||||||
|
QList<Variant> m_variants;
|
||||||
|
};
|
@ -21,7 +21,10 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QImageReader>
|
||||||
|
#include "Exception.h"
|
||||||
#include "ui/themes/BrightTheme.h"
|
#include "ui/themes/BrightTheme.h"
|
||||||
|
#include "ui/themes/CatPack.h"
|
||||||
#include "ui/themes/CustomTheme.h"
|
#include "ui/themes/CustomTheme.h"
|
||||||
#include "ui/themes/DarkTheme.h"
|
#include "ui/themes/DarkTheme.h"
|
||||||
#include "ui/themes/SystemTheme.h"
|
#include "ui/themes/SystemTheme.h"
|
||||||
@ -32,6 +35,7 @@ ThemeManager::ThemeManager(MainWindow* mainWindow)
|
|||||||
{
|
{
|
||||||
m_mainWindow = mainWindow;
|
m_mainWindow = mainWindow;
|
||||||
initializeThemes();
|
initializeThemes();
|
||||||
|
initializeCatPacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Adds the Theme to the list of themes
|
/// @brief Adds the Theme to the list of themes
|
||||||
@ -40,7 +44,10 @@ ThemeManager::ThemeManager(MainWindow* mainWindow)
|
|||||||
QString ThemeManager::addTheme(std::unique_ptr<ITheme> theme)
|
QString ThemeManager::addTheme(std::unique_ptr<ITheme> theme)
|
||||||
{
|
{
|
||||||
QString id = theme->id();
|
QString id = theme->id();
|
||||||
m_themes.emplace(id, std::move(theme));
|
if (m_themes.find(id) == m_themes.end())
|
||||||
|
m_themes.emplace(id, std::move(theme));
|
||||||
|
else
|
||||||
|
themeWarningLog() << "Theme(" << id << ") not added to prevent id duplication";
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +84,7 @@ void ThemeManager::initializeThemes()
|
|||||||
QString themeFolder = QDir("./themes/").absoluteFilePath("");
|
QString themeFolder = QDir("./themes/").absoluteFilePath("");
|
||||||
themeDebugLog() << "Theme Folder Path: " << themeFolder;
|
themeDebugLog() << "Theme Folder Path: " << themeFolder;
|
||||||
|
|
||||||
QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
while (directoryIterator.hasNext()) {
|
while (directoryIterator.hasNext()) {
|
||||||
QDir dir(directoryIterator.next());
|
QDir dir(directoryIterator.next());
|
||||||
QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
|
QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
|
||||||
@ -111,6 +118,16 @@ QList<ITheme*> ThemeManager::getValidApplicationThemes()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<CatPack*> ThemeManager::getValidCatPacks()
|
||||||
|
{
|
||||||
|
QList<CatPack*> ret;
|
||||||
|
ret.reserve(m_catPacks.size());
|
||||||
|
for (auto&& [id, theme] : m_catPacks) {
|
||||||
|
ret.append(theme.get());
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void ThemeManager::setIconTheme(const QString& name)
|
void ThemeManager::setIconTheme(const QString& name)
|
||||||
{
|
{
|
||||||
QIcon::setThemeName(name);
|
QIcon::setThemeName(name);
|
||||||
@ -137,19 +154,74 @@ void ThemeManager::setApplicationTheme(const QString& name, bool initial)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ThemeManager::getCatImage(QString catName)
|
QString ThemeManager::getCatPack(QString catName)
|
||||||
{
|
{
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
auto catIter = m_catPacks.find(!catName.isEmpty() ? catName : APPLICATION->settings()->get("BackgroundCat").toString());
|
||||||
QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0));
|
if (catIter != m_catPacks.end()) {
|
||||||
QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
|
auto& catPack = catIter->second;
|
||||||
QDateTime halloween(QDate(now.date().year(), 10, 31), QTime(0, 0));
|
themeDebugLog() << "applying catpack" << catPack->id();
|
||||||
QString cat = !catName.isEmpty() ? catName : APPLICATION->settings()->get("BackgroundCat").toString();
|
return catPack->path();
|
||||||
if (std::abs(now.daysTo(xmas)) <= 4) {
|
} else {
|
||||||
cat += "-xmas";
|
themeWarningLog() << "Tried to get invalid catPack:" << catName;
|
||||||
} else if (std::abs(now.daysTo(halloween)) <= 4) {
|
}
|
||||||
cat += "-spooky";
|
|
||||||
} else if (std::abs(now.daysTo(birthday)) <= 12) {
|
return m_catPacks.begin()->second->path();
|
||||||
cat += "-bday";
|
}
|
||||||
|
|
||||||
|
QString ThemeManager::addCatPack(std::unique_ptr<CatPack> catPack)
|
||||||
|
{
|
||||||
|
QString id = catPack->id();
|
||||||
|
if (m_catPacks.find(id) == m_catPacks.end())
|
||||||
|
m_catPacks.emplace(id, std::move(catPack));
|
||||||
|
else
|
||||||
|
themeWarningLog() << "CatPack(" << id << ") not added to prevent id duplication";
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThemeManager::initializeCatPacks()
|
||||||
|
{
|
||||||
|
QList<std::pair<QString, QString>> defaultCats{ { "kitteh", QObject::tr("Background Cat (from MultiMC)") },
|
||||||
|
{ "rory", QObject::tr("Rory ID 11 (drawn by Ashtaka)") },
|
||||||
|
{ "rory-flat", QObject::tr("Rory ID 11 (flat edition, drawn by Ashtaka)") },
|
||||||
|
{ "teawie", QObject::tr("Teawie (drawn by SympathyTea)") } };
|
||||||
|
for (auto [id, name] : defaultCats) {
|
||||||
|
addCatPack(std::unique_ptr<CatPack>(new BasicCatPack(id, name)));
|
||||||
|
}
|
||||||
|
QDir catpacksDir("catpacks");
|
||||||
|
QString catpacksFolder = catpacksDir.absoluteFilePath("");
|
||||||
|
themeDebugLog() << "CatPacks Folder Path:" << catpacksFolder;
|
||||||
|
|
||||||
|
QStringList supportedImageFormats;
|
||||||
|
for (auto format : QImageReader::supportedImageFormats()) {
|
||||||
|
supportedImageFormats.append("*." + format);
|
||||||
|
}
|
||||||
|
auto loadFiles = [this, supportedImageFormats](QDir dir) {
|
||||||
|
// Load image files directly
|
||||||
|
QDirIterator ImageFileIterator(dir.absoluteFilePath(""), supportedImageFormats, QDir::Files);
|
||||||
|
while (ImageFileIterator.hasNext()) {
|
||||||
|
QFile customCatFile(ImageFileIterator.next());
|
||||||
|
QFileInfo customCatFileInfo(customCatFile);
|
||||||
|
themeDebugLog() << "Loading CatPack from:" << customCatFileInfo.absoluteFilePath();
|
||||||
|
addCatPack(std::unique_ptr<CatPack>(new FileCatPack(customCatFileInfo)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadFiles(catpacksDir);
|
||||||
|
|
||||||
|
QDirIterator directoryIterator(catpacksFolder, QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
|
while (directoryIterator.hasNext()) {
|
||||||
|
QDir dir(directoryIterator.next());
|
||||||
|
QFileInfo manifest(dir.absoluteFilePath("catpack.json"));
|
||||||
|
if (manifest.isFile()) {
|
||||||
|
try {
|
||||||
|
// Load background manifest
|
||||||
|
themeDebugLog() << "Loading background manifest from:" << manifest.absoluteFilePath();
|
||||||
|
addCatPack(std::unique_ptr<CatPack>(new JsonCatPack(manifest)));
|
||||||
|
} catch (const Exception& e) {
|
||||||
|
themeWarningLog() << "Couldn't load catpack json:" << e.cause();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loadFiles(dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cat;
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "ui/MainWindow.h"
|
#include "ui/MainWindow.h"
|
||||||
|
#include "ui/themes/CatPack.h"
|
||||||
#include "ui/themes/ITheme.h"
|
#include "ui/themes/ITheme.h"
|
||||||
|
|
||||||
inline auto themeDebugLog()
|
inline auto themeDebugLog()
|
||||||
@ -40,18 +41,20 @@ class ThemeManager {
|
|||||||
void applyCurrentlySelectedTheme(bool initial = false);
|
void applyCurrentlySelectedTheme(bool initial = false);
|
||||||
void setApplicationTheme(const QString& name, bool initial = false);
|
void setApplicationTheme(const QString& name, bool initial = false);
|
||||||
|
|
||||||
/// <summary>
|
/// @brief Returns the background based on selected and with events (Birthday, XMas, etc.)
|
||||||
/// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)
|
/// @param catName Optional, if you need a specific background.
|
||||||
/// </summary>
|
/// @return
|
||||||
/// <param name="catName">Optional, if you need a specific cat.</param>
|
QString getCatPack(QString catName = "");
|
||||||
/// <returns></returns>
|
QList<CatPack*> getValidCatPacks();
|
||||||
static QString getCatImage(QString catName = "");
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
||||||
|
std::map<QString, std::unique_ptr<CatPack>> m_catPacks;
|
||||||
MainWindow* m_mainWindow;
|
MainWindow* m_mainWindow;
|
||||||
|
|
||||||
void initializeThemes();
|
void initializeThemes();
|
||||||
|
void initializeCatPacks();
|
||||||
QString addTheme(std::unique_ptr<ITheme> theme);
|
QString addTheme(std::unique_ptr<ITheme> theme);
|
||||||
ITheme* getTheme(QString themeId);
|
ITheme* getTheme(QString themeId);
|
||||||
|
QString addCatPack(std::unique_ptr<CatPack> catPack);
|
||||||
};
|
};
|
||||||
|
@ -95,9 +95,14 @@ void ThemeCustomizationWidget::applyWidgetTheme(int index) {
|
|||||||
emit currentWidgetThemeChanged(index);
|
emit currentWidgetThemeChanged(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeCustomizationWidget::applyCatTheme(int index) {
|
void ThemeCustomizationWidget::applyCatTheme(int index)
|
||||||
|
{
|
||||||
auto settings = APPLICATION->settings();
|
auto settings = APPLICATION->settings();
|
||||||
settings->set("BackgroundCat", m_catOptions[index].first);
|
auto originalCat = settings->get("BackgroundCat").toString();
|
||||||
|
auto newCat = ui->backgroundCatComboBox->currentData().toString();
|
||||||
|
if (originalCat != newCat) {
|
||||||
|
settings->set("BackgroundCat", newCat);
|
||||||
|
}
|
||||||
|
|
||||||
emit currentCatChanged(index);
|
emit currentCatChanged(index);
|
||||||
}
|
}
|
||||||
@ -135,10 +140,10 @@ void ThemeCustomizationWidget::loadSettings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto cat = settings->get("BackgroundCat").toString();
|
auto cat = settings->get("BackgroundCat").toString();
|
||||||
for (auto& catFromList : m_catOptions) {
|
for (auto& catFromList : APPLICATION->getValidCatPacks()) {
|
||||||
QIcon catIcon = QIcon(QString(":/backgrounds/%1").arg(ThemeManager::getCatImage(catFromList.first)));
|
QIcon catIcon = QIcon(QString("%1").arg(catFromList->path()));
|
||||||
ui->backgroundCatComboBox->addItem(catIcon, catFromList.second);
|
ui->backgroundCatComboBox->addItem(catIcon, catFromList->name(), catFromList->id());
|
||||||
if (cat == catFromList.first) {
|
if (cat == catFromList->id()) {
|
||||||
ui->backgroundCatComboBox->setCurrentIndex(ui->backgroundCatComboBox->count() - 1);
|
ui->backgroundCatComboBox->setCurrentIndex(ui->backgroundCatComboBox->count() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,25 +53,17 @@ class ThemeCustomizationWidget : public QWidget {
|
|||||||
private:
|
private:
|
||||||
Ui::ThemeCustomizationWidget* ui;
|
Ui::ThemeCustomizationWidget* ui;
|
||||||
|
|
||||||
//TODO finish implementing
|
// TODO finish implementing
|
||||||
QList<std::pair<QString, QString>> m_iconThemeOptions{
|
QList<std::pair<QString, QString>> m_iconThemeOptions{ { "pe_colored", QObject::tr("Simple (Colored Icons)") },
|
||||||
{ "pe_colored", QObject::tr("Simple (Colored Icons)") },
|
{ "pe_light", QObject::tr("Simple (Light Icons)") },
|
||||||
{ "pe_light", QObject::tr("Simple (Light Icons)") },
|
{ "pe_dark", QObject::tr("Simple (Dark Icons)") },
|
||||||
{ "pe_dark", QObject::tr("Simple (Dark Icons)") },
|
{ "pe_blue", QObject::tr("Simple (Blue Icons)") },
|
||||||
{ "pe_blue", QObject::tr("Simple (Blue Icons)") },
|
{ "breeze_light", QObject::tr("Breeze Light") },
|
||||||
{ "breeze_light", QObject::tr("Breeze Light") },
|
{ "breeze_dark", QObject::tr("Breeze Dark") },
|
||||||
{ "breeze_dark", QObject::tr("Breeze Dark") },
|
{ "OSX", QObject::tr("OSX") },
|
||||||
{ "OSX", QObject::tr("OSX") },
|
{ "iOS", QObject::tr("iOS") },
|
||||||
{ "iOS", QObject::tr("iOS") },
|
{ "flat", QObject::tr("Flat") },
|
||||||
{ "flat", QObject::tr("Flat") },
|
{ "flat_white", QObject::tr("Flat (White)") },
|
||||||
{ "flat_white", QObject::tr("Flat (White)") },
|
{ "multimc", QObject::tr("Legacy") },
|
||||||
{ "multimc", QObject::tr("Legacy") },
|
{ "custom", QObject::tr("Custom") } };
|
||||||
{ "custom", QObject::tr("Custom") }
|
|
||||||
};
|
|
||||||
QList<std::pair<QString, QString>> m_catOptions{
|
|
||||||
{ "kitteh", QObject::tr("Background Cat (from MultiMC)") },
|
|
||||||
{ "rory", QObject::tr("Rory ID 11 (drawn by Ashtaka)") },
|
|
||||||
{ "rory-flat", QObject::tr("Rory ID 11 (flat edition, drawn by Ashtaka)") },
|
|
||||||
{ "teawie", QObject::tr("Teawie (drawn by SympathyTea)") }
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user