rnd-20060506-1-src
[rocksndiamonds.git] / src / screens.c
index 6f0208de91732e8b3a37df2b4c1a359a25a81eb1..031d7f6e09b658997fe99e4cbf076f84f222d564 100644 (file)
 
 /* screens on the info screen */
 #define INFO_MODE_MAIN                 0
-#define INFO_MODE_ELEMENTS             1
-#define INFO_MODE_MUSIC                        2
-#define INFO_MODE_CREDITS              3
-#define INFO_MODE_PROGRAM              4
-#define INFO_MODE_LEVELSET             5
+#define INFO_MODE_TITLESCREEN          1
+#define INFO_MODE_ELEMENTS             2
+#define INFO_MODE_MUSIC                        3
+#define INFO_MODE_CREDITS              4
+#define INFO_MODE_PROGRAM              5
+#define INFO_MODE_LEVELSET             6
 
-#define MAX_INFO_MODES                 6
+#define MAX_INFO_MODES                 7
 
 /* for various menu stuff  */
 #define MENU_SCREEN_START_XPOS         1
@@ -115,9 +116,11 @@ static void DrawChooseLevel(void);
 static void DrawInfoScreen(void);
 static void DrawSetupScreen(void);
 
+static void DrawInfoScreenExt(int);
 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);
@@ -201,40 +204,6 @@ static void drawChooseTreeCursor(int ypos, int color)
   game_status = last_game_status;      /* restore current game status */
 }
 
-static void PlayMenuSound()
-{
-  int sound = menu.sound[game_status];
-
-  if (sound == SND_UNDEFINED)
-    return;
-
-  if (sound_info[sound].loop)
-    PlaySoundLoop(sound);
-  else
-    PlaySound(sound);
-}
-
-static void PlayMenuSoundIfLoop()
-{
-  int sound = menu.sound[game_status];
-
-  if (sound == SND_UNDEFINED)
-    return;
-
-  if (sound_info[sound].loop)
-    PlaySoundLoop(sound);
-}
-
-static void PlayMenuMusic()
-{
-  int music = menu.music[game_status];
-
-  if (music == MUS_UNDEFINED)
-    return;
-
-  PlayMusic(music);
-}
-
 void DrawHeadline()
 {
   DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
@@ -299,12 +268,14 @@ void DrawTitleScreenImage(int nr)
 
   if (width > WIN_XSIZE)
   {
+    /* image width too large for window => center image horizontally */
     src_x = (width - WIN_XSIZE) / 2;
     width = WIN_XSIZE;
   }
 
   if (height > WIN_YSIZE)
   {
+    /* image height too large for window => center image vertically */
     src_y = (height - WIN_YSIZE) / 2;
     height = WIN_YSIZE;
   }
@@ -312,11 +283,7 @@ void DrawTitleScreenImage(int nr)
   dst_x = (WIN_XSIZE - width) / 2;
   dst_y = (WIN_YSIZE - height) / 2;
 
-#if 1
   ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
-#else
-  DrawBackground(0, 0, WIN_XSIZE, WIN_YSIZE);
-#endif
 
   if (DrawingOnBackground(dst_x, dst_y))
     BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
@@ -332,23 +299,11 @@ void DrawTitleScreen()
 
   SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
 
-#if 0
-  CloseDoor(DOOR_CLOSE_1);
-#endif
-
   PlayMenuSound();
   PlayMenuMusic();
 
   HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
 
-#if 0
-#if 1
-  FadeIn(1000);
-#else
-  FadeToFront();
-#endif
-#endif
-
   StopAnimation();
 }
 
@@ -376,6 +331,10 @@ static void DrawMainMenuExt(int fade_delay)
 
   audio.sound_deactivated = FALSE;
 
+#if 1
+  GetPlayerConfig();
+#endif
+
   /* needed if last screen was the playing screen, invoked from level editor */
   if (level_editor_test_game)
   {
@@ -427,7 +386,9 @@ static void DrawMainMenuExt(int fade_delay)
   if (setup.handicap && level_nr > leveldir_current->handicap_level)
     level_nr = leveldir_current->handicap_level;
 
+#if 0
   GetPlayerConfig();
+#endif
   LoadLevel(level_nr);
 
   SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
@@ -533,6 +494,8 @@ static void DrawMainMenuExt(int fade_delay)
 
 #if 0
   FadeToFront();
+#endif
+#if 0
   InitAnimation();
 #endif
 
@@ -546,6 +509,7 @@ static void DrawMainMenuExt(int fade_delay)
   PlayMenuSound();
   PlayMenuMusic();
 
+#if 0
 #if 1
   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
 #else
@@ -554,6 +518,11 @@ static void DrawMainMenuExt(int fade_delay)
   else
     OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
 #endif
+#endif
+
+#if 0
+  InitAnimation();
+#endif
 
 #if 1
   /* map gadgets for main menu screen */
@@ -561,18 +530,25 @@ static void DrawMainMenuExt(int fade_delay)
 #endif
 
 #if 1
-  if (fade_delay > 0)
-    FadeIn(fade_delay);
-  else
-    BackToFront();
+#if 1
+  FadeIn(fade_delay);
+#else
+  BackToFront();
+#endif
+#endif
 
+#if 1
   InitAnimation();
 #endif
+
+#if 1
+  OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
+#endif
 }
 
 void DrawMainMenu()
 {
-  DrawMainMenuExt(FALSE);
+  DrawMainMenuExt(0);
 }
 
 #if 0
