moved workaround for BD runtime elements in editor to separate function
[rocksndiamonds.git] / src / editor.c
index 919c66851b74b1a2c006649901447fdd98974960..6ec52ee30ac21c4100f3120c80d7c9d733b53696 100644 (file)
@@ -680,6 +680,13 @@ enum
   GADGET_ID_LEVEL_AUTHOR,
   GADGET_ID_LEVELSET_NAME,
   GADGET_ID_LEVELSET_AUTHOR,
+  GADGET_ID_BD_COLOR_TEXT_B,
+  GADGET_ID_BD_COLOR_TEXT_0,
+  GADGET_ID_BD_COLOR_TEXT_1,
+  GADGET_ID_BD_COLOR_TEXT_2,
+  GADGET_ID_BD_COLOR_TEXT_3,
+  GADGET_ID_BD_COLOR_TEXT_4,
+  GADGET_ID_BD_COLOR_TEXT_5,
   GADGET_ID_ELEMENT_NAME,
 
   // text area identifiers
@@ -693,6 +700,14 @@ enum
   GADGET_ID_GAME_ENGINE_TYPE,
   GADGET_ID_LEVELSET_SAVE_MODE,
   GADGET_ID_BD_SCHEDULING_TYPE,
+  GADGET_ID_BD_COLOR_TYPE,
+  GADGET_ID_BD_COLOR_C64_B,
+  GADGET_ID_BD_COLOR_C64_0,
+  GADGET_ID_BD_COLOR_C64_1,
+  GADGET_ID_BD_COLOR_C64_2,
+  GADGET_ID_BD_COLOR_C64_3,
+  GADGET_ID_BD_COLOR_C64_4,
+  GADGET_ID_BD_COLOR_C64_5,
   GADGET_ID_WIND_DIRECTION,
   GADGET_ID_PLAYER_SPEED,
   GADGET_ID_BD_GRAVITY_DIRECTION,
@@ -741,6 +756,7 @@ enum
   GADGET_ID_SAVE_LEVELSET,
   GADGET_ID_ADD_CHANGE_PAGE,
   GADGET_ID_DEL_CHANGE_PAGE,
+  GADGET_ID_BD_SET_RANDOM_COLORS,
 
   // graphicbutton identifiers
 
@@ -995,6 +1011,13 @@ enum
   ED_TEXTINPUT_ID_LEVEL_AUTHOR,
   ED_TEXTINPUT_ID_LEVELSET_NAME,
   ED_TEXTINPUT_ID_LEVELSET_AUTHOR,
+  ED_TEXTINPUT_ID_BD_COLOR_TEXT_B,
+  ED_TEXTINPUT_ID_BD_COLOR_TEXT_0,
+  ED_TEXTINPUT_ID_BD_COLOR_TEXT_1,
+  ED_TEXTINPUT_ID_BD_COLOR_TEXT_2,
+  ED_TEXTINPUT_ID_BD_COLOR_TEXT_3,
+  ED_TEXTINPUT_ID_BD_COLOR_TEXT_4,
+  ED_TEXTINPUT_ID_BD_COLOR_TEXT_5,
   ED_TEXTINPUT_ID_ELEMENT_NAME,
 
   ED_NUM_TEXTINPUT
@@ -1006,6 +1029,9 @@ enum
 #define ED_TEXTINPUT_ID_LEVELSET_FIRST ED_TEXTINPUT_ID_LEVELSET_NAME
 #define ED_TEXTINPUT_ID_LEVELSET_LAST  ED_TEXTINPUT_ID_LEVELSET_AUTHOR
 
