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 9c21b95..32ae112 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 baf4479..c8c5fec 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 601c05d..464840b 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)