fixed bug with restarting same menu music on different screens
[rocksndiamonds.git] / src / screens.c
index 66f863cce57fc97b3f99b4cc63bf69f52f7d5174..6e26fdf55e4f75e1c8b57b4349269ce1b691191c 100644 (file)
@@ -383,6 +383,7 @@ static struct
 {
   {    TOUCH_CONTROL_VIRTUAL_BUTTONS,  "Virtual Buttons"       },
   {    TOUCH_CONTROL_WIPE_GESTURES,    "Wipe Gestures"         },
+  {    TOUCH_CONTROL_FOLLOW_FINGER,    "Follow Finger"         },
 
   {    NULL,                           NULL                    },
 };
@@ -1184,6 +1185,17 @@ static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
          y >= rect_y && y < rect_y + rect->height);
 }
 
+static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
+{
+  int rect_width  = preview->xsize * preview->tile_size;
+  int rect_height = preview->ysize * preview->tile_size;
+  int rect_x = ALIGNED_XPOS(preview->x, rect_width,  preview->align);
+  int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
+
+  return (x >= rect_x && x < rect_x + rect_width &&
+         y >= rect_y && y < rect_y + rect_height);
+}
+
 static void AdjustScrollbar(int id, int items_max, int items_visible,
                            int item_position)
 {
@@ -1396,7 +1408,7 @@ void DrawMainMenu()
   /* do not fade out here -- function may continue and fade on editor screen */
 
   UnmapAllGadgets();
-  FadeSoundsAndMusic();
+  FadeMenuSoundsAndMusic();
 
   ExpireSoundLoops(FALSE);
 
@@ -1440,8 +1452,6 @@ void DrawMainMenu()
 
   if (CheckTitleScreen(levelset_has_changed))
   {
-    game_status_last_screen = GAME_MODE_MAIN;
-
     SetGameStatus(GAME_MODE_TITLE);
 
     DrawTitleScreen();
@@ -1494,8 +1504,7 @@ void DrawMainMenu()
     LoadTape(level_nr);
   DrawCompleteVideoDisplay();
 
-  PlayMenuSound();
-  PlayMenuMusic();
+  PlayMenuSoundsAndMusic();
 
   /* create gadgets for main menu screen */
   FreeScreenGadgets();
@@ -1590,12 +1599,15 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
        /* switch game mode from title screen mode back to info screen mode */
        SetGameStatus(GAME_MODE_INFO);
 
+       /* store that last screen was info screen, not main menu screen */
+       game_status_last_screen = GAME_MODE_INFO;
+
        DrawInfoScreen_NotAvailable("Title screen information:",
                                    "No title screen for this level set.");
        return;
       }
 
-      FadeSoundsAndMusic();
+      FadeMenuSoundsAndMusic();
     }
 
     FadeOut(REDRAW_ALL);
@@ -1693,7 +1705,7 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
     }
     else
     {
-      FadeSoundsAndMusic();
+      FadeMenuSoundsAndMusic();
 
       return_to_main_menu = TRUE;
     }
@@ -1807,6 +1819,10 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
       }
     }
 