+#define ED_TEXTINPUT_ID_COLORS_FIRST   ED_TEXTINPUT_ID_BD_COLOR_TEXT_B
+#define ED_TEXTINPUT_ID_COLORS_LAST    ED_TEXTINPUT_ID_BD_COLOR_TEXT_5
+
 // values for text area gadgets
 enum
 {
@@ -1025,6 +1051,14 @@ enum
   ED_SELECTBOX_ID_GAME_ENGINE_TYPE,
   ED_SELECTBOX_ID_LEVELSET_SAVE_MODE,
   ED_SELECTBOX_ID_BD_SCHEDULING_TYPE,
+  ED_SELECTBOX_ID_BD_COLOR_TYPE,
+  ED_SELECTBOX_ID_BD_COLOR_C64_B,
+  ED_SELECTBOX_ID_BD_COLOR_C64_0,
+  ED_SELECTBOX_ID_BD_COLOR_C64_1,
+  ED_SELECTBOX_ID_BD_COLOR_C64_2,
+  ED_SELECTBOX_ID_BD_COLOR_C64_3,
+  ED_SELECTBOX_ID_BD_COLOR_C64_4,
+  ED_SELECTBOX_ID_BD_COLOR_C64_5,
   ED_SELECTBOX_ID_WIND_DIRECTION,
   ED_SELECTBOX_ID_PLAYER_SPEED,
   ED_SELECTBOX_ID_BD_GRAVITY_DIRECTION,
@@ -1067,6 +1101,9 @@ enum
 #define ED_SELECTBOX_ID_ENGINE_FIRST   ED_SELECTBOX_ID_BD_SCHEDULING_TYPE
 #define ED_SELECTBOX_ID_ENGINE_LAST    ED_SELECTBOX_ID_BD_SCHEDULING_TYPE
 
+#define ED_SELECTBOX_ID_COLORS_FIRST   ED_SELECTBOX_ID_BD_COLOR_C64_B
+#define ED_SELECTBOX_ID_COLORS_LAST    ED_SELECTBOX_ID_BD_COLOR_C64_5
+
 #define ED_SELECTBOX_ID_CUSTOM1_FIRST  ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE
 #define ED_SELECTBOX_ID_CUSTOM1_LAST   ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION
 #define ED_SELECTBOX_ID_CUSTOM2_FIRST  ED_SELECTBOX_ID_CUSTOM_MOVE_PATTERN
@@ -1096,6 +1133,7 @@ enum
   ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1,
   ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE,
   ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE,
+  ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS,
 
   ED_NUM_TEXTBUTTONS
 };
@@ -1627,6 +1665,25 @@ static boolean levelset_use_levelset_artwork = FALSE;
 static boolean levelset_copy_level_template = FALSE;
 static int levelset_save_mode = LEVELSET_SAVE_MODE_UPDATE;
 
