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
|
else
|
||||||
sprintf (options.value[5], "Off");
|
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");
|
sprintf(options.value[6], "Custom");
|
||||||
else
|
else
|
||||||
sprintf(options.value[6], "Default");
|
sprintf(options.value[6], "Default");
|
||||||
@ -3623,6 +3623,9 @@ GXColor GetCol(int i) {
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static int MenuPalette()
|
static int MenuPalette()
|
||||||
{
|
{
|
||||||
|
// We are now using a custom palette
|
||||||
|
strncpy(CurrentPalette.gameName, RomTitle, 17);
|
||||||
|
|
||||||
int menu = MENU_NONE;
|
int menu = MENU_NONE;
|
||||||
|
|
||||||
GuiText titleTxt("Palette", 28, (GXColor){255, 255, 255, 255});
|
GuiText titleTxt("Palette", 28, (GXColor){255, 255, 255, 255});
|
||||||
@ -4058,13 +4061,13 @@ static int MenuPalette()
|
|||||||
}
|
}
|
||||||
else if(importBtn.GetState() == STATE_CLICKED)
|
else if(importBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
SavePalettes(SILENT);
|
SavePaletteAs(NOTSILENT, RomTitle);
|
||||||
menu = MENU_GAMESETTINGS_PALETTE;
|
menu = MENU_GAMESETTINGS_PALETTE;
|
||||||
}
|
}
|
||||||
else if(closeBtn.GetState() == STATE_CLICKED)
|
else if(closeBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
menu = MENU_EXIT;
|
menu = MENU_EXIT;
|
||||||
SavePalettes(SILENT);
|
SavePaletteAs(SILENT, RomTitle);
|
||||||
SavePrefs(NOTSILENT);
|
SavePrefs(NOTSILENT);
|
||||||
|
|
||||||
exitSound->Play();
|
exitSound->Play();
|
||||||
@ -4081,7 +4084,7 @@ static int MenuPalette()
|
|||||||
}
|
}
|
||||||
else if(backBtn.GetState() == STATE_CLICKED)
|
else if(backBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
SavePalettes(SILENT);
|
SavePaletteAs(SILENT, RomTitle);
|
||||||
menu = MENU_GAMESETTINGS_VIDEO;
|
menu = MENU_GAMESETTINGS_VIDEO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -676,11 +676,18 @@ bool SavePalettes(bool silent)
|
|||||||
return false;
|
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++)
|
for (int i=0; i < loadedPalettes; i++)
|
||||||
if (strcmp(palettes[i].gameName, gameName)==0)
|
if (strcmp(palettes[i].gameName, gameName)==0) {
|
||||||
return;
|
if (overwrite) {
|
||||||
|
palettes[i] = pal;
|
||||||
|
strncpy(palettes[i].gameName, gameName, 17);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
palettes = (gamePalette *)realloc(palettes, sizeof(gamePalette)*(loadedPalettes+1));
|
palettes = (gamePalette *)realloc(palettes, sizeof(gamePalette)*(loadedPalettes+1));
|
||||||
palettes[loadedPalettes] = pal;
|
palettes[loadedPalettes] = pal;
|
||||||
@ -688,6 +695,12 @@ static void AddPalette(gamePalette pal, const char *gameName)
|
|||||||
loadedPalettes++;
|
loadedPalettes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SavePaletteAs(bool silent, const char *name)
|
||||||
|
{
|
||||||
|
AddPalette(CurrentPalette, name, true);
|
||||||
|
return SavePalettes(silent);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Load Palettes
|
* Load Palettes
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
@ -718,7 +731,7 @@ bool LoadPalettes()
|
|||||||
|
|
||||||
// add hard-coded palettes
|
// add hard-coded palettes
|
||||||
for (int i=0; i<gamePalettesCount; i++)
|
for (int i=0; i<gamePalettesCount; i++)
|
||||||
AddPalette(gamePalettes[i], gamePalettes[i].gameName);
|
AddPalette(gamePalettes[i], gamePalettes[i].gameName, false);
|
||||||
|
|
||||||
if (!retval)
|
if (!retval)
|
||||||
retval = SavePalettes(SILENT);
|
retval = SavePalettes(SILENT);
|
||||||
@ -741,11 +754,27 @@ void SetPalette(const char *gameName)
|
|||||||
// match found!
|
// match found!
|
||||||
if(snum >= 0)
|
if(snum >= 0)
|
||||||
{
|
{
|
||||||
CurrentPalette = gamePalettes[snum];
|
CurrentPalette = palettes[snum];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
// no match, use the default palette
|
||||||
{
|
{
|
||||||
CurrentPalette = gamePalettes[0]; // use the default palette
|
for (int i = 0; i < loadedPalettes; i++)
|
||||||
AddPalette(gamePalettes[0], gameName); // add this game to the palette list
|
{
|
||||||
|
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 SavePalettes (bool silent);
|
||||||
bool LoadPalettes();
|
bool LoadPalettes();
|
||||||
void SetPalette(const char *gameName);
|
void SetPalette(const char *gameName);
|
||||||
|
bool SavePaletteAs(bool silent, const char *name);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user