added key shortcuts to restart and replay/resume (before end) the game
authorHolger Schemel <info@artsoft.org>
Thu, 3 Feb 2022 19:26:39 +0000 (20:26 +0100)
committerHolger Schemel <info@artsoft.org>
Thu, 10 Feb 2022 18:23:52 +0000 (19:23 +0100)
src/events.c
src/files.c
src/libgame/system.h
src/screens.c
src/tape.c
src/tape.h

index 4a1ecbfee9df368244a8d26d596c7b677fcce925..968084f48474583c99d069c728b5425b27dac550 100644 (file)
@@ -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);
 
index 18fc104924900eed536be361eba8acf20eda4b50..7bbcac77d755ddbc4e2e9d8446bbb020d5d03ee3 100644 (file)
@@ -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;
index 4acc61d8858bb4dc68ee26271bc2b0196d19b3b9..ad89c320722276631d38f4d766c5ef5e09c04812 100644 (file)
 // 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];
index a5b808a1969462bac0a1bc7b1aefd001a1b49cb3..23b8b0d1753d7389f109722bddc1d6558bc69bac 100644 (file)
@@ -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,                   ""                      },
index a6ab98561aa32c9f2dcc213cbc07312941cfa3d2..68ffadcf92677d6d126deb3075b6b5e1f417fdeb 100644 (file)
@@ -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));
index 4b914c73d2ac394debdce2a290264708861062ec..022e9ca54e7116eca0c651a43c1ffeb33f6db161 100644 (file)
@@ -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);