From 0587b220cc43de572cc22b1651912be28ee02ad1 Mon Sep 17 00:00:00 2001 From: Sophia Hadash Date: Sun, 26 Sep 2021 22:26:47 +0200 Subject: [PATCH 1/2] add alternative emulator badge --- es-app/src/views/gamelist/DetailedGameListView.cpp | 1 + es-app/src/views/gamelist/VideoGameListView.cpp | 1 + es-core/src/components/BadgesComponent.cpp | 9 +++++++-- es-core/src/components/BadgesComponent.h | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/es-app/src/views/gamelist/DetailedGameListView.cpp b/es-app/src/views/gamelist/DetailedGameListView.cpp index c6bb5b5aa..c62eef1b1 100644 --- a/es-app/src/views/gamelist/DetailedGameListView.cpp +++ b/es-app/src/views/gamelist/DetailedGameListView.cpp @@ -389,6 +389,7 @@ void DetailedGameListView::updateInfoPanel() ss << (file->metadata.get("completed").compare("true") ? "" : "completed "); ss << (file->metadata.get("kidgame").compare("true") ? "" : "kidgame "); ss << (file->metadata.get("broken").compare("true") ? "" : "broken "); + ss << (file->metadata.get("altemulator").compare("") ? "altemu " : ""); std::string slots = ss.str(); if (!slots.empty()) slots.pop_back(); diff --git a/es-app/src/views/gamelist/VideoGameListView.cpp b/es-app/src/views/gamelist/VideoGameListView.cpp index a6a187e0a..49b25ddd1 100644 --- a/es-app/src/views/gamelist/VideoGameListView.cpp +++ b/es-app/src/views/gamelist/VideoGameListView.cpp @@ -451,6 +451,7 @@ void VideoGameListView::updateInfoPanel() ss << (file->metadata.get("completed").compare("true") ? "" : "completed "); ss << (file->metadata.get("kidgame").compare("true") ? "" : "kidgame "); ss << (file->metadata.get("broken").compare("true") ? "" : "broken "); + ss << (file->metadata.get("altemulator").compare("") ? "altemu " : ""); std::string slots = ss.str(); if (!slots.empty()) slots.pop_back(); diff --git a/es-core/src/components/BadgesComponent.cpp b/es-core/src/components/BadgesComponent.cpp index 5b0a569be..48bcc1f78 100644 --- a/es-core/src/components/BadgesComponent.cpp +++ b/es-core/src/components/BadgesComponent.cpp @@ -14,7 +14,8 @@ #include "resources/TextureResource.h" // Available slot definitions. -const std::vector BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS, SLOT_BROKEN}; +const std::vector BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS, SLOT_BROKEN, + SLOT_ALTERNATIVE_EMULATOR}; std::map BadgesComponent::mBadgeIcons = std::map(); std::map BadgesComponent::mImageComponents = std::map(); @@ -25,6 +26,7 @@ BadgesComponent::BadgesComponent(Window *window) mBadgeIcons[SLOT_COMPLETED] = ":/graphics/badge_completed.svg"; mBadgeIcons[SLOT_KIDS] = ":/graphics/badge_kidgame.svg"; mBadgeIcons[SLOT_BROKEN] = ":/graphics/badge_broken.svg"; + mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR] = ":/graphics/badge_altemu.svg"; } @@ -42,6 +44,9 @@ BadgesComponent::BadgesComponent(Window *window) ImageComponent mImageBroken = ImageComponent(window); mImageBroken.setImage(mBadgeIcons[SLOT_BROKEN], false, true); mImageComponents.insert({SLOT_BROKEN, mImageBroken}); + ImageComponent mImageAltEmu = ImageComponent(window); + mImageAltEmu.setImage(mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR], false, true); + mImageComponents.insert({SLOT_ALTERNATIVE_EMULATOR, mImageAltEmu}); } } @@ -54,7 +59,7 @@ void BadgesComponent::setValue(const std::string& value) std::istringstream ss(value); while (std::getline(ss, temp, ' ')) { if (!(temp == SLOT_FAVORITE || temp == SLOT_COMPLETED || temp == SLOT_KIDS || - temp == SLOT_BROKEN)) + temp == SLOT_BROKEN || temp == SLOT_ALTERNATIVE_EMULATOR)) LOG(LogError) << "Badge slot '" << temp << "' is invalid."; else mChildren.push_back(&mImageComponents.find(temp)->second); diff --git a/es-core/src/components/BadgesComponent.h b/es-core/src/components/BadgesComponent.h index 79b49fc8a..6c3c1509e 100644 --- a/es-core/src/components/BadgesComponent.h +++ b/es-core/src/components/BadgesComponent.h @@ -20,6 +20,7 @@ #define SLOT_COMPLETED "completed" #define SLOT_KIDS "kidgame" #define SLOT_BROKEN "broken" +#define SLOT_ALTERNATIVE_EMULATOR "altemu" class TextureResource; From a4d4493d3ea6194bd123d2fe58122b6ab2928f6c Mon Sep 17 00:00:00 2001 From: Sophia Hadash Date: Sun, 26 Sep 2021 22:45:10 +0200 Subject: [PATCH 2/2] fix segfault on application exit --- es-core/src/components/BadgesComponent.cpp | 10 +++++++--- es-core/src/components/BadgesComponent.h | 4 +++- es-core/src/components/ImageComponent.h | 14 ++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/es-core/src/components/BadgesComponent.cpp b/es-core/src/components/BadgesComponent.cpp index 48bcc1f78..8adff44a1 100644 --- a/es-core/src/components/BadgesComponent.cpp +++ b/es-core/src/components/BadgesComponent.cpp @@ -48,11 +48,15 @@ BadgesComponent::BadgesComponent(Window *window) mImageAltEmu.setImage(mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR], false, true); mImageComponents.insert({SLOT_ALTERNATIVE_EMULATOR, mImageAltEmu}); } - } -void BadgesComponent::setValue(const std::string& value) -{ +BadgesComponent::~BadgesComponent() { + mBadgeIcons.clear(); + mImageComponents.clear(); +} + + +void BadgesComponent::setValue(const std::string &value) { mChildren.clear(); if (!value.empty()) { std::string temp; diff --git a/es-core/src/components/BadgesComponent.h b/es-core/src/components/BadgesComponent.h index 6c3c1509e..7da63e447 100644 --- a/es-core/src/components/BadgesComponent.h +++ b/es-core/src/components/BadgesComponent.h @@ -27,7 +27,9 @@ class TextureResource; class BadgesComponent : public FlexboxComponent { public: - BadgesComponent(Window* window); + BadgesComponent(Window *window); + + ~BadgesComponent() noexcept; std::string getValue() const override; // Should be a list of strings. diff --git a/es-core/src/components/ImageComponent.h b/es-core/src/components/ImageComponent.h index ca537c62f..2d7b0c49d 100644 --- a/es-core/src/components/ImageComponent.h +++ b/es-core/src/components/ImageComponent.h @@ -14,21 +14,23 @@ class TextureResource; -class ImageComponent : public GuiComponent -{ +class ImageComponent : public GuiComponent { public: - ImageComponent(Window* window, bool forceLoad = false, bool dynamic = true); - virtual ~ImageComponent() {} + ImageComponent(Window *window, bool forceLoad = false, bool dynamic = true); + + virtual ~ImageComponent() noexcept {}; void setDefaultImage(std::string path) { mDefaultPath = path; } // Loads the image at the given filepath. Will tile if tile is true (retrieves texture // as tiling, creates vertices accordingly). void setImage(std::string path, bool tile = false, bool linearMagnify = false); + // Loads an image from memory. - void setImage(const char* data, size_t length, bool tile = false); + void setImage(const char *data, size_t length, bool tile = false); + // Use an already existing texture. - void setImage(const std::shared_ptr& texture); + void setImage(const std::shared_ptr &texture); void onSizeChanged() override { updateVertices(); }