rnd-20061020-1-src
[rocksndiamonds.git] / src / screens.c
index ce3bbe47a3895349848f66661b9bced0833964a6..dcfd35b891704ee818f77a0e6c35ceabdcebb9e9 100644 (file)
@@ -158,6 +158,9 @@ static void MapScreenMenuGadgets(int);
 static void MapScreenTreeGadgets(TreeInfo *);
 
 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
+
+static boolean show_titlescreen_initial = TRUE;
+
 static int setup_mode = SETUP_MODE_MAIN;
 static int info_mode = INFO_MODE_MAIN;
 
@@ -512,11 +515,13 @@ static void DrawCursorAndText_Main(int pos, boolean active)
 
 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
 {
+  if (rect == NULL)
+    return FALSE;
+
   int rect_x = ALIGNED_XPOS(rect->x, rect->width, rect->align);
   int rect_y = rect->y;
 
-  return (rect != NULL &&
-         x >= rect_x && x < rect_x + rect->width &&
+  return (x >= rect_x && x < rect_x + rect->width &&
          y >= rect_y && y < rect_y + rect->height);
 }
 
@@ -596,9 +601,15 @@ static int getLevelRangeTextPos()
 }
 #endif
 
+static int getTitleScreenGraphic()
+{
+  return (show_titlescreen_initial ? IMG_TITLESCREEN_INITIAL_1 :
+         IMG_TITLESCREEN_1);
+}
+
 void DrawTitleScreenImage(int nr)
 {
-  int graphic = IMG_TITLESCREEN_1 + nr;
+  int graphic = getTitleScreenGraphic() + nr;
   Bitmap *bitmap = graphic_info[graphic].bitmap;
   int width  = graphic_info[graphic].src_image_width;
   int height = graphic_info[graphic].src_image_height;
@@ -633,6 +644,19 @@ void DrawTitleScreenImage(int nr)
     BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
 
   redraw_mask = REDRAW_ALL;
+
+  /* reset fading control values to default config settings */
+  title.fade_delay_final = title.fade_delay;
+  title.post_delay_final = title.post_delay;
+  title.auto_delay_final = title.auto_delay;
+
+  /* override default settings with image config settings, if defined */
+  if (graphic_info[graphic].fade_delay > -1)
+    title.fade_delay_final = graphic_info[graphic].fade_delay;
+  if (graphic_info[graphic].post_delay > -1)
+    title.post_delay_final = graphic_info[graphic].post_delay;
+  if (graphic_info[graphic].auto_delay > -1)
+    title.auto_delay_final = graphic_info[graphic].auto_delay;
 }
 
 void DrawTitleScreen()
