1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
27 /* screens in the setup menu */
28 #define SETUP_MODE_MAIN 0
29 #define SETUP_MODE_GAME 1
30 #define SETUP_MODE_EDITOR 2
31 #define SETUP_MODE_INPUT 3
32 #define SETUP_MODE_SHORTCUT 4
33 #define SETUP_MODE_GRAPHICS 5
34 #define SETUP_MODE_SOUND 6
35 #define SETUP_MODE_ARTWORK 7
36 #define SETUP_MODE_CHOOSE_GRAPHICS 8
37 #define SETUP_MODE_CHOOSE_SOUNDS 9
38 #define SETUP_MODE_CHOOSE_MUSIC 10
40 #define MAX_SETUP_MODES 11
42 /* for input setup functions */
43 #define SETUPINPUT_SCREEN_POS_START 0
44 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
45 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
46 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
48 /* for various menu stuff */
49 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
50 #define MENU_SCREEN_START_YPOS 2
51 #define MENU_SCREEN_VALUE_XPOS 14
53 /* buttons and scrollbars identifiers */
54 #define SCREEN_CTRL_ID_SCROLL_UP 0
55 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
56 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
58 #define NUM_SCREEN_SCROLLBUTTONS 2
59 #define NUM_SCREEN_SCROLLBARS 1
60 #define NUM_SCREEN_GADGETS 3
62 /* forward declarations of internal functions */
63 static void HandleScreenGadgets(struct GadgetInfo *);
64 static void HandleSetupScreen_Generic(int, int, int, int, int);
65 static void HandleSetupScreen_Input(int, int, int, int, int);
66 static void CustomizeKeyboard(int);
67 static void CalibrateJoystick(int);
68 static void execSetupArtwork(void);
69 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
71 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
72 static int setup_mode = SETUP_MODE_MAIN;
74 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
75 static Bitmap *scrollbar_bitmap[4];
79 static void drawCursorExt(int xpos, int ypos, int color, int graphic)
81 static int cursor_array[SCR_FIELDY];
86 cursor_array[ypos] = graphic;
88 graphic = cursor_array[ypos];
92 graphic = (graphic == IMG_ARROW_BLUE_LEFT ? IMG_ARROW_RED_LEFT :
93 graphic == IMG_ARROW_BLUE_RIGHT ? IMG_ARROW_RED_RIGHT :
96 ypos += MENU_SCREEN_START_YPOS;
98 DrawBackground(SX + xpos * 32, SY + ypos * 32, TILEX, TILEY);
99 DrawGraphicThruMask(xpos, ypos, graphic, 0);
102 static void initCursor(int ypos, int graphic)
104 drawCursorExt(0, ypos, FC_BLUE, graphic);
107 static void drawCursor(int ypos, int color)
109 drawCursorExt(0, ypos, color, 0);
112 static void drawCursorXY(int xpos, int ypos, int graphic)
114 drawCursorExt(xpos, ypos, -1, graphic);
119 int x = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * FONT1_XSIZE) / 2;
121 DrawText(x, SY + 8, PROGRAM_TITLE_STRING, FS_BIG, FC_YELLOW);
122 DrawTextFCentered(46, FC_RED, WINDOW_SUBTITLE_STRING);
125 static void ToggleFullscreenIfNeeded()
127 if (setup.fullscreen != video.fullscreen_enabled)
129 /* save old door content */
130 BlitBitmap(backbuffer, bitmap_db_door,
131 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
133 /* toggle fullscreen */
134 ChangeVideoModeIfNeeded(setup.fullscreen);
135 setup.fullscreen = video.fullscreen_enabled;
137 /* redraw background to newly created backbuffer */
138 BlitBitmap(new_graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
139 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
141 /* restore old door content */
142 BlitBitmap(bitmap_db_door, backbuffer,
143 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
145 redraw_mask = REDRAW_ALL;
151 static LevelDirTree *leveldir_last_valid = NULL;
153 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
158 KeyboardAutoRepeatOn();
161 SetDrawDeactivationMask(REDRAW_NONE);
162 SetDrawBackgroundMask(REDRAW_FIELD);
164 audio.sound_deactivated = FALSE;
166 /* needed if last screen was the playing screen, invoked from level editor */
167 if (level_editor_test_game)
169 game_status = LEVELED;
174 /* needed if last screen was the editor screen */
175 UndrawSpecialEditorDoor();
177 /* needed if last screen was the setup screen and fullscreen state changed */
178 ToggleFullscreenIfNeeded();
180 /* needed if last screen (level choice) changed graphics, sounds or music */
181 ReloadCustomArtwork();
184 SetDrawtoField(DRAW_BACKBUFFER);
187 /* map gadgets for main menu screen */
190 /* leveldir_current may be invalid (level group, parent link) */
191 if (!validLevelSeries(leveldir_current))
192 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
194 /* store valid level series information */
195 leveldir_last_valid = leveldir_current;
197 /* level_nr may have been set to value over handicap with level editor */
198 if (setup.handicap && level_nr > leveldir_current->handicap_level)
199 level_nr = leveldir_current->handicap_level;
204 SetMainBackgroundBitmap(new_graphic_info[IMG_BACKGROUND_DEFAULT].bitmap);
209 DrawText(SX + 32, SY + 2*32, name_text, FS_BIG, FC_GREEN);
210 DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
211 DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
212 DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
213 (leveldir_current->readonly ? FC_RED : FC_YELLOW));
214 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
215 DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
216 DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
217 DrawText(SX + 32, SY + 7*32, "Start Game", FS_BIG, FC_GREEN);
218 DrawText(SX + 32, SY + 8*32, "Setup", FS_BIG, FC_GREEN);
219 DrawText(SX + 32, SY + 9*32, "Quit", FS_BIG, FC_GREEN);
221 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
223 DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
224 leveldir_current->first_level,
225 leveldir_current->last_level);
227 if (leveldir_current->readonly)
229 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
230 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
234 initCursor(i, (i == 1 || i == 6 ? IMG_ARROW_BLUE_RIGHT : IMG_BALL_BLUE));
237 DrawGraphic(10, 3, IMG_ARROW_BLUE_LEFT, 0);
238 DrawGraphic(14, 3, IMG_ARROW_BLUE_RIGHT, 0);
240 drawCursorXY(10, 1, IMG_ARROW_BLUE_LEFT);
241 drawCursorXY(14, 1, IMG_ARROW_BLUE_RIGHT);
244 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
247 if (leveldir_current->name)
249 int len = strlen(leveldir_current->name);
250 int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
251 int lypos = SY + 352;
253 DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
258 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
261 if (TAPE_IS_EMPTY(tape))
263 DrawCompleteVideoDisplay();
265 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
272 static void gotoTopLevelDir()
274 /* move upwards to top level directory */
275 while (leveldir_current->node_parent)
277 /* write a "path" into level tree for easy navigation to last level */
278 if (leveldir_current->node_parent->node_group->cl_first == -1)
280 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
281 int leveldir_pos = posTreeInfo(leveldir_current);
282 int num_page_entries;
283 int cl_first, cl_cursor;
285 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
286 num_page_entries = num_leveldirs;
288 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
290 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
291 cl_cursor = leveldir_pos - cl_first;
293 leveldir_current->node_parent->node_group->cl_first = cl_first;
294 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
297 leveldir_current = leveldir_current->node_parent;
301 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
303 static int choice = 0;
307 if (button == MB_MENU_INITIALIZE)
309 drawCursor(choice, FC_RED);
313 if (mx || my) /* mouse input */
316 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
318 else if (dx || dy) /* keyboard input */
320 if (dx && choice == 1)
321 x = (dx < 0 ? 10 : 14);
326 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
327 (x == 14 && level_nr < leveldir_current->last_level)) &&
330 static unsigned long level_delay = 0;
331 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
332 int new_level_nr, old_level_nr = level_nr;
333 int font_color = (leveldir_current->readonly ? FC_RED : FC_YELLOW);
335 new_level_nr = level_nr + (x == 10 ? -step : +step);
336 if (new_level_nr < leveldir_current->first_level)
337 new_level_nr = leveldir_current->first_level;
338 if (new_level_nr > leveldir_current->last_level)
339 new_level_nr = leveldir_current->last_level;
341 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
342 new_level_nr = leveldir_current->handicap_level;
344 if (old_level_nr == new_level_nr ||
345 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
348 level_nr = new_level_nr;
350 DrawText(SX + 11 * 32, SY + 3 * 32, int2str(level_nr, 3),
354 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
358 DrawCompleteVideoDisplay();
360 /* needed because DrawMicroLevel() takes some time */
363 DelayReached(&level_delay, 0); /* reset delay counter */
365 else if (x == 0 && y >= 0 && y <= 7)
371 drawCursor(y, FC_RED);
372 drawCursor(choice, FC_BLUE);
380 game_status = TYPENAME;
381 HandleTypeName(strlen(setup.player_name), 0);
387 game_status = CHOOSELEVEL;
388 SaveLevelSetup_LastSeries();
389 SaveLevelSetup_SeriesInfo();
398 game_status = HALLOFFAME;
403 if (leveldir_current->readonly &&
404 strcmp(setup.player_name, "Artsoft") != 0)
405 Request("This level is read only !", REQ_CONFIRM);
406 game_status = LEVELED;
411 game_status = HELPSCREEN;
416 if (setup.autorecord)
417 TapeStartRecording();
419 #if defined(PLATFORM_UNIX)
421 SendToServer_StartPlaying();
425 game_status = PLAYING;
433 setup_mode = SETUP_MODE_MAIN;
438 SaveLevelSetup_LastSeries();
439 SaveLevelSetup_SeriesInfo();
440 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
441 game_status = EXITGAME;
450 if (game_status == MAINMENU)
452 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
458 #define MAX_HELPSCREEN_ELS 10
462 static long helpscreen_state;
463 static int helpscreen_step[MAX_HELPSCREEN_ELS];
464 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
466 static int OLD_helpscreen_action[] =
468 GFX_SPIELER1_DOWN,4,2,
470 GFX_SPIELER1_LEFT,4,2,
471 GFX_SPIELER1_RIGHT,4,2,
472 GFX_SPIELER1_PUSH_LEFT,4,2,
473 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
474 GFX_ERDREICH,1,100, HA_NEXT,
475 GFX_LEERRAUM,1,100, HA_NEXT,
476 GFX_MORAST_LEER,1,100, HA_NEXT,
477 GFX_BETON,1,100, HA_NEXT,
478 GFX_MAUERWERK,1,100, HA_NEXT,
479 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
480 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
481 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
482 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
483 GFX_UNSICHTBAR,1,100, HA_NEXT,
484 GFX_FELSBODEN,1,100, HA_NEXT,
485 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
486 GFX_EDELSTEIN,2,5, HA_NEXT,
487 GFX_DIAMANT,2,5, HA_NEXT,
488 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
489 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
490 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
491 GFX_FELSBROCKEN,4,5, HA_NEXT,
492 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
493 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
494 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
495 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
496 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
497 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
498 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
499 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
500 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
501 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
502 GFX_GEBLUBBER,4,4, HA_NEXT,
503 GFX_SCHLUESSEL1,4,25, HA_NEXT,
504 GFX_PFORTE1,4,25, HA_NEXT,
505 GFX_PFORTE1X,4,25, HA_NEXT,
506 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
507 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
508 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
509 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
510 GFX_LEERRAUM,1,10, HA_NEXT,
511 GFX_DYNABOMB_NR,1,100, HA_NEXT,
512 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
513 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
514 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
515 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
516 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
517 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
518 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
519 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
520 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
521 GFX_BUTTERFLY,2,2, HA_NEXT,
522 GFX_FIREFLY,2,2, HA_NEXT,
523 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
524 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
525 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
526 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
527 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
528 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
529 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
530 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
531 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
532 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
536 GFX_MOLE_RIGHT,4,2, HA_NEXT,
537 GFX_PINGUIN_DOWN,4,2,
539 GFX_PINGUIN_LEFT,4,2,
540 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
541 GFX_SCHWEIN_DOWN,4,2,
543 GFX_SCHWEIN_LEFT,4,2,
544 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
548 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
549 GFX_SONDE_START,8,1, HA_NEXT,
550 GFX_ABLENK,4,1, HA_NEXT,
551 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
552 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
553 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
554 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
555 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
556 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
557 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
558 GFX_DIAMANT,1,10, HA_NEXT,
559 GFX_LIFE,1,100, HA_NEXT,
560 GFX_LIFE_ASYNC,1,100, HA_NEXT,
561 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
562 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
563 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
564 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
565 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
566 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
567 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
568 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
569 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
570 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
571 GFX_SPEED_PILL,1,100, HA_NEXT,
576 static int helpscreen_action[] =
578 IMG_PLAYER1_DOWN_MOVING, 16,
579 IMG_PLAYER1_UP_MOVING, 16,
580 IMG_PLAYER1_LEFT_MOVING, 16,
581 IMG_PLAYER1_RIGHT_MOVING, 16,
582 IMG_PLAYER1_LEFT_PUSHING, 16,
583 IMG_PLAYER1_RIGHT_PUSHING, 16, HA_NEXT,
585 IMG_SAND, -1, HA_NEXT,
587 IMG_EMPTY_SPACE, -1, HA_NEXT,
589 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
591 IMG_STEELWALL, -1, HA_NEXT,
593 IMG_WALL, -1, HA_NEXT,
595 IMG_WALL_GROWING_ACTIVE_LEFT, 20,
598 IMG_WALL_GROWING_ACTIVE_RIGHT, 20,
601 IMG_WALL_GROWING_ACTIVE_UP, 20,
604 IMG_WALL_GROWING_ACTIVE_DOWN, 20,
606 IMG_EMPTY_SPACE, 20, HA_NEXT,
608 IMG_INVISIBLE_WALL, -1, HA_NEXT,
610 IMG_WALL_CRUMBLED, -1, HA_NEXT,
612 IMG_INFO_FONT_EM_1, 160,
613 IMG_INFO_FONT_EM_2, 160,
614 IMG_INFO_FONT_EM_3, 160,
615 IMG_INFO_FONT_EM_4, 160,
616 IMG_INFO_FONT_EM_5, 40, HA_NEXT,
618 IMG_EMERALD, -1, HA_NEXT,
620 IMG_DIAMOND, -1, HA_NEXT,
622 IMG_BD_DIAMOND, -1, HA_NEXT,
624 IMG_EMERALD_YELLOW, 50,
626 IMG_EMERALD_PURPLE, 50, HA_NEXT,
628 IMG_BD_ROCK, -1, HA_NEXT,
632 IMG_EMPTY_SPACE, 10, HA_NEXT,
636 IMG_EMERALD, 20, HA_NEXT,
638 IMG_WALL_EMERALD, 100,
640 IMG_EMERALD, 20, HA_NEXT,
642 IMG_WALL_DIAMOND, 100,
644 IMG_DIAMOND, 20, HA_NEXT,
646 IMG_WALL_BD_DIAMOND, 100,
648 IMG_BD_DIAMOND, 20, HA_NEXT,
650 IMG_WALL_EMERALD_YELLOW, 100,
652 IMG_EMERALD_YELLOW, 20,
653 IMG_WALL_EMERALD_RED, 100,
656 IMG_WALL_EMERALD_PURPLE, 100,
658 IMG_EMERALD_PURPLE, 20, HA_NEXT,
660 IMG_ACID, -1, HA_NEXT,
665 IMG_KEY4, 50, HA_NEXT,
670 IMG_GATE4, 50, HA_NEXT,
675 IMG_GATE4_GRAY, 50, HA_NEXT,
677 IMG_DYNAMITE, -1, HA_NEXT,
679 IMG_DYNAMITE_ACTIVE, 96,
681 IMG_EMPTY_SPACE, 20, HA_NEXT,
683 IMG_DYNABOMB_ACTIVE, 100,
685 IMG_EMPTY_SPACE, 20, HA_NEXT,
687 IMG_DYNABOMB_NR, -1, HA_NEXT,
689 IMG_DYNABOMB_SZ, -1, HA_NEXT,
691 IMG_SPACESHIP_RIGHT, 16,
692 IMG_SPACESHIP_UP, 16,
693 IMG_SPACESHIP_LEFT, 16,
694 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
699 IMG_BUG_DOWN, 16, HA_NEXT,
701 IMG_BD_BUTTERFLY, -1, HA_NEXT,
703 IMG_BD_FIREFLY, -1, HA_NEXT,
705 IMG_PACMAN_RIGHT, 16,
708 IMG_PACMAN_DOWN, 16, HA_NEXT,
710 IMG_YAMYAM, -1, HA_NEXT,
712 IMG_DARK_YAMYAM, -1, HA_NEXT,
714 IMG_ROBOT, -1, HA_NEXT,
716 IMG_MOLE_RIGHT_MOVING, 16,
717 IMG_MOLE_UP_MOVING, 16,
718 IMG_MOLE_LEFT_MOVING, 16,
719 IMG_MOLE_DOWN_MOVING, 16, HA_NEXT,
721 IMG_PENGUIN_RIGHT_MOVING, 16,
722 IMG_PENGUIN_UP_MOVING, 16,
723 IMG_PENGUIN_LEFT_MOVING, 16,
724 IMG_PENGUIN_DOWN_MOVING, 16, HA_NEXT,
726 IMG_PIG_RIGHT_MOVING, 16,
727 IMG_PIG_UP_MOVING, 16,
728 IMG_PIG_LEFT_MOVING, 16,
729 IMG_PIG_DOWN_MOVING, 16, HA_NEXT,
731 IMG_DRAGON_RIGHT_MOVING, 16,
732 IMG_DRAGON_UP_MOVING, 16,
733 IMG_DRAGON_LEFT_MOVING, 16,
734 IMG_DRAGON_DOWN_MOVING, 16, HA_NEXT,
736 IMG_SATELLITE, -1, HA_NEXT,
739 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
742 IMG_LAMP_ACTIVE, 50, HA_NEXT,
744 IMG_TIME_ORB_FULL, 50,
745 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
748 IMG_AMOEBA_CREATING, 6,
749 IMG_AMOEBA_WET, 20, HA_NEXT,
751 IMG_AMOEBA_DEAD, -1, HA_NEXT,
753 IMG_AMOEBA_WET, -1, HA_NEXT,
756 IMG_AMOEBA_CREATING, 6, HA_NEXT,
761 IMG_DIAMOND, 20, HA_NEXT,
763 IMG_GAMEOFLIFE, -1, HA_NEXT,
765 IMG_BIOMAZE, -1, HA_NEXT,
767 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
769 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
771 IMG_EXIT_CLOSED, 200,
772 IMG_EXIT_OPENING, 16,
773 IMG_EXIT_OPEN, 100, HA_NEXT,
775 IMG_EXIT_OPEN, -1, HA_NEXT,
777 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
779 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
781 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
783 IMG_SPEED_PILL, -1, HA_NEXT,
787 static char *helpscreen_eltext[][2] =
789 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
790 {"Normal sand:", "You can dig through it"},
791 {"Empty field:", "You can walk through it"},
792 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
793 {"Massive Wall:", "Nothing can go through it"},
794 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
795 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
796 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
797 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
798 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
799 {"Emerald: You must collect enough of","them to finish a level"},
800 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
801 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
802 {"Colorful Gems:", "Seem to behave like Emeralds"},
803 {"Rock: Smashes several things;", "Can be moved by the player"},
804 {"Bomb: You can move it, but be", "careful when dropping it"},
805 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
806 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
807 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
808 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
809 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
810 {"Acid: Things that fall in are gone", "forever (including our hero)"},
811 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
812 {"Door: Can be opened by the key", "with the same color"},
813 {"Door: You have to find out the", "right color of the key for it"},
814 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
815 {"Dynamite: This one explodes after", "a few seconds"},
816 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
817 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
818 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
819 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
820 {"Bug: Moves at the right side", "of walls; don't touch it!"},
821 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
822 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
823 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
824 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
825 {"Cruncher (BD style):", "Eats almost everything"},
826 {"Robot: Tries to kill the player", ""},
827 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
828 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
829 {"The Pig: Harmless, but eats all", "gems it can get"},
830 {"The Dragon: Breathes fire,", "especially to some monsters"},
831 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
832 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
833 {"Light Bulb: All of them must be", "switched on to finish a level"},
834 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
835 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
836 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
837 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
838 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
839 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
840 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
841 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
842 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
843 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
844 {"Exit door: Opens if you have enough","emeralds to finish the level"},
845 {"Open exit door: Enter here to leave","the level and exit the actual game"},
846 {"Sokoban element: Object which must", "be pushed to an empty field"},
847 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
848 {"Sokoban element: Field with object", "which can be pushed away"},
849 {"Speed pill: Lets the player run", "twice as fast as normally"},
851 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
853 static char *helpscreen_music[][3] =
855 { "Alchemy", "Ian Boddy", "Drive" },
856 { "The Chase", "Propaganda", "A Secret Wish" },
857 { "Network 23", "Tangerine Dream", "Exit" },
858 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
859 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
860 { "Voyager", "The Alan Parsons Project","Pyramid" },
861 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
863 static int num_helpscreen_music = 7;
864 static int helpscreen_musicpos;
867 void OLD_DrawHelpScreenElAction(int start)
871 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
873 while(helpscreen_action[j] != HA_END)
875 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
877 else if (i<start || helpscreen_delay[i-start])
879 if (i>=start && helpscreen_delay[i-start])
880 helpscreen_delay[i-start]--;
882 while(helpscreen_action[j] != HA_NEXT)
889 j += 3*helpscreen_step[i-start];
890 graphic = helpscreen_action[j++];
892 if (helpscreen_frame[i-start])
894 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
895 helpscreen_frame[i-start]--;
900 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
903 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
905 if (helpscreen_action[j] == HA_NEXT)
907 if (!helpscreen_frame[i-start])
908 helpscreen_step[i-start] = 0;
912 if (!helpscreen_frame[i-start])
913 helpscreen_step[i-start]++;
914 while(helpscreen_action[j] != HA_NEXT)
919 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
931 void DrawHelpScreenElAction(int start)
934 int xstart = SX + 16;
935 int ystart = SY + 64 + 2 * 32;
936 int ystep = TILEY + 4;
942 while (helpscreen_action[j] != HA_END)
944 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
948 while (helpscreen_action[j] != HA_NEXT)
957 j += 2 * helpscreen_step[i-start];
958 graphic = helpscreen_action[j++];
959 frame_count = helpscreen_action[j++];
960 if (frame_count == -1)
961 frame_count = 1000000;
963 if (helpscreen_frame[i-start] == 0)
966 helpscreen_frame[i-start] = frame_count - 1;
970 sync_frame = frame_count - helpscreen_frame[i-start];
971 helpscreen_frame[i-start]--;
974 if (helpscreen_action[j] == HA_NEXT)
976 if (!helpscreen_frame[i-start])
977 helpscreen_step[i-start] = 0;
981 if (!helpscreen_frame[i-start])
982 helpscreen_step[i-start]++;
983 while(helpscreen_action[j] != HA_NEXT)
988 frame = getGraphicAnimationFrame(graphic, sync_frame);
990 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
1005 void DrawHelpScreenElText(int start)
1008 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
1009 int ybottom = SYSIZE - 20;
1014 DrawTextFCentered(100, FC_GREEN, "The game elements:");
1016 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1019 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1020 helpscreen_eltext[i][0], FS_SMALL, FC_YELLOW);
1021 DrawText(xstart, ystart + (i - start) * ystep + 16,
1022 helpscreen_eltext[i][1], FS_SMALL, FC_YELLOW);
1025 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1028 void DrawHelpScreenMusicText(int num)
1030 int ystart = 150, ystep = 30;
1031 int ybottom = SYSIZE - 20;
1037 DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
1039 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1041 DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
1042 helpscreen_music[num][0]);
1043 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
1045 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
1046 "%s", helpscreen_music[num][1]);
1047 DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
1049 DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
1050 helpscreen_music[num][2]);
1052 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1055 PlaySoundLoop(background_loop[num]);
1059 void DrawHelpScreenCreditsText()
1061 int ystart = 150, ystep = 30;
1062 int ybottom = SYSIZE - 20;
1068 DrawTextFCentered(100, FC_GREEN,
1070 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1071 "DOS port of the game:");
1072 DrawTextFCentered(ystart + 1 * ystep, FC_RED,
1074 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
1075 "Additional toons:");
1076 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
1078 DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
1079 "...and many thanks to all contributors");
1080 DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
1083 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1086 void DrawHelpScreenContactText()
1088 int ystart = 150, ystep = 30;
1089 int ybottom = SYSIZE - 20;
1094 DrawTextFCentered(100, FC_GREEN, "Program information:");
1096 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1097 "This game is Freeware!");
1098 DrawTextFCentered(ystart + 1 * ystep, FC_YELLOW,
1099 "If you like it, send e-mail to:");
1100 DrawTextFCentered(ystart + 2 * ystep, FC_RED,
1101 "info@artsoft.org");
1102 DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
1103 "or SnailMail to:");
1104 DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
1106 DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
1107 "Detmolder Strasse 189");
1108 DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
1110 DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
1113 DrawTextFCentered(ystart + 7 * ystep, FC_YELLOW,
1114 "If you have created new levels,");
1115 DrawTextFCentered(ystart + 8 * ystep, FC_YELLOW,
1116 "send them to me to include them!");
1117 DrawTextFCentered(ystart + 9 * ystep, FC_YELLOW,
1120 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
1123 void DrawHelpScreen()
1128 CloseDoor(DOOR_CLOSE_2);
1130 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1131 helpscreen_step[i] = helpscreen_frame[i] = 0;
1132 helpscreen_musicpos = 0;
1133 helpscreen_state = 0;
1134 DrawHelpScreenElText(0);
1135 DrawHelpScreenElAction(0);
1139 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1142 void HandleHelpScreen(int button)
1144 static unsigned long hs_delay = 0;
1145 int num_helpscreen_els_pages =
1146 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1147 int button_released = !button;
1150 if (button_released)
1152 if (helpscreen_state < num_helpscreen_els_pages - 1)
1154 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1155 helpscreen_step[i] = helpscreen_frame[i] = 0;
1159 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1160 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1162 else if (helpscreen_state <
1163 num_helpscreen_els_pages + num_helpscreen_music - 1)
1166 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1168 else if (helpscreen_state ==
1169 num_helpscreen_els_pages + num_helpscreen_music - 1)
1172 DrawHelpScreenCreditsText();
1174 else if (helpscreen_state ==
1175 num_helpscreen_els_pages + num_helpscreen_music)
1178 DrawHelpScreenContactText();
1184 game_status = MAINMENU;
1189 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1191 if (helpscreen_state < num_helpscreen_els_pages)
1192 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1195 /* !!! workaround for playing "music" that is really a sound loop (and
1196 must therefore periodically be reactivated with the current sound
1198 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1206 void HandleTypeName(int newxpos, Key key)
1208 static int xpos = 0, ypos = 2;
1213 DrawText(SX + 6 * 32, SY + ypos * 32, setup.player_name,
1215 drawCursorXY(xpos + 6, ypos - 2, IMG_BALL_RED);
1220 if (((key >= KSYM_A && key <= KSYM_Z) ||
1221 (key >= KSYM_a && key <= KSYM_z)) &&
1222 xpos < MAX_PLAYER_NAME_LEN)
1226 if (key >= KSYM_A && key <= KSYM_Z)
1227 ascii = 'A' + (char)(key - KSYM_A);
1229 ascii = 'a' + (char)(key - KSYM_a);
1231 setup.player_name[xpos] = ascii;
1232 setup.player_name[xpos + 1] = 0;
1235 DrawText(SX + 6 * 32, SY + ypos * 32, setup.player_name,
1237 drawCursorXY(xpos + 6, ypos - 2, IMG_BALL_RED);
1239 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1242 setup.player_name[xpos] = 0;
1244 DrawBackground(SX + (xpos + 6) * 32, SY + ypos * 32, 2 * TILEX, TILEY);
1245 drawCursorXY(xpos + 6, ypos - 2, IMG_BALL_RED);
1247 else if (key == KSYM_Return && xpos > 0)
1249 DrawText(SX + 6 * 32, SY + ypos * 32, setup.player_name, FS_BIG, FC_RED);
1250 DrawBackground(SX + (xpos + 6) * 32, SY + ypos * 32, TILEX, TILEY);
1253 game_status = MAINMENU;
1259 static void DrawChooseTree(TreeInfo **ti_ptr)
1262 CloseDoor(DOOR_CLOSE_2);
1265 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1266 MapChooseTreeGadgets(*ti_ptr);
1272 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1274 struct GadgetInfo *gi = screen_gadget[id];
1275 int items_max, items_visible, item_position;
1277 items_max = numTreeInfoInGroup(ti);
1278 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1279 item_position = first_entry;
1281 if (item_position > items_max - items_visible)
1282 item_position = items_max - items_visible;
1284 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1285 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1288 static void drawChooseTreeList(int first_entry, int num_page_entries,
1292 char buffer[SCR_FIELDX * 2];
1293 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1294 int num_entries = numTreeInfoInGroup(ti);
1295 char *title_string = NULL;
1296 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1298 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1299 redraw_mask |= REDRAW_FIELD;
1302 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1303 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1304 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1305 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1307 DrawText(SX + offset, SY + offset, title_string, FS_BIG,
1308 (ti->type == TREE_TYPE_LEVEL_DIR ? FC_GREEN : FC_YELLOW));
1310 for(i=0; i<num_page_entries; i++)
1312 TreeInfo *node, *node_first;
1313 int entry_pos = first_entry + i;
1314 int ypos = MENU_SCREEN_START_YPOS + i;
1316 node_first = getTreeInfoFirstGroupEntry(ti);
1317 node = getTreeInfoFromPos(node_first, entry_pos);
1319 strncpy(buffer, node->name , max_buffer_len);
1320 buffer[max_buffer_len] = '\0';
1322 DrawText(SX + 32, SY + ypos * 32, buffer, FS_MEDIUM, node->color);
1324 if (node->parent_link)
1325 initCursor(i, IMG_ARROW_BLUE_LEFT);
1326 else if (node->level_group)
1327 initCursor(i, IMG_ARROW_BLUE_RIGHT);
1329 initCursor(i, IMG_BALL_BLUE);
1332 if (first_entry > 0)
1336 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1337 DrawGraphicThruMask(0, ypos, IMG_ARROW_BLUE_UP, 0);
1340 if (first_entry + num_page_entries < num_entries)
1342 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1344 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1345 DrawGraphicThruMask(0, ypos, IMG_ARROW_BLUE_DOWN, 0);
1349 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1351 TreeInfo *node, *node_first;
1352 int x, last_redraw_mask = redraw_mask;
1354 if (ti->type != TREE_TYPE_LEVEL_DIR)
1357 node_first = getTreeInfoFirstGroupEntry(ti);
1358 node = getTreeInfoFromPos(node_first, entry_pos);
1360 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1362 if (node->parent_link)
1363 DrawTextFCentered(40, FC_RED, "leave group \"%s\"", node->class_desc);
1364 else if (node->level_group)
1365 DrawTextFCentered(40, FC_RED, "enter group \"%s\"", node->class_desc);
1366 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1367 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
1368 node->levels, node->class_desc);
1370 /* let BackToFront() redraw only what is needed */
1371 redraw_mask = last_redraw_mask | REDRAW_TILES;
1372 for (x=0; x<SCR_FIELDX; x++)
1373 MarkTileDirty(x, 1);
1376 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1379 static unsigned long choose_delay = 0;
1380 TreeInfo *ti = *ti_ptr;
1382 int y = ti->cl_cursor;
1383 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1384 int num_entries = numTreeInfoInGroup(ti);
1385 int num_page_entries;
1387 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1388 num_page_entries = num_entries;
1390 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1392 if (button == MB_MENU_INITIALIZE)
1394 int entry_pos = posTreeInfo(ti);
1396 if (ti->cl_first == -1)
1398 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1400 entry_pos - ti->cl_first;
1403 if (dx == 999) /* first entry is set by scrollbar position */
1406 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1409 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1410 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1411 drawCursor(ti->cl_cursor, FC_RED);
1414 else if (button == MB_MENU_LEAVE)
1416 if (ti->node_parent)
1418 *ti_ptr = ti->node_parent;
1419 DrawChooseTree(ti_ptr);
1421 else if (game_status == SETUP)
1427 game_status = MAINMENU;
1434 if (mx || my) /* mouse input */
1437 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1439 else if (dx || dy) /* keyboard input */
1442 y = ti->cl_cursor + dy;
1444 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1447 step = num_page_entries - 1;
1448 y = (dy < 0 ? -1 : num_page_entries);
1452 if (x == 0 && y == -1)
1454 if (ti->cl_first > 0 &&
1455 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1457 ti->cl_first -= step;
1458 if (ti->cl_first < 0)
1461 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1462 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1463 drawCursor(ti->cl_cursor, FC_RED);
1464 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1469 else if (x == 0 && y > num_page_entries - 1)
1471 if (ti->cl_first + num_page_entries < num_entries &&
1472 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1474 ti->cl_first += step;
1475 if (ti->cl_first + num_page_entries > num_entries)
1476 ti->cl_first = MAX(0, num_entries - num_page_entries);
1478 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1479 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1480 drawCursor(ti->cl_cursor, FC_RED);
1481 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1489 TreeInfo *node_first, *node_cursor;
1490 int entry_pos = ti->cl_first + y;
1492 node_first = getTreeInfoFirstGroupEntry(ti);
1493 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1495 if (node_cursor->node_group)
1497 node_cursor->cl_first = ti->cl_first;
1498 node_cursor->cl_cursor = ti->cl_cursor;
1499 *ti_ptr = node_cursor->node_group;
1500 DrawChooseTree(ti_ptr);
1504 else if (dx == -1 && ti->node_parent)
1506 *ti_ptr = ti->node_parent;
1507 DrawChooseTree(ti_ptr);
1511 if (x == 0 && y >= 0 && y < num_page_entries)
1515 if (y != ti->cl_cursor)
1517 drawCursor(y, FC_RED);
1518 drawCursor(ti->cl_cursor, FC_BLUE);
1519 drawChooseTreeInfo(ti->cl_first + y, ti);
1525 TreeInfo *node_first, *node_cursor;
1526 int entry_pos = ti->cl_first + y;
1528 node_first = getTreeInfoFirstGroupEntry(ti);
1529 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1531 if (node_cursor->node_group)
1533 node_cursor->cl_first = ti->cl_first;
1534 node_cursor->cl_cursor = ti->cl_cursor;
1535 *ti_ptr = node_cursor->node_group;
1536 DrawChooseTree(ti_ptr);
1538 else if (node_cursor->parent_link)
1540 *ti_ptr = node_cursor->node_parent;
1541 DrawChooseTree(ti_ptr);
1545 node_cursor->cl_first = ti->cl_first;
1546 node_cursor->cl_cursor = ti->cl_cursor;
1547 *ti_ptr = node_cursor;
1549 if (ti->type == TREE_TYPE_LEVEL_DIR)
1551 LoadLevelSetup_SeriesInfo();
1553 SaveLevelSetup_LastSeries();
1554 SaveLevelSetup_SeriesInfo();
1558 if (game_status == SETUP)
1564 game_status = MAINMENU;
1573 if (game_status == CHOOSELEVEL || game_status == SETUP)
1577 void DrawChooseLevel()
1579 DrawChooseTree(&leveldir_current);
1582 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1584 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1587 void DrawHallOfFame(int highlight_position)
1591 CloseDoor(DOOR_CLOSE_2);
1593 if (highlight_position < 0)
1594 LoadScore(level_nr);
1598 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1599 PlaySound(SND_MENU_HALL_OF_FAME);
1602 static void drawHallOfFameList(int first_entry, int highlight_position)
1607 DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1608 DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1610 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1612 int entry = first_entry + i;
1613 int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1616 DrawText(SX, SY + 64 + i * 32, ".................", FS_BIG, color);
1617 DrawText(SX, SY + 64 + i * 32, highscore[i].Name, FS_BIG, color);
1618 DrawText(SX + 12 * 32, SY + 64 + i * 32,
1619 int2str(highscore[i].Score, 5), FS_BIG, color);
1621 DrawText(SX, SY + 64 + i * 32, "..................................",
1622 FS_MEDIUM, FC_YELLOW);
1623 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1624 FS_MEDIUM, FC_YELLOW);
1625 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name, FS_BIG, color);
1626 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1627 int2str(highscore[entry].Score, 5), FS_MEDIUM, color);
1632 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1634 static int first_entry = 0;
1635 static int highlight_position = 0;
1636 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1637 int button_released = !button;
1639 if (button == MB_MENU_INITIALIZE)
1642 highlight_position = mx;
1643 drawHallOfFameList(first_entry, highlight_position);
1647 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1648 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1652 if (first_entry > 0)
1654 first_entry -= step;
1655 if (first_entry < 0)
1658 drawHallOfFameList(first_entry, highlight_position);
1664 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1666 first_entry += step;
1667 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1668 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1670 drawHallOfFameList(first_entry, highlight_position);
1675 if (button_released)
1677 FadeSound(SND_MENU_HALL_OF_FAME);
1678 game_status = MAINMENU;
1684 if (game_status == HALLOFFAME)
1689 /* ========================================================================= */
1690 /* setup screen functions */
1691 /* ========================================================================= */
1693 static struct TokenInfo *setup_info;
1694 static int num_setup_info;
1696 static char *graphics_set_name;
1697 static char *sounds_set_name;
1698 static char *music_set_name;
1700 static void execSetupMain()
1702 setup_mode = SETUP_MODE_MAIN;
1706 static void execSetupGame()
1708 setup_mode = SETUP_MODE_GAME;
1712 static void execSetupEditor()
1714 setup_mode = SETUP_MODE_EDITOR;
1718 static void execSetupGraphics()
1720 setup_mode = SETUP_MODE_GRAPHICS;
1724 static void execSetupSound()
1726 setup_mode = SETUP_MODE_SOUND;
1730 static void execSetupArtwork()
1732 /* needed if last screen (setup choice) changed graphics, sounds or music */
1733 ReloadCustomArtwork();
1735 setup.graphics_set = artwork.gfx_current->identifier;
1736 setup.sounds_set = artwork.snd_current->identifier;
1737 setup.music_set = artwork.mus_current->identifier;
1739 /* needed for displaying artwork name instead of artwork identifier */
1740 graphics_set_name = artwork.gfx_current->name;
1741 sounds_set_name = artwork.snd_current->name;
1742 music_set_name = artwork.mus_current->name;
1744 setup_mode = SETUP_MODE_ARTWORK;
1748 static void execSetupChooseGraphics()
1750 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1754 static void execSetupChooseSounds()
1756 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1760 static void execSetupChooseMusic()
1762 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1766 static void execSetupInput()
1768 setup_mode = SETUP_MODE_INPUT;
1772 static void execSetupShortcut()
1774 setup_mode = SETUP_MODE_SHORTCUT;
1778 static void execExitSetup()
1780 game_status = MAINMENU;
1784 static void execSaveAndExitSetup()
1790 static struct TokenInfo setup_info_main[] =
1792 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1793 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1794 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1795 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1796 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1797 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1798 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1799 { TYPE_EMPTY, NULL, "" },
1800 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1801 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1805 static struct TokenInfo setup_info_game[] =
1807 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1808 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1809 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1810 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1811 { TYPE_EMPTY, NULL, "" },
1812 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1816 static struct TokenInfo setup_info_editor[] =
1818 { TYPE_STRING, NULL, "Offer Special Elements:"},
1819 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1820 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1821 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1822 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1823 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1824 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1825 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1826 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1827 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1828 { TYPE_EMPTY, NULL, "" },
1829 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1833 static struct TokenInfo setup_info_graphics[] =
1835 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1836 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1837 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1839 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1840 { TYPE_SWITCH, &setup.fading, "Fading:" },
1842 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1843 { TYPE_SWITCH, &setup.toons, "Toons:" },
1844 { TYPE_EMPTY, NULL, "" },
1845 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1849 static struct TokenInfo setup_info_sound[] =
1851 { TYPE_SWITCH, &setup.sound, "Sound:", },
1852 { TYPE_EMPTY, NULL, "" },
1853 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1854 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1855 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1856 { TYPE_EMPTY, NULL, "" },
1857 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1861 static struct TokenInfo setup_info_artwork[] =
1863 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1864 { TYPE_STRING, &graphics_set_name, "" },
1865 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1866 { TYPE_STRING, &sounds_set_name, "" },
1867 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1868 { TYPE_STRING, &music_set_name, "" },
1869 { TYPE_EMPTY, NULL, "" },
1870 { TYPE_STRING, NULL, "Override Level Artwork:"},
1871 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1872 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1873 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1874 { TYPE_EMPTY, NULL, "" },
1875 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1879 static struct TokenInfo setup_info_shortcut[] =
1881 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1882 { TYPE_KEY, &setup.shortcut.save_game, "" },
1883 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1884 { TYPE_KEY, &setup.shortcut.load_game, "" },
1885 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1886 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1887 { TYPE_EMPTY, NULL, "" },
1888 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1889 { TYPE_EMPTY, NULL, "" },
1890 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1894 static Key getSetupKey()
1896 Key key = KSYM_UNDEFINED;
1897 boolean got_key_event = FALSE;
1899 while (!got_key_event)
1901 if (PendingEvent()) /* got event */
1909 case EVENT_KEYPRESS:
1911 key = GetEventKey((KeyEvent *)&event, TRUE);
1913 /* press 'Escape' or 'Enter' to keep the existing key binding */
1914 if (key == KSYM_Escape || key == KSYM_Return)
1915 key = KSYM_UNDEFINED; /* keep old value */
1917 got_key_event = TRUE;
1921 case EVENT_KEYRELEASE:
1922 key_joystick_mapping = 0;
1926 HandleOtherEvents(&event);
1934 /* don't eat all CPU time */
1941 static void drawSetupValue(int pos)
1943 int xpos = MENU_SCREEN_VALUE_XPOS;
1944 int ypos = MENU_SCREEN_START_YPOS + pos;
1945 int font_size = FS_BIG;
1946 int font_color = FC_YELLOW;
1947 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1948 setup_info[pos].value);
1950 if (value_string == NULL)
1953 if (setup_info[pos].type & TYPE_KEY)
1957 if (setup_info[pos].type & TYPE_QUERY)
1959 value_string = "<press key>";
1960 font_color = FC_RED;
1963 else if (setup_info[pos].type & TYPE_STRING)
1965 int max_value_len = (SCR_FIELDX - 2) * 2;
1968 font_size = FS_MEDIUM;
1970 if (strlen(value_string) > max_value_len)
1971 value_string[max_value_len] = '\0';
1973 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
1974 !*(boolean *)(setup_info[pos].value))
1975 font_color = FC_BLUE;
1977 DrawText(SX + xpos * 32, SY + ypos * 32,
1978 (xpos == 3 ? " " : " "), FS_BIG, FC_YELLOW);
1979 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, font_size,font_color);
1982 static void changeSetupValue(int pos)
1984 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1986 *(boolean *)setup_info[pos].value ^= TRUE;
1988 else if (setup_info[pos].type & TYPE_KEY)
1992 setup_info[pos].type |= TYPE_QUERY;
1993 drawSetupValue(pos);
1994 setup_info[pos].type &= ~TYPE_QUERY;
1996 key = getSetupKey();
1997 if (key != KSYM_UNDEFINED)
1998 *(Key *)setup_info[pos].value = key;
2001 drawSetupValue(pos);
2004 static void DrawSetupScreen_Generic()
2006 char *title_string = NULL;
2010 CloseDoor(DOOR_CLOSE_2);
2013 if (setup_mode == SETUP_MODE_MAIN)
2015 setup_info = setup_info_main;
2016 title_string = "Setup";
2018 else if (setup_mode == SETUP_MODE_GAME)
2020 setup_info = setup_info_game;
2021 title_string = "Setup Game";
2023 else if (setup_mode == SETUP_MODE_EDITOR)
2025 setup_info = setup_info_editor;
2026 title_string = "Setup Editor";
2028 else if (setup_mode == SETUP_MODE_GRAPHICS)
2030 setup_info = setup_info_graphics;
2031 title_string = "Setup Graphics";
2033 else if (setup_mode == SETUP_MODE_SOUND)
2035 setup_info = setup_info_sound;
2036 title_string = "Setup Sound";
2038 else if (setup_mode == SETUP_MODE_ARTWORK)
2040 setup_info = setup_info_artwork;
2041 title_string = "Custom Artwork";
2043 else if (setup_mode == SETUP_MODE_SHORTCUT)
2045 setup_info = setup_info_shortcut;
2046 title_string = "Setup Shortcuts";
2049 DrawText(SX + 16, SY + 16, title_string, FS_BIG, FC_YELLOW);
2052 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2054 void *value_ptr = setup_info[i].value;
2055 int ypos = MENU_SCREEN_START_YPOS + i;
2056 int font_size = FS_BIG;
2058 /* set some entries to "unchangeable" according to other variables */
2059 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2060 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2061 (value_ptr == &setup.sound_music && !audio.music_available) ||
2062 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2063 setup_info[i].type |= TYPE_GHOSTED;
2065 if (setup_info[i].type & TYPE_STRING)
2066 font_size = FS_MEDIUM;
2068 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, font_size, FC_GREEN);
2070 if (setup_info[i].type & TYPE_ENTER_MENU)
2071 initCursor(i, IMG_ARROW_BLUE_RIGHT);
2072 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2073 initCursor(i, IMG_ARROW_BLUE_LEFT);
2074 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2075 initCursor(i, IMG_BALL_BLUE);
2077 if (setup_info[i].type & TYPE_VALUE)
2085 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2088 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2090 static int choice_store[MAX_SETUP_MODES];
2091 int choice = choice_store[setup_mode]; /* always starts with 0 */
2095 if (button == MB_MENU_INITIALIZE)
2097 /* advance to first valid menu entry */
2098 while (choice < num_setup_info &&
2099 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2101 choice_store[setup_mode] = choice;
2103 drawCursor(choice, FC_RED);
2106 else if (button == MB_MENU_LEAVE)
2108 for (y=0; y<num_setup_info; y++)
2110 if (setup_info[y].type & TYPE_LEAVE_MENU)
2112 void (*menu_callback_function)(void) = setup_info[y].value;
2114 menu_callback_function();
2115 break; /* absolutely needed because function changes 'setup_info'! */
2122 if (mx || my) /* mouse input */
2125 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2127 else if (dx || dy) /* keyboard input */
2131 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2133 if ((setup_info[choice].type & menu_navigation_type) ||
2134 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2135 button = MB_MENU_CHOICE;
2140 /* jump to next non-empty menu entry (up or down) */
2141 while (y > 0 && y < num_setup_info - 1 &&
2142 (setup_info[y].type & TYPE_SKIP_ENTRY))
2146 if (x == 0 && y >= 0 && y < num_setup_info &&
2147 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2153 drawCursor(y, FC_RED);
2154 drawCursor(choice, FC_BLUE);
2155 choice = choice_store[setup_mode] = y;
2158 else if (!(setup_info[y].type & TYPE_GHOSTED))
2160 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2162 void (*menu_callback_function)(void) = setup_info[choice].value;
2164 menu_callback_function();
2168 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2169 (setup_info[y + 1].type & TYPE_KEY))
2172 if (setup_info[y].type & TYPE_VALUE)
2173 changeSetupValue(y);
2180 if (game_status == SETUP)
2184 void DrawSetupScreen_Input()
2187 DrawText(SX+16, SY+16, "Setup Input", FS_BIG, FC_YELLOW);
2189 initCursor(0, IMG_BALL_BLUE);
2190 initCursor(1, IMG_BALL_BLUE);
2191 initCursor(2, IMG_ARROW_BLUE_RIGHT);
2192 initCursor(13, IMG_ARROW_BLUE_LEFT);
2194 drawCursorXY(10, 0, IMG_ARROW_BLUE_LEFT);
2195 drawCursorXY(12, 0, IMG_ARROW_BLUE_RIGHT);
2197 DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
2198 DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
2199 DrawText(SX+32, SY+15*32, "Back", FS_BIG, FC_GREEN);
2202 DeactivateJoystickForCalibration();
2203 DrawTextFCentered(SYSIZE - 20, FC_BLUE,
2204 "Joysticks deactivated on this screen");
2207 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2212 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2214 if (device_name == NULL)
2217 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2220 if (strlen(device_name) > 1)
2222 char c1 = device_name[strlen(device_name) - 1];
2223 char c2 = device_name[strlen(device_name) - 2];
2225 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2226 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2229 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2230 strlen(device_name));
2233 static void drawPlayerSetupInputInfo(int player_nr)
2236 static struct SetupKeyboardInfo custom_key;
2243 { &custom_key.left, "Joystick Left" },
2244 { &custom_key.right, "Joystick Right" },
2245 { &custom_key.up, "Joystick Up" },
2246 { &custom_key.down, "Joystick Down" },
2247 { &custom_key.snap, "Button 1" },
2248 { &custom_key.bomb, "Button 2" }
2250 static char *joystick_name[MAX_PLAYERS] =
2258 custom_key = setup.input[player_nr].key;
2260 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
2261 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER1, player_nr), 0);
2263 if (setup.input[player_nr].use_joystick)
2265 char *device_name = setup.input[player_nr].joy.device_name;
2267 DrawText(SX+8*32, SY+3*32,
2268 joystick_name[getJoystickNrFromDeviceName(device_name)],
2270 DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
2274 DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
2275 DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
2278 DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
2279 drawCursorXY(1, 4, IMG_ARROW_BLUE_LEFT);
2280 drawCursorXY(1, 5, IMG_ARROW_BLUE_RIGHT);
2281 drawCursorXY(1, 6, IMG_ARROW_BLUE_UP);
2282 drawCursorXY(1, 7, IMG_ARROW_BLUE_DOWN);
2283 DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
2284 DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
2285 DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
2286 DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
2287 DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
2288 DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
2292 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2294 DrawText(SX + 3*32, SY + ypos*32,
2295 " ", FS_BIG, FC_YELLOW);
2296 DrawText(SX + 3*32, SY + ypos*32,
2297 (setup.input[player_nr].use_joystick ?
2299 getKeyNameFromKey(*custom[i].key)),
2304 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2306 static int choice = 0;
2307 static int player_nr = 0;
2310 int pos_start = SETUPINPUT_SCREEN_POS_START;
2311 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2312 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2313 int pos_end = SETUPINPUT_SCREEN_POS_END;
2315 if (button == MB_MENU_INITIALIZE)
2317 drawPlayerSetupInputInfo(player_nr);
2318 drawCursor(choice, FC_RED);
2321 else if (button == MB_MENU_LEAVE)
2323 setup_mode = SETUP_MODE_MAIN;
2328 if (mx || my) /* mouse input */
2331 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2333 else if (dx || dy) /* keyboard input */
2335 if (dx && choice == 0)
2336 x = (dx < 0 ? 10 : 12);
2337 else if ((dx && choice == 1) ||
2338 (dx == +1 && choice == 2) ||
2339 (dx == -1 && choice == pos_end))
2340 button = MB_MENU_CHOICE;
2344 if (y >= pos_empty1 && y <= pos_empty2)
2345 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2348 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2350 static unsigned long delay = 0;
2352 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2355 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2357 drawPlayerSetupInputInfo(player_nr);
2359 else if (x == 0 && y >= pos_start && y <= pos_end &&
2360 !(y >= pos_empty1 && y <= pos_empty2))
2366 drawCursor(y, FC_RED);
2367 drawCursor(choice, FC_BLUE);
2375 char *device_name = setup.input[player_nr].joy.device_name;
2377 if (!setup.input[player_nr].use_joystick)
2379 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2381 setJoystickDeviceToNr(device_name, new_device_nr);
2382 setup.input[player_nr].use_joystick = TRUE;
2386 int device_nr = getJoystickNrFromDeviceName(device_name);
2387 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2389 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2390 setup.input[player_nr].use_joystick = FALSE;
2392 setJoystickDeviceToNr(device_name, new_device_nr);
2395 drawPlayerSetupInputInfo(player_nr);
2399 if (setup.input[player_nr].use_joystick)
2402 CalibrateJoystick(player_nr);
2405 CustomizeKeyboard(player_nr);
2407 else if (y == pos_end)
2411 setup_mode = SETUP_MODE_MAIN;
2421 if (game_status == SETUP)
2425 void CustomizeKeyboard(int player_nr)
2429 boolean finished = FALSE;
2430 static struct SetupKeyboardInfo custom_key;
2435 } customize_step[] =
2437 { &custom_key.left, "Move Left" },
2438 { &custom_key.right, "Move Right" },
2439 { &custom_key.up, "Move Up" },
2440 { &custom_key.down, "Move Down" },
2441 { &custom_key.snap, "Snap Field" },
2442 { &custom_key.bomb, "Place Bomb" }
2445 /* read existing key bindings from player setup */
2446 custom_key = setup.input[player_nr].key;
2449 DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
2455 DrawText(SX, SY + (2+2*step_nr)*32,
2456 customize_step[step_nr].text, FS_BIG, FC_RED);
2457 DrawText(SX, SY + (2+2*step_nr+1)*32,
2458 "Key:", FS_BIG, FC_RED);
2459 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2460 getKeyNameFromKey(*customize_step[step_nr].key),
2465 if (PendingEvent()) /* got event */
2473 case EVENT_KEYPRESS:
2475 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2477 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2483 /* all keys configured -- wait for "Escape" or "Return" key */
2487 /* press 'Enter' to keep the existing key binding */
2488 if (key == KSYM_Return)
2489 key = *customize_step[step_nr].key;
2491 /* check if key already used */
2492 for (i=0; i<step_nr; i++)
2493 if (*customize_step[i].key == key)
2498 /* got new key binding */
2499 *customize_step[step_nr].key = key;
2500 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2501 " ", FS_BIG, FC_YELLOW);
2502 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2503 getKeyNameFromKey(key), FS_BIG, FC_YELLOW);
2506 /* un-highlight last query */
2507 DrawText(SX, SY+(2+2*(step_nr-1))*32,
2508 customize_step[step_nr-1].text, FS_BIG, FC_GREEN);
2509 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
2510 "Key:", FS_BIG, FC_GREEN);
2512 /* press 'Enter' to leave */
2515 DrawText(SX + 16, SY + 15*32+16,
2516 "Press Enter", FS_BIG, FC_YELLOW);
2520 /* query next key binding */
2521 DrawText(SX, SY+(2+2*step_nr)*32,
2522 customize_step[step_nr].text, FS_BIG, FC_RED);
2523 DrawText(SX, SY+(2+2*step_nr+1)*32,
2524 "Key:", FS_BIG, FC_RED);
2525 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
2526 getKeyNameFromKey(*customize_step[step_nr].key),
2531 case EVENT_KEYRELEASE:
2532 key_joystick_mapping = 0;
2536 HandleOtherEvents(&event);
2544 /* don't eat all CPU time */
2548 /* write new key bindings back to player setup */
2549 setup.input[player_nr].key = custom_key;
2552 DrawSetupScreen_Input();
2555 static boolean CalibrateJoystickMain(int player_nr)
2557 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2558 int new_joystick_xright = JOYSTICK_XMIDDLE;
2559 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2560 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2561 int new_joystick_xmiddle, new_joystick_ymiddle;
2563 int joystick_fd = joystick.fd[player_nr];
2564 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2565 boolean check[3][3];
2566 int check_remaining = 3 * 3;
2571 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2574 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2583 check[x][y] = FALSE;
2584 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_BALL_BLUE, 0);
2588 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
2589 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
2590 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
2591 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
2592 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FS_BIG, FC_YELLOW);
2593 DrawText(SX, SY + 12 * 32, " AND ", FS_BIG, FC_YELLOW);
2594 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
2596 joy_value = Joystick(player_nr);
2597 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2598 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2600 /* eventually uncalibrated center position (joystick could be uncentered) */
2601 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2604 new_joystick_xmiddle = joy_x;
2605 new_joystick_ymiddle = joy_y;
2607 DrawGraphic(xpos + last_x, ypos + last_y, IMG_BALL_RED, 0);
2610 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2615 if (PendingEvent()) /* got event */
2623 case EVENT_KEYPRESS:
2624 switch(GetEventKey((KeyEvent *)&event, TRUE))
2627 if (check_remaining == 0)
2640 case EVENT_KEYRELEASE:
2641 key_joystick_mapping = 0;
2645 HandleOtherEvents(&event);
2650 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2653 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2654 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2655 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2656 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2658 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2659 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2660 setup.input[player_nr].joy.xright = new_joystick_xright;
2661 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2662 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2663 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2665 CheckJoystickData();
2667 joy_value = Joystick(player_nr);
2669 if (joy_value & JOY_BUTTON && check_remaining == 0)
2672 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2673 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2675 if (x != last_x || y != last_y)
2677 DrawGraphic(xpos + last_x, ypos + last_y, IMG_BALL_YELLOW, 0);
2678 DrawGraphic(xpos + x, ypos + y, IMG_BALL_RED, 0);
2683 if (check_remaining > 0 && !check[x+1][y+1])
2685 check[x+1][y+1] = TRUE;
2691 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2692 setup.input[player_nr].joy.xleft,
2693 setup.input[player_nr].joy.xmiddle,
2694 setup.input[player_nr].joy.xright);
2695 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2696 setup.input[player_nr].joy.yupper,
2697 setup.input[player_nr].joy.ymiddle,
2698 setup.input[player_nr].joy.ylower);
2707 /* don't eat all CPU time */
2711 /* calibrated center position (joystick should now be centered) */
2712 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2715 new_joystick_xmiddle = joy_x;
2716 new_joystick_ymiddle = joy_y;
2720 DrawSetupScreen_Input();
2722 /* wait until the last pressed button was released */
2723 while (Joystick(player_nr) & JOY_BUTTON)
2725 if (PendingEvent()) /* got event */
2730 HandleOtherEvents(&event);
2739 void CalibrateJoystick(int player_nr)
2741 if (!CalibrateJoystickMain(player_nr))
2745 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
2746 DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
2748 Delay(2000); /* show error message for two seconds */
2752 void DrawSetupScreen()
2754 DeactivateJoystick();
2756 if (setup_mode == SETUP_MODE_INPUT)
2757 DrawSetupScreen_Input();
2758 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2759 DrawChooseTree(&artwork.gfx_current);
2760 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2761 DrawChooseTree(&artwork.snd_current);
2762 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2763 DrawChooseTree(&artwork.mus_current);
2765 DrawSetupScreen_Generic();
2768 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2770 if (setup_mode == SETUP_MODE_INPUT)
2771 HandleSetupScreen_Input(mx, my, dx, dy, button);
2772 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2773 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2774 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2775 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2776 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2777 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2779 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2782 void HandleGameActions()
2784 if (game_status != PLAYING)
2787 if (local_player->LevelSolved)
2790 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2798 /* ---------- new screen button stuff -------------------------------------- */
2800 /* graphic position and size values for buttons and scrollbars */
2801 #define SC_SCROLLBUTTON_XSIZE 32
2802 #define SC_SCROLLBUTTON_YSIZE 32
2804 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2805 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2806 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2807 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2808 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2809 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2810 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2811 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2813 #define SC_BORDER_SIZE 14
2817 int gfx_unpressed, gfx_pressed;
2821 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2824 IMG_ARROW_BLUE_UP, IMG_ARROW_RED_UP,
2825 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2826 SCREEN_CTRL_ID_SCROLL_UP,
2830 IMG_ARROW_BLUE_DOWN, IMG_ARROW_RED_DOWN,
2831 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2832 SCREEN_CTRL_ID_SCROLL_DOWN,
2839 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2840 Bitmap **gfx_unpressed, **gfx_pressed;
2842 int gfx_unpressed, gfx_pressed;
2849 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2852 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2853 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2855 IMG_SCROLLBAR_BLUE, IMG_SCROLLBAR_RED,
2857 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2858 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2859 GD_TYPE_SCROLLBAR_VERTICAL,
2860 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2861 "scroll level series vertically"
2865 static void CreateScreenScrollbuttons()
2867 struct GadgetInfo *gi;
2868 unsigned long event_mask;
2871 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2873 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2874 int gfx_unpressed, gfx_pressed;
2875 int x, y, width, height;
2876 int gd_x1, gd_x2, gd_y1, gd_y2;
2877 int id = scrollbutton_info[i].gadget_id;
2879 x = scrollbutton_info[i].x;
2880 y = scrollbutton_info[i].y;
2882 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2886 width = SC_SCROLLBUTTON_XSIZE;
2887 height = SC_SCROLLBUTTON_YSIZE;
2889 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2890 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2891 gd_bitmap_unpressed = new_graphic_info[gfx_unpressed].bitmap;
2892 gd_bitmap_pressed = new_graphic_info[gfx_pressed].bitmap;
2893 gd_x1 = new_graphic_info[gfx_unpressed].src_x;
2894 gd_y1 = new_graphic_info[gfx_unpressed].src_y;
2895 gd_x2 = new_graphic_info[gfx_pressed].src_x;
2896 gd_y2 = new_graphic_info[gfx_pressed].src_y;
2898 gi = CreateGadget(GDI_CUSTOM_ID, id,
2899 GDI_CUSTOM_TYPE_ID, i,
2900 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2905 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2906 GDI_STATE, GD_BUTTON_UNPRESSED,
2907 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2908 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2909 GDI_EVENT_MASK, event_mask,
2910 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2914 Error(ERR_EXIT, "cannot create gadget");
2916 screen_gadget[id] = gi;
2920 static void CreateScreenScrollbars()
2924 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2926 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2927 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2928 int gfx_unpressed, gfx_pressed;
2930 int gd_x1, gd_x2, gd_y1, gd_y2;
2931 struct GadgetInfo *gi;
2932 int items_max, items_visible, item_position;
2933 unsigned long event_mask;
2934 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2935 int id = scrollbar_info[i].gadget_id;
2937 items_max = num_page_entries;
2938 items_visible = num_page_entries;
2941 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2943 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2944 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
2945 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
2951 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2952 gfx_pressed = scrollbar_info[i].gfx_pressed;
2953 gd_bitmap_unpressed = new_graphic_info[gfx_unpressed].bitmap;
2954 gd_bitmap_pressed = new_graphic_info[gfx_pressed].bitmap;
2955 gd_x1 = new_graphic_info[gfx_unpressed].src_x;
2956 gd_y1 = new_graphic_info[gfx_unpressed].src_y;
2957 gd_x2 = new_graphic_info[gfx_pressed].src_x;
2958 gd_y2 = new_graphic_info[gfx_pressed].src_y;
2961 gi = CreateGadget(GDI_CUSTOM_ID, id,
2962 GDI_CUSTOM_TYPE_ID, i,
2963 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2964 GDI_X, scrollbar_info[i].x,
2965 GDI_Y, scrollbar_info[i].y,
2966 GDI_WIDTH, scrollbar_info[i].width,
2967 GDI_HEIGHT, scrollbar_info[i].height,
2968 GDI_TYPE, scrollbar_info[i].type,
2969 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2970 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2971 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2972 GDI_STATE, GD_BUTTON_UNPRESSED,
2973 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2974 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2975 GDI_BORDER_SIZE, SC_BORDER_SIZE,
2976 GDI_EVENT_MASK, event_mask,
2977 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2981 Error(ERR_EXIT, "cannot create gadget");
2983 screen_gadget[id] = gi;
2987 void CreateScreenGadgets()
2989 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2994 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
2996 /* copy pointers to clip mask and GC */
2997 scrollbar_bitmap[i]->clip_mask =
2998 new_graphic_info[IMG_SCROLLBAR_BLUE + i].clip_mask;
2999 scrollbar_bitmap[i]->stored_clip_gc =
3000 new_graphic_info[IMG_SCROLLBAR_BLUE + i].clip_gc;
3002 BlitBitmap(new_graphic_info[IMG_SCROLLBAR_BLUE + i].bitmap,
3003 scrollbar_bitmap[i],
3004 new_graphic_info[IMG_SCROLLBAR_BLUE + i].src_x,
3005 new_graphic_info[IMG_SCROLLBAR_BLUE + i].src_y,
3006 TILEX, TILEY, 0, 0);
3010 CreateScreenScrollbuttons();
3011 CreateScreenScrollbars();
3014 void FreeScreenGadgets()
3018 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3021 /* prevent freeing clip mask and GC twice */
3022 scrollbar_bitmap[i]->clip_mask = None;
3023 scrollbar_bitmap[i]->stored_clip_gc = None;
3025 FreeBitmap(scrollbar_bitmap[i]);
3029 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3030 FreeGadget(screen_gadget[i]);
3033 void MapChooseTreeGadgets(TreeInfo *ti)
3035 int num_entries = numTreeInfoInGroup(ti);
3038 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
3041 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3042 MapGadget(screen_gadget[i]);
3045 void UnmapChooseTreeGadgets()
3049 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3050 UnmapGadget(screen_gadget[i]);
3053 static void HandleScreenGadgets(struct GadgetInfo *gi)
3055 int id = gi->custom_id;
3057 if (game_status != CHOOSELEVEL && game_status != SETUP)
3062 case SCREEN_CTRL_ID_SCROLL_UP:
3063 if (game_status == CHOOSELEVEL)
3064 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3065 else if (game_status == SETUP)
3066 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3069 case SCREEN_CTRL_ID_SCROLL_DOWN:
3070 if (game_status == CHOOSELEVEL)
3071 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3072 else if (game_status == SETUP)
3073 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3076 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3077 if (game_status == CHOOSELEVEL)
3078 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3079 else if (game_status == SETUP)
3080 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);