partial cleanup of palette saving/loading disaster code

This commit is contained in:
dborth 2009-06-01 07:20:23 +00:00
parent 6e583296f9
commit a8eb751e40
7 changed files with 339 additions and 559 deletions

View File

@ -45,12 +45,6 @@
GuiImageData * pointer[4];
#endif
static int MenuPalette();
void gbSetPalette(u32 RRGGBB[]);
void StopColorizing();
extern char RomTitle[17];
static GuiButton * btnLogo = NULL;
static GuiImage * gameScreenImg = NULL;
static GuiImage * bgImg = NULL;
@ -1856,10 +1850,6 @@ static int MenuGameSettings()
{
menu = MENU_GAMESETTINGS_VIDEO;
}
/*else if(cheatsBtn.GetState() == STATE_CLICKED)
{
menu = MENU_GAMESETTINGS_PALETTE;
}*/
else if(wiiControlsBtn.GetState() == STATE_CLICKED)
{
GCSettings.WiiControls ^= 1;
@ -2663,7 +2653,7 @@ static int MenuSettingsVideo()
sprintf(options.name[i++], "Screen Position");
sprintf(options.name[i++], "Video Mode");
sprintf(options.name[i++], "Colorize Mono GB");
sprintf(options.name[i++], "Choose Palette");
sprintf(options.name[i++], "GB Palette");
options.length = i;
GuiText titleTxt("Game Settings - Video", 28, (GXColor){255, 255, 255, 255});
@ -2750,7 +2740,11 @@ static int MenuSettingsVideo()
sprintf (options.value[5], "On");
else
sprintf (options.value[5], "Off");
sprintf(options.value[6], "click here");
if(true) // TODO - show custom if different from the default palette
sprintf(options.value[6], "Custom");
else
sprintf(options.value[6], "Default");
ret = optionBrowser.GetClickedOption();
@ -2788,11 +2782,7 @@ static int MenuSettingsVideo()
break;
case 5:
if (GCSettings.colorize) GCSettings.colorize = 0;
else GCSettings.colorize = 1;
if (strcmp(RomTitle, "MEGAMAN")==0) StopColorizing();
else if (GCSettings.colorize) LoadPalette(RomTitle);
else StopColorizing();
GCSettings.colorize ^= 1;
break;
case 6:
@ -3420,178 +3410,6 @@ static int MenuSettingsNetwork()
return menu;
}
/****************************************************************************
* MainMenu
***************************************************************************/
void
MainMenu (int menu)
{
int currentMenu = menu;
lastMenu = MENU_NONE;
mainWindow = new GuiWindow(screenwidth, screenheight);
bgImg = new GuiImage(screenwidth, screenheight, (GXColor){236, 226, 238, 255});
bgImg->ColorStripe(10);
mainWindow->Append(bgImg);
if(gameScreenTex)
{
gameScreenImg = new GuiImage(gameScreenTex, screenwidth, screenheight);
gameScreenImg->SetAlpha(192);
gameScreenImg->ColorStripe(30);
mainWindow->Append(gameScreenImg);
bgImg->SetVisible(false);
}
GuiTrigger trigA;
if(GCSettings.WiimoteOrientation)
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_2 | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
else
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
GuiSound btnSoundClick(button_click_pcm, button_click_pcm_size, SOUND_PCM);
GuiImageData bgTop(bg_top_png);
bgTopImg = new GuiImage(&bgTop);
GuiImageData bgBottom(bg_bottom_png);
bgBottomImg = new GuiImage(&bgBottom);
bgBottomImg->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
GuiImageData logo(logo_png);
GuiImage logoImg(&logo);
GuiImageData logoOver(logo_over_png);
GuiImage logoImgOver(&logoOver);
GuiText logoTxt(APPVERSION, 18, (GXColor){255, 255, 255, 255});
logoTxt.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
logoTxt.SetPosition(0, 4);
btnLogo = new GuiButton(logoImg.GetWidth(), logoImg.GetHeight());
btnLogo->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
btnLogo->SetPosition(-50, 24);
btnLogo->SetImage(&logoImg);
btnLogo->SetImageOver(&logoImgOver);
btnLogo->SetLabel(&logoTxt);
btnLogo->SetSoundOver(&btnSoundOver);
btnLogo->SetSoundClick(&btnSoundClick);
btnLogo->SetTrigger(&trigA);
btnLogo->SetUpdateCallback(WindowCredits);
mainWindow->Append(bgTopImg);
mainWindow->Append(bgBottomImg);
mainWindow->Append(btnLogo);
if(currentMenu == MENU_GAMESELECTION)
ResumeGui();
// Load preferences
if(!LoadPrefs())
SavePrefs(SILENT);
#ifndef NO_SOUND
bgMusic = new GuiSound(bg_music_ogg, bg_music_ogg_size, SOUND_OGG);
bgMusic->SetVolume(GCSettings.MusicVolume);
bgMusic->SetLoop(true);
enterSound = new GuiSound(enter_ogg, enter_ogg_size, SOUND_OGG);
enterSound->SetVolume(GCSettings.SFXVolume);
exitSound = new GuiSound(exit_ogg, exit_ogg_size, SOUND_OGG);
exitSound->SetVolume(GCSettings.SFXVolume);
if(currentMenu == MENU_GAMESELECTION) bgMusic->Play(); // startup music
#endif
while(currentMenu != MENU_EXIT || !ROMLoaded)
{
switch (currentMenu)
{
case MENU_GAMESELECTION:
currentMenu = MenuGameSelection();
break;
case MENU_GAME:
currentMenu = MenuGame();
break;
case MENU_GAME_LOAD:
currentMenu = MenuGameSaves(0);
break;
case MENU_GAME_SAVE:
currentMenu = MenuGameSaves(1);
break;
case MENU_GAMESETTINGS:
currentMenu = MenuGameSettings();
break;
case MENU_GAMESETTINGS_MAPPINGS:
currentMenu = MenuSettingsMappings();
break;
case MENU_GAMESETTINGS_MAPPINGS_MAP:
currentMenu = MenuSettingsMappingsMap();
break;
case MENU_GAMESETTINGS_VIDEO:
currentMenu = MenuSettingsVideo();
break;
/*case MENU_GAMESETTINGS_CHEATS:
currentMenu = MenuGameCheats();
break;*/
case MENU_GAMESETTINGS_PALETTE:
currentMenu = MenuPalette();
break;
case MENU_SETTINGS:
currentMenu = MenuSettings();
break;
case MENU_SETTINGS_FILE:
currentMenu = MenuSettingsFile();
break;
case MENU_SETTINGS_MENU:
currentMenu = MenuSettingsMenu();
break;
case MENU_SETTINGS_NETWORK:
currentMenu = MenuSettingsNetwork();
break;
default: // unrecognized menu
currentMenu = MenuGameSelection();
break;
}
lastMenu = currentMenu;
usleep(THREAD_SLEEP);
}
#ifdef HW_RVL
ShutoffRumble();
#endif
// wait for keys to be depressed
while(MenuRequested())
usleep(THREAD_SLEEP);
CancelAction();
HaltGui();
#ifndef NO_SOUND
delete bgMusic;
delete enterSound;
delete exitSound;
#endif
delete btnLogo;
delete bgImg;
delete bgTopImg;
delete bgBottomImg;
delete mainWindow;
mainWindow = NULL;
if(gameScreenImg)
{
delete gameScreenImg;
gameScreenImg = NULL;
}
if(gameScreenTex)
{
free(gameScreenTex);
gameScreenTex = NULL;
}
if(gameScreenTex2)
{
free(gameScreenTex2);
gameScreenTex2 = NULL;
}
}
static int redAmount=128, greenAmount=128, blueAmount=128;
static GuiText *redText;
@ -4096,7 +3914,7 @@ static int MenuPalette()
while(menu == MENU_NONE)
{
VIDEO_WaitVSync ();
usleep(THREAD_SLEEP);
if(bg0Btn.GetState() == STATE_CLICKED)
{
@ -4240,13 +4058,13 @@ static int MenuPalette()
}
else if(importBtn.GetState() == STATE_CLICKED)
{
SavePalette(SILENT, RomTitle);
SavePalettes(SILENT);
menu = MENU_GAMESETTINGS_PALETTE;
}
else if(closeBtn.GetState() == STATE_CLICKED)
{
menu = MENU_EXIT;
SavePalette(SILENT, RomTitle);
SavePalettes(SILENT);
SavePrefs(NOTSILENT);
exitSound->Play();
@ -4263,16 +4081,191 @@ static int MenuPalette()
}
else if(backBtn.GetState() == STATE_CLICKED)
{
SavePalette(SILENT, RomTitle);
SavePalettes(SILENT);
menu = MENU_GAMESETTINGS_VIDEO;
}
}
if(menu == MENU_GAME)
SavePrefs(NOTSILENT);
gbSetPalette(CurrentPalette.palette);
HaltGui();
mainWindow->Remove(&w);
return menu;
}
/****************************************************************************
* MainMenu
***************************************************************************/
void
MainMenu (int menu)
{
int currentMenu = menu;
lastMenu = MENU_NONE;
mainWindow = new GuiWindow(screenwidth, screenheight);
bgImg = new GuiImage(screenwidth, screenheight, (GXColor){236, 226, 238, 255});
bgImg->ColorStripe(10);
mainWindow->Append(bgImg);
if(gameScreenTex)
{
gameScreenImg = new GuiImage(gameScreenTex, screenwidth, screenheight);
gameScreenImg->SetAlpha(192);
gameScreenImg->ColorStripe(30);
mainWindow->Append(gameScreenImg);
bgImg->SetVisible(false);
}
GuiTrigger trigA;
if(GCSettings.WiimoteOrientation)
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_2 | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
else
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
GuiSound btnSoundClick(button_click_pcm, button_click_pcm_size, SOUND_PCM);
GuiImageData bgTop(bg_top_png);
bgTopImg = new GuiImage(&bgTop);
GuiImageData bgBottom(bg_bottom_png);
bgBottomImg = new GuiImage(&bgBottom);
bgBottomImg->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
GuiImageData logo(logo_png);
GuiImage logoImg(&logo);
GuiImageData logoOver(logo_over_png);
GuiImage logoImgOver(&logoOver);
GuiText logoTxt(APPVERSION, 18, (GXColor){255, 255, 255, 255});
logoTxt.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
logoTxt.SetPosition(0, 4);
btnLogo = new GuiButton(logoImg.GetWidth(), logoImg.GetHeight());
btnLogo->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
btnLogo->SetPosition(-50, 24);
btnLogo->SetImage(&logoImg);
btnLogo->SetImageOver(&logoImgOver);
btnLogo->SetLabel(&logoTxt);
btnLogo->SetSoundOver(&btnSoundOver);
btnLogo->SetSoundClick(&btnSoundClick);
btnLogo->SetTrigger(&trigA);
btnLogo->SetUpdateCallback(WindowCredits);
mainWindow->Append(bgTopImg);
mainWindow->Append(bgBottomImg);
mainWindow->Append(btnLogo);
if(currentMenu == MENU_GAMESELECTION)
ResumeGui();
// Load preferences
if(!LoadPrefs())
SavePrefs(SILENT);
// Load palettes
LoadPalettes();
#ifndef NO_SOUND
bgMusic = new GuiSound(bg_music_ogg, bg_music_ogg_size, SOUND_OGG);
bgMusic->SetVolume(GCSettings.MusicVolume);
bgMusic->SetLoop(true);
enterSound = new GuiSound(enter_ogg, enter_ogg_size, SOUND_OGG);
enterSound->SetVolume(GCSettings.SFXVolume);
exitSound = new GuiSound(exit_ogg, exit_ogg_size, SOUND_OGG);
exitSound->SetVolume(GCSettings.SFXVolume);
if(currentMenu == MENU_GAMESELECTION) bgMusic->Play(); // startup music
#endif
while(currentMenu != MENU_EXIT || !ROMLoaded)
{
switch (currentMenu)
{
case MENU_GAMESELECTION:
currentMenu = MenuGameSelection();
break;
case MENU_GAME:
currentMenu = MenuGame();
break;
case MENU_GAME_LOAD:
currentMenu = MenuGameSaves(0);
break;
case MENU_GAME_SAVE:
currentMenu = MenuGameSaves(1);
break;
case MENU_GAMESETTINGS:
currentMenu = MenuGameSettings();
break;
case MENU_GAMESETTINGS_MAPPINGS:
currentMenu = MenuSettingsMappings();
break;
case MENU_GAMESETTINGS_MAPPINGS_MAP:
currentMenu = MenuSettingsMappingsMap();
break;
case MENU_GAMESETTINGS_VIDEO:
currentMenu = MenuSettingsVideo();
break;
/*case MENU_GAMESETTINGS_CHEATS:
currentMenu = MenuGameCheats();
break;*/
case MENU_GAMESETTINGS_PALETTE:
currentMenu = MenuPalette();
break;
case MENU_SETTINGS:
currentMenu = MenuSettings();
break;
case MENU_SETTINGS_FILE:
currentMenu = MenuSettingsFile();
break;
case MENU_SETTINGS_MENU:
currentMenu = MenuSettingsMenu();
break;
case MENU_SETTINGS_NETWORK:
currentMenu = MenuSettingsNetwork();
break;
default: // unrecognized menu
currentMenu = MenuGameSelection();
break;
}
lastMenu = currentMenu;
usleep(THREAD_SLEEP);
}
#ifdef HW_RVL
ShutoffRumble();
#endif
// wait for keys to be depressed
while(MenuRequested())
usleep(THREAD_SLEEP);
CancelAction();
HaltGui();
#ifndef NO_SOUND
delete bgMusic;
delete enterSound;
delete exitSound;
#endif
delete btnLogo;
delete bgImg;
delete bgTopImg;
delete bgBottomImg;
delete mainWindow;
mainWindow = NULL;
if(gameScreenImg)
{
delete gameScreenImg;
gameScreenImg = NULL;
}
if(gameScreenTex)
{
free(gameScreenTex);
gameScreenTex = NULL;
}
if(gameScreenTex2)
{
free(gameScreenTex2);
gameScreenTex2 = NULL;
}
}

