From: Holger Schemel Date: Wed, 16 Dec 1998 02:37:19 +0000 (+0100) Subject: rnd-19981216-1 X-Git-Tag: 1.3.0^2~58 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=c5728b1ebc2a1d3753a6eea5a0f6335d077eef6b;p=rocksndiamonds.git rnd-19981216-1 --- diff --git a/src/buttons.c b/src/buttons.c index c9e00fca..cffd190b 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -1659,21 +1659,31 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) &gi->alt_design[state] : &gi->design[state]); - XCopyArea(display, gd->pixmap, (direct ? window : drawto), gc, + XCopyArea(display, gd->pixmap, drawto, gc, gd->x, gd->y, gi->width, gi->height, gi->x, gi->y); + + if (direct) + XCopyArea(display, gd->pixmap, window, gc, + gd->x, gd->y, gi->width, gi->height, gi->x, gi->y); + else + redraw_mask |= REDRAW_ALL; } void MapGadget(struct GadgetInfo *gi) { + if (gi == NULL) + return; + gi->mapped = TRUE; DrawGadget(gi, (gi->state == GD_BUTTON_PRESSED), FALSE); - - redraw_mask |= REDRAW_ALL; } void UnmapGadget(struct GadgetInfo *gi) { + if (gi == NULL) + return; + gi->mapped = FALSE; } diff --git a/src/buttons.h b/src/buttons.h index 695aef6b..94616e06 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -193,18 +193,21 @@ #define ED_BUTTON_EXIT_XSIZE 90 #define ED_BUTTON_EXIT_YSIZE 20 +#define ED_BUTTON_COUNT_YPOS 60 +#define ED_BUTTON_COUNT_XSIZE 20 +#define ED_BUTTON_COUNT_YSIZE 20 #define ED_BUTTON_MINUS_XPOS 2 -#define ED_BUTTON_MINUS_YPOS 60 -#define ED_BUTTON_MINUS_XSIZE 20 -#define ED_BUTTON_MINUS_YSIZE 20 +#define ED_BUTTON_MINUS_YPOS ED_BUTTON_COUNT_YPOS +#define ED_BUTTON_MINUS_XSIZE ED_BUTTON_COUNT_XSIZE +#define ED_BUTTON_MINUS_YSIZE ED_BUTTON_COUNT_YSIZE #define ED_WIN_COUNT_XPOS (ED_BUTTON_MINUS_XPOS+ED_BUTTON_MINUS_XSIZE+2) -#define ED_WIN_COUNT_YPOS ED_BUTTON_MINUS_YPOS +#define ED_WIN_COUNT_YPOS ED_BUTTON_COUNT_YPOS #define ED_WIN_COUNT_XSIZE 52 -#define ED_WIN_COUNT_YSIZE ED_BUTTON_MINUS_YSIZE +#define ED_WIN_COUNT_YSIZE ED_BUTTON_COUNT_YSIZE #define ED_BUTTON_PLUS_XPOS (ED_WIN_COUNT_XPOS+ED_WIN_COUNT_XSIZE+2) -#define ED_BUTTON_PLUS_YPOS ED_BUTTON_MINUS_YPOS -#define ED_BUTTON_PLUS_XSIZE ED_BUTTON_MINUS_XSIZE -#define ED_BUTTON_PLUS_YSIZE ED_BUTTON_MINUS_YSIZE +#define ED_BUTTON_PLUS_YPOS ED_BUTTON_COUNT_YPOS +#define ED_BUTTON_PLUS_XSIZE ED_BUTTON_COUNT_XSIZE +#define ED_BUTTON_PLUS_YSIZE ED_BUTTON_COUNT_YSIZE #define ED_COUNT_GADGET_XPOS 16 #define ED_COUNT_GADGET_YPOS (16+3*MINI_TILEY+64) diff --git a/src/editor.c b/src/editor.c index 0c97b9ee..d3d81c25 100644 --- a/src/editor.c +++ b/src/editor.c @@ -36,8 +36,10 @@ #define ED_SCROLL_UP 4 #define ED_SCROLL_DOWN 8 -/* delay value to avoid too fast scrolling etc. */ -#define CHOICE_DELAY_VALUE 100 +/* screens in the level editor */ +#define ED_MODE_EDIT 0 +#define ED_MODE_INFO 1 +#define ED_MODE_PROPERTIES 2 /* how many steps can be cancelled */ #define NUM_UNDO_STEPS (10 + 1) @@ -64,7 +66,16 @@ #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) -/* control button names */ +/* values for other gadgets */ +#define ED_SCORE_XPOS TILEX +#define ED_SCORE_YPOS (7 * TILEY) +#define ED_COUNT_VALUE_XOFFSET 5 +#define ED_COUNT_VALUE_YOFFSET 3 + +/* identifiers for DrawValueField() */ +#define ED_SCORE_FIELD 0 + +/* control button identifiers */ #define ED_CTRL_ID_SINGLE_ITEMS 0 #define ED_CTRL_ID_CONNECTED_ITEMS 1 #define ED_CTRL_ID_LINE 2 @@ -72,7 +83,7 @@ #define ED_CTRL_ID_RECTANGLE 4 #define ED_CTRL_ID_FILLED_BOX 5 #define ED_CTRL_ID_WRAP_UP 6 -#define ED_CTRL_ID_ITEM_PROPERTIES 7 +#define ED_CTRL_ID_PROPERTIES 7 #define ED_CTRL_ID_FLOOD_FILL 8 #define ED_CTRL_ID_WRAP_LEFT 9 #define ED_CTRL_ID_WRAP_RIGHT 11 @@ -86,14 +97,20 @@ #define ED_CTRL_ID_TEST 20 #define ED_CTRL_ID_EXIT 21 +/* other gadget identifiers */ +#define ED_CTRL_ID_SCORE_DOWN 22 +#define ED_CTRL_ID_SCORE_UP 23 + +#define ED_NUM_GADGETS 24 + /* forward declaration for internal use */ -void HandleDrawingFunctions(int, int, int); -void HandlePressedControlButtons(); -void HandleControlButtons(struct GadgetInfo *); +static void CopyLevelToUndoBuffer(); +static void HandleDrawingFunctions(int, int, int); +static void HandlePressedControlButtons(); +static 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 struct GadgetInfo *level_editor_gadget[ED_NUM_GADGETS]; +static boolean level_editor_gadgets_created = FALSE; static int drawing_function = ED_CTRL_ID_SINGLE_ITEMS; @@ -110,8 +127,11 @@ 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 level_xpos,level_ypos; -static boolean edit_mode; +static int edit_mode; static boolean name_typing; static int new_element1 = EL_MAUERWERK; static int new_element2 = EL_LEERRAUM; @@ -413,7 +433,7 @@ int editor_element[] = }; int elements_in_list = sizeof(editor_element)/sizeof(int); -void ScrollMiniLevel(int from_x, int from_y, int scroll) +static void ScrollMiniLevel(int from_x, int from_y, int scroll) { int x,y; int dx = (scroll==ED_SCROLL_LEFT ? -1 : scroll==ED_SCROLL_RIGHT ? 1 : 0); @@ -440,12 +460,17 @@ void ScrollMiniLevel(int from_x, int from_y, int scroll) BackToFront(); } -void CreateLevelEditorControlButtons() +void InitLevelEditorGadgets() { int i; - if (control_button_gadgets_created) - return; + for (i=0; i0) || (choice == ED_BUTTON_EDOWN && element_shift=0) { - if (!DelayReached(&choice_delay, CHOICE_DELAY_VALUE)) + if (!DelayReached(&choice_delay, GADGET_FRAME_DELAY)) break; if (lev_fieldx<2*SCR_FIELDX-2) break; @@ -988,7 +1068,7 @@ void LevelEd(int mx, int my, int button) case ED_BUTTON_RIGHT: if (level_xpos<=lev_fieldx-2*SCR_FIELDX) { - if (!DelayReached(&choice_delay, CHOICE_DELAY_VALUE)) + if (!DelayReached(&choice_delay, GADGET_FRAME_DELAY)) break; if (lev_fieldx<2*SCR_FIELDX-2) break; @@ -1005,7 +1085,7 @@ void LevelEd(int mx, int my, int button) case ED_BUTTON_UP: if (level_ypos>=0) { - if (!DelayReached(&choice_delay, CHOICE_DELAY_VALUE)) + if (!DelayReached(&choice_delay, GADGET_FRAME_DELAY)) break; if (lev_fieldy<2*SCR_FIELDY-2) break; @@ -1022,7 +1102,7 @@ void LevelEd(int mx, int my, int button) case ED_BUTTON_DOWN: if (level_ypos<=lev_fieldy-2*SCR_FIELDY) { - if (!DelayReached(&choice_delay, CHOICE_DELAY_VALUE)) + if (!DelayReached(&choice_delay, GADGET_FRAME_DELAY)) break; if (lev_fieldy<2*SCR_FIELDY-2) break; @@ -1101,7 +1181,7 @@ void LevelEd(int mx, int my, int button) int step = (button==1 ? 1 : button==2 ? 5 : button==3 ? 10 : 0); if (choice >= 0 && choice < 36 && - DelayReached(&choice_delay, CHOICE_DELAY_VALUE)) + DelayReached(&choice_delay, GADGET_FRAME_DELAY)) { if (!(choice % 2)) step = -step; @@ -1241,7 +1321,7 @@ void LevelEd(int mx, int my, int button) VXSIZE,VYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2); OpenDoor(DOOR_OPEN_2); - edit_mode = TRUE; + edit_mode = ED_MODE_EDIT; break; case ED_BUTTON_CLEAR: if (Request("Are you sure to clear this level ?",REQ_ASK)) @@ -1490,6 +1570,65 @@ void LevelNameTyping(KeySym key) } } +static void DrawValueField(int field, int value) +{ + int i = 0; + int screen_pos[][3] = + { + { ED_SCORE_FIELD, + ED_SCORE_XPOS + ED_WIN_COUNT_XPOS, ED_SCORE_YPOS }, + { -1, 0, 0 } + }; + + while (screen_pos[i][0] != -1) + { + int x = SX + screen_pos[i][1]; + int y = SY + screen_pos[i][2]; + + if (screen_pos[i++][0] != field) + continue; + + XCopyArea(display, pix[PIX_DOOR], drawto, gc, + DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS, + DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS, + ED_WIN_COUNT_XSIZE, ED_WIN_COUNT_YSIZE, + x, y); + + DrawText(x + ED_COUNT_VALUE_XOFFSET, y + ED_COUNT_VALUE_YOFFSET, + int2str(value, 3), FS_SMALL, FC_YELLOW); + } +} + +static void DrawPropertiesWindow(int button) +{ + int x, y; + int new_element; + int num_elements_in_level; + + ClearWindow(); + + new_element = (button == 1 ? new_element1 : + button == 2 ? new_element2 : + button == 3 ? new_element3 : 0); + + DrawGraphic(1, 1, el2gfx(new_element)); + DrawText(SX + 3*TILEX, SY + 5*TILEY/4, "Element Properties", + FS_SMALL, FC_YELLOW); + + num_elements_in_level = 0; + for(y=0; ystate; - int button = control_button_gadget[id]->event.button; + int state = level_editor_gadget[id]->state; + int button = level_editor_gadget[id]->event.button; int step = (button == 1 ? 1 : button == 2 ? 5 : 10); if (state != GD_BUTTON_PRESSED) @@ -1932,6 +2066,17 @@ void HandlePressedControlButtons() DrawMiniLevel(level_xpos, level_ypos); } break; + + 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; + + DrawValueField(ED_SCORE_FIELD, *gadget_score_value); + break; default: break; @@ -1939,25 +2084,28 @@ void HandlePressedControlButtons() } } -void HandleControlButtons(struct GadgetInfo *gi) +static void HandleControlButtons(struct GadgetInfo *gi) { + /* int event_type = gi->event.type; + */ int button = gi->event.button; int player_present = FALSE; int level_changed = FALSE; - int id; + int id = -1; int i, x, y; /* get the button id */ for (i=0; iid == control_button_gadget[i]->id) + if (gi->id == level_editor_gadget[i]->id) id = i; - if (id < ED_NUM_CTRL1_BUTTONS && !edit_mode) + if (id >= 0 && id < ED_NUM_CTRL1_BUTTONS && edit_mode != ED_MODE_EDIT) { + UnmapLevelEditorWindowGadgets(); AdjustLevelScrollPosition(); DrawMiniLevel(level_xpos, level_ypos); - edit_mode = TRUE; + edit_mode = ED_MODE_EDIT; } switch (id) @@ -1973,8 +2121,14 @@ void HandleControlButtons(struct GadgetInfo *gi) drawing_function = id; break; + case ED_CTRL_ID_PROPERTIES: + DrawPropertiesWindow(button); + edit_mode = ED_MODE_PROPERTIES; + break; + case ED_CTRL_ID_RANDOM_PLACEMENT: RandomPlacement(button); + CopyLevelToUndoBuffer(); break; case ED_CTRL_ID_UNDO: @@ -1995,25 +2149,24 @@ void HandleControlButtons(struct GadgetInfo *gi) break; case ED_CTRL_ID_INFO: - if (edit_mode) + if (edit_mode != ED_MODE_INFO) { DrawControlWindow(); - edit_mode = FALSE; + edit_mode = ED_MODE_INFO; } else { AdjustLevelScrollPosition(); DrawMiniLevel(level_xpos, level_ypos); - edit_mode = TRUE; + edit_mode = ED_MODE_EDIT; } break; case ED_CTRL_ID_CLEAR: - CopyLevelToUndoBuffer(); - for(x=0; x leveldir[leveldir_nr].levels - 1) new_level_nr = leveldir[leveldir_nr].levels - 1; - if (old_level_nr == new_level_nr || !DelayReached(&level_delay, 150)) + if (old_level_nr == new_level_nr || + !DelayReached(&level_delay, GADGET_FRAME_DELAY)) goto out; level_nr = new_level_nr; @@ -861,7 +862,7 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) if (x == 1 && y == 2) { if (first_entry > 0 && - (dy || DelayReached(&choose_delay, 150))) + (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY))) { #if 0 first_entry--; @@ -879,7 +880,7 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) else if (x == 1 && y > num_page_entries + 2) { if (first_entry + num_page_entries < num_leveldirs && - (dy || DelayReached(&choose_delay, 150))) + (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY))) { #if 0 first_entry++; @@ -1421,7 +1422,7 @@ void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button) { static unsigned long delay = 0; - if (!DelayReached(&delay, 150)) + if (!DelayReached(&delay, GADGET_FRAME_DELAY)) goto out; player_nr = (player_nr + (x == 11 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;