+ int graphic;
+ struct GraphicInfo *gd;
+ int gd_x1, gd_x2, gd_y1, gd_y2;
+ unsigned int event_mask;
+ char infotext[max_infotext_len + 1];
+
+ event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
+
+ if (i == ED_COUNTER_ID_SELECT_LEVEL)
+ {
+ graphic = (j == 0 ?
+ IMG_GFX_EDITOR_BUTTON_PREV_LEVEL :
+ IMG_GFX_EDITOR_BUTTON_NEXT_LEVEL);
+
+ event_mask |= GD_EVENT_RELEASED;
+
+ if (j == 0)
+ {
+ x = DX + editor.button.prev_level.x;
+ y = DY + editor.button.prev_level.y;
+ }
+ else
+ {
+ x = DX + editor.button.next_level.x;
+ y = DY + editor.button.next_level.y;
+ }
+ }
+ else
+ {
+ graphic = (j == 0 ?
+ IMG_EDITOR_COUNTER_DOWN :
+ IMG_EDITOR_COUNTER_UP);
+ }
+
+ gd = &graphic_info[graphic];
+
+ gd_x1 = gd->src_x;
+ gd_y1 = gd->src_y;
+ gd_x2 = gd->src_x + gd->pressed_xoffset;
+ gd_y2 = gd->src_y + gd->pressed_yoffset;
+
+ sprintf(infotext, "%s counter value by 1, 5 or 10",
+ (j == 0 ? "decrease" : "increase"));
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, infotext,
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_WIDTH, gd->width,
+ GDI_HEIGHT, gd->height,
+ GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleCounterButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ right_gadget_border[id] =
+ getRightGadgetBorder(gi, counterbutton_info[i].text_right);
+
+ x += gi->width + ED_GADGET_SMALL_DISTANCE; /* text count button */
+
+ if (j == 0)
+ {
+ int font_type = FONT_INPUT_1;
+ int font_type_active = FONT_INPUT_1_ACTIVE;
+
+ id = counterbutton_info[i].gadget_id_text;
+
+ event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
+
+ if (i == ED_COUNTER_ID_SELECT_LEVEL)
+ {
+ graphic = IMG_GFX_EDITOR_INPUT_LEVEL_NUMBER;
+
+ font_type = FONT_LEVEL_NUMBER;
+ font_type_active = FONT_LEVEL_NUMBER_ACTIVE;
+
+ x = DX + editor.input.level_number.x;
+ y = DY + editor.input.level_number.y;
+ }
+ else
+ {
+ graphic = IMG_EDITOR_COUNTER_INPUT;
+ }
+
+ gd = &graphic_info[graphic];
+
+ gd_x1 = gd->src_x;
+ gd_y1 = gd->src_y;
+ gd_x2 = gd->src_x + gd->active_xoffset;
+ gd_y2 = gd->src_y + gd->active_yoffset;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, "enter counter value",
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_TYPE, GD_TYPE_TEXT_INPUT_NUMERIC,
+ GDI_NUMBER_VALUE, 0,
+ GDI_NUMBER_MIN, counterbutton_info[i].min_value,
+ GDI_NUMBER_MAX, counterbutton_info[i].max_value,
+ GDI_TEXT_SIZE, 3, /* minimal counter text size */
+ GDI_TEXT_FONT, font_type,
+ GDI_TEXT_FONT_ACTIVE, font_type_active,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_BORDER_SIZE, gd->border_size, gd->border_size,
+ GDI_DESIGN_WIDTH, gd->width,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleCounterButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ right_gadget_border[id] =
+ getRightGadgetBorder(gi, counterbutton_info[i].text_right);
+
+ x += gi->width + ED_GADGET_SMALL_DISTANCE; /* up count button */
+ }
+ }
+ }
+}
+
+static void CreateDrawingAreas()
+{
+ int i;
+
+ /* these values are not constant, but can change at runtime */
+ drawingarea_info[ED_DRAWING_ID_DRAWING_LEVEL].area_xsize = MAX_ED_FIELDX;
+ drawingarea_info[ED_DRAWING_ID_DRAWING_LEVEL].area_ysize = MAX_ED_FIELDY;
+
+ for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
+ {
+ struct GadgetInfo *gi;
+ unsigned int event_mask;
+ int id = drawingarea_info[i].gadget_id;
+ int x = SX + ED_AREA_SETTINGS_X(drawingarea_info[i]);
+ int y = SY + ED_AREA_SETTINGS_Y(drawingarea_info[i]);
+ int area_xsize = drawingarea_info[i].area_xsize;
+ int area_ysize = drawingarea_info[i].area_ysize;
+ int item_size = (id == GADGET_ID_DRAWING_LEVEL ?
+ ed_tilesize : ED_DRAWINGAREA_TILE_SIZE);
+
+ event_mask =
+ GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING |
+ GD_EVENT_OFF_BORDERS | GD_EVENT_PIXEL_PRECISE;
+
+ /* determine horizontal position to the right of specified gadget */
+ if (drawingarea_info[i].gadget_id_align != GADGET_ID_NONE)
+ x = (right_gadget_border[drawingarea_info[i].gadget_id_align] +
+ ED_DRAWINGAREA_TEXT_DISTANCE);
+
+ /* determine horizontal offset for leading text */
+ if (drawingarea_info[i].text_left != NULL)
+ x += getTextWidthForDrawingArea(drawingarea_info[i].text_left);
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_TYPE, GD_TYPE_DRAWING_AREA,
+ GDI_AREA_SIZE, area_xsize, area_ysize,
+ GDI_ITEM_SIZE, item_size, item_size,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
+ GDI_CALLBACK_ACTION, HandleDrawingAreas,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ right_gadget_border[id] =
+ getRightGadgetBorder(gi, drawingarea_info[i].text_right);
+ }
+}
+
+static void CreateTextInputGadgets()
+{
+ struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_INPUT_TEXT];
+ int max_infotext_len = getMaxInfoTextLength();
+ int i;
+
+ for (i = 0; i < ED_NUM_TEXTINPUT; i++)
+ {
+ int gd_x1 = gd->src_x;
+ int gd_y1 = gd->src_y;
+ int gd_x2 = gd->src_x + gd->active_xoffset;
+ int gd_y2 = gd->src_y + gd->active_yoffset;
+ struct GadgetInfo *gi;
+ unsigned int event_mask;
+ char infotext[MAX_OUTPUT_LINESIZE + 1];
+ int id = textinput_info[i].gadget_id;
+ int x, y;
+
+ if (i == ED_TEXTINPUT_ID_ELEMENT_NAME)
+ {
+ int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
+ int border_size = gd->border_size;
+ int font_nr = FONT_INPUT_1;
+ int font_height = getFontHeight(font_nr);
+ int xoffset = element_border + TILEX + element_border + 3 * border_size;
+ int yoffset = element_border + (TILEY - font_height) / 2;
+
+ x = (editor.settings.element_name.x != -1 ?
+ editor.settings.element_name.x :
+ editor.settings.element_graphic.x + xoffset) - border_size;
+ y = (editor.settings.element_name.y != -1 ?
+ editor.settings.element_name.y :
+ editor.settings.element_graphic.y + yoffset) - border_size;
+ }
+ else
+ {
+ x = ED_SETTINGS_X(textinput_info[i].x);
+ y = ED_SETTINGS_Y(textinput_info[i].y);
+ }
+
+ event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
+
+ sprintf(infotext, "Enter %s", textinput_info[i].infotext);
+ infotext[max_infotext_len] = '\0';
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, infotext,
+ GDI_X, SX + x,
+ GDI_Y, SY + y,
+ GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
+ GDI_TEXT_VALUE, textinput_info[i].value,
+ GDI_TEXT_SIZE, textinput_info[i].size,
+ GDI_TEXT_FONT, FONT_INPUT_1,
+ GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_BORDER_SIZE, gd->border_size, gd->border_size,
+ GDI_DESIGN_WIDTH, gd->width,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleTextInputGadgets,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+}
+
+static void CreateTextAreaGadgets()
+{
+ int max_infotext_len = getMaxInfoTextLength();
+ int i;
+
+ for (i = 0; i < ED_NUM_TEXTAREAS; i++)
+ {
+ struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_INPUT_TEXTAREA];
+ int gd_x1 = gd->src_x;
+ int gd_y1 = gd->src_y;
+ int gd_x2 = gd->src_x + gd->active_xoffset;
+ int gd_y2 = gd->src_y + gd->active_yoffset;
+ struct GadgetInfo *gi;
+ unsigned int event_mask;
+ char infotext[MAX_OUTPUT_LINESIZE + 1];
+ int id = textarea_info[i].gadget_id;
+ int area_xsize = textarea_info[i].xsize;
+ int area_ysize = textarea_info[i].ysize;
+
+ event_mask = GD_EVENT_TEXT_LEAVING;
+
+ sprintf(infotext, "Enter %s", textarea_info[i].infotext);
+ infotext[max_infotext_len] = '\0';
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, infotext,
+ GDI_X, SX + ED_SETTINGS_X(textarea_info[i].x),
+ GDI_Y, SY + ED_SETTINGS_Y(textarea_info[i].y),
+ GDI_TYPE, GD_TYPE_TEXT_AREA,
+ GDI_AREA_SIZE, area_xsize, area_ysize,
+ GDI_TEXT_FONT, FONT_INPUT_1,
+ GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_BORDER_SIZE, gd->border_size, gd->border_size,
+ GDI_DESIGN_WIDTH, gd->width,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleTextAreaGadgets,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+}
+
+static void CreateSelectboxGadgets()
+{
+ int max_infotext_len = getMaxInfoTextLength();
+ int i, j;
+
+ for (i = 0; i < ED_NUM_SELECTBOX; i++)
+ {
+ struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_SELECTBOX_INPUT];
+ struct GraphicInfo *gd2 = &graphic_info[IMG_EDITOR_SELECTBOX_BUTTON];
+ int gd_x1 = gd->src_x;
+ int gd_y1 = gd->src_y;
+ int gd_x2 = gd->src_x + gd->active_xoffset;
+ int gd_y2 = gd->src_y + gd->active_yoffset;
+ int selectbox_button_xsize = gd2->width;
+ struct GadgetInfo *gi;
+ unsigned int event_mask;
+ char infotext[MAX_OUTPUT_LINESIZE + 1];
+ int id = selectbox_info[i].gadget_id;
+ int x = SX + ED_SETTINGS_X(selectbox_info[i].x);
+ int y = SY + ED_SETTINGS_Y(selectbox_info[i].y);
+
+ if (selectbox_info[i].size == -1) /* dynamically determine size */
+ {
+ /* (we cannot use -1 for uninitialized values if we directly compare
+ with results from strlen(), because the '<' and '>' operation will
+ implicitely cast -1 to an unsigned integer value!) */
+ selectbox_info[i].size = 0;
+
+ for (j = 0; selectbox_info[i].options[j].text != NULL; j++)
+ if (strlen(selectbox_info[i].options[j].text) > selectbox_info[i].size)
+ selectbox_info[i].size = strlen(selectbox_info[i].options[j].text);
+
+ selectbox_info[i].size++; /* add one character empty space */
+ }
+
+ event_mask = GD_EVENT_RELEASED |
+ GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
+
+ /* determine horizontal position to the right of specified gadget */
+ if (selectbox_info[i].gadget_id_align != GADGET_ID_NONE)
+ x = (right_gadget_border[selectbox_info[i].gadget_id_align] +
+ ED_GADGET_TEXT_DISTANCE);
+
+ /* determine horizontal offset for leading text */
+ if (selectbox_info[i].text_left != NULL)
+ x += getTextWidthForGadget(selectbox_info[i].text_left);
+
+ sprintf(infotext, "Select %s", selectbox_info[i].infotext);
+ infotext[max_infotext_len] = '\0';
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, infotext,
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_TYPE, GD_TYPE_SELECTBOX,
+ GDI_SELECTBOX_OPTIONS, selectbox_info[i].options,
+ GDI_SELECTBOX_CHAR_UNSELECTABLE, '[',
+ GDI_TEXT_SIZE, selectbox_info[i].size,
+ GDI_TEXT_FONT, FONT_INPUT_1,
+ GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
+ GDI_TEXT_FONT_UNSELECTABLE, FONT_TEXT_1,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_BORDER_SIZE, gd->border_size, gd->border_size,
+ GDI_BORDER_SIZE_SELECTBUTTON, selectbox_button_xsize,
+ GDI_DESIGN_WIDTH, gd->width,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleSelectboxGadgets,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ right_gadget_border[id] =
+ getRightGadgetBorder(gi, selectbox_info[i].text_right);
+ }
+}
+
+static void CreateTextbuttonGadgets()
+{
+ int max_infotext_len = getMaxInfoTextLength();
+ int i;
+
+ for (i = 0; i < ED_NUM_TEXTBUTTONS; i++)
+ {
+ int id = textbutton_info[i].gadget_id;
+ int is_tab_button =
+ ((id >= GADGET_ID_LEVELINFO_LEVEL && id <= GADGET_ID_LEVELINFO_EDITOR) ||
+ (id >= GADGET_ID_PROPERTIES_INFO && id <= GADGET_ID_PROPERTIES_CHANGE));
+ int graphic =
+ (is_tab_button ? IMG_EDITOR_TABBUTTON : IMG_EDITOR_TEXTBUTTON);
+ int gadget_distance =
+ (is_tab_button ? ED_GADGET_SMALL_DISTANCE : ED_GADGET_TEXT_DISTANCE);
+ struct GraphicInfo *gd = &graphic_info[graphic];
+ int gd_x1 = gd->src_x;
+ int gd_y1 = gd->src_y;
+ int gd_x2 = gd->src_x + gd->pressed_xoffset;
+ int gd_y2 = gd->src_y + gd->pressed_yoffset;
+ int gd_x1a = gd->src_x + gd->active_xoffset;
+ int gd_y1a = gd->src_y + gd->active_yoffset;
+ int border_xsize = gd->border_size + gd->draw_xoffset;
+ int border_ysize = gd->border_size;
+ struct GadgetInfo *gi;
+ unsigned int event_mask;
+ char infotext[MAX_OUTPUT_LINESIZE + 1];
+ int x = SX + ED_SETTINGS_X(textbutton_info[i].x);
+ int y = SY + ED_SETTINGS_Y(textbutton_info[i].y);
+
+ if (textbutton_info[i].size == -1) /* dynamically determine size */
+ textbutton_info[i].size = strlen(textbutton_info[i].text);
+
+ event_mask = GD_EVENT_RELEASED;
+
+ sprintf(infotext, "%s", textbutton_info[i].infotext);
+ infotext[max_infotext_len] = '\0';
+
+ /* determine horizontal position to the right of specified gadget */
+ if (textbutton_info[i].gadget_id_align != GADGET_ID_NONE)
+ {
+ int gadget_id_align = textbutton_info[i].gadget_id_align;
+
+ x = right_gadget_border[gadget_id_align] + gadget_distance;
+
+ if (textbutton_info[i].y == -1)
+ y = level_editor_gadget[gadget_id_align]->y;
+ }
+
+ /* determine horizontal offset for leading text */
+ if (textbutton_info[i].text_left != NULL)
+ x += getTextWidthForGadget(textbutton_info[i].text_left);
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, infotext,
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_TYPE, GD_TYPE_TEXT_BUTTON,
+ GDI_TEXT_VALUE, textbutton_info[i].text,
+ GDI_TEXT_SIZE, textbutton_info[i].size,
+ GDI_TEXT_FONT, FONT_INPUT_2,
+ GDI_TEXT_FONT_ACTIVE, FONT_INPUT_2_ACTIVE,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_ALT_DESIGN_UNPRESSED, gd->bitmap, gd_x1a, gd_y1a,
+ GDI_BORDER_SIZE, border_xsize, border_ysize,
+ GDI_DESIGN_WIDTH, gd->width,
+ GDI_DECORATION_SHIFTING, 1, 1,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleTextbuttonGadgets,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ right_gadget_border[id] =
+ getRightGadgetBorder(gi, textbutton_info[i].text_right);
+ }
+}
+
+static void CreateGraphicbuttonGadgets()
+{
+ struct GadgetInfo *gi;
+ unsigned int event_mask;
+ int i;
+
+ /* create buttons for scrolling of drawing area and element list */
+ for (i = 0; i < ED_NUM_GRAPHICBUTTONS; i++)
+ {
+ int id = graphicbutton_info[i].gadget_id;
+ int x = SX + ED_SETTINGS_X(graphicbutton_info[i].x);
+ int y = SY + ED_SETTINGS_Y(graphicbutton_info[i].y);
+ struct GraphicInfo *gd = &graphic_info[graphicbutton_info[i].graphic];
+ int gd_x1 = gd->src_x;
+ int gd_y1 = gd->src_y;
+ int gd_x2 = gd->src_x + gd->pressed_xoffset;
+ int gd_y2 = gd->src_y + gd->pressed_yoffset;
+
+ event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
+
+ /* determine horizontal position to the right of specified gadget */
+ if (graphicbutton_info[i].gadget_id_align != GADGET_ID_NONE)
+ x = (right_gadget_border[graphicbutton_info[i].gadget_id_align] +
+ ED_GADGET_TEXT_DISTANCE);
+
+ /* determine horizontal offset for leading text */
+ if (graphicbutton_info[i].text_left != NULL)
+ x += getTextWidthForGadget(graphicbutton_info[i].text_left);
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, graphicbutton_info[i].infotext,
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_WIDTH, gd->width,
+ GDI_HEIGHT, gd->height,
+ GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleGraphicbuttonGadgets,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ right_gadget_border[id] =
+ getRightGadgetBorder(gi, graphicbutton_info[i].text_right);
+ }
+}
+
+static void CreateScrollbarGadgets()
+{
+ int i;
+
+ /* these values are not constant, but can change at runtime */
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].x =
+ SX + ED_SCROLL_HORIZONTAL_XPOS;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].y =
+ SY + ED_SCROLL_HORIZONTAL_YPOS;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width =
+ ED_SCROLL_HORIZONTAL_XSIZE;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].height =
+ ED_SCROLL_HORIZONTAL_YSIZE;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_x = SX;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_y = SY;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_width = SXSIZE;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_height = SYSIZE;
+
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].x =
+ SX + ED_SCROLL_VERTICAL_XPOS;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].y =
+ SY + ED_SCROLL_VERTICAL_YPOS;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].width =
+ ED_SCROLL_VERTICAL_XSIZE;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].height =
+ ED_SCROLL_VERTICAL_YSIZE;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_x = SX;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_y = SY;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_width = SXSIZE;
+ scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_height = SYSIZE;
+
+ scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].x =
+ PX + ED_SCROLL2_VERTICAL_XPOS;
+ scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].y =
+ PY + ED_SCROLL2_VERTICAL_YPOS;
+ scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].width =
+ ED_SCROLL2_VERTICAL_XSIZE;
+ scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].height =
+ ED_SCROLL2_VERTICAL_YSIZE;
+ scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_x = PX;
+ scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_y = PY;
+ scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_width = PXSIZE;
+ scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_height = PYSIZE;
+
+ for (i = 0; i < ED_NUM_SCROLLBARS; i++)
+ {
+ int id = scrollbar_info[i].gadget_id;
+ int graphic = scrollbar_info[i].graphic;
+ struct GraphicInfo *gd = &graphic_info[graphic];
+ int gd_x1 = gd->src_x;
+ int gd_y1 = gd->src_y;
+ int gd_x2 = gd->src_x + gd->pressed_xoffset;
+ int gd_y2 = gd->src_y + gd->pressed_yoffset;
+ struct GadgetInfo *gi;
+ int items_max, items_visible, item_position;
+ unsigned int event_mask;
+
+ if (i == ED_SCROLLBAR_ID_LIST_VERTICAL)
+ {
+ items_max = num_editor_elements / ED_ELEMENTLIST_BUTTONS_HORIZ;
+ items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
+ item_position = element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ;
+ }
+ else /* drawing area scrollbars */
+ {
+ if (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL)
+ {
+ items_max = MAX(lev_fieldx + 2, ed_fieldx);
+ items_visible = ed_fieldx;
+ item_position = 0;
+ }
+ else
+ {
+ items_max = MAX(lev_fieldy + 2, ed_fieldy);
+ items_visible = ed_fieldy;
+ item_position = 0;
+ }
+ }
+
+ event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, scrollbar_info[i].infotext,
+ GDI_X, scrollbar_pos[i].x,
+ GDI_Y, scrollbar_pos[i].y,
+ GDI_WIDTH, scrollbar_pos[i].width,
+ GDI_HEIGHT, scrollbar_pos[i].height,
+ GDI_TYPE, scrollbar_info[i].type,
+ GDI_SCROLLBAR_ITEMS_MAX, items_max,
+ GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
+ GDI_SCROLLBAR_ITEM_POSITION, item_position,
+ GDI_WHEEL_AREA_X, scrollbar_pos[i].wheel_x,
+ GDI_WHEEL_AREA_Y, scrollbar_pos[i].wheel_y,
+ GDI_WHEEL_AREA_WIDTH, scrollbar_pos[i].wheel_width,
+ GDI_WHEEL_AREA_HEIGHT, scrollbar_pos[i].wheel_height,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_BORDER_SIZE, gd->border_size, gd->border_size,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+}
+
+static void CreateCheckbuttonGadgets()
+{
+ struct GadgetInfo *gi;
+ unsigned int event_mask;
+ int i;
+
+ event_mask = GD_EVENT_PRESSED;
+
+ for (i = 0; i < ED_NUM_CHECKBUTTONS; i++)
+ {
+ int id = checkbutton_info[i].gadget_id;
+ int graphic = (id == GADGET_ID_STICK_ELEMENT ? IMG_EDITOR_STICKYBUTTON :
+ IMG_EDITOR_CHECKBOX);
+ struct GraphicInfo *gd = &graphic_info[graphic];
+ int gd_x1 = gd->src_x;
+ int gd_y1 = gd->src_y;
+ int gd_x2 = gd->src_x + gd->pressed_xoffset;
+ int gd_y2 = gd->src_y + gd->pressed_yoffset;
+ int gd_x1a = gd->src_x + gd->active_xoffset;
+ int gd_y1a = gd->src_y + gd->active_yoffset;
+ int gd_x2a = gd->src_x + gd->active_xoffset + gd->pressed_xoffset;
+ int gd_y2a = gd->src_y + gd->active_yoffset + gd->pressed_yoffset;
+ int x = SX + ED_SETTINGS_X(checkbutton_info[i].x);
+ int y = SY + ED_SETTINGS_Y(checkbutton_info[i].y);
+
+ /* determine horizontal position to the right of specified gadget */
+ if (checkbutton_info[i].gadget_id_align != GADGET_ID_NONE)
+ x = (right_gadget_border[checkbutton_info[i].gadget_id_align] +
+ ED_GADGET_TEXT_DISTANCE);
+
+ /* determine horizontal offset for leading text */
+ if (checkbutton_info[i].text_left != NULL)
+ x += getTextWidthForGadget(checkbutton_info[i].text_left);
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, checkbutton_info[i].infotext,
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_WIDTH, gd->width,
+ GDI_HEIGHT, gd->height,
+ GDI_TYPE, GD_TYPE_CHECK_BUTTON,
+ GDI_CHECKED, *checkbutton_info[i].value,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_ALT_DESIGN_UNPRESSED, gd->bitmap, gd_x1a, gd_y1a,
+ GDI_ALT_DESIGN_PRESSED, gd->bitmap, gd_x2a, gd_y2a,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleCheckbuttons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ right_gadget_border[id] =
+ getRightGadgetBorder(gi, checkbutton_info[i].text_right);
+ }
+}
+
+static void CreateRadiobuttonGadgets()
+{
+ struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_RADIOBUTTON];
+ int gd_x1 = gd->src_x;
+ int gd_y1 = gd->src_y;
+ int gd_x2 = gd->src_x + gd->pressed_xoffset;
+ int gd_y2 = gd->src_y + gd->pressed_yoffset;
+ int gd_x1a = gd->src_x + gd->active_xoffset;
+ int gd_y1a = gd->src_y + gd->active_yoffset;
+ int gd_x2a = gd->src_x + gd->active_xoffset + gd->pressed_xoffset;
+ int gd_y2a = gd->src_y + gd->active_yoffset + gd->pressed_yoffset;
+ struct GadgetInfo *gi;
+ unsigned int event_mask;
+ int i;
+
+ event_mask = GD_EVENT_PRESSED;
+
+ for (i = 0; i < ED_NUM_RADIOBUTTONS; i++)
+ {
+ int id = radiobutton_info[i].gadget_id;
+ int x = SX + ED_SETTINGS_X(radiobutton_info[i].x);
+ int y = SY + ED_SETTINGS_Y(radiobutton_info[i].y);
+
+ int checked =
+ (*radiobutton_info[i].value == radiobutton_info[i].checked_value);
+
+ /* determine horizontal position to the right of specified gadget */
+ if (radiobutton_info[i].gadget_id_align != GADGET_ID_NONE)
+ x = (right_gadget_border[radiobutton_info[i].gadget_id_align] +
+ ED_GADGET_TEXT_DISTANCE);
+
+ /* determine horizontal offset for leading text */
+ if (radiobutton_info[i].text_left != NULL)
+ x += getTextWidthForGadget(radiobutton_info[i].text_left);
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, radiobutton_info[i].infotext,
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_WIDTH, gd->width,
+ GDI_HEIGHT, gd->height,
+ GDI_TYPE, GD_TYPE_RADIO_BUTTON,
+ GDI_RADIO_NR, radiobutton_info[i].radio_button_nr,
+ GDI_CHECKED, checked,
+ GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+ GDI_ALT_DESIGN_UNPRESSED, gd->bitmap, gd_x1a, gd_y1a,
+ GDI_ALT_DESIGN_PRESSED, gd->bitmap, gd_x2a, gd_y2a,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleRadiobuttons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ right_gadget_border[id] =
+ getRightGadgetBorder(gi, radiobutton_info[i].text_right);
+ }
+}
+
+void CreateLevelEditorGadgets()
+{
+ /* force EDITOR font inside level editor */
+ SetFontStatus(GAME_MODE_EDITOR);
+
+ /* these values are not constant, but can change at runtime */
+ ed_fieldx = MAX_ED_FIELDX - 1;
+ ed_fieldy = MAX_ED_FIELDY - 1;
+
+ num_editor_gadgets = NUM_EDITOR_GADGETS;
+
+ // printf("::: allocating %d gadgets ...\n", num_editor_gadgets);
+
+ level_editor_gadget =
+ checked_calloc(num_editor_gadgets * sizeof(struct GadgetInfo *));
+ right_gadget_border =
+ checked_calloc(num_editor_gadgets * sizeof(int));
+
+ editor_el_empty = checked_calloc(ED_NUM_ELEMENTLIST_BUTTONS * sizeof(int));
+ editor_el_empty_ptr = editor_el_empty;
+
+ use_permanent_palette = !editor.palette.show_as_separate_screen;
+
+ ReinitializeElementList();
+
+ CreateControlButtons();
+ CreateScrollbarGadgets();
+
+ /* order of function calls is important because of cross-references */
+ CreateCheckbuttonGadgets();
+ CreateCounterButtons();
+ CreateRadiobuttonGadgets();
+ CreateTextInputGadgets();
+ CreateTextAreaGadgets();
+ CreateSelectboxGadgets();
+ CreateGraphicbuttonGadgets();
+ CreateTextbuttonGadgets();
+ CreateDrawingAreas();
+
+ ResetFontStatus();
+}
+
+void FreeLevelEditorGadgets()
+{
+ int i;
+
+ // printf("::: freeing %d gadgets ...\n", num_editor_gadgets);
+
+ for (i = 0; i < num_editor_gadgets; i++)
+ {
+ FreeGadget(level_editor_gadget[i]);
+
+ level_editor_gadget[i] = NULL;
+ }
+
+ checked_free(level_editor_gadget);
+ checked_free(right_gadget_border);
+
+ checked_free(editor_el_empty);
+}
+
+static void MapCounterButtons(int id)
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ int gadget_id_down = counterbutton_info[id].gadget_id_down;
+ int gadget_id_text = counterbutton_info[id].gadget_id_text;
+ int gadget_id_up = counterbutton_info[id].gadget_id_up;
+ struct GadgetInfo *gi_down = level_editor_gadget[gadget_id_down];
+ struct GadgetInfo *gi_text = level_editor_gadget[gadget_id_text];
+ struct GadgetInfo *gi_up = level_editor_gadget[gadget_id_up];
+ int xoffset_left = getTextWidthForGadget(counterbutton_info[id].text_left);
+ int xoffset_right = ED_GADGET_TEXT_DISTANCE;
+ int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
+ int yoffset = (gi_down->height - font_height) / 2;
+ int x_left = gi_down->x - xoffset_left;
+ int x_right; /* set after gadget position was modified */
+ int y_above = gi_down->y - yoffset_above;
+ int x = gi_down->x;
+ int y; /* set after gadget position was modified */
+
+ /* counter limits must be changed first to prevent value truncation */
+ ModifyEditorCounterLimits(id, counterbutton_info[id].min_value,
+ counterbutton_info[id].max_value);
+
+ /* right text position might have changed after setting position above */
+ x_right = gi_up->x + gi_up->width + xoffset_right;
+
+ ModifyEditorCounterValue(id, *counterbutton_info[id].value);
+
+ /* set position for "value[1,2,3,4]" counter gadgets (score in most cases) */
+ if (id >= ED_COUNTER_ID_ELEMENT_VALUE1 &&
+ id <= ED_COUNTER_ID_ELEMENT_VALUE4)
+ {
+ ModifyGadget(gi_down, GDI_Y,
+ SY + ED_SETTINGS_Y(counterbutton_info[id].y), GDI_END);
+ ModifyGadget(gi_text, GDI_Y,
+ SY + ED_SETTINGS_Y(counterbutton_info[id].y), GDI_END);
+ ModifyGadget(gi_up, GDI_Y,
+ SY + ED_SETTINGS_Y(counterbutton_info[id].y), GDI_END);
+ }
+
+ /* vertical position might have changed after setting position above */
+ y = gi_up->y + yoffset;
+
+ if (counterbutton_info[id].text_above)
+ DrawText(x, y_above, counterbutton_info[id].text_above, font_nr);
+
+ if (counterbutton_info[id].text_left)
+ DrawText(x_left, y, counterbutton_info[id].text_left, font_nr);
+
+ if (counterbutton_info[id].text_right)
+ DrawText(x_right, y, counterbutton_info[id].text_right, font_nr);
+
+ MapGadget(gi_down);
+ MapGadget(gi_text);
+ MapGadget(gi_up);
+}
+
+static void MapControlButtons()
+{
+ int counter_id;
+ int i;
+
+ /* map toolbox buttons (excluding special CE toolbox buttons) */
+ for (i = 0; i < ED_NUM_CTRL1_2_BUTTONS; i++)
+ MapGadget(level_editor_gadget[i]);
+
+ /* map toolbox buttons (element properties buttons) */
+ for (i = ED_NUM_CTRL1_4_BUTTONS; i < ED_NUM_CTRL1_7_BUTTONS; i++)
+ MapGadget(level_editor_gadget[i]);
+
+ if (use_permanent_palette)
+ {
+ /* map buttons to select elements */
+ for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
+ MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
+ MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
+ MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
+ MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
+ }
+
+ /* map buttons to select level */
+ counter_id = ED_COUNTER_ID_SELECT_LEVEL;
+ counterbutton_info[counter_id].min_value = leveldir_current->first_level;
+ counterbutton_info[counter_id].max_value = leveldir_current->last_level;
+ MapCounterButtons(counter_id);
+}
+
+static void MapDrawingArea(int id)
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
+ int area_xsize = gi->drawing.area_xsize;
+ int area_ysize = gi->drawing.area_ysize;
+ int xoffset_left = getTextWidthForDrawingArea(drawingarea_info[id].text_left);
+ int xoffset_below = getTextWidth(drawingarea_info[id].text_below, font_nr);
+ int x_left = gi->x - xoffset_left;
+ int x_right = gi->x + gi->width + ED_DRAWINGAREA_TEXT_DISTANCE;
+ int x_below = gi->x + (gi->width - xoffset_below) / 2;
+ int y_side = gi->y + (gi->height - font_height) / 2;
+ int y_below = gi->y + gi->height + ED_DRAWINGAREA_TEXT_DISTANCE;
+
+ if (drawingarea_info[id].text_left)
+ DrawText(x_left, y_side, drawingarea_info[id].text_left, font_nr);
+
+ if (drawingarea_info[id].text_right)
+ DrawText(x_right, y_side, drawingarea_info[id].text_right, font_nr);
+
+ if (drawingarea_info[id].text_below)
+ DrawText(x_below, y_below, drawingarea_info[id].text_below, font_nr);
+
+ if (id != ED_DRAWING_ID_DRAWING_LEVEL)
+ {
+ DrawElementBorder(gi->x, gi->y,
+ area_xsize * ED_DRAWINGAREA_TILE_SIZE,
+ area_ysize * ED_DRAWINGAREA_TILE_SIZE, TRUE);
+
+ DrawDrawingArea(id);
+ }
+
+ MapGadget(gi);
+}
+
+static void MapTextInputGadget(int id)
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ struct GadgetInfo *gi = level_editor_gadget[textinput_info[id].gadget_id];
+ int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
+ int x_above = ED_SETTINGS_X(textinput_info[id].x);
+ int y_above = ED_SETTINGS_Y(textinput_info[id].y) - yoffset_above;
+
+ if (textinput_info[id].text_above)
+ DrawTextS(x_above, y_above, font_nr, textinput_info[id].text_above);
+
+ ModifyGadget(gi, GDI_TEXT_VALUE, textinput_info[id].value, GDI_END);
+
+ MapGadget(gi);
+}
+
+static void MapTextAreaGadget(int id)
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
+ int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
+ int x_above = ED_SETTINGS_X(textarea_info[id].x);
+ int y_above = ED_SETTINGS_Y(textarea_info[id].y) - yoffset_above;
+
+ if (textarea_info[id].text_above)
+ DrawTextS(x_above, y_above, font_nr, textarea_info[id].text_above);
+
+ ModifyGadget(gi, GDI_TEXT_VALUE, textarea_info[id].value, GDI_END);
+
+ MapGadget(gi);
+}
+
+static void MapSelectboxGadget(int id)
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ struct GadgetInfo *gi = level_editor_gadget[selectbox_info[id].gadget_id];
+ int xoffset_left = getTextWidthForGadget(selectbox_info[id].text_left);
+ int xoffset_right = ED_GADGET_TEXT_DISTANCE;
+ int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
+ int yoffset = (gi->height - font_height) / 2;
+ int x_left = gi->x - xoffset_left;
+ int x_right = gi->x + gi->width + xoffset_right;
+ int y_above = gi->y - yoffset_above;
+ int x = gi->x;
+ int y = gi->y + yoffset;
+
+ if (selectbox_info[id].text_above)
+ DrawText(x, y_above, selectbox_info[id].text_above, font_nr);
+
+ if (selectbox_info[id].text_left)
+ DrawText(x_left, y, selectbox_info[id].text_left, font_nr);
+
+ if (selectbox_info[id].text_right)
+ DrawText(x_right, y, selectbox_info[id].text_right, font_nr);
+
+ ModifyEditorSelectboxValue(id, *selectbox_info[id].value);
+
+ MapGadget(gi);
+}
+
+static void MapTextbuttonGadget(int id)
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ struct GadgetInfo *gi = level_editor_gadget[textbutton_info[id].gadget_id];
+ int xoffset_left = getTextWidthForGadget(textbutton_info[id].text_left);
+ int xoffset_right = ED_GADGET_TEXT_DISTANCE;
+ int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
+ int yoffset = (gi->height - font_height) / 2;
+ int x_left = gi->x - xoffset_left;
+ int x_right = gi->x + gi->width + xoffset_right;
+ int y_above = gi->y - yoffset_above;
+ int x = gi->x;
+ int y = gi->y + yoffset;
+
+ /* only show button to delete change pages when more than minimum pages */
+ if (id == ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE &&
+ custom_element.num_change_pages == MIN_CHANGE_PAGES)
+ return;
+
+ if (textbutton_info[id].text_above)
+ DrawText(x, y_above, textbutton_info[id].text_above, font_nr);
+
+ if (textbutton_info[id].text_left)
+ DrawText(x_left, y, textbutton_info[id].text_left, font_nr);
+
+ if (textbutton_info[id].text_right)
+ DrawText(x_right, y, textbutton_info[id].text_right, font_nr);
+
+ MapGadget(gi);
+}
+
+static void MapGraphicbuttonGadget(int id)
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ struct GadgetInfo *gi= level_editor_gadget[graphicbutton_info[id].gadget_id];
+ int xoffset_left = getTextWidthForGadget(graphicbutton_info[id].text_left);
+ int xoffset_right = ED_GADGET_TEXT_DISTANCE;
+ int yoffset = (gi->height - font_height) / 2;
+ int x_left = gi->x - xoffset_left;
+ int x_right = gi->x + gi->width + xoffset_right;
+ int y = gi->y + yoffset;
+
+ if (graphicbutton_info[id].text_left)
+ DrawText(x_left, y, graphicbutton_info[id].text_left, font_nr);
+
+ if (graphicbutton_info[id].text_right)
+ DrawText(x_right, y, graphicbutton_info[id].text_right, font_nr);
+
+ MapGadget(gi);
+}
+
+static void MapRadiobuttonGadget(int id)
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ struct GadgetInfo *gi = level_editor_gadget[radiobutton_info[id].gadget_id];
+ int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
+ int xoffset_right = ED_GADGET_TEXT_DISTANCE;
+ int yoffset = (gi->height - font_height) / 2;
+ int x_left = gi->x - xoffset_left;
+ int x_right = gi->x + gi->width + xoffset_right;
+ int y = gi->y + yoffset;
+ boolean checked =
+ (*radiobutton_info[id].value == radiobutton_info[id].checked_value);
+
+ if (radiobutton_info[id].text_left)
+ DrawText(x_left, y, radiobutton_info[id].text_left, font_nr);
+
+ if (radiobutton_info[id].text_right)
+ DrawText(x_right, y, radiobutton_info[id].text_right, font_nr);
+
+ ModifyGadget(gi, GDI_CHECKED, checked, GDI_END);
+
+ MapGadget(gi);
+}
+
+static void MapCheckbuttonGadget(int id)
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ struct GadgetInfo *gi = level_editor_gadget[checkbutton_info[id].gadget_id];
+ int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
+ int xoffset_right = ED_GADGET_TEXT_DISTANCE;
+ int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
+ int yoffset = (gi->height - font_height) / 2;
+ int y_above = gi->y - yoffset_above;
+ int x = gi->x;
+ int x_left, x_right, y; /* set after gadget position was modified */
+
+ /* set position for gadgets with dynamically determined position */
+ if (checkbutton_info[id].x != -1) /* do not change dynamic positions */
+ ModifyGadget(gi, GDI_X, SX + ED_SETTINGS_X(checkbutton_info[id].x),GDI_END);
+ ModifyGadget(gi, GDI_Y, SY + ED_SETTINGS_Y(checkbutton_info[id].y), GDI_END);
+
+ x_left = gi->x - xoffset_left;
+ x_right = gi->x + gi->width + xoffset_right;
+ y = gi->y + yoffset;
+
+ if (checkbutton_info[id].text_above)
+ DrawText(x, y_above, checkbutton_info[id].text_above, font_nr);
+
+ if (checkbutton_info[id].text_left)
+ DrawText(x_left, y, checkbutton_info[id].text_left, font_nr);
+
+ if (checkbutton_info[id].text_right)
+ DrawText(x_right, y, checkbutton_info[id].text_right, font_nr);
+
+ ModifyGadget(gi, GDI_CHECKED, *checkbutton_info[id].value, GDI_END);
+
+ MapGadget(gi);
+}
+
+static void MapMainDrawingArea()
+{
+ boolean no_horizontal_scrollbar = (lev_fieldx + 2 <= ed_fieldx);
+ boolean no_vertical_scrollbar = (lev_fieldy + 2 <= ed_fieldy);
+ int i;
+
+ if (suppressBorderElement())
+ {
+ no_horizontal_scrollbar = (lev_fieldx <= ed_fieldx);
+ no_vertical_scrollbar = (lev_fieldy <= ed_fieldy);
+ }
+
+ for (i=ED_SCROLLBUTTON_ID_AREA_FIRST; i <= ED_SCROLLBUTTON_ID_AREA_LAST; i++)
+ {
+ if (((i == ED_SCROLLBUTTON_ID_AREA_LEFT ||
+ i == ED_SCROLLBUTTON_ID_AREA_RIGHT) &&
+ no_horizontal_scrollbar) ||
+ ((i == ED_SCROLLBUTTON_ID_AREA_UP ||
+ i == ED_SCROLLBUTTON_ID_AREA_DOWN) &&
+ no_vertical_scrollbar))
+ continue;
+
+ MapGadget(level_editor_gadget[scrollbutton_info[i].gadget_id]);
+ }
+
+ for (i = ED_SCROLLBAR_ID_AREA_FIRST; i <= ED_SCROLLBAR_ID_AREA_LAST; i++)
+ {
+ if ((i == ED_SCROLLBAR_ID_AREA_HORIZONTAL && no_horizontal_scrollbar) ||
+ (i == ED_SCROLLBAR_ID_AREA_VERTICAL && no_vertical_scrollbar))
+ continue;
+
+ MapGadget(level_editor_gadget[scrollbar_info[i].gadget_id]);
+ }
+
+ MapDrawingArea(ED_DRAWING_ID_DRAWING_LEVEL);
+}
+
+static void MapOrUnmapLevelEditorToolboxCustomGadgets(boolean map)
+{
+ int i;
+
+ for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
+ {
+ if (i == GADGET_ID_CUSTOM_COPY_FROM ||
+ i == GADGET_ID_CUSTOM_COPY_TO ||
+ i == GADGET_ID_CUSTOM_EXCHANGE ||
+ i == GADGET_ID_CUSTOM_COPY ||
+ i == GADGET_ID_CUSTOM_PASTE)
+ {
+ if (map)
+ MapGadget(level_editor_gadget[i]);
+ else
+ UnmapGadget(level_editor_gadget[i]);
+ }
+ }
+}
+
+static void MapLevelEditorToolboxCustomGadgets()
+{
+ MapOrUnmapLevelEditorToolboxCustomGadgets(TRUE);
+}
+
+static void UnmapLevelEditorToolboxCustomGadgets()
+{
+ MapOrUnmapLevelEditorToolboxCustomGadgets(FALSE);
+}
+
+static void MapOrUnmapLevelEditorToolboxDrawingGadgets(boolean map)
+{
+ int i;
+
+ for (i = 0; i < ED_NUM_CTRL1_BUTTONS; i++)
+ {
+ if (i != GADGET_ID_SINGLE_ITEMS &&
+ i != GADGET_ID_PICK_ELEMENT)
+ {
+ struct GadgetInfo *gi = level_editor_gadget[i];
+
+ if (map)
+ {
+ MapGadget(gi);
+ }
+ else
+ {
+ int graphic = IMG_EDITOR_NO_TOOLBOX_BUTTON;
+ struct GraphicInfo *gd = &graphic_info[graphic];
+
+ UnmapGadget(gi);
+
+ BlitBitmap(gd->bitmap, drawto, gd->src_x, gd->src_y,
+ gi->width, gi->height, gi->x, gi->y);
+
+ redraw_mask |= REDRAW_DOOR_3;
+ }
+ }
+ }
+}
+
+static void MapLevelEditorToolboxDrawingGadgets()
+{
+ MapOrUnmapLevelEditorToolboxDrawingGadgets(TRUE);
+}
+
+static void UnmapLevelEditorToolboxDrawingGadgets()
+{
+ MapOrUnmapLevelEditorToolboxDrawingGadgets(FALSE);
+}
+
+static void UnmapDrawingArea(int id)
+{
+ UnmapGadget(level_editor_gadget[drawingarea_info[id].gadget_id]);
+}
+
+static void UnmapLevelEditorFieldGadgets()
+{
+ int i;
+
+ for (i = 0; i < num_editor_gadgets; i++)
+ if (IN_GFX_FIELD_FULL(level_editor_gadget[i]->x,
+ level_editor_gadget[i]->y))
+ UnmapGadget(level_editor_gadget[i]);
+}
+
+void UnmapLevelEditorGadgets()
+{
+ int i;
+
+ for (i = 0; i < num_editor_gadgets; i++)
+ UnmapGadget(level_editor_gadget[i]);
+}
+
+static void ResetUndoBuffer()
+{
+ undo_buffer_position = -1;
+ undo_buffer_steps = -1;
+ redo_buffer_steps = 0;
+
+ CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
+
+ level.changed = FALSE;
+}
+
+static void DrawEditModeWindowExt(boolean remap_toolbox_gadgets)
+{
+ if (remap_toolbox_gadgets)
+ {
+ ModifyEditorElementList();
+ RedrawDrawingElements();
+ }
+
+ if (edit_mode == ED_MODE_INFO)
+ DrawLevelInfoWindow();
+ else if (edit_mode == ED_MODE_PROPERTIES)
+ DrawPropertiesWindow();
+ else if (edit_mode == ED_MODE_PALETTE)
+ DrawPaletteWindow();
+ else /* edit_mode == ED_MODE_DRAWING */
+ DrawDrawingWindowExt(remap_toolbox_gadgets);
+}
+
+static void DrawEditModeWindow()
+{
+ DrawEditModeWindowExt(TRUE);
+}
+
+static void DrawEditModeWindow_PlayfieldOnly()
+{
+ DrawEditModeWindowExt(FALSE);
+}
+
+static void ChangeEditModeWindow(int new_edit_mode)
+{
+ edit_mode = (new_edit_mode != edit_mode ? new_edit_mode : ED_MODE_DRAWING);
+
+ DrawEditModeWindow();
+}
+
+static boolean LevelChanged()
+{
+ boolean field_changed = FALSE;
+ int x, y;
+
+ for (y = 0; y < lev_fieldy; y++)
+ for (x = 0; x < lev_fieldx; x++)
+ if (Feld[x][y] != level.field[x][y])
+ field_changed = TRUE;
+
+ return (level.changed || field_changed);
+}
+
+static boolean PrepareSavingIntoPersonalLevelSet()
+{
+ static LevelDirTree *last_copied_leveldir = NULL;
+ static LevelDirTree *last_written_leveldir = NULL;
+ static int last_copied_level_nr = -1;
+ static int last_written_level_nr = -1;
+ LevelDirTree *leveldir_former = leveldir_current;
+ int level_nr_former = level_nr;
+ int new_level_nr;
+
+ // remember last mod/save so that for current session, we write
+ // back to the same personal copy, asking only about overwrite.
+ if (leveldir_current == last_copied_leveldir &&
+ level_nr == last_copied_level_nr)
+ {
+ // "cd" to personal level set dir (as used when writing last copy)
+ leveldir_current = last_written_leveldir;
+ level_nr = last_written_level_nr;
+
+ return TRUE;
+ }
+
+ if (!Request("This level is read only! "
+ "Save into personal level set?", REQ_ASK))
+ return FALSE;
+
+ // "cd" to personal level set dir (for writing copy the first time)
+ leveldir_current =
+ getTreeInfoFromIdentifier(leveldir_first, getLoginName());
+
+ // find unused level number
+ for (new_level_nr = leveldir_current->first_level; ; new_level_nr++)
+ {
+ static char *level_filename = NULL;
+
+ setString(&level_filename, getDefaultLevelFilename(new_level_nr));
+
+ if (!fileExists(level_filename))
+ break;
+ }
+
+ last_copied_leveldir = leveldir_former;
+ last_copied_level_nr = level_nr_former;
+
+ last_written_leveldir = leveldir_current;
+ last_written_level_nr = level_nr = new_level_nr;
+
+ return TRUE;
+}
+
+static void ModifyLevelInfoForSavingIntoPersonalLevelSet(char *former_name)
+{
+ static char *filename_levelinfo = NULL, *mod_name = NULL;
+ FILE *file;
+
+ // annotate this copy-and-mod in personal levelinfo.conf
+ setString(&filename_levelinfo,
+ getPath2(getCurrentLevelDir(), LEVELINFO_FILENAME));
+
+ if ((file = fopen(filename_levelinfo, MODE_APPEND)))
+ {
+ fprintf(file, "\n");
+ fprintf(file, "# level %d was modified from:\n", level_nr);
+ fprintf(file, "# - previous level set name: %s\n",
+ former_name);
+ fprintf(file, "# - level within previous set: %d \"%s\"\n",
+ level.file_info.nr, level.name);
+ fprintf(file, "# - previous author: %s\n",
+ level.author);
+ fprintf(file, "# - previous save date: ");
+
+ if (level.creation_date.src == DATE_SRC_LEVELFILE)
+ {
+ fprintf(file, "%04d-%02d-%02d\n",
+ level.creation_date.year,
+ level.creation_date.month,
+ level.creation_date.day);
+ }
+ else
+ {
+ fprintf(file, "not recorded\n");
+ }
+
+ fclose(file);
+ }
+
+ if (level_nr > leveldir_current->last_level)
+ UpdateUserLevelSet(getLoginName(), NULL, NULL, level_nr + 9);
+
+ // else: allow the save even if annotation failed
+
+ // now... spray graffiti on the old level vital statistics
+ // user can change these; just trying to set a good baseline
+
+ // don't truncate names for fear of making offensive or silly:
+ // long-named original author only recorded in levelinfo.conf.
+ // try to fit "Joe after Bob", "Joe (ed.)", then just "Joe"
+ if (!strEqual(level.author, leveldir_current->author))
+ {
+ setString(&mod_name, getStringCat3(leveldir_current->author,
+ " after ", level.author));
+
+ if (strlen(mod_name) > MAX_LEVEL_AUTHOR_LEN)
+ setString(&mod_name,
+ getStringCat2(leveldir_current->author, " (ed.)"));
+
+ if (strlen(mod_name) > MAX_LEVEL_AUTHOR_LEN)
+ setString(&mod_name, leveldir_current->author);
+
+ strncpy(level.author, mod_name, MAX_LEVEL_AUTHOR_LEN);
+
+ // less worried about truncation here
+ setString(&mod_name, getStringCat2("Mod: ", level.name));
+ strncpy(level.name, mod_name, MAX_LEVEL_NAME_LEN);
+ }
+}
+
+static void CopyPlayfield(short src[MAX_LEV_FIELDX][MAX_LEV_FIELDY],
+ short dst[MAX_LEV_FIELDX][MAX_LEV_FIELDY])
+{
+ int x, y;
+
+ for (x = 0; x < lev_fieldx; x++)
+ for (y = 0; y < lev_fieldy; y++)
+ dst[x][y] = src[x][y];
+}
+
+static int setSelectboxValue(int selectbox_id, int new_value)
+{
+ int new_index_value = 0;
+ int i;
+
+ for (i = 0; selectbox_info[selectbox_id].options[i].text != NULL; i++)
+ if (selectbox_info[selectbox_id].options[i].value == new_value)
+ new_index_value = i;
+
+ *selectbox_info[selectbox_id].value =
+ selectbox_info[selectbox_id].options[new_index_value].value;
+
+ return new_index_value;
+}
+
+static void setSelectboxSpecialActionVariablesIfNeeded()
+{
+ int i;
+
+ /* change action mode and arg variables according to action type variable */
+ for (i = 0; action_arg_options[i].value != -1; i++)
+ {
+ if (action_arg_options[i].value == custom_element_change.action_type)
+ {
+ int mode = action_arg_options[i].mode;
+
+ /* only change if corresponding selectbox has changed */
+ if (selectbox_info[ED_SELECTBOX_ID_ACTION_MODE].options !=
+ action_arg_modes[mode])
+ custom_element_change.action_mode = -1;
+
+ /* only change if corresponding selectbox has changed */
+ if (selectbox_info[ED_SELECTBOX_ID_ACTION_ARG].options !=
+ action_arg_options[i].options)
+ custom_element_change.action_arg = -1;
+
+ break;
+ }
+ }
+}
+
+static void setSelectboxSpecialActionOptions()
+{
+ int i;
+
+ /* change action mode and arg selectbox according to action type selectbox */
+ for (i = 0; action_arg_options[i].value != -1; i++)
+ {
+ if (action_arg_options[i].value == custom_element_change.action_type)
+ {
+ int mode = action_arg_options[i].mode;
+
+ ModifyEditorSelectboxOptions(ED_SELECTBOX_ID_ACTION_MODE,
+ action_arg_modes[mode]);
+ ModifyEditorSelectboxValue(ED_SELECTBOX_ID_ACTION_MODE,
+ custom_element_change.action_mode);
+
+ ModifyEditorSelectboxOptions(ED_SELECTBOX_ID_ACTION_ARG,
+ action_arg_options[i].options);
+ ModifyEditorSelectboxValue(ED_SELECTBOX_ID_ACTION_ARG,
+ custom_element_change.action_arg);
+ break;
+ }
+ }
+}
+
+static void copy_custom_element_settings(int element_from, int element_to)
+{
+ struct ElementInfo *ei_from = &element_info[element_from];
+ struct ElementInfo *ei_to = &element_info[element_to];
+
+ copyElementInfo(ei_from, ei_to);
+}
+
+static void replace_custom_element_in_settings(int element_from,
+ int element_to)
+{
+ int i, j, x, y;
+
+ for (i = 0; i < NUM_FILE_ELEMENTS; i++)
+ {
+ struct ElementInfo *ei = &element_info[i];
+
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ if (ei->content.e[x][y] == element_from)
+ ei->content.e[x][y] = element_to;
+
+ for (j = 0; j < ei->num_change_pages; j++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[j];
+
+ if (change->target_element == element_from)
+ change->target_element = element_to;
+
+ if (change->initial_trigger_element == element_from)
+ change->initial_trigger_element = element_to;
+
+ if (change->action_element == element_from)
+ change->action_element = element_to;
+
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ if (change->target_content.e[x][y] == element_from)
+ change->target_content.e[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;
+ }
+}
+
+static void replace_custom_element_in_playfield(int element_from,
+ int element_to)
+{
+ int x, y;
+
+ for (x = 0; x < lev_fieldx; x++)
+ for (y = 0; y < lev_fieldy; y++)
+ if (Feld[x][y] == element_from)
+ Feld[x][y] = element_to;
+}
+
+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) ?
+ EL_INTERNAL_CLIPBOARD_CUSTOM : EL_INTERNAL_CLIPBOARD_GROUP);
+ copy_mode = GADGET_ID_CUSTOM_COPY_TO;
+ }
+ else if (copy_mode == GADGET_ID_CUSTOM_PASTE)
+ {
+ element_old = (IS_CUSTOM_ELEMENT(element_new) ?
+ EL_INTERNAL_CLIPBOARD_CUSTOM : EL_INTERNAL_CLIPBOARD_GROUP);
+ copy_mode = GADGET_ID_CUSTOM_COPY_TO;
+
+ level.changed = TRUE;
+ }
+ else 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;
+ }
+ else
+ {
+ 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);
+ }
+ else if (copy_mode == GADGET_ID_CUSTOM_COPY_TO)
+ {
+ copy_custom_element_settings(element_old, element_new);
+ }
+ else if (copy_mode == GADGET_ID_CUSTOM_EXCHANGE)
+ {
+ copy_custom_element_settings(element_old, EL_INTERNAL_DUMMY);
+ copy_custom_element_settings(element_new, element_old);
+ copy_custom_element_settings(EL_INTERNAL_DUMMY, element_new);
+
+ replace_custom_element_in_settings(element_old, EL_INTERNAL_DUMMY);
+ replace_custom_element_in_settings(element_new, element_old);
+ replace_custom_element_in_settings(EL_INTERNAL_DUMMY, element_new);
+
+ replace_custom_element_in_playfield(element_old, EL_INTERNAL_DUMMY);
+ replace_custom_element_in_playfield(element_new, element_old);
+ replace_custom_element_in_playfield(EL_INTERNAL_DUMMY, element_new);
+ }
+
+ UpdateCustomElementGraphicGadgets();
+ DrawPropertiesWindow();
+
+ return TRUE;
+}
+
+static void CopyCustomElementPropertiesToEditor(int element)
+{
+ int i;
+ int current_change_page = element_info[element].current_change_page;
+
+ /* dynamically (re)build selectbox for selecting change page */
+ for (i = 0; i < element_info[element].num_change_pages; i++)
+ {
+ sprintf(options_change_page_strings[i], "%d", i + 1);
+
+ options_change_page[i].value = i;
+ options_change_page[i].text = options_change_page_strings[i];
+ }
+
+ options_change_page[i].value = -1;
+ options_change_page[i].text = NULL;
+
+ /* needed here to initialize combined element properties */
+ InitElementPropertiesEngine(level.game_version);
+
+ element_info[element].change =
+ &element_info[element].change_page[current_change_page];
+
+ custom_element = element_info[element];
+ custom_element_change = *element_info[element].change;
+
+ /* needed to initially set selectbox options for special action options */
+ setSelectboxSpecialActionOptions();
+
+ /* needed to initially set selectbox value variables to reliable defaults */
+ for (i = 0; i < ED_NUM_SELECTBOX; i++)
+ setSelectboxValue(i, *selectbox_info[i].value);
+
+ for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
+ custom_element_properties[i] = HAS_PROPERTY(element, i);
+
+ for (i = 0; i < NUM_CHANGE_EVENTS; i++)
+ custom_element_change_events[i] = HAS_CHANGE_EVENT(element, i);
+
+ /* ---------- element settings: configure (custom elements) ------------- */
+
+ /* set accessible layer selectbox help value */
+ custom_element.access_type =
+ (IS_WALKABLE(element) ? EP_WALKABLE :
+ IS_PASSABLE(element) ? EP_PASSABLE :
+ custom_element.access_type);
+ custom_element.access_layer =
+ (IS_ACCESSIBLE_OVER(element) ? EP_ACCESSIBLE_OVER :
+ IS_ACCESSIBLE_INSIDE(element) ? EP_ACCESSIBLE_INSIDE :
+ IS_ACCESSIBLE_UNDER(element) ? EP_ACCESSIBLE_UNDER :
+ custom_element.access_layer);
+ custom_element.access_protected =
+ (IS_PROTECTED(element) ? 1 : 0);
+ custom_element_properties[EP_ACCESSIBLE] =
+ (IS_ACCESSIBLE_OVER(element) ||
+ IS_ACCESSIBLE_INSIDE(element) ||
+ IS_ACCESSIBLE_UNDER(element));
+
+ /* set walk-to-object action selectbox help value */
+ custom_element.walk_to_action =
+ (IS_DIGGABLE(element) ? EP_DIGGABLE :
+ IS_COLLECTIBLE_ONLY(element) ? EP_COLLECTIBLE_ONLY :
+ IS_DROPPABLE(element) ? EP_DROPPABLE :
+ IS_THROWABLE(element) ? EP_THROWABLE :
+ IS_PUSHABLE(element) ? EP_PUSHABLE :
+ custom_element.walk_to_action);
+ custom_element_properties[EP_WALK_TO_OBJECT] =
+ (IS_DIGGABLE(element) ||
+ IS_COLLECTIBLE_ONLY(element) ||
+ IS_DROPPABLE(element) ||
+ IS_THROWABLE(element) ||
+ IS_PUSHABLE(element));
+
+ /* set smash targets selectbox help value */
+ custom_element.smash_targets =
+ (CAN_SMASH_EVERYTHING(element) ? EP_CAN_SMASH_EVERYTHING :
+ CAN_SMASH_ENEMIES(element) ? EP_CAN_SMASH_ENEMIES :
+ CAN_SMASH_PLAYER(element) ? EP_CAN_SMASH_PLAYER :
+ custom_element.smash_targets);
+ custom_element_properties[EP_CAN_SMASH] =
+ (CAN_SMASH_EVERYTHING(element) ||
+ CAN_SMASH_ENEMIES(element) ||
+ CAN_SMASH_PLAYER(element));
+
+ /* set deadliness selectbox help value */
+ custom_element.deadliness =
+ (DONT_TOUCH(element) ? EP_DONT_TOUCH :
+ DONT_GET_HIT_BY(element) ? EP_DONT_GET_HIT_BY :
+ DONT_COLLIDE_WITH(element) ? EP_DONT_COLLIDE_WITH :
+ DONT_RUN_INTO(element) ? EP_DONT_RUN_INTO :
+ custom_element.deadliness);
+ custom_element_properties[EP_DEADLY] =
+ (DONT_TOUCH(element) ||
+ DONT_GET_HIT_BY(element) ||
+ DONT_COLLIDE_WITH(element) ||
+ DONT_RUN_INTO(element));
+
+ /* ---------- element settings: advanced (custom elements) --------------- */
+
+ /* set "change by direct action" selectbox help value */
+ custom_element_change.direct_action =
+ (HAS_CHANGE_EVENT(element, CE_TOUCHED_BY_PLAYER) ? CE_TOUCHED_BY_PLAYER :
+ HAS_CHANGE_EVENT(element, CE_PRESSED_BY_PLAYER) ? CE_PRESSED_BY_PLAYER :
+ HAS_CHANGE_EVENT(element, CE_SWITCHED_BY_PLAYER) ? CE_SWITCHED_BY_PLAYER :
+ HAS_CHANGE_EVENT(element, CE_SNAPPED_BY_PLAYER) ? CE_SNAPPED_BY_PLAYER :
+ HAS_CHANGE_EVENT(element, CE_PUSHED_BY_PLAYER) ? CE_PUSHED_BY_PLAYER :
+ HAS_CHANGE_EVENT(element, CE_ENTERED_BY_PLAYER) ? CE_ENTERED_BY_PLAYER :
+ HAS_CHANGE_EVENT(element, CE_LEFT_BY_PLAYER) ? CE_LEFT_BY_PLAYER :
+ HAS_CHANGE_EVENT(element, CE_DROPPED_BY_PLAYER) ? CE_DROPPED_BY_PLAYER :
+ HAS_CHANGE_EVENT(element, CE_SWITCHED) ? CE_SWITCHED :
+ HAS_CHANGE_EVENT(element, CE_HITTING_SOMETHING) ? CE_HITTING_SOMETHING :
+ HAS_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING) ? CE_HIT_BY_SOMETHING :
+ HAS_CHANGE_EVENT(element, CE_BLOCKED) ? CE_BLOCKED :
+ HAS_CHANGE_EVENT(element, CE_IMPACT) ? CE_IMPACT :
+ HAS_CHANGE_EVENT(element, CE_SMASHED) ? CE_SMASHED :
+ HAS_CHANGE_EVENT(element, CE_VALUE_CHANGES) ? CE_VALUE_CHANGES :
+ HAS_CHANGE_EVENT(element, CE_SCORE_CHANGES) ? CE_SCORE_CHANGES :
+ HAS_CHANGE_EVENT(element, CE_VALUE_GETS_ZERO) ? CE_VALUE_GETS_ZERO :
+ HAS_CHANGE_EVENT(element, CE_SCORE_GETS_ZERO) ? CE_SCORE_GETS_ZERO :
+ custom_element_change.direct_action);
+
+ /* set "change by other element action" selectbox help value */
+ custom_element_change.other_action =
+ (HAS_CHANGE_EVENT(element, CE_PLAYER_TOUCHES_X) ? CE_PLAYER_TOUCHES_X :
+ HAS_CHANGE_EVENT(element, CE_PLAYER_PRESSES_X) ? CE_PLAYER_PRESSES_X :
+ HAS_CHANGE_EVENT(element, CE_PLAYER_SWITCHES_X) ? CE_PLAYER_SWITCHES_X :
+ HAS_CHANGE_EVENT(element, CE_PLAYER_SNAPS_X) ? CE_PLAYER_SNAPS_X :
+ HAS_CHANGE_EVENT(element, CE_PLAYER_PUSHES_X) ? CE_PLAYER_PUSHES_X :
+ HAS_CHANGE_EVENT(element, CE_PLAYER_ENTERS_X) ? CE_PLAYER_ENTERS_X :
+ HAS_CHANGE_EVENT(element, CE_PLAYER_LEAVES_X) ? CE_PLAYER_LEAVES_X :
+ HAS_CHANGE_EVENT(element, CE_PLAYER_DIGS_X) ? CE_PLAYER_DIGS_X :
+ HAS_CHANGE_EVENT(element, CE_PLAYER_COLLECTS_X) ? CE_PLAYER_COLLECTS_X :
+ HAS_CHANGE_EVENT(element, CE_PLAYER_DROPS_X) ? CE_PLAYER_DROPS_X :
+ HAS_CHANGE_EVENT(element, CE_TOUCHING_X) ? CE_TOUCHING_X :
+ HAS_CHANGE_EVENT(element, CE_HITTING_X) ? CE_HITTING_X :
+ HAS_CHANGE_EVENT(element, CE_DIGGING_X) ? CE_DIGGING_X :
+ HAS_CHANGE_EVENT(element, CE_HIT_BY_X) ? CE_HIT_BY_X :
+ HAS_CHANGE_EVENT(element, CE_SWITCH_OF_X) ? CE_SWITCH_OF_X :
+ HAS_CHANGE_EVENT(element, CE_CHANGE_OF_X) ? CE_CHANGE_OF_X :
+ HAS_CHANGE_EVENT(element, CE_EXPLOSION_OF_X) ? CE_EXPLOSION_OF_X :
+ HAS_CHANGE_EVENT(element, CE_MOVE_OF_X) ? CE_MOVE_OF_X :
+ HAS_CHANGE_EVENT(element, CE_CREATION_OF_X) ? CE_CREATION_OF_X :
+ HAS_CHANGE_EVENT(element, CE_VALUE_CHANGES_OF_X) ? CE_VALUE_CHANGES_OF_X :
+ HAS_CHANGE_EVENT(element, CE_SCORE_CHANGES_OF_X) ? CE_SCORE_CHANGES_OF_X :
+ HAS_CHANGE_EVENT(element, CE_VALUE_GETS_ZERO_OF_X) ? CE_VALUE_GETS_ZERO_OF_X :
+ HAS_CHANGE_EVENT(element, CE_SCORE_GETS_ZERO_OF_X) ? CE_SCORE_GETS_ZERO_OF_X :
+ custom_element_change.other_action);
+}
+
+static void CopyGroupElementPropertiesToEditor(int element)
+{
+ group_element_info = *element_info[element].group;
+ custom_element = element_info[element]; /* needed for description */
+}
+
+static void CopyClassicElementPropertiesToEditor(int element)
+{
+ if (ELEM_IS_PLAYER(element) || COULD_MOVE_INTO_ACID(element))
+ custom_element_properties[EP_CAN_MOVE_INTO_ACID] =
+ getMoveIntoAcidProperty(&level, element);
+
+ if (MAYBE_DONT_COLLIDE_WITH(element))
+ custom_element_properties[EP_DONT_COLLIDE_WITH] =
+ getDontCollideWithProperty(&level, element);
+}
+
+static void CopyElementPropertiesToEditor(int element)
+{
+ if (IS_CUSTOM_ELEMENT(element))
+ CopyCustomElementPropertiesToEditor(element);
+ else if (IS_GROUP_ELEMENT(element))
+ CopyGroupElementPropertiesToEditor(element);
+ else
+ CopyClassicElementPropertiesToEditor(element);
+}
+
+static boolean AskToCopyAndModifyLevelTemplate()
+{
+ if (Request("Copy and modify settings from level template?", REQ_ASK))
+ {
+ level.use_custom_template = FALSE;
+
+ ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE_1],
+ GDI_CHECKED, FALSE, GDI_END);
+ ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE_2],
+ 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;
+ int access_type_and_layer;
+
+ /* mark that this custom element has been modified */
+ custom_element.modified_settings = TRUE;
+ level.changed = TRUE;
+
+ if (level.use_custom_template)
+ AskToCopyAndModifyLevelTemplate();
+
+ element_info[element] = custom_element;
+ *element_info[element].change = custom_element_change;
+
+ /* ---------- element settings: configure (custom elements) ------------- */
+
+ /* set accessible property from checkbox and selectbox */
+ custom_element_properties[EP_WALKABLE_OVER] = FALSE;
+ custom_element_properties[EP_WALKABLE_INSIDE] = FALSE;
+ custom_element_properties[EP_WALKABLE_UNDER] = FALSE;
+ custom_element_properties[EP_PASSABLE_OVER] = FALSE;
+ custom_element_properties[EP_PASSABLE_INSIDE] = FALSE;
+ custom_element_properties[EP_PASSABLE_UNDER] = FALSE;
+ access_type_and_layer = ((custom_element.access_type == EP_WALKABLE ?
+ EP_WALKABLE_OVER : EP_PASSABLE_OVER) +
+ (custom_element.access_layer - EP_ACCESSIBLE_OVER));
+ custom_element_properties[access_type_and_layer] =
+ custom_element_properties[EP_ACCESSIBLE];
+ custom_element_properties[EP_PROTECTED] =
+ (custom_element.access_protected != 0 &&
+ custom_element_properties[EP_ACCESSIBLE]);
+
+ /* set walk-to-object property from checkbox and selectbox */
+ custom_element_properties[EP_DIGGABLE] = FALSE;
+ custom_element_properties[EP_COLLECTIBLE_ONLY] = FALSE;
+ custom_element_properties[EP_DROPPABLE] = FALSE;
+ custom_element_properties[EP_THROWABLE] = FALSE;
+ custom_element_properties[EP_PUSHABLE] = FALSE;
+ custom_element_properties[custom_element.walk_to_action] =
+ custom_element_properties[EP_WALK_TO_OBJECT];
+
+ /* set smash property from checkbox and selectbox */
+ custom_element_properties[EP_CAN_SMASH_PLAYER] = FALSE;
+ custom_element_properties[EP_CAN_SMASH_ENEMIES] = FALSE;
+ custom_element_properties[EP_CAN_SMASH_EVERYTHING] = FALSE;
+ custom_element_properties[custom_element.smash_targets] =
+ custom_element_properties[EP_CAN_SMASH];
+
+ /* set deadliness property from checkbox and selectbox */
+ custom_element_properties[EP_DONT_RUN_INTO] = FALSE;
+ custom_element_properties[EP_DONT_COLLIDE_WITH] = FALSE;
+ custom_element_properties[EP_DONT_GET_HIT_BY] = FALSE;
+ custom_element_properties[EP_DONT_TOUCH] = FALSE;
+ custom_element_properties[custom_element.deadliness] =
+ custom_element_properties[EP_DEADLY];
+
+ /* ---------- element settings: advanced (custom elements) --------------- */
+
+ /* set player change event from checkbox and selectbox */
+ custom_element_change_events[CE_TOUCHED_BY_PLAYER] = FALSE;
+ custom_element_change_events[CE_PRESSED_BY_PLAYER] = FALSE;
+ custom_element_change_events[CE_SWITCHED_BY_PLAYER] = FALSE;
+ custom_element_change_events[CE_SNAPPED_BY_PLAYER] = FALSE;
+ custom_element_change_events[CE_PUSHED_BY_PLAYER] = FALSE;
+ custom_element_change_events[CE_ENTERED_BY_PLAYER] = FALSE;
+ custom_element_change_events[CE_LEFT_BY_PLAYER] = FALSE;
+ custom_element_change_events[CE_DROPPED_BY_PLAYER] = FALSE;
+ custom_element_change_events[CE_SWITCHED] = FALSE;
+ custom_element_change_events[CE_HITTING_SOMETHING] = FALSE;
+ custom_element_change_events[CE_HIT_BY_SOMETHING] = FALSE;
+ custom_element_change_events[CE_BLOCKED] = FALSE;
+ custom_element_change_events[CE_IMPACT] = FALSE;
+ custom_element_change_events[CE_SMASHED] = FALSE;
+ custom_element_change_events[CE_VALUE_CHANGES] = FALSE;
+ custom_element_change_events[CE_SCORE_CHANGES] = FALSE;
+ custom_element_change_events[CE_VALUE_GETS_ZERO] = FALSE;
+ custom_element_change_events[CE_SCORE_GETS_ZERO] = FALSE;
+ custom_element_change_events[custom_element_change.direct_action] =
+ custom_element_change_events[CE_BY_DIRECT_ACTION];
+
+ /* set other element action change event from checkbox and selectbox */
+ custom_element_change_events[CE_PLAYER_TOUCHES_X] = FALSE;
+ custom_element_change_events[CE_PLAYER_PRESSES_X] = FALSE;
+ custom_element_change_events[CE_PLAYER_SWITCHES_X] = FALSE;
+ custom_element_change_events[CE_PLAYER_SNAPS_X] = FALSE;
+ custom_element_change_events[CE_PLAYER_PUSHES_X] = FALSE;
+ custom_element_change_events[CE_PLAYER_ENTERS_X] = FALSE;
+ custom_element_change_events[CE_PLAYER_LEAVES_X] = FALSE;
+ custom_element_change_events[CE_PLAYER_DIGS_X] = FALSE;
+ custom_element_change_events[CE_PLAYER_COLLECTS_X] = FALSE;
+ custom_element_change_events[CE_PLAYER_DROPS_X] = FALSE;
+ custom_element_change_events[CE_TOUCHING_X] = FALSE;
+ custom_element_change_events[CE_HITTING_X] = FALSE;
+ custom_element_change_events[CE_DIGGING_X] = FALSE;
+ custom_element_change_events[CE_HIT_BY_X] = FALSE;
+ custom_element_change_events[CE_SWITCH_OF_X] = FALSE;
+ custom_element_change_events[CE_CHANGE_OF_X] = FALSE;
+ custom_element_change_events[CE_EXPLOSION_OF_X] = FALSE;
+ custom_element_change_events[CE_MOVE_OF_X] = FALSE;
+ custom_element_change_events[CE_CREATION_OF_X] = FALSE;
+ custom_element_change_events[CE_VALUE_CHANGES_OF_X] = FALSE;
+ custom_element_change_events[CE_SCORE_CHANGES_OF_X] = FALSE;
+ custom_element_change_events[CE_VALUE_GETS_ZERO_OF_X] = FALSE;
+ custom_element_change_events[CE_SCORE_GETS_ZERO_OF_X] = FALSE;
+ custom_element_change_events[custom_element_change.other_action] =
+ custom_element_change_events[CE_BY_OTHER_ACTION];
+
+ for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
+ SET_PROPERTY(element, i, custom_element_properties[i]);
+
+ for (i = 0; i < NUM_CHANGE_EVENTS; i++)
+ SET_CHANGE_EVENT(element, i, custom_element_change_events[i]);
+
+ /* copy change events also to special level editor variable */
+ custom_element = element_info[element];
+ custom_element_change = *element_info[element].change;
+}
+
+static void CopyGroupElementPropertiesToGame(int element)
+{
+ /* mark that this group element has been modified */
+ 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)
+{
+ if (ELEM_IS_PLAYER(element) || COULD_MOVE_INTO_ACID(element))
+ setMoveIntoAcidProperty(&level, element,
+ custom_element_properties[EP_CAN_MOVE_INTO_ACID]);
+
+ if (MAYBE_DONT_COLLIDE_WITH(element))
+ setDontCollideWithProperty(&level, element,
+ custom_element_properties[EP_DONT_COLLIDE_WITH]);
+}
+
+static void CopyElementPropertiesToGame(int element)
+{
+ if (IS_CUSTOM_ELEMENT(element))
+ CopyCustomElementPropertiesToGame(element);
+ else if (IS_GROUP_ELEMENT(element))
+ CopyGroupElementPropertiesToGame(element);
+ else
+ CopyClassicElementPropertiesToGame(element);
+}
+
+void CheckElementDescriptions()
+{
+ int i;
+
+ for (i = 0; i < NUM_FILE_ELEMENTS; i++)
+ if (getElementDescriptionFilename(i) == NULL && !IS_OBSOLETE(i))
+ Error(ERR_WARN, "no element description file for element '%s'",
+ EL_NAME(i));
+}
+
+static int getMaxEdFieldX(boolean has_scrollbar)
+{
+ int scrollbar_width = (has_scrollbar ? ED_SCROLLBUTTON_XSIZE : 0);
+ int sxsize = SXSIZE - scrollbar_width;
+ int max_ed_fieldx = sxsize / ed_tilesize;
+
+ return max_ed_fieldx;
+}
+
+static int getMaxEdFieldY(boolean has_scrollbar)
+{
+ int infotext_height = (IN_PIX_FIELD(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY) ?
+ INFOTEXT_YSIZE_FULL : 0);
+ int scrollbar_height = (has_scrollbar ? ED_SCROLLBUTTON_YSIZE : 0);
+ int sysize = SYSIZE - scrollbar_height - infotext_height;
+ int max_ed_fieldy = sysize / ed_tilesize;
+
+ return max_ed_fieldy;
+}
+
+void InitZoomLevelSettings(int zoom_tilesize)
+{
+ static int last_game_engine_type = GAME_ENGINE_TYPE_UNKNOWN;
+
+ if (zoom_tilesize == -1 && level.game_engine_type != last_game_engine_type)
+ {
+ ed_tilesize = setup.auto_setup.editor_zoom_tilesize;
+ ed_tilesize_default = DEFAULT_EDITOR_TILESIZE;
+
+ if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
+ {
+ ed_tilesize = DEFAULT_EDITOR_TILESIZE_MM;
+ ed_tilesize_default = DEFAULT_EDITOR_TILESIZE_MM;
+ }
+ }
+
+ last_game_engine_type = level.game_engine_type;
+
+ // limit zoom tilesize by upper and lower bound
+ ed_tilesize = MIN(MAX(MICRO_TILESIZE, ed_tilesize), TILESIZE);
+
+ // store zoom tilesize in auto setup file only if it was manually changed
+ if (zoom_tilesize != -1)
+ setup.auto_setup.editor_zoom_tilesize = ed_tilesize;
+
+ MAX_ED_FIELDX = getMaxEdFieldX(FALSE);
+ MAX_ED_FIELDY = getMaxEdFieldY(FALSE);
+}
+
+static void InitDrawingElements()
+{
+ static int game_engine_type_last = GAME_ENGINE_TYPE_UNKNOWN;
+
+ if (level.game_engine_type == game_engine_type_last)
+ return;
+
+ 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;
+ }
+
+ game_engine_type_last = level.game_engine_type;
+}
+
+static void InitLevelSetInfo()
+{
+ snprintf(levelset_name, MAX_LEVEL_NAME_LEN + 1,
+ "%s", leveldir_current->name);
+ snprintf(levelset_author, MAX_LEVEL_AUTHOR_LEN + 1,
+ "%s", leveldir_current->author);
+
+ levelset_num_levels = leveldir_current->levels;
+
+ levelset_use_levelset_artwork = FALSE;
+ levelset_copy_level_template = FALSE;
+
+ levelset_save_mode = LEVELSET_SAVE_MODE_UPDATE;
+}
+
+static void ChangeEditorToLevelSet(char *levelset_subdir)
+{
+ leveldir_current = getTreeInfoFromIdentifier(leveldir_first, levelset_subdir);
+
+ // the previous level set might have used custom artwork
+ ReloadCustomArtwork(0);
+
+ LoadLevelSetup_SeriesInfo();
+
+ SaveLevelSetup_LastSeries();
+ SaveLevelSetup_SeriesInfo();
+
+ TapeErase();
+
+ LoadLevel(level_nr);
+ LoadScore(level_nr);
+
+ DrawLevelEd();
+}
+
+static boolean useEditorDoorAnimation()
+{
+ struct RectWithBorder *vp_door_1 = &viewport.door_1[GAME_MODE_MAIN];
+ boolean door_1_viewport_unchanged =
+ (vp_door_1->x == DX &&
+ vp_door_1->y == DY &&
+ vp_door_1->width == DXSIZE &&
+ vp_door_1->height == DYSIZE);
+ boolean door_1_contains_toolbox =
+ (EX >= DX &&
+ EY >= DY &&
+ EX + EXSIZE <= DX + DXSIZE &&
+ EY + EYSIZE <= DY + DYSIZE);
+
+ return (door_1_viewport_unchanged && door_1_contains_toolbox);
+}
+
+void DrawEditorDoorContent()
+{
+ /* needed for gadgets drawn on background (like palette scrollbar) */
+ SetDoorBackgroundImage(IMG_UNDEFINED);
+
+ /* copy default editor door content to main double buffer */
+ BlitBitmap(graphic_info[IMG_BACKGROUND_PALETTE].bitmap, drawto,
+ graphic_info[IMG_BACKGROUND_PALETTE].src_x,
+ graphic_info[IMG_BACKGROUND_PALETTE].src_y,
+ MIN(DXSIZE, graphic_info[IMG_BACKGROUND_PALETTE].width),
+ MIN(DYSIZE, graphic_info[IMG_BACKGROUND_PALETTE].height),
+ DX, DY);
+
+ /* draw bigger door */
+ DrawSpecialEditorDoor();
+
+ /* draw new control window */
+ BlitBitmap(graphic_info[IMG_BACKGROUND_TOOLBOX].bitmap, drawto,
+ graphic_info[IMG_BACKGROUND_TOOLBOX].src_x,
+ graphic_info[IMG_BACKGROUND_TOOLBOX].src_y,
+ MIN(EXSIZE, graphic_info[IMG_BACKGROUND_TOOLBOX].width),
+ MIN(EYSIZE, graphic_info[IMG_BACKGROUND_TOOLBOX].height),
+ EX, EY);
+
+ /* draw all toolbox gadgets to editor doors */
+ MapControlButtons();
+
+ /* draw all palette gadgets to editor doors */
+ ModifyEditorElementList();
+ RedrawDrawingElements();
+
+ /* copy actual editor door content to door double buffer for OpenDoor() */
+ BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
+}
+
+void DrawLevelEd()
+{
+ int fade_mask = REDRAW_FIELD;
+
+ FadeSoundsAndMusic();
+
+ if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
+ fade_mask = REDRAW_ALL;
+
+ FadeOut(fade_mask);
+
+ /* needed if different viewport properties defined for editor */
+ ChangeViewportPropertiesIfNeeded();
+
+ ClearField();
+
+ InitZoomLevelSettings(-1);
+ InitDrawingElements();
+ InitLevelSetInfo();
+
+#if DEBUG
+ CheckElementDescriptions();
+#endif
+
+ if (level_editor_test_game)
+ {
+ CopyPlayfield(level.field, Feld);
+ CopyPlayfield(FieldBackup, level.field);
+
+ level_editor_test_game = FALSE;
+ }
+ else
+ {
+ edit_mode = ED_MODE_DRAWING;
+ edit_mode_levelinfo = ED_MODE_LEVELINFO_LEVEL;
+ edit_mode_properties = ED_MODE_PROPERTIES_INFO;
+
+ ResetUndoBuffer();
+
+ level_xpos = -1;
+ level_ypos = -1;
+ }
+
+ // redraw_mask |= REDRAW_ALL;
+
+ FreeLevelEditorGadgets();
+ CreateLevelEditorGadgets();
+
+ ReinitializeElementList(); /* update dynamic level element list */
+ ReinitializeElementListButtons(); /* custom element may look different */
+
+ InitElementPropertiesGfxElement();
+
+ UnmapAllGadgets();
+
+ DrawEditModeWindow_PlayfieldOnly();
+
+ DrawMaskedBorder(fade_mask);
+
+ // use door animation if door 1 viewport is unchanged and contains toolbox
+ if (useEditorDoorAnimation())
+ {
+ FadeIn(fade_mask);
+
+ DrawEditorDoorContent();
+
+ OpenDoor(DOOR_OPEN_1 | DOOR_FORCE_ANIM);
+ }
+ else
+ {
+ DrawEditorDoorContent();
+
+ FadeIn(fade_mask);
+ }
+
+ SetDoorState(DOOR_OPEN_1 | DOOR_OPEN_2);
+}
+
+static void AdjustDrawingAreaGadgets()
+{
+ int ed_xsize = lev_fieldx + 2;
+ int ed_ysize = lev_fieldy + 2;
+ int max_ed_fieldx = MAX_ED_FIELDX;
+ int max_ed_fieldy = MAX_ED_FIELDY;
+ boolean horizontal_scrollbar_needed;
+ boolean vertical_scrollbar_needed;
+ int x, y, width, height;
+
+ if (suppressBorderElement())
+ {
+ ed_xsize = max_ed_fieldx;
+ ed_ysize = max_ed_fieldy;
+ }
+
+ /* check if we need any scrollbars */
+ horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
+ vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
+
+ /* check if we have a smaller editor field because of scrollbars */
+ max_ed_fieldx = getMaxEdFieldX(vertical_scrollbar_needed);
+ max_ed_fieldy = getMaxEdFieldY(horizontal_scrollbar_needed);
+
+ /* check again if we now need more scrollbars because of less space */
+ horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
+ vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
+
+ /* check if editor field gets even smaller after adding new scrollbars */
+ max_ed_fieldx = getMaxEdFieldX(vertical_scrollbar_needed);
+ max_ed_fieldy = getMaxEdFieldY(horizontal_scrollbar_needed);
+
+ ed_fieldx = (ed_xsize > max_ed_fieldx ? max_ed_fieldx : ed_xsize);
+ ed_fieldy = (ed_ysize > max_ed_fieldy ? max_ed_fieldy : ed_ysize);
+
+ x = SX + ed_fieldx * ed_tilesize;
+ y = SY + ed_fieldy * ed_tilesize;
+
+ width = ed_fieldx * ed_tilesize - 2 * ED_SCROLLBUTTON_XSIZE;
+ height = ed_fieldy * ed_tilesize - 2 * ED_SCROLLBUTTON_YSIZE;
+
+ /* adjust drawing area gadget */
+ ModifyGadget(level_editor_gadget[GADGET_ID_DRAWING_LEVEL],
+ GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
+ GDI_ITEM_SIZE, ed_tilesize, ed_tilesize,
+ GDI_END);
+
+ /* adjust horizontal scrollbar gadgets */
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LEFT],
+ GDI_Y, y,
+ GDI_END);
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_RIGHT],
+ GDI_X, x - ED_SCROLLBUTTON_XSIZE,
+ GDI_Y, y,
+ GDI_END);
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
+ GDI_Y, y,
+ GDI_WIDTH, width,
+ GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldx,
+ GDI_END);
+
+ /* adjust vertical scrollbar gadgets */
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_UP],
+ GDI_X, x,
+ GDI_END);
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_DOWN],
+ GDI_X, x,
+ GDI_Y, y - ED_SCROLLBUTTON_YSIZE,
+ GDI_END);
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
+ GDI_X, x,
+ GDI_HEIGHT, height,
+ GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldy,
+ GDI_END);
+}
+
+static void AdjustLevelScrollPosition()
+{
+ if (level_xpos < -1)
+ level_xpos = -1;
+ if (level_xpos > lev_fieldx - ed_fieldx + 1)
+ level_xpos = lev_fieldx - ed_fieldx + 1;
+ if (lev_fieldx < ed_fieldx - 2)
+ level_xpos = -1;
+
+ if (level_ypos < -1)
+ level_ypos = -1;
+ if (level_ypos > lev_fieldy - ed_fieldy + 1)
+ level_ypos = lev_fieldy - ed_fieldy + 1;
+ if (lev_fieldy < ed_fieldy - 2)
+ level_ypos = -1;
+
+ if (suppressBorderElement())
+ {
+ level_xpos = 0;
+ level_ypos = 0;
+ }
+}
+
+static void AdjustEditorScrollbar(int id)
+{
+ struct GadgetInfo *gi = level_editor_gadget[id];
+ int items_max, items_visible, item_position;
+
+ if (id == GADGET_ID_SCROLL_HORIZONTAL)
+ {
+ items_max = MAX(lev_fieldx + 2, ed_fieldx);
+ items_visible = ed_fieldx;
+ item_position = level_xpos + 1;
+ }
+ else
+ {
+ items_max = MAX(lev_fieldy + 2, ed_fieldy);
+ items_visible = ed_fieldy;
+ item_position = level_ypos + 1;
+ }
+
+ if (item_position > items_max - items_visible)
+ item_position = items_max - items_visible;
+
+ ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
+ GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
+}
+
+static void AdjustElementListScrollbar()
+{
+ struct GadgetInfo *gi = level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL];
+ int items_max, items_visible, item_position;
+
+ /* correct position of element list scrollbar */
+ if (element_shift < 0)
+ element_shift = 0;
+ if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
+ element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
+
+ items_max = num_editor_elements / ED_ELEMENTLIST_BUTTONS_HORIZ;
+ items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
+ item_position = element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ;
+
+ ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
+ GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
+ GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
+}
+
+static void ModifyEditorCounterValue(int counter_id, int new_value)
+{
+ int *counter_value = counterbutton_info[counter_id].value;
+ int gadget_id = counterbutton_info[counter_id].gadget_id_text;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+
+ ModifyGadget(gi, GDI_NUMBER_VALUE, new_value, GDI_END);
+
+ if (counter_value != NULL)
+ *counter_value = gi->textinput.number_value;
+}
+
+static void ModifyEditorCounterLimits(int counter_id, int min, int max)
+{
+ int gadget_id = counterbutton_info[counter_id].gadget_id_text;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+
+ ModifyGadget(gi, GDI_NUMBER_MIN, min, GDI_NUMBER_MAX, max, GDI_END);
+
+ if (counter_id >= ED_COUNTER_ID_ELEMENT_VALUE1 &&
+ counter_id <= ED_COUNTER_ID_ELEMENT_VALUE4)
+ {
+ int gadget_id_up = counterbutton_info[counter_id].gadget_id_up;
+ struct GadgetInfo *gi_up = level_editor_gadget[gadget_id_up];
+
+ ModifyGadget(gi, GDI_TEXT_SIZE, (max < 10 ? 1 : 3), GDI_END);
+ ModifyGadget(gi_up, GDI_X, gi->x + gi->width + ED_GADGET_SMALL_DISTANCE,
+ GDI_END);
+ }
+}
+
+static void ModifyEditorSelectboxValue(int selectbox_id, int new_value)
+{
+ int gadget_id = selectbox_info[selectbox_id].gadget_id;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+ int new_index_value = setSelectboxValue(selectbox_id, new_value);
+
+ ModifyGadget(gi, GDI_SELECTBOX_INDEX, new_index_value, GDI_END);
+}
+
+static void ModifyEditorSelectboxOptions(int selectbox_id,
+ struct ValueTextInfo *options)
+{
+ int gadget_id = selectbox_info[selectbox_id].gadget_id;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+
+ selectbox_info[selectbox_id].options = options;
+
+ /* set index to zero -- list may be shorter now (correct later, if needed) */
+ ModifyGadget(gi, GDI_SELECTBOX_INDEX, 0,
+ GDI_SELECTBOX_OPTIONS, options, GDI_END);
+}
+
+static void ModifyEditorDrawingArea(int drawingarea_id, int xsize, int ysize)
+{
+ int gadget_id = drawingarea_info[drawingarea_id].gadget_id;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+
+ drawingarea_info[drawingarea_id].area_xsize = xsize;
+ drawingarea_info[drawingarea_id].area_ysize = ysize;
+
+ ModifyGadget(gi, GDI_AREA_SIZE, xsize, ysize, GDI_END);
+}
+
+static void ModifyEditorElementList()
+{
+ int i;
+
+ if (!use_permanent_palette && edit_mode != ED_MODE_PALETTE)
+ return;
+
+ for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
+ {
+ int gadget_id = GADGET_ID_ELEMENTLIST_FIRST + i;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+ struct GadgetDesign *gd = &gi->deco.design;
+ int element = editor_elements[element_shift + i];
+ int tile_size = BUTTON_TILE_SIZE(editor.palette.tile_size);
+
+ UnmapGadget(gi);
+
+ getEditorGraphicSource(element, tile_size, &gd->bitmap, &gd->x, &gd->y);
+
+ ModifyGadget(gi, GDI_INFO_TEXT, getElementInfoText(element), GDI_END);
+
+ MapGadget(gi);
+ }
+}
+
+static void DrawDrawingElementGraphic(int element, struct XYTileSize *pos)
+{
+ int graphic = el2edimg(element);
+ int tile_size = BUTTON_TILE_SIZE(pos->tile_size);
+
+ if (pos->x == -1 &&
+ pos->y == -1)
+ return;
+
+ DrawSizedGraphicExt(drawto, DX + pos->x, DY + pos->y, graphic, 0, tile_size);
+}
+
+static void ModifyDrawingElementButton(int element, int id)
+{
+ struct GadgetInfo *gi = level_editor_gadget[id];
+ Bitmap *deco_bitmap;
+ int deco_x, deco_y;
+ int tile_size = gi->deco.width;
+
+ getEditorGraphicSource(element, tile_size, &deco_bitmap, &deco_x, &deco_y);
+
+ ModifyGadget(gi, GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y, GDI_END);
+}
+
+static void PickDrawingElement(int button, int element)
+{
+ struct
+ {
+ int *new_element;
+ struct XYTileSize *pos;
+ int id;
+ } de, drawing_elements[] =
+ {
+ { &new_element1, &editor.palette.element_left, GADGET_ID_ELEMENT_LEFT },
+ { &new_element2, &editor.palette.element_middle, GADGET_ID_ELEMENT_MIDDLE },
+ { &new_element3, &editor.palette.element_right, GADGET_ID_ELEMENT_RIGHT },
+ };
+
+ if (button < 1 || button > 3)
+ return;
+
+ if (IS_MM_WALL(element))
+ element = map_mm_wall_element(element);
+
+ de = drawing_elements[button - 1];
+
+ *de.new_element = element; // update global drawing element variable
+
+ DrawDrawingElementGraphic(element, de.pos);
+ ModifyDrawingElementButton(element, de.id);
+
+ redraw_mask |= REDRAW_DOOR_1;
+}
+
+static void RedrawDrawingElements()
+{
+ PickDrawingElement(1, new_element1);
+ PickDrawingElement(2, new_element2);
+ PickDrawingElement(3, new_element3);
+}
+
+static void DrawDrawingWindowExt(boolean remap_toolbox_gadgets)
+{
+ stick_element_properties_window = FALSE;
+
+ SetMainBackgroundImage(IMG_UNDEFINED);
+ ClearField();
+
+ UnmapLevelEditorFieldGadgets();
+
+ AdjustDrawingAreaGadgets();
+ AdjustLevelScrollPosition();
+ AdjustEditorScrollbar(GADGET_ID_SCROLL_HORIZONTAL);
+ AdjustEditorScrollbar(GADGET_ID_SCROLL_VERTICAL);
+
+ DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
+
+ MapMainDrawingArea();
+
+ if (remap_toolbox_gadgets)
+ {
+ UnmapLevelEditorToolboxCustomGadgets();
+ MapLevelEditorToolboxDrawingGadgets();
+ }
+}
+
+static void DrawDrawingWindow()
+{
+ DrawDrawingWindowExt(TRUE);
+}
+
+static int getTabulatorBarWidth()
+{
+ struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
+ struct GadgetInfo *gd_gi4 = level_editor_gadget[GADGET_ID_PROPERTIES_CHANGE];
+
+ return gd_gi4->x - gd_gi1->x + gd_gi4->width;
+}
+
+static int getTabulatorBarHeight()
+{
+ return ED_TAB_BAR_HEIGHT;
+}
+
+static Pixel getTabulatorBarColor()
+{
+ struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_LEVELINFO_LEVEL];
+ struct GadgetDesign *gd = &gd_gi1->alt_design[GD_BUTTON_UNPRESSED];
+ int gd_x = gd->x + gd_gi1->border.width / 2;
+ int gd_y = gd->y + gd_gi1->height - 1;
+
+ return GetPixel(gd->bitmap, gd_x, gd_y);
+}
+
+static void DrawLevelInfoTabulatorGadgets()
+{
+ struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_LEVELINFO_LEVEL];
+ Pixel tab_color = getTabulatorBarColor();
+ int id_first = ED_TAB_BUTTON_ID_LEVELINFO_FIRST;
+ int id_last = ED_TAB_BUTTON_ID_LEVELINFO_LAST;
+ int i;
+
+ for (i = id_first; i <= id_last; i++)
+ {
+ int gadget_id = textbutton_info[i].gadget_id;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+ boolean active = (i != edit_mode_levelinfo);
+
+ /* draw background line below tabulator button */
+ ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width, 1);
+
+ /* draw solid line below inactive tabulator buttons */
+ if (!active && tab_color != BLACK_PIXEL) /* black => transparent */
+ FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,
+ ED_GADGET_TINY_DISTANCE, tab_color);
+
+ ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
+ MapTextbuttonGadget(i);
+ }
+
+ /* draw little border line below tabulator buttons */
+ if (tab_color != BLACK_PIXEL) /* black => transparent */
+ FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height +
+ ED_GADGET_TINY_DISTANCE,
+ getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
+}
+
+static void DrawPropertiesTabulatorGadgets()
+{
+ struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
+ struct GadgetDesign *gd = &gd_gi1->alt_design[GD_BUTTON_UNPRESSED];
+ int gd_x = gd->x + gd_gi1->border.width / 2;
+ int gd_y = gd->y + gd_gi1->height - 1;
+ Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
+ int id_first = ED_TEXTBUTTON_ID_PROPERTIES_INFO;
+ int id_last = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG;
+ int i;
+
+ /* draw two config tabulators for player elements */
+ if (ELEM_IS_PLAYER(properties_element))
+ id_last = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2;
+
+ /* draw two config and one "change" tabulator for custom elements */
+ if (IS_CUSTOM_ELEMENT(properties_element))
+ id_last = ED_TEXTBUTTON_ID_PROPERTIES_CHANGE;
+
+ for (i = id_first; i <= id_last; i++)
+ {
+ int gadget_id = textbutton_info[i].gadget_id;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+ boolean active = (i != edit_mode_properties);
+
+ /* use "config 1" and "config 2" instead of "config" for players and CEs */
+ if (i == ED_TEXTBUTTON_ID_PROPERTIES_CONFIG &&
+ (ELEM_IS_PLAYER(properties_element) ||
+ IS_CUSTOM_ELEMENT(properties_element)))
+ continue;
+
+ /* draw background line below tabulator button */
+ ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width, 1);
+
+ /* draw solid line below inactive tabulator buttons */
+ if (!active && tab_color != BLACK_PIXEL) /* black => transparent */
+ FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,
+ ED_GADGET_TINY_DISTANCE, tab_color);
+
+ ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
+ MapTextbuttonGadget(i);
+ }
+
+ /* draw little border line below tabulator buttons */
+ if (tab_color != BLACK_PIXEL) /* black => transparent */
+ FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height +
+ ED_GADGET_TINY_DISTANCE,
+ getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
+}
+
+static void PrintInfoText(char *text, int font_nr, int xpos, int ypos)
+{
+ DrawText(SX + xpos, SY + ypos, text, font_nr);
+}
+
+static int PrintElementDescriptionFromFile(char *filename, int font_nr,
+ int xpos, int ypos)
+{
+ int font_width = getFontWidth(font_nr);
+ int font_height = getFontHeight(font_nr);
+ int max_chars_per_line = (SXSIZE - 2 * xpos) / font_width;
+ int max_lines_drawable = (SYSIZE - ypos) / font_height - 1;
+
+ return DrawTextFile(SX + xpos, SY + ypos, filename, font_nr,
+ max_chars_per_line, -1, max_lines_drawable, 0, -1,
+ TRUE, FALSE, FALSE);
+}
+
+static void DrawLevelInfoLevel()
+{
+ int i;
+
+ /* draw counter gadgets */
+ for (i = ED_COUNTER_ID_LEVEL_FIRST; i <= ED_COUNTER_ID_LEVEL_LAST; i++)
+ MapCounterButtons(i);
+
+ /* draw checkbutton gadgets */
+ for (i = ED_CHECKBUTTON_ID_LEVEL_FIRST; i<= ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
+ MapCheckbuttonGadget(i);
+
+ /* draw selectbox gadgets */
+ for (i = ED_SELECTBOX_ID_LEVEL_FIRST; i <= ED_SELECTBOX_ID_LEVEL_LAST; i++)
+ MapSelectboxGadget(i);
+
+ /* draw text input gadgets */
+ for (i = ED_TEXTINPUT_ID_LEVEL_FIRST; i <= ED_TEXTINPUT_ID_LEVEL_LAST; i++)
+ MapTextInputGadget(i);
+}
+
+static char *getLevelSubdirFromSaveMode(int save_mode)
+{
+ if (save_mode == LEVELSET_SAVE_MODE_CREATE)
+ return getNewUserLevelSubdir();
+
+ return leveldir_current->subdir;
+}
+
+static void DrawLevelInfoLevelSet_DirectoryInfo()
+{
+ char *directory_text = "Level set directory:";
+ char *directory_name = getLevelSubdirFromSaveMode(levelset_save_mode);
+ int font1_nr = FONT_TEXT_1;
+ int font2_nr = FONT_TEXT_2;
+ int font1_height = getFontHeight(font1_nr);
+ int yoffset_above = font1_height + ED_GADGET_LINE_DISTANCE;
+ int x = ED_LEVEL_SETTINGS_X(0);
+ int y = ED_LEVEL_SETTINGS_Y(6);
+
+ PrintInfoText(directory_text, font1_nr, x, y - yoffset_above);
+ PrintInfoText(directory_name, font2_nr, x, y);
+}
+
+static void DrawLevelInfoLevelSet()
+{
+ boolean artwork_exists = checkIfCustomArtworkExistsForCurrentLevelSet();
+ boolean template_exists = fileExists(getLocalLevelTemplateFilename());
+ int i;
+
+ /* draw counter gadgets */
+ for (i = ED_COUNTER_ID_LEVELSET_FIRST; i <= ED_COUNTER_ID_LEVELSET_LAST; i++)
+ MapCounterButtons(i);
+
+ /* draw checkbutton gadgets */
+ for (i = ED_CHECKBUTTON_ID_LEVELSET_FIRST; i <= ED_CHECKBUTTON_ID_LEVELSET_LAST; i++)
+ {
+ if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE ||
+ (i == ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK && !artwork_exists) ||
+ (i == ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE && !template_exists))
+ continue;
+
+ MapCheckbuttonGadget(i);
+ }
+
+ /* draw selectbox gadgets */
+ for (i = ED_SELECTBOX_ID_LEVELSET_FIRST; i <= ED_SELECTBOX_ID_LEVELSET_LAST; i++)
+ MapSelectboxGadget(i);
+
+ /* draw text input gadgets */
+ for (i = ED_TEXTINPUT_ID_LEVELSET_FIRST; i <= ED_TEXTINPUT_ID_LEVELSET_LAST; i++)
+ MapTextInputGadget(i);
+
+ /* draw textbutton gadgets */
+ MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_LEVELSET);
+
+ /* draw info text */
+ DrawLevelInfoLevelSet_DirectoryInfo();
+}
+
+static void DrawLevelInfoEditor()
+{
+ int i;
+
+ /* draw counter gadgets */
+ for (i = ED_COUNTER_ID_EDITOR_FIRST; i <= ED_COUNTER_ID_EDITOR_LAST; i++)
+ MapCounterButtons(i);
+
+ /* draw checkbutton gadgets */
+ for (i=ED_CHECKBUTTON_ID_EDITOR_FIRST; i<= ED_CHECKBUTTON_ID_EDITOR_LAST; i++)
+ MapCheckbuttonGadget(i);
+
+ /* draw radiobutton gadgets */
+ for (i=ED_RADIOBUTTON_ID_EDITOR_FIRST; i<= ED_RADIOBUTTON_ID_EDITOR_LAST; i++)
+ MapRadiobuttonGadget(i);
+
+ /* draw drawing area */
+ MapDrawingArea(ED_DRAWING_ID_RANDOM_BACKGROUND);
+
+ /* draw textbutton gadgets */
+ MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_2);
+}
+
+static void DrawLevelInfoWindow()
+{
+ char *text = "Global Settings";
+ int font_nr = FONT_TITLE_1;
+ struct MenuPosInfo *pos = &editor.settings.headline;
+ int sx = SX + ALIGNED_XPOS(pos->x, getTextWidth(text, font_nr), pos->align);
+ int sy = SY + pos->y;
+
+ stick_element_properties_window = FALSE;
+
+ SetAutomaticNumberOfGemsNeeded();
+
+ UnmapLevelEditorFieldGadgets();
+
+ SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
+ ClearField();
+
+ DrawText(sx, sy, text, font_nr);
+
+ DrawLevelInfoTabulatorGadgets();
+
+ if (edit_mode_levelinfo == ED_MODE_LEVELINFO_LEVEL)
+ DrawLevelInfoLevel();
+ else if (edit_mode_levelinfo == ED_MODE_LEVELINFO_LEVELSET)
+ DrawLevelInfoLevelSet();
+ else if (edit_mode_levelinfo == ED_MODE_LEVELINFO_EDITOR)
+ DrawLevelInfoEditor();
+}
+
+static void DrawCustomContentArea()
+{
+ int id = ED_DRAWING_ID_CUSTOM_CONTENT;
+ struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
+ int x1 = right_gadget_border[GADGET_ID_CUSTOM_DEADLINESS];
+ int x2 = right_gadget_border[GADGET_ID_CUSTOM_EXPLOSION_TYPE];
+ int x3 = right_gadget_border[GADGET_ID_CUSTOM_EXPLODE_IMPACT];
+ int xoffset = ED_GADGET_SPACE_DISTANCE;
+
+ /* add distance for potential left text (without drawing area border) */
+ x2 += getTextWidthForGadget(drawingarea_info[id].text_left);
+
+ ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
+
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_CONTENT);
+}
+
+static void DrawCustomChangeContentArea()
+{
+ int id = ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT;
+ struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
+ int x1 = right_gadget_border[GADGET_ID_CHANGE_USE_CONTENT];
+ int x2 = right_gadget_border[GADGET_ID_CHANGE_REPLACE_WHEN];
+ int x3 = right_gadget_border[GADGET_ID_CHANGE_ONLY_COMPLETE];
+ int xoffset = ED_GADGET_SPACE_DISTANCE;
+
+ ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
+
+ MapDrawingArea(id);
+}
+
+static void RemoveElementContentArea(int id, int font_height)
+{
+ int border_size = ED_DRAWINGAREA_BORDER_SIZE;
+
+ DrawBackground(SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size,
+ SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size,
+ 3 * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
+ 3 * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size +
+ ED_GADGET_TEXT_DISTANCE + font_height);
+}
+
+static void DrawYamYamContentAreas()
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ int tilesize = ED_DRAWINGAREA_TILE_SIZE;
+ int yoffset = (tilesize - font_height) / 2;
+ int x = SX + ED_AREA_YAMYAM_CONTENT_X(3) + 4 * tilesize;
+ int y = SY + ED_AREA_YAMYAM_CONTENT_Y(3) + yoffset;
+ int i;
+
+ /* display counter to choose number of element content areas */
+ MapCounterButtons(ED_COUNTER_ID_YAMYAM_CONTENT);
+
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ {
+ int id = ED_DRAWING_ID_YAMYAM_CONTENT_0 + i;
+
+ if (i < level.num_yamyam_contents)
+ {
+ MapDrawingArea(id);
+ }
+ else
+ {
+ UnmapDrawingArea(id);
+
+ /* delete content areas in case of reducing number of them */
+ RemoveElementContentArea(id, font_height);
+ }
+ }
+
+ DrawText(x, y + 0 * tilesize, "content", font_nr);
+ DrawText(x, y + 1 * tilesize, "when", font_nr);
+ DrawText(x, y + 2 * tilesize, "smashed", font_nr);
+}
+
+static void DrawMagicBallContentAreas()
+{
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ int tilesize = ED_DRAWINGAREA_TILE_SIZE;
+ int yoffset = (tilesize - font_height) / 2;
+ int x = SX + ED_AREA_MAGIC_BALL_CONTENT_X(3) + 4 * tilesize;
+ int y = SY + ED_AREA_MAGIC_BALL_CONTENT_Y(3) + yoffset;
+ int i;
+
+ /* display counter to choose number of element content areas */
+ MapCounterButtons(ED_COUNTER_ID_BALL_CONTENT);
+
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ {
+ int id = ED_DRAWING_ID_MAGIC_BALL_CONTENT_0 + i;
+
+ if (i < level.num_ball_contents)
+ {
+ MapDrawingArea(id);
+ }
+ else
+ {
+ UnmapDrawingArea(id);
+
+ /* delete content areas in case of reducing number of them */
+ RemoveElementContentArea(id, font_height);
+ }
+ }
+
+ DrawText(x, y + 0 * tilesize, "generated", font_nr);
+ DrawText(x, y + 1 * tilesize, "when", font_nr);
+ DrawText(x, y + 2 * tilesize, "active", font_nr);
+}
+
+static void DrawAndroidElementArea(int element)
+{
+ int id = ED_DRAWING_ID_ANDROID_CONTENT;
+ int num_elements = level.num_android_clone_elements;
+ int border_size = ED_DRAWINGAREA_BORDER_SIZE;
+ int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
+ int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
+ int xsize = MAX_ANDROID_ELEMENTS;
+ int ysize = 1;
+
+ /* display counter to choose number of element areas */
+ MapCounterButtons(ED_COUNTER_ID_ANDROID_CONTENT);
+
+ if (drawingarea_info[id].text_left != NULL)
+ sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
+
+ UnmapDrawingArea(id);
+
+ ModifyEditorDrawingArea(id, num_elements, 1);
+
+ /* delete content areas in case of reducing number of them */
+ DrawBackground(sx, sy,
+ xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
+ ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
+
+ MapDrawingArea(id);
+}
+
+static void DrawGroupElementArea(int element)
+{
+ int id = ED_DRAWING_ID_GROUP_CONTENT;
+ int num_elements = group_element_info.num_elements;
+ int border_size = ED_DRAWINGAREA_BORDER_SIZE;
+ int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
+ int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
+ int xsize = MAX_ELEMENTS_IN_GROUP;
+ int ysize = 1;
+
+ if (drawingarea_info[id].text_left != NULL)
+ sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
+
+ UnmapDrawingArea(id);
+
+ ModifyEditorDrawingArea(id, num_elements, 1);
+
+ /* delete content areas in case of reducing number of them */
+ DrawBackground(sx, sy,
+ xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
+ ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
+
+ MapDrawingArea(id);
+}
+
+static void DrawPlayerInitialInventoryArea(int element)
+{
+ int id = ED_DRAWING_ID_INVENTORY_CONTENT;
+ int player_nr = GET_PLAYER_NR(element);
+ int num_elements = level.initial_inventory_size[player_nr];
+ int border_size = ED_DRAWINGAREA_BORDER_SIZE;
+ int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
+ int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
+ int xsize = MAX_INITIAL_INVENTORY_SIZE;
+ int ysize = 1;
+
+ /* determine horizontal position to the right of specified gadget */
+ if (drawingarea_info[id].gadget_id_align != GADGET_ID_NONE)
+ sx = (right_gadget_border[drawingarea_info[id].gadget_id_align] +
+ ED_DRAWINGAREA_TEXT_DISTANCE);
+
+ /* determine horizontal offset for leading text */
+ if (drawingarea_info[id].text_left != NULL)
+ sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
+
+ UnmapDrawingArea(id);
+
+ ModifyEditorDrawingArea(id, num_elements, 1);
+
+ /* delete content areas in case of reducing number of them */
+ DrawBackground(sx, sy,
+ xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
+ ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
+
+ MapDrawingArea(id);
+}
+
+static void DrawEnvelopeTextArea(int envelope_nr)
+{
+ int id = ED_TEXTAREA_ID_ENVELOPE_INFO;
+ struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
+
+ UnmapGadget(gi);
+ DrawBackground(gi->x, gi->y, gi->width, gi->height);
+
+ if (envelope_nr != -1)
+ textarea_info[id].value = level.envelope[envelope_nr].text;
+
+ ModifyGadget(gi, GDI_AREA_SIZE,
+ *counterbutton_info[ED_COUNTER_ID_ENVELOPE_XSIZE].value,
+ *counterbutton_info[ED_COUNTER_ID_ENVELOPE_YSIZE].value,
+ GDI_END);
+
+ MapTextAreaGadget(ED_TEXTAREA_ID_ENVELOPE_INFO);
+}
+
+static void DrawPropertiesInfo()
+{
+ static struct
+ {
+ int value;
+ char *text;
+ }
+ properties[] =
+ {
+ /* configurable properties */
+
+ { EP_WALKABLE_OVER, "- player can walk over it" },
+ { EP_WALKABLE_INSIDE, "- player can walk inside it" },
+ { EP_WALKABLE_UNDER, "- player can walk under it" },
+ { EP_PASSABLE_OVER, "- player can pass over it" },
+ { EP_PASSABLE_INSIDE, "- player can pass through it" },
+ { EP_PASSABLE_UNDER, "- player can pass under it" },
+ { EP_PROTECTED, "- player is protected by it" },
+
+ { EP_DIGGABLE, "- can be digged away" },
+ { EP_COLLECTIBLE, "- can be collected" },
+ { EP_DROPPABLE, "- can be dropped after collecting" },
+ { EP_THROWABLE, "- can be thrown after collecting" },
+ { EP_PUSHABLE, "- can be pushed" },
+
+ { EP_CAN_FALL, "- can fall" },
+ { EP_CAN_MOVE, "- can move" },
+
+ { EP_CAN_SMASH_PLAYER, "- can smash player" },
+#if 0
+ { EP_CAN_SMASH_ENEMIES, "- can smash good and bad guys" },
+#endif
+ { EP_CAN_SMASH_EVERYTHING, "- can smash everything smashable" },
+
+ { EP_SLIPPERY, "- slippery for falling elements" },
+ { EP_EM_SLIPPERY_WALL, "- slippery for some gems (EM style)" },
+
+ { EP_DONT_RUN_INTO, "- deadly when running into" },
+ { EP_DONT_COLLIDE_WITH, "- deadly when colliding with" },
+ { EP_DONT_GET_HIT_BY, "- deadly when getting hit by" },
+ { EP_DONT_TOUCH, "- deadly when touching" },
+
+ { EP_INDESTRUCTIBLE, "- indestructible" },
+
+ { EP_CAN_EXPLODE_BY_FIRE, "- can explode by fire or explosions" },
+ { EP_CAN_EXPLODE_SMASHED, "- can explode when smashed" },
+ { EP_CAN_EXPLODE_IMPACT, "- can explode on impact" },
+
+ { EP_CAN_CHANGE, "- can change to other element" },
+
+ /* pre-defined properties */
+ { EP_CAN_PASS_MAGIC_WALL, "- can pass magic walls" },
+ { EP_CAN_PASS_DC_MAGIC_WALL,"- can pass magic walls (DC style)" },
+ { EP_SWITCHABLE, "- can be switched" },
+#if 0
+ { EP_HAS_EDITOR_CONTENT, "- can contain other elements" },
+#endif
+
+ { -1, NULL }
+ };
+ char *filename = getElementDescriptionFilename(properties_element);
+ char *percentage_text = "In this level: ";
+ char *properties_text = "Standard properties: ";
+ char *description_text = "Description:";
+ char *no_description_text = "No description available.";
+ char *none_text = "None";
+ float percentage;
+ int num_elements_in_level;
+ int num_standard_properties = 0;
+ int font1_nr = FONT_TEXT_1;
+ int font2_nr = FONT_TEXT_2;
+ int font1_width = getFontWidth(font1_nr);
+ int font1_height = getFontHeight(font1_nr);
+ int font2_height = getFontHeight(font2_nr);
+ int line1_height = font1_height + ED_GADGET_LINE_DISTANCE;
+ int font2_yoffset = (font1_height - font2_height) / 2;
+ int percentage_text_len = strlen(percentage_text) * font1_width;
+ int properties_text_len = strlen(properties_text) * font1_width;
+ int xpos = ED_ELEMENT_SETTINGS_X(0);
+ int ypos = ED_ELEMENT_SETTINGS_Y(0) + ED_GADGET_SMALL_DISTANCE;
+ int i, x, y;
+
+ if (setup.editor.show_element_token)
+ {
+ int font3_nr = FONT_TEXT_3;
+ int font3_height = getFontHeight(font3_nr);
+
+ DrawTextF(xpos, ypos, font3_nr,
+ "[%s]", element_info[properties_element].token_name);
+
+ ypos += 2 * font3_height;
+ }
+
+ /* ----- print number of elements / percentage of this element in level */
+
+ num_elements_in_level = 0;
+ for (y = 0; y < lev_fieldy; y++)
+ for (x = 0; x < lev_fieldx; x++)
+ if (Feld[x][y] == properties_element)
+ num_elements_in_level++;
+ percentage = num_elements_in_level * 100.0 / (lev_fieldx * lev_fieldy);
+
+ DrawTextS(xpos, ypos, font1_nr, percentage_text);
+
+ if (num_elements_in_level > 0)
+ DrawTextF(xpos + percentage_text_len, ypos + font2_yoffset, font2_nr,
+ "%d (%.2f %%)", num_elements_in_level, percentage);
+ else
+ DrawTextF(xpos + percentage_text_len, ypos + font2_yoffset, font2_nr,
+ none_text);
+
+ ypos += 2 * MAX(font1_height, font2_height);
+
+ /* ----- print standard properties of this element */
+
+ DrawTextS(xpos, ypos, font1_nr, properties_text);
+
+ ypos += line1_height;
+
+ 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);
+
+ ypos += font2_height;
+
+ num_standard_properties++;
+ }
+
+ 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 += MAX(font1_height, font2_height);
+
+ /* ----- print special description of this element */
+
+ PrintInfoText(description_text, font1_nr, xpos, ypos);
+
+ ypos += line1_height;
+
+ if (PrintElementDescriptionFromFile(filename, font2_nr, xpos, ypos) == 0)
+ PrintInfoText(no_description_text, font1_nr, xpos, ypos - line1_height);
+}
+
+#define TEXT_COLLECTING "Score for collecting"
+#define TEXT_SMASHING "Score for smashing"
+#define TEXT_SLURPING "Score for slurping robot"
+#define TEXT_CRACKING "Score for cracking"
+#define TEXT_AMOEBA_SPEED "Speed of amoeba growth"
+#define TEXT_DURATION "Duration when activated"
+#define TEXT_DELAY_ON "Delay before activating"
+#define TEXT_DELAY_OFF "Delay before deactivating"
+#define TEXT_DELAY_EXPLODING "Delay before exploding"
+#define TEXT_DELAY_MOVING "Delay before moving"
+#define TEXT_BALL_DELAY "Element generation delay"
+#define TEXT_MOVE_SPEED "Speed of android moving"
+#define TEXT_CLONE_SPEED "Speed of android cloning"
+#define TEXT_GAME_OF_LIFE_1 "Min neighbours to survive"
+#define TEXT_GAME_OF_LIFE_2 "Max neighbours to survive"
+#define TEXT_GAME_OF_LIFE_3 "Min neighbours to create"
+#define TEXT_GAME_OF_LIFE_4 "Max neighbours to create"
+#define TEXT_TIME_BONUS "Extra time to solve level"
+
+static struct
+{
+ int element;
+ int *value;
+ char *text;
+} elements_with_counter[] =
+{
+ { EL_EMERALD, &level.score[SC_EMERALD], TEXT_COLLECTING },
+ { EL_BD_DIAMOND, &level.score[SC_EMERALD], TEXT_COLLECTING },
+ { EL_EMERALD_YELLOW, &level.score[SC_EMERALD], TEXT_COLLECTING },
+ { EL_EMERALD_RED, &level.score[SC_EMERALD], TEXT_COLLECTING },
+ { EL_EMERALD_PURPLE, &level.score[SC_EMERALD], TEXT_COLLECTING },
+ { EL_SP_INFOTRON, &level.score[SC_EMERALD], TEXT_COLLECTING },
+ { EL_DIAMOND, &level.score[SC_DIAMOND], TEXT_COLLECTING },
+ { EL_CRYSTAL, &level.score[SC_CRYSTAL], TEXT_COLLECTING },
+ { EL_PEARL, &level.score[SC_PEARL], TEXT_COLLECTING },
+ { EL_BUG, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_BUG_RIGHT, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_BUG_UP, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_BUG_LEFT, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_BUG_DOWN, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_BD_BUTTERFLY, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_BD_BUTTERFLY_RIGHT,&level.score[SC_BUG], TEXT_SMASHING },
+ { EL_BD_BUTTERFLY_UP, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_BD_BUTTERFLY_LEFT, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_BD_BUTTERFLY_DOWN, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_SP_ELECTRON, &level.score[SC_BUG], TEXT_SMASHING },
+ { EL_SPACESHIP, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_SPACESHIP_RIGHT, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_SPACESHIP_UP, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_SPACESHIP_LEFT, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_SPACESHIP_DOWN, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_BD_FIREFLY, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_BD_FIREFLY_RIGHT,&level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_BD_FIREFLY_UP, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_BD_FIREFLY_LEFT, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_BD_FIREFLY_DOWN, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_SP_SNIKSNAK, &level.score[SC_SPACESHIP], TEXT_SMASHING },
+ { EL_YAMYAM, &level.score[SC_YAMYAM], TEXT_SMASHING },
+ { EL_YAMYAM_LEFT, &level.score[SC_YAMYAM], TEXT_SMASHING },
+ { EL_YAMYAM_RIGHT, &level.score[SC_YAMYAM], TEXT_SMASHING },
+ { EL_YAMYAM_UP, &level.score[SC_YAMYAM], TEXT_SMASHING },
+ { EL_YAMYAM_DOWN, &level.score[SC_YAMYAM], TEXT_SMASHING },
+ { EL_DARK_YAMYAM, &level.score[SC_YAMYAM], TEXT_SMASHING },
+ { EL_ROBOT, &level.score[SC_ROBOT], TEXT_SMASHING },
+ { EL_PACMAN, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_PACMAN_RIGHT, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_PACMAN_UP, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_PACMAN_LEFT, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_PACMAN_DOWN, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_NUT, &level.score[SC_NUT], TEXT_CRACKING },
+ { EL_DYNAMITE, &level.score[SC_DYNAMITE], TEXT_COLLECTING },
+ { EL_EM_DYNAMITE, &level.score[SC_DYNAMITE], TEXT_COLLECTING },
+ { EL_DYNABOMB_INCREASE_NUMBER,&level.score[SC_DYNAMITE],TEXT_COLLECTING },
+ { EL_DYNABOMB_INCREASE_SIZE, &level.score[SC_DYNAMITE],TEXT_COLLECTING },
+ { EL_DYNABOMB_INCREASE_POWER, &level.score[SC_DYNAMITE],TEXT_COLLECTING },
+ { EL_SHIELD_NORMAL, &level.score[SC_SHIELD], TEXT_COLLECTING },
+ { EL_SHIELD_DEADLY, &level.score[SC_SHIELD], TEXT_COLLECTING },
+ { EL_EXTRA_TIME, &level.extra_time_score, TEXT_COLLECTING },
+ { EL_KEY_1, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_KEY_2, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_KEY_3, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_KEY_4, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_EM_KEY_1, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_EM_KEY_2, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_EM_KEY_3, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_EM_KEY_4, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_EMC_KEY_5, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_EMC_KEY_6, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_EMC_KEY_7, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_EMC_KEY_8, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_DC_KEY_WHITE, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_MM_KETTLE, &level.score[SC_EMERALD], TEXT_COLLECTING },
+ { EL_DF_CELL, &level.score[SC_EMERALD], TEXT_COLLECTING },
+ { EL_MM_KEY, &level.score[SC_KEY], TEXT_COLLECTING },
+ { EL_MM_LIGHTBALL, &level.score[SC_ELEM_BONUS], TEXT_COLLECTING },
+ { EL_MM_PACMAN, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_MM_PACMAN_RIGHT, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_MM_PACMAN_UP, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_MM_PACMAN_LEFT, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_MM_PACMAN_DOWN, &level.score[SC_PACMAN], TEXT_SMASHING },
+ { EL_AMOEBA_WET, &level.amoeba_speed, TEXT_AMOEBA_SPEED },
+ { EL_AMOEBA_DRY, &level.amoeba_speed, TEXT_AMOEBA_SPEED },
+ { EL_AMOEBA_FULL, &level.amoeba_speed, TEXT_AMOEBA_SPEED },
+ { EL_BD_AMOEBA, &level.amoeba_speed, TEXT_AMOEBA_SPEED },
+ { EL_EMC_DRIPPER, &level.amoeba_speed, TEXT_AMOEBA_SPEED },
+ { EL_MAGIC_WALL, &level.time_magic_wall, TEXT_DURATION },
+ { EL_BD_MAGIC_WALL, &level.time_magic_wall, TEXT_DURATION },
+ { EL_DC_MAGIC_WALL, &level.time_magic_wall, TEXT_DURATION },
+ { EL_ROBOT_WHEEL, &level.time_wheel, TEXT_DURATION },
+
+ { EL_TIMEGATE_SWITCH, &level.time_timegate, TEXT_DURATION },
+ { EL_DC_TIMEGATE_SWITCH,&level.time_timegate, TEXT_DURATION },
+ { EL_LIGHT_SWITCH, &level.time_light, TEXT_DURATION },
+ { EL_LIGHT_SWITCH_ACTIVE, &level.time_light, TEXT_DURATION },
+ { EL_SHIELD_NORMAL, &level.shield_normal_time, TEXT_DURATION },
+ { EL_SHIELD_DEADLY, &level.shield_deadly_time, TEXT_DURATION },
+ { EL_EXTRA_TIME, &level.extra_time, TEXT_TIME_BONUS },
+ { EL_TIME_ORB_FULL, &level.time_orb_time, TEXT_TIME_BONUS },
+ { EL_GAME_OF_LIFE, &level.game_of_life[0], TEXT_GAME_OF_LIFE_1 },
+ { EL_GAME_OF_LIFE, &level.game_of_life[1], TEXT_GAME_OF_LIFE_2 },
+ { EL_GAME_OF_LIFE, &level.game_of_life[2], TEXT_GAME_OF_LIFE_3 },
+ { EL_GAME_OF_LIFE, &level.game_of_life[3], TEXT_GAME_OF_LIFE_4 },
+ { EL_BIOMAZE, &level.biomaze[0], TEXT_GAME_OF_LIFE_1 },
+ { EL_BIOMAZE, &level.biomaze[1], TEXT_GAME_OF_LIFE_2 },
+ { EL_BIOMAZE, &level.biomaze[2], TEXT_GAME_OF_LIFE_3 },
+ { EL_BIOMAZE, &level.biomaze[3], TEXT_GAME_OF_LIFE_4 },
+
+ { EL_EMC_ANDROID, &level.android_move_time, TEXT_MOVE_SPEED },
+ { EL_EMC_ANDROID, &level.android_clone_time, TEXT_CLONE_SPEED },
+ { EL_EMC_MAGIC_BALL, &level.ball_time, TEXT_BALL_DELAY },
+ { EL_EMC_LENSES, &level.lenses_score, TEXT_COLLECTING },
+ { EL_EMC_MAGNIFIER, &level.magnify_score, TEXT_COLLECTING },
+ { EL_SPRING, &level.slurp_score, TEXT_SLURPING },
+ { EL_EMC_LENSES, &level.lenses_time, TEXT_DURATION },
+ { EL_EMC_MAGNIFIER, &level.magnify_time, TEXT_DURATION },
+ { EL_MM_FUSE_ACTIVE, &level.mm_time_fuse, TEXT_DELAY_OFF },
+ { EL_MM_BOMB, &level.mm_time_bomb, TEXT_DELAY_EXPLODING },
+ { EL_MM_GRAY_BALL, &level.mm_time_ball, TEXT_DELAY_ON },
+ { EL_MM_STEEL_BLOCK, &level.mm_time_block, TEXT_DELAY_MOVING },
+ { EL_MM_WOODEN_BLOCK, &level.mm_time_block, TEXT_DELAY_MOVING },
+
+ { -1, NULL, NULL }
+};
+
+static boolean checkPropertiesConfig(int element)
+{
+ int i;
+
+ if (IS_GEM(element) ||
+ IS_CUSTOM_ELEMENT(element) ||
+ IS_GROUP_ELEMENT(element) ||
+ IS_BALLOON_ELEMENT(element) ||
+ IS_ENVELOPE(element) ||
+ IS_MM_MCDUFFIN(element) ||
+ IS_DF_LASER(element) ||
+ ELEM_IS_PLAYER(element) ||
+ HAS_EDITOR_CONTENT(element) ||
+ CAN_GROW(element) ||
+ COULD_MOVE_INTO_ACID(element) ||
+ MAYBE_DONT_COLLIDE_WITH(element) ||
+ element == EL_SOKOBAN_OBJECT ||
+ element == EL_SOKOBAN_FIELD_EMPTY ||
+ element == EL_SOKOBAN_FIELD_FULL)
+ return TRUE;
+ else
+ for (i = 0; elements_with_counter[i].element != -1; i++)
+ if (elements_with_counter[i].element == element)
+ return TRUE;
+
+ return FALSE;
+}
+
+static void SetAutomaticNumberOfGemsNeeded()
+{
+ int x, y;
+
+ if (!level.auto_count_gems)
+ return;
+
+ level.gems_needed = 0;
+
+ for (x = 0; x < lev_fieldx; x++)
+ {
+ for (y = 0; y < lev_fieldy; y++)
+ {
+ int element = Feld[x][y];
+
+ if (IS_GEM(element) ||
+ element == EL_MM_KETTLE ||
+ element == EL_DF_CELL)
+ level.gems_needed++;
+ }
+ }
+
+ ModifyEditorCounterValue(ED_COUNTER_ID_LEVEL_GEMSLIMIT, level.gems_needed);
+}
+
+static void DrawPropertiesConfig()
+{
+ boolean draw_footer_line = FALSE;
+ int max_num_element_counters = 4;
+ int num_element_counters = 0;
+ int i;
+
+ if (!checkPropertiesConfig(properties_element))
+ {
+ int xpos = ED_ELEMENT_SETTINGS_X(0);
+ int ypos = ED_ELEMENT_SETTINGS_Y(0) + ED_GADGET_SMALL_DISTANCE;
+
+ PrintInfoText("No configuration options available.",
+ FONT_TEXT_1, xpos, ypos);
+
+ return;
+ }
+
+ /* check if there are elements where a value can be chosen for */
+ for (i = 0; elements_with_counter[i].element != -1; i++)
+ {
+ if (elements_with_counter[i].element == properties_element)
+ {
+ int counter_id = ED_COUNTER_ID_ELEMENT_VALUE1 + num_element_counters;
+
+ counterbutton_info[counter_id].y =
+ ED_ELEMENT_SETTINGS_YPOS(
+ (HAS_EDITOR_CONTENT(properties_element) ? 1 : 0) +
+ (CAN_GROW(properties_element) ? 1 : 0) +
+ (COULD_MOVE_INTO_ACID(properties_element) ? 1 : 0) +
+ (MAYBE_DONT_COLLIDE_WITH(properties_element) ? 1 : 0) +
+ (properties_element == EL_EMC_MAGIC_BALL ? 2 : 0) +
+ num_element_counters);
+
+ counterbutton_info[counter_id].value = elements_with_counter[i].value;
+ counterbutton_info[counter_id].text_right= elements_with_counter[i].text;
+
+ if (properties_element == EL_GAME_OF_LIFE ||
+ properties_element == EL_BIOMAZE)
+ {
+ counterbutton_info[counter_id].min_value = 0; /* min neighbours */
+ counterbutton_info[counter_id].max_value = 8; /* max neighbours */
+ }
+ else
+ {
+ /* !!! CHANGE THIS FOR CERTAIN ELEMENTS !!! */
+ counterbutton_info[counter_id].min_value = MIN_SCORE;
+ counterbutton_info[counter_id].max_value = MAX_SCORE;
+ }
+
+ MapCounterButtons(counter_id);
+
+ num_element_counters++;
+ if (num_element_counters >= max_num_element_counters)
+ break;
+ }
+ }
+
+ if (HAS_EDITOR_CONTENT(properties_element))
+ {
+ /* draw stickybutton gadget */
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
+
+ if (IS_AMOEBOID(properties_element))
+ MapDrawingArea(ED_DRAWING_ID_AMOEBA_CONTENT);
+ else if (properties_element == EL_YAMYAM ||
+ properties_element == EL_YAMYAM_LEFT ||
+ properties_element == EL_YAMYAM_RIGHT ||
+ properties_element == EL_YAMYAM_UP ||
+ properties_element == EL_YAMYAM_DOWN)
+ DrawYamYamContentAreas();
+ else if (properties_element == EL_EMC_MAGIC_BALL)
+ {
+ DrawMagicBallContentAreas();
+
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_RANDOM_BALL_CONTENT);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INITIAL_BALL_STATE);
+ }
+ else if (properties_element == EL_EMC_ANDROID)
+ DrawAndroidElementArea(properties_element);
+ }
+
+ if (ELEM_IS_PLAYER(properties_element))
+ {
+ int player_nr = GET_PLAYER_NR(properties_element);
+
+ /* these properties can be set for every player individually */
+
+ if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_1)
+ {
+ drawingarea_info[ED_DRAWING_ID_START_ELEMENT].value =
+ &level.start_element[player_nr];
+ drawingarea_info[ED_DRAWING_ID_ARTWORK_ELEMENT].value =
+ &level.artwork_element[player_nr];
+ drawingarea_info[ED_DRAWING_ID_EXPLOSION_ELEMENT].value =
+ &level.explosion_element[player_nr];
+
+ checkbutton_info[ED_CHECKBUTTON_ID_USE_START_ELEMENT].value =
+ &level.use_start_element[player_nr];
+ checkbutton_info[ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT].value =
+ &level.use_artwork_element[player_nr];
+ checkbutton_info[ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT].value =
+ &level.use_explosion_element[player_nr];
+ checkbutton_info[ED_CHECKBUTTON_ID_INITIAL_GRAVITY].value =
+ &level.initial_player_gravity[player_nr];
+
+ selectbox_info[ED_SELECTBOX_ID_PLAYER_SPEED].value =
+ &level.initial_player_stepsize[player_nr];
+
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID);
+ MapCheckbuttonGadget(properties_element == EL_SP_MURPHY ?
+ ED_CHECKBUTTON_ID_SP_BLOCK_LAST_FIELD :
+ ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BLOCK_SNAP_FIELD);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CONTINUOUS_SNAPPING);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INSTANT_RELOCATION);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_SHIFTED_RELOCATION);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_LAZY_RELOCATION);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_START_ELEMENT);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INITIAL_GRAVITY);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_PASS_TO_WALKABLE);
+
+ MapDrawingArea(ED_DRAWING_ID_START_ELEMENT);
+ MapDrawingArea(ED_DRAWING_ID_ARTWORK_ELEMENT);
+ MapDrawingArea(ED_DRAWING_ID_EXPLOSION_ELEMENT);
+
+ MapSelectboxGadget(ED_SELECTBOX_ID_PLAYER_SPEED);
+ }
+ else if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2)
+ {
+ drawingarea_info[ED_DRAWING_ID_INVENTORY_CONTENT].value =
+ &level.initial_inventory_content[player_nr][0];
+
+ counterbutton_info[ED_COUNTER_ID_INVENTORY_SIZE].value =
+ &level.initial_inventory_size[player_nr];
+
+ checkbutton_info[ED_CHECKBUTTON_ID_USE_INITIAL_INVENTORY].value =
+ &level.use_initial_inventory[player_nr];
+
+ /* draw checkbutton gadgets */
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_INITIAL_INVENTORY);
+
+ /* draw counter gadgets */
+ MapCounterButtons(ED_COUNTER_ID_INVENTORY_SIZE);
+
+ /* draw drawing area gadgets */
+ DrawPlayerInitialInventoryArea(properties_element);
+ }
+ }
+
+ if (IS_GEM(properties_element))
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS);
+
+ if (properties_element == EL_EM_DYNAMITE)
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_EXPLODES_BY_FIRE);
+
+ if (COULD_MOVE_INTO_ACID(properties_element) &&
+ !ELEM_IS_PLAYER(properties_element) &&
+ (!IS_CUSTOM_ELEMENT(properties_element) ||
+ edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2))
+ {
+ /* set position for checkbutton for "can move into acid" */
+ checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].x =
+ ED_ELEMENT_SETTINGS_XPOS(IS_CUSTOM_ELEMENT(properties_element) ? 1 : 0);
+ checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].y =
+ ED_ELEMENT_SETTINGS_YPOS(IS_CUSTOM_ELEMENT(properties_element) ? 6 :
+ IS_BALLOON_ELEMENT(properties_element) ||
+ HAS_EDITOR_CONTENT(properties_element) ? 1 : 0);
+
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID);
+ }
+
+ if (MAYBE_DONT_COLLIDE_WITH(properties_element))
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH);
+
+ if (properties_element == EL_SPRING)
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_SPRING_BUG);
+
+ if (properties_element == EL_TIME_ORB_FULL)
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_TIME_ORB_BUG);
+
+ if (CAN_GROW(properties_element))
+ {
+ checkbutton_info[ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE].y =
+ ED_ELEMENT_SETTINGS_YPOS(HAS_EDITOR_CONTENT(properties_element) ? 1 : 0);
+
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE);
+ }
+
+ if (properties_element == EL_SOKOBAN_OBJECT ||
+ properties_element == EL_SOKOBAN_FIELD_EMPTY ||
+ properties_element == EL_SOKOBAN_FIELD_FULL)
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_AUTO_EXIT_SOKOBAN);
+
+ if (IS_BALLOON_ELEMENT(properties_element))
+ MapSelectboxGadget(ED_SELECTBOX_ID_WIND_DIRECTION);
+
+ if (IS_ENVELOPE(properties_element))
+ {
+ int counter1_id = ED_COUNTER_ID_ENVELOPE_XSIZE;
+ int counter2_id = ED_COUNTER_ID_ENVELOPE_YSIZE;
+ int button1_id = ED_CHECKBUTTON_ID_ENVELOPE_AUTOWRAP;
+ int button2_id = ED_CHECKBUTTON_ID_ENVELOPE_CENTERED;
+ int envelope_nr = properties_element - EL_ENVELOPE_1;
+
+ counterbutton_info[counter1_id].value = &level.envelope[envelope_nr].xsize;
+ counterbutton_info[counter2_id].value = &level.envelope[envelope_nr].ysize;
+
+ checkbutton_info[button1_id].value = &level.envelope[envelope_nr].autowrap;
+ checkbutton_info[button2_id].value = &level.envelope[envelope_nr].centered;
+
+ /* display counter to choose size of envelope text area */
+ MapCounterButtons(counter1_id);
+ MapCounterButtons(counter2_id);
+
+ /* display checkbuttons to choose auto-wrap and alignment properties */
+ MapCheckbuttonGadget(button1_id);
+ MapCheckbuttonGadget(button2_id);
+
+ DrawEnvelopeTextArea(envelope_nr);
+ }
+
+ if (IS_MM_MCDUFFIN(properties_element))
+ {
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_MM_LASER_RED);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_MM_LASER_GREEN);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_MM_LASER_BLUE);
+ }
+
+ if (IS_DF_LASER(properties_element))
+ {
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DF_LASER_RED);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DF_LASER_GREEN);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DF_LASER_BLUE);
+ }
+
+ if (IS_CUSTOM_ELEMENT(properties_element))
+ {
+ /* draw stickybutton gadget */
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
+
+ if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_1)
+ {
+ /* draw checkbutton gadgets */
+ for (i = ED_CHECKBUTTON_ID_CUSTOM1_FIRST;
+ i <= ED_CHECKBUTTON_ID_CUSTOM1_LAST; i++)
+ MapCheckbuttonGadget(i);
+
+ /* draw counter gadgets */
+ for (i = ED_COUNTER_ID_CUSTOM1_FIRST;
+ i <= ED_COUNTER_ID_CUSTOM1_LAST; i++)
+ MapCounterButtons(i);
+
+ /* draw selectbox gadgets */
+ for (i = ED_SELECTBOX_ID_CUSTOM1_FIRST;
+ i <= ED_SELECTBOX_ID_CUSTOM1_LAST; i++)
+ MapSelectboxGadget(i);
+
+ /* draw textbutton gadgets */
+ MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1);
+
+ /* draw text input gadgets */
+ MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
+
+ /* draw drawing area gadgets */
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
+
+ draw_footer_line = TRUE;
+ }
+ else if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2)
+ {
+ /* draw checkbutton gadgets */
+ for (i = ED_CHECKBUTTON_ID_CUSTOM2_FIRST;
+ i <= ED_CHECKBUTTON_ID_CUSTOM2_LAST; i++)
+ MapCheckbuttonGadget(i);
+
+ /* draw counter gadgets */
+ for (i = ED_COUNTER_ID_CUSTOM2_FIRST;
+ i <= ED_COUNTER_ID_CUSTOM2_LAST; i++)
+ MapCounterButtons(i);
+
+ /* draw selectbox gadgets */
+ for (i = ED_SELECTBOX_ID_CUSTOM2_FIRST;
+ i <= ED_SELECTBOX_ID_CUSTOM2_LAST; i++)
+ MapSelectboxGadget(i);
+
+ /* draw drawing area gadgets */
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_ENTER);
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_LEAVE);
+ DrawCustomContentArea();
+ }
+ }
+ else if (IS_GROUP_ELEMENT(properties_element))
+ {
+ /* draw stickybutton gadget */
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
+
+ /* draw checkbutton gadgets */
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1);
+
+ /* draw counter gadgets */
+ MapCounterButtons(ED_COUNTER_ID_GROUP_CONTENT);
+
+ /* draw selectbox gadgets */
+ MapSelectboxGadget(ED_SELECTBOX_ID_GROUP_CHOICE_MODE);
+
+ /* draw textbutton gadgets */
+ MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1);
+
+ /* draw drawing area gadgets */
+ DrawGroupElementArea(properties_element);
+
+ /* draw text input gadgets */
+ MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
+
+ /* draw drawing area gadgets */
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
+
+ draw_footer_line = TRUE;
+ }
+
+ /* draw little footer border line above CE/GE use/save template gadgets */
+ if (draw_footer_line)
+ {
+ struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
+ struct GadgetDesign *gd = &gd_gi1->alt_design[GD_BUTTON_UNPRESSED];
+ int gd_x = gd->x + gd_gi1->border.width / 2;
+ int gd_y = gd->y + gd_gi1->height - 1;
+ Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
+
+ if (tab_color != BLACK_PIXEL) /* black => transparent */
+ FillRectangle(drawto,
+ SX + ED_ELEMENT_SETTINGS_X(0),
+ SY + ED_ELEMENT_SETTINGS_Y(14) - ED_SETTINGS_TABS_YOFFSET -
+ ED_TAB_BAR_HEIGHT,
+ getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
+ }
+}
+
+static void DrawPropertiesChangeDrawingAreas()
+{
+ if (IS_CUSTOM_ELEMENT(properties_element))
+ {
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TARGET);
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER);
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_ACTION);
+
+ DrawCustomChangeContentArea();
+ }
+
+ redraw_mask |= REDRAW_FIELD;
+}
+
+static void DrawPropertiesChange()
+{
+ int i;
+
+ /* needed to initially set selectbox options for special action options */
+ setSelectboxSpecialActionOptions();
+
+ /* draw stickybutton gadget */
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
+
+ /* draw checkbutton gadgets */
+ for (i = ED_CHECKBUTTON_ID_CHANGE_FIRST;
+ i <= ED_CHECKBUTTON_ID_CHANGE_LAST; i++)
+ MapCheckbuttonGadget(i);
+
+ /* draw counter gadgets */
+ for (i = ED_COUNTER_ID_CHANGE_FIRST;
+ i <= ED_COUNTER_ID_CHANGE_LAST; i++)
+ MapCounterButtons(i);
+
+ /* draw selectbox gadgets */
+ for (i = ED_SELECTBOX_ID_CHANGE_FIRST;
+ i <= ED_SELECTBOX_ID_CHANGE_LAST; i++)
+ MapSelectboxGadget(i);
+
+ /* draw textbutton gadgets */
+ for (i = ED_TEXTBUTTON_ID_CHANGE_FIRST;
+ i <= ED_TEXTBUTTON_ID_CHANGE_LAST; i++)
+ MapTextbuttonGadget(i);
+
+ /* draw graphicbutton gadgets */
+ for (i = ED_GRAPHICBUTTON_ID_CHANGE_FIRST;
+ i <= ED_GRAPHICBUTTON_ID_CHANGE_LAST; i++)
+ MapGraphicbuttonGadget(i);
+
+ /* draw drawing area gadgets */
+ DrawPropertiesChangeDrawingAreas();
+}
+
+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);
+
+ DrawFixedGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
+}
+
+static void DrawEditorElementName(int x, int y, int font_nr)
+{
+ char *element_name = getElementInfoText(properties_element);
+ int font_width = getFontWidth(font_nr);
+ int font_height = getFontHeight(font_nr);
+ int max_text_width = SXSIZE - x - ED_ELEMENT_SETTINGS_X(0);
+ int max_chars_per_line = max_text_width / font_width;
+ char buffer[max_chars_per_line + 1];
+
+ if (strlen(element_name) <= max_chars_per_line)
+ DrawTextS(x, y, font_nr, element_name);
+ else
+ {
+ int next_pos = max_chars_per_line;
+
+ strncpy(buffer, element_name, max_chars_per_line);
+ buffer[max_chars_per_line] = '\0';
+
+ if (element_name[max_chars_per_line] == ' ')
+ next_pos++;
+ else
+ {
+ int i;
+
+ for (i = max_chars_per_line - 1; i >= 0; i--)
+ if (buffer[i] == ' ')
+ break;
+
+ if (strlen(&element_name[i + 1]) <= max_chars_per_line)
+ {
+ buffer[i] = '\0';
+ next_pos = i + 1;
+ }
+ }
+
+ DrawTextS(x, y - font_height / 2, font_nr, buffer);
+
+ strncpy(buffer, &element_name[next_pos], max_chars_per_line);
+ buffer[max_chars_per_line] = '\0';
+
+ DrawTextS(x, y + font_height / 2, font_nr, buffer);
+ }
+}
+
+static void DrawPropertiesWindow()
+{
+ struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_INPUT_TEXT];
+ int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
+ int border_size = gd->border_size;
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ int xoffset = TILEX + element_border + 3 * border_size;
+ int yoffset = (TILEY - font_height) / 2;
+ int x1 = editor.settings.element_graphic.x + element_border;
+ int y1 = editor.settings.element_graphic.y + element_border;
+ int x2 = (editor.settings.element_name.x == -1 ? x1 + xoffset :
+ editor.settings.element_name.x);
+ int y2 = (editor.settings.element_name.y == -1 ? y1 + yoffset :
+ editor.settings.element_name.y);
+ char *text = "Element Settings";
+ int font2_nr = FONT_TITLE_1;
+ struct MenuPosInfo *pos = &editor.settings.headline;
+ int sx = SX + ALIGNED_XPOS(pos->x, getTextWidth(text, font2_nr), pos->align);
+ int sy = SY + pos->y;
+
+ stick_element_properties_window = FALSE;
+
+ /* make sure that previous properties edit mode exists for this element */
+ if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG_2 &&
+ !IS_CUSTOM_ELEMENT(properties_element))
+ edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_2;
+
+ if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG &&
+ !ELEM_IS_PLAYER(properties_element) &&
+ !IS_CUSTOM_ELEMENT(properties_element))
+ edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
+
+ if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG &&
+ (ELEM_IS_PLAYER(properties_element) ||
+ IS_CUSTOM_ELEMENT(properties_element)))
+ edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_1;
+
+ CopyElementPropertiesToEditor(properties_element);
+
+ UnmapLevelEditorFieldGadgets();
+ UnmapLevelEditorToolboxDrawingGadgets();
+ UnmapLevelEditorToolboxCustomGadgets();
+
+ if (IS_CUSTOM_ELEMENT(properties_element) ||
+ IS_GROUP_ELEMENT(properties_element))
+ MapLevelEditorToolboxCustomGadgets();
+
+ SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
+ ClearField();
+
+ DrawText(sx, sy, text, font2_nr);
+
+ FrameCounter = 0; /* restart animation frame counter */
+
+ DrawElementBorder(SX + x1, SY + y1, TILEX, TILEY, FALSE);
+ DrawEditorElementAnimation(SX + x1, SY + y1);
+ DrawEditorElementName(x2, y2, font_nr);
+
+ DrawPropertiesTabulatorGadgets();
+
+ if (edit_mode_properties == ED_MODE_PROPERTIES_INFO)
+ DrawPropertiesInfo();
+ else if (edit_mode_properties == ED_MODE_PROPERTIES_CHANGE)
+ DrawPropertiesChange();
+ else /* (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG[_1|_2]) */
+ DrawPropertiesConfig();
+}
+
+static void DrawPaletteWindow()
+{
+ int i;
+
+ UnmapLevelEditorFieldGadgets();
+
+ SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
+ ClearField();
+
+ /* map buttons to select elements */
+ for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
+ MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
+ MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
+ MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
+ MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
+}
+
+static void UpdateCustomElementGraphicGadgets()
+{
+ int i;
+
+ InitElementPropertiesGfxElement();
+
+ ModifyEditorElementList();
+ RedrawDrawingElements();
+
+ /* force redraw of all mapped drawing area gadgets */
+ for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
+ {
+ struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[i].gadget_id];
+
+ if (gi->mapped)
+ MapDrawingArea(i);
+ }
+}
+
+static int getOpenDirectionFromTube(int element)
+{
+ switch (element)
+ {
+ case EL_TUBE_LEFT_UP: return (MV_LEFT | MV_UP);
+ case EL_TUBE_LEFT_DOWN: return (MV_LEFT | MV_DOWN);
+ case EL_TUBE_RIGHT_UP: return (MV_RIGHT | MV_UP);
+ case EL_TUBE_RIGHT_DOWN: return (MV_RIGHT | MV_DOWN);
+ case EL_TUBE_HORIZONTAL: return (MV_HORIZONTAL);
+ case EL_TUBE_HORIZONTAL_UP: return (MV_HORIZONTAL | MV_UP);
+ case EL_TUBE_HORIZONTAL_DOWN: return (MV_HORIZONTAL | MV_DOWN);
+ case EL_TUBE_VERTICAL: return (MV_VERTICAL);
+ case EL_TUBE_VERTICAL_LEFT: return (MV_VERTICAL | MV_LEFT);
+ case EL_TUBE_VERTICAL_RIGHT: return (MV_VERTICAL | MV_RIGHT);
+ case EL_TUBE_ANY: return (MV_ANY_DIRECTION);
+ }
+
+ return MV_NONE;
+}
+
+static int getTubeFromOpenDirection(int direction)
+{
+ switch (direction)
+ {
+ case (MV_LEFT | MV_UP): return EL_TUBE_LEFT_UP;
+ case (MV_LEFT | MV_DOWN): return EL_TUBE_LEFT_DOWN;
+ case (MV_RIGHT | MV_UP): return EL_TUBE_RIGHT_UP;
+ case (MV_RIGHT | MV_DOWN): return EL_TUBE_RIGHT_DOWN;
+ case (MV_HORIZONTAL): return EL_TUBE_HORIZONTAL;
+ case (MV_HORIZONTAL | MV_UP): return EL_TUBE_HORIZONTAL_UP;
+ case (MV_HORIZONTAL | MV_DOWN): return EL_TUBE_HORIZONTAL_DOWN;
+ case (MV_VERTICAL): return EL_TUBE_VERTICAL;
+ case (MV_VERTICAL | MV_LEFT): return EL_TUBE_VERTICAL_LEFT;
+ case (MV_VERTICAL | MV_RIGHT): return EL_TUBE_VERTICAL_RIGHT;
+ case (MV_ANY_DIRECTION): return EL_TUBE_ANY;
+
+ /* if only one direction, fall back to simple tube with that direction */
+ case (MV_LEFT): return EL_TUBE_HORIZONTAL;
+ case (MV_RIGHT): return EL_TUBE_HORIZONTAL;
+ case (MV_UP): return EL_TUBE_VERTICAL;
+ case (MV_DOWN): return EL_TUBE_VERTICAL;
+ }
+
+ return EL_EMPTY;
+}
+
+static int getTubeFromOpenDirectionNotEmpty(int direction, int element_old)
+{
+ int element_new = getTubeFromOpenDirection(direction);
+
+ return (element_new != EL_EMPTY ? element_new : element_old);
+}