Skip to content

Commit

Permalink
Game Menu|Added: Delete save state from "SaveGame" and "LoadGame" pages
Browse files Browse the repository at this point in the history
When not editing the name of a save state, the user can delete an
existing save by highlighting it's name and pressing 'Delete'.
  • Loading branch information
danij-deng committed Jul 15, 2012
1 parent 0cc2b8d commit bfc1fc5
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 51 deletions.
4 changes: 4 additions & 0 deletions doomsday/plugins/common/include/hu_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,13 @@ void MNPage_SetY(mn_page_t* page, int y);

void MNPage_SetPreviousPage(mn_page_t* page, mn_page_t* prevPage);

void MNPage_Refocus(mn_page_t* page);

/// @return Currently focused object else @c NULL
mn_object_t* MNPage_FocusObject(mn_page_t* page);

void MNPage_ClearFocusObject(mn_page_t* page);

/**
* Attempt to give focus to the MNObject @a obj which is thought to be on
* this page. If @a obj is found to present and is not currently in-focus,
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/common/include/hu_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ mn_page_t* Hu_MenuActivePage(void);
/**
* Change the current active page.
*/
void Hu_MenuSetActivePage2(mn_page_t* page, boolean canReactivate);
void Hu_MenuSetActivePage(mn_page_t* page);

