changed custom artwork list to tree structure similar to level sets
authorHolger Schemel <info@artsoft.org>
Sat, 30 Jan 2021 19:59:17 +0000 (20:59 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Jan 2021 19:59:17 +0000 (20:59 +0100)
Before, all available custom artwork sets were presented as a long
list in the "custom artwork" setup menu. Now, all custom artwork
sets that are part of level sets (including pseudo level sets that
only contain custom artwork) are presented as a tree structure
similar to the level set selection menu, so it is much easier now
to find a custom artwork set related to a level set.

src/libgame/setup.c
src/screens.c

index 5a1b6c7d310f2d00cb07ec954460c9c8c47929fc..aca52f7db36ab9fa5ffea8c302a6428d0dfb76e4 100644 (file)
@@ -3914,6 +3914,7 @@ void LoadArtworkInfo(void)
 }
 
 static void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
+                                        ArtworkDirTree *node_parent,
                                         LevelDirTree *level_node)
 {
   int type = (*artwork_node)->type;
@@ -3963,7 +3964,38 @@ static void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
     DrawInitText(level_node->name, 150, FC_YELLOW);
 
     if (level_node->node_group != NULL)
-      LoadArtworkInfoFromLevelInfo(artwork_node, level_node->node_group);
+    {
+      TreeInfo *artwork_new = newTreeInfo();
+
+      if (node_parent)
+       setTreeInfoToDefaultsFromParent(artwork_new, node_parent);
+      else
+       setTreeInfoToDefaults(artwork_new, type);
+
+      artwork_new->level_group = TRUE;
+
+      setString(&artwork_new->identifier,   level_node->subdir);
+      setString(&artwork_new->name,         level_node->name);
+      setString(&artwork_new->name_sorting, level_node->name_sorting);
+
+      pushTreeInfo(artwork_node, artwork_new);
+
+      // create node to link back to current custom artwork directory
+      createParentTreeInfoNode(artwork_new);
+
+      // recursively step into sub-directory and look for more custom artwork
+      LoadArtworkInfoFromLevelInfo(&artwork_new->node_group, artwork_new,
+                                  level_node->node_group);
+
+      // if sub-tree has no custom artwork at all, remove it
+      if (artwork_new->node_group->next == NULL)
+      {
+       *artwork_node = artwork_new->next;
+       artwork_new->next = NULL;
+
+       freeTreeInfo(artwork_new);
+      }
+    }
 
     level_node = level_node->next;
   }
@@ -3977,11 +4009,11 @@ void LoadLevelArtworkInfo(void)
 
   print_timestamp_time("DrawTimeText");
 
-  LoadArtworkInfoFromLevelInfo(&artwork.gfx_first, leveldir_first_all);
+  LoadArtworkInfoFromLevelInfo(&artwork.gfx_first, NULL, leveldir_first_all);
   print_timestamp_time("LoadArtworkInfoFromLevelInfo (gfx)");
-  LoadArtworkInfoFromLevelInfo(&artwork.snd_first, leveldir_first_all);
+  LoadArtworkInfoFromLevelInfo(&artwork.snd_first, NULL, leveldir_first_all);
   print_timestamp_time("LoadArtworkInfoFromLevelInfo (snd)");
-  LoadArtworkInfoFromLevelInfo(&artwork.mus_first, leveldir_first_all);
+  LoadArtworkInfoFromLevelInfo(&artwork.mus_first, NULL, leveldir_first_all);
   print_timestamp_time("LoadArtworkInfoFromLevelInfo (mus)");
 
   SaveArtworkInfoCache();
index c5df369492548058483daf229319530122f8842f..a716f5eaf7d1941623ed04d66823ff637cbe8774 100644 (file)
@@ -6329,6 +6329,23 @@ static void execSetupTouch(void)
 
 static void execSetupArtwork(void)
 {
+  static ArtworkDirTree *gfx_last_valid = NULL;
+  static ArtworkDirTree *snd_last_valid = NULL;
+  static ArtworkDirTree *mus_last_valid = NULL;
+
+  // current artwork directory may be invalid (level group, parent link)
+  if (!validLevelSeries(artwork.gfx_current))
+    artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
+  if (!validLevelSeries(artwork.snd_current))
+    artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
+  if (!validLevelSeries(artwork.mus_current))
+    artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
+
+  // store valid artwork directory information
+  gfx_last_valid = artwork.gfx_current;
+  snd_last_valid = artwork.snd_current;
+  mus_last_valid = artwork.mus_current;
+
 #if 0
   Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
        artwork.gfx_current->subdir,