changed sorting and coloring in level sets and custom artwork menu
authorHolger Schemel <info@artsoft.org>
Wed, 10 Feb 2021 00:34:50 +0000 (01:34 +0100)
committerHolger Schemel <info@artsoft.org>
Wed, 10 Feb 2021 02:05:37 +0000 (03:05 +0100)
src/libgame/setup.c
src/libgame/setup.h
src/libgame/system.h
src/screens.c

index f85738a1fa71d0ce23bd4768dec23a4b2fc5ee58..90fb933af54d225dfc670d131af85d5fe7595bf7 100644 (file)
@@ -2858,34 +2858,13 @@ static int compareTreeInfoEntries(const void *object1, const void *object2)
 {
   const TreeInfo *entry1 = *((TreeInfo **)object1);
   const TreeInfo *entry2 = *((TreeInfo **)object2);
-  int class_sorting1 = 0, class_sorting2 = 0;
-  int compare_result;
+  int tree_sorting1 = TREE_SORTING(entry1);
+  int tree_sorting2 = TREE_SORTING(entry2);
 
-  if (entry1->type == TREE_TYPE_LEVEL_DIR)
-  {
-    class_sorting1 = LEVELSORTING(entry1);
-    class_sorting2 = LEVELSORTING(entry2);
-  }
-  else if (entry1->type == TREE_TYPE_GRAPHICS_DIR ||
-          entry1->type == TREE_TYPE_SOUNDS_DIR ||
-          entry1->type == TREE_TYPE_MUSIC_DIR)
-  {
-    class_sorting1 = ARTWORKSORTING(entry1);
-    class_sorting2 = ARTWORKSORTING(entry2);
-  }
-
-  if (entry1->parent_link || entry2->parent_link)
-    compare_result = (entry1->parent_link ? -1 : +1);
-  else if (entry1->level_group != entry2->level_group)
-    compare_result = (entry1->level_group ? -1 : +1);
-  else if (entry1->sort_priority == entry2->sort_priority)
-    compare_result = strcasecmp(entry1->name_sorting, entry2->name_sorting);
-  else if (class_sorting1 == class_sorting2)
-    compare_result = entry1->sort_priority - entry2->sort_priority;
+  if (tree_sorting1 != tree_sorting2)
+    return (tree_sorting1 - tree_sorting2);
   else
-    compare_result = class_sorting1 - class_sorting2;
-
-  return compare_result;
+    return strcasecmp(entry1->name_sorting, entry2->name_sorting);
 }
 
 static TreeInfo *createParentTreeInfoNode(TreeInfo *node_parent)
index 7877ccb23246ce42c5fff8d6ba508239359c0144..2f5489d9e482604a845dcca8889923b15cdf0056 100644 (file)
@@ -227,6 +227,28 @@ typedef struct hashtable     SetupFileHash;
                         IS_ARTWORKCLASS_LEVEL(n) ? ARTWORKCLASS_LEVEL :      \
                         ARTWORKCLASS_UNDEFINED)
 
+#define TREE_SORTING_DIR(ti)                                           \
+       (((ti)->parent_link                                     ? 0 :   \
+         (ti)->in_user_dir                                     ? 8 :   \
+         (ti)->sort_priority >= LEVELCLASS_CLASSICS_START      ? 6 :   \
+         (ti)->sort_priority >= LEVELCLASS_TUTORIAL_START      ? 4 :   \
+         2) +                                                          \
+        ((ti)->level_group ? 0 : 1))
+
+#define TREE_COLOR_DIR(ti, active)                                     \
+       ((active)                       ? FC_YELLOW :                   \
+        TREE_SORTING(ti) / 2 == 4      ? FC_GREEN :                    \
+        TREE_SORTING(ti) / 2 == 2      ? FC_BLUE :                     \
+        FC_RED)
+
+#define TREE_SORTING(ti)                                               \
+       (TREE_TYPE_IS_DIR((ti)->type) ? TREE_SORTING_DIR(ti) :          \
+        (ti)->sort_priority)
+
+#define TREE_COLOR(ti, active)                                         \
+       (TREE_TYPE_IS_DIR((ti)->type) ? TREE_COLOR_DIR(ti, active) :    \
+        (ti)->color)
+
 
 char *getUserGraphicsDir(void);
 char *getUserSoundsDir(void);
index f5b2967e5ffc5345b042c15a29fe5ac7e713422c..9b3dfe752f127bb1b41ace4bd0005cbba18823bf 100644 (file)
 #define NUM_BASE_TREE_TYPES    4
 #define NUM_TREE_TYPES         6
 
+#define TREE_TYPE_IS_DIR(type) ((type) == TREE_TYPE_GRAPHICS_DIR ||    \
+                                (type) == TREE_TYPE_SOUNDS_DIR ||      \
+                                (type) == TREE_TYPE_MUSIC_DIR ||       \
+                                (type) == TREE_TYPE_LEVEL_DIR)
+
 #define INFOTEXT_UNDEFINED     ""
 #define INFOTEXT_GRAPHICS_DIR  "Custom Graphics"
 #define INFOTEXT_SOUNDS_DIR    "Custom Sounds"
index dbac21b31e47d8625abb9f940bf84b7d12139bdc..81a54b064ca2fbe7f52a214172f2b9d643409ca3 100644 (file)
 // other screen text constants
 #define STR_CHOOSE_TREE_EDIT           "Edit"
 #define MENU_CHOOSE_TREE_FONT(x)       (FONT_TEXT_1 + (x))
+#define MENU_CHOOSE_TREE_COLOR(ti, a)  TREE_COLOR(ti, a)
 
 // for input setup functions
 #define SETUPINPUT_SCREEN_POS_START    0
@@ -4408,9 +4409,8 @@ static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
   int entry_pos = first_entry + y;
   TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
   TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
-  int node_color = (node->color == FC_YELLOW ? FC_GREEN : node->color);
-  int color = (active ? FC_YELLOW : node_color);
-  int font_nr = MENU_CHOOSE_TREE_FONT(color);
+  int font_color = MENU_CHOOSE_TREE_COLOR(node, active);
+  int font_nr = MENU_CHOOSE_TREE_FONT(font_color);
   int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
   int xpos = MENU_SCREEN_START_XPOS;
   int ypos = MENU_SCREEN_START_YPOS + y;