From 459e3ba4589c247d389e315d1f501ee099a8a125 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 7 Mar 2024 00:03:47 +0100 Subject: [PATCH] added graphics config option for level-specific colors for BD engine This adds a config option "bd_game_graphics_color_template" for the custom artwork config file "graphicsinfo.conf" to specify a template image file used to create level-specific game graphics colors for native Boulder Dash level files (to be used for all game elements for both in-game graphics and main menu preview graphics), while the normal game element image config options specify a default image file with static/fixed colors to be used in the level editor (that is, all levels in the level editor use the same colors). This implementation only works correctly for all game element graphics if all BD style game graphics are defined in one single image file, so the newly defined template image file must have the same image size and layout of game graphics as the default image file (which must also be a single image file containing game graphics for all game elements). --- src/conf_gfx.c | 3 +++ src/game_bd/bd_graphics.c | 2 ++ src/game_bd/export_bd.h | 1 + src/game_bd/main_bd.c | 6 ++++-- src/main.c | 5 +++++ src/main.h | 3 ++- src/tools.c | 24 ++++++++++++++++++++---- 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/conf_gfx.c b/src/conf_gfx.c index 342504b0..ae95ea37 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -6713,6 +6713,9 @@ struct ConfigInfo image_config[] = { "graphic_7", UNDEFINED_FILENAME }, { "graphic_8", UNDEFINED_FILENAME }, + // game graphics template for level-specific colors for native BD levels + { "bd_game_graphics_color_template", UNDEFINED_FILENAME }, + #include "conf_chr.c" // include auto-generated data structure definitions #include "conf_cus.c" // include auto-generated data structure definitions #include "conf_grp.c" // include auto-generated data structure definitions diff --git a/src/game_bd/bd_graphics.c b/src/game_bd/bd_graphics.c index b171b763..4797f8ed 100644 --- a/src/game_bd/bd_graphics.c +++ b/src/game_bd/bd_graphics.c @@ -61,6 +61,8 @@ static int cell_size = 0; // graphic info for game objects/frames and players/actions/frames struct GraphicInfo_BD graphic_info_bd_object[O_MAX_ALL][8]; +// graphic info for game graphics template for level-specific colors +struct GraphicInfo_BD graphic_info_bd_color_template; static inline int c64_png_colors(int r, int g, int b, int a) { diff --git a/src/game_bd/export_bd.h b/src/game_bd/export_bd.h index ae3e4527..52d367bb 100644 --- a/src/game_bd/export_bd.h +++ b/src/game_bd/export_bd.h @@ -79,6 +79,7 @@ struct EngineSnapshotInfo_BD extern struct GameInfo_BD game_bd; extern struct LevelInfo_BD native_bd_level; extern struct GraphicInfo_BD graphic_info_bd_object[O_MAX_ALL][8]; +extern struct GraphicInfo_BD graphic_info_bd_color_template; extern struct EngineSnapshotInfo_BD engine_snapshot_bd; void bd_open_all(void); diff --git a/src/game_bd/main_bd.c b/src/game_bd/main_bd.c index 56e448a7..fcd2a23d 100644 --- a/src/game_bd/main_bd.c +++ b/src/game_bd/main_bd.c @@ -250,9 +250,11 @@ static void UpdateGameDoorValues_BD(void) static void PrepareGameTileBitmap_BD(void) { - struct GraphicInfo_BD *g = &graphic_info_bd_object[O_STONE][0]; + struct GraphicInfo_BD *g_template = &graphic_info_bd_color_template; + struct GraphicInfo_BD *g_default = &graphic_info_bd_object[O_STONE][0]; - gd_prepare_tile_bitmap(native_bd_level.cave, g->bitmap, 1); + gd_prepare_tile_bitmap(native_bd_level.cave, g_template->bitmap, 1); + gd_set_tile_bitmap_reference(g_default->bitmap); } void PreparePreviewTileBitmap_BD(Bitmap *bitmap, int scale_down_factor) diff --git a/src/main.c b/src/main.c index b0d794b5..865c907d 100644 --- a/src/main.c +++ b/src/main.c @@ -7868,6 +7868,11 @@ struct ElementNameInfo element_name_info[MAX_NUM_ELEMENTS + 1] = "graphic", "-" }, + { + "bd_game_graphics_color_template", + "-", + "-" + }, { "internal_clipboard_custom", "internal", diff --git a/src/main.h b/src/main.h index 03d144c1..d1ee5b60 100644 --- a/src/main.h +++ b/src/main.h @@ -2294,9 +2294,10 @@ #define EL_GRAPHIC_6 (EL_FIRST_DUMMY + 34) #define EL_GRAPHIC_7 (EL_FIRST_DUMMY + 35) #define EL_GRAPHIC_8 (EL_FIRST_DUMMY + 36) +#define EL_BD_GAME_GRAPHICS_COLOR_TEMPLATE (EL_FIRST_DUMMY + 37) // internal elements (only used for internal purposes like copying) -#define EL_FIRST_INTERNAL (EL_FIRST_DUMMY + 37) +#define EL_FIRST_INTERNAL (EL_FIRST_DUMMY + 38) #define EL_INTERNAL_CLIPBOARD_CUSTOM (EL_FIRST_INTERNAL + 0) #define EL_INTERNAL_CLIPBOARD_CHANGE (EL_FIRST_INTERNAL + 1) diff --git a/src/tools.c b/src/tools.c index c271314e..b92cf01b 100644 --- a/src/tools.c +++ b/src/tools.c @@ -3838,15 +3838,17 @@ static void PreparePreviewTileBitmap(void) 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); + 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, 0, original_tilesize, &src_bitmap, &src_x, &src_y); + 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, 0, preview.tile_size, &src_bitmap, &src_x, &src_y); + getSizedGraphicSource(graphic_default, 0, preview.tile_size, &src_bitmap, &src_x, &src_y); SetPreviewTileBitmapReference_BD(src_bitmap); } @@ -10155,6 +10157,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) -- 2.34.1