From e781055ddb3142d2d309a98e67ec66cf261eb179 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 6 Mar 2024 10:19:13 +0100 Subject: [PATCH] added support for level-specific preview colors for BD engine --- src/game_bd/export_bd.h | 4 ++++ src/game_bd/main_bd.c | 15 +++++++++++++++ src/tools.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/src/game_bd/export_bd.h b/src/game_bd/export_bd.h index 1db82520..ae3e4527 100644 --- a/src/game_bd/export_bd.h +++ b/src/game_bd/export_bd.h @@ -100,6 +100,10 @@ void setLevelInfoToDefaults_BD(void); boolean LoadNativeLevel_BD(char *, int, boolean); boolean SaveNativeLevel_BD(char *); +void PreparePreviewTileBitmap_BD(Bitmap *, int); +void SetPreviewTileBitmapReference_BD(Bitmap *); +Bitmap *GetPreviewTileBitmap_BD(Bitmap *); + unsigned int InitEngineRandom_BD(int); void InitGameEngine_BD(void); void GameActions_BD(byte[MAX_PLAYERS]); diff --git a/src/game_bd/main_bd.c b/src/game_bd/main_bd.c index e7844fcb..56e448a7 100644 --- a/src/game_bd/main_bd.c +++ b/src/game_bd/main_bd.c @@ -255,6 +255,21 @@ static void PrepareGameTileBitmap_BD(void) gd_prepare_tile_bitmap(native_bd_level.cave, g->bitmap, 1); } +void PreparePreviewTileBitmap_BD(Bitmap *bitmap, int scale_down_factor) +{ + gd_prepare_tile_bitmap(native_bd_level.cave, bitmap, scale_down_factor); +} + +void SetPreviewTileBitmapReference_BD(Bitmap *bitmap) +{ + gd_set_tile_bitmap_reference(bitmap); +} + +Bitmap *GetPreviewTileBitmap_BD(Bitmap *bitmap) +{ + return gd_get_tile_bitmap(bitmap); +} + unsigned int InitEngineRandom_BD(int seed) { if (seed == NEW_RANDOMIZE) diff --git a/src/tools.c b/src/tools.c index e1b79cbf..c271314e 100644 --- a/src/tools.c +++ b/src/tools.c @@ -3396,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)) @@ -3409,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); } @@ -3815,8 +3827,33 @@ 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 = EL_BD_ROCK; + int graphic = el2preimg(element); + + // create special preview bitmap and scale it down to preview tile size + getSizedGraphicSource(graphic, 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, 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(); } -- 2.34.1