diff options
author | fearlessTobi <thm.frey@gmail.com> | 2018-08-29 15:42:53 +0200 |
---|---|---|
committer | fearlessTobi <thm.frey@gmail.com> | 2018-08-29 15:42:53 +0200 |
commit | 78653f73398b98071fe9bb4b4a32ec68f674ccfd (patch) | |
tree | bb6ba70e7bad5a53cb9655787ec8ebaf5495285f /src/yuzu/game_list_p.h | |
parent | 0d2435343a2acf114430a662192eb22470b53d62 (diff) |
Show game compatibility within yuzu
Diffstat (limited to 'src/yuzu/game_list_p.h')
-rw-r--r-- | src/yuzu/game_list_p.h | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/src/yuzu/game_list_p.h b/src/yuzu/game_list_p.h index 1d6c85400..b9676d069 100644 --- a/src/yuzu/game_list_p.h +++ b/src/yuzu/game_list_p.h @@ -8,11 +8,15 @@ #include <atomic> #include <map> #include <memory> +#include <unordered_map> #include <utility> +#include <QCoreApplication> #include <QImage> +#include <QObject> #include <QRunnable> #include <QStandardItem> #include <QString> +#include "common/logging/log.h" #include "common/string_util.h" #include "core/file_sys/content_archive.h" #include "ui_settings.h" @@ -29,6 +33,17 @@ static QPixmap GetDefaultIcon(u32 size) { return icon; } +static auto FindMatchingCompatibilityEntry( + const std::unordered_map<std::string, std::pair<QString, QString>>& compatibility_list, + u64 program_id) { + return std::find_if( + compatibility_list.begin(), compatibility_list.end(), + [program_id](const std::pair<std::string, std::pair<QString, QString>>& element) { + std::string pid = fmt::format("{:016X}", program_id); + return element.first == pid; + }); +} + class GameListItem : public QStandardItem { public: @@ -96,6 +111,45 @@ public: } }; +class GameListItemCompat : public GameListItem { + Q_DECLARE_TR_FUNCTIONS(GameListItemCompat) +public: + static const int CompatNumberRole = Qt::UserRole + 1; + GameListItemCompat() = default; + explicit GameListItemCompat(const QString& compatiblity) { + struct CompatStatus { + QString color; + const char* text; + const char* tooltip; + }; + // clang-format off + static const std::map<QString, CompatStatus> status_data = { + {"0", {"#5c93ed", QT_TR_NOOP("Perfect"), QT_TR_NOOP("Game functions flawless with no audio or graphical glitches, all tested functionality works as intended without\nany workarounds needed.")}}, + {"1", {"#47d35c", QT_TR_NOOP("Great"), QT_TR_NOOP("Game functions with minor graphical or audio glitches and is playable from start to finish. May require some\nworkarounds.")}}, + {"2", {"#94b242", QT_TR_NOOP("Okay"), QT_TR_NOOP("Game functions with major graphical or audio glitches, but game is playable from start to finish with\nworkarounds.")}}, + {"3", {"#f2d624", QT_TR_NOOP("Bad"), QT_TR_NOOP("Game functions, but with major graphical or audio glitches. Unable to progress in specific areas due to glitches\neven with workarounds.")}}, + {"4", {"#FF0000", QT_TR_NOOP("Intro/Menu"), QT_TR_NOOP("Game is completely unplayable due to major graphical or audio glitches. Unable to progress past the Start\nScreen.")}}, + {"5", {"#828282", QT_TR_NOOP("Won't Boot"), QT_TR_NOOP("The game crashes when attempting to startup.")}}, + {"99", {"#000000", QT_TR_NOOP("Not Tested"), QT_TR_NOOP("The game has not yet been tested.")}}}; + // clang-format on + + auto iterator = status_data.find(compatiblity); + if (iterator == status_data.end()) { + LOG_WARNING(Frontend, "Invalid compatibility number {}", compatiblity.toStdString()); + return; + } + CompatStatus status = iterator->second; + setData(compatiblity, CompatNumberRole); + setText(QObject::tr(status.text)); + setToolTip(QObject::tr(status.tooltip)); + setData(CreateCirclePixmapFromColor(status.color), Qt::DecorationRole); + } + + bool operator<(const QStandardItem& other) const override { + return data(CompatNumberRole) < other.data(CompatNumberRole); + } +}; + /** * A specialization of GameListItem for size values. * This class ensures that for every numerical size value it holds (in bytes), a correct @@ -141,8 +195,11 @@ class GameListWorker : public QObject, public QRunnable { Q_OBJECT public: - GameListWorker(FileSys::VirtualFilesystem vfs, QString dir_path, bool deep_scan) - : vfs(std::move(vfs)), dir_path(std::move(dir_path)), deep_scan(deep_scan) {} + GameListWorker( + FileSys::VirtualFilesystem vfs, QString dir_path, bool deep_scan, + const std::unordered_map<std::string, std::pair<QString, QString>>& compatibility_list) + : vfs(std::move(vfs)), dir_path(std::move(dir_path)), deep_scan(deep_scan), + compatibility_list(compatibility_list) {} public slots: /// Starts the processing of directory tree information. @@ -170,6 +227,7 @@ private: QStringList watch_list; QString dir_path; bool deep_scan; + const std::unordered_map<std::string, std::pair<QString, QString>>& compatibility_list; std::atomic_bool stop_processing; void AddInstalledTitlesToGameList(std::shared_ptr<FileSys::RegisteredCache> cache); |