From d0747d3b2d7c61844bc1ad096a4e18d889640018 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 10 Apr 2024 13:00:23 +0200 Subject: [PATCH] added setup option to select preferred color type for BD engine --- src/editor.c | 8 +-- src/editor.h | 1 + src/files.c | 8 +++ src/game_bd/bd_colors.h | 2 + src/libgame/system.h | 1 + src/screens.c | 131 ++++++++++++++++++++++++++++++++-------- 6 files changed, 123 insertions(+), 28 deletions(-) diff --git a/src/editor.c b/src/editor.c index cea40951..95d30a88 100644 --- a/src/editor.c +++ b/src/editor.c @@ -11452,13 +11452,13 @@ void SetDefaultLevelColors_BD(void) bd_color_default[i] = *bd_color[i]; } -static void SetRandomLevelColors_BD(void) +void SetRandomLevelColors_BD(int bd_color_type) { struct LevelInfo_BD *level_bd = level.native_bd_level; GdCave *cave = level_bd->cave; // create random cave colors - gd_cave_set_random_colors(cave, level.bd_color_type); + gd_cave_set_random_colors(cave, bd_color_type); // copy colors to level editor level.bd_color_b = cave->colorb; @@ -11514,7 +11514,7 @@ static void DrawEngineConfigColors(void) else { // color type switched to different color type as default colors => use random colors - SetRandomLevelColors_BD(); + SetRandomLevelColors_BD(level.bd_color_type); } } @@ -16636,7 +16636,7 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi) } else if (type_id == ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS) { - SetRandomLevelColors_BD(); + SetRandomLevelColors_BD(level.bd_color_type); // update BD color palette gadgets after setting random colors DrawLevelConfigWindow(); diff --git a/src/editor.h b/src/editor.h index 5b6b470e..1b674331 100644 --- a/src/editor.h +++ b/src/editor.h @@ -36,5 +36,6 @@ void RedoLevelEditorOperation(void); void SetDefaultLevelColorType_BD(void); void SetDefaultLevelColors_BD(void); +void SetRandomLevelColors_BD(int); #endif diff --git a/src/files.c b/src/files.c index 8ff22892..a0115f71 100644 --- a/src/files.c +++ b/src/files.c @@ -2382,6 +2382,9 @@ static void setLevelInfoToDefaults_Level(struct LevelInfo *level) // detect custom elements when loading them level->file_has_custom_elements = FALSE; + // set random colors for BD style levels according to preferred color type + SetRandomLevelColors_BD(setup.bd_color_type); + // set default color type and colors for BD style level colors SetDefaultLevelColorType_BD(); SetDefaultLevelColors_BD(); @@ -10752,6 +10755,10 @@ static struct TokenInfo global_setup_tokens[] = TYPE_INTEGER, &setup.bd_palette_atari, "bd_palette_atari" }, + { + TYPE_INTEGER, + &setup.bd_color_type, "bd_color_type" + }, { TYPE_SWITCH, &setup.sp_show_border_elements, "sp_show_border_elements" @@ -11579,6 +11586,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->bd_palette_c64 = GD_DEFAULT_PALETTE_C64; si->bd_palette_c64dtv = GD_DEFAULT_PALETTE_C64DTV; si->bd_palette_atari = GD_DEFAULT_PALETTE_ATARI; + si->bd_color_type = GD_DEFAULT_COLOR_TYPE; si->sp_show_border_elements = FALSE; si->small_game_graphics = FALSE; si->show_load_save_buttons = FALSE; diff --git a/src/game_bd/bd_colors.h b/src/game_bd/bd_colors.h index 262f9b2a..15f1e367 100644 --- a/src/game_bd/bd_colors.h +++ b/src/game_bd/bd_colors.h @@ -38,6 +38,8 @@ typedef enum _color_type GD_COLOR_TYPE_UNKNOWN // should be the last one } GdColorType; +#define GD_DEFAULT_COLOR_TYPE GD_COLOR_TYPE_RGB + // traditional c64 color indexes. #define GD_COLOR_INDEX_BLACK 0 #define GD_COLOR_INDEX_WHITE 1 diff --git a/src/libgame/system.h b/src/libgame/system.h index f5d96563..d3fcb89f 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1518,6 +1518,7 @@ struct SetupInfo int bd_palette_c64; int bd_palette_c64dtv; int bd_palette_atari; + int bd_color_type; boolean sp_show_border_elements; boolean small_game_graphics; boolean show_load_save_buttons; diff --git a/src/screens.c b/src/screens.c index c4955bee..a986ebd5 100644 --- a/src/screens.c +++ b/src/screens.c @@ -71,27 +71,28 @@ #define SETUP_MODE_CHOOSE_BD_PALETTE_C64 21 #define SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV 22 #define SETUP_MODE_CHOOSE_BD_PALETTE_ATARI 23 -#define SETUP_MODE_CHOOSE_WINDOW_SIZE 24 -#define SETUP_MODE_CHOOSE_SCALING_TYPE 25 -#define SETUP_MODE_CHOOSE_RENDERING 26 -#define SETUP_MODE_CHOOSE_VSYNC 27 -#define SETUP_MODE_CHOOSE_GRAPHICS 28 -#define SETUP_MODE_CHOOSE_SOUNDS 29 -#define SETUP_MODE_CHOOSE_MUSIC 30 -#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 31 -#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 32 -#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 33 -#define SETUP_MODE_CHOOSE_TOUCH_CONTROL 34 -#define SETUP_MODE_CHOOSE_MOVE_DISTANCE 35 -#define SETUP_MODE_CHOOSE_DROP_DISTANCE 36 -#define SETUP_MODE_CHOOSE_TRANSPARENCY 37 -#define SETUP_MODE_CHOOSE_GRID_XSIZE_0 38 -#define SETUP_MODE_CHOOSE_GRID_YSIZE_0 39 -#define SETUP_MODE_CHOOSE_GRID_XSIZE_1 40 -#define SETUP_MODE_CHOOSE_GRID_YSIZE_1 41 -#define SETUP_MODE_CONFIG_VIRT_BUTTONS 42 - -#define MAX_SETUP_MODES 43 +#define SETUP_MODE_CHOOSE_BD_COLOR_TYPE 24 +#define SETUP_MODE_CHOOSE_WINDOW_SIZE 25 +#define SETUP_MODE_CHOOSE_SCALING_TYPE 26 +#define SETUP_MODE_CHOOSE_RENDERING 27 +#define SETUP_MODE_CHOOSE_VSYNC 28 +#define SETUP_MODE_CHOOSE_GRAPHICS 29 +#define SETUP_MODE_CHOOSE_SOUNDS 30 +#define SETUP_MODE_CHOOSE_MUSIC 31 +#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 32 +#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 33 +#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 34 +#define SETUP_MODE_CHOOSE_TOUCH_CONTROL 35 +#define SETUP_MODE_CHOOSE_MOVE_DISTANCE 36 +#define SETUP_MODE_CHOOSE_DROP_DISTANCE 37 +#define SETUP_MODE_CHOOSE_TRANSPARENCY 38 +#define SETUP_MODE_CHOOSE_GRID_XSIZE_0 39 +#define SETUP_MODE_CHOOSE_GRID_YSIZE_0 40 +#define SETUP_MODE_CHOOSE_GRID_XSIZE_1 41 +#define SETUP_MODE_CHOOSE_GRID_YSIZE_1 42 +#define SETUP_MODE_CONFIG_VIRT_BUTTONS 43 + +#define MAX_SETUP_MODES 44 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES) @@ -127,6 +128,7 @@ #define STR_SETUP_CHOOSE_BD_PALETTE_C64 "Palette (C64)" #define STR_SETUP_CHOOSE_BD_PALETTE_C64DTV "Palette (C64DTV)" #define STR_SETUP_CHOOSE_BD_PALETTE_ATARI "Palette (Atari)" +#define STR_SETUP_CHOOSE_BD_COLOR_TYPE "Palette Type" #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling" #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing" #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode" @@ -382,6 +384,9 @@ static TreeInfo *bd_palette_c64dtv_current = NULL; static TreeInfo *bd_palettes_atari = NULL; static TreeInfo *bd_palette_atari_current = NULL; +static TreeInfo *bd_color_types = NULL; +static TreeInfo *bd_color_type_current = NULL; + static TreeInfo *scores_types = NULL; static TreeInfo *scores_type_current = NULL; @@ -577,6 +582,16 @@ static struct ValueTextInfo bd_palettes_atari_list[] = { -1, NULL }, }; +static struct ValueTextInfo bd_color_types_list[] = +{ + { GD_COLOR_TYPE_RGB, "RGB colors" }, + { GD_COLOR_TYPE_C64, "C64 colors" }, + { GD_COLOR_TYPE_C64DTV, "C64DTV colors" }, + { GD_COLOR_TYPE_ATARI, "Atari colors" }, + + { -1, NULL }, +}; + static struct ValueTextInfo volumes_list[] = { { 0, "0 %" }, @@ -5025,7 +5040,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, execSetupGame(); else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64 || setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV || - setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI) + setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI || + setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE) execSetupEngines(); else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE || setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE || @@ -5225,7 +5241,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, execSetupGame(); else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64 || setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV || - setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI) + setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI || + setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE) execSetupEngines(); else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE || setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE || @@ -5306,7 +5323,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, execSetupGame(); else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64 || setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV || - setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI) + setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI || + setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE) execSetupEngines(); else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE || setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE || @@ -5956,6 +5974,7 @@ static char *snapshot_mode_text; static char *bd_palette_c64_text; static char *bd_palette_c64dtv_text; static char *bd_palette_atari_text; +static char *bd_color_type_text; static char *game_speed_text; static char *scores_type_text; static char *network_server_text; @@ -6417,6 +6436,56 @@ static void execSetupEngines_setPalettesAtari(void) bd_palette_atari_text = bd_palette_atari_current->name; } +static void execSetupEngines_setColorType(void) +{ + if (bd_color_types == NULL) + { + int i; + + for (i = 0; bd_color_types_list[i].value != -1; i++) + { + TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED); + char identifier[32], name[32]; + int value = bd_color_types_list[i].value; + char *text = bd_color_types_list[i].text; + + ti->node_top = &bd_color_types; + ti->sort_priority = value; + + sprintf(identifier, "%d", value); + sprintf(name, "%s", text); + + setString(&ti->identifier, identifier); + setString(&ti->name, name); + setString(&ti->name_sorting, name); + setString(&ti->infotext, STR_SETUP_CHOOSE_BD_COLOR_TYPE); + + pushTreeInfo(&bd_color_types, ti); + } + + // sort palette values to start with lowest palette value + sortTreeInfo(&bd_color_types); + + // set current palette value to configured palette value + bd_color_type_current = + getTreeInfoFromIdentifier(bd_color_types, i_to_a(setup.bd_color_type)); + + // if that fails, set current palette to reliable default value + if (bd_color_type_current == NULL) + bd_color_type_current = + getTreeInfoFromIdentifier(bd_color_types, i_to_a(GD_DEFAULT_COLOR_TYPE)); + + // if that also fails, set current palette to first available value + if (bd_color_type_current == NULL) + bd_color_type_current = bd_color_types; + } + + setup.bd_color_type = atoi(bd_color_type_current->identifier); + + // needed for displaying palette text instead of identifier + bd_color_type_text = bd_color_type_current->name; +} + static void execSetupEngines(void) { setup_mode = SETUP_MODE_ENGINES; @@ -6424,6 +6493,7 @@ static void execSetupEngines(void) execSetupEngines_setPalettesC64(); execSetupEngines_setPalettesC64DTV(); execSetupEngines_setPalettesAtari(); + execSetupEngines_setColorType(); DrawSetupScreen(); } @@ -6449,6 +6519,13 @@ static void execSetupChoosePaletteAtari(void) DrawSetupScreen(); } +static void execSetupChooseColorType(void) +{ + setup_mode = SETUP_MODE_CHOOSE_BD_COLOR_TYPE; + + DrawSetupScreen(); +} + static void execSetupEditor(void) { setup_mode = SETUP_MODE_EDITOR; @@ -7805,6 +7882,8 @@ static struct TokenInfo setup_info_engines[] = { TYPE_STRING, &bd_palette_c64dtv_text, "" }, { TYPE_ENTER_LIST, &execSetupChoosePaletteAtari, "Color Palette (Atari):" }, { TYPE_STRING, &bd_palette_atari_text, "" }, + { TYPE_ENTER_LIST, &execSetupChooseColorType, "Preferred Color Type:" }, + { TYPE_STRING, &bd_color_type_text, "" }, { TYPE_EMPTY, NULL, "" }, { TYPE_HEADLINE, NULL, "Emerald Mine" }, { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" }, @@ -9796,6 +9875,8 @@ void DrawSetupScreen(void) DrawChooseTree(&bd_palette_c64dtv_current); else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI) DrawChooseTree(&bd_palette_atari_current); + else if (setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE) + DrawChooseTree(&bd_color_type_current); else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE) DrawChooseTree(&window_size_current); else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE) @@ -9886,6 +9967,8 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) HandleChooseTree(mx, my, dx, dy, button, &bd_palette_c64dtv_current); else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI) HandleChooseTree(mx, my, dx, dy, button, &bd_palette_atari_current); + else if (setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE) + HandleChooseTree(mx, my, dx, dy, button, &bd_color_type_current); else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE) HandleChooseTree(mx, my, dx, dy, button, &window_size_current); else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE) -- 2.34.1