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 static void drawCursorExt(int xpos, int ypos, int color, int graphic)
76 static int cursor_array[SCR_FIELDY];
81 cursor_array[ypos] = graphic;
83 graphic = cursor_array[ypos];
87 graphic = (graphic == IMG_ARROW_BLUE_LEFT ? IMG_ARROW_RED_LEFT :
88 graphic == IMG_ARROW_BLUE_RIGHT ? IMG_ARROW_RED_RIGHT :
91 ypos += MENU_SCREEN_START_YPOS;
93 DrawBackground(SX + xpos * 32, SY + ypos * 32, TILEX, TILEY);
94 DrawGraphicThruMask(xpos, ypos, graphic, 0);
97 static void initCursor(int ypos, int graphic)
99 drawCursorExt(0, ypos, FC_BLUE, graphic);
102 static void drawCursor(int ypos, int color)
104 drawCursorExt(0, ypos, color, 0);
107 static void drawCursorXY(int xpos, int ypos, int graphic)
109 drawCursorExt(xpos, ypos, -1, graphic);
114 int x = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * FONT1_XSIZE) / 2;
116 DrawText(x, SY + 8, PROGRAM_TITLE_STRING, FS_BIG, FC_YELLOW);
117 DrawTextFCentered(46, FC_RED, WINDOW_SUBTITLE_STRING);
120 static void ToggleFullscreenIfNeeded()
122 if (setup.fullscreen != video.fullscreen_enabled)
124 /* save old door content */
125 BlitBitmap(backbuffer, bitmap_db_door,
126 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
128 /* toggle fullscreen */
129 ChangeVideoModeIfNeeded(setup.fullscreen);
130 setup.fullscreen = video.fullscreen_enabled;
132 /* redraw background to newly created backbuffer */
133 BlitBitmap(new_graphic_info[IMG_MENU_FRAME].bitmap, backbuffer,
134 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
136 /* restore old door content */
137 BlitBitmap(bitmap_db_door, backbuffer,
138 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
140 redraw_mask = REDRAW_ALL;
146 static LevelDirTree *leveldir_last_valid = NULL;
148 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
152 KeyboardAutoRepeatOn();
154 SetDrawDeactivationMask(REDRAW_NONE);
155 SetBackgroundBitmap(new_graphic_info[IMG_MENU_BACKGROUND].bitmap);
156 audio.sound_deactivated = FALSE;
158 /* needed if last screen was the playing screen, invoked from level editor */
159 if (level_editor_test_game)
161 game_status = LEVELED;
166 /* needed if last screen was the editor screen */
167 UndrawSpecialEditorDoor();
169 /* needed if last screen was the setup screen and fullscreen state changed */
170 ToggleFullscreenIfNeeded();
172 /* needed if last screen (level choice) changed graphics, sounds or music */
173 ReloadCustomArtwork();
176 SetDrawtoField(DRAW_BACKBUFFER);
179 /* map gadgets for main menu screen */
182 /* leveldir_current may be invalid (level group, parent link) */
183 if (!validLevelSeries(leveldir_current))
184 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
186 /* store valid level series information */
187 leveldir_last_valid = leveldir_current;
189 /* level_nr may have been set to value over handicap with level editor */
190 if (setup.handicap && level_nr > leveldir_current->handicap_level)
191 level_nr = leveldir_current->handicap_level;
196 SetBackgroundBitmap(new_graphic_info[IMG_MENU_BACKGROUND].bitmap);
200 DrawText(SX + 32, SY + 2*32, name_text, FS_BIG, FC_GREEN);
201 DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
202 DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
203 DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
204 (leveldir_current->readonly ? FC_RED : FC_YELLOW));
205 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
206 DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
207 DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
208 DrawText(SX + 32, SY + 7*32, "Start Game", FS_BIG, FC_GREEN);
209 DrawText(SX + 32, SY + 8*32, "Setup", FS_BIG, FC_GREEN);
210 DrawText(SX + 32, SY + 9*32, "Quit", FS_BIG, FC_GREEN);
212 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
214 DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
215 leveldir_current->first_level,
216 leveldir_current->last_level);
218 if (leveldir_current->readonly)
220 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
221 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
225 initCursor(i, (i == 1 || i == 6 ? IMG_ARROW_BLUE_RIGHT : IMG_BALL_BLUE));
228 DrawGraphic(10, 3, IMG_ARROW_BLUE_LEFT, 0);
229 DrawGraphic(14, 3, IMG_ARROW_BLUE_RIGHT, 0);
231 drawCursorXY(10, 1, IMG_ARROW_BLUE_LEFT);
232 drawCursorXY(14, 1, IMG_ARROW_BLUE_RIGHT);
235 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
238 if (leveldir_current->name)
240 int len = strlen(leveldir_current->name);
241 int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
242 int lypos = SY + 352;
244 DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
249 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
252 if (TAPE_IS_EMPTY(tape))
254 DrawCompleteVideoDisplay();
256 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
263 static void gotoTopLevelDir()
265 /* move upwards to top level directory */
266 while (leveldir_current->node_parent)
268 /* write a "path" into level tree for easy navigation to last level */
269 if (leveldir_current->node_parent->node_group->cl_first == -1)
271 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
272 int leveldir_pos = posTreeInfo(leveldir_current);
273 int num_page_entries;
274 int cl_first, cl_cursor;
276 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
277 num_page_entries = num_leveldirs;
279 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
281 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
282 cl_cursor = leveldir_pos - cl_first;
284 leveldir_current->node_parent->node_group->cl_first = cl_first;
285 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
288 leveldir_current = leveldir_current->node_parent;
292 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
294 static int choice = 0;
298 if (button == MB_MENU_INITIALIZE)
300 drawCursor(choice, FC_RED);
304 if (mx || my) /* mouse input */
307 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
309 else if (dx || dy) /* keyboard input */
311 if (dx && choice == 1)
312 x = (dx < 0 ? 10 : 14);
317 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
318 (x == 14 && level_nr < leveldir_current->last_level)) &&
321 static unsigned long level_delay = 0;
322 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
323 int new_level_nr, old_level_nr = level_nr;
324 int font_color = (leveldir_current->readonly ? FC_RED : FC_YELLOW);
326 new_level_nr = level_nr + (x == 10 ? -step : +step);
327 if (new_level_nr < leveldir_current->first_level)
328 new_level_nr = leveldir_current->first_level;
329 if (new_level_nr > leveldir_current->last_level)
330 new_level_nr = leveldir_current->last_level;
332 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
333 new_level_nr = leveldir_current->handicap_level;
335 if (old_level_nr == new_level_nr ||
336 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
339 level_nr = new_level_nr;
341 DrawText(SX + 11 * 32, SY + 3 * 32, int2str(level_nr, 3),
345 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
349 DrawCompleteVideoDisplay();
351 /* needed because DrawMicroLevel() takes some time */
354 DelayReached(&level_delay, 0); /* reset delay counter */
356 else if (x == 0 && y >= 0 && y <= 7)
362 drawCursor(y, FC_RED);
363 drawCursor(choice, FC_BLUE);
371 game_status = TYPENAME;
372 HandleTypeName(strlen(setup.player_name), 0);
378 game_status = CHOOSELEVEL;
379 SaveLevelSetup_LastSeries();
380 SaveLevelSetup_SeriesInfo();
389 game_status = HALLOFFAME;
394 if (leveldir_current->readonly &&
395 strcmp(setup.player_name, "Artsoft") != 0)
396 Request("This level is read only !", REQ_CONFIRM);
397 game_status = LEVELED;
402 game_status = HELPSCREEN;
407 if (setup.autorecord)
408 TapeStartRecording();
410 #if defined(PLATFORM_UNIX)
412 SendToServer_StartPlaying();
416 game_status = PLAYING;
424 setup_mode = SETUP_MODE_MAIN;
429 SaveLevelSetup_LastSeries();
430 SaveLevelSetup_SeriesInfo();
431 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
432 game_status = EXITGAME;
441 if (game_status == MAINMENU)
443 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
449 #define MAX_HELPSCREEN_ELS 10
453 static long helpscreen_state;
454 static int helpscreen_step[MAX_HELPSCREEN_ELS];
455 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
457 static int OLD_helpscreen_action[] =
459 GFX_SPIELER1_DOWN,4,2,
461 GFX_SPIELER1_LEFT,4,2,
462 GFX_SPIELER1_RIGHT,4,2,
463 GFX_SPIELER1_PUSH_LEFT,4,2,
464 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
465 GFX_ERDREICH,1,100, HA_NEXT,
466 GFX_LEERRAUM,1,100, HA_NEXT,
467 GFX_MORAST_LEER,1,100, HA_NEXT,
468 GFX_BETON,1,100, HA_NEXT,
469 GFX_MAUERWERK,1,100, HA_NEXT,
470 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
471 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
472 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
473 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
474 GFX_UNSICHTBAR,1,100, HA_NEXT,
475 GFX_FELSBODEN,1,100, HA_NEXT,
476 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
477 GFX_EDELSTEIN,2,5, HA_NEXT,
478 GFX_DIAMANT,2,5, HA_NEXT,
479 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
480 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
481 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
482 GFX_FELSBROCKEN,4,5, HA_NEXT,
483 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
484 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
485 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
486 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
487 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
488 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
489 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
490 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
491 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
492 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
493 GFX_GEBLUBBER,4,4, HA_NEXT,
494 GFX_SCHLUESSEL1,4,25, HA_NEXT,
495 GFX_PFORTE1,4,25, HA_NEXT,
496 GFX_PFORTE1X,4,25, HA_NEXT,
497 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
498 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
499 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
500 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
501 GFX_LEERRAUM,1,10, HA_NEXT,
502 GFX_DYNABOMB_NR,1,100, HA_NEXT,
503 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
504 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
505 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
506 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
507 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
508 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
509 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
510 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
511 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
512 GFX_BUTTERFLY,2,2, HA_NEXT,
513 GFX_FIREFLY,2,2, HA_NEXT,
514 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
515 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
516 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
517 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
518 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
519 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
520 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
521 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
522 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
523 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
527 GFX_MOLE_RIGHT,4,2, HA_NEXT,
528 GFX_PINGUIN_DOWN,4,2,
530 GFX_PINGUIN_LEFT,4,2,
531 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
532 GFX_SCHWEIN_DOWN,4,2,
534 GFX_SCHWEIN_LEFT,4,2,
535 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
539 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
540 GFX_SONDE_START,8,1, HA_NEXT,
541 GFX_ABLENK,4,1, HA_NEXT,
542 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
543 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
544 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
545 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
546 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
547 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
548 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
549 GFX_DIAMANT,1,10, HA_NEXT,
550 GFX_LIFE,1,100, HA_NEXT,
551 GFX_LIFE_ASYNC,1,100, HA_NEXT,
552 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
553 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
554 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
555 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
556 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
557 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
558 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
559 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
560 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
561 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
562 GFX_SPEED_PILL,1,100, HA_NEXT,
567 static int helpscreen_action[] =
569 IMG_PLAYER1_DOWN_MOVING, 16,
570 IMG_PLAYER1_UP_MOVING, 16,
571 IMG_PLAYER1_LEFT_MOVING, 16,
572 IMG_PLAYER1_RIGHT_MOVING, 16,
573 IMG_PLAYER1_LEFT_PUSHING, 16,
574 IMG_PLAYER1_RIGHT_PUSHING, 16, HA_NEXT,
576 IMG_SAND, -1, HA_NEXT,
578 IMG_EMPTY_SPACE, -1, HA_NEXT,
580 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
582 IMG_STEELWALL, -1, HA_NEXT,
584 IMG_WALL, -1, HA_NEXT,
586 IMG_WALL_GROWING_ACTIVE_LEFT, 20,
589 IMG_WALL_GROWING_ACTIVE_RIGHT, 20,
592 IMG_WALL_GROWING_ACTIVE_UP, 20,
595 IMG_WALL_GROWING_ACTIVE_DOWN, 20,
597 IMG_EMPTY_SPACE, 20, HA_NEXT,
599 IMG_INVISIBLE_WALL, -1, HA_NEXT,
601 IMG_WALL_CRUMBLED, -1, HA_NEXT,
603 IMG_INFO_FONT_EM_1, 160,
604 IMG_INFO_FONT_EM_2, 160,
605 IMG_INFO_FONT_EM_3, 160,
606 IMG_INFO_FONT_EM_4, 160,
607 IMG_INFO_FONT_EM_5, 40, HA_NEXT,
609 IMG_EMERALD, -1, HA_NEXT,
611 IMG_DIAMOND, -1, HA_NEXT,
613 IMG_BD_DIAMOND, -1, HA_NEXT,
615 IMG_EMERALD_YELLOW, 50,
617 IMG_EMERALD_PURPLE, 50, HA_NEXT,
619 IMG_BD_ROCK, -1, HA_NEXT,
623 IMG_EMPTY_SPACE, 10, HA_NEXT,
627 IMG_EMERALD, 20, HA_NEXT,
629 IMG_WALL_EMERALD, 100,
631 IMG_EMERALD, 20, HA_NEXT,
633 IMG_WALL_DIAMOND, 100,
635 IMG_DIAMOND, 20, HA_NEXT,
637 IMG_WALL_BD_DIAMOND, 100,
639 IMG_BD_DIAMOND, 20, HA_NEXT,
641 IMG_WALL_EMERALD_YELLOW, 100,
643 IMG_EMERALD_YELLOW, 20,
644 IMG_WALL_EMERALD_RED, 100,
647 IMG_WALL_EMERALD_PURPLE, 100,
649 IMG_EMERALD_PURPLE, 20, HA_NEXT,
651 IMG_ACID, -1, HA_NEXT,
656 IMG_KEY4, 50, HA_NEXT,
661 IMG_GATE4, 50, HA_NEXT,
666 IMG_GATE4_GRAY, 50, HA_NEXT,
668 IMG_DYNAMITE, -1, HA_NEXT,
670 IMG_DYNAMITE_ACTIVE, 96,
672 IMG_EMPTY_SPACE, 20, HA_NEXT,
674 IMG_DYNABOMB_ACTIVE, 100,
676 IMG_EMPTY_SPACE, 20, HA_NEXT,
678 IMG_DYNABOMB_NR, -1, HA_NEXT,
680 IMG_DYNABOMB_SZ, -1, HA_NEXT,
682 IMG_SPACESHIP_RIGHT, 16,
683 IMG_SPACESHIP_UP, 16,
684 IMG_SPACESHIP_LEFT, 16,
685 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
690 IMG_BUG_DOWN, 16, HA_NEXT,
692 IMG_BD_BUTTERFLY, -1, HA_NEXT,
694 IMG_BD_FIREFLY, -1, HA_NEXT,
696 IMG_PACMAN_RIGHT, 16,
699 IMG_PACMAN_DOWN, 16, HA_NEXT,
701 IMG_YAMYAM, -1, HA_NEXT,
703 IMG_DARK_YAMYAM, -1, HA_NEXT,
705 IMG_ROBOT, -1, HA_NEXT,
707 IMG_MOLE_RIGHT_MOVING, 16,
708 IMG_MOLE_UP_MOVING, 16,
709 IMG_MOLE_LEFT_MOVING, 16,
710 IMG_MOLE_DOWN_MOVING, 16, HA_NEXT,
712 IMG_PENGUIN_RIGHT_MOVING, 16,
713 IMG_PENGUIN_UP_MOVING, 16,
714 IMG_PENGUIN_LEFT_MOVING, 16,
715 IMG_PENGUIN_DOWN_MOVING, 16, HA_NEXT,
717 IMG_PIG_RIGHT_MOVING, 16,
718 IMG_PIG_UP_MOVING, 16,
719 IMG_PIG_LEFT_MOVING, 16,
720 IMG_PIG_DOWN_MOVING, 16, HA_NEXT,
722 IMG_DRAGON_RIGHT_MOVING, 16,
723 IMG_DRAGON_UP_MOVING, 16,
724 IMG_DRAGON_LEFT_MOVING, 16,
725 IMG_DRAGON_DOWN_MOVING, 16, HA_NEXT,
727 IMG_SATELLITE, -1, HA_NEXT,
730 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
733 IMG_LAMP_ACTIVE, 50, HA_NEXT,
735 IMG_TIME_ORB_FULL, 50,
736 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
739 IMG_AMOEBA_CREATING, 6,
740 IMG_AMOEBA_WET, 20, HA_NEXT,
742 IMG_AMOEBA_DEAD, -1, HA_NEXT,
744 IMG_AMOEBA_WET, -1, HA_NEXT,
747 IMG_AMOEBA_CREATING, 6, HA_NEXT,
752 IMG_DIAMOND, 20, HA_NEXT,
754 IMG_GAMEOFLIFE, -1, HA_NEXT,
756 IMG_BIOMAZE, -1, HA_NEXT,
758 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
760 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
762 IMG_EXIT_CLOSED, 200,
763 IMG_EXIT_OPENING, 16,
764 IMG_EXIT_OPEN, 100, HA_NEXT,
766 IMG_EXIT_OPEN, -1, HA_NEXT,
768 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
770 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
772 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
774 IMG_SPEED_PILL, -1, HA_NEXT,
778 static char *helpscreen_eltext[][2] =
780 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
781 {"Normal sand:", "You can dig through it"},
782 {"Empty field:", "You can walk through it"},
783 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
784 {"Massive Wall:", "Nothing can go through it"},
785 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
786 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
787 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
788 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
789 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
790 {"Emerald: You must collect enough of","them to finish a level"},
791 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
792 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
793 {"Colorful Gems:", "Seem to behave like Emeralds"},
794 {"Rock: Smashes several things;", "Can be moved by the player"},
795 {"Bomb: You can move it, but be", "careful when dropping it"},
796 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
797 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
798 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
799 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
800 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
801 {"Acid: Things that fall in are gone", "forever (including our hero)"},
802 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
803 {"Door: Can be opened by the key", "with the same color"},
804 {"Door: You have to find out the", "right color of the key for it"},
805 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
806 {"Dynamite: This one explodes after", "a few seconds"},
807 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
808 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
809 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
810 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
811 {"Bug: Moves at the right side", "of walls; don't touch it!"},
812 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
813 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
814 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
815 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
816 {"Cruncher (BD style):", "Eats almost everything"},
817 {"Robot: Tries to kill the player", ""},
818 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
819 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
820 {"The Pig: Harmless, but eats all", "gems it can get"},
821 {"The Dragon: Breathes fire,", "especially to some monsters"},
822 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
823 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
824 {"Light Bulb: All of them must be", "switched on to finish a level"},
825 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
826 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
827 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
828 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
829 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
830 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
831 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
832 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
833 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
834 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
835 {"Exit door: Opens if you have enough","emeralds to finish the level"},
836 {"Open exit door: Enter here to leave","the level and exit the actual game"},
837 {"Sokoban element: Object which must", "be pushed to an empty field"},
838 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
839 {"Sokoban element: Field with object", "which can be pushed away"},
840 {"Speed pill: Lets the player run", "twice as fast as normally"},
842 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
844 static char *helpscreen_music[][3] =
846 { "Alchemy", "Ian Boddy", "Drive" },
847 { "The Chase", "Propaganda", "A Secret Wish" },
848 { "Network 23", "Tangerine Dream", "Exit" },
849 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
850 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
851 { "Voyager", "The Alan Parsons Project","Pyramid" },
852 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
854 static int num_helpscreen_music = 7;
855 static int helpscreen_musicpos;
858 void OLD_DrawHelpScreenElAction(int start)
862 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
864 while(helpscreen_action[j] != HA_END)
866 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
868 else if (i<start || helpscreen_delay[i-start])
870 if (i>=start && helpscreen_delay[i-start])
871 helpscreen_delay[i-start]--;
873 while(helpscreen_action[j] != HA_NEXT)
880 j += 3*helpscreen_step[i-start];
881 graphic = helpscreen_action[j++];
883 if (helpscreen_frame[i-start])
885 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
886 helpscreen_frame[i-start]--;
891 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
894 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
896 if (helpscreen_action[j] == HA_NEXT)
898 if (!helpscreen_frame[i-start])
899 helpscreen_step[i-start] = 0;
903 if (!helpscreen_frame[i-start])
904 helpscreen_step[i-start]++;
905 while(helpscreen_action[j] != HA_NEXT)
910 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
922 void DrawHelpScreenElAction(int start)
925 int xstart = SX + 16;
926 int ystart = SY + 64 + 2 * 32;
927 int ystep = TILEY + 4;
933 while (helpscreen_action[j] != HA_END)
935 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
939 while (helpscreen_action[j] != HA_NEXT)
948 j += 2 * helpscreen_step[i-start];
949 graphic = helpscreen_action[j++];
950 frame_count = helpscreen_action[j++];
951 if (frame_count == -1)
952 frame_count = 1000000;
954 if (helpscreen_frame[i-start] == 0)
957 helpscreen_frame[i-start] = frame_count - 1;
961 sync_frame = frame_count - helpscreen_frame[i-start];
962 helpscreen_frame[i-start]--;
965 if (helpscreen_action[j] == HA_NEXT)
967 if (!helpscreen_frame[i-start])
968 helpscreen_step[i-start] = 0;
972 if (!helpscreen_frame[i-start])
973 helpscreen_step[i-start]++;
974 while(helpscreen_action[j] != HA_NEXT)
979 frame = getGraphicAnimationFrame(graphic, sync_frame);
981 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
996 void DrawHelpScreenElText(int start)
999 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
1000 int ybottom = SYSIZE - 20;
1005 DrawTextFCentered(100, FC_GREEN, "The game elements:");
1007 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1010 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1011 helpscreen_eltext[i][0], FS_SMALL, FC_YELLOW);
1012 DrawText(xstart, ystart + (i - start) * ystep + 16,
1013 helpscreen_eltext[i][1], FS_SMALL, FC_YELLOW);
1016 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1019 void DrawHelpScreenMusicText(int num)
1021 int ystart = 150, ystep = 30;
1022 int ybottom = SYSIZE - 20;
1028 DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
1030 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1032 DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
1033 helpscreen_music[num][0]);
1034 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
1036 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
1037 "%s", helpscreen_music[num][1]);
1038 DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
1040 DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
1041 helpscreen_music[num][2]);
1043 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1046 PlaySoundLoop(background_loop[num]);
1050 void DrawHelpScreenCreditsText()
1052 int ystart = 150, ystep = 30;
1053 int ybottom = SYSIZE - 20;
1059 DrawTextFCentered(100, FC_GREEN,
1061 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1062 "DOS port of the game:");
1063 DrawTextFCentered(ystart + 1 * ystep, FC_RED,
1065 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
1066 "Additional toons:");
1067 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
1069 DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
1070 "...and many thanks to all contributors");
1071 DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
1074 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1077 void DrawHelpScreenContactText()
1079 int ystart = 150, ystep = 30;
1080 int ybottom = SYSIZE - 20;
1085 DrawTextFCentered(100, FC_GREEN, "Program information:");
1087 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1088 "This game is Freeware!");
1089 DrawTextFCentered(ystart + 1 * ystep, FC_YELLOW,
1090 "If you like it, send e-mail to:");
1091 DrawTextFCentered(ystart + 2 * ystep, FC_RED,
1092 "info@artsoft.org");
1093 DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
1094 "or SnailMail to:");
1095 DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
1097 DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
1098 "Detmolder Strasse 189");
1099 DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
1101 DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
1104 DrawTextFCentered(ystart + 7 * ystep, FC_YELLOW,
1105 "If you have created new levels,");
1106 DrawTextFCentered(ystart + 8 * ystep, FC_YELLOW,
1107 "send them to me to include them!");
1108 DrawTextFCentered(ystart + 9 * ystep, FC_YELLOW,
1111 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
1114 void DrawHelpScreen()
1119 CloseDoor(DOOR_CLOSE_2);
1121 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1122 helpscreen_step[i] = helpscreen_frame[i] = 0;
1123 helpscreen_musicpos = 0;
1124 helpscreen_state = 0;
1125 DrawHelpScreenElText(0);
1126 DrawHelpScreenElAction(0);
1130 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1133 void HandleHelpScreen(int button)
1135 static unsigned long hs_delay = 0;
1136 int num_helpscreen_els_pages =
1137 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1138 int button_released = !button;
1141 if (button_released)
1143 if (helpscreen_state < num_helpscreen_els_pages - 1)
1145 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1146 helpscreen_step[i] = helpscreen_frame[i] = 0;
1150 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1151 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1153 else if (helpscreen_state <
1154 num_helpscreen_els_pages + num_helpscreen_music - 1)
1157 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1159 else if (helpscreen_state ==
1160 num_helpscreen_els_pages + num_helpscreen_music - 1)
1163 DrawHelpScreenCreditsText();
1165 else if (helpscreen_state ==
1166 num_helpscreen_els_pages + num_helpscreen_music)
1169 DrawHelpScreenContactText();
1175 game_status = MAINMENU;
1180 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1182 if (helpscreen_state < num_helpscreen_els_pages)
1183 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1186 /* !!! workaround for playing "music" that is really a sound loop (and
1187 must therefore periodically be reactivated with the current sound
1189 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1197 void HandleTypeName(int newxpos, Key key)
1199 static int xpos = 0, ypos = 2;
1204 DrawText(SX + 6 * 32, SY + ypos * 32, setup.player_name,
1206 drawCursorXY(xpos + 6, ypos - 2, IMG_BALL_RED);
1211 if (((key >= KSYM_A && key <= KSYM_Z) ||
1212 (key >= KSYM_a && key <= KSYM_z)) &&
1213 xpos < MAX_PLAYER_NAME_LEN)
1217 if (key >= KSYM_A && key <= KSYM_Z)
1218 ascii = 'A' + (char)(key - KSYM_A);
1220 ascii = 'a' + (char)(key - KSYM_a);
1222 setup.player_name[xpos] = ascii;
1223 setup.player_name[xpos + 1] = 0;
1226 DrawText(SX + 6 * 32, SY + ypos * 32, setup.player_name,
1228 drawCursorXY(xpos + 6, ypos - 2, IMG_BALL_RED);
1230 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1233 setup.player_name[xpos] = 0;
1235 DrawBackground(SX + (xpos + 6) * 32, SY + ypos * 32, 2 * TILEX, TILEY);
1236 drawCursorXY(xpos + 6, ypos - 2, IMG_BALL_RED);
1238 else if (key == KSYM_Return && xpos > 0)
1240 DrawText(SX + 6 * 32, SY + ypos * 32, setup.player_name, FS_BIG, FC_RED);
1241 DrawBackground(SX + (xpos + 6) * 32, SY + ypos * 32, TILEX, TILEY);
1244 game_status = MAINMENU;
1250 static void DrawChooseTree(TreeInfo **ti_ptr)
1253 CloseDoor(DOOR_CLOSE_2);
1256 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1257 MapChooseTreeGadgets(*ti_ptr);
1263 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1265 struct GadgetInfo *gi = screen_gadget[id];
1266 int items_max, items_visible, item_position;
1268 items_max = numTreeInfoInGroup(ti);
1269 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1270 item_position = first_entry;
1272 if (item_position > items_max - items_visible)
1273 item_position = items_max - items_visible;
1275 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1276 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1279 static void drawChooseTreeList(int first_entry, int num_page_entries,
1283 char buffer[SCR_FIELDX * 2];
1284 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1285 int num_entries = numTreeInfoInGroup(ti);
1286 char *title_string = NULL;
1287 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1289 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1290 redraw_mask |= REDRAW_FIELD;
1293 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1294 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1295 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1296 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1298 DrawText(SX + offset, SY + offset, title_string, FS_BIG,
1299 (ti->type == TREE_TYPE_LEVEL_DIR ? FC_GREEN : FC_YELLOW));
1301 for(i=0; i<num_page_entries; i++)
1303 TreeInfo *node, *node_first;
1304 int entry_pos = first_entry + i;
1305 int ypos = MENU_SCREEN_START_YPOS + i;
1307 node_first = getTreeInfoFirstGroupEntry(ti);
1308 node = getTreeInfoFromPos(node_first, entry_pos);
1310 strncpy(buffer, node->name , max_buffer_len);
1311 buffer[max_buffer_len] = '\0';
1313 DrawText(SX + 32, SY + ypos * 32, buffer, FS_MEDIUM, node->color);
1315 if (node->parent_link)
1316 initCursor(i, IMG_ARROW_BLUE_LEFT);
1317 else if (node->level_group)
1318 initCursor(i, IMG_ARROW_BLUE_RIGHT);
1320 initCursor(i, IMG_BALL_BLUE);
1323 if (first_entry > 0)
1327 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1328 DrawGraphicThruMask(0, ypos, IMG_ARROW_BLUE_UP, 0);
1331 if (first_entry + num_page_entries < num_entries)
1333 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1335 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1336 DrawGraphicThruMask(0, ypos, IMG_ARROW_BLUE_DOWN, 0);
1340 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1342 TreeInfo *node, *node_first;
1343 int x, last_redraw_mask = redraw_mask;
1345 if (ti->type != TREE_TYPE_LEVEL_DIR)
1348 node_first = getTreeInfoFirstGroupEntry(ti);
1349 node = getTreeInfoFromPos(node_first, entry_pos);
1351 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1353 if (node->parent_link)
1354 DrawTextFCentered(40, FC_RED, "leave group \"%s\"", node->class_desc);
1355 else if (node->level_group)
1356 DrawTextFCentered(40, FC_RED, "enter group \"%s\"", node->class_desc);
1357 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1358 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
1359 node->levels, node->class_desc);
1361 /* let BackToFront() redraw only what is needed */
1362 redraw_mask = last_redraw_mask | REDRAW_TILES;
1363 for (x=0; x<SCR_FIELDX; x++)
1364 MarkTileDirty(x, 1);
1367 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1370 static unsigned long choose_delay = 0;
1371 TreeInfo *ti = *ti_ptr;
1373 int y = ti->cl_cursor;
1374 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1375 int num_entries = numTreeInfoInGroup(ti);
1376 int num_page_entries;
1378 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1379 num_page_entries = num_entries;
1381 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1383 if (button == MB_MENU_INITIALIZE)
1385 int entry_pos = posTreeInfo(ti);
1387 if (ti->cl_first == -1)
1389 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1391 entry_pos - ti->cl_first;
1394 if (dx == 999) /* first entry is set by scrollbar position */
1397 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1400 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1401 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1402 drawCursor(ti->cl_cursor, FC_RED);
1405 else if (button == MB_MENU_LEAVE)
1407 if (ti->node_parent)
1409 *ti_ptr = ti->node_parent;
1410 DrawChooseTree(ti_ptr);
1412 else if (game_status == SETUP)
1418 game_status = MAINMENU;
1425 if (mx || my) /* mouse input */
1428 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1430 else if (dx || dy) /* keyboard input */
1433 y = ti->cl_cursor + dy;
1435 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1438 step = num_page_entries - 1;
1439 y = (dy < 0 ? -1 : num_page_entries);
1443 if (x == 0 && y == -1)
1445 if (ti->cl_first > 0 &&
1446 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1448 ti->cl_first -= step;
1449 if (ti->cl_first < 0)
1452 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1453 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1454 drawCursor(ti->cl_cursor, FC_RED);
1455 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1460 else if (x == 0 && y > num_page_entries - 1)
1462 if (ti->cl_first + num_page_entries < num_entries &&
1463 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1465 ti->cl_first += step;
1466 if (ti->cl_first + num_page_entries > num_entries)
1467 ti->cl_first = MAX(0, num_entries - num_page_entries);
1469 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1470 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1471 drawCursor(ti->cl_cursor, FC_RED);
1472 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1480 TreeInfo *node_first, *node_cursor;
1481 int entry_pos = ti->cl_first + y;
1483 node_first = getTreeInfoFirstGroupEntry(ti);
1484 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1486 if (node_cursor->node_group)
1488 node_cursor->cl_first = ti->cl_first;
1489 node_cursor->cl_cursor = ti->cl_cursor;
1490 *ti_ptr = node_cursor->node_group;
1491 DrawChooseTree(ti_ptr);
1495 else if (dx == -1 && ti->node_parent)
1497 *ti_ptr = ti->node_parent;
1498 DrawChooseTree(ti_ptr);
1502 if (x == 0 && y >= 0 && y < num_page_entries)
1506 if (y != ti->cl_cursor)
1508 drawCursor(y, FC_RED);
1509 drawCursor(ti->cl_cursor, FC_BLUE);
1510 drawChooseTreeInfo(ti->cl_first + y, ti);
1516 TreeInfo *node_first, *node_cursor;
1517 int entry_pos = ti->cl_first + y;
1519 node_first = getTreeInfoFirstGroupEntry(ti);
1520 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1522 if (node_cursor->node_group)
1524 node_cursor->cl_first = ti->cl_first;
1525 node_cursor->cl_cursor = ti->cl_cursor;
1526 *ti_ptr = node_cursor->node_group;
1527 DrawChooseTree(ti_ptr);
1529 else if (node_cursor->parent_link)
1531 *ti_ptr = node_cursor->node_parent;
1532 DrawChooseTree(ti_ptr);
1536 node_cursor->cl_first = ti->cl_first;
1537 node_cursor->cl_cursor = ti->cl_cursor;
1538 *ti_ptr = node_cursor;
1540 if (ti->type == TREE_TYPE_LEVEL_DIR)
1542 LoadLevelSetup_SeriesInfo();
1544 SaveLevelSetup_LastSeries();
1545 SaveLevelSetup_SeriesInfo();
1549 if (game_status == SETUP)
1555 game_status = MAINMENU;
1564 if (game_status == CHOOSELEVEL || game_status == SETUP)
1568 void DrawChooseLevel()
1570 DrawChooseTree(&leveldir_current);
1573 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1575 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1578 void DrawHallOfFame(int highlight_position)
1582 CloseDoor(DOOR_CLOSE_2);
1584 if (highlight_position < 0)
1585 LoadScore(level_nr);
1589 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1590 PlaySound(SND_MENU_HALL_OF_FAME);
1593 static void drawHallOfFameList(int first_entry, int highlight_position)
1598 DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1599 DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1601 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1603 int entry = first_entry + i;
1604 int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1607 DrawText(SX, SY + 64 + i * 32, ".................", FS_BIG, color);
1608 DrawText(SX, SY + 64 + i * 32, highscore[i].Name, FS_BIG, color);
1609 DrawText(SX + 12 * 32, SY + 64 + i * 32,
1610 int2str(highscore[i].Score, 5), FS_BIG, color);
1612 DrawText(SX, SY + 64 + i * 32, "..................................",
1613 FS_MEDIUM, FC_YELLOW);
1614 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1615 FS_MEDIUM, FC_YELLOW);
1616 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name, FS_BIG, color);
1617 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1618 int2str(highscore[entry].Score, 5), FS_MEDIUM, color);
1623 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1625 static int first_entry = 0;
1626 static int highlight_position = 0;
1627 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1628 int button_released = !button;
1630 if (button == MB_MENU_INITIALIZE)
1633 highlight_position = mx;
1634 drawHallOfFameList(first_entry, highlight_position);
1638 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1639 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1643 if (first_entry > 0)
1645 first_entry -= step;
1646 if (first_entry < 0)
1649 drawHallOfFameList(first_entry, highlight_position);
1655 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1657 first_entry += step;
1658 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1659 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1661 drawHallOfFameList(first_entry, highlight_position);
1666 if (button_released)
1668 FadeSound(SND_MENU_HALL_OF_FAME);
1669 game_status = MAINMENU;
1675 if (game_status == HALLOFFAME)
1680 /* ========================================================================= */
1681 /* setup screen functions */
1682 /* ========================================================================= */
1684 static struct TokenInfo *setup_info;
1685 static int num_setup_info;
1687 static char *graphics_set_name;
1688 static char *sounds_set_name;
1689 static char *music_set_name;
1691 static void execSetupMain()
1693 setup_mode = SETUP_MODE_MAIN;
1697 static void execSetupGame()
1699 setup_mode = SETUP_MODE_GAME;
1703 static void execSetupEditor()
1705 setup_mode = SETUP_MODE_EDITOR;
1709 static void execSetupGraphics()
1711 setup_mode = SETUP_MODE_GRAPHICS;
1715 static void execSetupSound()
1717 setup_mode = SETUP_MODE_SOUND;
1721 static void execSetupArtwork()
1723 /* needed if last screen (setup choice) changed graphics, sounds or music */
1724 ReloadCustomArtwork();
1726 setup.graphics_set = artwork.gfx_current->identifier;
1727 setup.sounds_set = artwork.snd_current->identifier;
1728 setup.music_set = artwork.mus_current->identifier;
1730 /* needed for displaying artwork name instead of artwork identifier */
1731 graphics_set_name = artwork.gfx_current->name;
1732 sounds_set_name = artwork.snd_current->name;
1733 music_set_name = artwork.mus_current->name;
1735 setup_mode = SETUP_MODE_ARTWORK;
1739 static void execSetupChooseGraphics()
1741 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1745 static void execSetupChooseSounds()
1747 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1751 static void execSetupChooseMusic()
1753 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1757 static void execSetupInput()
1759 setup_mode = SETUP_MODE_INPUT;
1763 static void execSetupShortcut()
1765 setup_mode = SETUP_MODE_SHORTCUT;
1769 static void execExitSetup()
1771 game_status = MAINMENU;
1775 static void execSaveAndExitSetup()
1781 static struct TokenInfo setup_info_main[] =
1783 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1784 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1785 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1786 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1787 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1788 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1789 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1790 { TYPE_EMPTY, NULL, "" },
1791 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1792 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1796 static struct TokenInfo setup_info_game[] =
1798 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1799 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1800 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1801 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1802 { TYPE_EMPTY, NULL, "" },
1803 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1807 static struct TokenInfo setup_info_editor[] =
1809 { TYPE_STRING, NULL, "Offer Special Elements:"},
1810 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1811 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1812 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1813 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1814 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1815 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1816 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1817 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1818 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1819 { TYPE_EMPTY, NULL, "" },
1820 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1824 static struct TokenInfo setup_info_graphics[] =
1826 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1827 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1828 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1830 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1831 { TYPE_SWITCH, &setup.fading, "Fading:" },
1833 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1834 { TYPE_SWITCH, &setup.toons, "Toons:" },
1835 { TYPE_EMPTY, NULL, "" },
1836 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1840 static struct TokenInfo setup_info_sound[] =
1842 { TYPE_SWITCH, &setup.sound, "Sound:", },
1843 { TYPE_EMPTY, NULL, "" },
1844 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1845 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1846 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1847 { TYPE_EMPTY, NULL, "" },
1848 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1852 static struct TokenInfo setup_info_artwork[] =
1854 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1855 { TYPE_STRING, &graphics_set_name, "" },
1856 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1857 { TYPE_STRING, &sounds_set_name, "" },
1858 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1859 { TYPE_STRING, &music_set_name, "" },
1860 { TYPE_EMPTY, NULL, "" },
1861 { TYPE_STRING, NULL, "Override Level Artwork:"},
1862 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1863 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1864 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1865 { TYPE_EMPTY, NULL, "" },
1866 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1870 static struct TokenInfo setup_info_shortcut[] =
1872 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1873 { TYPE_KEY, &setup.shortcut.save_game, "" },
1874 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1875 { TYPE_KEY, &setup.shortcut.load_game, "" },
1876 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1877 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1878 { TYPE_EMPTY, NULL, "" },
1879 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1880 { TYPE_EMPTY, NULL, "" },
1881 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1885 static Key getSetupKey()
1887 Key key = KSYM_UNDEFINED;
1888 boolean got_key_event = FALSE;
1890 while (!got_key_event)
1892 if (PendingEvent()) /* got event */
1900 case EVENT_KEYPRESS:
1902 key = GetEventKey((KeyEvent *)&event, TRUE);
1904 /* press 'Escape' or 'Enter' to keep the existing key binding */
1905 if (key == KSYM_Escape || key == KSYM_Return)
1906 key = KSYM_UNDEFINED; /* keep old value */
1908 got_key_event = TRUE;
1912 case EVENT_KEYRELEASE:
1913 key_joystick_mapping = 0;
1917 HandleOtherEvents(&event);
1925 /* don't eat all CPU time */
1932 static void drawSetupValue(int pos)
1934 int xpos = MENU_SCREEN_VALUE_XPOS;
1935 int ypos = MENU_SCREEN_START_YPOS + pos;
1936 int font_size = FS_BIG;
1937 int font_color = FC_YELLOW;
1938 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1939 setup_info[pos].value);
1941 if (value_string == NULL)
1944 if (setup_info[pos].type & TYPE_KEY)
1948 if (setup_info[pos].type & TYPE_QUERY)
1950 value_string = "<press key>";
1951 font_color = FC_RED;
1954 else if (setup_info[pos].type & TYPE_STRING)
1956 int max_value_len = (SCR_FIELDX - 2) * 2;
1959 font_size = FS_MEDIUM;
1961 if (strlen(value_string) > max_value_len)
1962 value_string[max_value_len] = '\0';
1964 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
1965 !*(boolean *)(setup_info[pos].value))
1966 font_color = FC_BLUE;
1968 DrawText(SX + xpos * 32, SY + ypos * 32,
1969 (xpos == 3 ? " " : " "), FS_BIG, FC_YELLOW);
1970 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, font_size,font_color);
1973 static void changeSetupValue(int pos)
1975 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1977 *(boolean *)setup_info[pos].value ^= TRUE;
1979 else if (setup_info[pos].type & TYPE_KEY)
1983 setup_info[pos].type |= TYPE_QUERY;
1984 drawSetupValue(pos);
1985 setup_info[pos].type &= ~TYPE_QUERY;
1987 key = getSetupKey();
1988 if (key != KSYM_UNDEFINED)
1989 *(Key *)setup_info[pos].value = key;
1992 drawSetupValue(pos);
1995 static void DrawSetupScreen_Generic()
1997 char *title_string = NULL;
2001 CloseDoor(DOOR_CLOSE_2);
2004 if (setup_mode == SETUP_MODE_MAIN)
2006 setup_info = setup_info_main;
2007 title_string = "Setup";
2009 else if (setup_mode == SETUP_MODE_GAME)
2011 setup_info = setup_info_game;
2012 title_string = "Setup Game";
2014 else if (setup_mode == SETUP_MODE_EDITOR)
2016 setup_info = setup_info_editor;
2017 title_string = "Setup Editor";
2019 else if (setup_mode == SETUP_MODE_GRAPHICS)
2021 setup_info = setup_info_graphics;
2022 title_string = "Setup Graphics";
2024 else if (setup_mode == SETUP_MODE_SOUND)
2026 setup_info = setup_info_sound;
2027 title_string = "Setup Sound";
2029 else if (setup_mode == SETUP_MODE_ARTWORK)
2031 setup_info = setup_info_artwork;
2032 title_string = "Custom Artwork";
2034 else if (setup_mode == SETUP_MODE_SHORTCUT)
2036 setup_info = setup_info_shortcut;
2037 title_string = "Setup Shortcuts";
2040 DrawText(SX + 16, SY + 16, title_string, FS_BIG, FC_YELLOW);
2043 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2045 void *value_ptr = setup_info[i].value;
2046 int ypos = MENU_SCREEN_START_YPOS + i;
2047 int font_size = FS_BIG;
2049 /* set some entries to "unchangeable" according to other variables */
2050 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2051 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2052 (value_ptr == &setup.sound_music && !audio.music_available) ||
2053 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2054 setup_info[i].type |= TYPE_GHOSTED;
2056 if (setup_info[i].type & TYPE_STRING)
2057 font_size = FS_MEDIUM;
2059 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, font_size, FC_GREEN);
2061 if (setup_info[i].type & TYPE_ENTER_MENU)
2062 initCursor(i, IMG_ARROW_BLUE_RIGHT);
2063 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2064 initCursor(i, IMG_ARROW_BLUE_LEFT);
2065 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2066 initCursor(i, IMG_BALL_BLUE);
2068 if (setup_info[i].type & TYPE_VALUE)
2076 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2079 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2081 static int choice_store[MAX_SETUP_MODES];
2082 int choice = choice_store[setup_mode]; /* always starts with 0 */
2086 if (button == MB_MENU_INITIALIZE)
2088 /* advance to first valid menu entry */
2089 while (choice < num_setup_info &&
2090 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2092 choice_store[setup_mode] = choice;
2094 drawCursor(choice, FC_RED);
2097 else if (button == MB_MENU_LEAVE)
2099 for (y=0; y<num_setup_info; y++)
2101 if (setup_info[y].type & TYPE_LEAVE_MENU)
2103 void (*menu_callback_function)(void) = setup_info[y].value;
2105 menu_callback_function();
2106 break; /* absolutely needed because function changes 'setup_info'! */
2113 if (mx || my) /* mouse input */
2116 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2118 else if (dx || dy) /* keyboard input */
2122 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2124 if ((setup_info[choice].type & menu_navigation_type) ||
2125 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2126 button = MB_MENU_CHOICE;
2131 /* jump to next non-empty menu entry (up or down) */
2132 while (y > 0 && y < num_setup_info - 1 &&
2133 (setup_info[y].type & TYPE_SKIP_ENTRY))
2137 if (x == 0 && y >= 0 && y < num_setup_info &&
2138 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2144 drawCursor(y, FC_RED);
2145 drawCursor(choice, FC_BLUE);
2146 choice = choice_store[setup_mode] = y;
2149 else if (!(setup_info[y].type & TYPE_GHOSTED))
2151 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2153 void (*menu_callback_function)(void) = setup_info[choice].value;
2155 menu_callback_function();
2159 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2160 (setup_info[y + 1].type & TYPE_KEY))
2163 if (setup_info[y].type & TYPE_VALUE)
2164 changeSetupValue(y);
2171 if (game_status == SETUP)
2175 void DrawSetupScreen_Input()
2178 DrawText(SX+16, SY+16, "Setup Input", FS_BIG, FC_YELLOW);
2180 initCursor(0, IMG_BALL_BLUE);
2181 initCursor(1, IMG_BALL_BLUE);
2182 initCursor(2, IMG_ARROW_BLUE_RIGHT);
2183 initCursor(13, IMG_ARROW_BLUE_LEFT);
2185 drawCursorXY(10, 0, IMG_ARROW_BLUE_LEFT);
2186 drawCursorXY(12, 0, IMG_ARROW_BLUE_RIGHT);
2188 DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
2189 DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
2190 DrawText(SX+32, SY+15*32, "Back", FS_BIG, FC_GREEN);
2193 DeactivateJoystickForCalibration();
2194 DrawTextFCentered(SYSIZE - 20, FC_BLUE,
2195 "Joysticks deactivated on this screen");
2198 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2203 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2205 if (device_name == NULL)
2208 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2211 if (strlen(device_name) > 1)
2213 char c1 = device_name[strlen(device_name) - 1];
2214 char c2 = device_name[strlen(device_name) - 2];
2216 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2217 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2220 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2221 strlen(device_name));
2224 static void drawPlayerSetupInputInfo(int player_nr)
2227 static struct SetupKeyboardInfo custom_key;
2234 { &custom_key.left, "Joystick Left" },
2235 { &custom_key.right, "Joystick Right" },
2236 { &custom_key.up, "Joystick Up" },
2237 { &custom_key.down, "Joystick Down" },
2238 { &custom_key.snap, "Button 1" },
2239 { &custom_key.bomb, "Button 2" }
2241 static char *joystick_name[MAX_PLAYERS] =
2249 custom_key = setup.input[player_nr].key;
2251 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
2252 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER1, player_nr), 0);
2254 if (setup.input[player_nr].use_joystick)
2256 char *device_name = setup.input[player_nr].joy.device_name;
2258 DrawText(SX+8*32, SY+3*32,
2259 joystick_name[getJoystickNrFromDeviceName(device_name)],
2261 DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
2265 DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
2266 DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
2269 DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
2270 drawCursorXY(1, 4, IMG_ARROW_BLUE_LEFT);
2271 drawCursorXY(1, 5, IMG_ARROW_BLUE_RIGHT);
2272 drawCursorXY(1, 6, IMG_ARROW_BLUE_UP);
2273 drawCursorXY(1, 7, IMG_ARROW_BLUE_DOWN);
2274 DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
2275 DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
2276 DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
2277 DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
2278 DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
2279 DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
2283 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2285 DrawText(SX + 3*32, SY + ypos*32,
2286 " ", FS_BIG, FC_YELLOW);
2287 DrawText(SX + 3*32, SY + ypos*32,
2288 (setup.input[player_nr].use_joystick ?
2290 getKeyNameFromKey(*custom[i].key)),
2295 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2297 static int choice = 0;
2298 static int player_nr = 0;
2301 int pos_start = SETUPINPUT_SCREEN_POS_START;
2302 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2303 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2304 int pos_end = SETUPINPUT_SCREEN_POS_END;
2306 if (button == MB_MENU_INITIALIZE)
2308 drawPlayerSetupInputInfo(player_nr);
2309 drawCursor(choice, FC_RED);
2312 else if (button == MB_MENU_LEAVE)
2314 setup_mode = SETUP_MODE_MAIN;
2319 if (mx || my) /* mouse input */
2322 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2324 else if (dx || dy) /* keyboard input */
2326 if (dx && choice == 0)
2327 x = (dx < 0 ? 10 : 12);
2328 else if ((dx && choice == 1) ||
2329 (dx == +1 && choice == 2) ||
2330 (dx == -1 && choice == pos_end))
2331 button = MB_MENU_CHOICE;
2335 if (y >= pos_empty1 && y <= pos_empty2)
2336 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2339 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2341 static unsigned long delay = 0;
2343 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2346 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2348 drawPlayerSetupInputInfo(player_nr);
2350 else if (x == 0 && y >= pos_start && y <= pos_end &&
2351 !(y >= pos_empty1 && y <= pos_empty2))
2357 drawCursor(y, FC_RED);
2358 drawCursor(choice, FC_BLUE);
2366 char *device_name = setup.input[player_nr].joy.device_name;
2368 if (!setup.input[player_nr].use_joystick)
2370 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2372 setJoystickDeviceToNr(device_name, new_device_nr);
2373 setup.input[player_nr].use_joystick = TRUE;
2377 int device_nr = getJoystickNrFromDeviceName(device_name);
2378 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2380 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2381 setup.input[player_nr].use_joystick = FALSE;
2383 setJoystickDeviceToNr(device_name, new_device_nr);
2386 drawPlayerSetupInputInfo(player_nr);
2390 if (setup.input[player_nr].use_joystick)
2393 CalibrateJoystick(player_nr);
2396 CustomizeKeyboard(player_nr);
2398 else if (y == pos_end)
2402 setup_mode = SETUP_MODE_MAIN;
2412 if (game_status == SETUP)
2416 void CustomizeKeyboard(int player_nr)
2420 boolean finished = FALSE;
2421 static struct SetupKeyboardInfo custom_key;
2426 } customize_step[] =
2428 { &custom_key.left, "Move Left" },
2429 { &custom_key.right, "Move Right" },
2430 { &custom_key.up, "Move Up" },
2431 { &custom_key.down, "Move Down" },
2432 { &custom_key.snap, "Snap Field" },
2433 { &custom_key.bomb, "Place Bomb" }
2436 /* read existing key bindings from player setup */
2437 custom_key = setup.input[player_nr].key;
2440 DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
2446 DrawText(SX, SY + (2+2*step_nr)*32,
2447 customize_step[step_nr].text, FS_BIG, FC_RED);
2448 DrawText(SX, SY + (2+2*step_nr+1)*32,
2449 "Key:", FS_BIG, FC_RED);
2450 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2451 getKeyNameFromKey(*customize_step[step_nr].key),
2456 if (PendingEvent()) /* got event */
2464 case EVENT_KEYPRESS:
2466 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2468 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2474 /* all keys configured -- wait for "Escape" or "Return" key */
2478 /* press 'Enter' to keep the existing key binding */
2479 if (key == KSYM_Return)
2480 key = *customize_step[step_nr].key;
2482 /* check if key already used */
2483 for (i=0; i<step_nr; i++)
2484 if (*customize_step[i].key == key)
2489 /* got new key binding */
2490 *customize_step[step_nr].key = key;
2491 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2492 " ", FS_BIG, FC_YELLOW);
2493 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2494 getKeyNameFromKey(key), FS_BIG, FC_YELLOW);
2497 /* un-highlight last query */
2498 DrawText(SX, SY+(2+2*(step_nr-1))*32,
2499 customize_step[step_nr-1].text, FS_BIG, FC_GREEN);
2500 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
2501 "Key:", FS_BIG, FC_GREEN);
2503 /* press 'Enter' to leave */
2506 DrawText(SX + 16, SY + 15*32+16,
2507 "Press Enter", FS_BIG, FC_YELLOW);
2511 /* query next key binding */
2512 DrawText(SX, SY+(2+2*step_nr)*32,
2513 customize_step[step_nr].text, FS_BIG, FC_RED);
2514 DrawText(SX, SY+(2+2*step_nr+1)*32,
2515 "Key:", FS_BIG, FC_RED);
2516 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
2517 getKeyNameFromKey(*customize_step[step_nr].key),
2522 case EVENT_KEYRELEASE:
2523 key_joystick_mapping = 0;
2527 HandleOtherEvents(&event);
2535 /* don't eat all CPU time */
2539 /* write new key bindings back to player setup */
2540 setup.input[player_nr].key = custom_key;
2543 DrawSetupScreen_Input();
2546 static boolean CalibrateJoystickMain(int player_nr)
2548 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2549 int new_joystick_xright = JOYSTICK_XMIDDLE;
2550 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2551 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2552 int new_joystick_xmiddle, new_joystick_ymiddle;
2554 int joystick_fd = joystick.fd[player_nr];
2555 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2556 boolean check[3][3];
2557 int check_remaining = 3 * 3;
2562 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2565 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2574 check[x][y] = FALSE;
2575 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_BALL_BLUE, 0);
2579 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
2580 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
2581 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
2582 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
2583 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FS_BIG, FC_YELLOW);
2584 DrawText(SX, SY + 12 * 32, " AND ", FS_BIG, FC_YELLOW);
2585 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
2587 joy_value = Joystick(player_nr);
2588 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2589 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2591 /* eventually uncalibrated center position (joystick could be uncentered) */
2592 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2595 new_joystick_xmiddle = joy_x;
2596 new_joystick_ymiddle = joy_y;
2598 DrawGraphic(xpos + last_x, ypos + last_y, IMG_BALL_RED, 0);
2601 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2606 if (PendingEvent()) /* got event */
2614 case EVENT_KEYPRESS:
2615 switch(GetEventKey((KeyEvent *)&event, TRUE))
2618 if (check_remaining == 0)
2631 case EVENT_KEYRELEASE:
2632 key_joystick_mapping = 0;
2636 HandleOtherEvents(&event);
2641 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2644 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2645 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2646 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2647 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2649 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2650 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2651 setup.input[player_nr].joy.xright = new_joystick_xright;
2652 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2653 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2654 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2656 CheckJoystickData();
2658 joy_value = Joystick(player_nr);
2660 if (joy_value & JOY_BUTTON && check_remaining == 0)
2663 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2664 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2666 if (x != last_x || y != last_y)
2668 DrawGraphic(xpos + last_x, ypos + last_y, IMG_BALL_YELLOW, 0);
2669 DrawGraphic(xpos + x, ypos + y, IMG_BALL_RED, 0);
2674 if (check_remaining > 0 && !check[x+1][y+1])
2676 check[x+1][y+1] = TRUE;
2682 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2683 setup.input[player_nr].joy.xleft,
2684 setup.input[player_nr].joy.xmiddle,
2685 setup.input[player_nr].joy.xright);
2686 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2687 setup.input[player_nr].joy.yupper,
2688 setup.input[player_nr].joy.ymiddle,
2689 setup.input[player_nr].joy.ylower);
2698 /* don't eat all CPU time */
2702 /* calibrated center position (joystick should now be centered) */
2703 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2706 new_joystick_xmiddle = joy_x;
2707 new_joystick_ymiddle = joy_y;
2711 DrawSetupScreen_Input();
2713 /* wait until the last pressed button was released */
2714 while (Joystick(player_nr) & JOY_BUTTON)
2716 if (PendingEvent()) /* got event */
2721 HandleOtherEvents(&event);
2730 void CalibrateJoystick(int player_nr)
2732 if (!CalibrateJoystickMain(player_nr))
2736 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
2737 DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
2739 Delay(2000); /* show error message for two seconds */
2743 void DrawSetupScreen()
2745 DeactivateJoystick();
2747 if (setup_mode == SETUP_MODE_INPUT)
2748 DrawSetupScreen_Input();
2749 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2750 DrawChooseTree(&artwork.gfx_current);
2751 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2752 DrawChooseTree(&artwork.snd_current);
2753 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2754 DrawChooseTree(&artwork.mus_current);
2756 DrawSetupScreen_Generic();
2759 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2761 if (setup_mode == SETUP_MODE_INPUT)
2762 HandleSetupScreen_Input(mx, my, dx, dy, button);
2763 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2764 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2765 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2766 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2767 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2768 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2770 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2773 void HandleGameActions()
2775 if (game_status != PLAYING)
2778 if (local_player->LevelSolved)
2781 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2789 /* ---------- new screen button stuff -------------------------------------- */
2791 /* graphic position and size values for buttons and scrollbars */
2792 #define SC_SCROLLBUTTON_XSIZE 32
2793 #define SC_SCROLLBUTTON_YSIZE 32
2795 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2796 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2797 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2798 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2799 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2800 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2801 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2802 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2804 #define SC_BORDER_SIZE 14
2808 int gfx_unpressed, gfx_pressed;
2812 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2815 IMG_ARROW_BLUE_UP, IMG_ARROW_RED_UP,
2816 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2817 SCREEN_CTRL_ID_SCROLL_UP,
2821 IMG_ARROW_BLUE_DOWN, IMG_ARROW_RED_DOWN,
2822 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2823 SCREEN_CTRL_ID_SCROLL_DOWN,
2830 int gfx_unpressed, gfx_pressed;
2836 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2839 IMG_SCROLLBAR_BLUE, IMG_SCROLLBAR_RED,
2840 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2841 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2842 GD_TYPE_SCROLLBAR_VERTICAL,
2843 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2844 "scroll level series vertically"
2848 static void CreateScreenScrollbuttons()
2850 struct GadgetInfo *gi;
2851 unsigned long event_mask;
2854 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2856 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2857 int gfx_unpressed, gfx_pressed;
2858 int x, y, width, height;
2859 int gd_x1, gd_x2, gd_y1, gd_y2;
2860 int id = scrollbutton_info[i].gadget_id;
2862 x = scrollbutton_info[i].x;
2863 y = scrollbutton_info[i].y;
2865 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2869 width = SC_SCROLLBUTTON_XSIZE;
2870 height = SC_SCROLLBUTTON_YSIZE;
2872 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2873 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2874 gd_bitmap_unpressed = new_graphic_info[gfx_unpressed].bitmap;
2875 gd_bitmap_pressed = new_graphic_info[gfx_pressed].bitmap;
2876 gd_x1 = new_graphic_info[gfx_unpressed].src_x;
2877 gd_y1 = new_graphic_info[gfx_unpressed].src_y;
2878 gd_x2 = new_graphic_info[gfx_pressed].src_x;
2879 gd_y2 = new_graphic_info[gfx_pressed].src_y;
2881 gi = CreateGadget(GDI_CUSTOM_ID, id,
2882 GDI_CUSTOM_TYPE_ID, i,
2883 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2888 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2889 GDI_STATE, GD_BUTTON_UNPRESSED,
2890 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2891 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2892 GDI_EVENT_MASK, event_mask,
2893 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2897 Error(ERR_EXIT, "cannot create gadget");
2899 screen_gadget[id] = gi;
2903 static void CreateScreenScrollbars()
2907 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2909 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2910 int gfx_unpressed, gfx_pressed;
2911 int gd_x1, gd_x2, gd_y1, gd_y2;
2912 struct GadgetInfo *gi;
2913 int items_max, items_visible, item_position;
2914 unsigned long event_mask;
2915 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2916 int id = scrollbar_info[i].gadget_id;
2918 items_max = num_page_entries;
2919 items_visible = num_page_entries;
2922 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2924 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2925 gfx_pressed = scrollbar_info[i].gfx_pressed;
2926 gd_bitmap_unpressed = new_graphic_info[gfx_unpressed].bitmap;
2927 gd_bitmap_pressed = new_graphic_info[gfx_pressed].bitmap;
2928 gd_x1 = new_graphic_info[gfx_unpressed].src_x;
2929 gd_y1 = new_graphic_info[gfx_unpressed].src_y;
2930 gd_x2 = new_graphic_info[gfx_pressed].src_x;
2931 gd_y2 = new_graphic_info[gfx_pressed].src_y;
2933 gi = CreateGadget(GDI_CUSTOM_ID, id,
2934 GDI_CUSTOM_TYPE_ID, i,
2935 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2936 GDI_X, scrollbar_info[i].x,
2937 GDI_Y, scrollbar_info[i].y,
2938 GDI_WIDTH, scrollbar_info[i].width,
2939 GDI_HEIGHT, scrollbar_info[i].height,
2940 GDI_TYPE, scrollbar_info[i].type,
2941 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2942 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2943 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2944 GDI_STATE, GD_BUTTON_UNPRESSED,
2945 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2946 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2947 GDI_BORDER_SIZE, SC_BORDER_SIZE,
2948 GDI_EVENT_MASK, event_mask,
2949 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2953 Error(ERR_EXIT, "cannot create gadget");
2955 screen_gadget[id] = gi;
2959 void CreateScreenGadgets()
2961 CreateScreenScrollbuttons();
2962 CreateScreenScrollbars();
2965 void FreeScreenGadgets()
2969 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2970 FreeGadget(screen_gadget[i]);
2973 void MapChooseTreeGadgets(TreeInfo *ti)
2975 int num_entries = numTreeInfoInGroup(ti);
2978 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
2981 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2982 MapGadget(screen_gadget[i]);
2985 void UnmapChooseTreeGadgets()
2989 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2990 UnmapGadget(screen_gadget[i]);
2993 static void HandleScreenGadgets(struct GadgetInfo *gi)
2995 int id = gi->custom_id;
2997 if (game_status != CHOOSELEVEL && game_status != SETUP)
3002 case SCREEN_CTRL_ID_SCROLL_UP:
3003 if (game_status == CHOOSELEVEL)
3004 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3005 else if (game_status == SETUP)
3006 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3009 case SCREEN_CTRL_ID_SCROLL_DOWN:
3010 if (game_status == CHOOSELEVEL)
3011 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3012 else if (game_status == SETUP)
3013 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3016 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3017 if (game_status == CHOOSELEVEL)
3018 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3019 else if (game_status == SETUP)
3020 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);