Skip to content

Commit

Permalink
Allow setting custom color palettes based on user profile color for a…
Browse files Browse the repository at this point in the history
…ll paletted graphics (#2137)

* Move texture exists impl. + fix bottombubblemacro

* Add/reorder missing icons to grayscale all grf

* Add ini user palette options for all GRF files

* Load custom user palettes from bin files

* Allow user palettes to be enabled in 3DS skins

* username.bin for username palettes

* Progress bar color ini options
  • Loading branch information
DieGo367 committed Jan 6, 2023
1 parent 606655c commit 2ca6855
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 74 deletions.
5 changes: 5 additions & 0 deletions romsel_dsimenutheme/arm9/include/startborderpal.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ const unsigned short bmpPal_topSmallFont[16][4]
{0x7C1F, 0xC8BC, 0xCC7E, 0xD8DE} // 15: fuschia
};

const unsigned short progressBarColors[16]
{
0xCE0C, 0x8137, 0x8C1F, 0xFE3F, 0x825F, 0x839E, 0x83F5, 0x83E0, 0x9E80, 0xC769, 0xFAE6, 0xF960, 0xC800, 0xE811, 0xF41A, 0xC81F
};

#endif // START_BORDER_PAL_H

//}}BLOCK(start_border0)
29 changes: 29 additions & 0 deletions romsel_dsimenutheme/arm9/source/graphics/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "common/lodepng.h"
#include <math.h>

extern bool useTwlCfg;

Texture::Texture(const std::string &filePath, const std::string &fallback)
: _paletteLength(0), _texLength(0), _texCmpLength(0), _texHeight(0), _texWidth(0), _type(TextureType::Unknown) {
std::string pngPath;
Expand Down Expand Up @@ -241,6 +243,26 @@ void Texture::applyBitmapEffect(Texture::BitmapEffect effect) {
}
}

void Texture::applyUserPaletteFile(const std::string &filePath, Texture::PaletteEffect fallbackEffect) {
if (_type & TextureType::Paletted) {
FILE *file = fopen(filePath.c_str(), "rb");
if (file) {
u16 *pal = _palette.get();
int offset = ((useTwlCfg ? *(u8*)0x02000444 : PersonalData->theme) * _paletteLength);
fseek(file, sizeof(u16) * offset, SEEK_SET);
fread(pal, sizeof(u16), _paletteLength, file);
fclose(file);
// swap palette bytes
for (int i = 0; i < _paletteLength; i++) {
pal[i] = (pal[i] << 8 & 0xFF00) | pal[i] >> 8;
}
}
else {
fallbackEffect(_palette.get(), _paletteLength);
}
}
}

u16 Texture::bmpToDS(u16 val) {
// Return 0 for #ff00ff
if ((val & 0x7FFF) == 0x7C1F)
Expand All @@ -267,6 +289,13 @@ u16 Texture::bmpToDS(u16 val) {
}
}

bool Texture::exists(const std::string &filePath) {
for (const char *extension : extensions) {
if (access((filePath + extension).c_str(), F_OK) == 0) return true;
}
return false;
}

