fixed preview size of intermission levels for native BD level sets
[rocksndiamonds.git] / src / tools.c
index 7c8f825217ccc2459c94bef3b181412ba99aa228..537a0e2174e860ad0cefe01ac9a70e8df5d374ae 100644 (file)
@@ -500,7 +500,9 @@ void RedrawPlayfield(void)
   if (game_status != GAME_MODE_PLAYING)
     return;
 
-  if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+    RedrawPlayfield_BD(TRUE);
+  else if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
     RedrawPlayfield_EM(TRUE);
   else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
     RedrawPlayfield_SP(TRUE);
@@ -668,7 +670,9 @@ void BlitScreenToBitmap_RND(Bitmap *target_bitmap)
 
 void BlitScreenToBitmap(Bitmap *target_bitmap)
 {
-  if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+    BlitScreenToBitmap_BD(target_bitmap);
+  else if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
     BlitScreenToBitmap_EM(target_bitmap);
   else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
     BlitScreenToBitmap_SP(target_bitmap);
@@ -1026,6 +1030,10 @@ void FadeOut(int fade_mask)
       fade_type_skip != FADE_MODE_SKIP_FADE_OUT)
     BackToFront();
 
+  // when using BD game engine, cover playfield before fading out after a game
+  if (game_bd.cover_screen)
+    CoverScreen_BD();
+
   SetScreenStates_BeforeFadingOut();
 
   SetTileCursorActive(FALSE);
@@ -3388,6 +3396,14 @@ static void ShowEnvelopeRequest(char *text, unsigned int req_state, int action)
   game.envelope_active = FALSE;
 }
 
+static Bitmap *GetPreviewTileBitmap(Bitmap *bitmap)
+{
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+    return GetPreviewTileBitmap_BD(bitmap);
+
+  return bitmap;
+}
+
 static void DrawPreviewElement(int dst_x, int dst_y, int element, int tilesize)
 {
   if (IS_MM_WALL(element))
@@ -3401,6 +3417,10 @@ static void DrawPreviewElement(int dst_x, int dst_y, int element, int tilesize)
     int graphic = el2preimg(element);
 
     getSizedGraphicSource(graphic, 0, tilesize, &src_bitmap, &src_x, &src_y);
+
+    // for BD style levels, maybe use bitmap with level-specific colors
+    src_bitmap = GetPreviewTileBitmap(src_bitmap);
+
     BlitBitmap(src_bitmap, drawto, src_x, src_y, tilesize, tilesize,
               dst_x, dst_y);
   }
@@ -3445,11 +3465,27 @@ void DrawMiniLevel(int size_x, int size_y, int scroll_x, int scroll_y)
   redraw_mask |= REDRAW_FIELD;
 }
 
+static int getPreviewLevelWidth(void)
+{
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+    return (level.native_bd_level->cave->x2 - level.native_bd_level->cave->x1 + 1);
+
+  return lev_fieldx;
+}
+
+static int getPreviewLevelHeight(void)
+{
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+    return (level.native_bd_level->cave->y2 - level.native_bd_level->cave->y1 + 1);
+
+  return lev_fieldy;
+}
+
 static void DrawPreviewLevelPlayfield(int from_x, int from_y)
 {
   boolean show_level_border = (BorderElement != EL_EMPTY);
-  int level_xsize = lev_fieldx + (show_level_border ? 2 : 0);
-  int level_ysize = lev_fieldy + (show_level_border ? 2 : 0);
+  int level_xsize = getPreviewLevelWidth()  + (show_level_border ? 2 : 0);
+  int level_ysize = getPreviewLevelHeight() + (show_level_border ? 2 : 0);
   int tile_size = preview.tile_size;
   int preview_width  = preview.xsize * tile_size;
   int preview_height = preview.ysize * tile_size;
@@ -3807,8 +3843,35 @@ void DrawPreviewPlayers(void)
   }
 }
 
