fixed drawing native BD element graphics on properties page in editor
[rocksndiamonds.git] / src / editor.c
index 25853f868eea5dc67786bead6ee00b4cc0c90b72..5da47e5ecaccc60da999a2d97af0e0bf1cdf4ff7 100644 (file)
@@ -733,6 +733,7 @@ enum
   GADGET_ID_BD_REPLICATORS_ACTIVE,
   GADGET_ID_BD_CONVEYOR_BELTS_ACTIVE,
   GADGET_ID_BD_CONVEYOR_BELTS_CHANGED,
+  GADGET_ID_BD_WATER_CANNOT_FLOW_DOWN,
   GADGET_ID_ENVELOPE_AUTOWRAP,
   GADGET_ID_ENVELOPE_CENTERED,
   GADGET_ID_MM_LASER_RED,
@@ -1082,6 +1083,7 @@ enum
   ED_CHECKBUTTON_ID_BD_REPLICATORS_ACTIVE,
   ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_ACTIVE,
   ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_CHANGED,
+  ED_CHECKBUTTON_ID_BD_WATER_CANNOT_FLOW_DOWN,
   ED_CHECKBUTTON_ID_ENVELOPE_AUTOWRAP,
   ED_CHECKBUTTON_ID_ENVELOPE_CENTERED,
   ED_CHECKBUTTON_ID_MM_LASER_RED,
@@ -3850,6 +3852,14 @@ static struct
     NULL, NULL,
     "Change direction",                        "Switch conveyor belt direction"
   },
