Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask for confirmation when quickly loading saves by (F8) key #4150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading