From: Holger Schemel Date: Tue, 15 Dec 1998 01:10:55 +0000 (+0100) Subject: rnd-19981215-1 X-Git-Tag: 1.3.0^2~60 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=6fe98dc77891e9fc45cbd99bbd4793e2133c6960;p=rocksndiamonds.git rnd-19981215-1 --- diff --git a/src/editor.c b/src/editor.c index 4b52fdb5..5a8035a8 100644 --- a/src/editor.c +++ b/src/editor.c @@ -17,6 +17,7 @@ #include "misc.h" #include "buttons.h" #include "files.h" +#include "game.h" /* positions in the level editor */ #define ED_WIN_MB_LEFT_XPOS 7 @@ -82,13 +83,17 @@ #define ED_CTRL_ID_EXIT 21 /* forward declaration for internal use */ -void HandleDrawingFunction(int, int, int); +void HandleDrawingFunctions(int, int, int); +void HandlePressedControlButtons(); +void HandleControlButtons(struct GadgetInfo *); static struct GadgetInfo *control_button_gadget[ED_NUM_CTRL_BUTTONS]; static boolean control_button_gadgets_created = FALSE; +static boolean control_button_gadgets_mapped = FALSE; static int drawing_function = ED_CTRL_ID_SINGLE_ITEMS; +static short OrigBackup[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; static short UndoBuffer[NUM_UNDO_STEPS][MAX_LEV_FIELDX][MAX_LEV_FIELDY]; static int undo_buffer_position = 0; static int undo_buffer_steps = 0; @@ -423,234 +428,6 @@ void ScrollMiniLevel(int from_x, int from_y, int scroll) BackToFront(); } -void HandlePressedControlButtons() -{ - static unsigned long button_delay = 0; - int i = 0; - - /* buttons with action when held pressed */ - int gadget_id[] = - { - ED_CTRL_ID_WRAP_UP, - ED_CTRL_ID_WRAP_LEFT, - ED_CTRL_ID_WRAP_RIGHT, - ED_CTRL_ID_WRAP_DOWN, - -1 - }; - - if (!DelayReached(&button_delay, CHOICE_DELAY_VALUE)) - return; - - while (gadget_id[i] != -1) - { - int id = gadget_id[i++]; - int state = control_button_gadget[id]->state; - int button = control_button_gadget[id]->event.button; - int step = (button == 1 ? 1 : button == 2 ? 5 : 10); - - if (state != GD_BUTTON_PRESSED) - continue; - - switch (id) - { - case ED_CTRL_ID_WRAP_LEFT: - if (level_xpos >= 0) - { - if (lev_fieldx < 2*SCR_FIELDX - 2) - break; - - level_xpos -= step; - if (level_xpos <- 1) - level_xpos = -1; - if (button == 1) - ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT); - else - DrawMiniLevel(level_xpos, level_ypos); - } - break; - - case ED_CTRL_ID_WRAP_RIGHT: - if (level_xpos <= lev_fieldx - 2*SCR_FIELDX) - { - if (lev_fieldx < 2*SCR_FIELDX - 2) - break; - - level_xpos += step; - if (level_xpos > lev_fieldx - 2*SCR_FIELDX + 1) - level_xpos = lev_fieldx - 2*SCR_FIELDX + 1; - if (button == 1) - ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT); - else - DrawMiniLevel(level_xpos, level_ypos); - } - break; - - case ED_CTRL_ID_WRAP_UP: - if (level_ypos >= 0) - { - if (lev_fieldy < 2*SCR_FIELDY - 2) - break; - - level_ypos -= step; - if (level_ypos < -1) - level_ypos = -1; - if (button == 1) - ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN); - else - DrawMiniLevel(level_xpos, level_ypos); - } - break; - - case ED_CTRL_ID_WRAP_DOWN: - if (level_ypos <= lev_fieldy - 2*SCR_FIELDY) - { - if (lev_fieldy < 2*SCR_FIELDY - 2) - break; - - level_ypos += step; - if (level_ypos > lev_fieldy - 2*SCR_FIELDY + 1) - level_ypos = lev_fieldy - 2*SCR_FIELDY + 1; - if (button == 1) - ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP); - else - DrawMiniLevel(level_xpos, level_ypos); - } - break; - - default: - break; - } - } -} - -void HandleLevelEditorControlButtons(struct GadgetInfo *gi) -{ - int event_type = gi->event.type; - - /* - int button = gi->event.button; - */ - - int id; - int i, x, y; - - /* get the button id */ - for (i=0; iid == control_button_gadget[i]->id) - id = i; - - switch (id) - { - case ED_CTRL_ID_SINGLE_ITEMS: - case ED_CTRL_ID_CONNECTED_ITEMS: - case ED_CTRL_ID_LINE: - case ED_CTRL_ID_TEXT: - case ED_CTRL_ID_RECTANGLE: - case ED_CTRL_ID_FILLED_BOX: - case ED_CTRL_ID_FLOOD_FILL: - case ED_CTRL_ID_RANDOM_PLACEMENT: - case ED_CTRL_ID_BRUSH: - drawing_function = id; - break; - - case ED_CTRL_ID_UNDO: - if (undo_buffer_steps == 0) - { - Request("Undo buffer empty !", REQ_CONFIRM); - break; - } - - undo_buffer_position = - (undo_buffer_position - 1 + NUM_UNDO_STEPS) % NUM_UNDO_STEPS; - undo_buffer_steps--; - - for(x=0; xlev_fieldx-2*SCR_FIELDX+1) - level_xpos = lev_fieldx-2*SCR_FIELDX+1; - if (lev_fieldx<2*SCR_FIELDX-2) + if (level_xpos > lev_fieldx - 2*SCR_FIELDX + 1) + level_xpos = lev_fieldx - 2*SCR_FIELDX + 1; + if (lev_fieldx < 2*SCR_FIELDX - 2) level_xpos = -1; - if (level_ypos<-1) + if (level_ypos < -1) level_ypos = -1; - if (level_ypos>lev_fieldy-2*SCR_FIELDY+1) - level_ypos = lev_fieldy-2*SCR_FIELDY+1; - if (lev_fieldy<2*SCR_FIELDY-2) + if (level_ypos > lev_fieldy - 2*SCR_FIELDY + 1) + level_ypos = lev_fieldy - 2*SCR_FIELDY + 1; + if (lev_fieldy < 2*SCR_FIELDY - 2) level_ypos = -1; } @@ -1036,7 +832,7 @@ void LevelEd(int mx, int my, int button) HandlePressedControlButtons(); - HandleDrawingFunction(mx, my, button); + HandleDrawingFunctions(mx, my, button); if (use_floodfill) /********** FLOOD FILL **********/ { @@ -1448,7 +1244,7 @@ void LevelEd(int mx, int my, int button) if (leveldir[leveldir_nr].readonly || Request("Exit without saving ?",REQ_ASK | REQ_STAY_OPEN)) { - CloseDoor(DOOR_CLOSE_BOTH); + CloseDoor(DOOR_CLOSE_ALL); game_status=MAINMENU; DrawMainMenu(); } @@ -1486,7 +1282,7 @@ void LevelEd(int mx, int my, int button) Ur[x][y]=Feld[x][y]; SaveLevel(level_nr); } - CloseDoor(DOOR_CLOSE_BOTH); + CloseDoor(DOOR_CLOSE_ALL); game_status=MAINMENU; DrawMainMenu(); } @@ -1827,7 +1623,27 @@ void FloodFill(int from_x, int from_y, int fill_element) safety--; } -void HandleDrawingFunction(int mx, int my, int button) +void CopyLevelToUndoBuffer() +{ + int x, y; + + undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS; + + if (undo_buffer_steps < NUM_UNDO_STEPS - 1) + undo_buffer_steps++; + + for(x=0; x= SX + SXSIZE || my < SY || my >= SY + SYSIZE) return; - if (sx > lev_fieldx || sy > lev_fieldy || + if ((!button && !button_release_event) || + sx > lev_fieldx || sy > lev_fieldy || (sx == 0 && level_xpos<0) || (sx == 2*SCR_FIELDX - 1 && level_xpos > lev_fieldx - 2*SCR_FIELDX) || (sy == 0 && level_ypos < 0) || @@ -1949,38 +1769,7 @@ void HandleDrawingFunction(int mx, int my, int button) } break; - case 999: - { - static int last_sx = -1; - static int last_sy = -1; - - if (last_sx == -1) - { - Feld[lx][ly] = new_element; - DrawMiniElement(sx, sy, new_element); - - last_sx = sx; - last_sy = sy; - } - else if (last_sx != sx || last_sy != sy) - { - DrawLine(last_sx, last_sy, sx, sy, new_element, TRUE); - - last_sx = -1; - last_sy = -1; - } - - /* - last_sx = sx; - last_sy = sy; - */ - } - break; - case ED_CTRL_ID_FLOOD_FILL: - if (!button) - break; - if (button_press_event && Feld[lx][ly] != new_element) { FloodFill(lx, ly, new_element); @@ -1996,22 +1785,289 @@ void HandleDrawingFunction(int mx, int my, int button) last_element = new_element; if (copy_to_undo_buffer) + CopyLevelToUndoBuffer(); + copy_to_undo_buffer = FALSE; +} + +void HandlePressedControlButtons() +{ + static unsigned long button_delay = 0; + int i = 0; + + /* buttons with action when held pressed */ + int gadget_id[] = { - undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS; + ED_CTRL_ID_WRAP_UP, + ED_CTRL_ID_WRAP_LEFT, + ED_CTRL_ID_WRAP_RIGHT, + ED_CTRL_ID_WRAP_DOWN, + -1 + }; - if (undo_buffer_steps < NUM_UNDO_STEPS - 1) - undo_buffer_steps++; + if (!DelayReached(&button_delay, CHOICE_DELAY_VALUE)) + return; - for(x=0; xstate; + int button = control_button_gadget[id]->event.button; + int step = (button == 1 ? 1 : button == 2 ? 5 : 10); - copy_to_undo_buffer = FALSE; + if (state != GD_BUTTON_PRESSED) + continue; + + switch (id) + { + case ED_CTRL_ID_WRAP_LEFT: + if (level_xpos >= 0) + { + if (lev_fieldx < 2*SCR_FIELDX - 2) + break; + + level_xpos -= step; + if (level_xpos <- 1) + level_xpos = -1; + if (button == 1) + ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT); + else + DrawMiniLevel(level_xpos, level_ypos); + } + break; + + case ED_CTRL_ID_WRAP_RIGHT: + if (level_xpos <= lev_fieldx - 2*SCR_FIELDX) + { + if (lev_fieldx < 2*SCR_FIELDX - 2) + break; + + level_xpos += step; + if (level_xpos > lev_fieldx - 2*SCR_FIELDX + 1) + level_xpos = lev_fieldx - 2*SCR_FIELDX + 1; + if (button == 1) + ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT); + else + DrawMiniLevel(level_xpos, level_ypos); + } + break; + + case ED_CTRL_ID_WRAP_UP: + if (level_ypos >= 0) + { + if (lev_fieldy < 2*SCR_FIELDY - 2) + break; + + level_ypos -= step; + if (level_ypos < -1) + level_ypos = -1; + if (button == 1) + ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN); + else + DrawMiniLevel(level_xpos, level_ypos); + } + break; + + case ED_CTRL_ID_WRAP_DOWN: + if (level_ypos <= lev_fieldy - 2*SCR_FIELDY) + { + if (lev_fieldy < 2*SCR_FIELDY - 2) + break; + + level_ypos += step; + if (level_ypos > lev_fieldy - 2*SCR_FIELDY + 1) + level_ypos = lev_fieldy - 2*SCR_FIELDY + 1; + if (button == 1) + ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP); + else + DrawMiniLevel(level_xpos, level_ypos); + } + break; + + default: + break; + } + } +} +void HandleControlButtons(struct GadgetInfo *gi) +{ + int event_type = gi->event.type; + int player_present = FALSE; + int level_changed = FALSE; + int id; + int i, x, y; + /* get the button id */ + for (i=0; iid == control_button_gadget[i]->id) + id = i; - /* - printf("state saved to undo buffer %d\n", undo_buffer_position); - */ + if (id < ED_NUM_CTRL1_BUTTONS && !edit_mode) + { + AdjustLevelScrollPosition(); + DrawMiniLevel(level_xpos, level_ypos); + edit_mode = TRUE; + } + + switch (id) + { + case ED_CTRL_ID_SINGLE_ITEMS: + case ED_CTRL_ID_CONNECTED_ITEMS: + case ED_CTRL_ID_LINE: + case ED_CTRL_ID_TEXT: + case ED_CTRL_ID_RECTANGLE: + case ED_CTRL_ID_FILLED_BOX: + case ED_CTRL_ID_FLOOD_FILL: + case ED_CTRL_ID_RANDOM_PLACEMENT: + case ED_CTRL_ID_BRUSH: + drawing_function = id; + break; + + case ED_CTRL_ID_UNDO: + if (undo_buffer_steps == 0) + { + Request("Undo buffer empty !", REQ_CONFIRM); + break; + } + + undo_buffer_position = + (undo_buffer_position - 1 + NUM_UNDO_STEPS) % NUM_UNDO_STEPS; + undo_buffer_steps--; + + for(x=0; x