+#define MAX_BD_COLORS                  7
+#define MAX_BD_COLOR_TEXT_LEN          10
+
+static boolean bd_color_type_changed = FALSE;
+static int bd_color_type_default = GD_COLOR_TYPE_RGB;
+static int bd_color_c64[MAX_BD_COLORS];
+static char bd_color_text[MAX_BD_COLORS][MAX_BD_COLOR_TEXT_LEN + 1];
+static int bd_color_default[MAX_BD_COLORS];
+static int *bd_color[MAX_BD_COLORS] =
+{
+  &level.bd_color_b,
+  &level.bd_color_0,
+  &level.bd_color_1,
+  &level.bd_color_2,
+  &level.bd_color_3,
+  &level.bd_color_4,
+  &level.bd_color_5,
+};
+
 static struct
 {
   int gadget_type_id;
@@ -2064,16 +2121,18 @@ static struct
   int gadget_id;
   int size;
   char *value;
-  char *text_above, *infotext;
+  char *text_above, *text_left, *text_right, *infotext;
 } textinput_info[ED_NUM_TEXTINPUT] =
 {
+  // ---------- level and editor settings -------------------------------------
+
   {
     ED_TEXTINPUT_ID_LEVEL_NAME,
     ED_LEVEL_SETTINGS_XPOS(0),                 ED_LEVEL_SETTINGS_YPOS(0),
     GADGET_ID_LEVEL_NAME,
     MAX_LEVEL_NAME_LEN,
     level.name,
-    "Title:", "Title for this level"
+    "Title:", NULL, NULL,                      "Enter title for this level"
   },
   {
     ED_TEXTINPUT_ID_LEVEL_AUTHOR,
@@ -2081,7 +2140,7 @@ static struct
     GADGET_ID_LEVEL_AUTHOR,
     MAX_LEVEL_AUTHOR_LEN,
     level.author,
-    "Author:", "Author for this level"
+    "Author:", NULL, NULL,                     "Enter author for this level"
   },
   {
     ED_TEXTINPUT_ID_LEVELSET_NAME,
@@ -2089,7 +2148,7 @@ static struct
     GADGET_ID_LEVELSET_NAME,
     MAX_LEVEL_NAME_LEN,
     levelset_name,
-    "Title:", "Title for this or new level set"
+    "Title:", NULL, NULL,                      "Enter title for this or new level set"
   },
   {
     ED_TEXTINPUT_ID_LEVELSET_AUTHOR,
@@ -2097,15 +2156,77 @@ static struct
     GADGET_ID_LEVELSET_AUTHOR,
     MAX_LEVEL_AUTHOR_LEN,
     levelset_author,
-    "Author:", "Author for this or new level set"
+    "Author:", NULL, NULL,                     "Enter author for this or new level set"
+  },
+
+  // ---------- engine settings: colors ---------------------------------------
+
+  {
+    ED_TEXTINPUT_ID_BD_COLOR_TEXT_B,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(1),
+    GADGET_ID_BD_COLOR_TEXT_B,
+    MAX_BD_COLOR_TEXT_LEN,
+    bd_color_text[0],
+    NULL, "Border color:      ", NULL,         "Enter border color (not used)"
+  },
+  {
+    ED_TEXTINPUT_ID_BD_COLOR_TEXT_0,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(2),
+    GADGET_ID_BD_COLOR_TEXT_0,
+    MAX_BD_COLOR_TEXT_LEN,
+    bd_color_text[1],
+    NULL, "Background color:  ", NULL,         "Enter background color (C64 graphics)"
+  },
+  {
+    ED_TEXTINPUT_ID_BD_COLOR_TEXT_1,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(3),
+    GADGET_ID_BD_COLOR_TEXT_1,
+    MAX_BD_COLOR_TEXT_LEN,
+    bd_color_text[2],
+    NULL, "Sand color:        ", NULL,         "Enter sand color (C64 graphics)"
+  },
+  {
+    ED_TEXTINPUT_ID_BD_COLOR_TEXT_2,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(4),
+    GADGET_ID_BD_COLOR_TEXT_2,
+    MAX_BD_COLOR_TEXT_LEN,
+    bd_color_text[3],
+    NULL, "Steel wall color:  ", NULL,         "Enter steel wall color (C64 graphics)"
+  },
+  {
+    ED_TEXTINPUT_ID_BD_COLOR_TEXT_3,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(5),
+    GADGET_ID_BD_COLOR_TEXT_3,
+    MAX_BD_COLOR_TEXT_LEN,
+    bd_color_text[4],
+    NULL, "Wall color:        ", NULL,         "Enter wall color (C64 graphics)"
+  },
+  {
+    ED_TEXTINPUT_ID_BD_COLOR_TEXT_4,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(6),
+    GADGET_ID_BD_COLOR_TEXT_4,
+    MAX_BD_COLOR_TEXT_LEN,
+    bd_color_text[5],
+    NULL, "Amoeba color:      ", NULL,         "Enter amoeba color (C64 graphics)"
+  },
+  {
+    ED_TEXTINPUT_ID_BD_COLOR_TEXT_5,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(7),
+    GADGET_ID_BD_COLOR_TEXT_5,
+    MAX_BD_COLOR_TEXT_LEN,
+    bd_color_text[6],
+    NULL, "Slime color:       ", NULL,         "Enter slime color (C64 graphics)"
   },
+
+  // ---------- element settings: configure (several elements) ----------------
+
   {
     ED_TEXTINPUT_ID_ELEMENT_NAME,
     -1, -1,    // these values are not constant, but can change at runtime
     GADGET_ID_ELEMENT_NAME,
     MAX_ELEMENT_NAME_LEN - 2,                  // currently 2 chars less editable
     custom_element.description,
-    NULL, "Element name"
+    NULL, NULL, NULL,                          "Enter element name"
   }
 };
 
@@ -2848,6 +2969,38 @@ static struct ValueTextInfo options_bd_scheduling_type[] =
   { -1,                                          NULL                          }
 };
 
