Skip to content

Commit e02af74

Browse files
Optionally color some boxes in the entry's accent color (#162)
* Get accent color for store entries * Allow customizing color of `GFX::DrawBox` * Add setting for accent color * Use entry accent color in some boxes * Make accent color enabled by default --------- Co-authored-by: Pk11 <[email protected]>
1 parent 9ec05e2 commit e02af74

File tree

16 files changed

+126
-34
lines changed

16 files changed

+126
-34
lines changed

include/gui/gfx.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace GFX {
4545
void DrawTop(void);
4646
void DrawBottom();
4747
void DrawSprite(int img, int x, int y, float ScaleX = 1, float ScaleY = 1);
48-
void DrawBox(float xPos, float yPos, float width = 50, float height = 50, bool selected = false, uint32_t clr = UIThemes->BoxInside());
48+
void DrawBox(float xPos, float yPos, float width = 50, float height = 50, bool selected = false, uint32_t clr = 0, uint32_t borderClr = 0);
4949
void DrawCheckbox(float xPos, float yPos, bool selected);
5050
void DrawToggle(float xPos, float yPos, bool toggled);
5151
void DrawTime();

include/store/store.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Store {
6161
std::vector<std::string> GetScreenshotList(int index) const;
6262
std::vector<std::string> GetScreenshotNames(int index) const;
6363
std::string GetReleaseNotes(int index) const;
64+
uint32_t GetAccentColorEntry(int index) const;
6465

6566
std::vector<std::string> GetDownloadList(int index) const;
6667

include/store/storeEntry.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class StoreEntry {
5252
int GetSheetIndex() const { return this->SheetIndex; };
5353
int GetEntryIndex() const { return this->EntryIndex; };
5454

55+
uint32_t GetAccentColor() const { return this->AccentColor; };
56+
5557
std::vector<std::string> GetCategoryFull() const { return this->FullCategory; };
5658
std::vector<std::string> GetConsoleFull() const { return this->FullConsole; };
5759
std::vector<std::string> GetSizes() const { return this->Sizes; };
@@ -73,6 +75,7 @@ class StoreEntry {
7375
int Stars;
7476
C2D_Image Icon;
7577
int SheetIndex, EntryIndex, Marks;
78+
uint32_t AccentColor;
7679
std::vector<std::string> FullCategory, FullConsole, Sizes, Types, Screenshots, ScreenshotNames;
7780
bool UpdateAvailable;
7881
};

include/utils/config.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ class Config {
102102
std::string theme() const { return this->v_theme; };
103103
void theme(const std::string &v) { this->v_theme = v; if (!this->changesMade) this->changesMade = true; };
104104

105+
/* If accent color should be used. */
106+
bool useAccentColor() const { return this->v_useAccentColor; };
107+
void useAccentColor(bool v) { this->v_useAccentColor = v; };
108+
105109
/* If showing prompt if action failed / succeeded. */
106110
bool prompt() const { return this->v_prompt; };
107111
void prompt(bool v) { this->v_prompt = v; if (!this->changesMade) this->changesMade = true; };
@@ -122,7 +126,8 @@ class Config {
122126
v_shortcutPath = "sdmc:/3ds/Universal-Updater/shortcuts", v_firmPath = "sdmc:/luma/payloads", v_theme = "Default";
123127

124128
bool v_list = false, v_autoUpdate = true, v_metadata = true, v_updateCheck = true, v_updateNightly = false,
125-
v_showBg = false, v_customFont = false, v_changelog = true, v_prompt = true, v_3dsxInFolder = false;
129+
v_showBg = false, v_customFont = false, v_changelog = true, v_prompt = true, v_3dsxInFolder = false,
130+
v_useAccentColor = true;
126131
};
127132

128133
#endif

include/utils/stringutils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace StringUtils {
3838
std::string GetMarkString(int marks);
3939
std::vector<std::string> GetMarks(int marks);
4040
std::string format(const char *fmt_str, ...);
41+
uint32_t ParseColorHexString(std::string_view str);
4142
};
4243

4344
#endif

romfs/lang/en/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,6 @@
158158
"UPDATING_SPRITE_SHEET": "Updating Spritesheet...",
159159
"UPDATING_SPRITE_SHEET2": "Updating Spritesheet %i of %i...",
160160
"UPDATING_UNISTORE": "Updating UniStore...",
161+
"USE_ACCENT_COLOR": "Use Accent Color of Entries",
161162
"VERSION": "Version"
162163
}

source/gui/gfx.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,22 @@ void GFX::DrawBottom() {
5252
float height: The Height of the button.
5353
bool selected: If selected, or not.
5454
uint32_t clr: (Optional) The color of the inside of the box.
55+
uint32_t borderClr: (Optional) The color of the border if selected.
5556
*/
56-
void GFX::DrawBox(float xPos, float yPos, float width, float height, bool selected, uint32_t clr) {
57-
Gui::Draw_Rect(xPos, yPos, width, height, UIThemes->BoxInside()); // Draw middle BG.
57+
void GFX::DrawBox(float xPos, float yPos, float width, float height, bool selected, uint32_t clr, uint32_t borderClr) {
58+
if (!clr) clr = UIThemes->BoxInside();
59+
60+
Gui::Draw_Rect(xPos, yPos, width, height, clr); // Draw middle BG.
5861

5962
if (selected) {
6063
static constexpr int depth = 3;
6164

62-
Gui::Draw_Rect(xPos - depth, yPos - depth, width + depth * 2, depth, UIThemes->BoxSelected()); // Top.
63-
Gui::Draw_Rect(xPos - depth, yPos - depth, depth, height + depth * 2, UIThemes->BoxSelected()); // Left.
64-
Gui::Draw_Rect(xPos + width, yPos - depth, depth, height + depth * 2, UIThemes->BoxSelected()); // Right.
65-
Gui::Draw_Rect(xPos - depth, yPos + height, width + depth * 2, depth, UIThemes->BoxSelected()); // Bottom.
65+
if (!borderClr) borderClr = UIThemes->BoxSelected();
66+
67+
Gui::Draw_Rect(xPos - depth, yPos - depth, width + depth * 2, depth, borderClr); // Top.
68+
Gui::Draw_Rect(xPos - depth, yPos - depth, depth, height + depth * 2, borderClr); // Left.
69+
Gui::Draw_Rect(xPos + width, yPos - depth, depth, height + depth * 2, borderClr); // Right.
70+
Gui::Draw_Rect(xPos - depth, yPos + height, width + depth * 2, depth, borderClr); // Bottom.
6671
}
6772
}
6873

source/menu/downList.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,25 @@ static bool CreateShortcut(const std::string &entryName, int index, const std::s
108108
const std::vector<std::string> &sizes: Const Reference to the download sizes as a vector of strings.
109109
*/
110110
void StoreUtils::DrawDownList(const std::vector<std::string> &entries, bool fetch, const std::unique_ptr<StoreEntry> &entry, const std::vector<std::string> &sizes, const std::vector<bool> &installs) {
111+
uint32_t accentColor = 0;
112+
111113
/* For the Top Screen. */
112114
if (StoreUtils::store && StoreUtils::store->GetValid() && !fetch && entry) {
113115
if (entries.size() > 0) {
114-
Gui::Draw_Rect(0, 174, 400, 66, UIThemes->DownListPrev());
116+
accentColor = config->useAccentColor() ? entry->GetAccentColor() : 0;
117+
118+
if (accentColor) Gui::Draw_Rect(0, 173, 400, 1, UIThemes->EntryOutline());
119+
Gui::Draw_Rect(0, 174, 400, 66, accentColor ? accentColor : UIThemes->DownListPrev());
115120
const C2D_Image tempImg = entry->GetIcon();
116121
const uint8_t offsetW = (48 - tempImg.subtex->width) / 2; // Center W.
117122
const uint8_t offsetH = (48 - tempImg.subtex->height) / 2; // Center H.
118123
C2D_DrawImageAt(tempImg, 9 + offsetW, 174 + 9 + offsetH, 0.5);
119124

120-
Gui::DrawString(70, 174 + 15, 0.45f, UIThemes->TextColor(), entries[StoreUtils::store->GetDownloadIndex()], 310, 0, font);
125+
Gui::DrawString(70, 174 + 15, 0.45f, accentColor ? WHITE : UIThemes->TextColor(), entries[StoreUtils::store->GetDownloadIndex()], 310, 0, font);
121126

122127
if (!sizes.empty()) {
123128
if (sizes[StoreUtils::store->GetDownloadIndex()] != "") {
124-
Gui::DrawString(70, 174 + 30, 0.45f, UIThemes->TextColor(), Lang::get("SIZE") + ": " + sizes[StoreUtils::store->GetDownloadIndex()], 310, 0, font);
129+
Gui::DrawString(70, 174 + 30, 0.45f, accentColor ? WHITE : UIThemes->TextColor(), Lang::get("SIZE") + ": " + sizes[StoreUtils::store->GetDownloadIndex()], 310, 0, font);
125130
}
126131
}
127132
}
@@ -133,9 +138,9 @@ void StoreUtils::DrawDownList(const std::vector<std::string> &entries, bool fetc
133138
Animation::QueueEntryDone();
134139

135140
GFX::DrawBottom();
136-
Gui::Draw_Rect(40, 0, 280, 25, UIThemes->EntryBar());
141+
Gui::Draw_Rect(40, 0, 280, 25, accentColor ? accentColor : UIThemes->EntryBar());
137142
Gui::Draw_Rect(40, 25, 280, 1, UIThemes->EntryOutline());
138-
Gui::DrawStringCentered(17, 2, 0.6, UIThemes->TextColor(), Lang::get("AVAILABLE_DOWNLOADS"), 273, 0, font);
143+
Gui::DrawStringCentered(17, 2, 0.6, accentColor ? WHITE : UIThemes->TextColor(), Lang::get("AVAILABLE_DOWNLOADS"), 273, 0, font);
139144

140145
if (StoreUtils::store && StoreUtils::store->GetValid() && !fetch && entry) {
141146
if (entries.size() > 0) {

source/menu/entryInfo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ extern bool exiting, QueueRuns;
4545
*/
4646
void StoreUtils::DrawEntryInfo(const std::unique_ptr<StoreEntry> &entry) {
4747
if (StoreUtils::store && entry) { // Ensure, store & entry is not a nullptr.
48-
Gui::Draw_Rect(40, 0, 280, 36, UIThemes->EntryBar());
48+
uint32_t accentColor = config->useAccentColor() ? entry->GetAccentColor() : 0;
49+
50+
Gui::Draw_Rect(40, 0, 280, 36, accentColor ? accentColor : UIThemes->EntryBar());
4951
Gui::Draw_Rect(40, 36, 280, 1, UIThemes->EntryOutline());
5052

51-
Gui::DrawStringCentered(17, 0, 0.6, UIThemes->TextColor(), entry->GetTitle(), 273, 0, font);
52-
Gui::DrawStringCentered(17, 20, 0.4, UIThemes->TextColor(), entry->GetAuthor(), 273, 0, font);
53+
Gui::DrawStringCentered(17, 0, 0.6, accentColor ? WHITE : UIThemes->TextColor(), entry->GetTitle(), 273, 0, font);
54+
Gui::DrawStringCentered(17, 20, 0.4, accentColor ? WHITE : UIThemes->TextColor(), entry->GetAuthor(), 273, 0, font);
5355
Gui::DrawStringCentered(17, 50, 0.4, UIThemes->TextColor(), entry->GetDescription(), 248, 0, font, C2D_WordWrap);
5456

5557
Gui::DrawString(53, 115, 0.45, UIThemes->TextColor(), Lang::get("VERSION") + ": " + entry->GetVersion(), 248, 0, font);

source/menu/grid.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ void StoreUtils::DrawGrid() {
8080
}
8181

8282
for (int i = 0, i2 = -5 + (StoreUtils::store->GetScreenIndx() * 5); i2 < 20 + (StoreUtils::store->GetScreenIndx() * 5) && i2 < (int)StoreUtils::entries.size(); i2++, i++) {
83+
uint32_t accentColor = 0;
84+
if (config->useAccentColor() && (int)StoreUtils::entries.size() > i + StoreUtils::store->GetScreenIndx()) {
85+
accentColor = StoreUtils::entries[i + StoreUtils::store->GetScreenIndx()]->GetAccentColor();
86+
}
87+
8388
/* Boxes. */
84-
if (i == StoreUtils::store->GetBox()) GFX::DrawBox(GridBoxes[i + 5].x, GridBoxes[i + 5].y + StoreUtils::store->GetAnimOffset(), 50, 50, true);
89+
if (i == StoreUtils::store->GetBox()) GFX::DrawBox(GridBoxes[i + 5].x, GridBoxes[i + 5].y + StoreUtils::store->GetAnimOffset(), 50, 50, true, accentColor);
8590

8691
/* Ensure, entries is larger than the index. */
8792
if ((int)StoreUtils::entries.size() > i2) {

0 commit comments

Comments
 (0)