From 884ccc90a6e3dd59a70a9ed5425029f797c52d8c Mon Sep 17 00:00:00 2001 From: dborth Date: Wed, 15 Apr 2009 06:01:08 +0000 Subject: [PATCH] corrections/improvements to game saving --- source/ngc/gui/gui_savebrowser.cpp | 8 ++--- source/ngc/menu.cpp | 10 +++--- source/ngc/vbasupport.cpp | 49 +++++++++++++++--------------- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/source/ngc/gui/gui_savebrowser.cpp b/source/ngc/gui/gui_savebrowser.cpp index bdf8693..c951a16 100644 --- a/source/ngc/gui/gui_savebrowser.cpp +++ b/source/ngc/gui/gui_savebrowser.cpp @@ -22,10 +22,10 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a) action = a; selectable = true; - if(action == 0) // save + if(action == 0) // load listOffset = 0; else - listOffset = -2; + listOffset = -2; // save - reserve -2 & -1 for new slots selectedItem = 0; focus = 0; // allow focus @@ -199,13 +199,13 @@ void GuiSaveBrowser::ResetState() int GuiSaveBrowser::GetClickedSave() { - int found = -1; + int found = -3; for(int i=0; iGetState() == STATE_CLICKED) { saveBtn[i]->SetState(STATE_SELECTED); - found = i; + found = listOffset+i; break; } } diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 133672a..b377c34 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -1494,7 +1494,7 @@ static int MenuGameSaves(int action) ret = saveBrowser.GetClickedSave(); // load or save game - if(ret >= 0) + if(ret > -3) { int result = 0; @@ -1516,7 +1516,7 @@ static int MenuGameSaves(int action) } else // save { - if(ret == 0) // new SRAM + if(ret == -2) // new SRAM { for(i=1; i < 100; i++) if(saves.files[FILE_SRAM][i] == 0) @@ -1529,7 +1529,7 @@ static int MenuGameSaves(int action) menu = MENU_GAME_SAVE; } } - else if(ret == 1) // new Snapshot + else if(ret == -1) // new Snapshot { for(i=1; i < 100; i++) if(saves.files[FILE_SNAPSHOT][i] == 0) @@ -1544,8 +1544,8 @@ static int MenuGameSaves(int action) } else // overwrite SRAM/Snapshot { - MakeFilePath(filepath, saves.type[ret-2], method, saves.filename[ret-2]); - switch(saves.type[ret-2]) + MakeFilePath(filepath, saves.type[ret], method, saves.filename[ret]); + switch(saves.type[ret]) { case FILE_SRAM: SaveBatteryOrState(filepath, GCSettings.SaveMethod, FILE_SRAM, NOTSILENT); diff --git a/source/ngc/vbasupport.cpp b/source/ngc/vbasupport.cpp index 17e0085..59f0891 100644 --- a/source/ngc/vbasupport.cpp +++ b/source/ngc/vbasupport.cpp @@ -368,6 +368,31 @@ bool SaveBatteryOrState(char * filepath, int method, int action, bool silent) if(method == METHOD_AUTO) return false; + // save screenshot - I would prefer to do this from gameScreenTex + if(action == FILE_SNAPSHOT && gameScreenTex2 != NULL && method != METHOD_MC_SLOTA && method != METHOD_MC_SLOTB) + { + AllocSaveBuffer (); + + IMGCTX pngContext = PNGU_SelectImageFromBuffer(savebuffer); + + if (pngContext != NULL) + { + imgSize = PNGU_EncodeFromGXTexture(pngContext, screenwidth, screenheight, gameScreenTex2, 0); + PNGU_ReleaseImageContext(pngContext); + } + + if(imgSize > 0) + { + char screenpath[1024]; + strncpy(screenpath, filepath, 1024); + screenpath[strlen(screenpath)-4] = 0; + sprintf(screenpath, "%s.png", screenpath); + SaveFile(screenpath, imgSize, method, silent); + } + + FreeSaveBuffer (); + } + AllocSaveBuffer(); // set comments for Memory Card saves @@ -455,30 +480,6 @@ bool SaveBatteryOrState(char * filepath, int method, int action, bool silent) FreeSaveBuffer(); - // save screenshot - I would prefer to do this from gameScreenTex - if(offset > 0 && gameScreenTex2 != NULL && method != METHOD_MC_SLOTA && method != METHOD_MC_SLOTB) - { - AllocSaveBuffer (); - - IMGCTX pngContext = PNGU_SelectImageFromBuffer(savebuffer); - - if (pngContext != NULL) - { - imgSize = PNGU_EncodeFromGXTexture(pngContext, 640, 480, gameScreenTex2, 0); - PNGU_ReleaseImageContext(pngContext); - } - - if(imgSize > 0) - { - char screenpath[1024]; - filepath[strlen(filepath)-4] = 0; - sprintf(screenpath, "%s.png", filepath); - SaveFile(screenpath, imgSize, method, silent); - } - - FreeSaveBuffer (); - } - return result; }