+static struct ValueTextInfo options_bd_color_type[] =
+{
+  { 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 options_bd_color_c64_name[] =
+{
+  { GD_COLOR_INDEX_BLACK,              "Black"                         },
+  { GD_COLOR_INDEX_WHITE,              "White"                         },
+  { GD_COLOR_INDEX_RED,                        "Red"                           },
+  { GD_COLOR_INDEX_CYAN,               "Cyan"                          },
+  { GD_COLOR_INDEX_PURPLE,             "Purple"                        },
+  { GD_COLOR_INDEX_GREEN,              "Green"                         },
+  { GD_COLOR_INDEX_BLUE,               "Blue"                          },
+  { GD_COLOR_INDEX_YELLOW,             "Yellow"                        },
+  { GD_COLOR_INDEX_ORANGE,             "Orange"                        },
+  { GD_COLOR_INDEX_BROWN,              "Brown"                         },
+  { GD_COLOR_INDEX_LIGHTRED,           "Light red"                     },
+  { GD_COLOR_INDEX_GRAY1,              "Dark gray"                     },
+  { GD_COLOR_INDEX_GRAY2,              "Gray"                          },
+  { GD_COLOR_INDEX_LIGHTGREEN,         "Light green"                   },
+  { GD_COLOR_INDEX_LIGHTBLUE,          "Light blue"                    },
+  { GD_COLOR_INDEX_GRAY3,              "Light gray"                    },
+
+  { -1,                                          NULL                          }
+};
+
 static struct ValueTextInfo *action_arg_modes[] =
 {
   options_action_mode_none,
@@ -2955,6 +3108,80 @@ static struct
 
   // ---------- engine settings: colors ---------------------------------------
 
+  {
+    ED_SELECTBOX_ID_BD_COLOR_TYPE,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(0),
+    GADGET_ID_BD_COLOR_TYPE,                   GADGET_ID_NONE,
+    -1,
+    options_bd_color_type,
+    &level.bd_color_type,
+    "Boulder Dash level colors:",
+    "Color palette type:", NULL,               "Select color palette type"
+  },
+  {
+    ED_SELECTBOX_ID_BD_COLOR_C64_B,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(1),
+    GADGET_ID_BD_COLOR_C64_B,                  GADGET_ID_NONE,
+    -1,
+    options_bd_color_c64_name,
+    &bd_color_c64[0],
+    NULL, "Border color:      ", NULL,         "Select border color (not used)"
+  },
+  {
+    ED_SELECTBOX_ID_BD_COLOR_C64_0,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(2),
+    GADGET_ID_BD_COLOR_C64_0,                  GADGET_ID_NONE,
+    -1,
+    options_bd_color_c64_name,
+    &bd_color_c64[1],
+    NULL, "Background color:  ", NULL,         "Select background color (C64 graphics)"
+  },
+  {
+    ED_SELECTBOX_ID_BD_COLOR_C64_1,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(3),
+    GADGET_ID_BD_COLOR_C64_1,                  GADGET_ID_NONE,
+    -1,
+    options_bd_color_c64_name,
+    &bd_color_c64[2],
+    NULL, "Sand color:        ", NULL,         "Select sand color (C64 graphics)"
+  },
+  {
+    ED_SELECTBOX_ID_BD_COLOR_C64_2,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(4),
+    GADGET_ID_BD_COLOR_C64_2,                  GADGET_ID_NONE,
+    -1,
+    options_bd_color_c64_name,
+    &bd_color_c64[3],
+    NULL, "Steel wall color:  ", NULL,         "Select steel wall color (C64 graphics)"
+  },
+  {
+    ED_SELECTBOX_ID_BD_COLOR_C64_3,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(5),
+    GADGET_ID_BD_COLOR_C64_3,                  GADGET_ID_NONE,
+    -1,
+    options_bd_color_c64_name,
+    &bd_color_c64[4],
+    NULL, "Wall color:        ", NULL,         "Select wall color (C64 graphics)"
+  },
+  {
+    ED_SELECTBOX_ID_BD_COLOR_C64_4,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(6),
+    GADGET_ID_BD_COLOR_C64_4,                  GADGET_ID_NONE,
+    -1,
+    options_bd_color_c64_name,
+    &bd_color_c64[5],
+    NULL, "Amoeba color:      ", NULL,         "Select amoeba color (C64 graphics)"
+  },
+  {
+    ED_SELECTBOX_ID_BD_COLOR_C64_5,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(7),
+    GADGET_ID_BD_COLOR_C64_5,                  GADGET_ID_NONE,
+    -1,
+    options_bd_color_c64_name,
+    &bd_color_c64[6],
+    NULL, "Slime color:       ", NULL,         "Select slime color (C64 graphics)"
+  },
+
   // ---------- element settings: configure (several elements) ----------------
 
   {
@@ -3291,7 +3518,7 @@ static struct
     -1,                                                -1,
     GADGET_ID_ENGINECONFIG_COLORS,             GADGET_ID_ENGINECONFIG_CONFIG,
     8,                                         "Colors",
-    NULL, NULL, NULL,                          "Configure game engine colors"
+    NULL, NULL, NULL,                          "Configure level colors"
   },
 
   // ---------- element settings (tabs) ---------------------------------------
@@ -3374,6 +3601,16 @@ static struct
     -1,                                                "Delete",
     NULL, NULL, NULL,                          "Delete current change page"
   },
+
+  // ---------- engine settings (buttons) -------------------------------------
+
+  {
+    ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS,
+    ED_ENGINE_SETTINGS_XPOS(0),                        ED_ENGINE_SETTINGS_YPOS(8),
+    GADGET_ID_BD_SET_RANDOM_COLORS,            GADGET_ID_NONE,
+    -1,                                                "Set random colors",
+    NULL, NULL, NULL,                          "Create and set random level colors"
+  },
 };
 
 static struct
@@ -7865,8 +8102,7 @@ static void getEditorGraphicAndFrame(int element, int *graphic, int *frame, bool
 {
   if (use_editor_gfx)
   {
-    *graphic = el2edimg(element);
-    *frame = 0;
+    el2edimg_with_frame(element, graphic, frame);
   }
   else
   {
@@ -7876,21 +8112,6 @@ static void getEditorGraphicAndFrame(int element, int *graphic, int *frame, bool
              ANIM_MODE(*graphic) == ANIM_CE_SCORE ?
              custom_element.collect_score_initial : FrameCounter);
   }
-
-  if (*graphic == IMG_UNKNOWN)
-  {
-    // no graphic defined -- if BD style, try to get runtime ("effect") element graphics
-    // (normal BD style elements have graphics, but runtime ("effects") elements do not)
-    int element_bd = map_element_RND_to_BD_cave(element);
-
-    if (element_bd != O_UNKNOWN)
-    {
-      struct GraphicInfo_BD *g_bd = &graphic_info_bd_object[element_bd][0];
-
-      *graphic = g_bd->graphic;
-      *frame   = g_bd->frame;
-    }
-  }
 }
 
 static void getEditorGraphicSource(int element, int tile_size, Bitmap **bitmap,
@@ -8419,7 +8640,11 @@ static void CreateTextInputGadgets(void)
       y = ED_SETTINGS_Y(textinput_info[i].y);
     }
 
-    sprintf(infotext, "Enter %s", textinput_info[i].infotext);
+    // determine horizontal offset for leading text
+    if (textinput_info[i].text_left != NULL)
+      x += getTextWidthForGadget(textinput_info[i].text_left);
+
+    sprintf(infotext, "%s", textinput_info[i].infotext);
     infotext[max_infotext_len] = '\0';
 
     gi = CreateGadget(GDI_CUSTOM_ID, id,
@@ -9170,12 +9395,23 @@ static void MapTextInputGadget(int id)
   int font_nr = FONT_TEXT_1;
   int font_height = getFontHeight(font_nr);
   struct GadgetInfo *gi = level_editor_gadget[textinput_info[id].gadget_id];
+  int xoffset_left = getTextWidthForGadget(textinput_info[id].text_left);
+  int xoffset_right = ED_GADGET_TEXT_DISTANCE;
   int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
-  int x_above = ED_SETTINGS_X(textinput_info[id].x);
-  int y_above = ED_SETTINGS_Y(textinput_info[id].y) - yoffset_above;
+  int yoffset = (gi->height - font_height) / 2;
+  int x_left = gi->x - xoffset_left;
+  int x_right = gi->x + gi->width + xoffset_right;
+  int y_above = gi->y - yoffset_above;
+  int y = gi->y + yoffset;
 
   if (textinput_info[id].text_above)
-    DrawTextS(x_above, y_above, font_nr, textinput_info[id].text_above);
+    DrawText(x_left, y_above, textinput_info[id].text_above, font_nr);
+
+  if (textinput_info[id].text_left)
+    DrawText(x_left, y, textinput_info[id].text_left, font_nr);
+
+  if (textinput_info[id].text_right)
+    DrawText(x_right, y, textinput_info[id].text_right, font_nr);
 
   ModifyGadget(gi, GDI_TEXT_VALUE, textinput_info[id].value, GDI_END);
 
@@ -9215,11 +9451,10 @@ static void MapSelectboxGadget(int id)
   int x_left = gi->x - xoffset_left;
   int x_right = gi->x + gi->width + xoffset_right;
   int y_above = gi->y - yoffset_above;
-  int x = gi->x;
   int y = gi->y + yoffset;
 
   if (selectbox_info[id].text_above)
-    DrawText(x, y_above, selectbox_info[id].text_above, font_nr);
+    DrawText(x_left, y_above, selectbox_info[id].text_above, font_nr);
 
   if (selectbox_info[id].text_left)
     DrawText(x_left, y, selectbox_info[id].text_left, font_nr);
@@ -10351,30 +10586,10 @@ static void InitDrawingElements(void)
   if (level.game_engine_type == game_engine_type_last)
     return;
 
-  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
-  {
-    new_element1 = EL_BD_WALL;
-    new_element2 = EL_EMPTY;
-    new_element3 = EL_BD_SAND;
-  }
-  else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
-  {
-    new_element1 = EL_SP_CHIP_SINGLE;
-    new_element2 = EL_EMPTY;
-    new_element3 = EL_SP_BASE;
-  }
-  else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
-  {
-    new_element1 = EL_MM_MIRROR_START;
-    new_element2 = EL_EMPTY;
-    new_element3 = EL_MM_WOODEN_WALL;
-  }
-  else
-  {
-    new_element1 = EL_WALL;
-    new_element2 = EL_EMPTY;
-    new_element3 = EL_SAND;
-  }
+  // select drawing elements according to game engine type
+  new_element1 = getDrawingElement(EL_WALL);
+  new_element2 = getDrawingElement(EL_EMPTY);
+  new_element3 = getDrawingElement(EL_SAND);
 
   game_engine_type_last = level.game_engine_type;
 }
@@ -11173,9 +11388,135 @@ static void DrawEngineConfigConfig(void)
     MapSelectboxGadget(i);
 }
 
+static int GetCommonColorType_BD(void)
+{
+  int bd_color_type = *bd_color[0] >> 24;
+  int i;
+
+  // check if all colors have the same color type
+  for (i = 1; i < MAX_BD_COLORS; i++)
+    if ((*bd_color[i] >> 24) != bd_color_type)
+      return GD_COLOR_TYPE_RGB;
+
+  return bd_color_type;
+}
+
+void SetDefaultLevelColorType_BD(void)
+{
+  bd_color_type_default = GetCommonColorType_BD();
+
+  level.bd_color_type = bd_color_type_default;
+}
+
+void SetDefaultLevelColors_BD(void)
+{
+  int i;
+
+  for (i = 0; i < MAX_BD_COLORS; i++)
+    bd_color_default[i] = *bd_color[i];
+}
+
+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, bd_color_type);
+
+  // copy colors to level editor
+  level.bd_color_b = cave->colorb;
+  level.bd_color_0 = cave->color0;
+  level.bd_color_1 = cave->color1;
+  level.bd_color_2 = cave->color2;
+  level.bd_color_3 = cave->color3;
+  level.bd_color_4 = cave->color4;
+  level.bd_color_5 = cave->color5;
+}
+
+static void DrawColorBox_BD(int nr)
+{
+  int id = ED_SELECTBOX_ID_COLORS_FIRST + nr;
+  struct GadgetInfo *gi = level_editor_gadget[selectbox_info[id].gadget_id];
+  int graphic = IMG_EDITOR_CHECKBOX;
+  struct GraphicInfo *gd = &graphic_info[graphic];
+  int offset = ED_GADGET_TEXT_DISTANCE;
+  int x1 = gi->x - offset - gd->width;
+  int y1 = gi->y;
+  int x2 = x1 + offset;
+  int y2 = y1 + offset;
+  int xsize1 = gd->width;
+  int ysize1 = gd->height;
+  int xsize2 = xsize1 - 2 * offset;
+  int ysize2 = ysize1 - 2 * offset;
+  int bd_color_x = *bd_color[nr];
+  int r = gd_color_get_r(bd_color_x);
+  int g = gd_color_get_g(bd_color_x);
+  int b = gd_color_get_b(bd_color_x);
+  Pixel color = SDL_MapRGB(drawto->surface->format, r, g, b);
+
+  BlitBitmap(gd->bitmap, drawto, gd->src_x, gd->src_y, xsize1, ysize1, x1, y1);
+  FillRectangle(drawto, x2, y2, xsize2, ysize2, color);
+}
+
 static void DrawEngineConfigColors(void)
 {
-  // (no settings yet)
+  int i;
+
+  if (bd_color_type_changed)
+  {
+    if (level.bd_color_type != GD_COLOR_TYPE_RGB && level.bd_color_type != GetCommonColorType_BD())
+    {
+      // color type switched to non-RGB colors, but using different color type => reset colors
+
+      if (level.bd_color_type == bd_color_type_default)
+      {
+       // color type switched to same color type as default colors => reset to defaults
+       for (i = 0; i < MAX_BD_COLORS; i++)
+         *bd_color[i] = bd_color_default[i];
+      }
+      else
+      {
+       // color type switched to different color type as default colors => use random colors
+       SetRandomLevelColors_BD(level.bd_color_type);
+      }
+    }
+
+    bd_color_type_changed = FALSE;
+  }
+
+  // copy level colors to either C64-style color index or color text
+  for (i = 0; i < MAX_BD_COLORS; i++)
+  {
+    int bd_color_x = (level.bd_color_type == GD_COLOR_TYPE_C64 ? *bd_color[i] & 0x0f :
+                     level.bd_color_type == GD_COLOR_TYPE_RGB ? gd_color_get_rgb(*bd_color[i]) :
+                     *bd_color[i]);
+
+    if (level.bd_color_type == GD_COLOR_TYPE_C64)
+      bd_color_c64[i] = bd_color_x;
+    else
+      snprintf(bd_color_text[i], sizeof(bd_color_text[i]), "%s", gd_color_get_string(bd_color_x));
+  }
+
+  MapSelectboxGadget(ED_SELECTBOX_ID_BD_COLOR_TYPE);
+
+  if (level.bd_color_type == GD_COLOR_TYPE_C64)
+  {
+    // draw selectbox gadgets
+    for (i = ED_SELECTBOX_ID_COLORS_FIRST; i <= ED_SELECTBOX_ID_COLORS_LAST; i++)
+      MapSelectboxGadget(i);
+  }
+  else
+  {
+    // draw text input gadgets
+    for (i = ED_TEXTINPUT_ID_COLORS_FIRST; i <= ED_TEXTINPUT_ID_COLORS_LAST; i++)
+      MapTextInputGadget(i);
+  }
+
+  for (i = 0; i < MAX_BD_COLORS; i++)
+    DrawColorBox_BD(i);
+
+  MapTextbuttonGadget(ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS);
 }
 
 static void DrawLevelConfigEngine(void)
