From fd1fdc585ce939b1245a80781f8deaafeebfac45 Mon Sep 17 00:00:00 2001 From: "Carl.Kenner" Date: Mon, 1 Jun 2009 12:36:56 +0000 Subject: [PATCH] partial cleanup of Tantric's palette saving/loading disaster code --- source/ngc/menu.cpp | 11 ++++++---- source/ngc/preferences.cpp | 43 +++++++++++++++++++++++++++++++------- source/ngc/preferences.h | 2 ++ 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 9577fd6..dbed652 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -2741,7 +2741,7 @@ static int MenuSettingsVideo() else sprintf (options.value[5], "Off"); - if(true) // TODO - show custom if different from the default palette + if(strcmp(CurrentPalette.gameName,"default")) sprintf(options.value[6], "Custom"); else sprintf(options.value[6], "Default"); @@ -3623,6 +3623,9 @@ GXColor GetCol(int i) { ***************************************************************************/ static int MenuPalette() { + // We are now using a custom palette + strncpy(CurrentPalette.gameName, RomTitle, 17); + int menu = MENU_NONE; GuiText titleTxt("Palette", 28, (GXColor){255, 255, 255, 255}); @@ -4058,13 +4061,13 @@ static int MenuPalette() } else if(importBtn.GetState() == STATE_CLICKED) { - SavePalettes(SILENT); + SavePaletteAs(NOTSILENT, RomTitle); menu = MENU_GAMESETTINGS_PALETTE; } else if(closeBtn.GetState() == STATE_CLICKED) { menu = MENU_EXIT; - SavePalettes(SILENT); + SavePaletteAs(SILENT, RomTitle); SavePrefs(NOTSILENT); exitSound->Play(); @@ -4081,7 +4084,7 @@ static int MenuPalette() } else if(backBtn.GetState() == STATE_CLICKED) { - SavePalettes(SILENT); + SavePaletteAs(SILENT, RomTitle); menu = MENU_GAMESETTINGS_VIDEO; } } diff --git a/source/ngc/preferences.cpp b/source/ngc/preferences.cpp index 578b10e..0984b26 100644 --- a/source/ngc/preferences.cpp +++ b/source/ngc/preferences.cpp @@ -676,11 +676,18 @@ bool SavePalettes(bool silent) return false; } -static void AddPalette(gamePalette pal, const char *gameName) +static void AddPalette(gamePalette pal, const char *gameName, bool overwrite) { for (int i=0; i < loadedPalettes; i++) - if (strcmp(palettes[i].gameName, gameName)==0) - return; + if (strcmp(palettes[i].gameName, gameName)==0) { + if (overwrite) { + palettes[i] = pal; + strncpy(palettes[i].gameName, gameName, 17); + return; + } else { + return; + } + } palettes = (gamePalette *)realloc(palettes, sizeof(gamePalette)*(loadedPalettes+1)); palettes[loadedPalettes] = pal; @@ -688,6 +695,12 @@ static void AddPalette(gamePalette pal, const char *gameName) loadedPalettes++; } +bool SavePaletteAs(bool silent, const char *name) +{ + AddPalette(CurrentPalette, name, true); + return SavePalettes(silent); +} + /**************************************************************************** * Load Palettes ***************************************************************************/ @@ -718,7 +731,7 @@ bool LoadPalettes() // add hard-coded palettes for (int i=0; i= 0) { - CurrentPalette = gamePalettes[snum]; + CurrentPalette = palettes[snum]; } else + // no match, use the default palette { - CurrentPalette = gamePalettes[0]; // use the default palette - AddPalette(gamePalettes[0], gameName); // add this game to the palette list + for (int i = 0; i < loadedPalettes; i++) + { + if(strcmp(gameName, "default")==0) + { + snum = i; + break; + } + } + if(snum >= 0) + { + CurrentPalette = palettes[snum]; + } + else + { + CurrentPalette = palettes[0]; + } + // DON'T add this game to the palette list } } diff --git a/source/ngc/preferences.h b/source/ngc/preferences.h index 1568e47..6e2a6c7 100644 --- a/source/ngc/preferences.h +++ b/source/ngc/preferences.h @@ -13,3 +13,5 @@ bool LoadPrefs (); bool SavePalettes (bool silent); bool LoadPalettes(); void SetPalette(const char *gameName); +bool SavePaletteAs(bool silent, const char *name); +