fixed bug with not warning on copy/paste of CE/GE when using level template
[rocksndiamonds.git] / src / editor.c
index 507f9c3b71cfc71ed8a446898a57c26e3a42cfc7..49073d30d004043d6c35dd455426f15f936c70e0 100644 (file)
@@ -3505,6 +3505,7 @@ static void HandleCheckbuttons(struct GadgetInfo *);
 static void HandleControlButtons(struct GadgetInfo *);
 static void HandleDrawingAreaInfo(struct GadgetInfo *);
 static void PrintEditorGadgetInfoText(struct GadgetInfo *);
+static boolean AskToCopyAndModifyLevelTemplate();
 
 static int num_editor_gadgets = 0;     /* dynamically determined */
 
@@ -7280,6 +7281,8 @@ static void replace_custom_element_in_playfield(int element_from,
 static boolean CopyCustomElement(int element_old, int element_new,
                                 int copy_mode)
 {
+  int copy_mode_orig = copy_mode;
+
   if (copy_mode == GADGET_ID_CUSTOM_COPY)
   {
     element_new = (IS_CUSTOM_ELEMENT(element_old) ?
@@ -7311,6 +7314,13 @@ static boolean CopyCustomElement(int element_old, int element_new,
     level.changed = TRUE;
   }
 
+  /* when modifying custom/group element, ask for copying level template */
+  if (copy_mode_orig != GADGET_ID_CUSTOM_COPY && level.use_custom_template)
+  {
+    if (!AskToCopyAndModifyLevelTemplate())
+      return FALSE;
+  }
+
   if (copy_mode == GADGET_ID_CUSTOM_COPY_FROM)
   {
     copy_custom_element_settings(element_new, element_old);
@@ -7516,6 +7526,27 @@ static void CopyElementPropertiesToEditor(int element)
     CopyClassicElementPropertiesToEditor(element);
 }
 
+static boolean AskToCopyAndModifyLevelTemplate()
+{
+  if (Request("Copy and modify level template?", REQ_ASK))
+  {
+    level.use_custom_template = FALSE;
+
+    ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE],
+                GDI_CHECKED, FALSE, GDI_END);
+
+    return TRUE;
+  }
+  else
+  {
+    LoadLevelTemplate(-1);     /* this resets all element modifications ... */
+
+    DrawEditModeWindow();      /* ... and copies them to 'custom_element' */
+
+    return FALSE;
+  }
+}
+
 static void CopyCustomElementPropertiesToGame(int element)
 {
   int i;
@@ -7526,20 +7557,7 @@ static void CopyCustomElementPropertiesToGame(int element)
   level.changed = TRUE;
 
   if (level.use_custom_template)
-  {
-    if (Request("Copy and modify level template?", REQ_ASK))
-    {
-      level.use_custom_template = FALSE;
-      ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE],
-                  GDI_CHECKED, FALSE, GDI_END);
-    }
-    else
-    {
-      LoadLevelTemplate(-1);   /* this resets all element modifications ... */
-
-      DrawEditModeWindow();    /* ... and copies them to 'custom_element' */
-    }
-  }
+    AskToCopyAndModifyLevelTemplate();
 
   element_info[element] = custom_element;
   *element_info[element].change = custom_element_change;
@@ -7650,12 +7668,15 @@ static void CopyCustomElementPropertiesToGame(int element)
 
 static void CopyGroupElementPropertiesToGame(int element)
 {
-  element_info[element] = custom_element;
-  *element_info[element].group = group_element_info;
-
   /* mark that this group element has been modified */
-  element_info[element].modified_settings = TRUE;
+  custom_element.modified_settings = TRUE;
   level.changed = TRUE;
+
+  if (level.use_custom_template)
+    AskToCopyAndModifyLevelTemplate();
+
+  element_info[element] = custom_element;
+  *element_info[element].group = group_element_info;
 }
 
 static void CopyClassicElementPropertiesToGame(int element)
@@ -9309,11 +9330,9 @@ static void DrawPaletteWindow()
 
 static void UpdateCustomElementGraphicGadgets()
 {
-  struct ElementInfo *ei = &element_info[properties_element];
   int i;
 
-  ei->gfx_element = (ei->use_gfx_element ? ei->gfx_element_initial :
-                    properties_element);
+  InitElementPropertiesGfxElement();
 
   ModifyEditorElementList();
   RedrawDrawingElements();
@@ -11513,6 +11532,16 @@ static void HandleCheckbuttons(struct GadgetInfo *gi)
       return;
     }
 
+    if (level.use_custom_template &&
+       !Request("Discard changes and use level template?", REQ_ASK))
+    {
+      level.use_custom_template = FALSE;
+
+      ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END);
+
+      return;
+    }
+
     LoadLevelTemplate(level.use_custom_template ? -1 : level_nr);
 
     DrawEditModeWindow();