static void UnmapDrawingArea(int id)
{
- UnmapGadget(level_editor_gadget[id]);
+ UnmapGadget(level_editor_gadget[drawingarea_info[id].gadget_id]);
}
static void UnmapLevelEditorWindowGadgets()
static void CopyGroupElementPropertiesToEditor(int element)
{
group_element_info = *element_info[element].group;
+ custom_element = element_info[element]; /* needed for description */
+}
+
+static void CopyElementPropertiesToEditor(int element)
+{
+ if (IS_CUSTOM_ELEMENT(element))
+ CopyCustomElementPropertiesToEditor(element);
+ else if (IS_GROUP_ELEMENT(element))
+ CopyGroupElementPropertiesToEditor(element);
}
static void CopyCustomElementPropertiesToGame(int element)
static void CopyGroupElementPropertiesToGame(int element)
{
+ element_info[element] = custom_element;
+ *element_info[element].group = group_element_info;
+
/* mark that this group element has been modified */
element_info[element].modified_settings = TRUE;
+}
- *element_info[element].group = group_element_info;
+static void CopyElementPropertiesToGame(int element)
+{
+ if (IS_CUSTOM_ELEMENT(element))
+ CopyCustomElementPropertiesToGame(element);
+ else if (IS_GROUP_ELEMENT(element))
+ CopyGroupElementPropertiesToGame(element);
}
void DrawLevelEd()
int i;
/* draw additional "advanced" tabulator for custom elements */
- if (IS_CUSTOM_ELEMENT(properties_element))
+ if (IS_CUSTOM_ELEMENT(properties_element) ||
+ IS_GROUP_ELEMENT(properties_element))
id_last = ED_TEXTBUTTON_ID_PROPERTIES_ADVANCED;
for (i = id_first; i <= id_last; i++)
"[Custom Element %d]", properties_element - EL_CUSTOM_START + 1);
screen_line++;
}
+ else if (IS_GROUP_ELEMENT(properties_element))
+ {
+ DrawTextF(pad_x, pad_y + screen_line++ * font2_height, FONT_TEXT_3,
+ "[Group Element %d]", properties_element - EL_GROUP_START + 1);
+ screen_line++;
+ }
#endif
/* ----- print number of elements / percentage of this element in level */
/* draw text input gadgets */
MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
}
-
- if (IS_GROUP_ELEMENT(properties_element))
+ else if (IS_GROUP_ELEMENT(properties_element))
{
/* draw stickybutton gadget */
i = ED_CHECKBUTTON_ID_STICK_ELEMENT;
checkbutton_info[i].y = ED_SETTINGS_YPOS(0);
MapCheckbuttonGadget(i);
+ /* draw counter gadgets */
MapCounterButtons(ED_COUNTER_ID_GROUP_CONTENT);
+ /* draw drawing area gadgets */
DrawGroupElementArea(properties_element);
+
+ /* draw text input gadgets */
+ MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
}
}
static void DrawPropertiesAdvancedDrawingAreas()
{
MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
- MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TARGET);
- MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER);
- DrawCustomChangeContentArea();
+ if (IS_CUSTOM_ELEMENT(properties_element))
+ {
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TARGET);
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER);
+
+ DrawCustomChangeContentArea();
+ }
redraw_mask |= REDRAW_FIELD;
}
checkbutton_info[i].y = ED_SETTINGS_YPOS(0);
MapCheckbuttonGadget(i);
- /* draw checkbutton gadgets */
- for (i = ED_CHECKBUTTON_ID_CHANGE_FIRST;
- i <= ED_CHECKBUTTON_ID_CHANGE_LAST; i++)
+ if (IS_CUSTOM_ELEMENT(properties_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 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 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 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);
+ }
+ else if (IS_GROUP_ELEMENT(properties_element))
+ {
+ /* draw checkbutton gadgets */
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC);
+ MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE);
- /* draw graphicbutton gadgets */
- for (i = ED_GRAPHICBUTTON_ID_CHANGE_FIRST;
- i <= ED_GRAPHICBUTTON_ID_CHANGE_LAST; i++)
- MapGraphicbuttonGadget(i);
+ /* draw textbutton gadgets */
+ MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE);
+ }
/* draw drawing area gadgets */
DrawPropertiesAdvancedDrawingAreas();
/* make sure that previous properties edit mode exists for this element */
if (edit_mode_properties == ED_MODE_PROPERTIES_ADVANCED &&
- !IS_CUSTOM_ELEMENT(properties_element))
+ !IS_CUSTOM_ELEMENT(properties_element) &&
+ !IS_GROUP_ELEMENT(properties_element))
edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
- if (IS_CUSTOM_ELEMENT(properties_element))
- CopyCustomElementPropertiesToEditor(properties_element);
-
- if (IS_GROUP_ELEMENT(properties_element))
- CopyGroupElementPropertiesToEditor(properties_element);
+ CopyElementPropertiesToEditor(properties_element);
UnmapLevelEditorWindowGadgets();
UnmapLevelEditorToolboxDrawingGadgets();
new_element = GFX_ELEMENT(new_element);
custom_element.gfx_element = new_element;
- CopyCustomElementPropertiesToGame(properties_element);
+ CopyElementPropertiesToGame(properties_element);
UpdateCustomElementGraphicGadgets();
PickDrawingElement(button, custom_element_change.content[sx][sy]);
else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
PickDrawingElement(button, custom_element_change.trigger_element);
+ else if (id == GADGET_ID_GROUP_CONTENT)
+ PickDrawingElement(button, group_element_info.element[sx]);
else if (id == GADGET_ID_RANDOM_BACKGROUND)
PickDrawingElement(button, random_placement_background_element);
else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
counter_id <= ED_COUNTER_ID_CUSTOM_LAST) ||
(counter_id >= ED_COUNTER_ID_CHANGE_FIRST &&
counter_id <= ED_COUNTER_ID_CHANGE_LAST))
- CopyCustomElementPropertiesToGame(properties_element);
+ CopyElementPropertiesToGame(properties_element);
}
static void HandleTextInputGadgets(struct GadgetInfo *gi)
if (type_id == ED_TEXTINPUT_ID_ELEMENT_NAME)
{
- CopyCustomElementPropertiesToGame(properties_element);
+ CopyElementPropertiesToGame(properties_element);
ModifyEditorElementList(); /* update changed button info text */
}
type_id <= ED_SELECTBOX_ID_CUSTOM_LAST) ||
(type_id >= ED_SELECTBOX_ID_CHANGE_FIRST &&
type_id <= ED_SELECTBOX_ID_CHANGE_LAST))
- CopyCustomElementPropertiesToGame(properties_element);
+ CopyElementPropertiesToGame(properties_element);
}
static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
type_id <= ED_CHECKBUTTON_ID_CHANGE_LAST &&
type_id != ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE))
{
- CopyCustomElementPropertiesToGame(properties_element);
+ CopyElementPropertiesToGame(properties_element);
}
if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC)
else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
getElementInfoText(custom_element_change.trigger_element));
+ else if (id == GADGET_ID_GROUP_CONTENT)
+ DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
+ getElementInfoText(group_element_info.element[sx]));
else if (id == GADGET_ID_RANDOM_BACKGROUND)
DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
getElementInfoText(random_placement_background_element));
else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
"Other element triggering change");
+ else if (id == GADGET_ID_GROUP_CONTENT)
+ DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
+ "Group element position: %d", sx + 1);
else if (id == GADGET_ID_RANDOM_BACKGROUND)
DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
"Random placement background");
#define LEVEL_CHUNK_CNT3_UNUSED 10 /* unused CNT3 chunk bytes */
#define LEVEL_CPART_CUS3_SIZE 134 /* size of CUS3 chunk part */
#define LEVEL_CPART_CUS3_UNUSED 15 /* unused CUS3 bytes / part */
+#define LEVEL_CHUNK_GRP1_SIZE 74 /* size of level GRP1 chunk */
#define TAPE_HEADER_SIZE 20 /* size of tape file header */
#define TAPE_HEADER_UNUSED 3 /* unused tape header bytes */
+#define LEVEL_CHUNK_CNT3_SIZE(x) (LEVEL_CHUNK_CNT3_HEADER + (x))
#define LEVEL_CHUNK_CUS3_SIZE(x) (2 + (x) * LEVEL_CPART_CUS3_SIZE)
#define LEVEL_CHUNK_CUS4_SIZE(x) (48 + 48 + (x) * 48)
-#define LEVEL_CHUNK_GRP1_SIZE(x) (2 + 8 + (x) * 2)
/* file identifier strings */
#define LEVEL_COOKIE_TMPL "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_x.x"
for (i = 0; i < MAX_NUM_ELEMENTS; i++)
{
- setElementChangePages(&element_info[i], 1);
- setElementChangeInfoToDefaults(element_info[i].change);
- }
-
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
+ int element = i;
- for (j = 0; j < MAX_ELEMENT_NAME_LEN + 1; j++)
- element_info[element].description[j] = '\0';
- if (element_info[element].custom_description != NULL)
- strncpy(element_info[element].description,
- element_info[element].custom_description, MAX_ELEMENT_NAME_LEN);
- else
- strcpy(element_info[element].description,
- element_info[element].editor_description);
+ setElementChangePages(&element_info[element], 1);
+ setElementChangeInfoToDefaults(element_info[element].change);
- element_info[element].use_gfx_element = FALSE;
- element_info[element].gfx_element = EL_EMPTY_SPACE;
+ if (IS_CUSTOM_ELEMENT(element) || IS_GROUP_ELEMENT(element))
+ {
+ for (j = 0; j < MAX_ELEMENT_NAME_LEN + 1; j++)
+ element_info[element].description[j] = '\0';
- element_info[element].collect_score = 10; /* special default */
- element_info[element].collect_count = 1; /* special default */
+ if (element_info[element].custom_description != NULL)
+ strncpy(element_info[element].description,
+ element_info[element].custom_description,MAX_ELEMENT_NAME_LEN);
+ else
+ strcpy(element_info[element].description,
+ element_info[element].editor_description);
- element_info[element].push_delay_fixed = -1; /* initialize later */
- element_info[element].push_delay_random = -1; /* initialize later */
- element_info[element].move_delay_fixed = 0;
- element_info[element].move_delay_random = 0;
+ element_info[element].use_gfx_element = FALSE;
+ element_info[element].gfx_element = EL_EMPTY_SPACE;
+ }
- element_info[element].move_pattern = MV_ALL_DIRECTIONS;
- element_info[element].move_direction_initial = MV_NO_MOVING;
- element_info[element].move_stepsize = TILEX / 8;
+ if (IS_CUSTOM_ELEMENT(element))
+ {
+ element_info[element].collect_score = 10; /* special default */
+ element_info[element].collect_count = 1; /* special default */
- element_info[element].slippery_type = SLIPPERY_ANY_RANDOM;
+ element_info[element].push_delay_fixed = -1; /* initialize later */
+ element_info[element].push_delay_random = -1; /* initialize later */
+ element_info[element].move_delay_fixed = 0;
+ element_info[element].move_delay_random = 0;
- for (x = 0; x < 3; x++)
- for (y = 0; y < 3; y++)
- element_info[element].content[x][y] = EL_EMPTY_SPACE;
+ element_info[element].move_pattern = MV_ALL_DIRECTIONS;
+ element_info[element].move_direction_initial = MV_NO_MOVING;
+ element_info[element].move_stepsize = TILEX / 8;
- element_info[element].access_type = 0;
- element_info[element].access_layer = 0;
- element_info[element].walk_to_action = 0;
- element_info[element].smash_targets = 0;
- element_info[element].deadliness = 0;
- element_info[element].consistency = 0;
+ element_info[element].slippery_type = SLIPPERY_ANY_RANDOM;
- element_info[element].can_explode_by_fire = FALSE;
- element_info[element].can_explode_smashed = FALSE;
- element_info[element].can_explode_impact = FALSE;
+ for (x = 0; x < 3; x++)
+ for (y = 0; y < 3; y++)
+ element_info[element].content[x][y] = EL_EMPTY_SPACE;
- element_info[element].current_change_page = 0;
+ element_info[element].access_type = 0;
+ element_info[element].access_layer = 0;
+ element_info[element].walk_to_action = 0;
+ element_info[element].smash_targets = 0;
+ element_info[element].deadliness = 0;
+ element_info[element].consistency = 0;
- /* start with no properties at all */
- for (j = 0; j < NUM_EP_BITFIELDS; j++)
- Properties[element][j] = EP_BITMASK_DEFAULT;
+ element_info[element].can_explode_by_fire = FALSE;
+ element_info[element].can_explode_smashed = FALSE;
+ element_info[element].can_explode_impact = FALSE;
- element_info[element].modified_settings = FALSE;
- }
+ element_info[element].current_change_page = 0;
- for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
- {
- int element = EL_GROUP_START + i;
+ /* start with no properties at all */
+ for (j = 0; j < NUM_EP_BITFIELDS; j++)
+ Properties[element][j] = EP_BITMASK_DEFAULT;
- if (element_info[element].group == NULL)
- element_info[element].group =
- checked_malloc(sizeof(struct ElementGroupInfo));
+ element_info[element].modified_settings = FALSE;
+ }
+ else if (IS_GROUP_ELEMENT(element))
+ {
+ /* initialize memory for list of elements in group */
+ if (element_info[element].group == NULL)
+ element_info[element].group =
+ checked_malloc(sizeof(struct ElementGroupInfo));
- for (j = 0; j < MAX_ELEMENTS_IN_GROUP; j++)
- element_info[element].group->element[j] = EL_EMPTY_SPACE;
+ for (j = 0; j < MAX_ELEMENTS_IN_GROUP; j++)
+ element_info[element].group->element[j] = EL_EMPTY_SPACE;
- element_info[element].group->num_elements = 1;
+ /* default: only one element in group */
+ element_info[element].group->num_elements = 1;
+ }
}
BorderElement = EL_STEELWALL;
ReadUnusedBytesFromFile(file, LEVEL_CHUNK_CNT3_UNUSED);
- chunk_size_expected = LEVEL_CHUNK_CNT3_HEADER + envelope_len;
-
+ chunk_size_expected = LEVEL_CHUNK_CNT3_SIZE(envelope_len);
if (chunk_size_expected != chunk_size)
{
ReadUnusedBytesFromFile(file, chunk_size - LEVEL_CHUNK_CNT3_HEADER);
{
Error(ERR_WARN, "invalid custom element number %d", element);
- element = EL_DUMMY;
+ ReadUnusedBytesFromFile(file, chunk_size - 2);
+ return chunk_size;
}
ei = &element_info[element];
static int LoadLevel_GRP1(FILE *file, int chunk_size, struct LevelInfo *level)
{
+ struct ElementInfo *ei;
struct ElementGroupInfo *group;
- int chunk_size_expected;
int element;
int i;
return chunk_size;
}
+ ei = &element_info[element];
+
+ for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
+ ei->description[i] = getFile8Bit(file);
+ ei->description[MAX_ELEMENT_NAME_LEN] = 0;
+
group = element_info[element].group;
group->num_elements = getFile8Bit(file);
- /* some free bytes for future values and padding */
- ReadUnusedBytesFromFile(file, 7);
+ ei->use_gfx_element = getFile8Bit(file);
+ ei->gfx_element = checkLevelElement(getFile16BitBE(file));
- chunk_size_expected = LEVEL_CHUNK_GRP1_SIZE(group->num_elements);
- if (chunk_size_expected != chunk_size)
- {
- ReadUnusedBytesFromFile(file, chunk_size - 10);
- return chunk_size_expected;
- }
+ /* some free bytes for future values and padding */
+ ReadUnusedBytesFromFile(file, 4);
- for (i = 0; i < group->num_elements; i++)
+ for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++)
group->element[i] = checkLevelElement(getFile16BitBE(file));
/* mark this group element as modified */
static void SaveLevel_GRP1(FILE *file, struct LevelInfo *level, int element)
{
- struct ElementGroupInfo *group = element_info[element].group;
+ struct ElementInfo *ei = &element_info[element];
+ struct ElementGroupInfo *group = ei->group;
int i;
putFile16BitBE(file, element);
+ for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
+ putFile8Bit(file, ei->description[i]);
+
putFile8Bit(file, group->num_elements);
+ putFile8Bit(file, ei->use_gfx_element);
+ putFile16BitBE(file, ei->gfx_element);
+
/* some free bytes for future values and padding */
- WriteUnusedBytesToFile(file, 7);
+ WriteUnusedBytesToFile(file, 4);
- for (i = 0; i < group->num_elements; i++)
+ for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++)
putFile16BitBE(file, group->element[i]);
}
{
int envelope_len = strlen(level->envelope_text[i]) + 1;
- putFileChunkBE(file, "CNT3", LEVEL_CHUNK_CNT3_HEADER + envelope_len);
+ putFileChunkBE(file, "CNT3", LEVEL_CHUNK_CNT3_SIZE(envelope_len));
SaveLevel_CNT3(file, level, EL_ENVELOPE_1 + i);
}
}
if (element_info[element].modified_settings)
{
- int num_elements = element_info[element].group->num_elements;
-
- putFileChunkBE(file, "GRP1", LEVEL_CHUNK_GRP1_SIZE(num_elements));
+ putFileChunkBE(file, "GRP1", LEVEL_CHUNK_GRP1_SIZE);
SaveLevel_GRP1(file, level, element);
}
}