/**
Expand Down
12 changes: 12 additions & 0 deletions doomsday/plugins/common/src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,18 @@ boolean G_DeleteSaveGame(int slot)
info = SV_SaveInfoForSlot(slot);
DENG_ASSERT(info);
SV_ClearSlot(slot);

if(Hu_MenuIsActive())
{
mn_page_t* activePage = Hu_MenuActivePage();
if(activePage == Hu_MenuFindPageByName("LoadGame") ||
activePage == Hu_MenuFindPageByName("SaveGame"))
{
// Re-open the current menu page.
Hu_MenuUpdateGameSaveWidgets();
Hu_MenuSetActivePage2(activePage, true);
}
}
return true;
}

Expand Down
121 changes: 75 additions & 46 deletions doomsday/plugins/common/src/hu_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,28 @@ mn_object_t* MNPage_FocusObject(mn_page_t* page)
return &page->objects[page->focus];
}

void MNPage_ClearFocusObject(mn_page_t* page)
{
mn_object_t* ob;
int i;
DENG_ASSERT(page);
if(page->focus >= 0)
{
ob = &page->objects[page->focus];
if(MNObject_Flags(ob) & MNF_ACTIVE)
{
return;
}
}
page->focus = -1;
ob = page->objects;
for(i = 0; i < page->objectsCount; ++i, ob++)
{
MNObject_SetFlags(ob, FO_CLEAR, MNF_FOCUS);
}
MNPage_Refocus(page);
}

mn_object_t* MNPage_FindObject(mn_page_t* page, int group, int flags)
{
mn_object_t* obj = page->objects;
Expand Down Expand Up @@ -1235,11 +1257,62 @@ void MNPage_SetFocus(mn_page_t* page, mn_object_t* obj)
MNPage_GiveChildFocus(page, page->objects + objIndex, false);
}

void MNPage_Refocus(mn_page_t* page)
{
DENG_ASSERT(page);

// If we haven't yet visited this page then find the first focusable
// object and select it.
if(0 > page->focus)
{
int i, giveFocus = -1;

// First look for a default focus object. There should only be one
// but find the last with this flag...
for(i = 0; i < page->objectsCount; ++i)
{
mn_object_t* ob = &page->objects[i];
if((MNObject_Flags(ob) & MNF_DEFAULT) && !(MNObject_Flags(ob) & (MNF_DISABLED|MNF_NO_FOCUS)))
{
giveFocus = i;
}
}

// No default focus? Find the first focusable object.
if(-1 == giveFocus)
for(i = 0; i < page->objectsCount; ++i)
{
mn_object_t* ob = &page->objects[i];
if(!(MNObject_Flags(ob) & (MNF_DISABLED|MNF_NO_FOCUS)))
{
giveFocus = i;
break;
}
}

if(-1 != giveFocus)
{
MNPage_GiveChildFocus(page, page->objects + giveFocus, false);
}
#if _DEBUG
else
{
Con_Message("Warning:MNPage::Refocus: No focusable object on page.\n");
}
#endif
}
else
{
// We've been here before; re-focus on the last focused object.
MNPage_GiveChildFocus(page, page->objects + page->focus, true);
}
}

void MNPage_Initialize(mn_page_t* page)
{
mn_object_t* ob;
int i;
assert(page);
DENG_ASSERT(page);

// Reset page timer.
page->timer = 0;
Expand Down Expand Up @@ -1286,51 +1359,7 @@ void MNPage_Initialize(mn_page_t* page)
return;
}

// If we haven't yet visited this page then find the first focusable
// object and select it.
if(0 > page->focus)
{
int i, giveFocus = -1;

// First look for a default focus object. There should only be one
// but find the last with this flag...
for(i = 0; i < page->objectsCount; ++i)
{
mn_object_t* ob = &page->objects[i];
if((MNObject_Flags(ob) & MNF_DEFAULT) && !(MNObject_Flags(ob) & (MNF_DISABLED|MNF_NO_FOCUS)))
{
giveFocus = i;
}
}

// No default focus? Find the first focusable object.
if(-1 == giveFocus)
for(i = 0; i < page->objectsCount; ++i)
{
mn_object_t* ob = &page->objects[i];
if(!(MNObject_Flags(ob) & (MNF_DISABLED|MNF_NO_FOCUS)))
{
giveFocus = i;
break;
}
}

if(-1 != giveFocus)
{
MNPage_GiveChildFocus(page, page->objects + giveFocus, false);
}
#if _DEBUG
else
{
Con_Message("Warning:MNPage::Initialize: No focusable object on page.\n");
}
#endif
}
else
{
// We've been here before; re-focus on the last focused object.
MNPage_GiveChildFocus(page, page->objects + page->focus, true);
}
MNPage_Refocus(page);
}

void MNPage_Ticker(mn_page_t* page)
Expand Down
65 changes: 60 additions & 5 deletions doomsday/plugins/common/src/hu_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,37 @@ void Hu_MenuInitFilesPage(void)
}
#endif

static void deleteGameSave(int slot)
{
DD_Executef(true, "deletegamesave %i", slot);
}

int Hu_MenuLoadSlotCommandResponder(mn_object_t* ob, menucommand_e cmd)
{
DENG_ASSERT(ob && ob->_type == MN_EDIT);
if(MCMD_DELETE == cmd &&
(ob->_flags & MNF_FOCUS) && !(ob->_flags & MNF_ACTIVE) && !(ob->_flags & MNF_DISABLED))
{
mndata_edit_t* edit = (mndata_edit_t*)ob->_typedata;
deleteGameSave(edit->data2);
return true;
}
return MNObject_DefaultCommandResponder(ob, cmd);
}

int Hu_MenuSaveSlotCommandResponder(mn_object_t* ob, menucommand_e cmd)
{
assert(ob);
if(MCMD_DELETE == cmd &&
(ob->_flags & MNF_FOCUS) && !(ob->_flags & MNF_ACTIVE) && !(ob->_flags & MNF_DISABLED))
{
mndata_edit_t* edit = (mndata_edit_t*)ob->_typedata;
deleteGameSave(edit->data2);
return true;
}
return MNEdit_CommandResponder(ob, cmd);
}

void Hu_MenuInitLoadGameAndSaveGamePages(void)
{
#if __JDOOM__ || __JDOOM64__
Expand Down Expand Up @@ -1777,7 +1808,7 @@ void Hu_MenuInitLoadGameAndSaveGamePages(void)
ob->drawer = MNEdit_Drawer;
ob->actions[MNA_ACTIVEOUT].callback = Hu_MenuSelectLoadSlot;
ob->actions[MNA_FOCUSOUT].callback = Hu_MenuDefaultFocusAction;
ob->cmdResponder = MNObject_DefaultCommandResponder;
ob->cmdResponder = Hu_MenuLoadSlotCommandResponder;
ob->_typedata = edit;
ob->data2 = saveSlotObjectIds[i];
Str_Init(&edit->text);
Expand Down Expand Up @@ -1805,7 +1836,7 @@ void Hu_MenuInitLoadGameAndSaveGamePages(void)
ob->actions[MNA_ACTIVEOUT].callback = Hu_MenuSelectSaveSlot;
ob->actions[MNA_ACTIVE].callback = Hu_MenuSaveSlotEdit;
ob->actions[MNA_FOCUSOUT].callback = Hu_MenuDefaultFocusAction;
ob->cmdResponder = MNEdit_CommandResponder;
ob->cmdResponder = Hu_MenuSaveSlotCommandResponder;
ob->responder = MNEdit_Responder;
ob->_typedata = edit;
ob->data2 = saveSlotObjectIds[i];
Expand Down Expand Up @@ -4303,7 +4334,7 @@ mn_page_t* Hu_MenuActivePage(void)
return menuActivePage;
}

void Hu_MenuSetActivePage(mn_page_t* page)
void Hu_MenuSetActivePage2(mn_page_t* page, boolean canReactivate)
{
if(!menuActive) return;
if(!page) return;
Expand All @@ -4316,7 +4347,11 @@ void Hu_MenuSetActivePage(mn_page_t* page)
cursorAngle = 0; // Stop cursor rotation animation dead (don't rewind).
menuNominatingQuickSaveSlot = false;

if(menuActivePage == page) return;
if(menuActivePage == page)
{
if(!canReactivate) return;
MNPage_ClearFocusObject(page);
}

updatePageObjects(page);

Expand All @@ -4325,6 +4360,11 @@ void Hu_MenuSetActivePage(mn_page_t* page)
MNPage_Initialize(page);
}

void Hu_MenuSetActivePage(mn_page_t* page)
{
Hu_MenuSetActivePage2(page, false/*don't reactivate*/);
}