@@ -11196,6 +11537,11 @@ static void DrawLevelConfigWindow(void)
 
   stick_element_properties_window = FALSE;
 
+  // make sure that previous level config edit mode exists for this level
+  if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_ENGINE &&
+      level.game_engine_type != GAME_ENGINE_TYPE_BD)
+    edit_mode_levelconfig = ED_MODE_LEVELCONFIG_LEVEL;
+
   SetAutomaticNumberOfGemsNeeded();
 
   UnmapLevelEditorFieldGadgets();
@@ -11621,33 +11967,38 @@ static void DrawPropertiesInfo(void)
 
   ypos += 2 * MAX(font1_height, font2_height);
 
-  // ----- print standard properties of this element
+  // ----- print standard properties of this element (only for certain game engines)
 
-  DrawTextS(xpos, ypos, font1_nr, properties_text);
+  if (level.game_engine_type == GAME_ENGINE_TYPE_RND ||
+      level.game_engine_type == GAME_ENGINE_TYPE_EM ||
+      level.game_engine_type == GAME_ENGINE_TYPE_SP)
+  {
+    DrawTextS(xpos, ypos, font1_nr, properties_text);
 
-  ypos += line1_height;
+    ypos += line1_height;
 
-  for (i = 0; properties[i].value != -1; i++)
-  {
-    if (!HAS_PROPERTY(properties_element, properties[i].value))
-      continue;
+    for (i = 0; properties[i].value != -1; i++)
+    {
+      if (!HAS_PROPERTY(properties_element, properties[i].value))
+       continue;
 
-    DrawTextS(xpos, ypos, font2_nr, properties[i].text);
+      DrawTextS(xpos, ypos, font2_nr, properties[i].text);
 
-    ypos += font2_height;
+      ypos += font2_height;
 
-    num_standard_properties++;
-  }
+      num_standard_properties++;
+    }
 
-  if (num_standard_properties == 0)
-  {
-    DrawTextS(xpos + properties_text_len, ypos - line1_height + font2_yoffset,
-             font2_nr, none_text);
+    if (num_standard_properties == 0)
+    {
+      DrawTextS(xpos + properties_text_len, ypos - line1_height + font2_yoffset,
+               font2_nr, none_text);
 
-    ypos -= (line1_height - font1_height);
-  }
+      ypos -= (line1_height - font1_height);
+    }
 
-  ypos += MAX(font1_height, font2_height);
+    ypos += MAX(font1_height, font2_height);
+  }
 
   // ----- print special description of this element
 
