rnd-20040117-1-src
[rocksndiamonds.git] / src / editor.c
index 07401c10e352f2342d60942f4ef2c920ae2abe42..6dd5fd3fd62f502147301b1568c8e1b364a1b8c7 100644 (file)
@@ -2209,11 +2209,7 @@ static int editor_el_more[] =
   EL_BD_FIREFLY,
 
   EL_MOLE_LEFT,
-#if 0
-  EL_MAZE_RUNNER,
-#else
   EL_EMPTY,
-#endif
   EL_MOLE_RIGHT,
   EL_PACMAN,
 
@@ -2270,7 +2266,7 @@ static int editor_el_sokoban[] =
   EL_SOKOBAN_OBJECT,
   EL_SOKOBAN_FIELD_EMPTY,
   EL_SOKOBAN_FIELD_FULL,
-  EL_STEELWALL,
+  EL_SOKOBAN_FIELD_PLAYER,
 };
 static int *editor_hl_sokoban_ptr = editor_hl_sokoban;
 static int *editor_el_sokoban_ptr = editor_el_sokoban;
@@ -4880,6 +4876,40 @@ static int setSelectboxValue(int selectbox_id, int new_value)
 
 static void copy_custom_element_settings(int element_from, int element_to)
 {
+#if 1
+  struct ElementInfo ei_to_old = element_info[element_to];
+  struct ElementInfo *ei_from = &element_info[element_from];
+  struct ElementInfo *ei_to = &element_info[element_to];
+  int i;
+
+  /* ---------- copy whole element structure ---------- */
+  *ei_to = *ei_from;
+
+  /* ---------- restore structure pointers which cannot be copied ---------- */
+  ei_to->token_name         = ei_to_old.token_name;
+  ei_to->class_name         = ei_to_old.class_name;
+  ei_to->editor_description = ei_to_old.editor_description;
+  ei_to->custom_description = ei_to_old.custom_description;
+  ei_to->change_page        = ei_to_old.change_page;
+  ei_to->change             = ei_to_old.change;
+  ei_to->group              = ei_to_old.group;
+
+  /* ---------- copy element base properties ---------- */
+  Properties[element_to][EP_BITFIELD_BASE] =
+    Properties[element_from][EP_BITFIELD_BASE];
+
+  /* ---------- reinitialize and copy change pages ---------- */
+  setElementChangePages(ei_to, ei_to->num_change_pages);
+
+  for (i=0; i < ei_to->num_change_pages; i++)
+    ei_to->change_page[i] = ei_from->change_page[i];
+
+  /* ---------- copy group element info ---------- */
+  if (ei_from->group != NULL && ei_to->group != NULL)  /* group or internal */
+    *ei_to->group = *ei_from->group;
+
+#else
+
   struct ElementInfo *ei_from = &element_info[element_from];
   struct ElementInfo *ei_to = &element_info[element_to];
   int i, x, y;
@@ -4952,6 +4982,7 @@ static void copy_custom_element_settings(int element_from, int element_to)
 
     change_to->sides = change_from->sides;
   }
+#endif
 
   /* mark this custom element as modified */
   ei_to->modified_settings = TRUE;
@@ -4971,7 +5002,7 @@ static void replace_custom_element_in_settings(int element_from,
        if (ei->content[x][y] == element_from)
          ei->content[x][y] = element_to;
 
-    for (j=0; j < ei->num_change_pages; j++)
+    for (j = 0; j < ei->num_change_pages; j++)
     {
       struct ElementChangeInfo *change = &ei->change_page[j];
 
@@ -4986,6 +5017,11 @@ static void replace_custom_element_in_settings(int element_from,
          if (change->content[x][y] == element_from)
            change->content[x][y] = element_to;
     }
+
+    if (ei->group != NULL)                             /* group or internal */
+      for (j = 0; j < MAX_ELEMENTS_IN_GROUP; j++)
+       if (ei->group->element[j] == element_from)
+         ei->group->element[j] = element_to;
   }
 }
 
