X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Feditor.c;h=64e96e24164b6515b4c6ae7bcd3a52ead062fe1b;hb=f941ccddee3065d7531298e37ad4dcfcd892c1f8;hp=b38e5aa9e1d8ee6b75b14f03f31dcd714b56948f;hpb=05c80e257e74b9f48c5d4b5cc807db0a4fb82fd2;p=rocksndiamonds.git diff --git a/src/editor.c b/src/editor.c index b38e5aa9..64e96e24 100644 --- a/src/editor.c +++ b/src/editor.c @@ -11,6 +11,8 @@ * editor.c * ***********************************************************/ +#include + #include "editor.h" #include "screens.h" #include "tools.h" @@ -21,122 +23,150 @@ #include "tape.h" /* positions in the level editor */ -#define ED_WIN_MB_LEFT_XPOS 7 -#define ED_WIN_MB_LEFT_YPOS 6 -#define ED_WIN_LEVELNR_XPOS 77 -#define ED_WIN_LEVELNR_YPOS 7 -#define ED_WIN_MB_MIDDLE_XPOS 7 -#define ED_WIN_MB_MIDDLE_YPOS 258 -#define ED_WIN_MB_RIGHT_XPOS 77 -#define ED_WIN_MB_RIGHT_YPOS 258 +#define ED_WIN_MB_LEFT_XPOS 7 +#define ED_WIN_MB_LEFT_YPOS 6 +#define ED_WIN_LEVELNR_XPOS 77 +#define ED_WIN_LEVELNR_YPOS 7 +#define ED_WIN_MB_MIDDLE_XPOS 7 +#define ED_WIN_MB_MIDDLE_YPOS 258 +#define ED_WIN_MB_RIGHT_XPOS 77 +#define ED_WIN_MB_RIGHT_YPOS 258 /* other constants for the editor */ -#define ED_SCROLL_NO 0 -#define ED_SCROLL_LEFT 1 -#define ED_SCROLL_RIGHT 2 -#define ED_SCROLL_UP 4 -#define ED_SCROLL_DOWN 8 +#define ED_SCROLL_NO 0 +#define ED_SCROLL_LEFT 1 +#define ED_SCROLL_RIGHT 2 +#define ED_SCROLL_UP 4 +#define ED_SCROLL_DOWN 8 /* screens in the level editor */ -#define ED_MODE_DRAWING 0 -#define ED_MODE_INFO 1 -#define ED_MODE_PROPERTIES 2 +#define ED_MODE_DRAWING 0 +#define ED_MODE_INFO 1 +#define ED_MODE_PROPERTIES 2 /* how many steps can be cancelled */ -#define NUM_UNDO_STEPS (10 + 1) +#define NUM_UNDO_STEPS (10 + 1) /* values for random placement */ -#define RANDOM_USE_PERCENTAGE 0 -#define RANDOM_USE_NUM_OBJECTS 1 +#define RANDOM_USE_PERCENTAGE 0 +#define RANDOM_USE_NUM_OBJECTS 1 + +/* values for elements with score */ +#define MIN_SCORE 0 +#define MAX_SCORE 255 /* values for elements with content */ -#define MAX_ELEMCONT 8 +#define MIN_ELEM_CONTENT 1 +#define MAX_ELEM_CONTENT 8 /* values for the control window */ #define ED_CTRL_BUTTONS_GFX_YPOS 236 #define ED_CTRL_BUTTONS_ALT_GFX_YPOS 142 -#define ED_CTRL1_BUTTONS_HORIZ 4 -#define ED_CTRL1_BUTTONS_VERT 4 -#define ED_CTRL1_BUTTON_XSIZE 22 -#define ED_CTRL1_BUTTON_YSIZE 22 -#define ED_CTRL1_BUTTONS_XPOS 6 -#define ED_CTRL1_BUTTONS_YPOS 6 -#define ED_CTRL2_BUTTONS_HORIZ 3 -#define ED_CTRL2_BUTTONS_VERT 2 -#define ED_CTRL2_BUTTON_XSIZE 30 -#define ED_CTRL2_BUTTON_YSIZE 20 -#define ED_CTRL2_BUTTONS_XPOS 5 -#define ED_CTRL2_BUTTONS_YPOS 100 +#define ED_CTRL1_BUTTONS_HORIZ 4 +#define ED_CTRL1_BUTTONS_VERT 4 +#define ED_CTRL1_BUTTON_XSIZE 22 +#define ED_CTRL1_BUTTON_YSIZE 22 +#define ED_CTRL1_BUTTONS_XPOS 6 +#define ED_CTRL1_BUTTONS_YPOS 6 +#define ED_CTRL2_BUTTONS_HORIZ 3 +#define ED_CTRL2_BUTTONS_VERT 2 +#define ED_CTRL2_BUTTON_XSIZE 30 +#define ED_CTRL2_BUTTON_YSIZE 20 +#define ED_CTRL2_BUTTONS_XPOS 5 +#define ED_CTRL2_BUTTONS_YPOS 99 #define ED_NUM_CTRL1_BUTTONS (ED_CTRL1_BUTTONS_HORIZ * ED_CTRL1_BUTTONS_VERT) #define ED_NUM_CTRL2_BUTTONS (ED_CTRL2_BUTTONS_HORIZ * ED_CTRL2_BUTTONS_VERT) #define ED_NUM_CTRL_BUTTONS (ED_NUM_CTRL1_BUTTONS + ED_NUM_CTRL2_BUTTONS) -/* values for properties window */ -#define ED_PROPERTIES_XPOS (TILEX - MINI_TILEX/2) +/* values for the element list */ +#define ED_ELEMENTLIST_UP_XPOS 35 +#define ED_ELEMENTLIST_UP_YPOS 5 +#define ED_ELEMENTLIST_UP_ALT_YPOS 140 +#define ED_ELEMENTLIST_DOWN_XPOS 35 +#define ED_ELEMENTLIST_DOWN_YPOS 250 +#define ED_ELEMENTLIST_DOWN_ALT_YPOS 165 +#define ED_ELEMENTLIST_UPDOWN_XSIZE 30 +#define ED_ELEMENTLIST_UPDOWN_YSIZE 25 +#define ED_ELEMENTLIST_XPOS 6 +#define ED_ELEMENTLIST_YPOS 30 +#define ED_ELEMENTLIST_ALT_YPOS 190 +#define ED_ELEMENTLIST_XSIZE 22 +#define ED_ELEMENTLIST_YSIZE 22 +#define ED_ELEMENTLIST_BUTTONS_HORIZ 4 +#define ED_ELEMENTLIST_BUTTONS_VERT 10 +#define ED_NUM_ELEMENTLIST_BUTTONS (ED_ELEMENTLIST_BUTTONS_HORIZ * \ + ED_ELEMENTLIST_BUTTONS_VERT) + +/* values for element properties window */ +#define ED_PROPERTIES_XPOS (TILEX - MINI_TILEX/2) + +/* values for level information window */ +#define ED_LEVELINFO_XPOS (TILEX - MINI_TILEX/2) +#define ED_LEVELINFO_YPOS (TILEY - MINI_TILEY/2) + /* values for counter gadgets */ -#define ED_COUNT_VALUE_XOFFSET 5 -#define ED_COUNT_VALUE_YOFFSET 3 -#define ED_COUNT_SCORE_XPOS ED_PROPERTIES_XPOS -#define ED_COUNT_SCORE_YPOS (14 * MINI_TILEY) -#define ED_COUNT_ELEMCONT_XPOS ED_PROPERTIES_XPOS -#define ED_COUNT_ELEMCONT_YPOS (17 * MINI_TILEY) +#define ED_COUNT_VALUE_XOFFSET 5 +#define ED_COUNT_VALUE_YOFFSET 3 +#define ED_COUNT_ELEM_SCORE_XPOS ED_PROPERTIES_XPOS +#define ED_COUNT_ELEM_SCORE_YPOS (14 * MINI_TILEY) +#define ED_COUNT_ELEM_CONTENT_XPOS ED_PROPERTIES_XPOS +#define ED_COUNT_ELEM_CONTENT_YPOS (17 * MINI_TILEY) +#define ED_COUNTER_YSTART (ED_LEVELINFO_YPOS + 3 * TILEY) +#define ED_COUNTER_YDISTANCE (3 * MINI_TILEY) +#define ED_COUNTER_YPOS(n) (ED_COUNTER_YSTART + \ + n * ED_COUNTER_YDISTANCE) +/* standard distances */ +#define ED_BORDER_SIZE 3 +#define ED_GADGET_DISTANCE 2 /* values for element content drawing areas */ -#define ED_AREA_ELEMCONT_XPOS (TILEX) -#define ED_AREA_ELEMCONT_YPOS (10 * TILEY) +#define ED_AREA_ELEM_CONTENT_XPOS (TILEX) +#define ED_AREA_ELEM_CONTENT_YPOS (10 * TILEY) /* values for scrolling gadgets */ -#if 1 -#define ED_SCROLLBUTTON_XSIZE 16 -#define ED_SCROLLBUTTON_YSIZE 16 - -#define ED_SCROLLBUTTON_XPOS 24 -#define ED_SCROLLBUTTON_YPOS 0 -#define ED_SCROLLBAR_XPOS 24 -#define ED_SCROLLBAR_YPOS 64 -#else -#define ED_SCROLLBUTTON_XSIZE 30 -#define ED_SCROLLBUTTON_YSIZE 30 - -#define ED_SCROLLBUTTON_XPOS 70 -#define ED_SCROLLBUTTON_YPOS 0 -#define ED_SCROLLBAR_XPOS 10 -#define ED_SCROLLBAR_YPOS 110 -#endif - -#define ED_SCROLL_UP_XPOS (SXSIZE - ED_SCROLLBUTTON_XSIZE) -#define ED_SCROLL_UP_YPOS (0) -#define ED_SCROLL_DOWN_XPOS ED_SCROLL_UP_XPOS -#define ED_SCROLL_DOWN_YPOS (SYSIZE - TILEX - ED_SCROLLBUTTON_YSIZE) -#define ED_SCROLL_LEFT_XPOS (0) -#define ED_SCROLL_LEFT_YPOS (SYSIZE - ED_SCROLLBUTTON_YSIZE) -#define ED_SCROLL_RIGHT_XPOS (SXSIZE - TILEX - ED_SCROLLBUTTON_XSIZE) -#define ED_SCROLL_RIGHT_YPOS ED_SCROLL_LEFT_YPOS -#define ED_SCROLL_VERTICAL_XPOS ED_SCROLL_UP_XPOS -#define ED_SCROLL_VERTICAL_YPOS (ED_SCROLL_UP_YPOS + ED_SCROLLBUTTON_YSIZE) -#define ED_SCROLL_VERTICAL_XSIZE ED_SCROLLBUTTON_XSIZE -#define ED_SCROLL_VERTICAL_YSIZE (SYSIZE - TILEY - 2 * ED_SCROLLBUTTON_YSIZE) +#define ED_SCROLLBUTTON_XPOS 24 +#define ED_SCROLLBUTTON_YPOS 0 +#define ED_SCROLLBAR_XPOS 24 +#define ED_SCROLLBAR_YPOS 64 + +#define ED_SCROLLBUTTON_XSIZE 16 +#define ED_SCROLLBUTTON_YSIZE 16 + +#define ED_SCROLL_UP_XPOS (SXSIZE - ED_SCROLLBUTTON_XSIZE) +#define ED_SCROLL_UP_YPOS (0) +#define ED_SCROLL_DOWN_XPOS ED_SCROLL_UP_XPOS +#define ED_SCROLL_DOWN_YPOS (SYSIZE - 3 * ED_SCROLLBUTTON_YSIZE) +#define ED_SCROLL_LEFT_XPOS (0) +#define ED_SCROLL_LEFT_YPOS (SYSIZE - 2 * ED_SCROLLBUTTON_YSIZE) +#define ED_SCROLL_RIGHT_XPOS (SXSIZE - 2 * ED_SCROLLBUTTON_XSIZE) +#define ED_SCROLL_RIGHT_YPOS ED_SCROLL_LEFT_YPOS +#define ED_SCROLL_VERTICAL_XPOS ED_SCROLL_UP_XPOS +#define ED_SCROLL_VERTICAL_YPOS (ED_SCROLL_UP_YPOS + ED_SCROLLBUTTON_YSIZE) +#define ED_SCROLL_VERTICAL_XSIZE ED_SCROLLBUTTON_XSIZE +#define ED_SCROLL_VERTICAL_YSIZE (SYSIZE - 4 * ED_SCROLLBUTTON_YSIZE) #define ED_SCROLL_HORIZONTAL_XPOS (ED_SCROLL_LEFT_XPOS + ED_SCROLLBUTTON_XSIZE) -#define ED_SCROLL_HORIZONTAL_YPOS (SYSIZE - ED_SCROLLBUTTON_YSIZE) -#define ED_SCROLL_HORIZONTAL_XSIZE (SXSIZE - TILEX - 2 * ED_SCROLLBUTTON_XSIZE) -#define ED_SCROLL_HORIZONTAL_YSIZE ED_SCROLLBUTTON_YSIZE +#define ED_SCROLL_HORIZONTAL_YPOS ED_SCROLL_LEFT_YPOS +#define ED_SCROLL_HORIZONTAL_XSIZE (SXSIZE - 3 * ED_SCROLLBUTTON_XSIZE) +#define ED_SCROLL_HORIZONTAL_YSIZE ED_SCROLLBUTTON_YSIZE /* control button identifiers */ +#define ED_CTRL_ID_NONE -1 + #define ED_CTRL_ID_SINGLE_ITEMS 0 #define ED_CTRL_ID_CONNECTED_ITEMS 1 #define ED_CTRL_ID_LINE 2 -#define ED_CTRL_ID_TEXT 3 +#define ED_CTRL_ID_ARC 3 #define ED_CTRL_ID_RECTANGLE 4 #define ED_CTRL_ID_FILLED_BOX 5 #define ED_CTRL_ID_WRAP_UP 6 -#define ED_CTRL_ID_PROPERTIES 7 +#define ED_CTRL_ID_TEXT 7 #define ED_CTRL_ID_FLOOD_FILL 8 #define ED_CTRL_ID_WRAP_LEFT 9 -#define ED_CTRL_ID_UNUSED1 10 +#define ED_CTRL_ID_PROPERTIES 10 #define ED_CTRL_ID_WRAP_RIGHT 11 #define ED_CTRL_ID_RANDOM_PLACEMENT 12 -#define ED_CTRL_ID_BRUSH 13 +#define ED_CTRL_ID_GRAB_BRUSH 13 #define ED_CTRL_ID_WRAP_DOWN 14 #define ED_CTRL_ID_PICK_ELEMENT 15 #define ED_CTRL_ID_UNDO 16 @@ -147,50 +177,231 @@ #define ED_CTRL_ID_EXIT 21 /* counter button identifiers */ -#define ED_CTRL_ID_SCORE_DOWN 22 -#define ED_CTRL_ID_SCORE_UP 23 -#define ED_CTRL_ID_ELEMCONT_DOWN 24 -#define ED_CTRL_ID_ELEMCONT_UP 25 +#define ED_CTRL_ID_ELEM_SCORE_DOWN 22 +#define ED_CTRL_ID_ELEM_SCORE_TEXT 23 +#define ED_CTRL_ID_ELEM_SCORE_UP 24 +#define ED_CTRL_ID_ELEM_CONTENT_DOWN 25 +#define ED_CTRL_ID_ELEM_CONTENT_TEXT 26 +#define ED_CTRL_ID_ELEM_CONTENT_UP 27 +#define ED_CTRL_ID_LEVEL_XSIZE_DOWN 28 +#define ED_CTRL_ID_LEVEL_XSIZE_TEXT 29 +#define ED_CTRL_ID_LEVEL_XSIZE_UP 30 +#define ED_CTRL_ID_LEVEL_YSIZE_DOWN 31 +#define ED_CTRL_ID_LEVEL_YSIZE_TEXT 32 +#define ED_CTRL_ID_LEVEL_YSIZE_UP 33 +#define ED_CTRL_ID_LEVEL_RANDOM_DOWN 34 +#define ED_CTRL_ID_LEVEL_RANDOM_TEXT 35 +#define ED_CTRL_ID_LEVEL_RANDOM_UP 36 +#define ED_CTRL_ID_LEVEL_COLLECT_DOWN 37 +#define ED_CTRL_ID_LEVEL_COLLECT_TEXT 38 +#define ED_CTRL_ID_LEVEL_COLLECT_UP 39 +#define ED_CTRL_ID_LEVEL_TIMELIMIT_DOWN 40 +#define ED_CTRL_ID_LEVEL_TIMELIMIT_TEXT 41 +#define ED_CTRL_ID_LEVEL_TIMELIMIT_UP 42 +#define ED_CTRL_ID_LEVEL_TIMESCORE_DOWN 43 +#define ED_CTRL_ID_LEVEL_TIMESCORE_TEXT 44 +#define ED_CTRL_ID_LEVEL_TIMESCORE_UP 45 /* drawing area identifiers */ -#define ED_CTRL_ID_DRAWING_LEVEL 26 -#define ED_CTRL_ID_ELEMCONT_0 27 -#define ED_CTRL_ID_ELEMCONT_7 34 -#define ED_CTRL_ID_AMOEBA_CONTENT 35 +#define ED_CTRL_ID_DRAWING_LEVEL 46 +#define ED_CTRL_ID_ELEM_CONTENT_0 47 +#define ED_CTRL_ID_ELEM_CONTENT_1 48 +#define ED_CTRL_ID_ELEM_CONTENT_2 49 +#define ED_CTRL_ID_ELEM_CONTENT_3 50 +#define ED_CTRL_ID_ELEM_CONTENT_4 51 +#define ED_CTRL_ID_ELEM_CONTENT_5 52 +#define ED_CTRL_ID_ELEM_CONTENT_6 53 +#define ED_CTRL_ID_ELEM_CONTENT_7 54 +#define ED_CTRL_ID_AMOEBA_CONTENT 55 /* text input identifiers */ -#define ED_CTRL_ID_LEVEL_NAME 36 +#define ED_CTRL_ID_LEVEL_NAME 56 +#define ED_CTRL_ID_LEVEL_AUTHOR 57 /* gadgets for scrolling of drawing area */ -#define ED_CTRL_ID_SCROLL_UP 37 -#define ED_CTRL_ID_SCROLL_DOWN 38 -#define ED_CTRL_ID_SCROLL_LEFT 39 -#define ED_CTRL_ID_SCROLL_RIGHT 40 -#define ED_CTRL_ID_SCROLL_VERTICAL 41 -#define ED_CTRL_ID_SCROLL_HORIZONTAL 42 +#define ED_CTRL_ID_SCROLL_UP 58 +#define ED_CTRL_ID_SCROLL_DOWN 59 +#define ED_CTRL_ID_SCROLL_LEFT 60 +#define ED_CTRL_ID_SCROLL_RIGHT 61 +#define ED_CTRL_ID_SCROLL_VERTICAL 62 +#define ED_CTRL_ID_SCROLL_HORIZONTAL 63 -#define ED_NUM_GADGETS 43 +/* gadgets for scrolling element list */ +#define ED_CTRL_ID_ELEMENTLIST_UP 64 +#define ED_CTRL_ID_ELEMENTLIST_DOWN 65 -/* values for counter gadgets */ -#define ED_COUNTER_SCORE 0 -#define ED_COUNTER_ELEMCONT 1 +/* gadgets for buttons in element list */ +#define ED_CTRL_ID_ELEMENTLIST_FIRST 66 +#define ED_CTRL_ID_ELEMENTLIST_LAST 105 -#define ED_NUM_COUNTERBUTTONS 2 -#define ED_NUM_SCROLLBUTTONS 4 +#define ED_NUM_GADGETS 106 + +/* values for counter gadgets */ +#define ED_COUNTER_ID_ELEM_SCORE 0 +#define ED_COUNTER_ID_ELEM_CONTENT 1 +#define ED_COUNTER_ID_LEVEL_XSIZE 2 +#define ED_COUNTER_ID_LEVEL_YSIZE 3 +#define ED_COUNTER_ID_LEVEL_RANDOM 4 +#define ED_COUNTER_ID_LEVEL_COLLECT 5 +#define ED_COUNTER_ID_LEVEL_TIMELIMIT 6 +#define ED_COUNTER_ID_LEVEL_TIMESCORE 7 + +/* values for text input gadgets */ +#define ED_TEXTINPUT_ID_LEVEL_NAME 0 +#define ED_TEXTINPUT_ID_LEVEL_AUTHOR 1 + +#define ED_NUM_COUNTERBUTTONS 8 +#define ED_NUM_SCROLLBUTTONS 6 #define ED_NUM_SCROLLBARS 2 +#define ED_NUM_TEXTINPUT 2 /* values for CopyLevelToUndoBuffer() */ #define UNDO_IMMEDIATE 0 #define UNDO_ACCUMULATE 1 +/* values for ClearEditorGadgetInfoText() and HandleGadgetInfoText() */ +#define INFOTEXT_XPOS SX +#define INFOTEXT_YPOS (SY + SYSIZE - MINI_TILEX + 2) +#define INFOTEXT_XSIZE SXSIZE +#define INFOTEXT_YSIZE MINI_TILEX +#define MAX_INFOTEXT_LEN (SXSIZE / FONT2_XSIZE) + +static struct +{ + char shortcut; + char *text; +} control_info[ED_NUM_CTRL_BUTTONS] = +{ + { 's', "draw single items" }, + { 'd', "draw connected items" }, + { 'l', "draw lines" }, + { 'a', "draw arcs" }, + { 'r', "draw outline rectangles" }, + { 'R', "draw filled rectangles" }, + { '\0', "wrap (rotate) level up" }, + { 't', "enter text elements" }, + { 'f', "flood fill" }, + { '\0', "wrap (rotate) level left" }, + { '?', "properties of drawing element" }, + { '\0', "wrap (rotate) level right" }, + { '\0', "random element placement" }, + { 'b', "grab brush" }, + { '\0', "wrap (rotate) level down" }, + { ',', "pick drawing element" }, + { 'U', "undo last operation" }, + { 'I', "level properties" }, + { 'S', "save level" }, + { 'C', "clear level" }, + { 'T', "test level" }, + { 'E', "exit level editor" } +}; + +/* pointers to counter values */ +static int *gadget_elem_score_value = NULL; +static int *gadget_elem_content_value = NULL; +static int *gadget_level_xsize_value = NULL; +static int *gadget_level_ysize_value = NULL; +static int *gadget_level_random_value = NULL; +static int *gadget_level_collect_value = NULL; +static int *gadget_level_timelimit_value = NULL; +static int *gadget_level_timescore_value = NULL; + static struct { int x, y; - int gadget_id; + int min_value, max_value; + int gadget_id_down, gadget_id_up; + int gadget_id_text; + int **counter_value; + char *infotext; } counterbutton_info[ED_NUM_COUNTERBUTTONS] = { - { ED_COUNT_SCORE_XPOS, ED_COUNT_SCORE_YPOS, ED_CTRL_ID_SCORE_DOWN }, - { ED_COUNT_ELEMCONT_XPOS, ED_COUNT_ELEMCONT_YPOS, ED_CTRL_ID_ELEMCONT_DOWN } + { + ED_COUNT_ELEM_SCORE_XPOS, ED_COUNT_ELEM_SCORE_YPOS, + MIN_SCORE, MAX_SCORE, + ED_CTRL_ID_ELEM_SCORE_DOWN, ED_CTRL_ID_ELEM_SCORE_UP, + ED_CTRL_ID_ELEM_SCORE_TEXT, + &gadget_elem_score_value, + "element score" + }, + { + ED_COUNT_ELEM_CONTENT_XPOS, ED_COUNT_ELEM_CONTENT_YPOS, + MIN_ELEM_CONTENT, MAX_ELEM_CONTENT, + ED_CTRL_ID_ELEM_CONTENT_DOWN, ED_CTRL_ID_ELEM_CONTENT_UP, + ED_CTRL_ID_ELEM_CONTENT_TEXT, + &gadget_elem_content_value, + "element content" + }, + { + ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(0), + MIN_LEV_FIELDX, MAX_LEV_FIELDX, + ED_CTRL_ID_LEVEL_XSIZE_DOWN, ED_CTRL_ID_LEVEL_XSIZE_UP, + ED_CTRL_ID_LEVEL_XSIZE_TEXT, + &gadget_level_xsize_value, + "playfield width" + }, + { + ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(1), + MIN_LEV_FIELDY, MAX_LEV_FIELDY, + ED_CTRL_ID_LEVEL_YSIZE_DOWN, ED_CTRL_ID_LEVEL_YSIZE_UP, + ED_CTRL_ID_LEVEL_YSIZE_TEXT, + &gadget_level_ysize_value, + "playfield height" + }, + { + ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(2), + 0, 100, + ED_CTRL_ID_LEVEL_RANDOM_DOWN, ED_CTRL_ID_LEVEL_RANDOM_UP, + ED_CTRL_ID_LEVEL_RANDOM_TEXT, + &gadget_level_random_value, + "number of random elements" + }, + { + ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(3), + 0, 999, + ED_CTRL_ID_LEVEL_COLLECT_DOWN, ED_CTRL_ID_LEVEL_COLLECT_UP, + ED_CTRL_ID_LEVEL_COLLECT_TEXT, + &gadget_level_collect_value, + "number of emeralds to collect" + }, + { + ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(4), + 0, 999, + ED_CTRL_ID_LEVEL_TIMELIMIT_DOWN, ED_CTRL_ID_LEVEL_TIMELIMIT_UP, + ED_CTRL_ID_LEVEL_TIMELIMIT_TEXT, + &gadget_level_timelimit_value, + "time available to solve level" + }, + { + ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(5), + 0, 255, + ED_CTRL_ID_LEVEL_TIMESCORE_DOWN, ED_CTRL_ID_LEVEL_TIMESCORE_UP, + ED_CTRL_ID_LEVEL_TIMESCORE_TEXT, + &gadget_level_timescore_value, + "score for each 10 seconds left" + }, +}; + +static struct +{ + int x, y; + int gadget_id; + char *value; + char *infotext; +} textinput_info[ED_NUM_TEXTINPUT] = +{ + { + ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(6), + ED_CTRL_ID_LEVEL_NAME, + level.name, + "Level Title" + }, + { + ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(7), + ED_CTRL_ID_LEVEL_AUTHOR, + level.author, + "Level Author" + } }; static struct @@ -198,16 +409,45 @@ static struct int xpos, ypos; int x, y; int gadget_id; + char *infotext; } scrollbutton_info[ED_NUM_SCROLLBUTTONS] = { - { ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 0 * ED_SCROLLBUTTON_YSIZE, - ED_SCROLL_UP_XPOS, ED_SCROLL_UP_YPOS, ED_CTRL_ID_SCROLL_UP }, - { ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 1 * ED_SCROLLBUTTON_YSIZE, - ED_SCROLL_DOWN_XPOS, ED_SCROLL_DOWN_YPOS, ED_CTRL_ID_SCROLL_DOWN }, - { ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 2 * ED_SCROLLBUTTON_YSIZE, - ED_SCROLL_LEFT_XPOS, ED_SCROLL_LEFT_YPOS, ED_CTRL_ID_SCROLL_LEFT }, - { ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 3 * ED_SCROLLBUTTON_YSIZE, - ED_SCROLL_RIGHT_XPOS, ED_SCROLL_RIGHT_YPOS, ED_CTRL_ID_SCROLL_RIGHT } + { + ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 0 * ED_SCROLLBUTTON_YSIZE, + ED_SCROLL_UP_XPOS, ED_SCROLL_UP_YPOS, + ED_CTRL_ID_SCROLL_UP, + "scroll level editing area up" + }, + { + ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 1 * ED_SCROLLBUTTON_YSIZE, + ED_SCROLL_DOWN_XPOS, ED_SCROLL_DOWN_YPOS, + ED_CTRL_ID_SCROLL_DOWN, + "scroll level editing area down" + }, + { + ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 2 * ED_SCROLLBUTTON_YSIZE, + ED_SCROLL_LEFT_XPOS, ED_SCROLL_LEFT_YPOS, + ED_CTRL_ID_SCROLL_LEFT, + "scroll level editing area left" + }, + { + ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 3 * ED_SCROLLBUTTON_YSIZE, + ED_SCROLL_RIGHT_XPOS, ED_SCROLL_RIGHT_YPOS, + ED_CTRL_ID_SCROLL_RIGHT, + "scroll level editing area right" + }, + { + ED_ELEMENTLIST_UP_XPOS, ED_ELEMENTLIST_UP_ALT_YPOS, + ED_ELEMENTLIST_UP_XPOS, ED_ELEMENTLIST_UP_YPOS, + ED_CTRL_ID_ELEMENTLIST_UP, + "scroll element list up" + }, + { + ED_ELEMENTLIST_DOWN_XPOS, ED_ELEMENTLIST_DOWN_ALT_YPOS, + ED_ELEMENTLIST_DOWN_XPOS, ED_ELEMENTLIST_DOWN_YPOS, + ED_CTRL_ID_ELEMENTLIST_DOWN, + "scroll element list down" + } }; static struct @@ -217,38 +457,46 @@ static struct int width, height; int type; int gadget_id; + char *infotext; } scrollbar_info[ED_NUM_SCROLLBARS] = { - { ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS, + { + ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS, ED_SCROLL_VERTICAL_XPOS, ED_SCROLL_VERTICAL_YPOS, ED_SCROLL_VERTICAL_XSIZE, ED_SCROLL_VERTICAL_YSIZE, GD_TYPE_SCROLLBAR_VERTICAL, - ED_CTRL_ID_SCROLL_VERTICAL }, - { ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS, + ED_CTRL_ID_SCROLL_VERTICAL, + "scroll level editing area vertically" + }, + { + ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS, ED_SCROLL_HORIZONTAL_XPOS, ED_SCROLL_HORIZONTAL_YPOS, ED_SCROLL_HORIZONTAL_XSIZE, ED_SCROLL_HORIZONTAL_YSIZE, GD_TYPE_SCROLLBAR_HORIZONTAL, - ED_CTRL_ID_SCROLL_HORIZONTAL }, + ED_CTRL_ID_SCROLL_HORIZONTAL, + "scroll level editing area horizontally" + }, }; - /* forward declaration for internal use */ static void DrawDrawingWindow(); +static void DrawLevelInfoWindow(); static void DrawPropertiesWindow(); static void CopyLevelToUndoBuffer(int); static void HandleControlButtons(struct GadgetInfo *); static void HandleCounterButtons(struct GadgetInfo *); static void HandleDrawingAreas(struct GadgetInfo *); +static void HandleDrawingAreaInfo(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 boolean draw_with_brush = FALSE; static int properties_element = 0; -static short ElementContent[MAX_ELEMCONT][3][3]; +static short ElementContent[MAX_ELEM_CONTENT][3][3]; static short FieldBackup[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; static short UndoBuffer[NUM_UNDO_STEPS][MAX_LEV_FIELDX][MAX_LEV_FIELDY]; static int undo_buffer_position = 0; @@ -262,17 +510,15 @@ static int random_placement_method = RANDOM_USE_PERCENTAGE; static int random_placement_method = RANDOM_USE_NUM_OBJECTS; #endif -/* pointer to score value */ -static int *gadget_score_value; -static int *gadget_areas_value; - -static int level_xpos,level_ypos; +static int level_xpos, level_ypos; static int edit_mode; static boolean name_typing; static int new_element1 = EL_MAUERWERK; static int new_element2 = EL_LEERRAUM; static int new_element3 = EL_ERDREICH; +static int counter_xsize = DXSIZE + 20; + int element_shift = 0; int editor_element[] = @@ -457,10 +703,10 @@ int editor_element[] = EL_MAUER_Y, EL_MAUER_XY, + EL_INVISIBLE_STEEL, + EL_UNSICHTBAR, EL_SPEED_PILL, EL_LEERRAUM, - EL_LEERRAUM, - EL_LEERRAUM, EL_CHAR_A + ('S' - 'A'), EL_CHAR_A + ('O' - 'A'), @@ -671,14 +917,6 @@ static void ScrollMiniLevel(int from_x, int from_y, int scroll) BackToFront(); } -void InitLevelEditorGadgets() -{ - int i; - - for (i=0; iwidth + ED_GADGET_DISTANCE; /* xpos of text count button */ + + if (j == 0) + { + id = counterbutton_info[i].gadget_id_text; + event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING; + + gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS; + gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS; + + gi = CreateGadget(GDI_CUSTOM_ID, id, + GDI_INFO_TEXT, "enter counter value", + GDI_X, xpos, + GDI_Y, ypos, + GDI_TYPE, GD_TYPE_TEXTINPUT_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, + GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x, gd_y, + GDI_DESIGN_PRESSED, gd_pixmap, gd_x, gd_y, + GDI_DESIGN_BORDER, ED_BORDER_SIZE, + GDI_EVENT_MASK, event_mask, + GDI_CALLBACK_ACTION, HandleCounterButtons, + GDI_END); + + if (gi == NULL) + Error(ERR_EXIT, "cannot create gadget"); + + level_editor_gadget[id] = gi; + xpos += gi->width + ED_GADGET_DISTANCE; /* xpos of up count button */ + } } } } @@ -867,17 +1224,12 @@ static void CreateDrawingAreas() gi = CreateGadget(GDI_CUSTOM_ID, id, GDI_X, SX, GDI_Y, SY, - - /* - GDI_WIDTH, SXSIZE, - GDI_HEIGHT, SYSIZE, - */ - GDI_TYPE, GD_TYPE_DRAWING_AREA, GDI_AREA_SIZE, ED_FIELDX, ED_FIELDY, GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY, GDI_EVENT_MASK, event_mask, - GDI_CALLBACK, HandleDrawingAreas, + GDI_CALLBACK_INFO, HandleDrawingAreaInfo, + GDI_CALLBACK_ACTION, HandleDrawingAreas, GDI_END); if (gi == NULL) @@ -886,12 +1238,12 @@ static void CreateDrawingAreas() level_editor_gadget[id] = gi; /* ... up to eight areas for element content ... */ - for (i=0; ix < DX) + UnmapGadget(level_editor_gadget[i]); } void UnmapLevelEditorGadgets() @@ -1103,8 +1457,6 @@ void DrawLevelEd() { int i, x, y, graphic; - level_xpos = -1; - level_ypos = -1; edit_mode = ED_MODE_DRAWING; name_typing = FALSE; @@ -1126,6 +1478,8 @@ void DrawLevelEd() } else { + level_xpos = -1; + level_ypos = -1; undo_buffer_position = -1; undo_buffer_steps = -1; CopyLevelToUndoBuffer(UNDO_IMMEDIATE); @@ -1212,8 +1566,7 @@ void DrawLevelEd() OpenDoor(DOOR_OPEN_1); - if (!level_editor_gadgets_created) - CreateLevelEditorGadgets(); + strcpy(level_editor_gadget[ED_CTRL_ID_LEVEL_NAME]->text.value, level.name); MapControlButtons(); @@ -1405,6 +1758,50 @@ void AdjustLevelScrollPosition() level_ypos = -1; } +void AdjustEditorScrollbar(int id) +{ + struct GadgetInfo *gi = level_editor_gadget[id]; + int items_max, items_visible, item_position; + + if (id == ED_CTRL_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; + + AdjustScrollbar(gi, items_max, item_position); +} + +void ModifyEditorTextInput(int textinput_id, char *new_text) +{ + int gadget_id = textinput_info[textinput_id].gadget_id; + struct GadgetInfo *gi = level_editor_gadget[gadget_id]; + + ModifyTextInputTextValue(gi, new_text); +} + +void ModifyEditorCounter(int counter_id, int new_value) +{ + int *counter_value = *counterbutton_info[counter_id].counter_value; + int gadget_id = counterbutton_info[counter_id].gadget_id_text; + struct GadgetInfo *gi = level_editor_gadget[gadget_id]; + + ModifyTextInputNumberValue(gi, new_value); + + if (counter_value != NULL) + *counter_value = gi->text.number_value; +} + static void PickDrawingElement(int button, int element) { if (button < 1 || button > 3) @@ -1441,7 +1838,11 @@ static void PickDrawingElement(int button, int element) void LevelEd(int mx, int my, int button) { static int last_button = 0; + + /* static int in_field_pressed = FALSE; + */ + static boolean use_floodfill = FALSE; @@ -1498,6 +1899,9 @@ void LevelEd(int mx, int my, int button) } else /********** EDIT/CTRL-FENSTER **********/ { + + +#if 0 static unsigned long choice_delay = 0; int choice = CheckElemButtons(mx,my,button); int elem_pos = choice-ED_BUTTON_ELEM; @@ -1510,14 +1914,8 @@ void LevelEd(int mx, int my, int button) int step = (button == 1 ? 1 : button == 2 ? 5 : 10); int i; -#if 0 - step = (button==1 ? MAX_ELEM_X : button==2 ? 5*MAX_ELEM_X : - elements_in_list); - element_shift += (choice==ED_BUTTON_EUP ? -step : step); -#else step = step * MAX_ELEM_X * (choice == ED_BUTTON_EUP ? -1 : +1); element_shift += step; -#endif if (element_shift<0) element_shift = 0; @@ -1547,6 +1945,9 @@ void LevelEd(int mx, int my, int button) DrawPropertiesWindow(); } } +#endif + + if (edit_mode == ED_MODE_DRAWING) /********** EDIT-FENSTER **********/ { @@ -1701,6 +2102,10 @@ void LevelEd(int mx, int my, int button) } else if (edit_mode == ED_MODE_INFO)/********** KONTROLL-FENSTER **********/ { + + +#if 0 + int choice = CheckCountButtons(mx,my,button); int step = (button==1 ? 1 : button==2 ? 5 : button==3 ? 10 : 0); @@ -1830,10 +2235,6 @@ void LevelEd(int mx, int my, int button) XFlush(display); } - - -#if 0 - switch(CheckCtrlButtons(mx,my,button)) { case ED_BUTTON_EDIT: @@ -1910,10 +2311,6 @@ void LevelEd(int mx, int my, int button) break; } -#endif - - - if (mx>=ED_COUNT_GADGET_XPOS && mx=ED_COUNT_GADGET_YPOS+16*ED_COUNT_GADGET_YSIZE && @@ -1995,6 +2392,11 @@ void LevelEd(int mx, int my, int button) } else if (!motion_status) /* Mauszeiger nicht im Cruncher-Feld */ in_field_pressed = FALSE; + +#endif + + + } } @@ -2036,7 +2438,7 @@ void LevelNameTyping(KeySym key) ascii = '_'; #endif - if (ascii && len from_x ? +1 : -1); + int to_y = to_y2 - (to_y2 > from_y ? +1 : -1); + int len_x = ABS(to_x - from_x); + int len_y = ABS(to_y - from_y); + int radius, x, y; + + radius = (int)(sqrt((float)(len_x * len_x + len_y * len_y)) + 0.5); + + /* not optimal (some points get drawn twice) but simple, + and fast enough for the few points we are drawing */ + + for (x=0; x<=radius; x++) + { + int sx, sy, lx, ly; + + y = (int)(sqrt((float)(radius * radius - x * x)) + 0.5); + + sx = from_x + x * (from_x < to_x2 ? +1 : -1); + sy = from_y + y * (from_y < to_y2 ? +1 : -1); + lx = sx + level_xpos; + ly = sy + level_ypos; + + if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly)) + DrawLineElement(sx, sy, element, change_level); + } + + for (y=0; y<=radius; y++) + { + int sx, sy, lx, ly; + + x = (int)(sqrt((float)(radius * radius - y * y)) + 0.5); + + sx = from_x + x * (from_x < to_x2 ? +1 : -1); + sy = from_y + y * (from_y < to_y2 ? +1 : -1); + lx = sx + level_xpos; + ly = sy + level_ypos; + + if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly)) + DrawLineElement(sx, sy, element, change_level); + } +} + +static void DrawArc(int from_x, int from_y, int to_x, int to_y, + int element, boolean change_level) +{ + int to_x2 = to_x + (to_x < from_x ? -1 : +1); + int to_y2 = to_y + (to_y > from_y ? +1 : -1); + + DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level); +} + +#if 0 +static void DrawCircle(int from_x, int from_y, int to_x, int to_y, + int element, boolean change_level) +{ + int to_x2 = to_x + (to_x < from_x ? -1 : +1); + int to_y2 = to_y + (to_y > from_y ? +1 : -1); + int mirror_to_x2 = from_x - (to_x2 - from_x); + int mirror_to_y2 = from_y - (to_y2 - from_y); + + DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level); + DrawArcExt(from_x, from_y, mirror_to_x2, to_y2, element, change_level); + DrawArcExt(from_x, from_y, to_x2, mirror_to_y2, element, change_level); + DrawArcExt(from_x, from_y, mirror_to_x2, mirror_to_y2, element,change_level); +} +#endif + static void DrawAreaBorder(int from_x, int from_y, int to_x, int to_y) { int from_sx, from_sy; @@ -2503,52 +3026,147 @@ static void SelectArea(int from_x, int from_y, int to_x, int to_y, /* values for CopyBrushExt() */ #define CB_AREA_TO_BRUSH 0 -#define CB_BRUSH_TO_LEVEL 1 +#define CB_BRUSH_TO_CURSOR 1 +#define CB_BRUSH_TO_LEVEL 2 +#define CB_DELETE_OLD_CURSOR 3 -static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, int mode) +static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, + int button, int mode) { - static short brush_buffer[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; - static int brush_from_x, brush_from_y; - static int brush_to_x, brush_to_y; + static short brush_buffer[ED_FIELDX][ED_FIELDY]; + static int brush_width, brush_height; + static int last_cursor_x = -1, last_cursor_y = -1; + static boolean delete_old_brush; + int new_element; int x, y; - if (from_x > to_x) - swap_numbers(&from_x, &to_x); + if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush) + return; - if (from_y > to_y) - swap_numbers(&from_y, &to_y); + new_element = (button == 1 ? new_element1 : + button == 2 ? new_element2 : + button == 3 ? new_element3 : 0); if (mode == CB_AREA_TO_BRUSH) { - for (y=from_y; y<=to_y; y++) - for (x=from_x; x<=to_x; x++) - brush_buffer[x][y] = Feld[x][y]; + int from_lx, from_ly; + + if (from_x > to_x) + swap_numbers(&from_x, &to_x); + + if (from_y > to_y) + swap_numbers(&from_y, &to_y); - brush_from_x = from_x; - brush_from_y = from_y; - brush_to_x = to_x; - brush_to_y = to_y; + brush_width = to_x - from_x + 1; + brush_height = to_y - from_y + 1; + + from_lx = from_x + level_xpos; + from_ly = from_y + level_ypos; + + for (y=0; y border_to_x) + border_to_x = sx; + if (sy < border_from_y) + border_from_y = sy; + else if (sy > border_to_y) + border_to_y = sy; + + DrawLineElement(sx, sy, element, change_level); + } + } + } + + /* + printf("%d, %d - %d, %d in level and screen\n", + border_from_x, border_from_y, border_to_x, border_to_y); + */ + + if (mode != CB_DELETE_OLD_CURSOR) + DrawAreaBorder(border_from_x, border_from_y, border_to_x, border_to_y); + + /* + if (mode == CB_BRUSH_TO_LEVEL) + CopyLevelToUndoBuffer(UNDO_IMMEDIATE); + */ + + last_cursor_x = cursor_x; + last_cursor_y = cursor_y; + delete_old_brush = TRUE; } } -static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y) +static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y, + int button) { - CopyBrushExt(from_x, from_y, to_x, to_y, CB_AREA_TO_BRUSH); + CopyBrushExt(from_x, from_y, to_x, to_y, button, CB_AREA_TO_BRUSH); } -#if 0 -static void CopyBrushToLevel() +static void CopyBrushToLevel(int x, int y, int button) { - CopyBrushExt(0, 0, 0, 0, CB_BRUSH_TO_LEVEL); + CopyBrushExt(x, y, 0, 0, button, CB_BRUSH_TO_LEVEL); +} + +static void CopyBrushToCursor(int x, int y) +{ + CopyBrushExt(x, y, 0, 0, 0, CB_BRUSH_TO_CURSOR); +} + +static void DeleteBrushFromCursor() +{ + CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR); } -#endif static void FloodFill(int from_x, int from_y, int fill_element) { @@ -2688,6 +3306,18 @@ static void DrawLevelText(int sx, int sy, char letter, int mode) } } +static void SetTextCursor(int unused_sx, int unused_sy, int sx, int sy, + int element, boolean change_level) +{ + int lx = sx + level_xpos; + int ly = sy + level_ypos; + + if (element == -1) + DrawMiniElement(sx, sy, Feld[lx][ly]); + else + DrawAreaBorder(sx, sy, sx, sy); +} + static void CopyLevelToUndoBuffer(int mode) { static boolean accumulated_undo = FALSE; @@ -2788,7 +3418,6 @@ void WrapLevel(int dx, int dy) static void HandleDrawingAreas(struct GadgetInfo *gi) { static boolean started_inside_drawing_area = FALSE; - static boolean draw_with_brush = FALSE; int id = gi->custom_id; boolean inside_drawing_area = !gi->event.off_borders; boolean button_press_event; @@ -2804,6 +3433,9 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1; int x, y; + /* handle info callback for each invocation of action callback */ + gi->callback_info(gi); + /* if (edit_mode != ED_MODE_DRAWING) return; @@ -2844,6 +3476,13 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) button == 2 ? new_element2 : button == 3 ? new_element3 : 0); + +#if 0 + if (button_release_event) + button = 0; +#endif + + if (!draw_level && drawing_function != ED_CTRL_ID_SINGLE_ITEMS) return; @@ -2853,12 +3492,23 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) if (draw_level) { if (button_release_event) + { CopyLevelToUndoBuffer(UNDO_IMMEDIATE); + if (edit_mode == ED_MODE_DRAWING && draw_with_brush && + !inside_drawing_area) + DeleteBrushFromCursor(); + } + if (!button) break; - if (new_element != Feld[lx][ly]) + if (draw_with_brush) + { + if (!button_release_event) + CopyBrushToLevel(sx, sy, button); + } + else if (new_element != Feld[lx][ly]) { if (new_element == EL_SPIELFIGUR) { @@ -2896,8 +3546,9 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) if (id == ED_CTRL_ID_AMOEBA_CONTENT) level.amoebe_inhalt = new_element; - else if (id >= ED_CTRL_ID_ELEMCONT_0 && id <= ED_CTRL_ID_ELEMCONT_7) - level.mampfer_inhalt[id - ED_CTRL_ID_ELEMCONT_0][sx][sy] = + else if (id >= ED_CTRL_ID_ELEM_CONTENT_0 && + id <= ED_CTRL_ID_ELEM_CONTENT_7) + level.mampfer_inhalt[id - ED_CTRL_ID_ELEM_CONTENT_0][sx][sy] = new_element; } break; @@ -2922,9 +3573,11 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) break; case ED_CTRL_ID_LINE: + case ED_CTRL_ID_ARC: case ED_CTRL_ID_RECTANGLE: case ED_CTRL_ID_FILLED_BOX: - case ED_CTRL_ID_BRUSH: + case ED_CTRL_ID_GRAB_BRUSH: + case ED_CTRL_ID_TEXT: { static int last_sx = -1; static int last_sy = -1; @@ -2934,27 +3587,38 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) if (drawing_function == ED_CTRL_ID_LINE) draw_func = DrawLine; + else if (drawing_function == ED_CTRL_ID_ARC) + draw_func = DrawArc; else if (drawing_function == ED_CTRL_ID_RECTANGLE) draw_func = DrawRectangle; else if (drawing_function == ED_CTRL_ID_FILLED_BOX) draw_func = DrawFilledBox; - else + else if (drawing_function == ED_CTRL_ID_GRAB_BRUSH) draw_func = SelectArea; + else /* (drawing_function == ED_CTRL_ID_TEXT) */ + draw_func = SetTextCursor; if (button_press_event) { draw_func(sx, sy, sx, sy, new_element, FALSE); start_sx = last_sx = sx; start_sy = last_sy = sy; + + if (drawing_function == ED_CTRL_ID_TEXT) + DrawLevelText(0, 0, 0, TEXT_END); } else if (button_release_event) { draw_func(start_sx, start_sy, sx, sy, new_element, TRUE); - if (drawing_function == ED_CTRL_ID_BRUSH) + if (drawing_function == ED_CTRL_ID_GRAB_BRUSH) { - CopyAreaToBrush(start_sx, start_sy, sx, sy); + CopyAreaToBrush(start_sx, start_sy, sx, sy, button); + CopyBrushToCursor(sx, sy); + ClickOnGadget(level_editor_gadget[ED_CTRL_ID_SINGLE_ITEMS]); draw_with_brush = TRUE; } + else if (drawing_function == ED_CTRL_ID_TEXT) + DrawLevelText(sx, sy, 0, TEXT_INIT); else CopyLevelToUndoBuffer(UNDO_IMMEDIATE); } @@ -2968,10 +3632,23 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) } break; + + +#if 0 case ED_CTRL_ID_TEXT: + /* + DrawMiniElement(last_sx, last_sy, Feld[lx][ly]); + DrawAreaBorder(sx, sy, sx, sy); + last_sx = sx; + last_sy = sy; + */ + if (button_press_event) DrawLevelText(sx, sy, 0, TEXT_INIT); break; +#endif + + case ED_CTRL_ID_FLOOD_FILL: if (button_press_event && Feld[lx][ly] != new_element) @@ -3002,27 +3679,109 @@ static void HandleCounterButtons(struct GadgetInfo *gi) switch (id) { - case ED_CTRL_ID_SCORE_DOWN: - case ED_CTRL_ID_SCORE_UP: - *gadget_score_value += (id == ED_CTRL_ID_SCORE_DOWN ? -step : step); - if (*gadget_score_value < 0) - *gadget_score_value = 0; - else if (*gadget_score_value > 255) - *gadget_score_value = 255; + case ED_CTRL_ID_ELEM_SCORE_DOWN: + case ED_CTRL_ID_ELEM_SCORE_UP: + step *= (id == ED_CTRL_ID_ELEM_SCORE_DOWN ? -1 : 1); + ModifyEditorCounter(ED_COUNTER_ID_ELEM_SCORE, + *gadget_elem_score_value + step); + break; + case ED_CTRL_ID_ELEM_SCORE_TEXT: + *gadget_elem_score_value = gi->text.number_value; + break; - DrawCounterValueField(ED_COUNTER_SCORE, *gadget_score_value); + case ED_CTRL_ID_ELEM_CONTENT_DOWN: + case ED_CTRL_ID_ELEM_CONTENT_UP: + step *= (id == ED_CTRL_ID_ELEM_CONTENT_DOWN ? -1 : 1); + ModifyEditorCounter(ED_COUNTER_ID_ELEM_CONTENT, + *gadget_elem_content_value + step); + DrawElementContentAreas(); + break; + case ED_CTRL_ID_ELEM_CONTENT_TEXT: + *gadget_elem_content_value = gi->text.number_value; + DrawElementContentAreas(); break; - case ED_CTRL_ID_ELEMCONT_DOWN: - case ED_CTRL_ID_ELEMCONT_UP: - *gadget_areas_value += (id == ED_CTRL_ID_ELEMCONT_DOWN ? -step : step); - if (*gadget_areas_value < 1) - *gadget_areas_value = 1; - else if (*gadget_areas_value > MAX_ELEMCONT) - *gadget_areas_value = MAX_ELEMCONT; + case ED_CTRL_ID_LEVEL_XSIZE_DOWN: + case ED_CTRL_ID_LEVEL_XSIZE_UP: + step *= (id == ED_CTRL_ID_LEVEL_XSIZE_DOWN ? -1 : 1); + ModifyEditorCounter(ED_COUNTER_ID_LEVEL_XSIZE, + *gadget_level_xsize_value + step); + level.fieldx = lev_fieldx; + break; + case ED_CTRL_ID_LEVEL_XSIZE_TEXT: + *gadget_level_xsize_value = gi->text.number_value; + level.fieldx = lev_fieldx; + break; - DrawCounterValueField(ED_COUNTER_ELEMCONT, *gadget_areas_value); - DrawElementContentAreas(); + case ED_CTRL_ID_LEVEL_YSIZE_DOWN: + case ED_CTRL_ID_LEVEL_YSIZE_UP: + step *= (id == ED_CTRL_ID_LEVEL_YSIZE_DOWN ? -1 : 1); + ModifyEditorCounter(ED_COUNTER_ID_LEVEL_YSIZE, + *gadget_level_ysize_value + step); + level.fieldy = lev_fieldy; + break; + case ED_CTRL_ID_LEVEL_YSIZE_TEXT: + *gadget_level_ysize_value = gi->text.number_value; + level.fieldy = lev_fieldy; + break; + + case ED_CTRL_ID_LEVEL_RANDOM_DOWN: + case ED_CTRL_ID_LEVEL_RANDOM_UP: + step *= (id == ED_CTRL_ID_LEVEL_RANDOM_DOWN ? -1 : 1); + ModifyEditorCounter(ED_COUNTER_ID_LEVEL_RANDOM, + *gadget_level_random_value + step); + break; + case ED_CTRL_ID_LEVEL_RANDOM_TEXT: + *gadget_level_random_value = gi->text.number_value; + break; + + case ED_CTRL_ID_LEVEL_COLLECT_DOWN: + case ED_CTRL_ID_LEVEL_COLLECT_UP: + step *= (id == ED_CTRL_ID_LEVEL_COLLECT_DOWN ? -1 : 1); + ModifyEditorCounter(ED_COUNTER_ID_LEVEL_COLLECT, + *gadget_level_collect_value + step); + break; + case ED_CTRL_ID_LEVEL_COLLECT_TEXT: + *gadget_level_collect_value = gi->text.number_value; + break; + + case ED_CTRL_ID_LEVEL_TIMELIMIT_DOWN: + case ED_CTRL_ID_LEVEL_TIMELIMIT_UP: + step *= (id == ED_CTRL_ID_LEVEL_TIMELIMIT_DOWN ? -1 : 1); + ModifyEditorCounter(ED_COUNTER_ID_LEVEL_TIMELIMIT, + *gadget_level_timelimit_value + step); + break; + case ED_CTRL_ID_LEVEL_TIMELIMIT_TEXT: + *gadget_level_timelimit_value = gi->text.number_value; + break; + + case ED_CTRL_ID_LEVEL_TIMESCORE_DOWN: + case ED_CTRL_ID_LEVEL_TIMESCORE_UP: + step *= (id == ED_CTRL_ID_LEVEL_TIMESCORE_DOWN ? -1 : 1); + ModifyEditorCounter(ED_COUNTER_ID_LEVEL_TIMESCORE, + *gadget_level_timescore_value + step); + break; + case ED_CTRL_ID_LEVEL_TIMESCORE_TEXT: + *gadget_level_timescore_value = gi->text.number_value; + break; + + default: + break; + } +} + +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; + + case ED_CTRL_ID_LEVEL_AUTHOR: + strcpy(level.author, gi->text.value); break; default: @@ -3038,7 +3797,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) int new_element; int player_present = FALSE; int level_changed = FALSE; - int x, y; + int i, x, y; new_element = (button == 1 ? new_element1 : button == 2 ? new_element2 : @@ -3154,6 +3913,29 @@ static void HandleControlButtons(struct GadgetInfo *gi) DrawMiniLevel(level_xpos, level_ypos); break; + case ED_CTRL_ID_ELEMENTLIST_UP: + case ED_CTRL_ID_ELEMENTLIST_DOWN: + step *= (id == ED_CTRL_ID_ELEMENTLIST_UP ? -1 : +1); + element_shift += step * ED_ELEMENTLIST_BUTTONS_HORIZ; + + 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; + + for (i=0; ideco.design; + + UnmapGadget(gi); + getMiniGraphicSource(el2gfx(editor_element[element_shift + i]), + &design->pixmap, &design->x, &design->y); + MapGadget(gi); + } + break; + case ED_CTRL_ID_WRAP_LEFT: WrapLevel(-step, 0); break; @@ -3173,14 +3955,16 @@ static void HandleControlButtons(struct GadgetInfo *gi) case ED_CTRL_ID_SINGLE_ITEMS: case ED_CTRL_ID_CONNECTED_ITEMS: case ED_CTRL_ID_LINE: + case ED_CTRL_ID_ARC: 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_BRUSH: + case ED_CTRL_ID_GRAB_BRUSH: case ED_CTRL_ID_PICK_ELEMENT: last_drawing_function = drawing_function; drawing_function = id; + draw_with_brush = FALSE; break; case ED_CTRL_ID_RANDOM_PLACEMENT: @@ -3221,7 +4005,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) case ED_CTRL_ID_INFO: if (edit_mode != ED_MODE_INFO) { - DrawControlWindow(); + DrawLevelInfoWindow(); edit_mode = ED_MODE_INFO; } else @@ -3375,30 +4159,210 @@ static void HandleControlButtons(struct GadgetInfo *gi) void HandleLevelEditorKeyInput(KeySym key) { - if (edit_mode == ED_MODE_DRAWING && drawing_function == ED_CTRL_ID_TEXT) + if (edit_mode == ED_MODE_DRAWING) { char letter = getCharFromKeySym(key); - if (letter) - DrawLevelText(0, 0, letter, TEXT_WRITECHAR); - else if (key == XK_Delete || key == XK_BackSpace) - DrawLevelText(0, 0, 0, TEXT_BACKSPACE); - else if (key == XK_Return) - DrawLevelText(0, 0, 0, TEXT_NEWLINE); + if (drawing_function == ED_CTRL_ID_TEXT) + { + if (letter) + DrawLevelText(0, 0, letter, TEXT_WRITECHAR); + else if (key == XK_Delete || key == XK_BackSpace) + DrawLevelText(0, 0, 0, TEXT_BACKSPACE); + else if (key == XK_Return) + DrawLevelText(0, 0, 0, TEXT_NEWLINE); + } + else if (button_status == MB_RELEASED) + { + int i, id; + + switch (key) + { + case XK_Left: + id = ED_CTRL_ID_SCROLL_LEFT; + break; + case XK_Right: + id = ED_CTRL_ID_SCROLL_RIGHT; + break; + case XK_Up: + id = ED_CTRL_ID_SCROLL_UP; + break; + case XK_Down: + id = ED_CTRL_ID_SCROLL_DOWN; + break; + + default: + id = ED_CTRL_ID_NONE; + break; + } + + if (id != ED_CTRL_ID_NONE) + ClickOnGadget(level_editor_gadget[id]); + else if (letter == '.') + ClickOnGadget(level_editor_gadget[ED_CTRL_ID_SINGLE_ITEMS]); + else + for (i=0; iinfo_text == NULL) + return; + + strncpy(infotext, gi->info_text, MAX_INFOTEXT_LEN); + infotext[MAX_INFOTEXT_LEN] = '\0'; + + if (gi->custom_id < ED_NUM_CTRL_BUTTONS) + { + int key = control_info[gi->custom_id].shortcut; + + if (key) + { + sprintf(shortcut, " ('%s%c')", + (key >= 'A' && key <= 'Z' ? "Shift-" : + gi->custom_id == ED_CTRL_ID_SINGLE_ITEMS ? ".' or '" : ""), + key); + + if (strlen(infotext) + strlen(shortcut) <= MAX_INFOTEXT_LEN) + strcat(infotext, shortcut); + } + } + + DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, FS_SMALL, FC_YELLOW); +} + +static void HandleDrawingAreaInfo(struct GadgetInfo *gi) { + static int start_lx, start_ly; + char *infotext; int id = gi->custom_id; + int sx = gi->event.x; + int sy = gi->event.y; + int lx = sx + level_xpos; + int ly = sy + level_ypos; - switch (id) + ClearEditorGadgetInfoText(); + + if (id == ED_CTRL_ID_DRAWING_LEVEL) { - case ED_CTRL_ID_LEVEL_NAME: - strcpy(level.name, gi->text_value); - break; + if (button_status) + { + int min_sx = 0, min_sy = 0; + int max_sx = gi->drawing.area_xsize - 1; + int max_sy = gi->drawing.area_ysize - 1; + int min_lx = 0, min_ly = 0; + int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1; + + /* 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); + + /* get positions inside level field */ + lx = sx + level_xpos; + ly = sy + level_ypos; + + /* 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; + } - default: - break; + if (IN_ED_FIELD(sx,sy) && IN_LEV_FIELD(lx, ly)) + { + if (button_status) /* if (gi->state == GD_BUTTON_PRESSED) */ + { + if (gi->event.type == GD_EVENT_PRESSED) + { + start_lx = lx; + start_ly = ly; + } + + switch (drawing_function) + { + case ED_CTRL_ID_SINGLE_ITEMS: + infotext = "Drawing single items"; + break; + case ED_CTRL_ID_CONNECTED_ITEMS: + infotext = "Drawing connected items"; + break; + case ED_CTRL_ID_LINE: + infotext = "Drawing line"; + break; + case ED_CTRL_ID_ARC: + infotext = "Drawing arc"; + break; + case ED_CTRL_ID_TEXT: + infotext = "Setting text cursor"; + break; + case ED_CTRL_ID_RECTANGLE: + infotext = "Drawing rectangle"; + break; + case ED_CTRL_ID_FILLED_BOX: + infotext = "Drawing filled box"; + break; + case ED_CTRL_ID_FLOOD_FILL: + infotext = "Flood fill"; + break; + case ED_CTRL_ID_GRAB_BRUSH: + infotext = "Grabbing brush"; + break; + case ED_CTRL_ID_PICK_ELEMENT: + infotext = "Picking element"; + break; + + default: + infotext = "Drawing position"; + break; + } + + DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW, + "%s: %d, %d", infotext, + ABS(lx - start_lx) + 1, + ABS(ly - start_ly) + 1); + } + else + DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW, + "Level position: %d, %d", lx, ly); + } + + /* misuse this function to draw brush cursor, if needed */ + if (edit_mode == ED_MODE_DRAWING && draw_with_brush && !button_status) + { + if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly)) + CopyBrushToCursor(sx, sy); + else + DeleteBrushFromCursor(); + } } + else if (id == ED_CTRL_ID_AMOEBA_CONTENT) + DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW, + "Amoeba content"); + else + DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW, + "Cruncher %d content: %d, %d", + id - ED_CTRL_ID_ELEM_CONTENT_0 + 1, sx, sy); }