added highlighting color when navigating tree info nodes
[rocksndiamonds.git] / src / screens.c
index 36125cd573a898de20f0abc1ce7b2a977f8df5ce..dbac21b31e47d8625abb9f940bf84b7d12139bdc 100644 (file)
@@ -4398,13 +4398,39 @@ static void DrawChooseTree(TreeInfo **ti_ptr)
   FadeIn(fade_mask);
 }
 
-static void drawChooseTreeList(int first_entry, int num_page_entries,
-                              TreeInfo *ti)
+static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
 {
   int num_entries = numTreeInfoInGroup(ti);
   boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
   int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
   int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
+  int first_entry = ti->cl_first;
+  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_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
+  int xpos = MENU_SCREEN_START_XPOS;
+  int ypos = MENU_SCREEN_START_YPOS + y;
+  int startx = amSX + xpos * 32;
+  int starty = amSY + ypos * 32;
+  int startx_text = startx + font_xoffset;
+  int endx_text = amSX + screen_width;
+  int max_text_size = endx_text - startx_text;
+  int max_buffer_len = max_text_size / getFontWidth(font_nr);
+  char buffer[max_buffer_len + 1];
+
+  strncpy(buffer, node->name, max_buffer_len);
+  buffer[max_buffer_len] = '\0';
+
+  DrawText(startx, starty, buffer, font_nr);
+}
+
+static void drawChooseTreeList(int first_entry, int num_page_entries,
+                              TreeInfo *ti)
+{
   int i;
   char *title_string = NULL;
   int yoffset_sets = MENU_TITLE1_YPOS;
@@ -4426,22 +4452,7 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
     node_first = getTreeInfoFirstGroupEntry(ti);
     node = getTreeInfoFromPos(node_first, entry_pos);
 
-    int font_nr = MENU_CHOOSE_TREE_FONT(node->color);
-    int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
-    int xpos = MENU_SCREEN_START_XPOS;
-    int ypos = MENU_SCREEN_START_YPOS + i;
-    int startx = amSX + xpos * 32;
-    int starty = amSY + ypos * 32;
-    int startx_text = startx + font_xoffset;
-    int endx_text = amSX + screen_width;
-    int max_text_size = endx_text - startx_text;
-    int max_buffer_len = max_text_size / getFontWidth(font_nr);
-    char buffer[max_buffer_len + 1];
-
-    strncpy(buffer, node->name, max_buffer_len);
-    buffer[max_buffer_len] = '\0';
-
-    DrawText(startx, starty, buffer, font_nr);
+    drawChooseTreeText(i, FALSE, ti);
 
     if (node->parent_link)
       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
@@ -4492,6 +4503,12 @@ static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
     MarkTileDirty(x, 1);
 }
 
+static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
+{
+  drawChooseTreeCursor(y, active);
+  drawChooseTreeText(y, active, ti);
+}
+
 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
                             TreeInfo **ti_ptr)
 {
@@ -4539,7 +4556,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
 
     drawChooseTreeList(ti->cl_first, num_page_entries, ti);
     drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
-    drawChooseTreeCursor(ti->cl_cursor, TRUE);
+    drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
 
     return;
   }
@@ -4649,7 +4666,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       {
        drawChooseTreeList(ti->cl_first, num_page_entries, ti);
        drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
-       drawChooseTreeCursor(ti->cl_cursor, TRUE);
+       drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
 
        AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
                                  ti->cl_first, ti);
@@ -4713,8 +4730,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       {
        PlaySound(SND_MENU_ITEM_ACTIVATING);
 
-       drawChooseTreeCursor(ti->cl_cursor, FALSE);
-       drawChooseTreeCursor(y, TRUE);
+       drawChooseTreeCursorAndText(ti->cl_cursor, FALSE, ti);
+       drawChooseTreeCursorAndText(y, TRUE, ti);
        drawChooseTreeInfo(ti->cl_first + y, ti);
 
        ti->cl_cursor = y;