From 9922d2906055eacc595d80c0f2bfb3cf0dea196e Mon Sep 17 00:00:00 2001 From: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com> Date: Wed, 24 Mar 2021 23:16:12 +0100 Subject: [PATCH] [THEME]: Add Description and show it on the Theme Selector. --- include/utils/theme.hpp | 2 +- resources/Themes.json | 1 + source/init.cpp | 2 +- source/menu/settings.cpp | 2 +- source/overlays/themeSelect.cpp | 13 +++---- source/utils/theme.cpp | 60 ++++++++++++++++++--------------- 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/include/utils/theme.hpp b/include/utils/theme.hpp index ec804b2..dadad84 100644 --- a/include/utils/theme.hpp +++ b/include/utils/theme.hpp @@ -36,7 +36,7 @@ public: Theme(const std::string &ThemeJSON = "sdmc:/3ds/Universal-Updater/Themes.json"); nlohmann::json InitWithDefaultColors(const std::string &ThemePath = "sdmc:/3ds/Universal-Updater/Themes.json"); void LoadTheme(const std::string &ThemeName); - std::vector ThemeNames(); + std::vector> ThemeNames(); uint32_t GetThemeColor(const std::string &ThemeName, const std::string &Key, const uint32_t DefaultColor); uint32_t BarColor() const { return this->vBarColor; }; diff --git a/resources/Themes.json b/resources/Themes.json index b350257..70ce12b 100644 --- a/resources/Themes.json +++ b/resources/Themes.json @@ -6,6 +6,7 @@ "BoxInside": "#1C213A", "BoxSelected": "#6C829B", "BoxUnselected": "#000000", + "Description": "Universal-Updater's default Theme.\n\nBy: Universal-Team", "DownListPrev": "#1C213A", "EntryBar": "#324962", "EntryOutline": "#191E35", diff --git a/source/init.cpp b/source/init.cpp index 3888542..c9b70fa 100644 --- a/source/init.cpp +++ b/source/init.cpp @@ -41,7 +41,7 @@ u32 old_time_limit; std::unique_ptr UIThemes = nullptr; std::unique_ptr Music = nullptr; bool dspfirmFound = false; -std::vector Themes = { }; +std::vector> Themes = { }; /* Set, if 3DSX or CIA. diff --git a/source/menu/settings.cpp b/source/menu/settings.cpp index df01c7c..484a4b8 100644 --- a/source/menu/settings.cpp +++ b/source/menu/settings.cpp @@ -83,7 +83,7 @@ static const Structs::ButtonPos Theme = { 40, 196, 280, 24 }; // Themes. static const std::vector mainStrings = { "LANGUAGE", "SELECT_UNISTORE", "AUTO_UPDATE_SETTINGS_BTN", "GUI_SETTINGS_BTN", "DIRECTORY_SETTINGS_BTN", "CREDITS", "EXIT_APP" }; static const std::vector dirStrings = { "CHANGE_3DSX_PATH", "3DSX_IN_FOLDER", "CHANGE_NDS_PATH", "CHANGE_ARCHIVE_PATH", "CHANGE_SHORTCUT_PATH", "CHANGE_FIRM_PATH" }; -extern std::vector Themes; +extern std::vector> Themes; /* Note: Украïнська is spelled using a latin i with dieresis to work in the system font */ static const std::vector languages = { "Bruh", "Deutsch", "English", "Español", "Français", "Italiano", /* "Lietuvių", */ "Magyar", /* "Nederlands", */ "Polski", "Português", "Português (Brasil)", "Русский", "Украïнська", /* "עברית", */ "中文 (简体)", "中文 (繁體)", "日本語", /* "한국어" */ }; diff --git a/source/overlays/themeSelect.cpp b/source/overlays/themeSelect.cpp index e9554e1..cd9ef3c 100644 --- a/source/overlays/themeSelect.cpp +++ b/source/overlays/themeSelect.cpp @@ -40,7 +40,7 @@ static const std::vector mainButtons = { { 10, 186, 300, 22 } }; -extern std::vector Themes; +extern std::vector> Themes; /* Select a Theme. */ void Overlays::SelectTheme() { @@ -67,6 +67,7 @@ void Overlays::SelectTheme() { Gui::Draw_Rect(0, 215, 400, 25, UIThemes->BarColor()); Gui::Draw_Rect(0, 214, 400, 1, UIThemes->BarOutline()); + Gui::DrawStringCentered(0, 40, 0.5f, UIThemes->TextColor(), Themes[selection].second, 380, 140, font); Animation::QueueEntryDone(); GFX::DrawBottom(); @@ -77,7 +78,7 @@ void Overlays::SelectTheme() { if (Themes.size() > 0) { for(int i = 0; i < 7 && i < (int)Themes.size(); i++) { if (sPos + i == selection) Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, UIThemes->MarkSelected()); - Gui::DrawStringCentered(10 - 160 + (300 / 2), mainButtons[i].y + 4, 0.45f, UIThemes->TextColor(), Themes[sPos + i], 295, 0, font); + Gui::DrawStringCentered(10 - 160 + (300 / 2), mainButtons[i].y + 4, 0.45f, UIThemes->TextColor(), Themes[sPos + i].first, 295, 0, font); } } @@ -110,8 +111,8 @@ void Overlays::SelectTheme() { } if (hidKeysDown() & KEY_A) { - UIThemes->LoadTheme(Themes[selection]); - config->theme(Themes[selection]); + UIThemes->LoadTheme(Themes[selection].first); + config->theme(Themes[selection].first); Finish = true; } @@ -119,8 +120,8 @@ void Overlays::SelectTheme() { for (int i = 0; i < 7; i++) { if (touching(touch, mainButtons[i])) { if (i + sPos < (int)Themes.size()) { - UIThemes->LoadTheme(Themes[i + sPos]); - config->theme(Themes[i + sPos]); + UIThemes->LoadTheme(Themes[i + sPos].first); + config->theme(Themes[i + sPos].first); Finish = true; } } diff --git a/source/utils/theme.cpp b/source/utils/theme.cpp index 24b9644..7cb7603 100644 --- a/source/utils/theme.cpp +++ b/source/utils/theme.cpp @@ -35,42 +35,43 @@ * @param b blue component of the color * @param a alpha component of the color */ -#define RGBA8(r, g, b, a) ((((r)&0xFF)<<0) | (((g)&0xFF)<<8) | (((b)&0xFF)<<16) | (((a)&0xFF)<<24)) +#define RGBA8(r, g, b, a) ((((r) & 0xFF) << 0) | (((g) & 0xFF) << 8) | (((b) & 0xFF) << 16) | (((a) & 0xFF) << 24)) Theme::Theme(const std::string &ThemeJSON) { FILE *file = fopen(ThemeJSON.c_str(), "rt"); - if(file) { + if (file) { this->json = nlohmann::json::parse(file, nullptr, false); fclose(file); } - if(!file || this->json.is_discarded()) - this->json = this->InitWithDefaultColors(); + + if (!file || this->json.is_discarded()) this->json = this->InitWithDefaultColors(); this->Loaded = true; } nlohmann::json Theme::InitWithDefaultColors(const std::string &ThemePath) { nlohmann::json JS = { - {"Default", { - {"BarColor", "#324962"}, - {"BGColor", "#262C4D"}, - {"BarOutline", "#191E35"}, - {"TextColor", "#FFFFFF"}, - {"EntryBar", "#324962"}, - {"EntryOutline", "#191E35"}, - {"BoxInside", "#1C213A"}, - {"BoxSelected", "#6C829B"}, - {"BoxUnselected", "#000000"}, - {"ProgressbarOut", "#1C213A"}, - {"ProgressbarIn", "#4D6580"}, - {"SearchBar", "#334B66"}, - {"SearchBarOutline", "#191E35"}, - {"SideBarSelected", "#6C829B"}, - {"SideBarUnselected", "#4D6580"}, - {"MarkSelected", "#4D6580"}, - {"MarkUnselected", "#1C213A"}, - {"DownListPrev", "#1C213A"}, - {"SideBarIconColor", "#ADCCEF"} + { "Default", { + { "BarColor", "#324962" }, + { "BGColor", "#262C4D" }, + { "BarOutline", "#191E35" }, + { "TextColor", "#FFFFFF" }, + { "EntryBar", "#324962" }, + { "EntryOutline", "#191E35" }, + { "BoxInside", "#1C213A" }, + { "BoxSelected", "#6C829B" }, + { "BoxUnselected", "#000000" }, + { "ProgressbarOut", "#1C213A" }, + { "ProgressbarIn", "#4D6580" }, + { "SearchBar", "#334B66" }, + { "SearchBarOutline", "#191E35" }, + { "SideBarSelected", "#6C829B" }, + { "SideBarUnselected", "#4D6580" }, + { "MarkSelected", "#4D6580" }, + { "MarkUnselected", "#1C213A" }, + { "DownListPrev", "#1C213A" }, + { "SideBarIconColor", "#ADCCEF" }, + { "Description", "Universal-Updater's default Theme.\n\nBy: Universal-Team" } }} }; @@ -105,12 +106,17 @@ void Theme::LoadTheme(const std::string &ThemeName) { this->vSideBarIconColor = this->GetThemeColor(ThemeName, "SideBarIconColor", C2D_Color32(173, 204, 239, 255)); } -std::vector Theme::ThemeNames() { - std::vector Temp = { }; +std::vector> Theme::ThemeNames() { + std::vector> Temp = { }; if (this->Loaded) { for(auto it = this->json.begin(); it != this->json.end(); ++it) { - Temp.push_back(it.key().c_str()); + if (this->json[it.key()].contains("Description") && this->json[it.key()]["Description"].is_string()) { + Temp.push_back(std::make_pair(it.key(), this->json[it.key()]["Description"])); + + } else { + Temp.push_back(std::make_pair(it.key(), it.key())); + } } }