Renamed BadgesComponent to BadgeComponent.

This commit is contained in:
Leon Styhre 2021-10-23 20:28:07 +02:00
parent 0351a2ccdb
commit 1aa360598d
10 changed files with 44 additions and 45 deletions

View file

@ -53,7 +53,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
, mMediaFilesUpdated{false} , mMediaFilesUpdated{false}
, mInvalidEmulatorEntry{false} , mInvalidEmulatorEntry{false}
{ {
mGameControllers = BadgesComponent::getGameControllers(); mGameControllers = BadgeComponent::getGameControllers();
// Remove the last "unknown" controller entry. // Remove the last "unknown" controller entry.
if (mGameControllers.size() > 1) if (mGameControllers.size() > 1)
@ -200,7 +200,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
// OK callback (apply new value to ed). // OK callback (apply new value to ed).
auto updateVal = [ed, originalValue](const std::string& newVal) { auto updateVal = [ed, originalValue](const std::string& newVal) {
ed->setValue(newVal); ed->setValue(newVal);
if (newVal == BadgesComponent::getDisplayName(originalValue)) if (newVal == BadgeComponent::getDisplayName(originalValue))
ed->setColor(DEFAULT_TEXTCOLOR); ed->setColor(DEFAULT_TEXTCOLOR);
else else
ed->setColor(TEXTCOLOR_USERMARKED); ed->setColor(TEXTCOLOR_USERMARKED);
@ -478,7 +478,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
ed->setValue(ViewController::EXCLAMATION_CHAR + " " + originalValue); ed->setValue(ViewController::EXCLAMATION_CHAR + " " + originalValue);
} }
else if (iter->type == MD_CONTROLLER && mMetaData->get(iter->key) != "") { else if (iter->type == MD_CONTROLLER && mMetaData->get(iter->key) != "") {
std::string displayName = BadgesComponent::getDisplayName(mMetaData->get(iter->key)); std::string displayName = BadgeComponent::getDisplayName(mMetaData->get(iter->key));
if (displayName != "unknown") if (displayName != "unknown")
ed->setValue(displayName); ed->setValue(displayName);
else else
@ -618,7 +618,7 @@ void GuiMetaDataEd::save()
continue; continue;
if (mMetaDataDecl.at(i).key == "controller" && mEditors.at(i)->getValue() != "") { if (mMetaDataDecl.at(i).key == "controller" && mEditors.at(i)->getValue() != "") {
std::string shortName = BadgesComponent::getShortName(mEditors.at(i)->getValue()); std::string shortName = BadgeComponent::getShortName(mEditors.at(i)->getValue());
if (shortName != "unknown") if (shortName != "unknown")
mMetaData->set(mMetaDataDecl.at(i).key, shortName); mMetaData->set(mMetaDataDecl.at(i).key, shortName);
continue; continue;
@ -769,7 +769,7 @@ void GuiMetaDataEd::close()
continue; continue;
if (mMetaDataDecl.at(i).key == "controller" && mEditors.at(i)->getValue() != "") { if (mMetaDataDecl.at(i).key == "controller" && mEditors.at(i)->getValue() != "") {
std::string shortName = BadgesComponent::getShortName(mEditors.at(i)->getValue()); std::string shortName = BadgeComponent::getShortName(mEditors.at(i)->getValue());
if (shortName == "unknown" || mMetaDataValue == shortName) if (shortName == "unknown" || mMetaDataValue == shortName)
continue; continue;
} }

View file

@ -13,7 +13,7 @@
#include "GuiComponent.h" #include "GuiComponent.h"
#include "MetaData.h" #include "MetaData.h"
#include "components/BadgesComponent.h" #include "components/BadgeComponent.h"
#include "components/ComponentGrid.h" #include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h" #include "components/NinePatchComponent.h"
#include "components/ScrollIndicatorComponent.h" #include "components/ScrollIndicatorComponent.h"

View file

@ -410,9 +410,9 @@ void DetailedGameListView::updateInfoPanel()
mPlayers.setValue(file->metadata.get("players")); mPlayers.setValue(file->metadata.get("players"));
// Populate the badge slots based on game metadata. // Populate the badge slots based on game metadata.
std::vector<BadgesComponent::BadgeInfo> badgeSlots; std::vector<BadgeComponent::BadgeInfo> badgeSlots;
for (auto badge : mBadges.getBadgeTypes()) { for (auto badge : mBadges.getBadgeTypes()) {
BadgesComponent::BadgeInfo badgeInfo; BadgeComponent::BadgeInfo badgeInfo;
badgeInfo.badgeType = badge; badgeInfo.badgeType = badge;
if (badge == "controller") { if (badge == "controller") {
if (file->metadata.get("controller").compare("") != 0) { if (file->metadata.get("controller").compare("") != 0) {

View file

@ -9,7 +9,7 @@
#ifndef ES_APP_VIEWS_GAME_LIST_DETAILED_GAME_LIST_VIEW_H #ifndef ES_APP_VIEWS_GAME_LIST_DETAILED_GAME_LIST_VIEW_H
#define ES_APP_VIEWS_GAME_LIST_DETAILED_GAME_LIST_VIEW_H #define ES_APP_VIEWS_GAME_LIST_DETAILED_GAME_LIST_VIEW_H
#include "components/BadgesComponent.h" #include "components/BadgeComponent.h"
#include "components/DateTimeComponent.h" #include "components/DateTimeComponent.h"
#include "components/RatingComponent.h" #include "components/RatingComponent.h"
#include "components/ScrollableContainer.h" #include "components/ScrollableContainer.h"
@ -56,7 +56,7 @@ private:
DateTimeComponent mLastPlayed; DateTimeComponent mLastPlayed;
TextComponent mPlayCount; TextComponent mPlayCount;
TextComponent mName; TextComponent mName;
BadgesComponent mBadges; BadgeComponent mBadges;
std::vector<TextComponent*> getMDLabels(); std::vector<TextComponent*> getMDLabels();
std::vector<GuiComponent*> getMDValues(); std::vector<GuiComponent*> getMDValues();

View file

@ -9,7 +9,7 @@
#ifndef ES_APP_VIEWS_GAME_LIST_GRID_GAME_LIST_VIEW_H #ifndef ES_APP_VIEWS_GAME_LIST_GRID_GAME_LIST_VIEW_H
#define ES_APP_VIEWS_GAME_LIST_GRID_GAME_LIST_VIEW_H #define ES_APP_VIEWS_GAME_LIST_GRID_GAME_LIST_VIEW_H
#include "components/BadgesComponent.h" #include "components/BadgeComponent.h"
#include "components/DateTimeComponent.h" #include "components/DateTimeComponent.h"
#include "components/ImageGridComponent.h" #include "components/ImageGridComponent.h"
#include "components/RatingComponent.h" #include "components/RatingComponent.h"
@ -89,7 +89,7 @@ private:
TextComponent mLblLastPlayed; TextComponent mLblLastPlayed;
TextComponent mLblPlayCount; TextComponent mLblPlayCount;
BadgesComponent mBadges; BadgeComponent mBadges;
RatingComponent mRating; RatingComponent mRating;
DateTimeComponent mReleaseDate; DateTimeComponent mReleaseDate;
TextComponent mDeveloper; TextComponent mDeveloper;

View file

@ -450,9 +450,9 @@ void VideoGameListView::updateInfoPanel()
mPlayers.setValue(file->metadata.get("players")); mPlayers.setValue(file->metadata.get("players"));
// Populate the badge slots based on game metadata. // Populate the badge slots based on game metadata.
std::vector<BadgesComponent::BadgeInfo> badgeSlots; std::vector<BadgeComponent::BadgeInfo> badgeSlots;
for (auto badge : mBadges.getBadgeTypes()) { for (auto badge : mBadges.getBadgeTypes()) {
BadgesComponent::BadgeInfo badgeInfo; BadgeComponent::BadgeInfo badgeInfo;
badgeInfo.badgeType = badge; badgeInfo.badgeType = badge;
if (badge == "controller") { if (badge == "controller") {
if (file->metadata.get("controller").compare("") != 0) { if (file->metadata.get("controller").compare("") != 0) {

View file

@ -9,7 +9,7 @@
#ifndef ES_APP_VIEWS_GAME_LIST_VIDEO_GAME_LIST_VIEW_H #ifndef ES_APP_VIEWS_GAME_LIST_VIDEO_GAME_LIST_VIEW_H
#define ES_APP_VIEWS_GAME_LIST_VIDEO_GAME_LIST_VIEW_H #define ES_APP_VIEWS_GAME_LIST_VIDEO_GAME_LIST_VIEW_H
#include "components/BadgesComponent.h" #include "components/BadgeComponent.h"
#include "components/DateTimeComponent.h" #include "components/DateTimeComponent.h"
#include "components/RatingComponent.h" #include "components/RatingComponent.h"
#include "components/ScrollableContainer.h" #include "components/ScrollableContainer.h"
@ -60,7 +60,7 @@ private:
DateTimeComponent mLastPlayed; DateTimeComponent mLastPlayed;
TextComponent mPlayCount; TextComponent mPlayCount;
TextComponent mName; TextComponent mName;
BadgesComponent mBadges; BadgeComponent mBadges;
std::vector<TextComponent*> getMDLabels(); std::vector<TextComponent*> getMDLabels();
std::vector<GuiComponent*> getMDValues(); std::vector<GuiComponent*> getMDValues();

View file

@ -34,7 +34,7 @@ set(CORE_HEADERS
# GUI components # GUI components
${CMAKE_CURRENT_SOURCE_DIR}/src/components/AnimatedImageComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/AnimatedImageComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/BadgesComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/BadgeComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/BusyComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/BusyComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ButtonComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/ButtonComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentGrid.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentGrid.h
@ -112,7 +112,7 @@ set(CORE_SOURCES
# GUI components # GUI components
${CMAKE_CURRENT_SOURCE_DIR}/src/components/AnimatedImageComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/AnimatedImageComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/BadgesComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/BadgeComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/BusyComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/BusyComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ButtonComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/ButtonComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentGrid.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentGrid.cpp

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // EmulationStation Desktop Edition
// BadgesComponent.cpp // BadgeComponent.cpp
// //
// Game badges icons. // Game badges icons.
// Used by the gamelist views. // Used by the gamelist views.
@ -14,13 +14,13 @@
#define SLOT_CONTROLLER "controller" #define SLOT_CONTROLLER "controller"
#define SLOT_ALTEMULATOR "altemulator" #define SLOT_ALTEMULATOR "altemulator"
#include "components/BadgesComponent.h" #include "components/BadgeComponent.h"
#include "Log.h" #include "Log.h"
#include "ThemeData.h" #include "ThemeData.h"
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
std::vector<GameControllers> BadgesComponent::sGameControllers; std::vector<GameControllers> BadgeComponent::sGameControllers;
// clang-format off // clang-format off
@ -55,7 +55,7 @@ GameControllers sControllerDefinitions [] = {
// clang-format on // clang-format on
BadgesComponent::BadgesComponent(Window* window) BadgeComponent::BadgeComponent(Window* window)
: GuiComponent{window} : GuiComponent{window}
, mFlexboxItems{} , mFlexboxItems{}
, mFlexboxComponent{window, mFlexboxItems} , mFlexboxComponent{window, mFlexboxItems}
@ -70,14 +70,14 @@ BadgesComponent::BadgesComponent(Window* window)
mBadgeIcons[SLOT_ALTEMULATOR] = ":/graphics/badge_altemulator.svg"; mBadgeIcons[SLOT_ALTEMULATOR] = ":/graphics/badge_altemulator.svg";
} }
void BadgesComponent::populateGameControllers() void BadgeComponent::populateGameControllers()
{ {
sGameControllers.clear(); sGameControllers.clear();
for (auto controller : sControllerDefinitions) for (auto controller : sControllerDefinitions)
sGameControllers.push_back(controller); sGameControllers.push_back(controller);
} }
void BadgesComponent::setBadges(const std::vector<BadgeInfo>& badges) void BadgeComponent::setBadges(const std::vector<BadgeInfo>& badges)
{ {
std::map<std::string, bool> prevVisibility; std::map<std::string, bool> prevVisibility;
std::map<std::string, std::string> prevPlayers; std::map<std::string, std::string> prevPlayers;
@ -124,7 +124,7 @@ void BadgesComponent::setBadges(const std::vector<BadgeInfo>& badges)
} }
} }
const std::string BadgesComponent::getShortName(const std::string& displayName) const std::string BadgeComponent::getShortName(const std::string& displayName)
{ {
auto it = std::find_if(sGameControllers.begin(), sGameControllers.end(), auto it = std::find_if(sGameControllers.begin(), sGameControllers.end(),
[displayName](GameControllers gameController) { [displayName](GameControllers gameController) {
@ -136,7 +136,7 @@ const std::string BadgesComponent::getShortName(const std::string& displayName)
return "unknown"; return "unknown";
} }
const std::string BadgesComponent::getDisplayName(const std::string& shortName) const std::string BadgeComponent::getDisplayName(const std::string& shortName)
{ {
auto it = std::find_if(sGameControllers.begin(), sGameControllers.end(), auto it = std::find_if(sGameControllers.begin(), sGameControllers.end(),
[shortName](GameControllers gameController) { [shortName](GameControllers gameController) {
@ -148,7 +148,7 @@ const std::string BadgesComponent::getDisplayName(const std::string& shortName)
return "unknown"; return "unknown";
} }
void BadgesComponent::render(const glm::mat4& parentTrans) void BadgeComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible()) if (!isVisible())
return; return;
@ -163,10 +163,10 @@ void BadgesComponent::render(const glm::mat4& parentTrans)
} }
} }
void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, void BadgeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view, const std::string& view,
const std::string& element, const std::string& element,
unsigned int properties) unsigned int properties)
{ {
populateGameControllers(); populateGameControllers();
@ -179,7 +179,7 @@ void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("alignment")) { if (elem->has("alignment")) {
const std::string alignment{elem->get<std::string>("alignment")}; const std::string alignment{elem->get<std::string>("alignment")};
if (alignment != "left" && alignment != "right") { if (alignment != "left" && alignment != "right") {
LOG(LogWarning) << "BadgesComponent: Invalid theme configuration, <alignment> set to \"" LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, <alignment> set to \""
<< alignment << "\""; << alignment << "\"";
} }
else { else {
@ -191,7 +191,7 @@ void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const float itemsPerRow{elem->get<float>("itemsPerRow")}; const float itemsPerRow{elem->get<float>("itemsPerRow")};
if (itemsPerRow < 1.0f || itemsPerRow > 10.0f) { if (itemsPerRow < 1.0f || itemsPerRow > 10.0f) {
LOG(LogWarning) LOG(LogWarning)
<< "BadgesComponent: Invalid theme configuration, <itemsPerRow> set to \"" << "BadgeComponent: Invalid theme configuration, <itemsPerRow> set to \""
<< itemsPerRow << "\""; << itemsPerRow << "\"";
} }
else { else {
@ -202,7 +202,7 @@ void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("rows")) { if (elem->has("rows")) {
const float rows{elem->get<float>("rows")}; const float rows{elem->get<float>("rows")};
if (rows < 1.0f || rows > 10.0f) { if (rows < 1.0f || rows > 10.0f) {
LOG(LogWarning) << "BadgesComponent: Invalid theme configuration, <rows> set to \"" LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, <rows> set to \""
<< rows << "\""; << rows << "\"";
} }
else { else {
@ -215,9 +215,8 @@ void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if ((itemMargin.x != -1.0 && itemMargin.y != -1.0) && if ((itemMargin.x != -1.0 && itemMargin.y != -1.0) &&
(itemMargin.x < 0.0f || itemMargin.x > 0.2f || itemMargin.y < 0.0f || (itemMargin.x < 0.0f || itemMargin.x > 0.2f || itemMargin.y < 0.0f ||
itemMargin.y > 0.2f)) { itemMargin.y > 0.2f)) {
LOG(LogWarning) LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, <itemMargin> set to \""
<< "BadgesComponent: Invalid theme configuration, <itemMargin> set to \"" << itemMargin.x << " " << itemMargin.y << "\"";
<< itemMargin.x << " " << itemMargin.y << "\"";
} }
else { else {
mFlexboxComponent.setItemMargin(itemMargin); mFlexboxComponent.setItemMargin(itemMargin);
@ -229,7 +228,7 @@ void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (controllerPos.x < -1.0f || controllerPos.x > 2.0f || controllerPos.y < -1.0f || if (controllerPos.x < -1.0f || controllerPos.x > 2.0f || controllerPos.y < -1.0f ||
controllerPos.y > 2.0f) { controllerPos.y > 2.0f) {
LOG(LogWarning) LOG(LogWarning)
<< "BadgesComponent: Invalid theme configuration, <controllerPos> set to \"" << "BadgeComponent: Invalid theme configuration, <controllerPos> set to \""
<< controllerPos.x << " " << controllerPos.y << "\""; << controllerPos.x << " " << controllerPos.y << "\"";
} }
else { else {
@ -241,7 +240,7 @@ void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const float controllerSize = elem->get<float>("controllerSize"); const float controllerSize = elem->get<float>("controllerSize");
if (controllerSize < 0.1f || controllerSize > 2.0f) { if (controllerSize < 0.1f || controllerSize > 2.0f) {
LOG(LogWarning) LOG(LogWarning)
<< "BadgesComponent: Invalid theme configuration, <controllerSize> set to \"" << "BadgeComponent: Invalid theme configuration, <controllerSize> set to \""
<< controllerSize << "\""; << controllerSize << "\"";
} }
else { else {

View file

@ -1,14 +1,14 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // EmulationStation Desktop Edition
// BadgesComponent.h // BadgeComponent.h
// //
// Game badges icons. // Game badges icons.
// Used by the gamelist views. // Used by the gamelist views.
// //
#ifndef ES_CORE_COMPONENTS_BADGES_COMPONENT_H #ifndef ES_CORE_COMPONENTS_BADGE_COMPONENT_H
#define ES_CORE_COMPONENTS_BADGES_COMPONENT_H #define ES_CORE_COMPONENTS_BADGE_COMPONENT_H
#include "FlexboxComponent.h" #include "FlexboxComponent.h"
#include "GuiComponent.h" #include "GuiComponent.h"
@ -19,10 +19,10 @@ struct GameControllers {
std::string fileName; std::string fileName;
}; };
class BadgesComponent : public GuiComponent class BadgeComponent : public GuiComponent
{ {
public: public:
BadgesComponent(Window* window); BadgeComponent(Window* window);
struct BadgeInfo { struct BadgeInfo {
std::string badgeType; std::string badgeType;
@ -60,4 +60,4 @@ private:
std::map<std::string, std::string> mBadgeIcons; std::map<std::string, std::string> mBadgeIcons;
}; };
#endif // ES_CORE_COMPONENTS_BADGES_COMPONENT_H #endif // ES_CORE_COMPONENTS_BADGE_COMPONENT_H