From: Holger Schemel Date: Sat, 27 Feb 2021 19:22:37 +0000 (+0100) Subject: re-enabled storing selection from "last played level set" menu X-Git-Tag: 4.2.3.1~1 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=3bb225da5092d0741870829d9f8f8642070d29c5;p=rocksndiamonds.git re-enabled storing selection from "last played level set" menu --- diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 9c21b95a..32ae1121 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -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) { // -------------------------------------------------------------------------- diff --git a/src/libgame/setup.h b/src/libgame/setup.h index baf44794..c8c5fecc 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -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); diff --git a/src/screens.c b/src/screens.c index 601c05de..464840b6 100644 --- a/src/screens.c +++ b/src/screens.c @@ -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)