changed sound handling to only expire loop sounds during gameplay
[rocksndiamonds.git] / src / screens.c
index de42525a6ab33fc43a651a0c94a4ae00bd7546f3..d6377c1d4254aa70921996e9aa79a2cbab898008 100644 (file)
@@ -725,6 +725,13 @@ static int getTitleMessageGameMode(boolean initial)
   return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
 }
 
+static int getTitleAnimMode(struct TitleControlInfo *tci)
+{
+  int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
+
+  return base + tci->local_nr;
+}
+
 #if 0
 static int getTitleScreenBackground(boolean initial)
 {
@@ -1247,11 +1254,7 @@ static void drawCursorXY(int xpos, int ypos, int graphic)
 
 static void drawChooseTreeCursor(int ypos, boolean active)
 {
-  int last_game_status = game_status;  /* save current game status */
-
   drawCursorExt(0, ypos, active, -1);
-
-  SetGameStatus(last_game_status);     /* restore current game status */
 }
 
 void DrawHeadline()
@@ -1309,13 +1312,12 @@ void DrawTitleScreenMessage(int nr, boolean initial)
 {
   char *filename = getLevelSetTitleMessageFilename(nr, initial);
   struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
-  int last_game_status = game_status;  /* save current game status */
 
   if (filename == NULL)
     return;
 
   /* force TITLE font on title message screen */
-  SetGameStatus(getTitleMessageGameMode(initial));
+  SetFontStatus(getTitleMessageGameMode(initial));
 
   /* if chars *and* width set to "-1", automatically determine width */
   if (tmi->chars == -1 && tmi->width == -1)
@@ -1354,7 +1356,7 @@ void DrawTitleScreenMessage(int nr, boolean initial)
               filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
               tmi->autowrap, tmi->centered, tmi->parse_comments);
 
-  SetGameStatus(last_game_status);     /* restore current game status */
+  ResetFontStatus();
 }
 
 void DrawTitleScreen()
@@ -1398,6 +1400,8 @@ void DrawMainMenu()
   UnmapAllGadgets();
   FadeSoundsAndMusic();
 
+  ExpireSoundLoops(FALSE);
+
   KeyboardAutoRepeatOn();
   ActivateJoystick();
 
@@ -1570,6 +1574,8 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
     title_screen_nr = 0;
     tci = &title_controls[title_screen_nr];
 
+    SetAnimStatus(getTitleAnimMode(tci));
+
     last_sound = SND_UNDEFINED;
     last_music = MUS_UNDEFINED;
 
@@ -1590,7 +1596,6 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
 
        DrawInfoScreen_NotAvailable("Title screen information:",
                                    "No title screen for this level set.");
-
        return;
       }
 
@@ -1651,10 +1656,13 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
     }
 
     title_screen_nr++;
-    tci = &title_controls[title_screen_nr];
 
     if (title_screen_nr < num_title_screens)
     {
+      tci = &title_controls[title_screen_nr];
+
+      SetAnimStatus(getTitleAnimMode(tci));
+
       sound = getTitleSound(tci);
       music = getTitleMusic(tci);
 
@@ -3696,7 +3704,6 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
   int yoffset_setup = 16;
   int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
                 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
-  int last_game_status = game_status;  /* save current game status */
 
   title_string = ti->infotext;
 
@@ -3736,8 +3743,6 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
       initCursor(i, IMG_MENU_BUTTON);
   }
 
-  SetGameStatus(last_game_status);     /* restore current game status */
-
   redraw_mask |= REDRAW_FIELD;
 }
 
@@ -3785,7 +3790,6 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
   int num_entries = numTreeInfoInGroup(ti);
   int num_page_entries;
-  int last_game_status = game_status;  /* save current game status */
   boolean position_set_by_scrollbar = (dx == 999);
 
   if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
@@ -3793,8 +3797,6 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   else
     num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
 
-  SetGameStatus(last_game_status);     /* restore current game status */
-
   if (button == MB_MENU_INITIALIZE)
   {
     int num_entries = numTreeInfoInGroup(ti);
@@ -3878,12 +3880,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
 
   if (mx || my)                /* mouse input */
   {
-    int last_game_status = game_status;        /* save current game status */
-
     x = (mx - mSX) / 32;
     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
-
-    SetGameStatus(last_game_status);   /* restore current game status */
   }
   else if (dx || dy)   /* keyboard or scrollbar/scrollbutton input */
   {
@@ -5616,13 +5614,22 @@ static int getSetupValueFont(int type, void *value)
     return FONT_VALUE_1;
 }
 
+static int getSetupValueFontNarrow(int type, int font_nr)
+{
+  return (font_nr == FONT_VALUE_1    ? FONT_VALUE_NARROW :
+         font_nr == FONT_OPTION_ON  ? FONT_OPTION_ON_NARROW :
+         font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
+         font_nr);
+}
+
 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
 {
   int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
   struct TokenInfo *si = &setup_info[si_pos];
   boolean font_draw_xoffset_modified = FALSE;
+  boolean scrollbar_needed = (num_setup_info < max_setup_info);
   int font_draw_xoffset_old = -1;
-  int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
+  int xoffset = (scrollbar_needed ? -1 : 0);
   int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
   int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
   int xpos = menu_screen_value_xpos;
@@ -5664,6 +5671,26 @@ static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
   font_nr = getSetupValueFont(type, value);
   font_width = getFontWidth(font_nr);
 
+  // special check if right-side setup values moved left due to scrollbar
+  if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
+  {
+    int max_menu_text_length = 26;     // maximum text length for classic menu
+    int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
+    int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
+    int text_font_nr = getMenuTextFont(FONT_MENU_2);
+    int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
+    int text_width = max_menu_text_length * getFontWidth(text_font_nr);
+
+    if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
+    {
+      xpos += 1;
+      startx = mSX + xpos * 32;
+
+      font_nr = getSetupValueFontNarrow(type, font_nr);
+      font_width = getFontWidth(font_nr);
+    }
+  }
+
   /* downward compatibility correction for Juergen Bonhagen's menu settings */
   if (setup_mode != SETUP_MODE_INPUT)
   {
@@ -6906,14 +6933,10 @@ static void CreateScreenScrollbars()
 
 void CreateScreenGadgets()
 {
-  int last_game_status = game_status;  /* save current game status */
-
   CreateScreenMenubuttons();
 
   CreateScreenScrollbuttons();
   CreateScreenScrollbars();
-
-  SetGameStatus(last_game_status);     /* restore current game status */
 }
 
 void FreeScreenGadgets()