added cursor key navigation to title info screens
[rocksndiamonds.git] / src / screens.c
index 3245e4474e97a78c89ab312416431b95784a566c..8e18035e42c84586322715d96d60c9851794cbf7 100644 (file)
@@ -277,10 +277,10 @@ static void DrawInfoScreen_NotAvailable(char *, char *);
 static void DrawInfoScreen_HelpAnim(int, int, boolean);
 static void DrawInfoScreen_HelpText(int, int, int, int);
 static void HandleInfoScreen_Main(int, int, int, int, int);
-static void HandleInfoScreen_TitleScreen(int);
-static void HandleInfoScreen_Elements(int);
-static void HandleInfoScreen_Music(int);
-static void HandleInfoScreen_Credits(int);
+static void HandleInfoScreen_TitleScreen(int, int, int);
+static void HandleInfoScreen_Elements(int, int, int);
+static void HandleInfoScreen_Music(int, int, int);
+static void HandleInfoScreen_Credits(int, int, int);
 static void HandleInfoScreen_Program(int);
 static void HandleInfoScreen_Version(int);
 
@@ -1918,7 +1918,7 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
   {
     return_to_main_menu = TRUE;
   }
-  else if (button == MB_MENU_CHOICE)
+  else if (button == MB_MENU_CHOICE || dx)
   {
     if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
     {
@@ -1931,9 +1931,10 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
       return;
     }
 
-    title_screen_nr++;
+    title_screen_nr +=
+      (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
 
-    if (title_screen_nr < num_title_screens)
+    if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
     {
       tci = &title_controls[title_screen_nr];
 
@@ -3090,9 +3091,9 @@ static void DrawInfoScreen_TitleScreen(void)
   DrawTitleScreen();
 }
 
-void HandleInfoScreen_TitleScreen(int button)
+void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
 {
-  HandleTitleScreen(0, 0, 0, 0, button);
+  HandleTitleScreen(0, 0, dx, dy, button);
 }
 
 static void DrawInfoScreen_Elements(void)
@@ -3104,12 +3105,12 @@ static void DrawInfoScreen_Elements(void)
   LoadHelpAnimInfo();
   LoadHelpTextInfo();
 
-  HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
+  HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
 
   FadeIn(REDRAW_FIELD);
 }
 
-void HandleInfoScreen_Elements(int button)
+void HandleInfoScreen_Elements(int dx, int dy, int button)
 {
   static unsigned int info_delay = 0;
   static int num_anims;
@@ -3148,16 +3149,16 @@ void HandleInfoScreen_Elements(int button)
 
     return;
   }
-  else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
+  else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
   {
     if (button != MB_MENU_INITIALIZE)
     {
       PlaySound(SND_MENU_ITEM_SELECTING);
 
-      page++;
+      page += (dx < 0 ? -1 : +1);
     }
 
-    if (page >= num_pages)
+    if (page < 0 || page >= num_pages)
     {
       FadeMenuSoundsAndMusic();
 
@@ -3167,7 +3168,7 @@ void HandleInfoScreen_Elements(int button)
       return;
     }
 
-    if (page > 0)
+    if (button != MB_MENU_INITIALIZE)
       FadeSetNextScreen();
 
     if (button != MB_MENU_INITIALIZE)
@@ -3199,12 +3200,12 @@ static void DrawInfoScreen_Music(void)
 
   LoadMusicInfo();
 
-  HandleInfoScreen_Music(MB_MENU_INITIALIZE);
+  HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
 
   FadeIn(REDRAW_FIELD);
 }
 
-void HandleInfoScreen_Music(int button)
+void HandleInfoScreen_Music(int dx, int dy, int button)
 {
   static struct MusicFileInfo *list = NULL;
   int font_title = MENU_INFO_FONT_TITLE;
@@ -3250,14 +3251,14 @@ void HandleInfoScreen_Music(int button)
 
     return;
   }
-  else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
+  else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
   {
     if (button != MB_MENU_INITIALIZE)
     {
       PlaySound(SND_MENU_ITEM_SELECTING);
 
       if (list != NULL)
-       list = list->next;
+       list = (dx < 0 ? list->prev : list->next);
     }
 
     if (list == NULL)
@@ -3607,12 +3608,12 @@ static void DrawInfoScreen_Credits(void)
 
   FadeOut(REDRAW_FIELD);
 
-  HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
+  HandleInfoScreen_Credits(0, 0, MB_MENU_INITIALIZE);
 
   FadeIn(REDRAW_FIELD);
 }
 
-void HandleInfoScreen_Credits(int button)
+void HandleInfoScreen_Credits(int dx, int dy, int button)
 {
   static int screen_nr = 0;
   int num_screens = 9;
@@ -3621,10 +3622,9 @@ void HandleInfoScreen_Credits(int button)
   {
     screen_nr = 0;
 
-    // DrawInfoScreen_CreditsScreen(screen_nr);
+    DrawInfoScreen_CreditsScreen(screen_nr);
   }
-
-  if (button == MB_MENU_LEAVE)
+  else if (button == MB_MENU_LEAVE)
   {
     PlaySound(SND_MENU_ITEM_SELECTING);
 
@@ -3633,16 +3633,13 @@ void HandleInfoScreen_Credits(int button)
 
     return;
   }
-  else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
+  else if (button == MB_MENU_CHOICE || dx)
   {
-    if (button != MB_MENU_INITIALIZE)
-    {
-      PlaySound(SND_MENU_ITEM_SELECTING);
+    PlaySound(SND_MENU_ITEM_SELECTING);
 
-      screen_nr++;
-    }
+    screen_nr += (dx < 0 ? -1 : +1);
 
-    if (screen_nr >= num_screens)
+    if (screen_nr < 0 || screen_nr >= num_screens)
     {
       FadeMenuSoundsAndMusic();
 
@@ -3652,16 +3649,13 @@ void HandleInfoScreen_Credits(int button)
       return;
     }
 
-    if (screen_nr > 0)
-      FadeSetNextScreen();
+    FadeSetNextScreen();
 
-    if (button != MB_MENU_INITIALIZE)
-      FadeOut(REDRAW_FIELD);
+    FadeOut(REDRAW_FIELD);
 
     DrawInfoScreen_CreditsScreen(screen_nr);
 
-    if (button != MB_MENU_INITIALIZE)
-      FadeIn(REDRAW_FIELD);
+    FadeIn(REDRAW_FIELD);
   }
   else
   {
@@ -4067,13 +4061,13 @@ static void DrawInfoScreen(void)
 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
 {
   if (info_mode == INFO_MODE_TITLE)
-    HandleInfoScreen_TitleScreen(button);
+    HandleInfoScreen_TitleScreen(dx, dy, button);
   else if (info_mode == INFO_MODE_ELEMENTS)
-    HandleInfoScreen_Elements(button);
+    HandleInfoScreen_Elements(dx, dy, button);
   else if (info_mode == INFO_MODE_MUSIC)
-    HandleInfoScreen_Music(button);
+    HandleInfoScreen_Music(dx, dy, button);
   else if (info_mode == INFO_MODE_CREDITS)
-    HandleInfoScreen_Credits(button);
+    HandleInfoScreen_Credits(dx, dy, button);
   else if (info_mode == INFO_MODE_PROGRAM)
     HandleInfoScreen_Program(button);
   else if (info_mode == INFO_MODE_VERSION)
@@ -4833,6 +4827,8 @@ static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
 static void DrawChooseTree(TreeInfo **ti_ptr)
 {
   int fade_mask = REDRAW_FIELD;
+  boolean restart_music = (game_status != game_status_last_screen &&
+                          game_status_last_screen != GAME_MODE_SCOREINFO);
 
   if (CheckFadeAll())
     fade_mask = REDRAW_ALL;
@@ -4858,7 +4854,7 @@ static void DrawChooseTree(TreeInfo **ti_ptr)
   FreeScreenGadgets();
   CreateScreenGadgets();
 
-  if (game_status != game_status_last_screen)
+  if (restart_music)
     FadeMenuSoundsAndMusic();
 
   FadeOut(fade_mask);
@@ -4889,7 +4885,7 @@ static void DrawChooseTree(TreeInfo **ti_ptr)
 
   DrawMaskedBorder(fade_mask);
 
-  if (game_status != game_status_last_screen)
+  if (restart_music)
     PlayMenuSoundsAndMusic();
 
   FadeIn(fade_mask);
@@ -4941,7 +4937,7 @@ static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
     int border = amSX - SX + getFontDrawOffsetX(font_nr1);
     int dx1 = 0;
     int dx3 = text_size_1;
-    int dx4 = screen_width - startdx - 2 * border - text_size_4;
+    int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
     int num_dots = (dx4 - dx3) / font_size_3;
     int startx1 = startx + dx1;
     int startx3 = startx + dx3;
@@ -5713,7 +5709,9 @@ void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
 
 static void DrawHallOfFame_setScoreEntries(void)
 {
-  int num_visible_score_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1;
+  int max_empty_entries = 10;  // at least show "top ten" list, if empty
+  int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1;   // w/o back link
+  int min_score_entries = MIN(max_empty_entries, max_visible_entries);
   int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
   int i;
 
@@ -5729,7 +5727,7 @@ static void DrawHallOfFame_setScoreEntries(void)
     // do not add empty score entries if off-screen
     if (scores.entry[i].score == 0 &&
        scores.entry[i].time == 0 &&
-       i >= num_visible_score_entries)
+       i >= min_score_entries)
       break;
 
     TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);