X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Feditor.c;h=e8201e302b6f3ddcfaa6993a0a5867c1092cdf56;hb=fa26d82a378cebf6b519c566c3f33739ebba7823;hp=db1a37e8705064866c79be94d87ea00baf298a9b;hpb=88a46f726da49d5ae03e736b1388a4b854221685;p=rocksndiamonds.git diff --git a/src/editor.c b/src/editor.c index db1a37e8..e8201e30 100644 --- a/src/editor.c +++ b/src/editor.c @@ -737,7 +737,7 @@ static int counter_xsize = DXSIZE + FONT2_XSIZE - 2 * ED_GADGET_DISTANCE; int element_shift = 0; -int editor_element[] = +int editor_el_boulderdash[] = { EL_CHAR('B'), EL_CHAR('O'), @@ -778,7 +778,11 @@ int editor_element[] = EL_BD_BUTTERFLY_DOWN, EL_BD_FIREFLY_DOWN, EL_EMPTY, +}; +int num_editor_el_boulderdash = SIZEOF_ARRAY_INT(editor_el_boulderdash); +int editor_el_emerald_mine[] = +{ EL_CHAR('E'), EL_CHAR('M'), EL_CHAR('E'), @@ -868,7 +872,11 @@ int editor_element[] = EL_EM_GATE2_GRAY, EL_EM_GATE3_GRAY, EL_EM_GATE4_GRAY, +}; +int num_editor_el_emerald_mine = SIZEOF_ARRAY_INT(editor_el_emerald_mine); +int editor_el_more[] = +{ EL_CHAR('M'), EL_CHAR('O'), EL_CHAR('R'), @@ -968,8 +976,11 @@ int editor_element[] = EL_EMC_WALL5, EL_EMC_WALL6, EL_EMC_WALL7, +}; +int num_editor_el_more = SIZEOF_ARRAY_INT(editor_el_more); - +int editor_el_sokoban[] = +{ EL_CHAR('S'), EL_CHAR('O'), EL_CHAR('K'), @@ -984,7 +995,11 @@ int editor_element[] = EL_SOKOBAN_FIELD_EMPTY, EL_SOKOBAN_FIELD_FULL, EL_STEELWALL, +}; +int num_editor_el_sokoban = SIZEOF_ARRAY_INT(editor_el_sokoban); +int editor_el_supaplex[] = +{ EL_CHAR('S'), EL_CHAR('U'), EL_CHAR('P'), @@ -1044,7 +1059,11 @@ int editor_element[] = EL_SP_HARD_BASE6, EL_SP_CHIP_UPPER, EL_SP_CHIP_LOWER, +}; +int num_editor_el_supaplex = SIZEOF_ARRAY_INT(editor_el_supaplex); +int editor_el_diamond_caves[] = +{ EL_CHAR('D'), EL_CHAR('I'), EL_CHAR('A'), @@ -1124,7 +1143,11 @@ int editor_element[] = EL_SHIELD_DEADLY, EL_EXTRA_TIME, EL_EMPTY, +}; +int num_editor_el_diamond_caves = SIZEOF_ARRAY_INT(editor_el_diamond_caves); +int editor_el_dx_boulderdash[] = +{ EL_CHAR('D'), EL_CHAR('X'), EL_CHAR('-'), @@ -1163,29 +1186,16 @@ int editor_element[] = EL_TRAP, EL_DX_SUPABOMB, EL_EMPTY, - EL_EMPTY, - - /* - EL_CHAR('D'), - EL_CHAR('Y'), - EL_CHAR('N'), - EL_CHAR('A'), - - EL_CHAR('B'), - EL_CHAR('L'), - EL_CHAR('A'), - EL_CHAR('S'), + EL_EMPTY +}; +int num_editor_el_dx_boulderdash = SIZEOF_ARRAY_INT(editor_el_dx_boulderdash); - EL_CHAR_MINUS, +int editor_el_chars[] = +{ EL_CHAR('T'), EL_CHAR('E'), - EL_CHAR('R'), - */ - - EL_EMPTY, - EL_EMPTY, - EL_EMPTY, - EL_EMPTY, + EL_CHAR('X'), + EL_CHAR('T'), EL_CHAR(' '), EL_CHAR('!'), @@ -1265,15 +1275,298 @@ int editor_element[] = EL_CHAR('Ö'), EL_CHAR('Ü'), EL_CHAR('^'), - EL_CHAR(' ') + EL_CHAR('_'), + + EL_CHAR(' '), + EL_CHAR('°'), + EL_CHAR('´'), + EL_CHAR('|') }; -int elements_in_list = sizeof(editor_element)/sizeof(int); +int num_editor_el_chars = SIZEOF_ARRAY_INT(editor_el_chars); + +int editor_el_custom[] = +{ + EL_CHAR('C'), + EL_CHAR('U'), + EL_CHAR('S'), + EL_CHAR('-'), + + EL_CHAR('T'), + EL_CHAR('O'), + EL_CHAR('M'), + EL_CHAR(' '), + + EL_CHAR('E'), + EL_CHAR('L'), + EL_CHAR('E'), + EL_CHAR('M'), + + EL_CHAR('E'), + EL_CHAR('N'), + EL_CHAR('T'), + EL_CHAR('S'), + + EL_CUSTOM_START + 0, + EL_CUSTOM_START + 1, + EL_CUSTOM_START + 2, + EL_CUSTOM_START + 3, + + EL_CUSTOM_START + 4, + EL_CUSTOM_START + 5, + EL_CUSTOM_START + 6, + EL_CUSTOM_START + 7, + + EL_CUSTOM_START + 8, + EL_CUSTOM_START + 9, + EL_CUSTOM_START + 10, + EL_CUSTOM_START + 11, + + EL_CUSTOM_START + 12, + EL_CUSTOM_START + 13, + EL_CUSTOM_START + 14, + EL_CUSTOM_START + 15, + + EL_CUSTOM_START + 16, + EL_CUSTOM_START + 17, + EL_CUSTOM_START + 18, + EL_CUSTOM_START + 19, + + EL_CUSTOM_START + 20, + EL_CUSTOM_START + 21, + EL_CUSTOM_START + 22, + EL_CUSTOM_START + 23, + + EL_CUSTOM_START + 24, + EL_CUSTOM_START + 25, + EL_CUSTOM_START + 26, + EL_CUSTOM_START + 27, + + EL_CUSTOM_START + 28, + EL_CUSTOM_START + 29, + EL_CUSTOM_START + 30, + EL_CUSTOM_START + 31, + + EL_CUSTOM_START + 32, + EL_CUSTOM_START + 33, + EL_CUSTOM_START + 34, + EL_CUSTOM_START + 35, + + EL_CUSTOM_START + 36, + EL_CUSTOM_START + 37, + EL_CUSTOM_START + 38, + EL_CUSTOM_START + 39, + + EL_CUSTOM_START + 40, + EL_CUSTOM_START + 41, + EL_CUSTOM_START + 42, + EL_CUSTOM_START + 43, + + EL_CUSTOM_START + 44, + EL_CUSTOM_START + 45, + EL_CUSTOM_START + 46, + EL_CUSTOM_START + 47, + + EL_CUSTOM_START + 48, + EL_CUSTOM_START + 49, + EL_CUSTOM_START + 50, + EL_CUSTOM_START + 51, + + EL_CUSTOM_START + 52, + EL_CUSTOM_START + 53, + EL_CUSTOM_START + 54, + EL_CUSTOM_START + 55, + + EL_CUSTOM_START + 56, + EL_CUSTOM_START + 57, + EL_CUSTOM_START + 58, + EL_CUSTOM_START + 59, + + EL_CUSTOM_START + 60, + EL_CUSTOM_START + 61, + EL_CUSTOM_START + 62, + EL_CUSTOM_START + 63, + + EL_CUSTOM_START + 64, + EL_CUSTOM_START + 65, + EL_CUSTOM_START + 66, + EL_CUSTOM_START + 67, + + EL_CUSTOM_START + 68, + EL_CUSTOM_START + 69, + EL_CUSTOM_START + 70, + EL_CUSTOM_START + 71, + + EL_CUSTOM_START + 72, + EL_CUSTOM_START + 73, + EL_CUSTOM_START + 74, + EL_CUSTOM_START + 75, + + EL_CUSTOM_START + 76, + EL_CUSTOM_START + 77, + EL_CUSTOM_START + 78, + EL_CUSTOM_START + 79, + + EL_CUSTOM_START + 80, + EL_CUSTOM_START + 81, + EL_CUSTOM_START + 82, + EL_CUSTOM_START + 83, + + EL_CUSTOM_START + 84, + EL_CUSTOM_START + 85, + EL_CUSTOM_START + 86, + EL_CUSTOM_START + 87, + + EL_CUSTOM_START + 88, + EL_CUSTOM_START + 89, + EL_CUSTOM_START + 90, + EL_CUSTOM_START + 91, + + EL_CUSTOM_START + 92, + EL_CUSTOM_START + 93, + EL_CUSTOM_START + 94, + EL_CUSTOM_START + 95, + + EL_CUSTOM_START + 96, + EL_CUSTOM_START + 97, + EL_CUSTOM_START + 98, + EL_CUSTOM_START + 99, + + EL_CUSTOM_START + 100, + EL_CUSTOM_START + 101, + EL_CUSTOM_START + 102, + EL_CUSTOM_START + 103, + + EL_CUSTOM_START + 104, + EL_CUSTOM_START + 105, + EL_CUSTOM_START + 106, + EL_CUSTOM_START + 107, + + EL_CUSTOM_START + 108, + EL_CUSTOM_START + 109, + EL_CUSTOM_START + 110, + EL_CUSTOM_START + 111, + + EL_CUSTOM_START + 112, + EL_CUSTOM_START + 113, + EL_CUSTOM_START + 114, + EL_CUSTOM_START + 115, + + EL_CUSTOM_START + 116, + EL_CUSTOM_START + 117, + EL_CUSTOM_START + 118, + EL_CUSTOM_START + 119, + + EL_CUSTOM_START + 120, + EL_CUSTOM_START + 121, + EL_CUSTOM_START + 122, + EL_CUSTOM_START + 123, + + EL_CUSTOM_START + 124, + EL_CUSTOM_START + 125, + EL_CUSTOM_START + 126, + EL_CUSTOM_START + 127 +}; +int num_editor_el_custom = SIZEOF_ARRAY_INT(editor_el_custom); + +int *editor_elements = NULL; /* dynamically allocated */ +int num_editor_elements = 0; /* dynamically determined */ + +struct +{ + boolean *setup_value; + int *element_list; + int *element_list_size; + + boolean last_setup_value; +} +editor_elements_info[] = +{ + { &setup.editor.el_boulderdash, editor_el_boulderdash, + &num_editor_el_boulderdash }, + { &setup.editor.el_emerald_mine, editor_el_emerald_mine, + &num_editor_el_emerald_mine }, + { &setup.editor.el_more, editor_el_more, + &num_editor_el_more }, + { &setup.editor.el_sokoban, editor_el_sokoban, + &num_editor_el_sokoban }, + { &setup.editor.el_supaplex, editor_el_supaplex, + &num_editor_el_supaplex }, + { &setup.editor.el_diamond_caves, editor_el_diamond_caves, + &num_editor_el_diamond_caves }, + { &setup.editor.el_dx_boulderdash, editor_el_dx_boulderdash, + &num_editor_el_dx_boulderdash }, + { &setup.editor.el_chars, editor_el_chars, + &num_editor_el_chars }, + { &setup.editor.el_custom, editor_el_custom, + &num_editor_el_custom }, + { NULL, NULL, + NULL } +}; + +static void ReinitializeElementList() +{ + int pos = 0; + int i, j; + + if (editor_elements != NULL) + free(editor_elements); + + num_editor_elements = 0; + + /* determine size of element list */ + for (i=0; editor_elements_info[i].setup_value != NULL; i++) + if (*editor_elements_info[i].setup_value) + num_editor_elements += *editor_elements_info[i].element_list_size; + + if (num_editor_elements < ED_NUM_ELEMENTLIST_BUTTONS) + { + /* workaround: offer at least as many elements as element buttons exist */ + int list_nr = 1; /* see above: editor_elements_info for Emerald Mine */ + + *editor_elements_info[list_nr].setup_value = TRUE; + num_editor_elements += *editor_elements_info[list_nr].element_list_size; + } + + editor_elements = checked_malloc(num_editor_elements * sizeof(int)); + + /* fill element list */ + for (i=0; editor_elements_info[i].setup_value != NULL; i++) + if (*editor_elements_info[i].setup_value) + for (j=0; j<*editor_elements_info[i].element_list_size; j++) + editor_elements[pos++] = editor_elements_info[i].element_list[j]; +} + +static void ReinitializeElementListButtons() +{ + static boolean initialization_needed = TRUE; + int i; + + if (!initialization_needed) /* check if editor element setup has changed */ + for (i=0; editor_elements_info[i].setup_value != NULL; i++) + if (editor_elements_info[i].last_setup_value != + *editor_elements_info[i].setup_value) + initialization_needed = TRUE; + + if (!initialization_needed) + return; + + FreeLevelEditorGadgets(); + CreateLevelEditorGadgets(); + + /* store current setup values for next invocation of this function */ + for (i=0; editor_elements_info[i].setup_value != NULL; i++) + editor_elements_info[i].last_setup_value = + *editor_elements_info[i].setup_value; + + initialization_needed = FALSE; +} static char *getElementInfoText(int element) { char *info_text = "unknown"; - if (element < NUM_FILE_ELEMENTS) + if (element < NUM_FILE_ELEMENTS && + element_info[element].editor_description != NULL) info_text = element_info[element].editor_description; else Error(ERR_WARN, "no element description for element %d", element); @@ -1298,13 +1591,13 @@ static void ScrollMiniLevel(int from_x, int from_y, int scroll) { x = (dx == 1 ? 0 : ed_fieldx - 1); for(y=0; y start_sx) { Feld[lx - 1][ly] = delete_buffer[sx - start_sx - 1]; - DrawNewMiniElement(sx - 1, sy, Feld[lx - 1][ly]); + DrawMiniElement(sx - 1, sy, Feld[lx - 1][ly]); DrawLevelText(sx - 1, sy, 0, TEXT_SETCURSOR); } break; @@ -3213,7 +3570,7 @@ static int DrawLevelText(int sx, int sy, char letter, int mode) case TEXT_END: CopyLevelToUndoBuffer(UNDO_IMMEDIATE); - DrawNewMiniElement(sx, sy, Feld[lx][ly]); + DrawMiniElement(sx, sy, Feld[lx][ly]); typing = FALSE; break; @@ -3234,7 +3591,7 @@ static void SetTextCursor(int unused_sx, int unused_sy, int sx, int sy, int ly = sy + level_ypos; if (element == -1) - DrawNewMiniElement(sx, sy, Feld[lx][ly]); + DrawMiniElement(sx, sy, Feld[lx][ly]); else DrawAreaBorder(sx, sy, sx, sy); } @@ -3279,7 +3636,7 @@ static void CopyLevelToUndoBuffer(int mode) last_border_element = BorderElement; SetBorderElement(); if (BorderElement != last_border_element) - DrawNewMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); + DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); #if 0 #ifdef DEBUG @@ -3320,7 +3677,7 @@ static void RandomPlacement(int new_element) for (y=0; y= 0 && x - level_xpos < ed_fieldx && y - level_ypos >= 0 && y - level_ypos < ed_fieldy) - DrawNewMiniElement(x - level_xpos, y - level_ypos, + DrawMiniElement(x - level_xpos, y - level_ypos, EL_EMPTY); } } @@ -3466,16 +3823,16 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) } Feld[lx][ly] = new_element; - DrawNewMiniElement(sx, sy, new_element); + DrawMiniElement(sx, sy, new_element); } } else { - DrawNewMiniGraphicExt(drawto, + DrawMiniGraphicExt(drawto, gi->x + sx * MINI_TILEX, gi->y + sy * MINI_TILEY, el2img(new_element)); - DrawNewMiniGraphicExt(window, + DrawMiniGraphicExt(window, gi->x + sx * MINI_TILEX, gi->y + sy * MINI_TILEY, el2img(new_element)); @@ -3575,7 +3932,7 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) if (button_press_event && Feld[lx][ly] != new_element) { FloodFill(lx, ly, new_element); - DrawNewMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); + DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); CopyLevelToUndoBuffer(UNDO_IMMEDIATE); } break; @@ -3698,7 +4055,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) if (button == 1) ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT); else - DrawNewMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); + DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL], GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END); @@ -3717,7 +4074,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) if (button == 1) ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT); else - DrawNewMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); + DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL], GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END); @@ -3736,7 +4093,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) if (button == 1) ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN); else - DrawNewMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); + DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL], GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END); @@ -3755,7 +4112,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) if (button == 1) ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP); else - DrawNewMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); + DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL], GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END); @@ -3764,12 +4121,12 @@ static void HandleControlButtons(struct GadgetInfo *gi) case GADGET_ID_SCROLL_HORIZONTAL: level_xpos = gi->event.item_position - 1; - DrawNewMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); + DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); break; case GADGET_ID_SCROLL_VERTICAL: level_ypos = gi->event.item_position - 1; - DrawNewMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); + DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos); break; case GADGET_ID_SCROLL_LIST_UP: @@ -3784,8 +4141,8 @@ static void HandleControlButtons(struct GadgetInfo *gi) if (element_shift < 0) element_shift = 0; - if (element_shift > elements_in_list - ED_NUM_ELEMENTLIST_BUTTONS) - element_shift = elements_in_list - ED_NUM_ELEMENTLIST_BUTTONS; + if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS) + element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS; ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL], GDI_SCROLLBAR_ITEM_POSITION, @@ -3797,10 +4154,10 @@ static void HandleControlButtons(struct GadgetInfo *gi) 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_element[element_shift + i]; + int element = editor_elements[element_shift + i]; UnmapGadget(gi); - getNewMiniGraphicSource(el2img(element), &gd->bitmap, &gd->x, &gd->y); + getMiniGraphicSource(el2img(element), &gd->bitmap, &gd->x, &gd->y); ModifyGadget(gi, GDI_INFO_TEXT, getElementInfoText(element), GDI_END); MapGadget(gi); } @@ -3869,7 +4226,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) for(x=0; x