Skip to content

Commit e5c7f35

Browse files
committed
Fix settings font breaking on opening stats
1 parent aac1663 commit e5c7f35

5 files changed

Lines changed: 31 additions & 32 deletions

File tree

include/gfx.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#define BG(x) (0 + x)
1010
#define BG_SUB(x) (4 + x)
1111

12-
#define MAIN_FONT_GRAY 0xF8
13-
#define MAIN_FONT_WHITE 0xFC
12+
#define TEXT_BLACK 0xF0
13+
#define TEXT_GRAY 0xF4
14+
#define TEXT_WHITE 0xF8
15+
#define TEXT_GREEN 0xFC
1416

1517
enum TilePalette : int {
1618
white = 0,
@@ -32,7 +34,7 @@ extern Font mainFont;
3234

3335
void initGraphics(bool altPalette);
3436

35-
void setSpritePalettes(bool altPalette);
37+
void setPalettes(bool altPalette);
3638

3739
void flipSprites(Sprite *letterSprites, int count, std::vector<TilePalette> newPalettes, FlipOptions option = FlipOptions::none);
3840

source/gfx.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,20 @@ constexpr std::array<std::array<u16, 16 * 5>, 2> letterPalettes = {{
3333
}
3434
}};
3535

36-
constexpr u16 fontPal[] = {
37-
0x0000, 0xEF7B, 0xD6B5, 0xC631, // Gray
38-
0x0000, 0xC631, 0xF39C, 0xFFFF // White
39-
};
36+
constexpr std::array<std::array<u16, 16>, 2> fontPal = {{
37+
{
38+
0xFFFF, 0xDEF7, 0xC631, 0x8000, // Black
39+
0x0000, 0xEF7B, 0xD6B5, 0xC631, // Gray
40+
0x39CE, 0xC631, 0xF39C, 0xFFFF, // White on gray
41+
0x32AD, 0xC2D1, 0xDF57, 0xFFFF, // White on green
42+
},
43+
{
44+
0xFFFF, 0xDEF7, 0xC631, 0x8000, // Black
45+
0x0000, 0xEF7B, 0xD6B5, 0xC631, // Gray
46+
0x39CE, 0xC631, 0xF39C, 0xFFFF, // White on gray
47+
0x1DFD, 0xB63D, 0xD6DE, 0xFFFF, // White on orange
48+
}
49+
}};
4050

