From 9a1db910db8dc9e6ecd58a98bba4f2184adb486c Mon Sep 17 00:00:00 2001 From: Jamiras <32680403+Jamiras@users.noreply.github.com> Date: Thu, 26 Sep 2024 07:54:41 -0600 Subject: [PATCH] allow next/prev state to go up to 99; add hotkey for save/load custom state (#426) --- src/Application.cpp | 12 ++++++++++++ src/KeyBinds.cpp | 16 ++++++++++++---- src/KeyBinds.h | 3 ++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index a333b88..55b8876 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -1846,6 +1846,12 @@ void Application::saveState(const std::string& path) void Application::saveState(unsigned ndx) { + if (ndx == 0) + { + saveState(); + return; + } + if (!_states.saveState(ndx)) { std::string message = "Failed to create save state."; @@ -1889,6 +1895,12 @@ void Application::loadState(const std::string& path) void Application::loadState(unsigned ndx) { + if (ndx == 0) + { + loadState(); + return; + } + if ((_validSlots & (1 << ndx)) == 0) { return; diff --git a/src/KeyBinds.cpp b/src/KeyBinds.cpp index 122d7c2..d3c0af8 100644 --- a/src/KeyBinds.cpp +++ b/src/KeyBinds.cpp @@ -119,6 +119,8 @@ enum kSetSlot10, kLoadCurrent, kSaveCurrent, + kLoadCustom, + kSaveCustom, // Disc management kToggleTray, @@ -169,7 +171,7 @@ static const char* bindingNames[] = { "LOAD1", "LOAD2", "LOAD3", "LOAD4", "LOAD5", "LOAD6", "LOAD7", "LOAD8", "LOAD9", "LOAD0", "NEXT_SLOT", "PREV_SLOT", "SLOT1", "SLOT2", "SLOT3", "SLOT4", "SLOT5", "SLOT6", "SLOT7", "SLOT8", "SLOT9", "SLOT0", - "LOAD_SLOT", "SAVE_SLOT", + "LOAD_SLOT", "SAVE_SLOT", "LOAD_CUSTOM", "SAVE_CUSTOM", "TRAY_OPEN", "DISK_NEXT", "DISK_PREV", @@ -283,7 +285,9 @@ bool KeyBinds::init(Logger* logger) _bindings[kSetSlot9] = { 0, SDLK_9, Binding::Type::Key, 0 }; _bindings[kSetSlot10] = { 0, SDLK_0, Binding::Type::Key, 0 }; _bindings[kLoadCurrent] = { 0, SDLK_F11, Binding::Type::Key, 0 }; - _bindings[kSaveCurrent] = { 0, SDLK_F12, Binding::Type::Key, 0 }; + _bindings[kSaveCurrent] = { 0, SDLK_F11, Binding::Type::Key, KMOD_SHIFT }; + _bindings[kLoadCustom] = { 0, SDLK_F12, Binding::Type::Key, 0 }; + _bindings[kSaveCustom] = { 0, SDLK_F12, Binding::Type::Key, KMOD_SHIFT }; _bindings[kSetWindowSize1] = { 0, SDLK_1, Binding::Type::Key, KMOD_ALT }; _bindings[kSetWindowSize2] = { 0, SDLK_2, Binding::Type::Key, KMOD_ALT }; @@ -417,8 +421,8 @@ KeyBinds::Action KeyBinds::translateButtonPress(int button, unsigned* extra) case kLoadState8: *extra = 8; return Action::kLoadState; case kLoadState9: *extra = 9; return Action::kLoadState; case kLoadState10: *extra = 10; return Action::kLoadState; - case kPreviousSlot: *extra = _slot = (_slot == 1) ? 10 : _slot - 1; return Action::kChangeCurrentState; - case kNextSlot: *extra = _slot = (_slot == 10) ? 1 : _slot + 1; return Action::kChangeCurrentState; + case kPreviousSlot: *extra = _slot = (_slot == 1) ? 99 : _slot - 1; return Action::kChangeCurrentState; + case kNextSlot: *extra = _slot = (_slot == 99) ? 1 : _slot + 1; return Action::kChangeCurrentState; case kSetSlot1: *extra = _slot = 1; return Action::kChangeCurrentState; case kSetSlot2: *extra = _slot = 2; return Action::kChangeCurrentState; case kSetSlot3: *extra = _slot = 3; return Action::kChangeCurrentState; @@ -431,6 +435,8 @@ KeyBinds::Action KeyBinds::translateButtonPress(int button, unsigned* extra) case kSetSlot10: *extra = _slot = 10; return Action::kChangeCurrentState; case kLoadCurrent: *extra = _slot; return Action::kLoadState; case kSaveCurrent: *extra = _slot; return Action::kSaveState; + case kLoadCustom: *extra = 0; return Action::kLoadState; + case kSaveCustom: *extra = 0; return Action::kSaveState; // Disc management case kToggleTray: return Action::kToggleTray; @@ -1529,6 +1535,7 @@ class InputDialog : public Dialog addButtonInput(i, 5, label, kSaveState1 + i); } addButtonInput(10, 5, "Save Current State", kSaveCurrent); + addButtonInput(11, 5, "Save Custom State", kSaveCustom); for (int i = 0; i < 10; ++i) { @@ -1536,6 +1543,7 @@ class InputDialog : public Dialog addButtonInput(i, 7, label, kLoadState1 + i); } addButtonInput(10, 7, "Load Current State", kLoadCurrent); + addButtonInput(11, 7, "Load Custom State", kLoadCustom); for (int i = 0; i < 10; ++i) { diff --git a/src/KeyBinds.h b/src/KeyBinds.h index d38125a..6d3f239 100644 --- a/src/KeyBinds.h +++ b/src/KeyBinds.h @@ -125,7 +125,8 @@ class KeyBinds Type type; uint16_t modifiers; }; - typedef std::array BindingList; + + typedef std::array BindingList; static void getBindingString(char buffer[32], const KeyBinds::Binding& desc);