Why isn't this working???

This commit is contained in:
Carl.Kenner 2009-05-29 20:04:11 +00:00
parent aec190e63f
commit 5a8546d5bf
4 changed files with 288 additions and 159 deletions

View File

@ -21,47 +21,47 @@ int gamePalettesCount = 19;
// 3 Sprite 1 Colours (brightest to dark), 3 Sprite 2 Colours (brightest to dark) // 3 Sprite 1 Colours (brightest to dark), 3 Sprite 2 Colours (brightest to dark)
gamePalette gamePalettes[19] = { gamePalette gamePalettes[19] = {
{"default", {0x00FF00,0x00AD00,0x006300,0x002000, 0xFFFFFF,0xADADAD,0x636363,0x000000, {"default", 1, {0x00FF00,0x00AD00,0x006300,0x002000, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0xFF0000,0xAD0000,0x630000, 0x0000FF,0x0000AD,0x000063}} 0xFF0000,0xAD0000,0x630000, 0x0000FF,0x0000AD,0x000063}}
,{"BASEBALL", {0x009000,0x006000,0x003000,0x000000, 0xFFFFFF,0xAD0000,0x630000,0x000000, ,{"BASEBALL", 1, {0x009000,0x006000,0x003000,0x000000, 0xFFFFFF,0xAD0000,0x630000,0x000000,
0xFFD060,0xAD0000,0x630000, 0x0050AD,0xFFD060,0x0040A0}} 0xFFD060,0xAD0000,0x630000, 0x0050AD,0xFFD060,0x0040A0}}
,{"MAGNETIC SOCCER", {0x009000,0x006000,0x003000,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"MAGNETIC SOCCER", 1, {0x009000,0x006000,0x003000,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0xFF0000,0xAD0000,0x630000, 0x0000FF,0x0000AD,0x000063}} 0xFF0000,0xAD0000,0x630000, 0x0000FF,0x0000AD,0x000063}}
,{"BEACH,VOLLEYBALL", {0xD4B4A4,0xADAD30,0x000063,0x000020, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"BEACH,VOLLEYBALL", 1, {0xD4B4A4,0xADAD30,0x000063,0x000020, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0xB49E90,0xB00000,0x31271E, 0x0000FF,0x0000AD,0x000063}} 0xB49E90,0xB00000,0x31271E, 0x0000FF,0x0000AD,0x000063}}
,{"MARBLE MADNESS", {0x00FFFF,0x00ADAD,0x006363,0x303030, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"MARBLE MADNESS", 1, {0x00FFFF,0x00ADAD,0x006363,0x303030, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0xFF0000,0xAD0000,0x630000, 0xFFFF00,0xAD8000,0x634000}} 0xFF0000,0xAD0000,0x630000, 0xFFFF00,0xAD8000,0x634000}}
,{"METROID2", {0xFF7B30,0xAD5230,0x300063,0x000018, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"METROID2", 1, {0xFF7B30,0xAD5230,0x300063,0x000018, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0x7B6300,0xAD0000,0x636363, 0xFF00FF,0x8400AD,0x300063}} 0x7B6300,0xAD0000,0x636363, 0xFF00FF,0x8400AD,0x300063}}
,{"MORTAL KOMBAT", {0xADFF00,0x00AD00,0x006300,0x400000, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"MORTAL KOMBAT", 1, {0xADFF00,0x00AD00,0x006300,0x400000, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0xFFFF00,0xADAD00,0x636300, 0xFFFF00,0xADAD00,0x636300}} 0xFFFF00,0xADAD00,0x636300, 0xFFFF00,0xADAD00,0x636300}}
,{"MORTAL KOMBAT II", {0xC0B0FF,0x6890A0,0x303063,0x000000, 0xADFF00,0x00AD00,0x006300,0x400000, ,{"MORTAL KOMBAT II", 1, {0xC0B0FF,0x6890A0,0x303063,0x000000, 0xADFF00,0x00AD00,0x006300,0x400000,
0xC9A104,0xBF5000,0xB20A00, 0x8080FF,0x5050AD,0x303063}} 0xC9A104,0xBF5000,0xB20A00, 0x8080FF,0x5050AD,0x303063}}
,{"MORTAL KOMBAT 3", {0xFFFFFF,0x6060A0,0x535373,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"MORTAL KOMBAT 3", 1, {0xFFFFFF,0x6060A0,0x535373,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0xF5CCAC,0x9A7057,0x630000, 0xA87860,0x882020,0x000000}} 0xF5CCAC,0x9A7057,0x630000, 0xA87860,0x882020,0x000000}}
,{"MR.DO!", {0x38F038,0x00C800,0x705000,0x600000, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"MR.DO!", 1, {0x38F038,0x00C800,0x705000,0x600000, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0xFFFFFF,0xADADAD,0x636363, 0xFFFFFF,0xADADAD,0x636363}} 0xFFFFFF,0xADADAD,0x636363, 0xFFFFFF,0xADADAD,0x636363}}
,{"SIMPSONS3", {0x80FF40,0x00AD50,0x006300,0x402000, 0xE0D000,0xADADAD,0x636363,0x000000, ,{"SIMPSONS3", 1, {0x80FF40,0x00AD50,0x006300,0x402000, 0xE0D000,0xADADAD,0x636363,0x000000,
0xF0E000,0xAD4000,0x0000FF, 0xFF0000,0xAD0000,0x630000}} 0xF0E000,0xAD4000,0x0000FF, 0xFF0000,0xAD0000,0x630000}}
,{"SUPER MARIO LAND", {0x90A0FF,0x80AD00,0x636300,0x301800, 0xFFFF40,0xADAD00,0x636300,0x000000, ,{"SUPER MARIO LAND", 1, {0x90A0FF,0x80AD00,0x636300,0x301800, 0xFFFF40,0xADAD00,0x636300,0x000000,
0xFFE080,0x0000AD,0xFF0000, 0xFFFFFF,0xADADAD,0x636363}} 0xFFE080,0x0000AD,0xFF0000, 0xFFFFFF,0xADADAD,0x636363}}
,{"TMNT FOOT CLAN", {0xFFFF80,0xADB800,0x636300,0x302000, 0x8080FF,0x0000AD,0x000063,0x000030, ,{"TMNT FOOT CLAN", 1, {0xFFFF80,0xADB800,0x636300,0x302000, 0x8080FF,0x0000AD,0x000063,0x000030,
0x60A060,0x633030,0x533000, 0xFFFFFF,0xADADAD,0x636363}} 0x60A060,0x633030,0x533000, 0xFFFFFF,0xADADAD,0x636363}}
,{"TENNIS", {0x008000,0xB49E90,0x630000,0x000000, 0xFFFFFF,0xB49E90,0x630000,0x201000, ,{"TENNIS", 1, {0x008000,0xB49E90,0x630000,0x000000, 0xFFFFFF,0xB49E90,0x630000,0x201000,
0xB4A880,0xADAD00,0x632000, 0x0000AD,0xA48E80,0x636300}} 0xB4A880,0xADAD00,0x632000, 0x0000AD,0xA48E80,0x636300}}
,{"TETRIS", {0xAD0000,0x00AD00,0x0000AD,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"TETRIS", 1, {0xAD0000,0x00AD00,0x0000AD,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0x00AD00,0x0000AD,0xAD0000, 0xFFFFFF,0xADADAD,0x636363}} 0x00AD00,0x0000AD,0xAD0000, 0xFFFFFF,0xADADAD,0x636363}}
,{"DUCK TALES", {0x80FF00,0x68AD00,0x633100,0x201000, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"DUCK TALES", 1, {0x80FF00,0x68AD00,0x633100,0x201000, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0xFFFFFF,0xAD5800,0xAD5800, 0xFFFFFF,0xADADAD,0x636363}} 0xFFFFFF,0xAD5800,0xAD5800, 0xFFFFFF,0xADADAD,0x636363}}
,{"ALLEY WAY", {0x00FF00,0xAD0000,0x000063,0x636300, 0xFFFFFF,0xAD0000,0x630000,0x000000, ,{"ALLEY WAY", 1, {0x00FF00,0xAD0000,0x000063,0x636300, 0xFFFFFF,0xAD0000,0x630000,0x000000,
0xFF0000,0xAD0000,0x630000, 0x0000FF,0x0000AD,0x000063}} 0xFF0000,0xAD0000,0x630000, 0x0000FF,0x0000AD,0x000063}}
,{"KID ICARUS", {0xFFFFFF,0xADADAD,0x314278,0x003163, 0xFFFFFF,0xAD0000,0x630000,0x000000, ,{"KID ICARUS", 1, {0xFFFFFF,0xADADAD,0x314278,0x003163, 0xFFFFFF,0xAD0000,0x630000,0x000000,
0xFFFF00,0xB80000,0x436300, 0xFFFFFF,0xD4B4A4,0x633100}} 0xFFFF00,0xB80000,0x436300, 0xFFFFFF,0xD4B4A4,0x633100}}
,{"", {0xFFFFFF,0xADADAD,0x636363,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000, ,{"", 1, {0xFFFFFF,0xADADAD,0x636363,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000,
0xFFFFFF,0xADADAD,0x636363, 0xFFFFFF,0xADADAD,0x636363}} 0xFFFFFF,0xADADAD,0x636363, 0xFFFFFF,0xADADAD,0x636363}}
}; };

