moved workaround for BD runtime elements in editor to separate function
[rocksndiamonds.git] / src / editor.c
index 2d3a9fb9f59823ceb60ae06f782eef3ef3cfba7b..6ec52ee30ac21c4100f3120c80d7c9d733b53696 100644 (file)
@@ -2167,7 +2167,7 @@ static struct
     GADGET_ID_BD_COLOR_TEXT_B,
     MAX_BD_COLOR_TEXT_LEN,
     bd_color_text[0],
-    NULL, "Border color:    ", NULL,           "Enter border color (not used)"
+    NULL, "Border color:      ", NULL,         "Enter border color (not used)"
   },
   {
     ED_TEXTINPUT_ID_BD_COLOR_TEXT_0,
@@ -2175,7 +2175,7 @@ static struct
     GADGET_ID_BD_COLOR_TEXT_0,
     MAX_BD_COLOR_TEXT_LEN,
     bd_color_text[1],
-    NULL, "Background color:", NULL,           "Enter background color (C64 graphics)"
+    NULL, "Background color:  ", NULL,         "Enter background color (C64 graphics)"
   },
   {
     ED_TEXTINPUT_ID_BD_COLOR_TEXT_1,
@@ -2183,7 +2183,7 @@ static struct
     GADGET_ID_BD_COLOR_TEXT_1,
     MAX_BD_COLOR_TEXT_LEN,
     bd_color_text[2],
-    NULL, "Sand color:      ", NULL,           "Enter sand color (C64 graphics)"
+    NULL, "Sand color:        ", NULL,         "Enter sand color (C64 graphics)"
   },
   {
     ED_TEXTINPUT_ID_BD_COLOR_TEXT_2,
@@ -2191,7 +2191,7 @@ static struct
     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)"
+    NULL, "Steel wall color:  ", NULL,         "Enter steel wall color (C64 graphics)"
   },
   {
     ED_TEXTINPUT_ID_BD_COLOR_TEXT_3,
@@ -2199,7 +2199,7 @@ static struct
     GADGET_ID_BD_COLOR_TEXT_3,
     MAX_BD_COLOR_TEXT_LEN,
     bd_color_text[4],
-    NULL, "Wall color:      ", NULL,           "Enter wall color (C64 graphics)"
+    NULL, "Wall color:        ", NULL,         "Enter wall color (C64 graphics)"
   },
   {
     ED_TEXTINPUT_ID_BD_COLOR_TEXT_4,
@@ -2207,7 +2207,7 @@ static struct
     GADGET_ID_BD_COLOR_TEXT_4,
     MAX_BD_COLOR_TEXT_LEN,
     bd_color_text[5],
-    NULL, "Amoeba color:    ", NULL,           "Enter amoeba color (C64 graphics)"
+    NULL, "Amoeba color:      ", NULL,         "Enter amoeba color (C64 graphics)"
   },
   {
     ED_TEXTINPUT_ID_BD_COLOR_TEXT_5,
@@ -2215,7 +2215,7 @@ static struct
     GADGET_ID_BD_COLOR_TEXT_5,
     MAX_BD_COLOR_TEXT_LEN,
     bd_color_text[6],
-    NULL, "Slime color:     ", NULL,           "Enter slime color (C64 graphics)"
+    NULL, "Slime color:       ", NULL,         "Enter slime color (C64 graphics)"
   },
 
   // ---------- element settings: configure (several elements) ----------------
@@ -3125,7 +3125,7 @@ static struct
     -1,
     options_bd_color_c64_name,
     &bd_color_c64[0],
-    NULL, "Border color:    ", NULL,           "Select border color (not used)"
+    NULL, "Border color:      ", NULL,         "Select border color (not used)"
   },
   {
     ED_SELECTBOX_ID_BD_COLOR_C64_0,
@@ -3134,7 +3134,7 @@ static struct
     -1,
     options_bd_color_c64_name,
     &bd_color_c64[1],
-    NULL, "Background color:", NULL,           "Select background color (C64 graphics)"
+    NULL, "Background color:  ", NULL,         "Select background color (C64 graphics)"
   },
   {
     ED_SELECTBOX_ID_BD_COLOR_C64_1,
@@ -3143,7 +3143,7 @@ static struct
     -1,
     options_bd_color_c64_name,
     &bd_color_c64[2],
-    NULL, "Sand color:      ", NULL,           "Select sand color (C64 graphics)"
+    NULL, "Sand color:        ", NULL,         "Select sand color (C64 graphics)"
   },
   {
     ED_SELECTBOX_ID_BD_COLOR_C64_2,
@@ -3152,7 +3152,7 @@ static struct
     -1,
     options_bd_color_c64_name,
     &bd_color_c64[3],
-    NULL, "Steel wall color:", NULL,           "Select steel wall color (C64 graphics)"
+    NULL, "Steel wall color:  ", NULL,         "Select steel wall color (C64 graphics)"
   },
   {
     ED_SELECTBOX_ID_BD_COLOR_C64_3,
@@ -3161,7 +3161,7 @@ static struct
     -1,
     options_bd_color_c64_name,
     &bd_color_c64[4],
-    NULL, "Wall color:      ", NULL,           "Select wall color (C64 graphics)"
+    NULL, "Wall color:        ", NULL,         "Select wall color (C64 graphics)"
   },
   {
     ED_SELECTBOX_ID_BD_COLOR_C64_4,
@@ -3170,7 +3170,7 @@ static struct
     -1,
     options_bd_color_c64_name,
     &bd_color_c64[5],
-    NULL, "Amoeba color:    ", NULL,           "Select amoeba color (C64 graphics)"
+    NULL, "Amoeba color:      ", NULL,         "Select amoeba color (C64 graphics)"
   },
   {
     ED_SELECTBOX_ID_BD_COLOR_C64_5,
@@ -3179,7 +3179,7 @@ static struct
     -1,
     options_bd_color_c64_name,
     &bd_color_c64[6],
-    NULL, "Slime color:     ", NULL,           "Select slime color (C64 graphics)"
+    NULL, "Slime color:       ", NULL,         "Select slime color (C64 graphics)"
   },
 
   // ---------- element settings: configure (several elements) ----------------
@@ -8102,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
   {
@@ -8113,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,
@@ -10602,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;
 }
@@ -11452,13 +11416,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;
@@ -11470,6 +11434,31 @@ static void SetRandomLevelColors_BD(void)
   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)
 {
   int i;
@@ -11489,7 +11478,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);
       }
     }
 
@@ -11524,6 +11513,9 @@ static void DrawEngineConfigColors(void)
       MapTextInputGadget(i);
   }
 
+  for (i = 0; i < MAX_BD_COLORS; i++)
+    DrawColorBox_BD(i);
+
   MapTextbuttonGadget(ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS);
 }
 
@@ -11545,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();
@@ -11970,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
 
@@ -13060,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);
+
+    DrawFixedGraphicExt(drawto, x, y, graphic, frame);
+  }
+  else
+  {
+    getEditorGraphicAndFrame(properties_element, &graphic, &frame, FALSE);
 
-  DrawFixedGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
+    DrawFixedGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
+  }
 }
 
 static void DrawEditorElementName(int x, int y, int font_nr)
@@ -16341,6 +16352,8 @@ static void HandleTextInputGadgets(struct GadgetInfo *gi)
     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
@@ -16439,6 +16452,8 @@ static void HandleSelectboxGadgets(struct GadgetInfo *gi)
     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
@@ -16604,7 +16619,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();