diff --git a/src/program/GameEvents.cpp b/src/program/GameEvents.cpp index 872a1ac0..102f632d 100644 --- a/src/program/GameEvents.cpp +++ b/src/program/GameEvents.cpp @@ -33,6 +33,8 @@ #include #include +#define MAX_SELECTABLE_SAVESTATE 9 + GameEvents::GameEvents(Context* c, MovieFile* m) : context(c), movie(m) {} void GameEvents::init() @@ -109,6 +111,7 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) case HOTKEY_SAVESTATE8: case HOTKEY_SAVESTATE9: case HOTKEY_SAVESTATE_BACKTRACK: + case HOTKEY_SAVESTATE_SELECTED: { /* Perform a savestate: * - save the moviefile if we are recording @@ -122,7 +125,13 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) } /* Slot number */ - int statei = hk.type - HOTKEY_SAVESTATE1 + 1; + int statei; + if (hk.type == HOTKEY_SAVESTATE_SELECTED) { + statei = selectedSavestateId; + } + else { + statei = hk.type - HOTKEY_SAVESTATE1 + 1; + } /* Perform savestate */ int message = SaveStateList::save(statei, context, *movie); @@ -146,6 +155,7 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) case HOTKEY_LOADSTATE8: case HOTKEY_LOADSTATE9: case HOTKEY_LOADSTATE_BACKTRACK: + case HOTKEY_LOADSTATE_SELECTED: case HOTKEY_LOADBRANCH1: case HOTKEY_LOADBRANCH2: case HOTKEY_LOADBRANCH3: @@ -180,7 +190,13 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) bool load_branch = (hk.type >= HOTKEY_LOADBRANCH1) && (hk.type <= HOTKEY_LOADBRANCH_BACKTRACK); /* Slot number */ - int statei = hk.type - (load_branch?HOTKEY_LOADBRANCH1:HOTKEY_LOADSTATE1) + 1; + int statei; + if (hk.type == HOTKEY_LOADSTATE_SELECTED) { + statei = selectedSavestateId; + } + else { + statei = hk.type - (load_branch?HOTKEY_LOADBRANCH1:HOTKEY_LOADSTATE1) + 1; + } /* Perform state loading */ int error = SaveStateList::load(statei, context, *movie, load_branch); @@ -268,6 +284,32 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) return false; } + case HOTKEY_SELECTSTATE_NEXT: + if (selectedSavestateId >= MAX_SELECTABLE_SAVESTATE) { + selectedSavestateId = 1; + } + else { + selectedSavestateId++; + } + + sendMessage(MSGN_OSD_MSG); + sendString("State " + std::to_string(selectedSavestateId) + " selected"); + + return false; + + case HOTKEY_SELECTSTATE_PREVIOUS: + if (selectedSavestateId <= 1) { + selectedSavestateId = MAX_SELECTABLE_SAVESTATE; + } + else { + selectedSavestateId--; + } + + sendMessage(MSGN_OSD_MSG); + sendString("State " + std::to_string(selectedSavestateId) + " selected"); + + return false; + case HOTKEY_READWRITE: /* Switch between movie write and read-only */ switch (context->config.sc.recording) { diff --git a/src/program/GameEvents.h b/src/program/GameEvents.h index 813b8846..19d749d8 100644 --- a/src/program/GameEvents.h +++ b/src/program/GameEvents.h @@ -58,6 +58,9 @@ class GameEvents : public QObject { /* Indicate if at least one savestate was performed, for backtrack savestate */ bool didASavestate = false; + /* Track selected savestate id */ + int selectedSavestateId = 1; + protected: Context* context; MovieFile* movie; diff --git a/src/program/KeyMapping.cpp b/src/program/KeyMapping.cpp index e7c34b19..8b8df60a 100644 --- a/src/program/KeyMapping.cpp +++ b/src/program/KeyMapping.cpp @@ -81,6 +81,10 @@ KeyMapping::KeyMapping(void* c) hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F9 | XK_Control_Flag}, HOTKEY_LOADBRANCH9, "Load Branch 9"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F10 | XK_Control_Flag}, HOTKEY_LOADBRANCH_BACKTRACK, "Load Backtrack Branch"}); hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_TOGGLE_ENCODE, "Toggle encode"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SAVESTATE_SELECTED, "Save Selected State"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_LOADSTATE_SELECTED, "Load Selected State"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SELECTSTATE_NEXT, "Select Next State"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SELECTSTATE_PREVIOUS, "Select Previous State"}); /* Add flags mapping */ input_list[INPUTLIST_FLAG].push_back({SingleInput::IT_FLAG, SingleInput::FLAG_RESTART, "Restart"}); diff --git a/src/program/KeyMapping.h b/src/program/KeyMapping.h index b90ff28f..395aeee5 100644 --- a/src/program/KeyMapping.h +++ b/src/program/KeyMapping.h @@ -78,7 +78,11 @@ typedef int HotKeyType; enum HOTKEY_LOADBRANCH9, HOTKEY_LOADBRANCH_BACKTRACK, HOTKEY_TOGGLE_FASTFORWARD, // Toggle fastforward - HOTKEY_LEN + HOTKEY_LEN, + HOTKEY_SAVESTATE_SELECTED, + HOTKEY_LOADSTATE_SELECTED, + HOTKEY_SELECTSTATE_NEXT, + HOTKEY_SELECTSTATE_PREVIOUS }; struct HotKey {