boolean Hu_MenuIsVisible(void)
{
return (menuActive || mnAlpha > .0001f);
Expand Down Expand Up @@ -5597,6 +5637,8 @@ int Hu_MenuCvarColorBox(mn_object_t* obj, mn_actionid_t action, void* parameters

void Hu_MenuDrawLoadGamePage(mn_page_t* page, const Point2Raw* origin)
{
DENG_UNUSED(page);

DGL_Enable(DGL_TEXTURE_2D);
DGL_Color4f(1, 1, 1, mnRendState->pageAlpha);
FR_SetFont(FID(GF_FONTB));
Expand All @@ -5608,12 +5650,19 @@ void Hu_MenuDrawLoadGamePage(mn_page_t* page, const Point2Raw* origin)
WI_DrawPatchXY3(pLoadGame, Hu_ChoosePatchReplacement(cfg.menuPatchReplaceMode, pLoadGame),
origin->x - 8, origin->y - 26, ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
#endif

DGL_Disable(DGL_TEXTURE_2D);

{ Point2Raw helpOrigin;
helpOrigin.x = SCREENWIDTH/2;
helpOrigin.y = (SCREENHEIGHT/2) + ((SCREENHEIGHT/2-5)/cfg.menuScale);
Hu_MenuDrawPageHelp("Select to load, [Del] to clear", helpOrigin.x, helpOrigin.y);
}
}

void Hu_MenuDrawSaveGamePage(mn_page_t* page, const Point2Raw* origin)
{
DENG_UNUSED(page);

#if __JHERETIC__ || __JHEXEN__
Hu_MenuDrawPageTitle("Save Game", SCREENWIDTH/2, origin->y - 20);
#else
Expand All @@ -5627,6 +5676,12 @@ void Hu_MenuDrawSaveGamePage(mn_page_t* page, const Point2Raw* origin)

DGL_Disable(DGL_TEXTURE_2D);
#endif

{ Point2Raw helpOrigin;
helpOrigin.x = SCREENWIDTH/2;
helpOrigin.y = (SCREENHEIGHT/2) + ((SCREENHEIGHT/2-5)/cfg.menuScale);
Hu_MenuDrawPageHelp("Select to save, [Del] to clear", helpOrigin.x, helpOrigin.y);
}
}

#if __JDOOM__ || __JHERETIC__ || __JHEXEN__
Expand Down

0 comments on commit bfc1fc5

Please sign in to comment.