@@ -705,8 +729,10 @@ void DrawMainMenuExt(int redraw_mask, boolean do_fading)
 #endif
 
   if (setup.show_titlescreen &&
-      levelset_has_changed &&
-      graphic_info[IMG_TITLESCREEN_1].bitmap != NULL)
+      ((levelset_has_changed &&
+       graphic_info[IMG_TITLESCREEN_1].bitmap != NULL) ||
+       (show_titlescreen_initial &&
+       graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL)))
   {
     game_status = GAME_MODE_TITLE;
 
@@ -870,16 +896,23 @@ static void gotoTopLevelDir()
 
 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
 {
+  static unsigned long title_delay = 0;
   static int title_nr = 0;
   boolean return_to_main_menu = FALSE;
   boolean use_fading_main_menu = TRUE;
-  boolean use_cross_fading = TRUE;
+  boolean use_cross_fading = !show_titlescreen_initial;                /* default */
 
   if (button == MB_MENU_INITIALIZE)
   {
     int last_game_status = game_status;        /* save current game status */
+
+    title_delay = 0;
     title_nr = 0;
 
+    if (show_titlescreen_initial &&
+       graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap == NULL)
+      show_titlescreen_initial = FALSE;
+
     if (game_status == GAME_MODE_INFO)
     {
       if (graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
@@ -907,15 +940,24 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
 
     FadeIn(REDRAW_ALL);
 
+    DelayReached(&title_delay, 0);     /* reset delay counter */
+
     return;
   }
-  else if (button == MB_MENU_LEAVE)
+
+  if (title.auto_delay_final > -1 &&
+      DelayReached(&title_delay, title.auto_delay_final))
+    button = MB_MENU_CHOICE;
+
+  if (button == MB_MENU_LEAVE)
   {
     return_to_main_menu = TRUE;
     use_fading_main_menu = FALSE;
   }
   else if (button == MB_MENU_CHOICE)
   {
+    int anim_mode;
+
     if (game_status == GAME_MODE_INFO &&
        graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
     {
@@ -927,11 +969,26 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
 
     title_nr++;
 
+    if (show_titlescreen_initial &&
+       (title_nr >= MAX_NUM_TITLE_SCREENS ||
+        graphic_info[IMG_TITLESCREEN_INITIAL_1 + title_nr].bitmap == NULL))
+    {
+      show_titlescreen_initial = FALSE;
+
+      title_nr = 0;    /* restart with title screens for current level set */
+    }
+
+    anim_mode = graphic_info[getTitleScreenGraphic() + title_nr].anim_mode;
+
+    use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
+                       anim_mode == ANIM_CROSSFADE ? TRUE :
+                       use_cross_fading);
+
     if (!use_cross_fading)
       FadeOut(REDRAW_ALL);
 
     if (title_nr < MAX_NUM_TITLE_SCREENS &&
-       graphic_info[IMG_TITLESCREEN_1 + title_nr].bitmap != NULL)
+       graphic_info[getTitleScreenGraphic() + title_nr].bitmap != NULL)
     {
       if (use_cross_fading)
        FadeCrossSaveBackbuffer();
@@ -942,6 +999,8 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
        FadeCross(REDRAW_ALL);
       else
        FadeIn(REDRAW_ALL);
+
+      DelayReached(&title_delay, 0);   /* reset delay counter */
     }
     else
     {
@@ -955,6 +1014,8 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
 
   if (return_to_main_menu)
   {
+    show_titlescreen_initial = FALSE;
+
     RedrawBackground();
 
     if (game_status == GAME_MODE_INFO)
@@ -1709,7 +1770,6 @@ void HandleInfoScreen_Elements(int button)
   static int num_pages;
   static int page;
   int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
-  int button_released = !button;
   int i;
 
   if (button == MB_MENU_INITIALIZE)
@@ -1717,6 +1777,7 @@ void HandleInfoScreen_Elements(int button)
     boolean new_element = TRUE;
 
     num_anims = 0;
+
     for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
     {
       if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
@@ -1731,15 +1792,15 @@ void HandleInfoScreen_Elements(int button)
     num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
     page = 0;
   }
-  else if (button == MB_MENU_LEAVE)
+
+  if (button == MB_MENU_LEAVE)
   {
     info_mode = INFO_MODE_MAIN;
     DrawInfoScreen();
 
     return;
   }
-
-  if (button_released || button == MB_MENU_INITIALIZE)
+  else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
   {
     if (button != MB_MENU_INITIALIZE)
       page++;
@@ -1794,7 +1855,6 @@ void HandleInfoScreen_Music(int button)
   static struct MusicFileInfo *list = NULL;
   int ystart = 150, dy = 30;
   int ybottom = SYSIZE - 20;
-  int button_released = !button;
 
   if (button == MB_MENU_INITIALIZE)
   {
@@ -1815,15 +1875,15 @@ void HandleInfoScreen_Music(int button)
       return;
     }
   }
-  else if (button == MB_MENU_LEAVE)
+
+  if (button == MB_MENU_LEAVE)
   {
     info_mode = INFO_MODE_MAIN;
     DrawInfoScreen();
 
     return;
   }
-
-  if (button_released || button == MB_MENU_INITIALIZE)
+  else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
   {
     int y = 0;
 
@@ -2200,8 +2260,6 @@ void DrawInfoScreen_Program()
 
 void HandleInfoScreen_Program(int button)
 {
-  int button_released = !button;
-
   if (button == MB_MENU_LEAVE)
   {
     info_mode = INFO_MODE_MAIN;
@@ -2209,8 +2267,7 @@ void HandleInfoScreen_Program(int button)
 
     return;
   }
-
-  if (button_released)
+  else if (button == MB_MENU_CHOICE)
   {
     FadeSoundsAndMusic();
     FadeOut(REDRAW_FIELD);
@@ -2263,8 +2320,6 @@ void DrawInfoScreen_LevelSet()
 
 void HandleInfoScreen_LevelSet(int button)
 {
-  int button_released = !button;
-
   if (button == MB_MENU_LEAVE)
   {
     info_mode = INFO_MODE_MAIN;
@@ -2272,8 +2327,7 @@ void HandleInfoScreen_LevelSet(int button)
 
     return;
   }
-
-  if (button_released)
+  else if (button == MB_MENU_CHOICE)
   {
     FadeSoundsAndMusic();
     FadeOut(REDRAW_FIELD);
@@ -3275,7 +3329,7 @@ static Key getSetupKey()
 
       NextEvent(&event);
 
-      switch(event.type)
+      switch (event.type)
       {
         case EVENT_KEYPRESS:
          {
@@ -4020,7 +4074,7 @@ void CustomizeKeyboard(int player_nr)
 
       NextEvent(&event);
 
-      switch(event.type)
+      switch (event.type)
       {
         case EVENT_KEYPRESS:
          {
@@ -4170,10 +4224,10 @@ static boolean CalibrateJoystickMain(int player_nr)
 
       NextEvent(&event);
 
-      switch(event.type)
+      switch (event.type)
       {
        case EVENT_KEYPRESS:
-         switch(GetEventKey((KeyEvent *)&event, TRUE))
+         switch (GetEventKey((KeyEvent *)&event, TRUE))
          {
            case KSYM_Return:
              if (check_remaining == 0)