X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Feditor.c;h=1265f4f72def1379441a5bd44af6991018146391;hb=57bbc28786e5cc6c531b53ef5e29512b1e0b73e8;hp=54741f74d57655338aae489c5082fecd20f837b7;hpb=9cfd3853252303df85d4fb925993448788d03483;p=rocksndiamonds.git diff --git a/src/editor.c b/src/editor.c index 54741f74..1265f4f7 100644 --- a/src/editor.c +++ b/src/editor.c @@ -18,6 +18,7 @@ #include "buttons.h" #include "files.h" #include "game.h" +#include "tape.h" /* positions in the level editor */ #define ED_WIN_MB_LEFT_XPOS 7 @@ -101,7 +102,7 @@ #define ED_CTRL_ID_RANDOM_PLACEMENT 12 #define ED_CTRL_ID_BRUSH 13 #define ED_CTRL_ID_WRAP_DOWN 14 -#define ED_CTRL_ID_UNUSED2 15 +#define ED_CTRL_ID_PICK_ELEMENT 15 #define ED_CTRL_ID_UNDO 16 #define ED_CTRL_ID_INFO 17 #define ED_CTRL_ID_SAVE 18 @@ -121,7 +122,10 @@ #define ED_CTRL_ID_ELEMCONT_7 34 #define ED_CTRL_ID_AMOEBA_CONTENT 35 -#define ED_NUM_GADGETS 36 +/* text input identifiers */ +#define ED_CTRL_ID_LEVEL_NAME 36 + +#define ED_NUM_GADGETS 37 /* values for counter gadgets */ #define ED_COUNTER_SCORE 0 @@ -145,14 +149,16 @@ static struct static void DrawDrawingWindow(); static void DrawPropertiesWindow(); static void CopyLevelToUndoBuffer(); -static void HandleDrawingAreas(struct GadgetInfo *); -static void HandleCounterButtons(struct GadgetInfo *); static void HandleControlButtons(struct GadgetInfo *); +static void HandleCounterButtons(struct GadgetInfo *); +static void HandleDrawingAreas(struct GadgetInfo *); +static void HandleTextInputGadgets(struct GadgetInfo *); static struct GadgetInfo *level_editor_gadget[ED_NUM_GADGETS]; static boolean level_editor_gadgets_created = FALSE; static int drawing_function = ED_CTRL_ID_SINGLE_ITEMS; +static int last_drawing_function = ED_CTRL_ID_SINGLE_ITEMS; static int properties_element = 0; static short ElementContent[MAX_ELEMCONT][3][3]; @@ -205,7 +211,7 @@ int editor_element[] = EL_BETON, EL_FELSBODEN, - EL_SIEB2_LEER, + EL_SIEB2_INAKTIV, EL_AUSGANG_ZU, EL_AUSGANG_AUF, @@ -252,7 +258,7 @@ int editor_element[] = EL_BETON, EL_MAUERWERK, EL_FELSBODEN, - EL_SIEB_LEER, + EL_SIEB_INAKTIV, EL_EDELSTEIN, EL_DIAMANT, @@ -364,6 +370,11 @@ int editor_element[] = EL_MAUER_Y, EL_MAUER_XY, + EL_SPEED_PILL, + EL_LEERRAUM, + EL_LEERRAUM, + EL_LEERRAUM, + EL_CHAR_A + ('S' - 'A'), EL_CHAR_A + ('O' - 'A'), EL_CHAR_A + ('K' - 'A'), @@ -379,6 +390,71 @@ int editor_element[] = EL_SOKOBAN_FELD_VOLL, EL_BETON, + EL_LEERRAUM, + EL_LEERRAUM, + EL_LEERRAUM, + EL_LEERRAUM, + + EL_CHAR('S'), + EL_CHAR('U'), + EL_CHAR('P'), + EL_CHAR('A'), + + EL_CHAR('P'), + EL_CHAR('L'), + EL_CHAR('E'), + EL_CHAR('X'), + + EL_SP_EMPTY, + EL_SP_ZONK, + EL_SP_BASE, + EL_SP_MURPHY, + + EL_SP_INFOTRON, + EL_SP_CHIP_SINGLE, + EL_SP_HARD_GRAY, + EL_SP_EXIT, + + EL_SP_DISK_ORANGE, + EL_SP_PORT1_RIGHT, + EL_SP_PORT1_DOWN, + EL_SP_PORT1_LEFT, + + EL_SP_PORT1_UP, + EL_SP_PORT2_RIGHT, + EL_SP_PORT2_DOWN, + EL_SP_PORT2_LEFT, + + EL_SP_PORT2_UP, + EL_SP_SNIKSNAK, + EL_SP_DISK_YELLOW, + EL_SP_TERMINAL, + + EL_SP_DISK_RED, + EL_SP_PORT_Y, + EL_SP_PORT_X, + EL_SP_PORT_XY, + + EL_SP_ELECTRON, + EL_SP_BUG, + EL_SP_CHIP_LEFT, + EL_SP_CHIP_RIGHT, + + EL_SP_HARD_BASE1, + EL_SP_HARD_GREEN, + EL_SP_HARD_BLUE, + EL_SP_HARD_RED, + + EL_SP_HARD_YELLOW, + EL_SP_HARD_BASE2, + EL_SP_HARD_BASE3, + EL_SP_HARD_BASE4, + + EL_SP_HARD_BASE5, + EL_SP_HARD_BASE6, + EL_SP_CHIP_UPPER, + EL_SP_CHIP_LOWER, + /* EL_CHAR_A + ('D' - 'A'), EL_CHAR_A + ('Y' - 'A'), @@ -474,62 +550,7 @@ int editor_element[] = EL_CHAR_OE, EL_CHAR_UE, EL_CHAR_COPY, - EL_LEERRAUM, - - EL_LEERRAUM, - EL_LEERRAUM, - EL_LEERRAUM, - EL_LEERRAUM, - - EL_LEERRAUM, - EL_SP_ZONK, - EL_SP_BASE, - EL_SP_MURPHY, - - EL_SP_INFOTRON, - EL_SP_CHIP_SINGLE, - EL_SP_HARD_GRAY, - EL_SP_EXIT, - - EL_SP_DISK_ORANGE, - EL_SP_PORT1_RIGHT, - EL_SP_PORT1_DOWN, - EL_SP_PORT1_LEFT, - - EL_SP_PORT1_UP, - EL_SP_PORT2_RIGHT, - EL_SP_PORT2_DOWN, - EL_SP_PORT2_LEFT, - - EL_SP_PORT2_UP, - EL_SP_SNIKSNAK, - EL_SP_DISK_YELLOW, - EL_SP_TERMINAL, - - EL_SP_DISK_RED, - EL_SP_PORT_Y, - EL_SP_PORT_X, - EL_SP_PORT_XY, - - EL_SP_ELECTRON, - EL_SP_BUG, - EL_SP_CHIP_LEFT, - EL_SP_CHIP_RIGHT, - - EL_SP_HARD_BASE1, - EL_SP_HARD_GREEN, - EL_SP_HARD_BLUE, - EL_SP_HARD_RED, - - EL_SP_HARD_YELLOW, - EL_SP_HARD_BASE2, - EL_SP_HARD_BASE3, - EL_SP_HARD_BASE4, - - EL_SP_HARD_BASE5, - EL_SP_HARD_BASE6, - EL_SP_CHIP_UPPER, - EL_SP_CHIP_LOWER + EL_LEERRAUM }; int elements_in_list = sizeof(editor_element)/sizeof(int); @@ -592,7 +613,8 @@ static void CreateControlButtons() id == ED_CTRL_ID_RECTANGLE || id == ED_CTRL_ID_FILLED_BOX || id == ED_CTRL_ID_FLOOD_FILL || - id == ED_CTRL_ID_BRUSH) + id == ED_CTRL_ID_BRUSH || + id == ED_CTRL_ID_PICK_ELEMENT) { button_type = GD_TYPE_RADIO_BUTTON; radio_button_nr = 1; @@ -779,6 +801,39 @@ static void CreateDrawingAreas() level_editor_gadget[id] = gi; } +static void CreateTextInputGadgets() +{ + Pixmap gd_pixmap = pix[PIX_DOOR]; + int gd_x, gd_y; + struct GadgetInfo *gi; + unsigned long event_mask; + int id; + + gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS; + gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS; + event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING; + + /* text input gadget for the level name */ + id = ED_CTRL_ID_LEVEL_NAME; + gi = CreateGadget(GDI_CUSTOM_ID, id, + GDI_X, SX + ED_COUNT_ELEMCONT_XPOS, + GDI_Y, SY + ED_AREA_ELEMCONT_YPOS + 3 * TILEX, + GDI_TYPE, GD_TYPE_TEXTINPUT, + GDI_TEXT_VALUE, level.name, + GDI_TEXT_SIZE, 30, + GDI_TEXT_BORDER, 3, + GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x, gd_y, + GDI_DESIGN_PRESSED, gd_pixmap, gd_x, gd_y, + GDI_EVENT_MASK, event_mask, + GDI_CALLBACK, HandleTextInputGadgets, + GDI_END); + + if (gi == NULL) + Error(ERR_EXIT, "cannot create gadget"); + + level_editor_gadget[id] = gi; +} + static void CreateLevelEditorGadgets() { if (level_editor_gadgets_created) @@ -787,6 +842,7 @@ static void CreateLevelEditorGadgets() CreateControlButtons(); CreateCounterButtons(); CreateDrawingAreas(); + CreateTextInputGadgets(); level_editor_gadgets_created = TRUE; } @@ -812,6 +868,11 @@ static void MapDrawingArea(int id) MapGadget(level_editor_gadget[id]); } +static void MapTextInputGadget(int id) +{ + MapGadget(level_editor_gadget[id]); +} + static void MapMainDrawingArea() { MapDrawingArea(ED_CTRL_ID_DRAWING_LEVEL); @@ -849,6 +910,8 @@ void DrawLevelEd() CloseDoor(DOOR_CLOSE_ALL); + OpenDoor(DOOR_OPEN_2 | DOOR_NO_DELAY); + if (level_editor_test_game) { for(x=0; x 3) + return; + + if (button == 1) + { + new_element1 = element; + DrawMiniGraphicExt(drawto, gc, + DX + ED_WIN_MB_LEFT_XPOS, + DY + ED_WIN_MB_LEFT_YPOS, + el2gfx(new_element1)); + } + else if (button == 2) + { + new_element2 = element; + DrawMiniGraphicExt(drawto, gc, + DX + ED_WIN_MB_MIDDLE_XPOS, + DY + ED_WIN_MB_MIDDLE_YPOS, + el2gfx(new_element2)); + } + else + { + new_element3 = element; + DrawMiniGraphicExt(drawto, gc, + DX + ED_WIN_MB_RIGHT_XPOS, + DY + ED_WIN_MB_RIGHT_YPOS, + el2gfx(new_element3)); + } + + redraw_mask |= REDRAW_DOOR_1; +} + void LevelEd(int mx, int my, int button) { static int last_button = 0; @@ -1234,26 +1330,7 @@ void LevelEd(int mx, int my, int button) else new_element = EL_LEERRAUM; - if (last_button==1) - new_element1 = new_element; - else if (last_button==2) - new_element2 = new_element; - else if (last_button==3) - new_element3 = new_element; - - DrawMiniGraphicExt(drawto,gc, - DX+ED_WIN_MB_LEFT_XPOS, - DY+ED_WIN_MB_LEFT_YPOS, - el2gfx(new_element1)); - DrawMiniGraphicExt(drawto,gc, - DX+ED_WIN_MB_MIDDLE_XPOS, - DY+ED_WIN_MB_MIDDLE_YPOS, - el2gfx(new_element2)); - DrawMiniGraphicExt(drawto,gc, - DX+ED_WIN_MB_RIGHT_XPOS, - DY+ED_WIN_MB_RIGHT_YPOS, - el2gfx(new_element3)); - redraw_mask |= REDRAW_DOOR_1; + PickDrawingElement(last_button, new_element); if (!HAS_CONTENT(properties_element)) { @@ -1597,7 +1674,9 @@ void LevelEd(int mx, int my, int button) for(y=0;yevent.button; int sx = gi->event.x, sy = gi->event.y; + int min_sx = 0, min_sy = 0; + int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1; int lx, ly; + int min_lx = 0, min_ly = 0; + int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1; int x, y; /* @@ -2458,23 +2544,24 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) button_press_event = (gi->event.type == GD_EVENT_PRESSED); button_release_event = (gi->event.type == GD_EVENT_RELEASED); + /* make sure to stay inside drawing area boundaries */ + sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx); + sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy); + if (draw_level) { - sx = (sx < 0 ? 0 : sx > 2*SCR_FIELDX - 1 ? 2*SCR_FIELDX - 1 : sx); - sy = (sy < 0 ? 0 : sy > 2*SCR_FIELDY - 1 ? 2*SCR_FIELDY - 1 : sy); + /* get positions inside level field */ lx = sx + level_xpos; ly = sy + level_ypos; - lx = (lx < 0 ? 0 : lx > lev_fieldx - 1 ? lev_fieldx - 1 : lx); - ly = (ly < 0 ? 0 : ly > lev_fieldy - 1 ? lev_fieldy - 1 : ly); + /* make sure to stay inside level field boundaries */ + lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx); + ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly); + + /* correct drawing area positions accordingly */ sx = lx - level_xpos; sy = ly - level_ypos; } - else - { - sx = (sx < 0 ? 0 : sx > 2 ? 2 : sx); - sy = (sy < 0 ? 0 : sy > 2 ? 2 : sy); - } if (button_press_event) started_inside_drawing_area = inside_drawing_area; @@ -2627,6 +2714,13 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) } break; + case ED_CTRL_ID_PICK_ELEMENT: + if (button_press_event) + PickDrawingElement(button, Feld[lx][ly]); + if (button_release_event) + ClickOnGadget(level_editor_gadget[last_drawing_function]); + break; + default: break; } @@ -2701,6 +2795,8 @@ static void HandleControlButtons(struct GadgetInfo *gi) case ED_CTRL_ID_FILLED_BOX: case ED_CTRL_ID_FLOOD_FILL: case ED_CTRL_ID_BRUSH: + case ED_CTRL_ID_PICK_ELEMENT: + last_drawing_function = drawing_function; drawing_function = id; break; @@ -2837,7 +2933,9 @@ static void HandleControlButtons(struct GadgetInfo *gi) for(y=0; y= 'a' && letter <= 'z') @@ -2963,3 +3068,19 @@ void HandleLevelEditorKeyInput(KeySym key) DrawLevelText(0, 0, 0, TEXT_NEWLINE); } } + + +static void HandleTextInputGadgets(struct GadgetInfo *gi) +{ + int id = gi->custom_id; + + switch (id) + { + case ED_CTRL_ID_LEVEL_NAME: + strcpy(level.name, gi->text_value); + break; + + default: + break; + } +}