Skip to content

Commit

Permalink
Ask for confirmation when quickly loading saves by (F8) key
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Dec 12, 2024
1 parent 96ce8bf commit 115ffed
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/ingameop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,45 @@ static bool startIGMouseOptionsMenu()
return true;
}

class IntFormAnimatedQuickLoad : public IntFormAnimated {};

void showQuickLoadConfirmation()
{
widgDelete(psWScreen, INTINGAMEOP);
auto const& parent = psWScreen->psForm;

auto ingameOp = std::make_shared<IntFormAnimatedQuickLoad>();
parent->attach(ingameOp);
ingameOp->id = INTINGAMEOP;

int row = 1;

auto label = std::make_shared<W_LABEL>();
ingameOp->attach(label);
label->setGeometry(INTINGAMEOP_2_X, INTINGAMEOPAUTO_Y_LINE(row), INTINGAMEOP4_OP_W, 0);
label->setString(_("Warning: Are you sure? Any unsaved progress will be lost."));
label->setTextAlignment(WLAB_ALIGNCENTRE);
label->setFont(font_medium, WZCOL_YELLOW);

row++;

auto label2 = std::make_shared<W_LABEL>();
ingameOp->attach(label2);
label2->setGeometry(INTINGAMEOP_2_X, INTINGAMEOPAUTO_Y_LINE(row), INTINGAMEOP4_OP_W, 0);
label2->setString(_("Press the key again to continue or ESC to cancel."));
label2->setTextAlignment(WLAB_ALIGNCENTRE);
label2->setFont(font_medium, WZCOL_WHITE);

ingameOp->setCalcLayout([row](WIDGET* psWidget) {
psWidget->setGeometry(INTINGAMEOP4_X, INTINGAMEOPAUTO_Y(row), INTINGAMEOP4_W, INTINGAMEOPAUTO_H(row));
});
}

bool isQuickLoadConfirmationFormOpen()
{
return dynamic_cast<IntFormAnimatedQuickLoad*>(widgGetFromID(psWScreen, INTINGAMEOP)) != nullptr;
}

static bool runIGMouseOptionsMenu(UDWORD id)
{
switch (id)
Expand Down
2 changes: 2 additions & 0 deletions src/ingameop.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ bool intCloseInGameOptions(bool bPutUpLoadSave, bool bResetMissionWidgets);
void intCloseInGameOptionsNoAnim();
void intProcessInGameOptions(UDWORD);
void intAddInGamePopup();
void showQuickLoadConfirmation();
bool isQuickLoadConfirmationFormOpen();

extern bool hostQuitConfirmation;

Expand Down
10 changes: 8 additions & 2 deletions src/keybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,13 @@ void kf_QuickLoad()

const char *filename = bMultiPlayer ? QUICKSAVE_SKI_FILENAME : QUICKSAVE_CAM_FILENAME;
// check for .json version, because that's what going to be loaded anyway
if (PHYSFS_exists(filename) || PHYSFS_exists(bMultiPlayer ? QUICKSAVE_SKI_JSON_FILENAME : QUICKSAVE_CAM_JSON_FILENAME))
if (!(PHYSFS_exists(filename) || PHYSFS_exists(bMultiPlayer ? QUICKSAVE_SKI_JSON_FILENAME : QUICKSAVE_CAM_JSON_FILENAME)))
{
console(_("QuickSave file does not exist yet"));
return;
}

if (isQuickLoadConfirmationFormOpen())
{
console(_("QuickLoad"));
audio_StopAll();
Expand All @@ -2618,7 +2624,7 @@ void kf_QuickLoad()
}
else
{
console(_("QuickSave file does not exist yet"));
showQuickLoadConfirmation();
}
}

Expand Down

0 comments on commit 115ffed

Please sign in to comment.