Add F11 Save State confirmation as it is too easy to confuse with F12.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2020-12-06 18:28:17 +00:00
parent 1d07215f78
commit 092a74f5b3
3 changed files with 54 additions and 4 deletions

View file

@ -1,5 +1,6 @@
#include "frontends/sa2/emulator.h"
#include "frontends/sa2/sdirectsound.h"
#include "frontends/sa2/utils.h"
#include <iostream>
@ -21,6 +22,7 @@
#include "Speaker.h"
#include "Utilities.h"
#include "SaveState.h"
#include "SoundCore.h"
// #define KEY_LOGGING_VERBOSE
@ -226,12 +228,20 @@ void Emulator::processKeyDown(const SDL_KeyboardEvent & key, bool & quit)
{
case SDLK_F12:
{
Snapshot_SaveState();
Snapshot_LoadState();
mySpeed.reset();
break;
}
case SDLK_F11:
{
Snapshot_LoadState();
const std::string & pathname = Snapshot_GetPathname();
const std::string message = "Do you want to save the state to " + pathname + "?";
SoundCore_SetFade(FADE_OUT);
if (show_yes_no_dialog(myWindow, "Save state", message))
{
Snapshot_SaveState();
}
SoundCore_SetFade(FADE_IN);
mySpeed.reset();
break;
}

View file

@ -1,7 +1,10 @@
#include "frontends/sa2/utils.h"
#include <ostream>
void printRendererInfo(std::ostream & os, std::shared_ptr<SDL_Renderer> & ren, const Uint32 pixelFormat, const int selectedDriver)
void printRendererInfo(std::ostream & os,
const std::shared_ptr<SDL_Renderer> & ren,
const Uint32 pixelFormat,
const int selectedDriver)
{
SDL_RendererInfo info;
SDL_GetRendererInfo(ren.get(), &info);
@ -35,3 +38,32 @@ void printRendererInfo(std::ostream & os, std::shared_ptr<SDL_Renderer> & ren, c
os << "No Renderinfo" << std::endl;
}
}
bool show_yes_no_dialog(const std::shared_ptr<SDL_Window> & win,
const std::string & title,
const std::string & text)
{
const SDL_MessageBoxButtonData buttons[] =
{
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "yes" },
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 1, "no" },
};
const SDL_MessageBoxData messageboxdata =
{
SDL_MESSAGEBOX_INFORMATION,
win.get(),
title.c_str(),
text.c_str(),
SDL_arraysize(buttons),
buttons,
nullptr
};
int buttonid;
if (SDL_ShowMessageBox(&messageboxdata, &buttonid) < 0) {
return false;
}
return buttonid == 0;
}

View file

@ -3,5 +3,13 @@
#include <SDL.h>
#include <memory>
#include <iosfwd>
#include <string>
void printRendererInfo(std::ostream & os, std::shared_ptr<SDL_Renderer> & ren, const Uint32 pixelFormat, const int selectedDriver);
void printRendererInfo(std::ostream & os,
const std::shared_ptr<SDL_Renderer> & ren,
const Uint32 pixelFormat,
const int selectedDriver);
bool show_yes_no_dialog(const std::shared_ptr<SDL_Window> & win,
const std::string & title,
const std::string & text);