rnd-20060816-1-src
[rocksndiamonds.git] / src / screens.c
index 199d83761e0e7e077564ddec5f647651db3f3a28..0a4534b5ab7122d4bf3c0a6c93ce8eb4eccafbb6 100644 (file)
@@ -229,30 +229,6 @@ void DrawHeadline()
   DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
 }
 
-static void ToggleFullscreenIfNeeded()
-{
-  if (setup.fullscreen != video.fullscreen_enabled)
-  {
-    /* save old door content */
-    BlitBitmap(backbuffer, bitmap_db_door,
-              DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
-
-    /* toggle fullscreen */
-    ChangeVideoModeIfNeeded(setup.fullscreen);
-    setup.fullscreen = video.fullscreen_enabled;
-
-    /* redraw background to newly created backbuffer */
-    BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
-              0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
-
-    /* restore old door content */
-    BlitBitmap(bitmap_db_door, backbuffer,
-              DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
-
-    redraw_mask = REDRAW_ALL;
-  }
-}
-
 static int getLastLevelButtonPos()
 {
   return 10;
@@ -323,7 +299,7 @@ void DrawTitleScreen()
   StopAnimation();
 }
 
-static void DrawMainMenuExt(int fade_delay)
+void DrawMainMenuExt(int fade_delay, int redraw_mask)
 {
   static LevelDirTree *leveldir_last_valid = NULL;
   boolean levelset_has_changed = FALSE;
@@ -449,7 +425,7 @@ static void DrawMainMenuExt(int fade_delay)
 #endif
 #endif
 
-  DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
+  DrawPreviewLevel(TRUE);
 
 #if 1
 
@@ -556,7 +532,12 @@ static void DrawMainMenuExt(int fade_delay)
 
 #if 1
 #if 1
-  FadeIn(fade_delay);
+  if (redraw_mask == REDRAW_FIELD)
+    FadeInField(fade_delay);
+  else if (redraw_mask == REDRAW_ALL)
+    FadeIn(fade_delay);
+
+  BackToFront();
 #else
   BackToFront();
 #endif
@@ -573,7 +554,7 @@ static void DrawMainMenuExt(int fade_delay)
 
 void DrawMainMenu()
 {
-  DrawMainMenuExt(0);
+  DrawMainMenuExt(0, REDRAW_ALL);
 }
 
 #if 0
@@ -613,8 +594,8 @@ 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 = 500;
-  int post_delay = fade_delay / 2;
+  int fade_delay = TITLE_SCREEN_FADE_DELAY;
+  int post_delay = TITLE_SCREEN_POST_DELAY;
 
   if (button == MB_MENU_INITIALIZE)
   {
@@ -716,7 +697,7 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
       OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
 
       game_status = GAME_MODE_MAIN;
-      DrawMainMenuExt(menu_fade_delay);
+      DrawMainMenuExt(menu_fade_delay, REDRAW_ALL);
     }
   }
 }
@@ -752,13 +733,13 @@ void HandleMainMenu_SelectLevel(int step, int direction)
     DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
 
     LoadLevel(level_nr);
-    DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
+    DrawPreviewLevel(TRUE);
 
     TapeErase();
     LoadTape(level_nr);
     DrawCompleteVideoDisplay();
 
-    /* needed because DrawMicroLevel() takes some time */
+    /* needed because DrawPreviewLevel() takes some time */
     BackToFront();
     SyncDisplay();
   }
@@ -848,13 +829,13 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
               FONT_VALUE_1);
 
       LoadLevel(level_nr);
-      DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
+      DrawPreviewLevel(TRUE);
 
       TapeErase();
       LoadTape(level_nr);
       DrawCompleteVideoDisplay();
 
-      /* needed because DrawMicroLevel() takes some time */
+      /* needed because DrawPreviewLevel() takes some time */
       BackToFront();
       SyncDisplay();
 
@@ -944,7 +925,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
   if (game_status == GAME_MODE_MAIN)
   {
-    DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
+    DrawPreviewLevel(FALSE);
     DoAnimation();
   }
 }
