added button to level editor to set random level colors for BD engine
authorHolger Schemel <info@artsoft.org>
Mon, 8 Apr 2024 23:50:00 +0000 (01:50 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 8 Apr 2024 23:50:02 +0000 (01:50 +0200)
src/editor.c

index 69e57de2c7638a0d9dacaccabb55245dcf6e4e84..2a481fc93e3105fd2250182d603c684de2a9bdb3 100644 (file)
@@ -756,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
 
@@ -1132,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
 };
@@ -3596,6 +3598,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
@@ -11476,6 +11488,8 @@ static void DrawEngineConfigColors(void)
     for (i = ED_SELECTBOX_ID_COLORS_FIRST; i <= ED_SELECTBOX_ID_COLORS_LAST; i++)
       MapSelectboxGadget(i);
   }
+
+  MapTextbuttonGadget(ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS);
 }
 
 static void DrawLevelConfigEngine(void)
@@ -16549,6 +16563,26 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
 
     level.changed = TRUE;
   }
+  else if (type_id == ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS)
+  {
+    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);
+
+    // 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;
+
+    // update BD color palette gadgets after setting random colors
+    DrawLevelConfigWindow();
+  }
 }
 
 static void HandleGraphicbuttonGadgets(struct GadgetInfo *gi)