+    /* check if level preview was clicked */
+    if (insidePreviewRect(&preview, mx - SX, my - SY))
+      pos = MAIN_CONTROL_GAME;
+
     // handle pressed/unpressed state for active/inactive menu buttons
     // (if pos != -1, "i" contains index position corresponding to "pos")
     if (button &&
@@ -2144,7 +2160,7 @@ static void DrawInfoScreen_Main()
     fade_mask = REDRAW_ALL;
 
   UnmapAllGadgets();
-  FadeSoundsAndMusic();
+  FadeMenuSoundsAndMusic();
 
   FreeScreenGadgets();
   CreateScreenGadgets();
@@ -2183,8 +2199,7 @@ static void DrawInfoScreen_Main()
 
   MapScreenGadgets(max_info_info);
 
-  PlayMenuSound();
-  PlayMenuMusic();
+  PlayMenuSoundsAndMusic();
 
   DrawMaskedBorder(fade_mask);
 
@@ -2662,8 +2677,6 @@ void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
 
 void DrawInfoScreen_TitleScreen()
 {
-  game_status_last_screen = GAME_MODE_INFO;
-
   SetGameStatus(GAME_MODE_TITLE);
 
   DrawTitleScreen();
@@ -2738,7 +2751,7 @@ void HandleInfoScreen_Elements(int button)
 
     if (page >= num_pages)
     {
-      FadeSoundsAndMusic();
+      FadeMenuSoundsAndMusic();
 
       info_mode = INFO_MODE_MAIN;
       DrawInfoScreen();
@@ -2797,7 +2810,7 @@ void HandleInfoScreen_Music(int button)
 
     if (list == NULL)
     {
-      FadeSoundsAndMusic();
+      FadeMenuSoundsAndMusic();
 
       ClearField();
       DrawHeadline();
@@ -2816,7 +2829,7 @@ void HandleInfoScreen_Music(int button)
   {
     PlaySound(SND_MENU_ITEM_SELECTING);
 
-    FadeSoundsAndMusic();
+    FadeMenuSoundsAndMusic();
 
     info_mode = INFO_MODE_MAIN;
     DrawInfoScreen();
@@ -2837,7 +2850,7 @@ void HandleInfoScreen_Music(int button)
 
     if (list == NULL)
     {
-      FadeSoundsAndMusic();
+      FadeMenuSoundsAndMusic();
 
       info_mode = INFO_MODE_MAIN;
       DrawInfoScreen();
@@ -2845,7 +2858,7 @@ void HandleInfoScreen_Music(int button)
       return;
     }
 
-    FadeSoundsAndMusic();
+    FadeMenuSoundsAndMusic();
 
     if (list != music_file_info)
       FadeSetNextScreen();
@@ -3100,7 +3113,7 @@ void DrawInfoScreen_Credits()
 {
   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
 
-  FadeSoundsAndMusic();
+  FadeMenuSoundsAndMusic();
 
   FadeOut(REDRAW_FIELD);
 
@@ -3141,7 +3154,7 @@ void HandleInfoScreen_Credits(int button)
 
     if (screen_nr >= num_screens)
     {
-      FadeSoundsAndMusic();
+      FadeMenuSoundsAndMusic();
 
       info_mode = INFO_MODE_MAIN;
       DrawInfoScreen();
@@ -3220,7 +3233,7 @@ void HandleInfoScreen_Program(int button)
   {
     PlaySound(SND_MENU_ITEM_SELECTING);
 
-    FadeSoundsAndMusic();
+    FadeMenuSoundsAndMusic();
 
     info_mode = INFO_MODE_MAIN;
     DrawInfoScreen();
@@ -3395,7 +3408,7 @@ void HandleInfoScreen_Version(int button)
   {
     PlaySound(SND_MENU_ITEM_SELECTING);
 
-    FadeSoundsAndMusic();
+    FadeMenuSoundsAndMusic();
 
     info_mode = INFO_MODE_MAIN;
     DrawInfoScreen();
@@ -3483,7 +3496,7 @@ void HandleInfoScreen_LevelSet(int button)
   {
     PlaySound(SND_MENU_ITEM_SELECTING);
 
-    FadeSoundsAndMusic();
+    FadeMenuSoundsAndMusic();
 
     info_mode = INFO_MODE_MAIN;
     DrawInfoScreen();
@@ -3516,10 +3529,7 @@ static void DrawInfoScreen()
   if (info_mode != INFO_MODE_MAIN &&
       info_mode != INFO_MODE_TITLE &&
       info_mode != INFO_MODE_MUSIC)
-  {
-    PlayMenuSound();
-    PlayMenuMusic();
-  }
+    PlayMenuSoundsAndMusic();
 }
 
 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
@@ -3570,9 +3580,7 @@ void HandleTypeName(int newxpos, Key key)
 
     xpos = newxpos;
 
-#if defined(TARGET_SDL2)
-    SDL_StartTextInput();
-#endif
+    StartTextInput(startx, starty, pos->width, pos->height);
   }
   else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
   {
@@ -3619,9 +3627,7 @@ void HandleTypeName(int newxpos, Key key)
 
     DrawText(startx, starty, setup.player_name, font_nr);
 
-#if defined(TARGET_SDL2)
-    SDL_StopTextInput();
-#endif
+    StopTextInput();
   }
 }
 
@@ -3656,10 +3662,11 @@ static void DrawChooseTree(TreeInfo **ti_ptr)
   /* needed if different viewport properties defined for choosing level (set) */
   ChangeViewportPropertiesIfNeeded();
 
-  SetMainBackgroundImage(game_status == GAME_MODE_LEVELNR ?
-                        IMG_BACKGROUND_LEVELNR :
-                        game_status == GAME_MODE_LEVELS ?
-                        IMG_BACKGROUND_LEVELS : IMG_BACKGROUND);
+  if (game_status == GAME_MODE_LEVELNR)
+    SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
+  else if (game_status == GAME_MODE_LEVELS)
+    SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
+
   ClearField();
 
   OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
@@ -4052,12 +4059,11 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
 
 void DrawChooseLevelSet()
 {
-  FadeSoundsAndMusic();
+  FadeMenuSoundsAndMusic();
 
   DrawChooseTree(&leveldir_current);
 
-  PlayMenuSound();
-  PlayMenuMusic();
+  PlayMenuSoundsAndMusic();
 }
 
 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
@@ -4069,7 +4075,7 @@ void DrawChooseLevelNr()
 {
   int i;
 
-  FadeSoundsAndMusic();
+  FadeMenuSoundsAndMusic();
 
   if (level_number != NULL)
   {
@@ -4117,8 +4123,7 @@ void DrawChooseLevelNr()
 
   DrawChooseTree(&level_number_current);
 
-  PlayMenuSound();
-  PlayMenuMusic();
+  PlayMenuSoundsAndMusic();
 }
 
 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
@@ -4134,7 +4139,7 @@ void DrawHallOfFame(int highlight_position)
     fade_mask = REDRAW_ALL;
 
   UnmapAllGadgets();
-  FadeSoundsAndMusic();
+  FadeMenuSoundsAndMusic();
 
   /* (this is needed when called from GameEnd() after winning a game) */
   KeyboardAutoRepeatOn();
@@ -4154,8 +4159,7 @@ void DrawHallOfFame(int highlight_position)
   /* needed if different viewport properties defined for scores */
   ChangeViewportPropertiesIfNeeded();
 
-  PlayMenuSound();
-  PlayMenuMusic();
+  PlayMenuSoundsAndMusic();
 
   OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
 
@@ -5413,6 +5417,16 @@ static struct TokenInfo setup_info_input[] =
 };
 
 static struct TokenInfo setup_info_touch[] =
+{
+  { TYPE_ENTER_LIST,   execSetupChooseTouchControls, "Touch Control Type:" },
+  { TYPE_STRING,       &touch_controls_text,   ""                      },
+  { TYPE_EMPTY,                NULL,                   ""                      },
+  { TYPE_LEAVE_MENU,   execSetupMain,          "Back"                  },
+
+  { 0,                 NULL,                   NULL                    }
+};
+
+static struct TokenInfo setup_info_touch_wipe_gestures[] =
 {
   { TYPE_ENTER_LIST,   execSetupChooseTouchControls, "Touch Control Type:" },
   { TYPE_STRING,       &touch_controls_text,   ""                      },
@@ -5759,7 +5773,7 @@ static void DrawSetupScreen_Generic()
     fade_mask = REDRAW_ALL;
 
   UnmapAllGadgets();
-  FadeSoundsAndMusic();
+  FadeMenuSoundsAndMusic();
 
   FreeScreenGadgets();
   CreateScreenGadgets();
@@ -5812,6 +5826,9 @@ static void DrawSetupScreen_Generic()
   {
     setup_info = setup_info_touch;
     title_string = "Setup Touch Ctrls";
+
+    if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
+      setup_info = setup_info_touch_wipe_gestures;
   }
   else if (setup_mode == SETUP_MODE_SHORTCUTS)
   {
@@ -6513,8 +6530,7 @@ void DrawSetupScreen()
   else
     DrawSetupScreen_Generic();
 
-  PlayMenuSound();
-  PlayMenuMusic();
+  PlayMenuSoundsAndMusic();
 }
 
 void RedrawSetupScreenAfterFullscreenToggle()