diff --git a/source/frontends/sa2/emulator.cpp b/source/frontends/sa2/emulator.cpp index 9bd59df8..484cd1c5 100644 --- a/source/frontends/sa2/emulator.cpp +++ b/source/frontends/sa2/emulator.cpp @@ -1,5 +1,6 @@ #include "frontends/sa2/emulator.h" #include "frontends/sa2/sdirectsound.h" +#include "frontends/sa2/utils.h" #include @@ -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; } diff --git a/source/frontends/sa2/utils.cpp b/source/frontends/sa2/utils.cpp index 0c1c0312..f077cb2e 100644 --- a/source/frontends/sa2/utils.cpp +++ b/source/frontends/sa2/utils.cpp @@ -1,7 +1,10 @@ #include "frontends/sa2/utils.h" #include -void printRendererInfo(std::ostream & os, std::shared_ptr & ren, const Uint32 pixelFormat, const int selectedDriver) +void printRendererInfo(std::ostream & os, + const std::shared_ptr & 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 & ren, c os << "No Renderinfo" << std::endl; } } + +bool show_yes_no_dialog(const std::shared_ptr & 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; +} diff --git a/source/frontends/sa2/utils.h b/source/frontends/sa2/utils.h index 3fe9492a..a6dc3bf5 100644 --- a/source/frontends/sa2/utils.h +++ b/source/frontends/sa2/utils.h @@ -3,5 +3,13 @@ #include #include #include +#include -void printRendererInfo(std::ostream & os, std::shared_ptr & ren, const Uint32 pixelFormat, const int selectedDriver); +void printRendererInfo(std::ostream & os, + const std::shared_ptr & ren, + const Uint32 pixelFormat, + const int selectedDriver); + +bool show_yes_no_dialog(const std::shared_ptr & win, + const std::string & title, + const std::string & text);