View File

@ -27,6 +27,7 @@ extern int gameSettingsCount;
struct gamePalette { struct gamePalette {
char gameName[17]; char gameName[17];
char use;
u32 palette[14]; // in 24-bit 0xRRGGBB u32 palette[14]; // in 24-bit 0xRRGGBB
}; };

View File

@ -4238,7 +4238,7 @@ static int MenuPalette()
else if(closeBtn.GetState() == STATE_CLICKED) else if(closeBtn.GetState() == STATE_CLICKED)
{ {
menu = MENU_EXIT; menu = MENU_EXIT;
SavePalette(SILENT, CurrentPalette.gameName); SavePalette(NOTSILENT, RomTitle);
SavePrefs(NOTSILENT); SavePrefs(NOTSILENT);
exitSound->Play(); exitSound->Play();

View File

@ -24,6 +24,9 @@
#include "button_mapping.h" #include "button_mapping.h"
#include "gamesettings.h" #include "gamesettings.h"
static gamePalette *palettes;
static int loadedPalettes = 0;
void StopColorizing(); void StopColorizing();
void gbSetPalette(u32 RRGGBB[]); void gbSetPalette(u32 RRGGBB[]);
@ -242,7 +245,7 @@ static void createXMLPalette(gamePalette *p, bool overwrite, const char *newname
} }
static int static int
preparePalData (int method) preparePalData (int method, gamePalette pals[], int palCount)
{ {
xml = mxmlNewXML("1.0"); xml = mxmlNewXML("1.0");
mxmlSetWrapMargin(0); // disable line wrapping mxmlSetWrapMargin(0); // disable line wrapping
@ -250,8 +253,8 @@ preparePalData (int method)
data = mxmlNewElement(xml, "palette"); data = mxmlNewElement(xml, "palette");
mxmlElementSetAttr(data, "app", APPNAME); mxmlElementSetAttr(data, "app", APPNAME);
mxmlElementSetAttr(data, "version", APPVERSION); mxmlElementSetAttr(data, "version", APPVERSION);
for (int i=0; i<gamePalettesCount; i++) { for (int i=palCount-1; i>=0; i--) {
createXMLPalette(&gamePalettes[i], false); createXMLPalette(&pals[i], false);
} }
int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSavePalCallback); int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSavePalCallback);
@ -261,37 +264,6 @@ preparePalData (int method)
return datasize; return datasize;
} }
static int
prepareExistingPalData (int method, const char *gameName)
{
int datasize = 0;
xml = mxmlLoadString(NULL, (char *)savebuffer, MXML_TEXT_CALLBACK);
if(xml)
{
// check settings version
// we don't do anything with the version #, but we'll store it anyway
data = mxmlFindElement(xml, xml, "palette", "version", NULL, MXML_DESCEND);
if(data) // a version entry exists
{
mxmlElementSetAttr(data, "app", APPNAME);
mxmlElementSetAttr(data, "version", APPVERSION);
} else {
data = mxmlNewElement(xml, "palette");
mxmlElementSetAttr(data, "app", APPNAME);
mxmlElementSetAttr(data, "version", APPVERSION);
}
for (int i=0; i<gamePalettesCount; i++) {
createXMLPalette(&gamePalettes[i], false);
}
createXMLPalette(&CurrentPalette, true, gameName);
datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSavePalCallback);
mxmlDelete(xml);
}
return datasize;
}
/**************************************************************************** /****************************************************************************
* loadXMLSetting * loadXMLSetting
@ -356,6 +328,61 @@ static void loadXMLController(unsigned int controller[], const char * name)
} }
} }
static void loadXMLPaletteFromSection(gamePalette &pal)
{
if (section) {
strncpy(pal.gameName, mxmlElementGetAttr(section, "name"), 17);
item = mxmlFindElement(section, xml, "bkgr", NULL, NULL, MXML_DESCEND);
if(item) {
const char * tmp = mxmlElementGetAttr(item, "c0");
if(tmp) pal.palette[0] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c1");
if(tmp) pal.palette[1] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c2");
if(tmp) pal.palette[2] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c3");
if(tmp) pal.palette[3] = strtoul(tmp, NULL, 16);
}
item = mxmlFindElement(section, xml, "wind", NULL, NULL, MXML_DESCEND);
if(item) {
const char * tmp = mxmlElementGetAttr(item, "c0");
if(tmp) pal.palette[4] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c1");
if(tmp) pal.palette[5] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c2");
if(tmp) pal.palette[6] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c3");
if(tmp) pal.palette[7] = strtoul(tmp, NULL, 16);
}
item = mxmlFindElement(section, xml, "obj0", NULL, NULL, MXML_DESCEND);
if(item) {
const char * tmp = mxmlElementGetAttr(item, "c0");
if(tmp) pal.palette[8] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c1");
if(tmp) pal.palette[9] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c2");
if(tmp) pal.palette[10] = strtoul(tmp, NULL, 16);
}
item = mxmlFindElement(section, xml, "obj1", NULL, NULL, MXML_DESCEND);
if(item) {
const char * tmp = mxmlElementGetAttr(item, "c0");
if(tmp) pal.palette[11] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c1");
if(tmp) pal.palette[12] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c2");
if(tmp) pal.palette[13] = strtoul(tmp, NULL, 16);
}
const char *use = mxmlElementGetAttr(section, "use");
if (use) {
if (atoi(use)==0) pal.use = 0;
else pal.use = 1;
} else {
pal.use = 1;
}
}
}
/**************************************************************************** /****************************************************************************
* decodePrefsData * decodePrefsData
* *
@ -503,58 +530,87 @@ decodePalData (int method, const char *gameName)
if (!section) section = mxmlFindElement(xml, xml, "game", "name", "default", MXML_DESCEND); if (!section) section = mxmlFindElement(xml, xml, "game", "name", "default", MXML_DESCEND);
// we have either the XML default palette or the XML game palette // we have either the XML default palette or the XML game palette
if (section) { if (section) {
item = mxmlFindElement(section, xml, "bkgr", NULL, NULL, MXML_DESCEND); loadXMLPaletteFromSection(CurrentPalette);
if(item) {
const char * tmp = mxmlElementGetAttr(item, "c0");
if(tmp) CurrentPalette.palette[0] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c1");
if(tmp) CurrentPalette.palette[1] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c2");
if(tmp) CurrentPalette.palette[2] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c3");
if(tmp) CurrentPalette.palette[3] = strtoul(tmp, NULL, 16);
}
item = mxmlFindElement(section, xml, "wind", NULL, NULL, MXML_DESCEND);
if(item) {
const char * tmp = mxmlElementGetAttr(item, "c0");
if(tmp) CurrentPalette.palette[4] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c1");
if(tmp) CurrentPalette.palette[5] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c2");
if(tmp) CurrentPalette.palette[6] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c3");
if(tmp) CurrentPalette.palette[7] = strtoul(tmp, NULL, 16);
}
item = mxmlFindElement(section, xml, "obj0", NULL, NULL, MXML_DESCEND);
if(item) {
const char * tmp = mxmlElementGetAttr(item, "c0");
if(tmp) CurrentPalette.palette[8] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c1");
if(tmp) CurrentPalette.palette[9] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c2");
if(tmp) CurrentPalette.palette[10] = strtoul(tmp, NULL, 16);
}
item = mxmlFindElement(section, xml, "obj1", NULL, NULL, MXML_DESCEND);
if(item) {
const char * tmp = mxmlElementGetAttr(item, "c0");
if(tmp) CurrentPalette.palette[11] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c1");
if(tmp) CurrentPalette.palette[12] = strtoul(tmp, NULL, 16);
tmp = mxmlElementGetAttr(item, "c2");
if(tmp) CurrentPalette.palette[13] = strtoul(tmp, NULL, 16);
}
const char *use = mxmlElementGetAttr(section, "use");
if (use) {
if (atoi(use)==0) StopColorizing();
else gbSetPalette(CurrentPalette.palette);
} else {
gbSetPalette(CurrentPalette.palette);
}
// there is no palette for this game and no default in XML // there is no palette for this game and no default in XML
} else { } else {
// use the hardcoded default palette // use the hardcoded default palette
CurrentPalette = gamePalettes[0]; CurrentPalette = gamePalettes[0];
gbSetPalette(CurrentPalette.palette); }
if (CurrentPalette.use) gbSetPalette(CurrentPalette.palette);
else StopColorizing();
}
mxmlDelete(xml);
}
return result;
}
static bool
decodePalsData (int method)
{
bool result = false;
xml = mxmlLoadString(NULL, (char *)savebuffer, MXML_TEXT_CALLBACK);
if(xml)
{
// check settings version
// we don't do anything with the version #, but we'll store it anyway
item = mxmlFindElement(xml, xml, "palette", "version", NULL, MXML_DESCEND);
if(item) // a version entry exists
{
const char * version = mxmlElementGetAttr(item, "version");
if(version && strlen(version) == 5)
{
// this code assumes version in format X.X.X
// XX.X.X, X.XX.X, or X.X.XX will NOT work
int verMajor = version[0] - '0';
int verMinor = version[2] - '0';
int verPoint = version[4] - '0';
int curMajor = APPVERSION[0] - '0';
int curMinor = APPVERSION[2] - '0';
int curPoint = APPVERSION[4] - '0';
// first we'll check that the versioning is valid
if(!(verMajor >= 0 && verMajor <= 9 &&
verMinor >= 0 && verMinor <= 9 &&
verPoint >= 0 && verPoint <= 9))
result = false;
else if(verMajor < 2) // less than version 2.0.0
result = false; // reset settings (sorry, should update settings instead)
else if(verMajor > curMajor || verMinor > curMinor || verPoint > curPoint) // some future version
result = true; // don't reset settings!
else
result = true;
}
}
if(result)
{
// count number of palettes in file
loadedPalettes = 0;
item = mxmlFindElement(xml, xml, "palette", NULL, NULL, MXML_DESCEND);
for (section = mxmlFindElement(item, xml, "game", NULL, NULL, MXML_DESCEND);
section;
section = mxmlFindElement(section, xml, "game", NULL, NULL, MXML_NO_DESCEND))
{
loadedPalettes++;
}
// Allocate enough memory for all palettes in file, plus all hardcoded palettes,
// plus one new palette
if (palettes) {
delete[] palettes;
palettes = NULL;
}
palettes = new gamePalette[loadedPalettes+1+gamePalettesCount];
// Load all palettes in file, hardcoded palettes are added later
int i = 0;
for (section = mxmlFindElement(item, xml, "game", NULL, NULL, MXML_DESCEND);
section;
section = mxmlFindElement(section, xml, "game", NULL, NULL, MXML_NO_DESCEND))
{
loadXMLPaletteFromSection(palettes[i]);
i++;
} }
} }
@ -616,9 +672,10 @@ SavePrefs (bool silent)
return false; return false;
} }
bool static bool
CreateAndLoadPalette(bool silent, const char *gameName) CreateAndLoadPalette(bool silent, const char *gameName, bool load)
{ {
if (load) {
// Load palette from hardcoded palettes // Load palette from hardcoded palettes
int snum = -1; int snum = -1;
for(int i=1; i < gamePalettesCount; i++) { for(int i=1; i < gamePalettesCount; i++) {
@ -636,7 +693,7 @@ CreateAndLoadPalette(bool silent, const char *gameName)
CurrentPalette = gamePalettes[0]; CurrentPalette = gamePalettes[0];
} }
gbSetPalette(CurrentPalette.palette); gbSetPalette(CurrentPalette.palette);
}
// Now create the XML palette file // Now create the XML palette file
char filepath[1024]; char filepath[1024];
int datasize; int datasize;
@ -656,7 +713,7 @@ CreateAndLoadPalette(bool silent, const char *gameName)
ShowAction ("Saving palette..."); ShowAction ("Saving palette...");
AllocSaveBuffer (); AllocSaveBuffer ();
datasize = preparePalData (method); datasize = preparePalData(method, gamePalettes, gamePalettesCount);
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{ {
@ -683,42 +740,29 @@ CreateAndLoadPalette(bool silent, const char *gameName)
return false; return false;
} }
bool static bool
SavePaletteMethod(bool silent, int method, const char *gameName) SavePalettes(bool silent) {
{ // Now create the XML palette file
char filepath[1024]; char filepath[1024];
int datasize;
int offset = 0; int offset = 0;
if(!MakeFilePath(filepath, FILE_PAL, method))
return false;
AllocSaveBuffer ();
offset = LoadFile(filepath, method, SILENT);
int datasize = 0;
if (offset > 0)
datasize = prepareExistingPalData (method, gameName);
if (!datasize) {
FreeSaveBuffer();
CancelAction();
return false;
}
if (!silent)
ShowAction ("Saving palette...");
// We'll save using the first available method (probably SD) since this // We'll save using the first available method (probably SD) since this
// is the method preferences will be loaded from by default // is the method preferences will be loaded from by default
method = autoSaveMethod(silent); int method = autoSaveMethod(silent);
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
return false; return false;
if(!MakeFilePath(filepath, FILE_PREF, method)) if(!MakeFilePath(filepath, FILE_PAL, method))
return false; return false;
if (!silent)
ShowAction("Saving palette...");
AllocSaveBuffer ();
datasize = preparePalData(method, palettes, loadedPalettes);
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{ {
// Set the comments // Set the comments
@ -770,7 +814,7 @@ LoadPrefsFromMethod (int method)
return retval; return retval;
} }
bool static bool
LoadPalFromMethod (int method, const char *gameName) LoadPalFromMethod (int method, const char *gameName)
{ {
bool retval = false; bool retval = false;
@ -792,6 +836,28 @@ LoadPalFromMethod (int method, const char *gameName)
return retval; return retval;
} }
static bool
LoadPalsFromMethod (int method)
{
bool retval = false;
char filepath[1024];
int offset = 0;
if(!MakeFilePath(filepath, FILE_PAL, method))
return false;
AllocSaveBuffer ();
offset = LoadFile(filepath, method, SILENT);
if (offset > 0)
retval = decodePalsData (method);
FreeSaveBuffer ();
return retval;
}
/**************************************************************************** /****************************************************************************
* Load Preferences * Load Preferences
* Checks sources consecutively until we find a preference file * Checks sources consecutively until we find a preference file
@ -823,6 +889,10 @@ bool LoadPrefs()
return prefFound; return prefFound;
} }
/****************************************************************************
* Load Palette
* Checks sources consecutively until we find a palette file
***************************************************************************/
bool LoadPalette(const char *gameName) bool LoadPalette(const char *gameName)
{ {
bool prefFound = false; bool prefFound = false;
@ -838,31 +908,89 @@ bool LoadPalette(const char *gameName)
prefFound = LoadPalFromMethod(METHOD_SMB, gameName); prefFound = LoadPalFromMethod(METHOD_SMB, gameName);
if(!prefFound) { if(!prefFound) {
return CreateAndLoadPalette(SILENT, gameName); char msg[1024];
sprintf(msg, "Failed to load palette");
InfoPrompt(msg);
return CreateAndLoadPalette(SILENT, gameName, true);
} }
return true; return true;
} }
bool SavePalette(bool silent, const char *gameName) static
bool LoadPalettes()
{ {
bool prefFound = false; bool prefFound = false;
if(ChangeInterface(METHOD_SD, SILENT)) if(ChangeInterface(METHOD_SD, SILENT))
prefFound = SavePaletteMethod(silent, METHOD_SD, gameName); prefFound = LoadPalsFromMethod(METHOD_SD);
if(!prefFound && ChangeInterface(METHOD_USB, SILENT)) if(!prefFound && ChangeInterface(METHOD_USB, SILENT))
prefFound = SavePaletteMethod(silent, METHOD_USB, gameName); prefFound = LoadPalsFromMethod(METHOD_USB);
if(!prefFound && TestMC(CARD_SLOTA, SILENT)) if(!prefFound && TestMC(CARD_SLOTA, SILENT))
prefFound = SavePaletteMethod(silent, METHOD_MC_SLOTA, gameName); prefFound = LoadPalsFromMethod(METHOD_MC_SLOTA);
if(!prefFound && TestMC(CARD_SLOTB, SILENT)) if(!prefFound && TestMC(CARD_SLOTB, SILENT))
prefFound = SavePaletteMethod(silent, METHOD_MC_SLOTB, gameName); prefFound = LoadPalsFromMethod(METHOD_MC_SLOTB);
if(!prefFound && ChangeInterface(METHOD_SMB, SILENT)) if(!prefFound && ChangeInterface(METHOD_SMB, SILENT))
prefFound = SavePaletteMethod(silent, METHOD_SMB, gameName); prefFound = LoadPalsFromMethod(METHOD_SMB);
if(!prefFound) { if(!prefFound) {
gamePalette pal = CurrentPalette; char msg[1024];
CreateAndLoadPalette(silent, gameName); sprintf(msg, "Failed to load palettes");
CurrentPalette = pal; InfoPrompt(msg);
gbSetPalette(CurrentPalette.palette); CreateAndLoadPalette(SILENT, "", false);
SavePaletteMethod(silent, METHOD_SD, gameName); if(ChangeInterface(METHOD_SD, SILENT))
prefFound = LoadPalsFromMethod(METHOD_SD);
if(!prefFound && ChangeInterface(METHOD_USB, SILENT))
prefFound = LoadPalsFromMethod(METHOD_USB);
if(!prefFound && TestMC(CARD_SLOTA, SILENT))
prefFound = LoadPalsFromMethod(METHOD_MC_SLOTA);
if(!prefFound && TestMC(CARD_SLOTB, SILENT))
prefFound = LoadPalsFromMethod(METHOD_MC_SLOTB);
if(!prefFound && ChangeInterface(METHOD_SMB, SILENT))
prefFound = LoadPalsFromMethod(METHOD_SMB);
}
return prefFound;
}
static void AddPalette(gamePalette pal, const char *gameName) {
for (int i=0; i<loadedPalettes; i++) {
if (strcmp(palettes[i].gameName, gameName)==0) {
palettes[i] = pal;
strncpy(palettes[i].gameName, gameName, 17);
return;
}
}
char msg[1024];
sprintf(msg, "Adding new palette '%s'", gameName);
InfoPrompt(msg);
palettes[loadedPalettes] = pal;
strncpy(palettes[loadedPalettes].gameName, gameName, 17);
loadedPalettes++;
}
bool SavePalette(bool silent, const char *gameName) {
char msg[1024];
sprintf(msg, "Save palette '%s'", gameName);
InfoPrompt(msg);
bool prefFound = LoadPalettes();
if (!prefFound) {
delete[] palettes;
palettes = NULL;
return false;
}
sprintf(msg, "%d palettes loaded", loadedPalettes);
InfoPrompt(msg);
if(prefFound && palettes) {
for (int i=0; i<gamePalettesCount; i++)
AddPalette(gamePalettes[i], gamePalettes[i].gameName);
sprintf(msg, "Added more to make %d palettes", loadedPalettes);
InfoPrompt(msg);
if (!gameName) gameName = CurrentPalette.gameName;
AddPalette(CurrentPalette, gameName);
sprintf(msg, "Added %s to make %d palettes", gameName, loadedPalettes);
InfoPrompt(msg);
SavePalettes(silent);
delete[] palettes;
palettes = NULL;
} }
return true; return true;
} }