+  {
+    ED_CHECKBUTTON_ID_BD_WATER_CANNOT_FLOW_DOWN,
+    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(0),
+    GADGET_ID_BD_WATER_CANNOT_FLOW_DOWN, GADGET_ID_NONE,
+    &level.bd_water_cannot_flow_down,
+    NULL, NULL,
+    "Does not flow downwards",         "Water can only flow up, left and right"
+  },
   {
     ED_CHECKBUTTON_ID_ENVELOPE_AUTOWRAP,
     ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(1),
@@ -4914,6 +4924,141 @@ static int *editor_el_boulderdash_native_ptr = editor_el_boulderdash_native;
 static int num_editor_hl_boulderdash_native = ARRAY_SIZE(editor_hl_boulderdash_native);
 static int num_editor_el_boulderdash_native = ARRAY_SIZE(editor_el_boulderdash_native);
 
+static int editor_hl_boulderdash_effects[] =
+{
+  EL_INTERNAL_CASCADE_BD_EFFECTS_ACTIVE,
+  EL_CHAR('B'),
+  EL_CHAR('D'),
+  EL_CHAR('E'),
+};
+
+static int editor_el_boulderdash_effects[] =
+{
+  EL_BD_DIAMOND_FALLING,
+  EL_BD_ROCK_FALLING,
+  EL_BD_MEGA_ROCK_FALLING,
+  EL_BD_FLYING_DIAMOND_FLYING,
+
+  EL_BD_FALLING_WALL_FALLING,
+  EL_BD_NITRO_PACK_FALLING,
+  EL_BD_NUT_FALLING,
+  EL_BD_FLYING_ROCK_FLYING,
+
+  EL_BD_PLAYER_GROWING_1,
+  EL_BD_PLAYER_GROWING_2,
+  EL_BD_PLAYER_GROWING_3,
+  EL_BD_PLAYER,
+
+  EL_BD_PLAYER_WITH_BOMB,
+  EL_BD_PLAYER_STIRRING,
+  EL_BD_EXIT_OPEN,
+  EL_BD_INVISIBLE_EXIT_OPEN,
+
+  EL_BD_BLADDER_1,
+  EL_BD_BLADDER_2,
+  EL_BD_BLADDER_3,
+  EL_BD_BLADDER_4,
+
+  EL_BD_BLADDER_5,
+  EL_BD_BLADDER_6,
+  EL_BD_BLADDER_7,
+  EL_BD_BLADDER_8,
+
+  EL_BD_SAND_2,
+  EL_BD_COW_ENCLOSED_1,
+  EL_BD_COW_ENCLOSED_2,
+  EL_BD_COW_ENCLOSED_3,
+
+  EL_BD_COW_ENCLOSED_4,
+  EL_BD_COW_ENCLOSED_5,
+  EL_BD_COW_ENCLOSED_6,
+  EL_BD_COW_ENCLOSED_7,
+
+  EL_BD_WATER_1,
+  EL_BD_WATER_2,
+  EL_BD_WATER_3,
+  EL_BD_WATER_4,
+
+  EL_BD_WATER_5,
+  EL_BD_WATER_6,
+  EL_BD_WATER_7,
+  EL_BD_WATER_8,
+
+  EL_BD_WATER_9,
+  EL_BD_WATER_10,
+  EL_BD_WATER_11,
+  EL_BD_WATER_12,
+
+  EL_BD_WATER_13,
+  EL_BD_WATER_14,
+  EL_BD_WATER_15,
+  EL_BD_WATER_16,
+
+  EL_BD_BOMB_TICKING_1,
+  EL_BD_BOMB_TICKING_2,
+  EL_BD_BOMB_TICKING_3,
+  EL_BD_BOMB_TICKING_4,
+
+  EL_BD_BOMB_TICKING_5,
+  EL_BD_BOMB_TICKING_6,
+  EL_BD_BOMB_TICKING_7,
+  EL_EMPTY,
+
+  EL_BD_BOMB_EXPLODING_1,
+  EL_BD_BOMB_EXPLODING_2,
+  EL_BD_BOMB_EXPLODING_3,
+  EL_BD_BOMB_EXPLODING_4,
+
+  EL_BD_NUT_BREAKING_1,
+  EL_BD_NUT_BREAKING_2,
+  EL_BD_NUT_BREAKING_3,
+  EL_BD_NUT_BREAKING_4,
+
+  EL_BD_EXPLODING_1,
+  EL_BD_EXPLODING_2,
+  EL_BD_EXPLODING_3,
+  EL_BD_EXPLODING_4,
+
+  EL_BD_EXPLODING_5,
+  EL_BD_TIME_PENALTY,
+  EL_BD_DIAMOND_GROWING_1,
+  EL_BD_DIAMOND_GROWING_2,
+
+  EL_BD_DIAMOND_GROWING_3,
+  EL_BD_DIAMOND_GROWING_4,
+  EL_BD_DIAMOND_GROWING_5,
+  EL_BD_NITRO_PACK_EXPLODING,
+
+  EL_BD_NITRO_PACK_EXPLODING_1,
+  EL_BD_NITRO_PACK_EXPLODING_2,
+  EL_BD_NITRO_PACK_EXPLODING_3,
+  EL_BD_NITRO_PACK_EXPLODING_4,
+
+  EL_BD_ROCK_GROWING_1,
+  EL_BD_ROCK_GROWING_2,
+  EL_BD_ROCK_GROWING_3,
+  EL_BD_ROCK_GROWING_4,
+
+  EL_BD_STEELWALL_GROWING_1,
+  EL_BD_STEELWALL_GROWING_2,
+  EL_BD_STEELWALL_GROWING_3,
+  EL_BD_STEELWALL_GROWING_4,
+
+  EL_BD_CLOCK_GROWING_1,
+  EL_BD_CLOCK_GROWING_2,
+  EL_BD_CLOCK_GROWING_3,
+  EL_BD_CLOCK_GROWING_4,
+
+  EL_BD_GHOST_EXPLODING_1,
+  EL_BD_GHOST_EXPLODING_2,
+  EL_BD_GHOST_EXPLODING_3,
+  EL_BD_GHOST_EXPLODING_4,
+};
+static int *editor_hl_boulderdash_effects_ptr = editor_hl_boulderdash_effects;
+static int *editor_el_boulderdash_effects_ptr = editor_el_boulderdash_effects;
+static int num_editor_hl_boulderdash_effects = ARRAY_SIZE(editor_hl_boulderdash_effects);
+static int num_editor_el_boulderdash_effects = ARRAY_SIZE(editor_el_boulderdash_effects);
+
 static int editor_hl_emerald_mine[] =
 {
   EL_INTERNAL_CASCADE_EM_ACTIVE,
@@ -6325,6 +6470,7 @@ static boolean setup_editor_cascade_never = FALSE;
 static boolean setup_editor_el_players                 = TRUE;
 static boolean setup_editor_el_boulderdash             = TRUE;
 static boolean setup_editor_el_boulderdash_native      = TRUE;
+static boolean setup_editor_el_boulderdash_effects     = TRUE;
 static boolean setup_editor_el_emerald_mine            = TRUE;
 static boolean setup_editor_el_emerald_mine_club       = TRUE;
 static boolean setup_editor_el_more                    = TRUE;
@@ -6377,6 +6523,12 @@ editor_elements_info[] =
     &editor_hl_boulderdash_native_ptr, &num_editor_hl_boulderdash_native,
     &editor_el_boulderdash_native_ptr, &num_editor_el_boulderdash_native
   },
+  {
+    &setup_editor_el_boulderdash_effects,
+    &setup.editor_cascade.el_bd_effects,
+    &editor_hl_boulderdash_effects_ptr,        &num_editor_hl_boulderdash_effects,
+    &editor_el_boulderdash_effects_ptr,        &num_editor_el_boulderdash_effects
+  },
   {
     &setup_editor_el_emerald_mine,
     &setup.editor_cascade.el_em,
@@ -6677,6 +6829,7 @@ static void ReinitializeElementList_EnableSections(void)
   setup_editor_el_players              = TRUE;
   setup_editor_el_boulderdash          = TRUE;
   setup_editor_el_boulderdash_native   = TRUE;
+  setup_editor_el_boulderdash_effects  = TRUE;
   setup_editor_el_emerald_mine         = TRUE;
   setup_editor_el_emerald_mine_club    = TRUE;
   setup_editor_el_more                 = TRUE;
@@ -6700,6 +6853,7 @@ static void ReinitializeElementList_EnableSections(void)
     setup_editor_el_players            = FALSE;
     setup_editor_el_boulderdash                = FALSE;
     setup_editor_el_boulderdash_native = FALSE;
+    setup_editor_el_boulderdash_effects        = FALSE;
     setup_editor_el_emerald_mine       = FALSE;
     setup_editor_el_emerald_mine_club  = FALSE;
     setup_editor_el_more               = FALSE;
@@ -6731,6 +6885,7 @@ static void ReinitializeElementList_EnableSections(void)
   if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
   {
     setup_editor_el_boulderdash_native = FALSE;
+    setup_editor_el_boulderdash_effects        = FALSE;
     setup_editor_el_mirror_magic       = FALSE;
     setup_editor_el_deflektor          = FALSE;
   }
@@ -6756,6 +6911,7 @@ static void ReinitializeElementList_EnableSections(void)
   {
     setup_editor_el_boulderdash                = FALSE;
     setup_editor_el_boulderdash_native = FALSE;
+    setup_editor_el_boulderdash_effects        = FALSE;
     setup_editor_el_more               = FALSE;
     setup_editor_el_sokoban            = FALSE;
     setup_editor_el_supaplex           = FALSE;
@@ -6772,6 +6928,7 @@ static void ReinitializeElementList_EnableSections(void)
     setup_editor_el_players            = FALSE;
     setup_editor_el_boulderdash                = FALSE;
     setup_editor_el_boulderdash_native = FALSE;
+    setup_editor_el_boulderdash_effects        = FALSE;
     setup_editor_el_emerald_mine       = FALSE;
     setup_editor_el_emerald_mine_club  = FALSE;
     setup_editor_el_more               = FALSE;
@@ -6790,6 +6947,7 @@ static void ReinitializeElementList_EnableSections(void)
     setup_editor_el_players            = FALSE;
     setup_editor_el_boulderdash                = FALSE;
     setup_editor_el_boulderdash_native = FALSE;
+    setup_editor_el_boulderdash_effects        = FALSE;
     setup_editor_el_emerald_mine       = FALSE;
     setup_editor_el_emerald_mine_club  = FALSE;
     setup_editor_el_more               = FALSE;
@@ -7198,10 +7356,47 @@ static void ScrollEditorLevel(int from_x, int from_y, int scroll)
   BackToFront();
 }
 
+static void getEditorGraphicAndFrame(int element, int *graphic, int *frame, boolean use_editor_gfx)
+{
+  if (use_editor_gfx)
+  {
+    *graphic = el2edimg(element);
+    *frame = 0;
+  }
+  else
+  {
+    *graphic = el2img(element);
+    *frame = (ANIM_MODE(*graphic) == ANIM_CE_VALUE ?
+             custom_element.ce_value_fixed_initial :
+             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,
                                   int *x, int *y)
 {
-  getSizedGraphicSource(el2edimg(element), 0, tile_size, bitmap, x, y);
+  int graphic;
+  int frame;
+
+  getEditorGraphicAndFrame(element, &graphic, &frame, TRUE);
+
+  getSizedGraphicSource(graphic, frame, tile_size, bitmap, x, y);
 }
 
 static void CreateControlButtons(void)
@@ -11137,7 +11332,8 @@ static boolean checkPropertiesConfig(int element)
       element == EL_BD_ROCK ||
       element == EL_BD_MEGA_ROCK ||
       element == EL_BD_SWEET ||
-      element == EL_BD_VOODOO_DOLL)
+      element == EL_BD_VOODOO_DOLL ||
+      element == EL_BD_WATER)
   {
     return TRUE;
   }
@@ -11504,6 +11700,11 @@ static void DrawPropertiesConfig(void)
     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_CHANGED);
   }
 
+  if (properties_element == EL_BD_WATER)
+  {
+    MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_WATER_CANNOT_FLOW_DOWN);
+  }
+
   // special case: slippery walls option for gems only available in R'n'D game engine
   if (IS_GEM(properties_element) && level.game_engine_type == GAME_ENGINE_TYPE_RND)
     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS);
@@ -11786,11 +11987,10 @@ static void DrawPropertiesChange(void)
 
 static void DrawEditorElementAnimation(int x, int y)
 {
-  int graphic = el2img(properties_element);
-  int frame = (ANIM_MODE(graphic) == ANIM_CE_VALUE ?
-              custom_element.ce_value_fixed_initial :
-              ANIM_MODE(graphic) == ANIM_CE_SCORE ?
-              custom_element.collect_score_initial : FrameCounter);
+  int graphic;
+  int frame;
+
+  getEditorGraphicAndFrame(properties_element, &graphic, &frame, FALSE);
 
   DrawFixedGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
 }