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 pos, int color, int graphic)
76 static int cursor_array[SCR_FIELDY];
79 cursor_array[pos] = graphic;
81 graphic = cursor_array[pos];
84 graphic = (graphic == IMG_ARROW_BLUE_LEFT ? IMG_ARROW_RED_LEFT :
85 graphic == IMG_ARROW_BLUE_RIGHT ? IMG_ARROW_RED_RIGHT :
88 DrawGraphic(0, MENU_SCREEN_START_YPOS + pos, graphic, 0);
91 static void initCursor(int pos, int graphic)
93 drawCursorExt(pos, FC_BLUE, graphic);
96 static void drawCursor(int pos, int color)
98 drawCursorExt(pos, color, 0);
103 int x = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * FONT1_XSIZE) / 2;
105 DrawText(x, SY + 8, PROGRAM_TITLE_STRING, FS_BIG, FC_YELLOW);
106 DrawTextFCentered(46, FC_RED, WINDOW_SUBTITLE_STRING);
109 static void ToggleFullscreenIfNeeded()
111 if (setup.fullscreen != video.fullscreen_enabled)
113 /* save old door content */
114 BlitBitmap(backbuffer, bitmap_db_door,
115 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
117 /* toggle fullscreen */
118 ChangeVideoModeIfNeeded(setup.fullscreen);
119 setup.fullscreen = video.fullscreen_enabled;
121 /* redraw background to newly created backbuffer */
122 BlitBitmap(new_graphic_info[IMG_MENU_BACK].bitmap, backbuffer,
123 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
125 /* restore old door content */
126 BlitBitmap(bitmap_db_door, backbuffer,
127 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
129 redraw_mask = REDRAW_ALL;
135 static LevelDirTree *leveldir_last_valid = NULL;
137 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
141 KeyboardAutoRepeatOn();
143 SetDrawDeactivationMask(REDRAW_NONE);
144 audio.sound_deactivated = FALSE;
146 /* needed if last screen was the playing screen, invoked from level editor */
147 if (level_editor_test_game)
149 game_status = LEVELED;
154 /* needed if last screen was the editor screen */
155 UndrawSpecialEditorDoor();
157 /* needed if last screen was the setup screen and fullscreen state changed */
158 ToggleFullscreenIfNeeded();
160 /* needed if last screen (level choice) changed graphics, sounds or music */
161 ReloadCustomArtwork();
164 SetDrawtoField(DRAW_BACKBUFFER);
167 /* map gadgets for main menu screen */
170 /* leveldir_current may be invalid (level group, parent link) */
171 if (!validLevelSeries(leveldir_current))
172 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
174 /* store valid level series information */
175 leveldir_last_valid = leveldir_current;
177 /* level_nr may have been set to value over handicap with level editor */
178 if (setup.handicap && level_nr > leveldir_current->handicap_level)
179 level_nr = leveldir_current->handicap_level;
186 DrawText(SX + 32, SY + 2*32, name_text, FS_BIG, FC_GREEN);
187 DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
188 DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
189 DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
190 (leveldir_current->readonly ? FC_RED : FC_YELLOW));
191 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
192 DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
193 DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
194 DrawText(SX + 32, SY + 7*32, "Start Game", FS_BIG, FC_GREEN);
195 DrawText(SX + 32, SY + 8*32, "Setup", FS_BIG, FC_GREEN);
196 DrawText(SX + 32, SY + 9*32, "Quit", FS_BIG, FC_GREEN);
198 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
200 DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
201 leveldir_current->first_level,
202 leveldir_current->last_level);
204 if (leveldir_current->readonly)
206 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
207 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
211 initCursor(i, (i == 1 || i == 6 ? IMG_ARROW_BLUE_RIGHT : IMG_BALL_BLUE));
213 DrawGraphic(10, 3, IMG_ARROW_BLUE_LEFT, 0);
214 DrawGraphic(14, 3, IMG_ARROW_BLUE_RIGHT, 0);
216 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
219 if (leveldir_current->name)
221 int len = strlen(leveldir_current->name);
222 int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
223 int lypos = SY + 352;
225 DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
230 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
233 if (TAPE_IS_EMPTY(tape))
235 DrawCompleteVideoDisplay();
237 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
244 static void gotoTopLevelDir()
246 /* move upwards to top level directory */
247 while (leveldir_current->node_parent)
249 /* write a "path" into level tree for easy navigation to last level */
250 if (leveldir_current->node_parent->node_group->cl_first == -1)
252 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
253 int leveldir_pos = posTreeInfo(leveldir_current);
254 int num_page_entries;
255 int cl_first, cl_cursor;
257 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
258 num_page_entries = num_leveldirs;
260 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
262 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
263 cl_cursor = leveldir_pos - cl_first;
265 leveldir_current->node_parent->node_group->cl_first = cl_first;
266 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
269 leveldir_current = leveldir_current->node_parent;
273 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
275 static int choice = 0;
279 if (button == MB_MENU_INITIALIZE)
281 drawCursor(choice, FC_RED);
285 if (mx || my) /* mouse input */
288 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
290 else if (dx || dy) /* keyboard input */
292 if (dx && choice == 1)
293 x = (dx < 0 ? 10 : 14);
298 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
299 (x == 14 && level_nr < leveldir_current->last_level)) &&
302 static unsigned long level_delay = 0;
303 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
304 int new_level_nr, old_level_nr = level_nr;
305 int font_color = (leveldir_current->readonly ? FC_RED : FC_YELLOW);
307 new_level_nr = level_nr + (x == 10 ? -step : +step);
308 if (new_level_nr < leveldir_current->first_level)
309 new_level_nr = leveldir_current->first_level;
310 if (new_level_nr > leveldir_current->last_level)
311 new_level_nr = leveldir_current->last_level;
313 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
314 new_level_nr = leveldir_current->handicap_level;
316 if (old_level_nr == new_level_nr ||
317 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
320 level_nr = new_level_nr;
322 DrawTextExt(drawto, SX + 11 * 32, SY + 3 * 32,
323 int2str(level_nr, 3), FS_BIG, font_color);
324 DrawTextExt(window, SX + 11 * 32, SY + 3 * 32,
325 int2str(level_nr, 3), FS_BIG, font_color);
328 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
332 DrawCompleteVideoDisplay();
334 /* needed because DrawMicroLevel() takes some time */
337 DelayReached(&level_delay, 0); /* reset delay counter */
339 else if (x == 0 && y >= 0 && y <= 7)
345 drawCursor(y, FC_RED);
346 drawCursor(choice, FC_BLUE);
354 game_status = TYPENAME;
355 HandleTypeName(strlen(setup.player_name), 0);
361 game_status = CHOOSELEVEL;
362 SaveLevelSetup_LastSeries();
363 SaveLevelSetup_SeriesInfo();
372 game_status = HALLOFFAME;
377 if (leveldir_current->readonly &&
378 strcmp(setup.player_name, "Artsoft") != 0)
379 Request("This level is read only !", REQ_CONFIRM);
380 game_status = LEVELED;
385 game_status = HELPSCREEN;
390 if (setup.autorecord)
391 TapeStartRecording();
393 #if defined(PLATFORM_UNIX)
395 SendToServer_StartPlaying();
399 game_status = PLAYING;
407 setup_mode = SETUP_MODE_MAIN;
412 SaveLevelSetup_LastSeries();
413 SaveLevelSetup_SeriesInfo();
414 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
415 game_status = EXITGAME;
424 if (game_status == MAINMENU)
426 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
432 #define MAX_HELPSCREEN_ELS 10
436 static long helpscreen_state;
437 static int helpscreen_step[MAX_HELPSCREEN_ELS];
438 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
440 static int OLD_helpscreen_action[] =
442 GFX_SPIELER1_DOWN,4,2,
444 GFX_SPIELER1_LEFT,4,2,
445 GFX_SPIELER1_RIGHT,4,2,
446 GFX_SPIELER1_PUSH_LEFT,4,2,
447 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
448 GFX_ERDREICH,1,100, HA_NEXT,
449 GFX_LEERRAUM,1,100, HA_NEXT,
450 GFX_MORAST_LEER,1,100, HA_NEXT,
451 GFX_BETON,1,100, HA_NEXT,
452 GFX_MAUERWERK,1,100, HA_NEXT,
453 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
454 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
455 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
456 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
457 GFX_UNSICHTBAR,1,100, HA_NEXT,
458 GFX_FELSBODEN,1,100, HA_NEXT,
459 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
460 GFX_EDELSTEIN,2,5, HA_NEXT,
461 GFX_DIAMANT,2,5, HA_NEXT,
462 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
463 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
464 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
465 GFX_FELSBROCKEN,4,5, HA_NEXT,
466 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
467 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
468 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
469 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
470 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
471 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
472 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
473 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
474 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
475 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
476 GFX_GEBLUBBER,4,4, HA_NEXT,
477 GFX_SCHLUESSEL1,4,25, HA_NEXT,
478 GFX_PFORTE1,4,25, HA_NEXT,
479 GFX_PFORTE1X,4,25, HA_NEXT,
480 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
481 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
482 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
483 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
484 GFX_LEERRAUM,1,10, HA_NEXT,
485 GFX_DYNABOMB_NR,1,100, HA_NEXT,
486 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
487 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
488 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
489 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
490 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
491 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
492 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
493 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
494 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
495 GFX_BUTTERFLY,2,2, HA_NEXT,
496 GFX_FIREFLY,2,2, HA_NEXT,
497 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
498 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
499 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
500 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
501 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
502 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
503 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
504 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
505 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
506 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
510 GFX_MOLE_RIGHT,4,2, HA_NEXT,
511 GFX_PINGUIN_DOWN,4,2,
513 GFX_PINGUIN_LEFT,4,2,
514 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
515 GFX_SCHWEIN_DOWN,4,2,
517 GFX_SCHWEIN_LEFT,4,2,
518 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
522 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
523 GFX_SONDE_START,8,1, HA_NEXT,
524 GFX_ABLENK,4,1, HA_NEXT,
525 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
526 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
527 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
528 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
529 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
530 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
531 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
532 GFX_DIAMANT,1,10, HA_NEXT,
533 GFX_LIFE,1,100, HA_NEXT,
534 GFX_LIFE_ASYNC,1,100, HA_NEXT,
535 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
536 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
537 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
538 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
539 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
540 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
541 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
542 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
543 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
544 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
545 GFX_SPEED_PILL,1,100, HA_NEXT,
550 static int helpscreen_action[] =
552 IMG_PLAYER1_DOWN_MOVING, 16,
553 IMG_PLAYER1_UP_MOVING, 16,
554 IMG_PLAYER1_LEFT_MOVING, 16,
555 IMG_PLAYER1_RIGHT_MOVING, 16,
556 IMG_PLAYER1_LEFT_PUSHING, 16,
557 IMG_PLAYER1_RIGHT_PUSHING, 16, HA_NEXT,
559 IMG_SAND, -1, HA_NEXT,
561 IMG_EMPTY_SPACE, -1, HA_NEXT,
563 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
565 IMG_STEELWALL, -1, HA_NEXT,
567 IMG_WALL, -1, HA_NEXT,
569 IMG_WALL_GROWING_ACTIVE_LEFT, 20,
572 IMG_WALL_GROWING_ACTIVE_RIGHT, 20,
575 IMG_WALL_GROWING_ACTIVE_UP, 20,
578 IMG_WALL_GROWING_ACTIVE_DOWN, 20,
580 IMG_EMPTY_SPACE, 20, HA_NEXT,
582 IMG_INVISIBLE_WALL, -1, HA_NEXT,
584 IMG_WALL_CRUMBLED, -1, HA_NEXT,
586 IMG_INFO_FONT_EM_1, 160,
587 IMG_INFO_FONT_EM_2, 160,
588 IMG_INFO_FONT_EM_3, 160,
589 IMG_INFO_FONT_EM_4, 160,
590 IMG_INFO_FONT_EM_5, 40, HA_NEXT,
592 IMG_EMERALD, -1, HA_NEXT,
594 IMG_DIAMOND, -1, HA_NEXT,
596 IMG_BD_DIAMOND, -1, HA_NEXT,
598 IMG_EMERALD_YELLOW, 50,
600 IMG_EMERALD_PURPLE, 50, HA_NEXT,
602 IMG_BD_ROCK, -1, HA_NEXT,
606 IMG_EMPTY_SPACE, 10, HA_NEXT,
610 IMG_EMERALD, 20, HA_NEXT,
612 IMG_WALL_EMERALD, 100,
614 IMG_EMERALD, 20, HA_NEXT,
616 IMG_WALL_DIAMOND, 100,
618 IMG_DIAMOND, 20, HA_NEXT,
620 IMG_WALL_BD_DIAMOND, 100,
622 IMG_BD_DIAMOND, 20, HA_NEXT,
624 IMG_WALL_EMERALD_YELLOW, 100,
626 IMG_EMERALD_YELLOW, 20,
627 IMG_WALL_EMERALD_RED, 100,
630 IMG_WALL_EMERALD_PURPLE, 100,
632 IMG_EMERALD_PURPLE, 20, HA_NEXT,
634 IMG_ACID, -1, HA_NEXT,
639 IMG_KEY4, 50, HA_NEXT,
644 IMG_GATE4, 50, HA_NEXT,
649 IMG_GATE4_GRAY, 50, HA_NEXT,
651 IMG_DYNAMITE, -1, HA_NEXT,
653 IMG_DYNAMITE_ACTIVE, 96,
655 IMG_EMPTY_SPACE, 20, HA_NEXT,
657 IMG_DYNABOMB_ACTIVE, 100,
659 IMG_EMPTY_SPACE, 20, HA_NEXT,
661 IMG_DYNABOMB_NR, -1, HA_NEXT,
663 IMG_DYNABOMB_SZ, -1, HA_NEXT,
665 IMG_SPACESHIP_RIGHT, 16,
666 IMG_SPACESHIP_UP, 16,
667 IMG_SPACESHIP_LEFT, 16,
668 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
673 IMG_BUG_DOWN, 16, HA_NEXT,
675 IMG_BD_BUTTERFLY, -1, HA_NEXT,
677 IMG_BD_FIREFLY, -1, HA_NEXT,
679 IMG_PACMAN_RIGHT, 16,
682 IMG_PACMAN_DOWN, 16, HA_NEXT,
684 IMG_YAMYAM, -1, HA_NEXT,
686 IMG_DARK_YAMYAM, -1, HA_NEXT,
688 IMG_ROBOT, -1, HA_NEXT,
690 IMG_MOLE_RIGHT_MOVING, 16,
691 IMG_MOLE_UP_MOVING, 16,
692 IMG_MOLE_LEFT_MOVING, 16,
693 IMG_MOLE_DOWN_MOVING, 16, HA_NEXT,
695 IMG_PENGUIN_RIGHT_MOVING, 16,
696 IMG_PENGUIN_UP_MOVING, 16,
697 IMG_PENGUIN_LEFT_MOVING, 16,
698 IMG_PENGUIN_DOWN_MOVING, 16, HA_NEXT,
700 IMG_PIG_RIGHT_MOVING, 16,
701 IMG_PIG_UP_MOVING, 16,
702 IMG_PIG_LEFT_MOVING, 16,
703 IMG_PIG_DOWN_MOVING, 16, HA_NEXT,
705 IMG_DRAGON_RIGHT_MOVING, 16,
706 IMG_DRAGON_UP_MOVING, 16,
707 IMG_DRAGON_LEFT_MOVING, 16,
708 IMG_DRAGON_DOWN_MOVING, 16, HA_NEXT,
710 IMG_SATELLITE, -1, HA_NEXT,
713 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
716 IMG_LAMP_ACTIVE, 50, HA_NEXT,
718 IMG_TIME_ORB_FULL, 50,
719 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
722 IMG_AMOEBA_CREATING, 6,
723 IMG_AMOEBA_WET, 20, HA_NEXT,
725 IMG_AMOEBA_DEAD, -1, HA_NEXT,
727 IMG_AMOEBA_WET, -1, HA_NEXT,
730 IMG_AMOEBA_CREATING, 6, HA_NEXT,
735 IMG_DIAMOND, 20, HA_NEXT,
737 IMG_GAMEOFLIFE, -1, HA_NEXT,
739 IMG_BIOMAZE, -1, HA_NEXT,
741 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
743 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
745 IMG_EXIT_CLOSED, 200,
746 IMG_EXIT_OPENING, 16,
747 IMG_EXIT_OPEN, 100, HA_NEXT,
749 IMG_EXIT_OPEN, -1, HA_NEXT,
751 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
753 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
755 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
757 IMG_SPEED_PILL, -1, HA_NEXT,
761 static char *helpscreen_eltext[][2] =
763 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
764 {"Normal sand:", "You can dig through it"},
765 {"Empty field:", "You can walk through it"},
766 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
767 {"Massive Wall:", "Nothing can go through it"},
768 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
769 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
770 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
771 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
772 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
773 {"Emerald: You must collect enough of","them to finish a level"},
774 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
775 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
776 {"Colorful Gems:", "Seem to behave like Emeralds"},
777 {"Rock: Smashes several things;", "Can be moved by the player"},
778 {"Bomb: You can move it, but be", "careful when dropping it"},
779 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
780 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
781 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
782 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
783 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
784 {"Acid: Things that fall in are gone", "forever (including our hero)"},
785 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
786 {"Door: Can be opened by the key", "with the same color"},
787 {"Door: You have to find out the", "right color of the key for it"},
788 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
789 {"Dynamite: This one explodes after", "a few seconds"},
790 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
791 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
792 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
793 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
794 {"Bug: Moves at the right side", "of walls; don't touch it!"},
795 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
796 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
797 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
798 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
799 {"Cruncher (BD style):", "Eats almost everything"},
800 {"Robot: Tries to kill the player", ""},
801 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
802 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
803 {"The Pig: Harmless, but eats all", "gems it can get"},
804 {"The Dragon: Breathes fire,", "especially to some monsters"},
805 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
806 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
807 {"Light Bulb: All of them must be", "switched on to finish a level"},
808 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
809 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
810 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
811 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
812 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
813 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
814 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
815 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
816 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
817 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
818 {"Exit door: Opens if you have enough","emeralds to finish the level"},
819 {"Open exit door: Enter here to leave","the level and exit the actual game"},
820 {"Sokoban element: Object which must", "be pushed to an empty field"},
821 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
822 {"Sokoban element: Field with object", "which can be pushed away"},
823 {"Speed pill: Lets the player run", "twice as fast as normally"},
825 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
827 static char *helpscreen_music[][3] =
829 { "Alchemy", "Ian Boddy", "Drive" },
830 { "The Chase", "Propaganda", "A Secret Wish" },
831 { "Network 23", "Tangerine Dream", "Exit" },
832 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
833 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
834 { "Voyager", "The Alan Parsons Project","Pyramid" },
835 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
837 static int num_helpscreen_music = 7;
838 static int helpscreen_musicpos;
841 void OLD_DrawHelpScreenElAction(int start)
845 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
847 while(helpscreen_action[j] != HA_END)
849 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
851 else if (i<start || helpscreen_delay[i-start])
853 if (i>=start && helpscreen_delay[i-start])
854 helpscreen_delay[i-start]--;
856 while(helpscreen_action[j] != HA_NEXT)
863 j += 3*helpscreen_step[i-start];
864 graphic = helpscreen_action[j++];
866 if (helpscreen_frame[i-start])
868 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
869 helpscreen_frame[i-start]--;
874 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
877 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
879 if (helpscreen_action[j] == HA_NEXT)
881 if (!helpscreen_frame[i-start])
882 helpscreen_step[i-start] = 0;
886 if (!helpscreen_frame[i-start])
887 helpscreen_step[i-start]++;
888 while(helpscreen_action[j] != HA_NEXT)
893 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
905 void DrawHelpScreenElAction(int start)
908 int xstart = SX + 16;
909 int ystart = SY + 64 + 2 * 32;
910 int ystep = TILEY + 4;
916 while (helpscreen_action[j] != HA_END)
918 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
922 while (helpscreen_action[j] != HA_NEXT)
931 j += 2 * helpscreen_step[i-start];
932 graphic = helpscreen_action[j++];
933 frame_count = helpscreen_action[j++];
934 if (frame_count == -1)
935 frame_count = 1000000;
937 if (helpscreen_frame[i-start] == 0)
940 helpscreen_frame[i-start] = frame_count - 1;
944 sync_frame = frame_count - helpscreen_frame[i-start];
945 helpscreen_frame[i-start]--;
948 if (helpscreen_action[j] == HA_NEXT)
950 if (!helpscreen_frame[i-start])
951 helpscreen_step[i-start] = 0;
955 if (!helpscreen_frame[i-start])
956 helpscreen_step[i-start]++;
957 while(helpscreen_action[j] != HA_NEXT)
962 frame = getGraphicAnimationFrame(graphic, sync_frame);
964 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
979 void DrawHelpScreenElText(int start)
982 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
983 int ybottom = SYSIZE - 20;
988 DrawTextFCentered(100, FC_GREEN, "The game elements:");
990 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
993 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
994 helpscreen_eltext[i][0], FS_SMALL, FC_YELLOW);
995 DrawText(xstart, ystart + (i - start) * ystep + 16,
996 helpscreen_eltext[i][1], FS_SMALL, FC_YELLOW);
999 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1002 void DrawHelpScreenMusicText(int num)
1004 int ystart = 150, ystep = 30;
1005 int ybottom = SYSIZE - 20;
1011 DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
1013 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1015 DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
1016 helpscreen_music[num][0]);
1017 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
1019 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
1020 "%s", helpscreen_music[num][1]);
1021 DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
1023 DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
1024 helpscreen_music[num][2]);
1026 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1029 PlaySoundLoop(background_loop[num]);
1033 void DrawHelpScreenCreditsText()
1035 int ystart = 150, ystep = 30;
1036 int ybottom = SYSIZE - 20;
1042 DrawTextFCentered(100, FC_GREEN,
1044 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1045 "DOS port of the game:");
1046 DrawTextFCentered(ystart + 1 * ystep, FC_RED,
1048 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
1049 "Additional toons:");
1050 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
1052 DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
1053 "...and many thanks to all contributors");
1054 DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
1057 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1060 void DrawHelpScreenContactText()
1062 int ystart = 150, ystep = 30;
1063 int ybottom = SYSIZE - 20;
1068 DrawTextFCentered(100, FC_GREEN, "Program information:");
1070 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1071 "This game is Freeware!");
1072 DrawTextFCentered(ystart + 1 * ystep, FC_YELLOW,
1073 "If you like it, send e-mail to:");
1074 DrawTextFCentered(ystart + 2 * ystep, FC_RED,
1075 "info@artsoft.org");
1076 DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
1077 "or SnailMail to:");
1078 DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
1080 DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
1081 "Detmolder Strasse 189");
1082 DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
1084 DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
1087 DrawTextFCentered(ystart + 7 * ystep, FC_YELLOW,
1088 "If you have created new levels,");
1089 DrawTextFCentered(ystart + 8 * ystep, FC_YELLOW,
1090 "send them to me to include them!");
1091 DrawTextFCentered(ystart + 9 * ystep, FC_YELLOW,
1094 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
1097 void DrawHelpScreen()
1102 CloseDoor(DOOR_CLOSE_2);
1104 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1105 helpscreen_step[i] = helpscreen_frame[i] = 0;
1106 helpscreen_musicpos = 0;
1107 helpscreen_state = 0;
1108 DrawHelpScreenElText(0);
1109 DrawHelpScreenElAction(0);
1113 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1116 void HandleHelpScreen(int button)
1118 static unsigned long hs_delay = 0;
1119 int num_helpscreen_els_pages =
1120 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1121 int button_released = !button;
1124 if (button_released)
1126 if (helpscreen_state < num_helpscreen_els_pages - 1)
1128 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1129 helpscreen_step[i] = helpscreen_frame[i] = 0;
1133 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1134 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1136 else if (helpscreen_state <
1137 num_helpscreen_els_pages + num_helpscreen_music - 1)
1140 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1142 else if (helpscreen_state ==
1143 num_helpscreen_els_pages + num_helpscreen_music - 1)
1146 DrawHelpScreenCreditsText();
1148 else if (helpscreen_state ==
1149 num_helpscreen_els_pages + num_helpscreen_music)
1152 DrawHelpScreenContactText();
1158 game_status = MAINMENU;
1163 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1165 if (helpscreen_state < num_helpscreen_els_pages)
1166 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1169 /* !!! workaround for playing "music" that is really a sound loop (and
1170 must therefore periodically be reactivated with the current sound
1172 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1180 void HandleTypeName(int newxpos, Key key)
1182 static int xpos = 0, ypos = 2;
1187 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
1188 DrawGraphic(xpos + 6, ypos, IMG_BALL_RED, 0);
1192 if (((key >= KSYM_A && key <= KSYM_Z) ||
1193 (key >= KSYM_a && key <= KSYM_z)) &&
1194 xpos < MAX_PLAYER_NAME_LEN)
1198 if (key >= KSYM_A && key <= KSYM_Z)
1199 ascii = 'A' + (char)(key - KSYM_A);
1201 ascii = 'a' + (char)(key - KSYM_a);
1203 setup.player_name[xpos] = ascii;
1204 setup.player_name[xpos + 1] = 0;
1206 DrawTextExt(drawto, SX + 6*32, SY + ypos*32,
1207 setup.player_name, FS_BIG, FC_YELLOW);
1208 DrawTextExt(window, SX + 6*32, SY + ypos*32,
1209 setup.player_name, FS_BIG, FC_YELLOW);
1210 DrawGraphic(xpos + 6, ypos, IMG_BALL_RED, 0);
1212 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1215 setup.player_name[xpos] = 0;
1216 DrawGraphic(xpos + 6, ypos, IMG_BALL_RED, 0);
1217 DrawGraphic(xpos + 7, ypos, IMG_EMPTY, 0);
1219 else if (key == KSYM_Return && xpos > 0)
1221 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_RED);
1222 DrawGraphic(xpos + 6, ypos, IMG_EMPTY, 0);
1225 game_status = MAINMENU;
1231 static void DrawChooseTree(TreeInfo **ti_ptr)
1234 CloseDoor(DOOR_CLOSE_2);
1237 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1238 MapChooseTreeGadgets(*ti_ptr);
1244 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1246 struct GadgetInfo *gi = screen_gadget[id];
1247 int items_max, items_visible, item_position;
1249 items_max = numTreeInfoInGroup(ti);
1250 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1251 item_position = first_entry;
1253 if (item_position > items_max - items_visible)
1254 item_position = items_max - items_visible;
1256 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1257 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1260 static void drawChooseTreeList(int first_entry, int num_page_entries,
1264 char buffer[SCR_FIELDX * 2];
1265 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1266 int num_entries = numTreeInfoInGroup(ti);
1267 char *title_string = NULL;
1268 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1270 ClearRectangle(backbuffer, SX, SY, SXSIZE - 32, SYSIZE);
1271 redraw_mask |= REDRAW_FIELD;
1274 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1275 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1276 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1277 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1279 DrawText(SX + offset, SY + offset, title_string, FS_BIG,
1280 (ti->type == TREE_TYPE_LEVEL_DIR ? FC_GREEN : FC_YELLOW));
1282 for(i=0; i<num_page_entries; i++)
1284 TreeInfo *node, *node_first;
1285 int entry_pos = first_entry + i;
1286 int ypos = MENU_SCREEN_START_YPOS + i;
1288 node_first = getTreeInfoFirstGroupEntry(ti);
1289 node = getTreeInfoFromPos(node_first, entry_pos);
1291 strncpy(buffer, node->name , max_buffer_len);
1292 buffer[max_buffer_len] = '\0';
1294 DrawText(SX + 32, SY + ypos * 32, buffer, FS_MEDIUM, node->color);
1296 if (node->parent_link)
1297 initCursor(i, IMG_ARROW_BLUE_LEFT);
1298 else if (node->level_group)
1299 initCursor(i, IMG_ARROW_BLUE_RIGHT);
1301 initCursor(i, IMG_BALL_BLUE);
1304 if (first_entry > 0)
1305 DrawGraphic(0, 1, IMG_ARROW_BLUE_UP, 0);
1307 if (first_entry + num_page_entries < num_entries)
1308 DrawGraphic(0, MAX_MENU_ENTRIES_ON_SCREEN + 1, IMG_ARROW_BLUE_DOWN, 0);
1311 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1313 TreeInfo *node, *node_first;
1314 int x, last_redraw_mask = redraw_mask;
1316 if (ti->type != TREE_TYPE_LEVEL_DIR)
1319 node_first = getTreeInfoFirstGroupEntry(ti);
1320 node = getTreeInfoFromPos(node_first, entry_pos);
1322 ClearRectangle(drawto, SX + 32, SY + 32, SXSIZE - 64, 32);
1324 if (node->parent_link)
1325 DrawTextFCentered(40, FC_RED, "leave group \"%s\"", node->class_desc);
1326 else if (node->level_group)
1327 DrawTextFCentered(40, FC_RED, "enter group \"%s\"", node->class_desc);
1328 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1329 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
1330 node->levels, node->class_desc);
1332 /* let BackToFront() redraw only what is needed */
1333 redraw_mask = last_redraw_mask | REDRAW_TILES;
1334 for (x=0; x<SCR_FIELDX; x++)
1335 MarkTileDirty(x, 1);
1338 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1341 static unsigned long choose_delay = 0;
1342 TreeInfo *ti = *ti_ptr;
1344 int y = ti->cl_cursor;
1345 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1346 int num_entries = numTreeInfoInGroup(ti);
1347 int num_page_entries;
1349 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1350 num_page_entries = num_entries;
1352 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1354 if (button == MB_MENU_INITIALIZE)
1356 int entry_pos = posTreeInfo(ti);
1358 if (ti->cl_first == -1)
1360 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1362 entry_pos - ti->cl_first;
1365 if (dx == 999) /* first entry is set by scrollbar position */
1368 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1371 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1372 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1373 drawCursor(ti->cl_cursor, FC_RED);
1376 else if (button == MB_MENU_LEAVE)
1378 if (ti->node_parent)
1380 *ti_ptr = ti->node_parent;
1381 DrawChooseTree(ti_ptr);
1383 else if (game_status == SETUP)
1389 game_status = MAINMENU;
1396 if (mx || my) /* mouse input */
1399 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1401 else if (dx || dy) /* keyboard input */
1404 y = ti->cl_cursor + dy;
1406 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1409 step = num_page_entries - 1;
1410 y = (dy < 0 ? -1 : num_page_entries);
1414 if (x == 0 && y == -1)
1416 if (ti->cl_first > 0 &&
1417 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1419 ti->cl_first -= step;
1420 if (ti->cl_first < 0)
1423 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1424 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1425 drawCursor(ti->cl_cursor, FC_RED);
1426 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1431 else if (x == 0 && y > num_page_entries - 1)
1433 if (ti->cl_first + num_page_entries < num_entries &&
1434 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1436 ti->cl_first += step;
1437 if (ti->cl_first + num_page_entries > num_entries)
1438 ti->cl_first = MAX(0, num_entries - num_page_entries);
1440 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1441 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1442 drawCursor(ti->cl_cursor, FC_RED);
1443 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1451 TreeInfo *node_first, *node_cursor;
1452 int entry_pos = ti->cl_first + y;
1454 node_first = getTreeInfoFirstGroupEntry(ti);
1455 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1457 if (node_cursor->node_group)
1459 node_cursor->cl_first = ti->cl_first;
1460 node_cursor->cl_cursor = ti->cl_cursor;
1461 *ti_ptr = node_cursor->node_group;
1462 DrawChooseTree(ti_ptr);
1466 else if (dx == -1 && ti->node_parent)
1468 *ti_ptr = ti->node_parent;
1469 DrawChooseTree(ti_ptr);
1473 if (x == 0 && y >= 0 && y < num_page_entries)
1477 if (y != ti->cl_cursor)
1479 drawCursor(y, FC_RED);
1480 drawCursor(ti->cl_cursor, FC_BLUE);
1481 drawChooseTreeInfo(ti->cl_first + y, ti);
1487 TreeInfo *node_first, *node_cursor;
1488 int entry_pos = ti->cl_first + y;
1490 node_first = getTreeInfoFirstGroupEntry(ti);
1491 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1493 if (node_cursor->node_group)
1495 node_cursor->cl_first = ti->cl_first;
1496 node_cursor->cl_cursor = ti->cl_cursor;
1497 *ti_ptr = node_cursor->node_group;
1498 DrawChooseTree(ti_ptr);
1500 else if (node_cursor->parent_link)
1502 *ti_ptr = node_cursor->node_parent;
1503 DrawChooseTree(ti_ptr);
1507 node_cursor->cl_first = ti->cl_first;
1508 node_cursor->cl_cursor = ti->cl_cursor;
1509 *ti_ptr = node_cursor;
1511 if (ti->type == TREE_TYPE_LEVEL_DIR)
1513 LoadLevelSetup_SeriesInfo();
1515 SaveLevelSetup_LastSeries();
1516 SaveLevelSetup_SeriesInfo();
1520 if (game_status == SETUP)
1526 game_status = MAINMENU;
1535 if (game_status == CHOOSELEVEL || game_status == SETUP)
1539 void DrawChooseLevel()
1541 DrawChooseTree(&leveldir_current);
1544 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1546 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1549 void DrawHallOfFame(int highlight_position)
1553 CloseDoor(DOOR_CLOSE_2);
1555 if (highlight_position < 0)
1556 LoadScore(level_nr);
1560 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1561 PlaySound(SND_MENU_HALL_OF_FAME);
1564 static void drawHallOfFameList(int first_entry, int highlight_position)
1569 DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1570 DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1572 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1574 int entry = first_entry + i;
1575 int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1578 DrawText(SX, SY + 64 + i * 32, ".................", FS_BIG, color);
1579 DrawText(SX, SY + 64 + i * 32, highscore[i].Name, FS_BIG, color);
1580 DrawText(SX + 12 * 32, SY + 64 + i * 32,
1581 int2str(highscore[i].Score, 5), FS_BIG, color);
1583 DrawText(SX, SY + 64 + i * 32, "..................................",
1584 FS_MEDIUM, FC_YELLOW);
1585 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1586 FS_MEDIUM, FC_YELLOW);
1587 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name, FS_BIG, color);
1588 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1589 int2str(highscore[entry].Score, 5), FS_MEDIUM, color);
1594 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1596 static int first_entry = 0;
1597 static int highlight_position = 0;
1598 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1599 int button_released = !button;
1601 if (button == MB_MENU_INITIALIZE)
1604 highlight_position = mx;
1605 drawHallOfFameList(first_entry, highlight_position);
1609 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1610 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1614 if (first_entry > 0)
1616 first_entry -= step;
1617 if (first_entry < 0)
1620 drawHallOfFameList(first_entry, highlight_position);
1626 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1628 first_entry += step;
1629 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1630 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1632 drawHallOfFameList(first_entry, highlight_position);
1637 if (button_released)
1639 FadeSound(SND_MENU_HALL_OF_FAME);
1640 game_status = MAINMENU;
1646 if (game_status == HALLOFFAME)
1651 /* ========================================================================= */
1652 /* setup screen functions */
1653 /* ========================================================================= */
1655 static struct TokenInfo *setup_info;
1656 static int num_setup_info;
1658 static char *graphics_set_name;
1659 static char *sounds_set_name;
1660 static char *music_set_name;
1662 static void execSetupMain()
1664 setup_mode = SETUP_MODE_MAIN;
1668 static void execSetupGame()
1670 setup_mode = SETUP_MODE_GAME;
1674 static void execSetupEditor()
1676 setup_mode = SETUP_MODE_EDITOR;
1680 static void execSetupGraphics()
1682 setup_mode = SETUP_MODE_GRAPHICS;
1686 static void execSetupSound()
1688 setup_mode = SETUP_MODE_SOUND;
1692 static void execSetupArtwork()
1694 /* needed if last screen (setup choice) changed graphics, sounds or music */
1695 ReloadCustomArtwork();
1697 setup.graphics_set = artwork.gfx_current->identifier;
1698 setup.sounds_set = artwork.snd_current->identifier;
1699 setup.music_set = artwork.mus_current->identifier;
1701 /* needed for displaying artwork name instead of artwork identifier */
1702 graphics_set_name = artwork.gfx_current->name;
1703 sounds_set_name = artwork.snd_current->name;
1704 music_set_name = artwork.mus_current->name;
1706 setup_mode = SETUP_MODE_ARTWORK;
1710 static void execSetupChooseGraphics()
1712 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1716 static void execSetupChooseSounds()
1718 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1722 static void execSetupChooseMusic()
1724 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1728 static void execSetupInput()
1730 setup_mode = SETUP_MODE_INPUT;
1734 static void execSetupShortcut()
1736 setup_mode = SETUP_MODE_SHORTCUT;
1740 static void execExitSetup()
1742 game_status = MAINMENU;
1746 static void execSaveAndExitSetup()
1752 static struct TokenInfo setup_info_main[] =
1754 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1755 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1756 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1757 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1758 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1759 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1760 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1761 { TYPE_EMPTY, NULL, "" },
1762 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1763 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1767 static struct TokenInfo setup_info_game[] =
1769 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1770 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1771 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1772 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1773 { TYPE_EMPTY, NULL, "" },
1774 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1778 static struct TokenInfo setup_info_editor[] =
1780 { TYPE_STRING, NULL, "Offer Special Elements:"},
1781 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1782 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1783 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1784 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1785 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1786 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1787 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1788 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1789 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1790 { TYPE_EMPTY, NULL, "" },
1791 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1795 static struct TokenInfo setup_info_graphics[] =
1797 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1798 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1799 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1801 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1802 { TYPE_SWITCH, &setup.fading, "Fading:" },
1804 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1805 { TYPE_SWITCH, &setup.toons, "Toons:" },
1806 { TYPE_EMPTY, NULL, "" },
1807 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1811 static struct TokenInfo setup_info_sound[] =
1813 { TYPE_SWITCH, &setup.sound, "Sound:", },
1814 { TYPE_EMPTY, NULL, "" },
1815 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1816 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1817 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1818 { TYPE_EMPTY, NULL, "" },
1819 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1823 static struct TokenInfo setup_info_artwork[] =
1825 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1826 { TYPE_STRING, &graphics_set_name, "" },
1827 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1828 { TYPE_STRING, &sounds_set_name, "" },
1829 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1830 { TYPE_STRING, &music_set_name, "" },
1831 { TYPE_EMPTY, NULL, "" },
1832 { TYPE_STRING, NULL, "Override Level Artwork:"},
1833 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1834 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1835 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1836 { TYPE_EMPTY, NULL, "" },
1837 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1841 static struct TokenInfo setup_info_shortcut[] =
1843 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1844 { TYPE_KEY, &setup.shortcut.save_game, "" },
1845 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1846 { TYPE_KEY, &setup.shortcut.load_game, "" },
1847 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1848 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1849 { TYPE_EMPTY, NULL, "" },
1850 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1851 { TYPE_EMPTY, NULL, "" },
1852 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1856 static Key getSetupKey()
1858 Key key = KSYM_UNDEFINED;
1859 boolean got_key_event = FALSE;
1861 while (!got_key_event)
1863 if (PendingEvent()) /* got event */
1871 case EVENT_KEYPRESS:
1873 key = GetEventKey((KeyEvent *)&event, TRUE);
1875 /* press 'Escape' or 'Enter' to keep the existing key binding */
1876 if (key == KSYM_Escape || key == KSYM_Return)
1877 key = KSYM_UNDEFINED; /* keep old value */
1879 got_key_event = TRUE;
1883 case EVENT_KEYRELEASE:
1884 key_joystick_mapping = 0;
1888 HandleOtherEvents(&event);
1896 /* don't eat all CPU time */
1903 static void drawSetupValue(int pos)
1905 int xpos = MENU_SCREEN_VALUE_XPOS;
1906 int ypos = MENU_SCREEN_START_YPOS + pos;
1907 int font_size = FS_BIG;
1908 int font_color = FC_YELLOW;
1909 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1910 setup_info[pos].value);
1912 if (value_string == NULL)
1915 if (setup_info[pos].type & TYPE_KEY)
1919 if (setup_info[pos].type & TYPE_QUERY)
1921 value_string = "<press key>";
1922 font_color = FC_RED;
1925 else if (setup_info[pos].type & TYPE_STRING)
1927 int max_value_len = (SCR_FIELDX - 2) * 2;
1930 font_size = FS_MEDIUM;
1932 if (strlen(value_string) > max_value_len)
1933 value_string[max_value_len] = '\0';
1935 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
1936 !*(boolean *)(setup_info[pos].value))
1937 font_color = FC_BLUE;
1939 DrawText(SX + xpos * 32, SY + ypos * 32,
1940 (xpos == 3 ? " " : " "), FS_BIG, FC_YELLOW);
1941 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, font_size,font_color);
1944 static void changeSetupValue(int pos)
1946 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1948 *(boolean *)setup_info[pos].value ^= TRUE;
1950 else if (setup_info[pos].type & TYPE_KEY)
1954 setup_info[pos].type |= TYPE_QUERY;
1955 drawSetupValue(pos);
1956 setup_info[pos].type &= ~TYPE_QUERY;
1958 key = getSetupKey();
1959 if (key != KSYM_UNDEFINED)
1960 *(Key *)setup_info[pos].value = key;
1963 drawSetupValue(pos);
1966 static void DrawSetupScreen_Generic()
1968 char *title_string = NULL;
1972 CloseDoor(DOOR_CLOSE_2);
1975 if (setup_mode == SETUP_MODE_MAIN)
1977 setup_info = setup_info_main;
1978 title_string = "Setup";
1980 else if (setup_mode == SETUP_MODE_GAME)
1982 setup_info = setup_info_game;
1983 title_string = "Setup Game";
1985 else if (setup_mode == SETUP_MODE_EDITOR)
1987 setup_info = setup_info_editor;
1988 title_string = "Setup Editor";
1990 else if (setup_mode == SETUP_MODE_GRAPHICS)
1992 setup_info = setup_info_graphics;
1993 title_string = "Setup Graphics";
1995 else if (setup_mode == SETUP_MODE_SOUND)
1997 setup_info = setup_info_sound;
1998 title_string = "Setup Sound";
2000 else if (setup_mode == SETUP_MODE_ARTWORK)
2002 setup_info = setup_info_artwork;
2003 title_string = "Custom Artwork";
2005 else if (setup_mode == SETUP_MODE_SHORTCUT)
2007 setup_info = setup_info_shortcut;
2008 title_string = "Setup Shortcuts";
2011 DrawText(SX + 16, SY + 16, title_string, FS_BIG, FC_YELLOW);
2014 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2016 void *value_ptr = setup_info[i].value;
2017 int ypos = MENU_SCREEN_START_YPOS + i;
2018 int font_size = FS_BIG;
2020 /* set some entries to "unchangeable" according to other variables */
2021 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2022 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2023 (value_ptr == &setup.sound_music && !audio.music_available) ||
2024 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2025 setup_info[i].type |= TYPE_GHOSTED;
2027 if (setup_info[i].type & TYPE_STRING)
2028 font_size = FS_MEDIUM;
2030 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, font_size, FC_GREEN);
2032 if (setup_info[i].type & TYPE_ENTER_MENU)
2033 initCursor(i, IMG_ARROW_BLUE_RIGHT);
2034 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2035 initCursor(i, IMG_ARROW_BLUE_LEFT);
2036 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2037 initCursor(i, IMG_BALL_BLUE);
2039 if (setup_info[i].type & TYPE_VALUE)
2047 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2050 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2052 static int choice_store[MAX_SETUP_MODES];
2053 int choice = choice_store[setup_mode]; /* always starts with 0 */
2057 if (button == MB_MENU_INITIALIZE)
2059 /* advance to first valid menu entry */
2060 while (choice < num_setup_info &&
2061 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2063 choice_store[setup_mode] = choice;
2065 drawCursor(choice, FC_RED);
2068 else if (button == MB_MENU_LEAVE)
2070 for (y=0; y<num_setup_info; y++)
2072 if (setup_info[y].type & TYPE_LEAVE_MENU)
2074 void (*menu_callback_function)(void) = setup_info[y].value;
2076 menu_callback_function();
2077 break; /* absolutely needed because function changes 'setup_info'! */
2084 if (mx || my) /* mouse input */
2087 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2089 else if (dx || dy) /* keyboard input */
2093 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2095 if ((setup_info[choice].type & menu_navigation_type) ||
2096 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2097 button = MB_MENU_CHOICE;
2102 /* jump to next non-empty menu entry (up or down) */
2103 while (y > 0 && y < num_setup_info - 1 &&
2104 (setup_info[y].type & TYPE_SKIP_ENTRY))
2108 if (x == 0 && y >= 0 && y < num_setup_info &&
2109 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2115 drawCursor(y, FC_RED);
2116 drawCursor(choice, FC_BLUE);
2117 choice = choice_store[setup_mode] = y;
2120 else if (!(setup_info[y].type & TYPE_GHOSTED))
2122 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2124 void (*menu_callback_function)(void) = setup_info[choice].value;
2126 menu_callback_function();
2130 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2131 (setup_info[y + 1].type & TYPE_KEY))
2134 if (setup_info[y].type & TYPE_VALUE)
2135 changeSetupValue(y);
2142 if (game_status == SETUP)
2146 void DrawSetupScreen_Input()
2149 DrawText(SX+16, SY+16, "Setup Input", FS_BIG, FC_YELLOW);
2151 initCursor(0, IMG_BALL_BLUE);
2152 initCursor(1, IMG_BALL_BLUE);
2153 initCursor(2, IMG_ARROW_BLUE_RIGHT);
2154 initCursor(13, IMG_ARROW_BLUE_LEFT);
2156 DrawGraphic(10, MENU_SCREEN_START_YPOS, IMG_ARROW_BLUE_LEFT, 0);
2157 DrawGraphic(12, MENU_SCREEN_START_YPOS, IMG_ARROW_BLUE_RIGHT, 0);
2159 DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
2160 DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
2161 DrawText(SX+32, SY+15*32, "Back", FS_BIG, FC_GREEN);
2164 DeactivateJoystickForCalibration();
2165 DrawTextFCentered(SYSIZE - 20, FC_BLUE,
2166 "Joysticks deactivated on this screen");
2169 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2174 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2176 if (device_name == NULL)
2179 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2182 if (strlen(device_name) > 1)
2184 char c1 = device_name[strlen(device_name) - 1];
2185 char c2 = device_name[strlen(device_name) - 2];
2187 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2188 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2191 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2192 strlen(device_name));
2195 static void drawPlayerSetupInputInfo(int player_nr)
2198 static struct SetupKeyboardInfo custom_key;
2205 { &custom_key.left, "Joystick Left" },
2206 { &custom_key.right, "Joystick Right" },
2207 { &custom_key.up, "Joystick Up" },
2208 { &custom_key.down, "Joystick Down" },
2209 { &custom_key.snap, "Button 1" },
2210 { &custom_key.bomb, "Button 2" }
2212 static char *joystick_name[MAX_PLAYERS] =
2220 custom_key = setup.input[player_nr].key;
2222 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
2223 DrawGraphic(8, 2, PLAYER_NR_GFX(IMG_PLAYER1, player_nr), 0);
2225 if (setup.input[player_nr].use_joystick)
2227 char *device_name = setup.input[player_nr].joy.device_name;
2229 DrawText(SX+8*32, SY+3*32,
2230 joystick_name[getJoystickNrFromDeviceName(device_name)],
2232 DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
2236 DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
2237 DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
2240 DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
2241 DrawGraphic(1, 6, IMG_ARROW_BLUE_LEFT, 0);
2242 DrawGraphic(1, 7, IMG_ARROW_BLUE_RIGHT, 0);
2243 DrawGraphic(1, 8, IMG_ARROW_BLUE_UP, 0);
2244 DrawGraphic(1, 9, IMG_ARROW_BLUE_DOWN, 0);
2245 DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
2246 DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
2247 DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
2248 DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
2249 DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
2250 DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
2254 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2256 DrawText(SX + 3*32, SY + ypos*32,
2257 " ", FS_BIG, FC_YELLOW);
2258 DrawText(SX + 3*32, SY + ypos*32,
2259 (setup.input[player_nr].use_joystick ?
2261 getKeyNameFromKey(*custom[i].key)),
2266 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2268 static int choice = 0;
2269 static int player_nr = 0;
2272 int pos_start = SETUPINPUT_SCREEN_POS_START;
2273 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2274 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2275 int pos_end = SETUPINPUT_SCREEN_POS_END;
2277 if (button == MB_MENU_INITIALIZE)
2279 drawPlayerSetupInputInfo(player_nr);
2280 drawCursor(choice, FC_RED);
2283 else if (button == MB_MENU_LEAVE)
2285 setup_mode = SETUP_MODE_MAIN;
2290 if (mx || my) /* mouse input */
2293 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2295 else if (dx || dy) /* keyboard input */
2297 if (dx && choice == 0)
2298 x = (dx < 0 ? 10 : 12);
2299 else if ((dx && choice == 1) ||
2300 (dx == +1 && choice == 2) ||
2301 (dx == -1 && choice == pos_end))
2302 button = MB_MENU_CHOICE;
2306 if (y >= pos_empty1 && y <= pos_empty2)
2307 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2310 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2312 static unsigned long delay = 0;
2314 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2317 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2319 drawPlayerSetupInputInfo(player_nr);
2321 else if (x == 0 && y >= pos_start && y <= pos_end &&
2322 !(y >= pos_empty1 && y <= pos_empty2))
2328 drawCursor(y, FC_RED);
2329 drawCursor(choice, FC_BLUE);
2337 char *device_name = setup.input[player_nr].joy.device_name;
2339 if (!setup.input[player_nr].use_joystick)
2341 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2343 setJoystickDeviceToNr(device_name, new_device_nr);
2344 setup.input[player_nr].use_joystick = TRUE;
2348 int device_nr = getJoystickNrFromDeviceName(device_name);
2349 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2351 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2352 setup.input[player_nr].use_joystick = FALSE;
2354 setJoystickDeviceToNr(device_name, new_device_nr);
2357 drawPlayerSetupInputInfo(player_nr);
2361 if (setup.input[player_nr].use_joystick)
2364 CalibrateJoystick(player_nr);
2367 CustomizeKeyboard(player_nr);
2369 else if (y == pos_end)
2373 setup_mode = SETUP_MODE_MAIN;
2383 if (game_status == SETUP)
2387 void CustomizeKeyboard(int player_nr)
2391 boolean finished = FALSE;
2392 static struct SetupKeyboardInfo custom_key;
2397 } customize_step[] =
2399 { &custom_key.left, "Move Left" },
2400 { &custom_key.right, "Move Right" },
2401 { &custom_key.up, "Move Up" },
2402 { &custom_key.down, "Move Down" },
2403 { &custom_key.snap, "Snap Field" },
2404 { &custom_key.bomb, "Place Bomb" }
2407 /* read existing key bindings from player setup */
2408 custom_key = setup.input[player_nr].key;
2411 DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
2417 DrawText(SX, SY + (2+2*step_nr)*32,
2418 customize_step[step_nr].text, FS_BIG, FC_RED);
2419 DrawText(SX, SY + (2+2*step_nr+1)*32,
2420 "Key:", FS_BIG, FC_RED);
2421 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2422 getKeyNameFromKey(*customize_step[step_nr].key),
2427 if (PendingEvent()) /* got event */
2435 case EVENT_KEYPRESS:
2437 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2439 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2445 /* all keys configured -- wait for "Escape" or "Return" key */
2449 /* press 'Enter' to keep the existing key binding */
2450 if (key == KSYM_Return)
2451 key = *customize_step[step_nr].key;
2453 /* check if key already used */
2454 for (i=0; i<step_nr; i++)
2455 if (*customize_step[i].key == key)
2460 /* got new key binding */
2461 *customize_step[step_nr].key = key;
2462 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2463 " ", FS_BIG, FC_YELLOW);
2464 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2465 getKeyNameFromKey(key), FS_BIG, FC_YELLOW);
2468 /* un-highlight last query */
2469 DrawText(SX, SY+(2+2*(step_nr-1))*32,
2470 customize_step[step_nr-1].text, FS_BIG, FC_GREEN);
2471 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
2472 "Key:", FS_BIG, FC_GREEN);
2474 /* press 'Enter' to leave */
2477 DrawText(SX + 16, SY + 15*32+16,
2478 "Press Enter", FS_BIG, FC_YELLOW);
2482 /* query next key binding */
2483 DrawText(SX, SY+(2+2*step_nr)*32,
2484 customize_step[step_nr].text, FS_BIG, FC_RED);
2485 DrawText(SX, SY+(2+2*step_nr+1)*32,
2486 "Key:", FS_BIG, FC_RED);
2487 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
2488 getKeyNameFromKey(*customize_step[step_nr].key),
2493 case EVENT_KEYRELEASE:
2494 key_joystick_mapping = 0;
2498 HandleOtherEvents(&event);
2506 /* don't eat all CPU time */
2510 /* write new key bindings back to player setup */
2511 setup.input[player_nr].key = custom_key;
2514 DrawSetupScreen_Input();
2517 static boolean CalibrateJoystickMain(int player_nr)
2519 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2520 int new_joystick_xright = JOYSTICK_XMIDDLE;
2521 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2522 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2523 int new_joystick_xmiddle, new_joystick_ymiddle;
2525 int joystick_fd = joystick.fd[player_nr];
2526 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2527 boolean check[3][3];
2528 int check_remaining = 3 * 3;
2533 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2536 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2545 check[x][y] = FALSE;
2546 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_BALL_BLUE, 0);
2550 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
2551 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
2552 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
2553 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
2554 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FS_BIG, FC_YELLOW);
2555 DrawText(SX, SY + 12 * 32, " AND ", FS_BIG, FC_YELLOW);
2556 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
2558 joy_value = Joystick(player_nr);
2559 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2560 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2562 /* eventually uncalibrated center position (joystick could be uncentered) */
2563 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2566 new_joystick_xmiddle = joy_x;
2567 new_joystick_ymiddle = joy_y;
2569 DrawGraphic(xpos + last_x, ypos + last_y, IMG_BALL_RED, 0);
2572 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2577 if (PendingEvent()) /* got event */
2585 case EVENT_KEYPRESS:
2586 switch(GetEventKey((KeyEvent *)&event, TRUE))
2589 if (check_remaining == 0)
2602 case EVENT_KEYRELEASE:
2603 key_joystick_mapping = 0;
2607 HandleOtherEvents(&event);
2612 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2615 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2616 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2617 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2618 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2620 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2621 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2622 setup.input[player_nr].joy.xright = new_joystick_xright;
2623 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2624 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2625 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2627 CheckJoystickData();
2629 joy_value = Joystick(player_nr);
2631 if (joy_value & JOY_BUTTON && check_remaining == 0)
2634 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2635 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2637 if (x != last_x || y != last_y)
2639 DrawGraphic(xpos + last_x, ypos + last_y, IMG_BALL_YELLOW, 0);
2640 DrawGraphic(xpos + x, ypos + y, IMG_BALL_RED, 0);
2645 if (check_remaining > 0 && !check[x+1][y+1])
2647 check[x+1][y+1] = TRUE;
2653 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2654 setup.input[player_nr].joy.xleft,
2655 setup.input[player_nr].joy.xmiddle,
2656 setup.input[player_nr].joy.xright);
2657 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2658 setup.input[player_nr].joy.yupper,
2659 setup.input[player_nr].joy.ymiddle,
2660 setup.input[player_nr].joy.ylower);
2669 /* don't eat all CPU time */
2673 /* calibrated center position (joystick should now be centered) */
2674 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2677 new_joystick_xmiddle = joy_x;
2678 new_joystick_ymiddle = joy_y;
2682 DrawSetupScreen_Input();
2684 /* wait until the last pressed button was released */
2685 while (Joystick(player_nr) & JOY_BUTTON)
2687 if (PendingEvent()) /* got event */
2692 HandleOtherEvents(&event);
2701 void CalibrateJoystick(int player_nr)
2703 if (!CalibrateJoystickMain(player_nr))
2707 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
2708 DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
2710 Delay(2000); /* show error message for two seconds */
2714 void DrawSetupScreen()
2716 DeactivateJoystick();
2718 if (setup_mode == SETUP_MODE_INPUT)
2719 DrawSetupScreen_Input();
2720 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2721 DrawChooseTree(&artwork.gfx_current);
2722 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2723 DrawChooseTree(&artwork.snd_current);
2724 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2725 DrawChooseTree(&artwork.mus_current);
2727 DrawSetupScreen_Generic();
2730 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2732 if (setup_mode == SETUP_MODE_INPUT)
2733 HandleSetupScreen_Input(mx, my, dx, dy, button);
2734 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2735 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2736 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2737 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2738 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2739 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2741 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2744 void HandleGameActions()
2746 if (game_status != PLAYING)
2749 if (local_player->LevelSolved)
2752 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2760 /* ---------- new screen button stuff -------------------------------------- */
2762 /* graphic position and size values for buttons and scrollbars */
2763 #define SC_SCROLLBUTTON_XSIZE 32
2764 #define SC_SCROLLBUTTON_YSIZE 32
2766 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2767 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2768 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2769 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2770 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2771 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2772 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2773 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2775 #define SC_BORDER_SIZE 14
2779 int gfx_unpressed, gfx_pressed;
2783 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2786 IMG_ARROW_BLUE_UP, IMG_ARROW_RED_UP,
2787 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2788 SCREEN_CTRL_ID_SCROLL_UP,
2792 IMG_ARROW_BLUE_DOWN, IMG_ARROW_RED_DOWN,
2793 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2794 SCREEN_CTRL_ID_SCROLL_DOWN,
2801 int gfx_unpressed, gfx_pressed;
2807 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2810 IMG_SCROLLBAR_BLUE, IMG_SCROLLBAR_RED,
2811 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2812 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2813 GD_TYPE_SCROLLBAR_VERTICAL,
2814 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2815 "scroll level series vertically"
2819 static void CreateScreenScrollbuttons()
2821 struct GadgetInfo *gi;
2822 unsigned long event_mask;
2825 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2827 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2828 int gfx_unpressed, gfx_pressed;
2829 int x, y, width, height;
2830 int gd_x1, gd_x2, gd_y1, gd_y2;
2831 int id = scrollbutton_info[i].gadget_id;
2833 x = scrollbutton_info[i].x;
2834 y = scrollbutton_info[i].y;
2836 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2840 width = SC_SCROLLBUTTON_XSIZE;
2841 height = SC_SCROLLBUTTON_YSIZE;
2843 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2844 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2845 gd_bitmap_unpressed = new_graphic_info[gfx_unpressed].bitmap;
2846 gd_bitmap_pressed = new_graphic_info[gfx_pressed].bitmap;
2847 gd_x1 = new_graphic_info[gfx_unpressed].src_x;
2848 gd_y1 = new_graphic_info[gfx_unpressed].src_y;
2849 gd_x2 = new_graphic_info[gfx_pressed].src_x;
2850 gd_y2 = new_graphic_info[gfx_pressed].src_y;
2852 gi = CreateGadget(GDI_CUSTOM_ID, id,
2853 GDI_CUSTOM_TYPE_ID, i,
2854 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2859 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2860 GDI_STATE, GD_BUTTON_UNPRESSED,
2861 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2862 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2863 GDI_EVENT_MASK, event_mask,
2864 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2868 Error(ERR_EXIT, "cannot create gadget");
2870 screen_gadget[id] = gi;
2874 static void CreateScreenScrollbars()
2878 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2880 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2881 int gfx_unpressed, gfx_pressed;
2882 int gd_x1, gd_x2, gd_y1, gd_y2;
2883 struct GadgetInfo *gi;
2884 int items_max, items_visible, item_position;
2885 unsigned long event_mask;
2886 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2887 int id = scrollbar_info[i].gadget_id;
2889 items_max = num_page_entries;
2890 items_visible = num_page_entries;
2893 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2895 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2896 gfx_pressed = scrollbar_info[i].gfx_pressed;
2897 gd_bitmap_unpressed = new_graphic_info[gfx_unpressed].bitmap;
2898 gd_bitmap_pressed = new_graphic_info[gfx_pressed].bitmap;
2899 gd_x1 = new_graphic_info[gfx_unpressed].src_x;
2900 gd_y1 = new_graphic_info[gfx_unpressed].src_y;
2901 gd_x2 = new_graphic_info[gfx_pressed].src_x;
2902 gd_y2 = new_graphic_info[gfx_pressed].src_y;
2904 gi = CreateGadget(GDI_CUSTOM_ID, id,
2905 GDI_CUSTOM_TYPE_ID, i,
2906 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2907 GDI_X, scrollbar_info[i].x,
2908 GDI_Y, scrollbar_info[i].y,
2909 GDI_WIDTH, scrollbar_info[i].width,
2910 GDI_HEIGHT, scrollbar_info[i].height,
2911 GDI_TYPE, scrollbar_info[i].type,
2912 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2913 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2914 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2915 GDI_STATE, GD_BUTTON_UNPRESSED,
2916 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2917 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2918 GDI_BORDER_SIZE, SC_BORDER_SIZE,
2919 GDI_EVENT_MASK, event_mask,
2920 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2924 Error(ERR_EXIT, "cannot create gadget");
2926 screen_gadget[id] = gi;
2930 void CreateScreenGadgets()
2932 CreateScreenScrollbuttons();
2933 CreateScreenScrollbars();
2936 void FreeScreenGadgets()
2940 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2941 FreeGadget(screen_gadget[i]);
2944 void MapChooseTreeGadgets(TreeInfo *ti)
2946 int num_entries = numTreeInfoInGroup(ti);
2949 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
2952 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2953 MapGadget(screen_gadget[i]);
2956 void UnmapChooseTreeGadgets()
2960 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2961 UnmapGadget(screen_gadget[i]);
2964 static void HandleScreenGadgets(struct GadgetInfo *gi)
2966 int id = gi->custom_id;
2968 if (game_status != CHOOSELEVEL && game_status != SETUP)
2973 case SCREEN_CTRL_ID_SCROLL_UP:
2974 if (game_status == CHOOSELEVEL)
2975 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
2976 else if (game_status == SETUP)
2977 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
2980 case SCREEN_CTRL_ID_SCROLL_DOWN:
2981 if (game_status == CHOOSELEVEL)
2982 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
2983 else if (game_status == SETUP)
2984 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
2987 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
2988 if (game_status == CHOOSELEVEL)
2989 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
2990 else if (game_status == SETUP)
2991 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);