@@ -1114,7 +1095,7 @@ void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
   {
     if (dx)
     {
-      int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
+      int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
 
       if (info_info[choice].type & menu_navigation_type ||
          info_info[choice].type & TYPE_ENTER_SCREEN ||
@@ -1467,6 +1448,7 @@ void HandleInfoScreen_Music(int button)
 
   if (button_released || button == MB_MENU_INITIALIZE)
   {
+    Bitmap *drawto_last = drawto;
     int y = 0;
 
     if (button != MB_MENU_INITIALIZE)
@@ -1483,6 +1465,9 @@ void HandleInfoScreen_Music(int button)
 
     FadeSoundsAndMusic();
 
+    if (button != MB_MENU_INITIALIZE)
+      drawto = bitmap_db_title;
+
     ClearWindow();
     DrawHeadline();
 
@@ -1544,6 +1529,11 @@ void HandleInfoScreen_Music(int button)
 
     DrawTextSCentered(ybottom, FONT_TEXT_4,
                      "Press any key or button for next page");
+
+    drawto = drawto_last;
+
+    if (button != MB_MENU_INITIALIZE)
+      FadeCrossField(TITLE_SCREEN_FADE_DELAY);
   }
 
   if (list != NULL && list->is_sound && sound_info[list->music].loop)
@@ -1748,9 +1738,22 @@ void HandleInfoScreen_Credits(int button)
   }
   else if (button == MB_MENU_CHOICE)
   {
+    Bitmap *drawto_last = drawto;
+    boolean show_screen;
+
     screen_nr++;
 
-    if (!DrawInfoScreen_CreditsScreen(screen_nr))
+    drawto = bitmap_db_title;
+
+    show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
+
+    drawto = drawto_last;
+  
+    if (show_screen)
+    {
+      FadeCrossField(TITLE_SCREEN_FADE_DELAY);
+    }
+    else
     {
       FadeSoundsAndMusic();
 
@@ -1781,7 +1784,7 @@ void DrawInfoScreen_Program()
   DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
                    "If you like it, send e-mail to:");
   DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
-                   "info@artsoft.org");
+                   PROGRAM_EMAIL_STRING);
   DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
                    "or SnailMail to:");
   DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
@@ -1792,12 +1795,15 @@ void DrawInfoScreen_Program()
                    "33604 Bielefeld");
   DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
                    "Germany");
-
   DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
+                   "More information and levels:");
+  DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_3,
+                   PROGRAM_WEBSITE_STRING);
+  DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
                    "If you have created new levels,");
-  DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
+  DrawTextSCentered(ystart + 10 * ystep, FONT_TEXT_2,
                    "send them to me to include them!");
-  DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
+  DrawTextSCentered(ystart + 11 * ystep, FONT_TEXT_2,
                    ":-)");
 
   DrawTextSCentered(ybottom, FONT_TEXT_4,
@@ -2414,13 +2420,19 @@ void DrawHallOfFame(int highlight_position)
   if (highlight_position < 0) 
     LoadScore(level_nr);
 
+  FadeOutField(TITLE_SCREEN_FADE_DELAY, TITLE_SCREEN_POST_DELAY);
+
+#if 0
   FadeToFront();
+#endif
   InitAnimation();
 
   PlayMenuSound();
   PlayMenuMusic();
 
   HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
+
+  FadeInField(TITLE_SCREEN_FADE_DELAY);
 }
 
 static void drawHallOfFameList(int first_entry, int highlight_position)
@@ -2471,7 +2483,6 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
   static int first_entry = 0;
   static int highlight_position = 0;
   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
-  int button_released = !button;
 
   if (button == MB_MENU_INITIALIZE)
   {
@@ -2507,11 +2518,22 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
       drawHallOfFameList(first_entry, highlight_position);
     }
   }
