diff --git a/source/ngc/gamesettings.cpp b/source/ngc/gamesettings.cpp index 38fb091..e7bda50 100644 --- a/source/ngc/gamesettings.cpp +++ b/source/ngc/gamesettings.cpp @@ -21,47 +21,47 @@ int gamePalettesCount = 19; // 3 Sprite 1 Colours (brightest to dark), 3 Sprite 2 Colours (brightest to dark) 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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"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}} - ,{"", {0xFFFFFF,0xADADAD,0x636363,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000, + ,{"", 1, {0xFFFFFF,0xADADAD,0x636363,0x000000, 0xFFFFFF,0xADADAD,0x636363,0x000000, 0xFFFFFF,0xADADAD,0x636363, 0xFFFFFF,0xADADAD,0x636363}} }; diff --git a/source/ngc/gamesettings.h b/source/ngc/gamesettings.h index e971788..7caed74 100644 --- a/source/ngc/gamesettings.h +++ b/source/ngc/gamesettings.h @@ -27,6 +27,7 @@ extern int gameSettingsCount; struct gamePalette { char gameName[17]; + char use; u32 palette[14]; // in 24-bit 0xRRGGBB }; diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index d92fe6d..8f84fa7 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -4238,7 +4238,7 @@ static int MenuPalette() else if(closeBtn.GetState() == STATE_CLICKED) { menu = MENU_EXIT; - SavePalette(SILENT, CurrentPalette.gameName); + SavePalette(NOTSILENT, RomTitle); SavePrefs(NOTSILENT); exitSound->Play(); diff --git a/source/ngc/preferences.cpp b/source/ngc/preferences.cpp index 9471cc6..f7537d2 100644 --- a/source/ngc/preferences.cpp +++ b/source/ngc/preferences.cpp @@ -24,6 +24,9 @@ #include "button_mapping.h" #include "gamesettings.h" +static gamePalette *palettes; +static int loadedPalettes = 0; + void StopColorizing(); void gbSetPalette(u32 RRGGBB[]); @@ -242,7 +245,7 @@ static void createXMLPalette(gamePalette *p, bool overwrite, const char *newname } static int -preparePalData (int method) +preparePalData (int method, gamePalette pals[], int palCount) { xml = mxmlNewXML("1.0"); mxmlSetWrapMargin(0); // disable line wrapping @@ -250,8 +253,8 @@ preparePalData (int method) data = mxmlNewElement(xml, "palette"); mxmlElementSetAttr(data, "app", APPNAME); mxmlElementSetAttr(data, "version", APPVERSION); - for (int i=0; i=0; i--) { + createXMLPalette(&pals[i], false); } int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSavePalCallback); @@ -261,37 +264,6 @@ preparePalData (int method) 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= 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,27 +672,28 @@ SavePrefs (bool silent) return false; } -bool -CreateAndLoadPalette(bool silent, const char *gameName) +static bool +CreateAndLoadPalette(bool silent, const char *gameName, bool load) { - // Load palette from hardcoded palettes - int snum = -1; - for(int i=1; i < gamePalettesCount; i++) { - if(strcmp(gameName, gamePalettes[i].gameName)==0) - { - snum = i; - break; + if (load) { + // Load palette from hardcoded palettes + int snum = -1; + for(int i=1; i < gamePalettesCount; i++) { + if(strcmp(gameName, gamePalettes[i].gameName)==0) + { + snum = i; + break; + } } + // match found! + if(snum >= 0) + { + CurrentPalette = gamePalettes[snum]; + } else { + CurrentPalette = gamePalettes[0]; + } + gbSetPalette(CurrentPalette.palette); } - // match found! - if(snum >= 0) - { - CurrentPalette = gamePalettes[snum]; - } else { - CurrentPalette = gamePalettes[0]; - } - gbSetPalette(CurrentPalette.palette); - // Now create the XML palette file char filepath[1024]; int datasize; @@ -656,7 +713,7 @@ CreateAndLoadPalette(bool silent, const char *gameName) ShowAction ("Saving palette..."); AllocSaveBuffer (); - datasize = preparePalData (method); + datasize = preparePalData(method, gamePalettes, gamePalettesCount); if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { @@ -683,42 +740,29 @@ CreateAndLoadPalette(bool silent, const char *gameName) return false; } -bool -SavePaletteMethod(bool silent, int method, const char *gameName) -{ +static bool +SavePalettes(bool silent) { + // Now create the XML palette file char filepath[1024]; + int datasize; 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 // is the method preferences will be loaded from by default - method = autoSaveMethod(silent); + int method = autoSaveMethod(silent); if(method == METHOD_AUTO) return false; - if(!MakeFilePath(filepath, FILE_PREF, method)) + if(!MakeFilePath(filepath, FILE_PAL, method)) return false; + if (!silent) + ShowAction("Saving palette..."); + + AllocSaveBuffer (); + datasize = preparePalData(method, palettes, loadedPalettes); + if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { // Set the comments @@ -770,7 +814,7 @@ LoadPrefsFromMethod (int method) return retval; } -bool +static bool LoadPalFromMethod (int method, const char *gameName) { bool retval = false; @@ -792,6 +836,28 @@ LoadPalFromMethod (int method, const char *gameName) 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 * Checks sources consecutively until we find a preference file @@ -823,6 +889,10 @@ bool LoadPrefs() return prefFound; } +/**************************************************************************** + * Load Palette + * Checks sources consecutively until we find a palette file + ***************************************************************************/ bool LoadPalette(const char *gameName) { bool prefFound = false; @@ -838,31 +908,89 @@ bool LoadPalette(const char *gameName) prefFound = LoadPalFromMethod(METHOD_SMB, gameName); if(!prefFound) { - return CreateAndLoadPalette(SILENT, gameName); + char msg[1024]; + sprintf(msg, "Failed to load palette"); + InfoPrompt(msg); + return CreateAndLoadPalette(SILENT, gameName, true); } return true; } -bool SavePalette(bool silent, const char *gameName) +static +bool LoadPalettes() { bool prefFound = false; if(ChangeInterface(METHOD_SD, SILENT)) - prefFound = SavePaletteMethod(silent, METHOD_SD, gameName); + prefFound = LoadPalsFromMethod(METHOD_SD); if(!prefFound && ChangeInterface(METHOD_USB, SILENT)) - prefFound = SavePaletteMethod(silent, METHOD_USB, gameName); + prefFound = LoadPalsFromMethod(METHOD_USB); if(!prefFound && TestMC(CARD_SLOTA, SILENT)) - prefFound = SavePaletteMethod(silent, METHOD_MC_SLOTA, gameName); + prefFound = LoadPalsFromMethod(METHOD_MC_SLOTA); if(!prefFound && TestMC(CARD_SLOTB, SILENT)) - prefFound = SavePaletteMethod(silent, METHOD_MC_SLOTB, gameName); + prefFound = LoadPalsFromMethod(METHOD_MC_SLOTB); if(!prefFound && ChangeInterface(METHOD_SMB, SILENT)) - prefFound = SavePaletteMethod(silent, METHOD_SMB, gameName); + prefFound = LoadPalsFromMethod(METHOD_SMB); if(!prefFound) { - gamePalette pal = CurrentPalette; - CreateAndLoadPalette(silent, gameName); - CurrentPalette = pal; - gbSetPalette(CurrentPalette.palette); - SavePaletteMethod(silent, METHOD_SD, gameName); + char msg[1024]; + sprintf(msg, "Failed to load palettes"); + InfoPrompt(msg); + CreateAndLoadPalette(SILENT, "", false); + 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