mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-25 12:06:53 +01:00
partial cleanup of Tantric's palette saving/loading disaster code
This commit is contained in:
parent
a8eb751e40
commit
fd1fdc585c
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<gamePalettesCount; i++)
|
||||
AddPalette(gamePalettes[i], gamePalettes[i].gameName);
|
||||
AddPalette(gamePalettes[i], gamePalettes[i].gameName, false);
|
||||
|
||||
if (!retval)
|
||||
retval = SavePalettes(SILENT);
|
||||
@ -741,11 +754,27 @@ void SetPalette(const char *gameName)
|
||||
// match found!
|
||||
if(snum >= 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
|
||||
}
|
||||
}
|
||||
|
@ -13,3 +13,5 @@ bool LoadPrefs ();
|
||||
bool SavePalettes (bool silent);
|
||||
bool LoadPalettes();
|
||||
void SetPalette(const char *gameName);
|
||||
bool SavePaletteAs(bool silent, const char *name);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user