View File

@ -24,12 +24,9 @@
#include "button_mapping.h"
#include "gamesettings.h"
static gamePalette *palettes;
static gamePalette *palettes = NULL;
static int loadedPalettes = 0;
void StopColorizing();
void gbSetPalette(u32 RRGGBB[]);
/****************************************************************************
* Prepare Preferences Data
*
@ -483,138 +480,38 @@ decodePrefsData (int method)
return result;
}
static bool
decodePalData (int method, const char *gameName)
{
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)
{
// load palette for this game
section = mxmlFindElement(xml, xml, "game", "name", gameName, MXML_DESCEND);
// if not found, load default palette
if (!section) section = mxmlFindElement(xml, xml, "game", "name", "default", MXML_DESCEND);
// we have either the XML default palette or the XML game palette
if (section) {
loadXMLPaletteFromSection(CurrentPalette);
// there is no palette for this game and no default in XML
} else {
// use the hardcoded default palette
CurrentPalette = gamePalettes[0];
}
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);
xml = mxmlLoadString(NULL, (char *) savebuffer, MXML_TEXT_CALLBACK);
if(xml)
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
// 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))
{
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;
}
loadedPalettes++;
}
// Allocate enough memory for all palettes in file, plus all hardcoded palettes,
// plus one new palette
if (palettes)
free(palettes);
if(result)
palettes = (gamePalette *)malloc(sizeof(gamePalette)*loadedPalettes);
// 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))
{
// 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++;
}
loadXMLPaletteFromSection(palettes[i]);
i++;
}
mxmlDelete(xml);
}
@ -674,123 +571,6 @@ SavePrefs (bool silent)
return false;
}
static bool
CreateAndLoadPalette(bool silent, const char *gameName, bool load)
{
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);
}
// Now create the XML palette file
char filepath[1024];
int datasize;
int offset = 0;
// We'll save using the first available method (probably SD) since this
// is the method preferences will be loaded from by default
int method = autoSaveMethod(silent);
if(method == METHOD_AUTO)
return false;
if(!MakeFilePath(filepath, FILE_PAL, method))
return false;
if (!silent)
ShowAction ("Saving palette...");
AllocSaveBuffer ();
datasize = preparePalData(method, gamePalettes, gamePalettesCount);
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{
// Set the comments
char prefscomment[2][32];
memset(prefscomment, 0, 64);
sprintf (prefscomment[0], "%s Pal", APPNAME);
sprintf (prefscomment[1], "Palette");
SetMCSaveComments(prefscomment);
}
offset = SaveFile(filepath, datasize, method, silent);
FreeSaveBuffer ();
CancelAction();
if (offset > 0)
{
if (!silent)
InfoPrompt("Palette saved");
return true;
}
return false;
}
static bool
SavePalettes(bool silent) {
// Now create the XML palette file
char filepath[1024];
int datasize;
int offset = 0;
// We'll save using the first available method (probably SD) since this
// is the method preferences will be loaded from by default
int method = autoSaveMethod(silent);
if(method == METHOD_AUTO)
return false;
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
char prefscomment[2][32];
memset(prefscomment, 0, 64);
sprintf (prefscomment[0], "%s Pal", APPNAME);
sprintf (prefscomment[1], "Palette");
SetMCSaveComments(prefscomment);
}
offset = SaveFile(filepath, datasize, method, silent);
FreeSaveBuffer ();
CancelAction();
if (offset > 0)
{
if (!silent)
InfoPrompt("Palette saved");
return true;
}
return false;
}
/****************************************************************************
* Load Preferences from specified method
***************************************************************************/
@ -816,50 +596,6 @@ LoadPrefsFromMethod (int method)
return retval;
}
static bool
LoadPalFromMethod (int method, const char *gameName)
{
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 = decodePalData (method, gameName);
FreeSaveBuffer ();
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
@ -891,90 +627,125 @@ bool LoadPrefs()
return prefFound;
}
/****************************************************************************
* Load Palette
* Checks sources consecutively until we find a palette file
***************************************************************************/
bool LoadPalette(const char *gameName)
bool SavePalettes(bool silent)
{
bool prefFound = false;
if(ChangeInterface(METHOD_SD, SILENT))
prefFound = LoadPalFromMethod(METHOD_SD, gameName);
if(!prefFound && ChangeInterface(METHOD_USB, SILENT))
prefFound = LoadPalFromMethod(METHOD_USB, gameName);
if(!prefFound && TestMC(CARD_SLOTA, SILENT))
prefFound = LoadPalFromMethod(METHOD_MC_SLOTA, gameName);
if(!prefFound && TestMC(CARD_SLOTB, SILENT))
prefFound = LoadPalFromMethod(METHOD_MC_SLOTB, gameName);
if(!prefFound && ChangeInterface(METHOD_SMB, SILENT))
prefFound = LoadPalFromMethod(METHOD_SMB, gameName);
char filepath[1024];
int datasize;
int offset = 0;
int method = GCSettings.SaveMethod;
if(!prefFound) {
return CreateAndLoadPalette(SILENT, gameName, true);
if(method == METHOD_AUTO)
method = autoSaveMethod(silent);
if(method == METHOD_AUTO)
return false;
if (!MakeFilePath(filepath, FILE_PAL, method))
return false;
// Now create the XML palette file
if (!silent)
ShowAction("Saving palette...");
AllocSaveBuffer();
datasize = preparePalData(method, palettes, loadedPalettes);
if (method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{
// Set the comments
char prefscomment[2][32];
memset(prefscomment, 0, 64);
sprintf(prefscomment[0], "%s Pal", APPNAME);
sprintf(prefscomment[1], "Palette");
SetMCSaveComments(prefscomment);
}
return true;
offset = SaveFile(filepath, datasize, method, silent);
FreeSaveBuffer();
CancelAction();
if (offset > 0)
{
if (!silent)
InfoPrompt("Palette saved");
return true;
}
return false;
}
static
bool LoadPalettes()
static void AddPalette(gamePalette pal, const char *gameName)
{
bool prefFound = 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);
if(!prefFound) {
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<loadedPalettes; i++) {
if (strcmp(palettes[i].gameName, gameName)==0) {
palettes[i] = pal;
strncpy(palettes[i].gameName, gameName, 17);
for (int i=0; i < loadedPalettes; i++)
if (strcmp(palettes[i].gameName, gameName)==0)
return;
}
}
palettes = (gamePalette *)realloc(palettes, sizeof(gamePalette)*(loadedPalettes+1));
palettes[loadedPalettes] = pal;
strncpy(palettes[loadedPalettes].gameName, gameName, 17);
loadedPalettes++;
}
bool SavePalette(bool silent, const char *gameName) {
bool prefFound = LoadPalettes();
if (!prefFound) {
delete[] palettes;
palettes = NULL;
return false;
}
/****************************************************************************
* Load Palettes
***************************************************************************/
bool LoadPalettes()
{
bool retval = false;
char filepath[1024];
int offset = 0;
int method = GCSettings.SaveMethod;
if(method == METHOD_AUTO)
method = autoSaveMethod(SILENT);
if(method == METHOD_AUTO)
return false;
if(!MakeFilePath(filepath, FILE_PAL, method))
return false;
AllocSaveBuffer ();
offset = LoadFile(filepath, method, SILENT);
if (offset > 0)
retval = decodePalsData (method);
FreeSaveBuffer ();
// add hard-coded palettes
for (int i=0; i<gamePalettesCount; i++)
AddPalette(gamePalettes[i], gamePalettes[i].gameName);
if (!retval)
retval = SavePalettes(SILENT);
if(prefFound && palettes) {
for (int i=0; i<gamePalettesCount; i++)
AddPalette(gamePalettes[i], gamePalettes[i].gameName);
if (!gameName) gameName = CurrentPalette.gameName;
AddPalette(CurrentPalette, gameName);
SavePalettes(silent);
delete[] palettes;
palettes = NULL;
}
return true;
}
void SetPalette(const char *gameName)
{
// Load existing palette
int snum = -1;
for (int i = 0; i < loadedPalettes; i++)
{
if(strcmp(gameName, palettes[i].gameName)==0)
{
snum = i;
break;
}
}
// match found!
if(snum >= 0)
{
CurrentPalette = gamePalettes[snum];
}
else
{
CurrentPalette = gamePalettes[0]; // use the default palette
AddPalette(gamePalettes[0], gameName); // add this game to the palette list
}
}

View File

@ -10,5 +10,6 @@
bool SavePrefs (bool silent);
bool LoadPrefs ();
bool SavePalette (bool silent, const char *gameName);
bool LoadPalette (const char *gameName);
bool SavePalettes (bool silent);
bool LoadPalettes();
void SetPalette(const char *gameName);

View File

@ -36,9 +36,12 @@
#include "input.h"
#include "video.h"
#include "vbaconfig.h"
#include "gamesettings.h"
#include "wiiusbsupport.h"
extern int emulating;
void StopColorizing();
void gbSetPalette(u32 RRGGBB[]);
int ScreenshotRequested = 0;
int ConfigRequested = 0;
int ShutdownRequested = 0;
@ -282,6 +285,15 @@ int main(int argc, char *argv[])
ResetVideo_Emu();
// GB colorizing - set palette
if(cartridgeType == 1)
{
if(GCSettings.colorize && strcmp(RomTitle, "MEGAMAN") != 0)
gbSetPalette(CurrentPalette.palette);
else
StopColorizing();
}
while (emulating) // emulation loop
{
emulator.emuMain(emulator.emuCount);

View File

@ -16,7 +16,7 @@
#define APPNAME "Visual Boy Advance GX"
#define APPVERSION "2.0.3"
#define PREF_FILE_NAME "settings.xml"
#define PAL_FILE_NAME "palette.xml"
#define PAL_FILE_NAME "palettes.xml"
#define NOTSILENT 0
#define SILENT 1

View File

@ -805,10 +805,12 @@ static void gbApplyPerImagePreferences()
}
// look for matching palettes if a monochrome gameboy game
// (or if a Super Gameboy game, but the palette will be ignored later in that case)
if ((Colour != 0x80) && (Colour != 0xC0)) {
if (strcmp(RomTitle, "MEGAMAN")==0) StopColorizing();
else if (GCSettings.colorize) LoadPalette(RomTitle);
else StopColorizing();
if ((Colour != 0x80) && (Colour != 0xC0))
{
if (GCSettings.colorize && strcmp(RomTitle, "MEGAMAN") != 0)
SetPalette(RomTitle);
else
StopColorizing();
}
}

View File

@ -18,6 +18,7 @@ extern int cartridgeType;
extern int SunBars;
extern u32 RomIdCode;
extern bool TiltSideways;
extern char RomTitle[];
bool LoadVBAROM(int method);
void InitialisePalette();