@@ -12711,9 +13062,18 @@ static void DrawEditorElementAnimation(int x, int y)
   int graphic;
   int frame;
 
-  getEditorGraphicAndFrame(properties_element, &graphic, &frame, FALSE);
+  if (IS_BD_RUNTIME_ELEMENT(properties_element))
+  {
+    getEditorGraphicAndFrame(properties_element, &graphic, &frame, TRUE);
 
-  DrawFixedGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
+    DrawFixedGraphicExt(drawto, x, y, graphic, frame);
+  }
+  else
+  {
+    getEditorGraphicAndFrame(properties_element, &graphic, &frame, FALSE);
+
+    DrawFixedGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
+  }
 }
 
 static void DrawEditorElementName(int x, int y, int font_nr)
@@ -15986,6 +16346,15 @@ static void HandleTextInputGadgets(struct GadgetInfo *gi)
 
     ModifyEditorElementList(); // update changed button info text
   }
+  else if (type_id >= ED_TEXTINPUT_ID_COLORS_FIRST &&
+          type_id <= ED_TEXTINPUT_ID_COLORS_LAST)
+  {
+    int pos = type_id - ED_TEXTINPUT_ID_COLORS_FIRST;
+
+    *bd_color[pos] = gd_color_get_from_string(bd_color_text[pos]);
+
+    DrawColorBox_BD(pos);
+  }
 
   // do not mark level as modified for certain non-level-changing gadgets
   if (type_id >= ED_TEXTINPUT_ID_LEVELSET_FIRST &&
@@ -16055,6 +16424,37 @@ static void HandleSelectboxGadgets(struct GadgetInfo *gi)
     // update BD cycle delay counter gadgets depending on BD scheduling type
     DrawLevelConfigWindow();
   }