void Texture::copy(u16 *dst, bool vram) const {
switch(_type) {
case TextureType::PalettedGrf:
Expand Down
3 changes: 3 additions & 0 deletions romsel_dsimenutheme/arm9/source/graphics/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Texture

void applyPaletteEffect(PaletteEffect effect);
void applyBitmapEffect(BitmapEffect effect);
void applyUserPaletteFile(const std::string &filePath, PaletteEffect fallbackEffect);

static u16 bmpToDS(u16 val);

Expand All @@ -77,6 +78,8 @@ class Texture

TextureType type() const { return _type; }

static bool exists(const std::string &filePath);

void copy(u16 *dst, bool vram) const;

private:
Expand Down
84 changes: 60 additions & 24 deletions romsel_dsimenutheme/arm9/source/graphics/ThemeConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,39 @@
#include <nds.h>
#include <string>

ThemeConfig::ThemeConfig() : ThemeConfig(false) {}

// Magic numbers derived from default dark theme
ThemeConfig::ThemeConfig(bool _3dsDefaults)
ThemeConfig::ThemeConfig()
: _startBorderRenderY(81), _startBorderSpriteW(32), _startBorderSpriteH(80), _startTextRenderY(143),
_titleboxRenderY(85), _titleboxMaxLines(4), _titleboxTextY(30), _titleboxTextW(240), _titleboxTextLarge(true),
_bubbleTipRenderY(80), _bubbleTipRenderX(122), _bubbleTipSpriteH(8), _bubbleTipSpriteW(11),
_rotatingCubesRenderY(78), _shoulderLRenderY(172), _shoulderLRenderX(0), _shoulderRRenderY(172), _shoulderRRenderX(178),
_volumeRenderY(4), _volumeRenderX(16), _batteryRenderY(5), _batteryRenderX(235), _usernameRenderY(3), _usernameRenderX(28),
_usernameRenderXDS(4), _dateRenderY(5), _dateRenderX(162), _timeRenderY(5), _timeRenderX(200),
// _photoRenderY(24), _photoRenderX(179),
_startTextUserPalette(true), _startBorderUserPalette(true), _buttonArrowUserPalette(true), _movingArrowUserPalette(true),
_launchDotsUserPalette(true), _dialogBoxUserPalette(true), _usernameUserPalette(true),
_bipsUserPalette(false), _boxUserPalette(false), _boxEmptyUserPalette(false), _boxFullUserPalette(false),
_braceUserPalette(false), _bubbleUserPalette(false), _buttonArrowUserPalette(true), _cornerButtonUserPalette(false),
_cursorUserPalette(false), _dialogBoxUserPalette(true), _folderUserPalette(false), _launchDotsUserPalette(true),
_movingArrowUserPalette(true), _progressUserPalette(true), _scrollWindowUserPalette(false), _smallCartUserPalette(false),
_startBorderUserPalette(true), _startTextUserPalette(true), _wirelessIconsUserPalette(false),
_iconA26UserPalette(false), _iconCOLUserPalette(false), _iconGBUserPalette(false), _iconGBAUserPalette(false),
_iconGBAModeUserPalette(false), _iconGGUserPalette(false), _iconIMGUserPalette(false), _iconINTUserPalette(false),
_iconM5UserPalette(false), _iconManualUserPalette(false), _iconMDUserPalette(false), _iconNESUserPalette(false),
_iconNGPUserPalette(false), _iconPCEUserPalette(false), _iconPLGUserPalette(false), _iconSettingsUserPalette(false),
_iconSGUserPalette(false), _iconSMSUserPalette(false), _iconSNESUserPalette(false), _iconUnknownUserPalette(false),
_iconWSUserPalette(false),
_usernameUserPalette(true), _progressBarUserPalette(true),
_purpleBatteryAvailable(false), _renderPhoto(true), _darkLoading(false), _playStartupJingle(false), _startupJingleDelayAdjust(0),
_progressBarColor(0x7C00),
_fontPalette1(0x0000), _fontPalette2(0xDEF7), _fontPalette3(0xC631), _fontPalette4(0xA108),
_fontPaletteTitlebox1(0x0000), _fontPaletteTitlebox2(0xDEF7), _fontPaletteTitlebox3(0xC631), _fontPaletteTitlebox4(0xA108),
_fontPaletteDialog1(0x0000), _fontPaletteDialog2(0xDEF7), _fontPaletteDialog3(0xC631), _fontPaletteDialog4(0xA108),
_fontPaletteOverlay1(0x0000), _fontPaletteOverlay2(0xDEF7), _fontPaletteOverlay3(0xC631), _fontPaletteOverlay4(0xA108),
_fontPaletteUsername1(0x0000), _fontPaletteUsername2(0xDEF7), _fontPaletteUsername3(0xC631), _fontPaletteUsername4(0xA108),
_fontPaletteDateTime1(0x0000), _fontPaletteDateTime2(0xDEF7), _fontPaletteDateTime3(0xC631), _fontPaletteDateTime4(0xA108)
{
// hack to reassign 3ds defaults
if (_3dsDefaults) {
_startBorderRenderY = 92;
_startBorderSpriteH = 64;
_titleboxRenderY = 96;
_bubbleTipRenderX = 125;
_bubbleTipRenderY = 98;
_bubbleTipSpriteH = 7;
_bubbleTipSpriteW = 7;
_renderPhoto = false;

_titleboxMaxLines = 3;
_titleboxTextY = 55;
_titleboxTextW = 200;
_titleboxTextLarge = false;
if (ms().theme == TWLSettings::ETheme3DS) {
_startBorderUserPalette = false;
_dialogBoxUserPalette = false;
}

if (ms().theme == TWLSettings::EThemeSaturn || ms().theme == TWLSettings::EThemeHBL) {
Expand Down Expand Up @@ -104,20 +101,59 @@ void ThemeConfig::loadConfig() {
_timeRenderY = getInt(themeConfig, "TimeRenderY", _timeRenderY);
_timeRenderX = getInt(themeConfig, "TimeRenderX", _timeRenderX);

_startTextUserPalette = getInt(themeConfig, "StartTextUserPalette", _startTextUserPalette);
_startBorderUserPalette = getInt(themeConfig, "StartBorderUserPalette", _startBorderUserPalette);
_bipsUserPalette = getInt(themeConfig, "BipsUserPalette", _bipsUserPalette);
_boxUserPalette = getInt(themeConfig, "BoxUserPalette", _boxUserPalette);
_boxEmptyUserPalette = getInt(themeConfig, "BoxEmptyUserPalette", _boxEmptyUserPalette);
_boxFullUserPalette = getInt(themeConfig, "BoxFullUserPalette", _boxFullUserPalette);
_braceUserPalette = getInt(themeConfig, "BraceUserPalette", _braceUserPalette);
_bubbleUserPalette = getInt(themeConfig, "BubbleUserPalette", _bubbleUserPalette);
_buttonArrowUserPalette = getInt(themeConfig, "ButtonArrowUserPalette", _buttonArrowUserPalette);
_movingArrowUserPalette = getInt(themeConfig, "MovingArrowUserPalette", _movingArrowUserPalette);
_launchDotsUserPalette = getInt(themeConfig, "LaunchDotsUserPalette", _launchDotsUserPalette);
_cornerButtonUserPalette = getInt(themeConfig, "CornerButtonUserPalette", _cornerButtonUserPalette);
_cursorUserPalette = getInt(themeConfig, "CursorUserPalette", _cursorUserPalette);
_dialogBoxUserPalette = getInt(themeConfig, "DialogBoxUserPalette", _dialogBoxUserPalette);
_folderUserPalette = getInt(themeConfig, "FolderUserPalette", _folderUserPalette);
_launchDotsUserPalette = getInt(themeConfig, "LaunchDotsUserPalette", _launchDotsUserPalette);
_movingArrowUserPalette = getInt(themeConfig, "MovingArrowUserPalette", _movingArrowUserPalette);
_progressUserPalette = getInt(themeConfig, "ProgressUserPalette", _progressUserPalette);
_scrollWindowUserPalette = getInt(themeConfig, "ScrollWindowUserPalette", _scrollWindowUserPalette);
_smallCartUserPalette = getInt(themeConfig, "SmallCartUserPalette", _smallCartUserPalette);
_startBorderUserPalette = getInt(themeConfig, "StartBorderUserPalette", _startBorderUserPalette);
_startTextUserPalette = getInt(themeConfig, "StartTextUserPalette", _startTextUserPalette);
_wirelessIconsUserPalette = getInt(themeConfig, "WirelessIconsUserPalette", _wirelessIconsUserPalette);

_iconA26UserPalette = getInt(themeConfig, "IconA26UserPalette", _iconA26UserPalette);
_iconCOLUserPalette = getInt(themeConfig, "IconCOLUserPalette", _iconCOLUserPalette);
_iconGBUserPalette = getInt(themeConfig, "IconGBUserPalette", _iconGBUserPalette);
_iconGBAUserPalette = getInt(themeConfig, "IconGBAUserPalette", _iconGBAUserPalette);
_iconGBAModeUserPalette = getInt(themeConfig, "IconGBAModeUserPalette", _iconGBAModeUserPalette);
_iconGGUserPalette = getInt(themeConfig, "IconGGUserPalette", _iconGGUserPalette);
_iconIMGUserPalette = getInt(themeConfig, "IconIMGUserPalette", _iconIMGUserPalette);
_iconINTUserPalette = getInt(themeConfig, "IconINTUserPalette", _iconINTUserPalette);
_iconM5UserPalette = getInt(themeConfig, "IconM5UserPalette", _iconM5UserPalette);
_iconManualUserPalette = getInt(themeConfig, "IconManualUserPalette", _iconManualUserPalette);
_iconMDUserPalette = getInt(themeConfig, "IconMDUserPalette", _iconMDUserPalette);
_iconNESUserPalette = getInt(themeConfig, "IconNESUserPalette", _iconNESUserPalette);
_iconNGPUserPalette = getInt(themeConfig, "IconNGPUserPalette", _iconNGPUserPalette);
_iconPCEUserPalette = getInt(themeConfig, "IconPCEUserPalette", _iconPCEUserPalette);
_iconPLGUserPalette = getInt(themeConfig, "IconPLGUserPalette", _iconPLGUserPalette);
_iconSettingsUserPalette = getInt(themeConfig, "IconSettingsUserPalette", _iconSettingsUserPalette);
_iconSGUserPalette = getInt(themeConfig, "IconSGUserPalette", _iconSGUserPalette);
_iconSMSUserPalette = getInt(themeConfig, "IconSMSUserPalette", _iconSMSUserPalette);
_iconSNESUserPalette = getInt(themeConfig, "IconSNESUserPalette", _iconSNESUserPalette);
_iconUnknownUserPalette = getInt(themeConfig, "IconUnknownUserPalette", _iconUnknownUserPalette);
_iconWSUserPalette = getInt(themeConfig, "IconWSUserPalette", _iconWSUserPalette);

_usernameUserPalette = getInt(themeConfig, "UsernameUserPalette", _usernameUserPalette);
_progressBarUserPalette = getInt(themeConfig, "ProgressBarUserPalette", _progressBarUserPalette);

_purpleBatteryAvailable = getInt(themeConfig, "PurpleBatteryAvailable", _purpleBatteryAvailable);
_rotatingCubesRenderY = getInt(themeConfig, "RotatingCubesRenderY", _rotatingCubesRenderY);
_renderPhoto = getInt(themeConfig, "RenderPhoto", _renderPhoto);
_darkLoading = getInt(themeConfig, "DarkLoading", _darkLoading);

_playStartupJingle = getInt(themeConfig, "PlayStartupJingle", _playStartupJingle);
_startupJingleDelayAdjust = getInt(themeConfig, "StartupJingleDelayAdjust", _startupJingleDelayAdjust);
_progressBarColor = getInt(themeConfig, "ProgressBarColor", _progressBarColor);

_fontPalette1 = getInt(themeConfig, "FontPalette1", _fontPalette1);
_fontPalette2 = getInt(themeConfig, "FontPalette2", _fontPalette2);
Expand Down
93 changes: 82 additions & 11 deletions romsel_dsimenutheme/arm9/source/graphics/ThemeConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,55 @@ class ThemeConfig {
// int _photoRenderY;
// int _photoRenderX;

bool _startTextUserPalette;
bool _startBorderUserPalette;
bool _bipsUserPalette;
bool _boxUserPalette;
bool _boxEmptyUserPalette;
bool _boxFullUserPalette;
bool _braceUserPalette;
bool _bubbleUserPalette;
bool _buttonArrowUserPalette;
bool _movingArrowUserPalette;
bool _launchDotsUserPalette;
bool _cornerButtonUserPalette;
bool _cursorUserPalette;
bool _dialogBoxUserPalette;
bool _folderUserPalette;
bool _launchDotsUserPalette;
bool _movingArrowUserPalette;
bool _progressUserPalette;
bool _scrollWindowUserPalette;
bool _smallCartUserPalette;
bool _startBorderUserPalette;
bool _startTextUserPalette;
bool _wirelessIconsUserPalette;
bool _iconA26UserPalette;
bool _iconCOLUserPalette;
bool _iconGBUserPalette;
bool _iconGBAUserPalette;
bool _iconGBAModeUserPalette;
bool _iconGGUserPalette;
bool _iconIMGUserPalette;
bool _iconINTUserPalette;
bool _iconM5UserPalette;
bool _iconManualUserPalette;
bool _iconMDUserPalette;
bool _iconNESUserPalette;
bool _iconNGPUserPalette;
bool _iconPCEUserPalette;
bool _iconPLGUserPalette;
bool _iconSettingsUserPalette;
bool _iconSGUserPalette;
bool _iconSMSUserPalette;
bool _iconSNESUserPalette;
bool _iconUnknownUserPalette;
bool _iconWSUserPalette;
bool _usernameUserPalette;
bool _progressBarUserPalette;

bool _purpleBatteryAvailable;

bool _renderPhoto;
bool _darkLoading;
bool _playStartupJingle;
int _startupJingleDelayAdjust;
u16 _progressBarColor;

u16 _fontPalette1;
u16 _fontPalette2;
Expand Down Expand Up @@ -94,7 +130,6 @@ class ThemeConfig {

public:
ThemeConfig();
ThemeConfig(bool _3dsDefaults);
virtual ~ThemeConfig() = default;

void loadConfig();
Expand Down Expand Up @@ -141,20 +176,56 @@ class ThemeConfig {
// int photoRenderY() const { return _photoRenderY; }
// int photoRenderX() const { return _photoRenderX; }

bool startTextUserPalette() const { return _startTextUserPalette; }
bool startBorderUserPalette() const { return _startBorderUserPalette; }
bool bipsUserPalette() const { return _bipsUserPalette; }
bool boxUserPalette() const { return _boxUserPalette; }
bool boxEmptyUserPalette() const { return _boxEmptyUserPalette; }
bool boxFullUserPalette() const { return _boxFullUserPalette; }
bool braceUserPalette() const { return _braceUserPalette; }
bool bubbleUserPalette() const { return _bubbleUserPalette; }
bool buttonArrowUserPalette() const { return _buttonArrowUserPalette; }
bool movingArrowUserPalette() const { return _movingArrowUserPalette; }
bool launchDotsUserPalette() const { return _launchDotsUserPalette; }
bool cornerButtonUserPalette() const { return _cornerButtonUserPalette; }
bool cursorUserPalette() const { return _cursorUserPalette; }
bool dialogBoxUserPalette() const { return _dialogBoxUserPalette; }
bool folderUserPalette() const { return _folderUserPalette; }
bool launchDotsUserPalette() const { return _launchDotsUserPalette; }
bool movingArrowUserPalette() const { return _movingArrowUserPalette; }
bool progressUserPalette() const { return _progressUserPalette; }
bool scrollWindowUserPalette() const { return _scrollWindowUserPalette; }
bool smallCartUserPalette() const { return _smallCartUserPalette; }
bool startBorderUserPalette() const { return _startBorderUserPalette; }
bool startTextUserPalette() const { return _startTextUserPalette; }
bool wirelessIconsUserPalette() const { return _wirelessIconsUserPalette; }
bool iconA26UserPalette() const { return _iconA26UserPalette; }
bool iconCOLUserPalette() const { return _iconCOLUserPalette; }
bool iconGBUserPalette() const { return _iconGBUserPalette; }
bool iconGBAUserPalette() const { return _iconGBAUserPalette; }
bool iconGBAModeUserPalette() const { return _iconGBAModeUserPalette; }
bool iconGGUserPalette() const { return _iconGGUserPalette; }
bool iconIMGUserPalette() const { return _iconIMGUserPalette; }
bool iconINTUserPalette() const { return _iconINTUserPalette; }
bool iconM5UserPalette() const { return _iconM5UserPalette; }
bool iconManualUserPalette() const { return _iconManualUserPalette; }
bool iconMDUserPalette() const { return _iconMDUserPalette; }
bool iconNESUserPalette() const { return _iconNESUserPalette; }
bool iconNGPUserPalette() const { return _iconNGPUserPalette; }
bool iconPCEUserPalette() const { return _iconPCEUserPalette; }
bool iconPLGUserPalette() const { return _iconPLGUserPalette; }
bool iconSettingsUserPalette() const { return _iconSettingsUserPalette; }
bool iconSGUserPalette() const { return _iconSGUserPalette; }
bool iconSMSUserPalette() const { return _iconSMSUserPalette; }
bool iconSNESUserPalette() const { return _iconSNESUserPalette; }
bool iconUnknownUserPalette() const { return _iconUnknownUserPalette; }
bool iconWSUserPalette() const { return _iconWSUserPalette; }
bool usernameUserPalette() const { return _usernameUserPalette; }
bool purpleBatteryAvailable() const { return _purpleBatteryAvailable; }
bool progressBarUserPalette() const { return _progressBarUserPalette; }

bool purpleBatteryAvailable() const { return _purpleBatteryAvailable; }
bool renderPhoto() const { return _renderPhoto; }
bool darkLoading() const { return _darkLoading; }

bool playStartupJingle() const { return _playStartupJingle; }
int startupJingleDelayAdjust() const { return _startupJingleDelayAdjust; }
u16 progressBarColor() const { return _progressBarColor; }

u16 fontPalette1() const { return _fontPalette1; }
u16 fontPalette2() const { return _fontPalette2; }
Expand Down
Loading

0 comments on commit 2ca6855

Please sign in to comment.