+static void PreparePreviewTileBitmap(void)
+{
+  // check if special preview bitmap with level-specific colors should be created
+  if (level.game_engine_type != GAME_ENGINE_TYPE_BD)
+    return;
+
+  // use original sized bitmap (else reduced color palette is lost by downscaling)
+  int original_tilesize = MAX(MINI_TILESIZE, preview.tile_size);
+  int scale_down_factor = original_tilesize / preview.tile_size;
+  Bitmap *src_bitmap;
+  int src_x, src_y;
+  int element_template = EL_BD_GAME_GRAPHICS_COLOR_TEMPLATE;
+  int graphic_template = el2preimg(element_template);
+  int element_default = EL_BD_ROCK;
+  int graphic_default = el2preimg(element_default);
+
+  // create special preview bitmap and scale it down to preview tile size
+  getSizedGraphicSource(graphic_template, 0, original_tilesize, &src_bitmap, &src_x, &src_y);
+  PreparePreviewTileBitmap_BD(src_bitmap, scale_down_factor);
+
+  // force using special preview bitmap to replace original preview bitmap
+  getSizedGraphicSource(graphic_default, 0, preview.tile_size, &src_bitmap, &src_x, &src_y);
+  SetPreviewTileBitmapReference_BD(src_bitmap);
+}
+
 void DrawPreviewLevelInitial(void)
 {
+  PreparePreviewTileBitmap();  // only needed for native BD style levels
+
   DrawPreviewLevelExt(TRUE);
   DrawPreviewPlayers();
 }
@@ -10110,6 +10173,20 @@ void InitGraphicInfo_BD(void)
       g_bd->height = TILEY;
     }
   }
+
+  // game graphics template for level-specific colors for native BD levels
+  int graphic = IMG_BD_GAME_GRAPHICS_COLOR_TEMPLATE;
+  struct GraphicInfo_BD *g_bd = &graphic_info_bd_color_template;
+  Bitmap *src_bitmap;
+  int src_x, src_y;
+
+  getGraphicSourceExt(graphic, 0, &src_bitmap, &src_x, &src_y, FALSE);
+
+  g_bd->bitmap = src_bitmap;
+  g_bd->src_x  = src_x;
+  g_bd->src_y  = src_y;
+  g_bd->width  = TILEX;
+  g_bd->height = TILEY;
 }
 
 void InitGraphicInfo_EM(void)
@@ -11213,6 +11290,11 @@ void OpenURLFromHash(SetupFileHash *hash, int hash_key)
   OpenURL(getHashEntry(hash, int2str(hash_key, 0)));
 }
 
+char *getCurrentLevelsetName(void)
+{
+  return leveldir_current->name;
+}
+
 
 // ============================================================================
 // tests
@@ -11308,10 +11390,10 @@ static unsigned int test_uuid_random_function_better(int max)
 
 static void TestGeneratingUUIDs_RunTest(int nr, int always_seed, int num_uuids)
 {
-  struct hashtable *hash_seeds =
-    create_hashtable(16, 0.75, get_hash_from_key, hash_keys_are_equal);
-  struct hashtable *hash_uuids =
-    create_hashtable(16, 0.75, get_hash_from_key, hash_keys_are_equal);
+  HashTable *hash_seeds =
+    create_hashtable(get_hash_from_string, hash_key_strings_are_equal, free, NULL);
+  HashTable *hash_uuids =
+    create_hashtable(get_hash_from_string, hash_key_strings_are_equal, free, NULL);
   static char message[100];
   int i;
 
@@ -11390,8 +11472,8 @@ static void TestGeneratingUUIDs_RunTest(int nr, int always_seed, int num_uuids)
 
   Request(message, REQ_CONFIRM);
 
-  hashtable_destroy(hash_seeds, 0);
-  hashtable_destroy(hash_uuids, 0);
+  hashtable_destroy(hash_seeds);
+  hashtable_destroy(hash_uuids);
 }
 
 void TestGeneratingUUIDs(void)