+  else if (type_id == ED_SELECTBOX_ID_BD_COLOR_TYPE)
+  {
+    bd_color_type_changed = TRUE;
+
+    if (level.bd_color_type != GD_COLOR_TYPE_RGB && level.bd_color_type != GetCommonColorType_BD())
+    {
+      // color type switched to non-RGB colors, but using different color type => reset colors
+      char *message = (level.bd_color_type == bd_color_type_default ?
+                      "This will reset colors to defaults! Continue?" :
+                      "This will reset colors to random colors! Continue?");
+
+      if (!Request(message, REQ_ASK))
+      {
+       // keep current RGB colors
+       level.bd_color_type = GD_COLOR_TYPE_RGB;
+       bd_color_type_changed = FALSE;
+      }
+    }
+
+    // update BD color palette gadgets depending on BD color type
+    DrawLevelConfigWindow();
+  }
+  else if (type_id >= ED_SELECTBOX_ID_COLORS_FIRST &&
+          type_id <= ED_SELECTBOX_ID_COLORS_LAST)
+  {
+    int pos = type_id - ED_SELECTBOX_ID_COLORS_FIRST;
+
+    *bd_color[pos] = gd_c64_color(bd_color_c64[pos]);
+
+    DrawColorBox_BD(pos);
+  }
 
   // do not mark level as modified for certain non-level-changing gadgets
   if (type_id == ED_SELECTBOX_ID_LEVELSET_SAVE_MODE ||
@@ -16217,6 +16617,13 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
 
     level.changed = TRUE;
   }
+  else if (type_id == ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS)
+  {
+    SetRandomLevelColors_BD(level.bd_color_type);
+
+    // update BD color palette gadgets after setting random colors
+    DrawLevelConfigWindow();
+  }
 }
 
 static void HandleGraphicbuttonGadgets(struct GadgetInfo *gi)