re-enabled storing selection from "last played level set" menu
authorHolger Schemel <info@artsoft.org>
Sat, 27 Feb 2021 19:22:37 +0000 (20:22 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 27 Feb 2021 19:22:37 +0000 (20:22 +0100)
src/libgame/setup.c
src/libgame/setup.h
src/screens.c

index 9c21b95ac4dd19a4e692780e60bbef679667251f..32ae11215a1a87626d9acdac70e99d6ea62cafaf 100644 (file)
@@ -4609,6 +4609,35 @@ static void UpdateLastPlayedLevels_List(void)
   setString(&last_level_series[0], leveldir_current->identifier);
 }
 
+static TreeInfo *StoreOrRestoreLastPlayedLevels(TreeInfo *node, boolean store)
+{
+  static char *identifier = NULL;
+
+  if (store)
+  {
+    setString(&identifier, (node && node->is_copy ? node->identifier : NULL));
+
+    return NULL;       // not used
+  }
+  else
+  {
+    TreeInfo *node_new = getTreeInfoFromIdentifierExt(leveldir_first,
+                                                     identifier,
+                                                     TREE_NODE_TYPE_COPY);
+    return (node_new != NULL ? node_new : node);
+  }
+}
+
+void StoreLastPlayedLevels(TreeInfo *node)
+{
+  StoreOrRestoreLastPlayedLevels(node, TRUE);
+}
+
+void RestoreLastPlayedLevels(TreeInfo **node)
+{
+  *node = StoreOrRestoreLastPlayedLevels(*node, FALSE);
+}
+
 void LoadLevelSetup_LastSeries(void)
 {
   // --------------------------------------------------------------------------
index baf447946a5a977932dffc66449084e5235808c7..c8c5feccd309922b6bcdc066de190fc7a528e8e6 100644 (file)
@@ -375,6 +375,8 @@ boolean UpdateUserLevelSet(char *, char *, char *, int);
 boolean CreateUserLevelSet(char *, char *, char *, int, boolean);
 
 void UpdateLastPlayedLevels_TreeInfo(void);
+void StoreLastPlayedLevels(TreeInfo *);
+void RestoreLastPlayedLevels(TreeInfo **);
 
 void LoadLevelSetup_LastSeries(void);
 void SaveLevelSetup_LastSeries(void);
index 601c05de45e3ff278c40ea8e637e5d7960caa8ab..464840b6e078a7575f84d36c1958fcb963b4a55d 100644 (file)
@@ -2165,6 +2165,9 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
          SaveLevelSetup_LastSeries();
          SaveLevelSetup_SeriesInfo();
 
+         // restore level set if chosen from "last played level set" menu
+         RestoreLastPlayedLevels(&leveldir_current);
+
          if (setup.internal.choose_from_top_leveldir)
            gotoTopLevelDir();
 
@@ -4855,6 +4858,11 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
 
            HandleMainMenu_SelectLevel(0, 0, new_level_nr);
          }
+         else if (game_status == GAME_MODE_LEVELS)
+         {
+           // store level set if chosen from "last played level set" menu
+           StoreLastPlayedLevels(leveldir_current);
+         }
          else if (game_status == GAME_MODE_NAMES)
          {
            if (mx >= sx1_edit_name && mx <= sx2_edit_name)