Skip to content

Commit

Permalink
allow next/prev state to go up to 99; add hotkey for save/load custom…
Browse files Browse the repository at this point in the history
… state (#426)
  • Loading branch information
Jamiras authored Sep 26, 2024
1 parent d81712a commit 9a1db91
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 12 additions & 4 deletions src/KeyBinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ enum
kSetSlot10,
kLoadCurrent,
kSaveCurrent,
kLoadCustom,
kSaveCustom,

// Disc management
kToggleTray,
Expand Down Expand Up @@ -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",

Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1529,13 +1535,15 @@ 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)
{
snprintf(label, sizeof(label), "Load State %d", i + 1);
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)
{
Expand Down
3 changes: 2 additions & 1 deletion src/KeyBinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class KeyBinds
Type type;
uint16_t modifiers;
};
typedef std::array<Binding, 101> BindingList;

typedef std::array<Binding, 103> BindingList;

static void getBindingString(char buffer[32], const KeyBinds::Binding& desc);

Expand Down

0 comments on commit 9a1db91

Please sign in to comment.