From: Holger Schemel Date: Thu, 3 Feb 2022 19:26:39 +0000 (+0100) Subject: added key shortcuts to restart and replay/resume (before end) the game X-Git-Tag: 4.3.2.0~134 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=1e56877fb87c1004b98e6c5fbb1132da2178b46e;p=rocksndiamonds.git added key shortcuts to restart and replay/resume (before end) the game --- diff --git a/src/events.c b/src/events.c index 4a1ecbfe..968084f4 100644 --- a/src/events.c +++ b/src/events.c @@ -2284,6 +2284,10 @@ void HandleKey(Key key, int key_status) TapeQuickSave(); else if (key == setup.shortcut.load_game) TapeQuickLoad(); + else if (key == setup.shortcut.restart_game) + TapeRestartGame(); + else if (key == setup.shortcut.pause_before_end) + TapeReplayAndPauseBeforeEnd(); else if (key == setup.shortcut.toggle_pause) TapeTogglePause(TAPE_TOGGLE_MANUAL | TAPE_TOGGLE_PLAY_PAUSE); diff --git a/src/files.c b/src/files.c index 18fc1049..7bbcac77 100644 --- a/src/files.c +++ b/src/files.c @@ -10364,6 +10364,14 @@ static struct TokenInfo shortcut_setup_tokens[] = TYPE_KEY_X11, &setup.shortcut.load_game, "shortcut.load_game" }, + { + TYPE_KEY_X11, + &setup.shortcut.restart_game, "shortcut.restart_game" + }, + { + TYPE_KEY_X11, + &setup.shortcut.pause_before_end, "shortcut.pause_before_end" + }, { TYPE_KEY_X11, &setup.shortcut.toggle_pause, "shortcut.toggle_pause" @@ -10922,6 +10930,8 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->shortcut.save_game = DEFAULT_KEY_SAVE_GAME; si->shortcut.load_game = DEFAULT_KEY_LOAD_GAME; + si->shortcut.restart_game = DEFAULT_KEY_RESTART_GAME; + si->shortcut.pause_before_end = DEFAULT_KEY_PAUSE_BEFORE_END; si->shortcut.toggle_pause = DEFAULT_KEY_TOGGLE_PAUSE; si->shortcut.focus_player[0] = DEFAULT_KEY_FOCUS_PLAYER_1; diff --git a/src/libgame/system.h b/src/libgame/system.h index 4acc61d8..ad89c320 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -175,6 +175,8 @@ // default shortcut keys #define DEFAULT_KEY_SAVE_GAME KSYM_F1 #define DEFAULT_KEY_LOAD_GAME KSYM_F2 +#define DEFAULT_KEY_RESTART_GAME KSYM_F3 +#define DEFAULT_KEY_PAUSE_BEFORE_END KSYM_F4 #define DEFAULT_KEY_TOGGLE_PAUSE KSYM_space #define DEFAULT_KEY_FOCUS_PLAYER_1 KSYM_F5 #define DEFAULT_KEY_FOCUS_PLAYER_2 KSYM_F6 @@ -1365,6 +1367,8 @@ struct SetupShortcutInfo { Key save_game; Key load_game; + Key restart_game; + Key pause_before_end; Key toggle_pause; Key focus_player[MAX_PLAYERS]; diff --git a/src/screens.c b/src/screens.c index a5b808a1..23b8b0d1 100644 --- a/src/screens.c +++ b/src/screens.c @@ -7558,6 +7558,10 @@ static struct TokenInfo setup_info_shortcuts_1[] = { TYPE_KEY, &setup.shortcut.save_game, "" }, { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", }, { TYPE_KEY, &setup.shortcut.load_game, "" }, + { TYPE_KEYTEXT, NULL, "Restart Game:", }, + { TYPE_KEY, &setup.shortcut.restart_game, "" }, + { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", }, + { TYPE_KEY, &setup.shortcut.pause_before_end, "" }, { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", }, { TYPE_KEY, &setup.shortcut.toggle_pause, "" }, { TYPE_EMPTY, NULL, "" }, diff --git a/src/tape.c b/src/tape.c index a6ab9856..68ffadcf 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1244,6 +1244,59 @@ void TapeQuickLoad(void) } } +static boolean checkRestartGame(char *message) +{ + if (game_status == GAME_MODE_MAIN) + return TRUE; + + if (!hasStartedNetworkGame()) + return FALSE; + + if (level_editor_test_game) + return TRUE; + + if (game.all_players_gone) + return TRUE; + + if (!setup.ask_on_quit_game) + return TRUE; + + if (Request(message, REQ_ASK | REQ_STAY_CLOSED)) + return TRUE; + + OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK); + + return FALSE; +} + +void TapeRestartGame(void) +{ + if (!checkRestartGame("Restart game?")) + return; + + StartGameActions(network.enabled, setup.autorecord, level.random_seed); +} + +void TapeReplayAndPauseBeforeEnd(void) +{ + if (TAPE_IS_EMPTY(tape) && !tape.recording) + { + Request("No tape for this level!", REQ_CONFIRM); + + return; + } + + if (!checkRestartGame("Replay game and pause before end?")) + return; + + TapeStop(); + TapeStartGamePlaying(); + TapeStartWarpForward(AUTOPLAY_MODE_WARP_NO_DISPLAY); + + tape.pause_before_end = TRUE; + tape.quick_resume = TRUE; +} + boolean hasSolutionTape(void) { boolean tape_file_exists = fileExists(getSolutionTapeFilename(level_nr)); diff --git a/src/tape.h b/src/tape.h index 4b914c73..022e9ca5 100644 --- a/src/tape.h +++ b/src/tape.h @@ -268,6 +268,8 @@ unsigned int GetTapeLengthFrames(void); unsigned int GetTapeLengthSeconds(void); void TapeQuickSave(void); void TapeQuickLoad(void); +void TapeRestartGame(void); +void TapeReplayAndPauseBeforeEnd(void); boolean hasSolutionTape(void); boolean InsertSolutionTape(void);