From: Holger Schemel Date: Thu, 25 Feb 2021 18:55:50 +0000 (+0100) Subject: fixed problems with current level set node being a tree node copy X-Git-Tag: 4.2.3.1~4 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=483d088f2bd4dd2ee267aff416503b2c667a69d3;p=rocksndiamonds.git fixed problems with current level set node being a tree node copy When selecting the current level set from the "last played level sets" sub-menu, using the corresponding tree node from this sub-tree instead of the "original" tree node of that level set may cause a number of problems: When using a level template stored in the parent level set directory, it will not be detected as there is no corresponding parent tree node if a tree node from the "last played level sets" sub-tree is used. When toggling between the "original" tree node and the node copy from the "last played level sets" sub-tree, custom artwork will always be reloaded, as the level set tree node is treated as "has changed". This change fixes these problems by always making sure that the "original" tree node is used after selecting a new level set, but causes the level set selection menu to always start with the "original" tree node, even if the last level set selection was made from the "last played level sets" menu. --- diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 581aac21..ed349743 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -1154,7 +1154,21 @@ int numTreeInfo(TreeInfo *node) boolean validLevelSeries(TreeInfo *node) { - return (node != NULL && !node->node_group && !node->parent_link); + // in a number of cases, tree node is no valid level set + if (node == NULL || node->node_group || node->parent_link || node->is_copy) + return FALSE; + + return TRUE; +} + +TreeInfo *getValidLevelSeries(TreeInfo *node, TreeInfo *default_node) +{ + if (validLevelSeries(node)) + return node; + else if (node->is_copy) + return getTreeInfoFromIdentifier(leveldir_first, node->identifier); + else + return getFirstValidTreeInfoEntry(default_node); } TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *node) @@ -1244,7 +1258,7 @@ static TreeInfo *getTreeInfoFromIdentifierExt(TreeInfo *node, char *identifier, if (node_group) return node_group; } - else if (!node->parent_link) + else if (!node->parent_link && !node->is_copy) { if (strEqual(identifier, node->identifier)) return node; diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 2d290b80..baf44794 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -294,6 +294,7 @@ void pushTreeInfo(TreeInfo **, TreeInfo *); void removeTreeInfo(TreeInfo **); int numTreeInfo(TreeInfo *); boolean validLevelSeries(TreeInfo *); +TreeInfo *getValidLevelSeries(TreeInfo *, TreeInfo *); TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *); TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *); int numTreeInfoInGroup(TreeInfo *); diff --git a/src/screens.c b/src/screens.c index c82f2a96..601c05de 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1630,9 +1630,8 @@ void DrawMainMenu(void) return; } - // leveldir_current may be invalid (level group, parent link) - if (!validLevelSeries(leveldir_current)) - leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid); + // leveldir_current may be invalid (level group, parent link, node copy) + leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid); if (leveldir_current != leveldir_last_valid) {