Skip to content

Commit

Permalink
Merge pull request #689 from askotx/master
Browse files Browse the repository at this point in the history
Add delete SRAM/state by Zopenko
  • Loading branch information
askotx authored Nov 22, 2016
2 parents 00b8c5f + d37fdde commit 1e46032
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
2 changes: 2 additions & 0 deletions source/filelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 6 additions & 2 deletions source/gui/gui_savebrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Binary file added source/images/icon_game_delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 62 additions & 4 deletions source/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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;
Expand All @@ -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");

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1e46032

Please sign in to comment.