diff --git a/source/filelist.h b/source/filelist.h index e15a85f..fcde07b 100644 --- a/source/filelist.h +++ b/source/filelist.h @@ -93,6 +93,8 @@ extern const u8 icon_game_load_png[]; extern const u32 icon_game_load_png_size; extern const u8 icon_game_save_png[]; extern const u32 icon_game_save_png_size; +extern const u8 icon_game_delete_png[]; +extern const u32 icon_game_delete_png_size; extern const u8 icon_game_reset_png[]; extern const u32 icon_game_reset_png_size; diff --git a/source/gui/gui_savebrowser.cpp b/source/gui/gui_savebrowser.cpp index 5e18177..1c17450 100644 --- a/source/gui/gui_savebrowser.cpp +++ b/source/gui/gui_savebrowser.cpp @@ -24,6 +24,8 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a) if(action == 0) // load listOffset = 0; + else if(action == 2) // delete SRAM / Snapshot + listOffset = 0; else listOffset = -2; // save - reserve -2 & -1 for new slots @@ -257,7 +259,8 @@ void GuiSaveBrowser::Update(GuiTrigger * t) if(selectedItem == 0) { if((listOffset - 2 >= 0 && action == 0) || - (listOffset >= 0 && action == 1)) + (listOffset >= 0 && action == 1) || + (listOffset - 2 >= 0 && action == 2)) { // move list up by 1 listOffset -= 2; @@ -295,7 +298,8 @@ void GuiSaveBrowser::Update(GuiTrigger * t) if(selectedItem < 2) { if((listOffset - 2 >= 0 && action == 0) || - (listOffset >= 0 && action == 1)) + (listOffset >= 0 && action == 1) || + (listOffset - 2 >= 0 && action == 2)) { // move list up by 1 listOffset -= 2; diff --git a/source/images/icon_game_delete.png b/source/images/icon_game_delete.png new file mode 100644 index 0000000..0502b49 Binary files /dev/null and b/source/images/icon_game_delete.png differ diff --git a/source/menu.cpp b/source/menu.cpp index 529e7ea..bc2782e 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -1230,6 +1230,7 @@ static int MenuGame() GuiImageData iconGameSettings(icon_game_settings_png); GuiImageData iconLoad(icon_game_load_png); GuiImageData iconSave(icon_game_save_png); + GuiImageData iconDelete(icon_game_delete_png); GuiImageData iconReset(icon_game_reset_png); GuiImageData battery(battery_png); @@ -1245,7 +1246,7 @@ static int MenuGame() GuiImage saveBtnIcon(&iconSave); GuiButton saveBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); saveBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - saveBtn.SetPosition(-125, 120); + saveBtn.SetPosition(-200, 120); saveBtn.SetLabel(&saveBtnTxt); saveBtn.SetImage(&saveBtnImg); saveBtn.SetImageOver(&saveBtnImgOver); @@ -1262,7 +1263,7 @@ static int MenuGame() GuiImage loadBtnIcon(&iconLoad); GuiButton loadBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); loadBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - loadBtn.SetPosition(125, 120); + loadBtn.SetPosition(0, 120); loadBtn.SetLabel(&loadBtnTxt); loadBtn.SetImage(&loadBtnImg); loadBtn.SetImageOver(&loadBtnImgOver); @@ -1273,6 +1274,23 @@ static int MenuGame() loadBtn.SetTrigger(trig2); loadBtn.SetEffectGrow(); + GuiText deleteBtnTxt("Delete", 22, (GXColor){0, 0, 0, 255}); + GuiImage deleteBtnImg(&btnLargeOutline); + GuiImage deleteBtnImgOver(&btnLargeOutlineOver); + GuiImage deleteBtnIcon(&iconDelete); + GuiButton deleteBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); + deleteBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); + deleteBtn.SetPosition(200, 120); + deleteBtn.SetLabel(&deleteBtnTxt); + deleteBtn.SetImage(&deleteBtnImg); + deleteBtn.SetImageOver(&deleteBtnImgOver); + deleteBtn.SetIcon(&deleteBtnIcon); + deleteBtn.SetSoundOver(&btnSoundOver); + deleteBtn.SetSoundClick(&btnSoundClick); + deleteBtn.SetTrigger(trigA); + deleteBtn.SetTrigger(trig2); + deleteBtn.SetEffectGrow(); + GuiText resetBtnTxt("Reset", 22, (GXColor){0, 0, 0, 255}); GuiImage resetBtnImg(&btnLargeOutline); GuiImage resetBtnImgOver(&btnLargeOutlineOver); @@ -1386,6 +1404,7 @@ static int MenuGame() w.Append(&titleTxt); w.Append(&saveBtn); w.Append(&loadBtn); + w.Append(&deleteBtn); w.Append(&resetBtn); w.Append(&gameSettingsBtn); @@ -1487,6 +1506,10 @@ static int MenuGame() { menu = MENU_GAME_LOAD; } + else if(deleteBtn.GetState() == STATE_CLICKED) + { + menu = MENU_GAME_DELETE; + } else if(resetBtn.GetState() == STATE_CLICKED) { if (WindowPrompt("Reset Game", "Are you sure that you want to reset this game? Any unsaved progress will be lost.", "OK", "Cancel")) @@ -1603,6 +1626,7 @@ static int MenuGameSaves(int action) int j = 0; SaveList saves; char filepath[1024]; + char deletepath[1024]; char scrfile[1024]; char tmp[MAXJOLIET+1]; struct stat filestat; @@ -1621,6 +1645,8 @@ static int MenuGameSaves(int action) if(action == 0) titleTxt.SetText("Load Game"); + else if (action == 2) + titleTxt.SetText("Delete Saves"); else titleTxt.SetText("Save Game"); @@ -1729,7 +1755,7 @@ static int MenuGameSaves(int action) FreeSaveBuffer(); saves.length = j; - if(saves.length == 0 && action == 0) + if((saves.length == 0 && action == 0) || (saves.length == 0 && action == 2)) { InfoPrompt("No game saves found."); menu = MENU_GAME; @@ -1750,7 +1776,7 @@ static int MenuGameSaves(int action) ret = saveBrowser.GetClickedSave(); - // load or save game + // load, save and delete save games if(ret > -3) { int result = 0; @@ -1769,6 +1795,35 @@ static int MenuGameSaves(int action) } if(result) menu = MENU_EXIT; + } + else if(action == 2) // delete SRAM/Snapshot + { + if (WindowPrompt("Delete File", "Delete this save file? Deleted files can not be restored.", "OK", "Cancel")) + { + MakeFilePath(filepath, saves.type[ret], saves.filename[ret]); + switch(saves.type[ret]) + { + case FILE_SRAM: + strncpy(deletepath, filepath, 1024); + deletepath[strlen(deletepath)-4] = 0; + sprintf(deletepath, "%s.srm", deletepath); + remove(deletepath); // Delete the *.srm file (Battery save file) + break; + case FILE_SNAPSHOT: + strncpy(deletepath, filepath, 1024); + deletepath[strlen(deletepath)-4] = 0; + sprintf(deletepath, "%s.png", deletepath); + remove(deletepath); // Delete the *.png file (Screenshot file) + strncpy(deletepath, filepath, 1024); + deletepath[strlen(deletepath)-4] = 0; + sprintf(deletepath, "%s.frz", deletepath); + remove(deletepath); // Delete the *.frz file (Save State file) + break; + } + } + menu = MENU_GAME_DELETE; + + } else // save { @@ -4053,6 +4108,9 @@ MainMenu (int menu) case MENU_GAME_SAVE: currentMenu = MenuGameSaves(1); break; + case MENU_GAME_DELETE: + currentMenu = MenuGameSaves(2); + break; case MENU_GAMESETTINGS: currentMenu = MenuGameSettings(); break; diff --git a/source/menu.h b/source/menu.h index fc3cd73..169cfbb 100644 --- a/source/menu.h +++ b/source/menu.h @@ -35,6 +35,7 @@ enum MENU_GAME, MENU_GAME_SAVE, MENU_GAME_LOAD, + MENU_GAME_DELETE, MENU_GAMESETTINGS, MENU_GAMESETTINGS_MAPPINGS, MENU_GAMESETTINGS_MAPPINGS_CTRL,