@@ -612,13 +588,20 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
   boolean return_to_main_menu = FALSE;
   boolean use_fading_main_menu = TRUE;
   boolean use_cross_fading = TRUE;
-  int fade_delay = 1000;
-  int post_delay = 500;
+  int fade_delay = 500;
+  int post_delay = fade_delay / 2;
 
   if (button == MB_MENU_INITIALIZE)
   {
     title_nr = 0;
 
+    if (game_status == GAME_MODE_INFO)
+    {
+      FadeSoundsAndMusic();
+
+      FadeOut(fade_delay, post_delay);
+    }
+
     DrawTitleScreenImage(title_nr);
 
     FadeIn(fade_delay);
@@ -650,12 +633,14 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
       drawto = drawto_last;
 
       if (use_cross_fading)
-       FadeCross(bitmap_db_title, fade_delay);
+       FadeCross(fade_delay);
       else
        FadeIn(fade_delay);
     }
     else
     {
+      FadeSoundsAndMusic();
+
       FadeOut(fade_delay, post_delay);
 
       return_to_main_menu = TRUE;
@@ -664,14 +649,24 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
 
   if (return_to_main_menu)
   {
+    int menu_fade_delay = (use_fading_main_menu ? fade_delay : 0);
+
     RedrawBackground();
 
-#if 1
-    OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
-#endif
+    if (game_status == GAME_MODE_INFO)
+    {
+      OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
 
-    game_status = GAME_MODE_MAIN;
-    DrawMainMenuExt(use_fading_main_menu ? fade_delay : 0);
+      info_mode = INFO_MODE_MAIN;
+      DrawInfoScreenExt(menu_fade_delay);
+    }
+    else       /* default: return to main menu */
+    {
+      OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+
+      game_status = GAME_MODE_MAIN;
+      DrawMainMenuExt(menu_fade_delay);
+    }
   }
 }
 
@@ -843,6 +838,12 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 static struct TokenInfo *info_info;
 static int num_info_info;
 
+static void execInfoTitleScreen()
+{
+  info_mode = INFO_MODE_TITLESCREEN;
+  DrawInfoScreen();
+}
+
 static void execInfoElements()
 {
   info_mode = INFO_MODE_ELEMENTS;
@@ -881,6 +882,7 @@ static void execExitInfo()
 
 static struct TokenInfo info_info_main[] =
 {
+  { TYPE_ENTER_SCREEN, execInfoTitleScreen,    "Title Screen"          },
   { TYPE_ENTER_SCREEN, execInfoElements,       "Elements Info"         },
   { TYPE_ENTER_SCREEN, execInfoMusic,          "Music Info"            },
   { TYPE_ENTER_SCREEN, execInfoCredits,        "Credits"               },
@@ -892,7 +894,7 @@ static struct TokenInfo info_info_main[] =
   { 0,                 NULL,                   NULL                    }
 };
 
-static void DrawInfoScreen_Main()
+static void DrawInfoScreen_Main(int fade_delay)
 {
   int i;
 
@@ -928,6 +930,18 @@ static void DrawInfoScreen_Main()
     num_info_info++;
   }
 
+#if 1
+
+  HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
+
+  PlayMenuSound();
+  PlayMenuMusic();
+
+  FadeIn(fade_delay);
+  InitAnimation();
+
+#else
+
   FadeToFront();
   InitAnimation();
 
@@ -935,6 +949,7 @@ static void DrawInfoScreen_Main()
   PlayMenuMusic();
 
   HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
+#endif
 }
 
 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
@@ -1180,6 +1195,16 @@ void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
                  max_chars_per_line, max_lines_per_text);
 }
 
+void DrawInfoScreen_TitleScreen()
+{
+  DrawTitleScreen();
+}
+
+void HandleInfoScreen_TitleScreen(int button)
+{
+  HandleTitleScreen(0, 0, 0, 0, button);
+}
+
 void DrawInfoScreen_Elements()
 {
   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
@@ -1561,11 +1586,13 @@ void HandleInfoScreen_LevelSet(int button)
   }
 }
 
-void DrawInfoScreen()
+static void DrawInfoScreenExt(int fade_delay)
 {
   SetMainBackgroundImage(IMG_BACKGROUND_INFO);
 
-  if (info_mode == INFO_MODE_ELEMENTS)
+  if (info_mode == INFO_MODE_TITLESCREEN)
+    DrawInfoScreen_TitleScreen();
+  else if (info_mode == INFO_MODE_ELEMENTS)
     DrawInfoScreen_Elements();
   else if (info_mode == INFO_MODE_MUSIC)
     DrawInfoScreen_Music();
@@ -1576,7 +1603,7 @@ void DrawInfoScreen()
   else if (info_mode == INFO_MODE_LEVELSET)
     DrawInfoScreen_LevelSet();
   else
-    DrawInfoScreen_Main();
+    DrawInfoScreen_Main(fade_delay);
 
   if (info_mode != INFO_MODE_MUSIC)
   {
@@ -1585,9 +1612,16 @@ void DrawInfoScreen()
   }
 }
 
+void DrawInfoScreen()
+{
+  DrawInfoScreenExt(0);
+}
+
 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
 {
-  if (info_mode == INFO_MODE_ELEMENTS)
+  if (info_mode == INFO_MODE_TITLESCREEN)
+    HandleInfoScreen_TitleScreen(button);
+  else if (info_mode == INFO_MODE_ELEMENTS)
     HandleInfoScreen_Elements(button);
   else if (info_mode == INFO_MODE_MUSIC)
     HandleInfoScreen_Music(button);