fixed bug with not unmapping gadgets from previous screen on score info
[rocksndiamonds.git] / src / screens.c
index 4156383e3a640604f7ff9ede5deb3e4af483b2d1..b5cef16637aba7a2cee5e1428b95cc5609d06fea 100644 (file)
@@ -262,6 +262,7 @@ static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
 static void DrawChoosePlayerName(void);
 static void DrawChooseLevelSet(void);
 static void DrawChooseLevelNr(void);
+static void DrawScoreInfo(int);
 static void DrawInfoScreen(void);
 static void DrawSetupScreen(void);
 static void DrawTypeName(void);
@@ -5144,6 +5145,9 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   int num_entries = numTreeInfoInGroup(ti);
   int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
   boolean position_set_by_scrollbar = (dx == 999);
+  boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
+  boolean button_is_valid = (mx >= 0 && my >= 0);
+  boolean button_screen_clicked = (button_action && button_is_valid);
 
   if (game_status == GAME_MODE_SCORES)
   {
@@ -5171,7 +5175,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       {
        drawChooseTreeScreen_Scores_NotAvailable();
       }
-      else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
+      else if (button_screen_clicked)
       {
        PlaySound(SND_MENU_ITEM_SELECTING);
 
@@ -5563,6 +5567,14 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
                               level.random_seed);
              return;
            }
+           else
+           {
+             SetGameStatus(GAME_MODE_SCOREINFO);
+
+             DrawScoreInfo(node_cursor->pos);
+
+             return;
+           }
          }
 
          SetGameStatus(GAME_MODE_MAIN);
@@ -5795,7 +5807,7 @@ static char *getHallOfFameScoreText(int nr)
 
 static void HandleHallOfFame_SelectLevel(int step, int direction)
 {
-  int old_level_nr = level_nr;
+  int old_level_nr = scores.last_level_nr;
   int new_level_nr = old_level_nr + step * direction;
 
   if (new_level_nr < leveldir_current->first_level)
@@ -5836,6 +5848,88 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
   HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
 }
 
+static void DrawScoreInfo(int pos)
+{
+  struct ScoreEntry *entry = &scores.entry[pos];
+  int font_title = MENU_INFO_FONT_TITLE;
+  int font_head  = MENU_INFO_FONT_HEAD;
+  int font_text  = MENU_INFO_FONT_TEXT;
+  int font_foot  = MENU_INFO_FONT_FOOT;
+  int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
+  int spacing_para  = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
+  int spacing_line  = menu.line_spacing[GAME_MODE_SCOREINFO];
+  int xstep = getFontWidth(font_text);
+  int ystep_title = getMenuTextStep(spacing_title, font_title);
+  int ystep_para  = getMenuTextStep(spacing_para,  font_text);
+  int ystep_line  = getMenuTextStep(spacing_line,  font_text);
+  int ystart  = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
+  int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
+  int xstart1 = mSX - SX + 2 * xstep;
+  int xstart2 = mSX - SX + 14 * xstep;
+
+  SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
+
+  UnmapAllGadgets();
+
+  FadeOut(REDRAW_FIELD);
+
+  ClearField();
+
+  drawChooseTreeHead(score_entries);
+  drawChooseTreeInfo(score_entries);
+
+  DrawTextSCentered(ystart, font_title, "Score Information:");
+  ystart += ystep_title;
+
+  DrawTextF(xstart1, ystart, font_head, "Level Set");
+  DrawTextF(xstart2, ystart, font_text, leveldir_current->name);
+  ystart += ystep_line;
+
+  DrawTextF(xstart1, ystart, font_head, "Level Name");
+  DrawTextF(xstart2, ystart, font_text, level.name);
+  ystart += ystep_para;
+
+  DrawTextF(xstart1, ystart, font_head, "Player");
+  DrawTextF(xstart2, ystart, font_text, entry->name);
+  ystart += ystep_line;
+
+  if (level.use_step_counter)
+  {
+    DrawTextF(xstart1, ystart, font_head, "Steps");
+    DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
+    ystart += ystep_line;
+  }
+  else
+  {
+    DrawTextF(xstart1, ystart, font_head, "Time");
+    DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(pos));
+    ystart += ystep_line;
+  }
+
+  if (!level.rate_time_over_score || entry->score > 0)
+  {
+    DrawTextF(xstart1, ystart, font_head, "Score");
+    DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
+    ystart += ystep_line;
+  }
+
+  DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
+
+  FadeIn(REDRAW_FIELD);
+}
+
+void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
+{
+  if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
+  {
+    PlaySound(SND_MENU_ITEM_SELECTING);
+
+    SetGameStatus(GAME_MODE_SCORES);
+
+    DrawHallOfFame(level_nr);
+  }
+}
+
 
 // ============================================================================
 // setup screen functions