@@ -5000,8 +5036,22 @@ static void replace_custom_element_in_playfield(int element_from,
        Feld[x][y] = element_to;
 }
 
-static void CopyCustomElement(int element_old, int element_new, int copy_mode)
+static boolean CopyCustomElement(int element_old, int element_new,
+                                int copy_mode)
 {
+  if (IS_CUSTOM_ELEMENT(element_old) && !IS_CUSTOM_ELEMENT(element_new))
+  {
+    Request("Please choose custom element !", REQ_CONFIRM);
+
+    return FALSE;
+  }
+  else if (IS_GROUP_ELEMENT(element_old) && !IS_GROUP_ELEMENT(element_new))
+  {
+    Request("Please choose group element !", REQ_CONFIRM);
+
+    return FALSE;
+  }
+
   if (copy_mode == GADGET_ID_CUSTOM_COPY_FROM)
   {
     copy_custom_element_settings(element_new, element_old);
@@ -5012,21 +5062,23 @@ static void CopyCustomElement(int element_old, int element_new, int copy_mode)
   }
   else if (copy_mode == GADGET_ID_CUSTOM_EXCHANGE)
   {
-    copy_custom_element_settings(element_old, EL_DUMMY);
+    copy_custom_element_settings(element_old, EL_INTERNAL_EDITOR);
     copy_custom_element_settings(element_new, element_old);
-    copy_custom_element_settings(EL_DUMMY, element_new);
+    copy_custom_element_settings(EL_INTERNAL_EDITOR, element_new);
 
-    replace_custom_element_in_settings(element_old, EL_DUMMY);
+    replace_custom_element_in_settings(element_old, EL_INTERNAL_EDITOR);
     replace_custom_element_in_settings(element_new, element_old);
-    replace_custom_element_in_settings(EL_DUMMY, element_new);
+    replace_custom_element_in_settings(EL_INTERNAL_EDITOR, element_new);
 
-    replace_custom_element_in_playfield(element_old, EL_DUMMY);
+    replace_custom_element_in_playfield(element_old, EL_INTERNAL_EDITOR);
     replace_custom_element_in_playfield(element_new, element_old);
-    replace_custom_element_in_playfield(EL_DUMMY, element_new);
+    replace_custom_element_in_playfield(EL_INTERNAL_EDITOR, element_new);
   }
 
   UpdateCustomElementGraphicGadgets();
   DrawPropertiesWindow();
+
+  return TRUE;
 }
 
 static void CopyCustomElementPropertiesToEditor(int element)
@@ -6404,7 +6456,8 @@ static void DrawPropertiesWindow()
   UnmapLevelEditorToolboxDrawingGadgets();
   UnmapLevelEditorToolboxCustomGadgets();
 
-  if (IS_CUSTOM_ELEMENT(properties_element))
+  if (IS_CUSTOM_ELEMENT(properties_element) ||
+      IS_GROUP_ELEMENT(properties_element))
     MapLevelEditorToolboxCustomGadgets();
 
   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
@@ -7631,6 +7684,10 @@ static void HandleControlButtons(struct GadgetInfo *gi)
     edit_mode = ED_MODE_DRAWING;
   }
 