-  else if (button_released)
+  else if (button == MB_MENU_LEAVE)
   {
     FadeSound(SND_BACKGROUND_SCORES);
+
     game_status = GAME_MODE_MAIN;
-    DrawMainMenu();
+
+    DrawMainMenuExt(0, REDRAW_FIELD);
+  }
+  else if (button == MB_MENU_CHOICE)
+  {
+    FadeSound(SND_BACKGROUND_SCORES);
+    FadeOutField(TITLE_SCREEN_FADE_DELAY, TITLE_SCREEN_POST_DELAY);
+
+    game_status = GAME_MODE_MAIN;
+
+    DrawMainMenuExt(TITLE_SCREEN_FADE_DELAY, REDRAW_FIELD);
   }
 
   if (game_status == GAME_MODE_SCORES)
@@ -2560,15 +2582,18 @@ static void execSetupGraphics()
     for (i = 0; video.fullscreen_modes[i].width != -1; i++)
     {
       TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
-      char identifier[20], name[20];
+      char identifier[32], name[32];
       int x = video.fullscreen_modes[i].width;
       int y = video.fullscreen_modes[i].height;
+      int xx, yy;
+
+      get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
 
       ti->node_top = &screen_modes;
-      ti->sort_priority = x * y;
+      ti->sort_priority = x * 10000 + y;
 
       sprintf(identifier, "%dx%d", x, y);
-      sprintf(name,     "%d x %d", x, y);
+      sprintf(name,     "%d x %d [%d:%d]", x, y, xx, yy);
 
       setString(&ti->identifier, identifier);
       setString(&ti->name, name);
@@ -2578,11 +2603,19 @@ static void execSetupGraphics()
       pushTreeInfo(&screen_modes, ti);
     }
 
+    /* sort fullscreen modes to start with lowest available screen resolution */
     sortTreeInfo(&screen_modes);
 
-    /* set current screen mode for fullscreen mode to reliable default value */
+    /* set current screen mode for fullscreen mode to configured setup value */
     screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
-                                                   DEFAULT_FULLSCREEN_MODE);
+                                                   setup.fullscreen_mode);
+
+    /* if that fails, set current screen mode to reliable default value */
+    if (screen_mode_current == NULL)
+      screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
+                                                     DEFAULT_FULLSCREEN_MODE);
+
+    /* if that also fails, set current screen mode to first available mode */
     if (screen_mode_current == NULL)
       screen_mode_current = screen_modes;
 
@@ -3192,6 +3225,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
     choice_store[setup_mode] = choice;
 
     drawCursor(choice, FC_RED);
+
     return;
   }
   else if (button == MB_MENU_LEAVE)
@@ -3203,6 +3237,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
        void (*menu_callback_function)(void) = setup_info[y].value;
 
        menu_callback_function();
+
        break;  /* absolutely needed because function changes 'setup_info'! */
       }
     }
@@ -3219,7 +3254,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
   {
     if (dx)
     {
-      int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
+      int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
 
       if (setup_info[choice].type & menu_navigation_type ||
          setup_info[choice].type & TYPE_BOOLEAN_STYLE)
@@ -3234,6 +3269,44 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
       y += dy;
   }
 
+#if 1
+  if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
+  {
+    if (button)
+    {
+      if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
+      {
+       drawCursor(y, FC_RED);
+       drawCursor(choice, FC_BLUE);
+       choice = choice_store[setup_mode] = y;
+      }
+    }
+    else if (!(setup_info[y].type & TYPE_GHOSTED))
+    {
+      /* when selecting key headline, execute function for key value change */
+      if (setup_info[y].type & TYPE_KEYTEXT &&
+         setup_info[y + 1].type & TYPE_KEY)
+       y++;
+
+      /* when selecting string value, execute function for list selection */
+      if (setup_info[y].type & TYPE_STRING && y > 0 &&
+         setup_info[y - 1].type & TYPE_ENTER_LIST)
+       y--;
+
+      if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
+      {
+       void (*menu_callback_function)(void) = setup_info[y].value;
+
+       menu_callback_function();
+      }
+      else
+      {
+       if (setup_info[y].type & TYPE_VALUE)
+         changeSetupValue(y);
+      }
+    }
+  }
+#else
   if (IN_VIS_FIELD(x, y) &&
       y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
   {
@@ -3265,6 +3338,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
       }
     }
   }
+#endif
 }
 
 void DrawSetupScreen_Input()