4151
void initGraphics(bool altPalette) {
4252
videoSetMode(MODE_5_2D);
@@ -64,7 +74,6 @@ void initGraphics(bool altPalette) {
6474

6575
oamInit(&oamMain, SpriteMapping_Bmp_1D_128, false);
6676
oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false);
67-
setSpritePalettes(altPalette);
6877

6978
constexpr int tileSize = 32 * 32 / 2;
7079
for(int i = 0; i < letterTilesTilesLen / tileSize; i++) {
@@ -81,12 +90,17 @@ void initGraphics(bool altPalette) {
8190
Sprite::update(true);
8291

8392
mainFont = std::move(Font(main_nftr, main_nftr_size));
84-
tonccpy(BG_PALETTE_SUB + MAIN_FONT_GRAY, fontPal, sizeof(fontPal));
93+
94+
setPalettes(altPalette);
8595
}
8696

87-
void setSpritePalettes(bool altPalette) {
97+
void setPalettes(bool altPalette) {
98+
// Sprites
8899
tonccpy(SPRITE_PALETTE, letterPalettes[altPalette].data(), letterPalettes[altPalette].size() * sizeof(u16));
89100
tonccpy(SPRITE_PALETTE_SUB, letterPalettes[altPalette].data(), letterPalettes[altPalette].size() * sizeof(u16));
101+
102+
// Fonts
103+
tonccpy(BG_PALETTE_SUB + 0xF0, fontPal[altPalette].data(), fontPal[altPalette].size() * sizeof(u16));
90104
}
91105

92106
void flipSprites(Sprite *letterSprites, int count, std::vector<TilePalette> newPalettes, FlipOptions option) {

source/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ void makeTxt(Config &config, std::u16string_view answer) {
9393
}
9494

9595
void drawBgBottom(std::string_view msg) {
96+
swiWaitForVBlank();
97+
9698
mainFont.clear(false);
9799

98100
if(msg.size() == 0) {
@@ -104,7 +106,7 @@ void drawBgBottom(std::string_view msg) {
104106
tonccpy(BG_PALETTE_SUB, bgBottomBoxPal, bgBottomBoxPalLen);
105107
tonccpy(bgGetMapPtr(BG_SUB(0)), bgBottomBoxMap, bgBottomBoxMapLen);
106108

107-
mainFont.palette(MAIN_FONT_WHITE).print(0, 56 - mainFont.calcHeight(msg) / 2, false, msg, Alignment::center);
109+
mainFont.palette(TEXT_WHITE).print(0, 56 - mainFont.calcHeight(msg) / 2, false, msg, Alignment::center);
108110
}
109111

110112
mainFont.update(false);

source/settings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ void settingsMenu(Config &config) {
5656
tonccpy(BG_PALETTE_SUB, settingsBottomPal, settingsBottomPalLen);
5757
tonccpy(bgGetMapPtr(BG_SUB(0)), settingsBottomMap, settingsBottomMapLen);
5858

59-
mainFont.palette(MAIN_FONT_GRAY);
59+
mainFont.palette(TEXT_GRAY);
6060
mainFont.print(4, 192 - 2 - mainFont.calcHeight(creditStr), false, creditStr);
6161
mainFont.print(256 - 4, 192 - 2 - mainFont.height(), false, VER_NUMBER, Alignment::right);
6262
mainFont.update(false);
6363

6464
while(1) {
6565
tonccpy(BG_PALETTE_SUB + 0x1D, togglePal[config.altPalette()].data(), togglePal[config.altPalette()].size() * sizeof(u16));
66-
setSpritePalettes(config.altPalette());
66+
setPalettes(config.altPalette());
6767
setToggle(0, config.hardMode());
6868
setToggle(1, config.altPalette());
6969

source/stats.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,6 @@
1313
#include <algorithm>
1414
#include <nds.h>
1515

16-
constexpr std::array<std::array<u16, 12>, 2> fontPal = {{
17-
{
18-
0xFFFF, 0xDEF7, 0xC631, 0x8000, // Black
19-
0x39CE, 0xC631, 0xF39C, 0xFFFF, // White on gray
20-
0x32AD, 0xC2D1, 0xDF57, 0xFFFF, // White on green
21-
},
22-
{
23-
0xFFFF, 0xDEF7, 0xC631, 0x8000, // Black
24-
0x39CE, 0xC631, 0xF39C, 0xFFFF, // White on gray
25-
0x1DFD, 0xB63D, 0xD6DE, 0xFFFF, // White on orange
26-
}
27-
28-
}};
29-
30-
#define TEXT_BLACK 0xF0
31-
#define TEXT_WHITE 0xF4
32-
#define TEXT_GREEN 0xF8
33-
3416
void statsMenu(const Config &config, bool won) {
3517
// Change to stats menu background
3618
swiWaitForVBlank();
@@ -42,7 +24,6 @@ void statsMenu(const Config &config, bool won) {
4224
Font largeFont(numbers_large_nftr, numbers_large_nftr_size), smallFont(numbers_small_nftr, numbers_small_nftr_size);
4325
largeFont.palette(TEXT_BLACK);
4426
smallFont.palette(TEXT_BLACK);
45-
tonccpy(BG_PALETTE_SUB + 0xF0, fontPal[config.altPalette()].data(), fontPal[config.altPalette()].size() * sizeof(u16));
4627

4728
// Print scores
4829
largeFont.print(-96, 32, false, config.gamesPlayed(), Alignment::center);

0 commit comments

Comments
 (0)