+  /* element copy mode active, but no element button pressed => deactivate */
+  if (last_custom_copy_mode != -1 && id < ED_NUM_CTRL_BUTTONS)
+    last_custom_copy_mode = -1;
+
   switch (id)
   {
     case GADGET_ID_SCROLL_LEFT:
@@ -7929,13 +7986,14 @@ static void HandleControlButtons(struct GadgetInfo *gi)
 
        if (last_custom_copy_mode != -1)
        {
-         CopyCustomElement(properties_element, new_element,
-                           last_custom_copy_mode);
-
-         ClickOnGadget(level_editor_gadget[last_drawing_function],
-                       MB_LEFTBUTTON);
+         if (CopyCustomElement(properties_element, new_element,
+                               last_custom_copy_mode))
+         {
+           ClickOnGadget(level_editor_gadget[last_drawing_function],
+                         MB_LEFTBUTTON);
 
-         last_custom_copy_mode = -1;
+           last_custom_copy_mode = -1;
+         }
 
          break;
        }
@@ -8240,8 +8298,6 @@ static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
        strncpy(infotext, getElementInfoText(Feld[lx][ly]), max_infotext_len);
       else
        sprintf(infotext, "Level position: %d, %d", lx, ly);
-
-      infotext[max_infotext_len] = '\0';
 #else
       else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
        DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
@@ -8263,36 +8319,33 @@ static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
   }
   else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
   {
+    int element = EL_EMPTY;
+
     if (id == GADGET_ID_AMOEBA_CONTENT)
-      text = getElementInfoText(level.amoeba_content);
+      element = level.amoeba_content;
     else if (id == GADGET_ID_CUSTOM_GRAPHIC)
-      text = getElementInfoText(custom_element.gfx_element);
+      element = custom_element.gfx_element;
     else if (id == GADGET_ID_CUSTOM_CONTENT)
-      text = getElementInfoText(custom_element.content[sx][sy]);
+      element = custom_element.content[sx][sy];
     else if (id == GADGET_ID_CUSTOM_MOVE_ENTER)
-      text = getElementInfoText(custom_element.move_enter_element);
+      element = custom_element.move_enter_element;
     else if (id == GADGET_ID_CUSTOM_MOVE_LEAVE)
-      text = getElementInfoText(custom_element.move_leave_element);
+      element = custom_element.move_leave_element;
     else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
-      text = getElementInfoText(custom_element_change.target_element);
+      element = custom_element_change.target_element;
     else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
-      text = getElementInfoText(custom_element_change.content[sx][sy]);
+      element = custom_element_change.content[sx][sy];
     else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
-      text = getElementInfoText(custom_element_change.trigger_element);
+      element = custom_element_change.trigger_element;
     else if (id == GADGET_ID_GROUP_CONTENT)
-      text = getElementInfoText(group_element_info.element[sx]);
+      element = group_element_info.element[sx];
     else if (id == GADGET_ID_RANDOM_BACKGROUND)
-      text = getElementInfoText(random_placement_background_element);
+      element = random_placement_background_element;
     else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
             id <= GADGET_ID_ELEMENT_CONTENT_7)
-    {
-      int i = id - GADGET_ID_ELEMENT_CONTENT_0;
-
-      text = getElementInfoText(level.yamyam_content[i][sx][sy]);
-    }
+      element = level.yamyam_content[id - GADGET_ID_ELEMENT_CONTENT_0][sx][sy];
 
-    strncpy(infotext, text, max_infotext_len);
-    infotext[max_infotext_len] = '\0';
+    strncpy(infotext, getElementInfoText(element), max_infotext_len);
   }
   else
   {
@@ -8303,9 +8356,9 @@ static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
     else if (id == GADGET_ID_CUSTOM_CONTENT)
       sprintf(infotext, "Custom element content position: %d, %d", sx, sy);
     else if (id == GADGET_ID_CUSTOM_MOVE_ENTER)
-      strcpy(infotext, "Element that can be digged");
+      strcpy(infotext, "Element that can be digged/collected");
     else if (id == GADGET_ID_CUSTOM_MOVE_LEAVE)
-      strcpy(infotext, "Element that can be left behind");
+      strcpy(infotext, "Element that will be left behind");
     else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
       strcpy(infotext, "New element after change");
     else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
@@ -8322,6 +8375,8 @@ static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
              id - GADGET_ID_ELEMENT_CONTENT_0 + 1, sx, sy);
   }
 
+  infotext[max_infotext_len] = '\0';
+
   if (strlen(infotext) > 0)
     DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, infotext);
 }