Custom palette persistence fix (#233)

Bug:
    Clicking on Palette Preset to cycle through palettes overwrites and erases the custom palette

Fix:
    Added config values coop_custom_palette_* to save the custom palette colors
    Clicking on Edit Palette now sets the current palette to Custom and loads the custom values instead of using the previous preset selected
This commit is contained in:
PeachyPeach 2022-11-19 03:43:44 +01:00 committed by GitHub
parent 452c641758
commit 36d85af91b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 7 deletions

View file

@ -137,6 +137,7 @@ unsigned int configMenuLevel = 0;
bool configMenuSound = false;
bool configMenuRandom = false;
struct PlayerPalette configPlayerPalette = {{{ 0x00, 0x00, 0xff }, { 0xff, 0x00, 0x00 }, { 0xff, 0xff, 0xff }, { 0x72, 0x1c, 0x0e }, { 0x73, 0x06, 0x00 }, { 0xfe, 0xc1, 0x79 }, { 0xff, 0x00, 0x00 }}};
struct PlayerPalette configCustomPalette = {{{ 0x00, 0x00, 0xff }, { 0xff, 0x00, 0x00 }, { 0xff, 0xff, 0xff }, { 0x72, 0x1c, 0x0e }, { 0x73, 0x06, 0x00 }, { 0xfe, 0xc1, 0x79 }, { 0xff, 0x00, 0x00 }}};
bool configUncappedFramerate = true;
unsigned int configFrameLimit = 60;
unsigned int configDrawDistance = 5;
@ -236,6 +237,13 @@ static const struct ConfigOption options[] = {
{.name = "coop_player_palette_hair", .type = CONFIG_TYPE_COLOR , .colorValue = &configPlayerPalette.parts[HAIR]},
{.name = "coop_player_palette_skin", .type = CONFIG_TYPE_COLOR , .colorValue = &configPlayerPalette.parts[SKIN]},
{.name = "coop_player_palette_cap", .type = CONFIG_TYPE_COLOR , .colorValue = &configPlayerPalette.parts[CAP]},
{.name = "coop_custom_palette_pants", .type = CONFIG_TYPE_COLOR , .colorValue = &configCustomPalette.parts[PANTS]},
{.name = "coop_custom_palette_shirt", .type = CONFIG_TYPE_COLOR , .colorValue = &configCustomPalette.parts[SHIRT]},
{.name = "coop_custom_palette_gloves", .type = CONFIG_TYPE_COLOR , .colorValue = &configCustomPalette.parts[GLOVES]},
{.name = "coop_custom_palette_shoes", .type = CONFIG_TYPE_COLOR , .colorValue = &configCustomPalette.parts[SHOES]},
{.name = "coop_custom_palette_hair", .type = CONFIG_TYPE_COLOR , .colorValue = &configCustomPalette.parts[HAIR]},
{.name = "coop_custom_palette_skin", .type = CONFIG_TYPE_COLOR , .colorValue = &configCustomPalette.parts[SKIN]},
{.name = "coop_custom_palette_cap", .type = CONFIG_TYPE_COLOR , .colorValue = &configCustomPalette.parts[CAP]},
{.name = "coop_stay_in_level_after_star", .type = CONFIG_TYPE_UINT , .uintValue = &configStayInLevelAfterStar},
{.name = "share_lives", .type = CONFIG_TYPE_BOOL , .boolValue = &configShareLives},
{.name = "disable_popups", .type = CONFIG_TYPE_BOOL , .boolValue = &configDisablePopups},

View file

@ -94,6 +94,7 @@ extern unsigned int configMenuLevel;
extern bool configMenuSound;
extern bool configMenuRandom;
extern struct PlayerPalette configPlayerPalette;
extern struct PlayerPalette configCustomPalette;
extern bool configUncappedFramerate;
extern unsigned int configFrameLimit;
extern unsigned int configDrawDistance;

View file

@ -23,8 +23,8 @@ static void djui_panel_player_edit_palette_update_hex_code_box() {
static const char digitToChar[] = "0123456789abcdef";
for (size_t i = 0; i < 3; i++) {
buf[2*i] = digitToChar[configPlayerPalette.parts[sCurrentPlayerPart][i] >> 4];
buf[2*i+1] = digitToChar[configPlayerPalette.parts[sCurrentPlayerPart][i] & 0xF];
buf[2*i] = digitToChar[configCustomPalette.parts[sCurrentPlayerPart][i] >> 4];
buf[2*i+1] = digitToChar[configCustomPalette.parts[sCurrentPlayerPart][i] & 0xF];
}
buf[6] = '\0';
@ -41,7 +41,7 @@ static void djui_panel_player_edit_palette_update_palette_display() {
}
static void djui_panel_player_edit_palette_update_sliders() {
for (int i = 0; i < 3; i++) sSliderChannels[i] = configPlayerPalette.parts[sCurrentPlayerPart][i];
for (int i = 0; i < 3; i++) sSliderChannels[i] = configCustomPalette.parts[sCurrentPlayerPart][i];
djui_slider_update_value(&sSliderR->base);
djui_slider_update_value(&sSliderG->base);
@ -72,9 +72,10 @@ static void djui_panel_player_edit_palette_hex_code_changed(struct DjuiBase* cal
}
for (int i = 0; i < 3; i++) {
configPlayerPalette.parts[sCurrentPlayerPart][i] = (char_to_hex_digit(input->buffer[2 * i]) << 4) |
configCustomPalette.parts[sCurrentPlayerPart][i] = (char_to_hex_digit(input->buffer[2 * i]) << 4) |
char_to_hex_digit(input->buffer[2 * i + 1]);
}
configPlayerPalette = configCustomPalette;
djui_panel_player_edit_palette_update_sliders();
djui_panel_player_edit_palette_update_palette_display();
@ -82,7 +83,8 @@ static void djui_panel_player_edit_palette_hex_code_changed(struct DjuiBase* cal
}
static void djui_panel_player_edit_palette_slider_changed(UNUSED struct DjuiBase* caller, size_t index) {
configPlayerPalette.parts[sCurrentPlayerPart][index] = sSliderChannels[index];
configCustomPalette.parts[sCurrentPlayerPart][index] = sSliderChannels[index];
configPlayerPalette = configCustomPalette;
djui_panel_player_edit_palette_update_hex_code_box();
djui_panel_player_edit_palette_update_palette_display();
@ -120,6 +122,11 @@ static void djui_panel_player_edit_palette_create(struct DjuiBase* caller) {
struct DjuiBase* defaultBase = NULL;
struct DjuiThreePanel* panel = djui_panel_menu_create(bodyHeight, "\\#ff0800\\P\\#1be700\\A\\#00b3ff\\L\\#ffef00\\E\\#ff0800\\T\\#1be700\\T\\#00b3ff\\E");
// Set current palette to custom when clicking on Edit Palette
sPalettePresetIndex = PALETTE_CUSTOM;
configPlayerPalette = configCustomPalette;
djui_panel_player_edit_palette_update_palette_display();
// A bit of a gross hack to send out palette changes and update the palette preset selection box on unpause AND
// pressing the Back button
sSavedDestroy = panel->base.destroy;
@ -153,7 +160,7 @@ static void djui_panel_player_edit_palette_create(struct DjuiBase* caller) {
djui_interactable_hook_value_change(&sHexColorTextBox->base, djui_panel_player_edit_palette_hex_code_changed);
}
for (int i = 0; i < 3; i++) sSliderChannels[i] = configPlayerPalette.parts[SHIRT][i];
for (int i = 0; i < 3; i++) sSliderChannels[i] = configCustomPalette.parts[SHIRT][i];
sSliderR = djui_slider_create(&body->base, "Red", &sSliderChannels[0], 0, 255);
djui_base_set_size_type(&sSliderR->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
@ -217,8 +224,10 @@ static void djui_panel_player_name_on_focus_end(struct DjuiBase* caller) {
static void djui_panel_player_value_changed(UNUSED struct DjuiBase* caller) {
if (sPalettePresetIndex != PALETTE_CUSTOM) {
configPlayerPalette = gPalettePresets[sPalettePresetIndex];
djui_panel_player_edit_palette_update_palette_display();
} else {
configPlayerPalette = configCustomPalette;
}
djui_panel_player_edit_palette_update_palette_display();
if (configPlayerModel >= CT_MAX) { configPlayerModel = 0; }
if (gNetworkPlayers[0].overrideModelIndex == gNetworkPlayers[0].modelIndex) { gNetworkPlayers[0].overrideModelIndex = configPlayerModel; }

View file

@ -273,6 +273,17 @@ void main_func(void) {
configfile_load(configfile_name());
dynos_pack_init();
// If coop_custom_palette_* values are not found in sm64config.txt, the custom palette config will use the default values (Mario's palette)
// But if no preset is found, that means the current palette is a custom palette
for (int i = 0; i <= PALETTE_PRESET_MAX; i++) {
if (i == PALETTE_PRESET_MAX) {
configCustomPalette = configPlayerPalette;
configfile_save(configfile_name());
} else if (memcmp(&configPlayerPalette, &gPalettePresets[i], sizeof(struct PlayerPalette)) == 0) {
break;
}
}
if (configPlayerModel >= CT_MAX) { configPlayerModel = 0; }
if (gCLIOpts.FullScreen == 1)