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 Bitmap *scrollbar_bitmap[4];
76 static void drawCursorExt(int xpos, int ypos, int color, int graphic)
78 static int cursor_array[SCR_FIELDY];
83 cursor_array[ypos] = graphic;
85 graphic = cursor_array[ypos];
89 graphic = (graphic == IMG_ARROW_BLUE_LEFT ? IMG_ARROW_RED_LEFT :
90 graphic == IMG_ARROW_BLUE_RIGHT ? IMG_ARROW_RED_RIGHT :
93 ypos += MENU_SCREEN_START_YPOS;
95 DrawBackground(SX + xpos * 32, SY + ypos * 32, TILEX, TILEY);
96 DrawGraphicThruMask(xpos, ypos, graphic, 0);
99 static void initCursor(int ypos, int graphic)
101 drawCursorExt(0, ypos, FC_BLUE, graphic);
104 static void drawCursor(int ypos, int color)
106 drawCursorExt(0, ypos, color, 0);
109 static void drawCursorXY(int xpos, int ypos, int graphic)
111 drawCursorExt(xpos, ypos, -1, graphic);
116 int x = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * FONT1_XSIZE) / 2;
118 DrawText(x, SY + 8, PROGRAM_TITLE_STRING, FS_BIG, FC_YELLOW);
119 DrawTextFCentered(46, FC_RED, WINDOW_SUBTITLE_STRING);
122 static void ToggleFullscreenIfNeeded()
124 if (setup.fullscreen != video.fullscreen_enabled)
126 /* save old door content */
127 BlitBitmap(backbuffer, bitmap_db_door,
128 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
130 /* toggle fullscreen */
131 ChangeVideoModeIfNeeded(setup.fullscreen);
132 setup.fullscreen = video.fullscreen_enabled;
134 /* redraw background to newly created backbuffer */
135 BlitBitmap(new_graphic_info[IMG_MENU_FRAME].bitmap, backbuffer,
136 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
138 /* restore old door content */
139 BlitBitmap(bitmap_db_door, backbuffer,
140 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
142 redraw_mask = REDRAW_ALL;
148 static LevelDirTree *leveldir_last_valid = NULL;
150 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
154 KeyboardAutoRepeatOn();
156 SetDrawDeactivationMask(REDRAW_NONE);
157 SetBackgroundBitmap(new_graphic_info[IMG_MENU_BACKGROUND].bitmap);
158 audio.sound_deactivated = FALSE;
160 /* needed if last screen was the playing screen, invoked from level editor */
161 if (level_editor_test_game)
163 game_status = LEVELED;
168 /* needed if last screen was the editor screen */
169 UndrawSpecialEditorDoor();
171 /* needed if last screen was the setup screen and fullscreen state changed */
172 ToggleFullscreenIfNeeded();
174 /* needed if last screen (level choice) changed graphics, sounds or music */
175 ReloadCustomArtwork();
178 SetDrawtoField(DRAW_BACKBUFFER);
181 /* map gadgets for main menu screen */
184 /* leveldir_current may be invalid (level group, parent link) */
185 if (!validLevelSeries(leveldir_current))
186 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
188 /* store valid level series information */
189 leveldir_last_valid = leveldir_current;
191 /* level_nr may have been set to value over handicap with level editor */
192 if (setup.handicap && level_nr > leveldir_current->handicap_level)
193 level_nr = leveldir_current->handicap_level;
198 SetBackgroundBitmap(new_graphic_info[IMG_MENU_BACKGROUND].bitmap);
202 DrawText(SX + 32, SY + 2*32, name_text, FS_BIG, FC_GREEN);
203 DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
204 DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
205 DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
206 (leveldir_current->readonly ? FC_RED : FC_YELLOW));
207 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
208 DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
209 DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
210 DrawText(SX + 32, SY + 7*32, "Start Game", FS_BIG, FC_GREEN);
211 DrawText(SX + 32, SY + 8*32, "Setup", FS_BIG, FC_GREEN);
212 DrawText(SX + 32, SY + 9*32, "Quit", FS_BIG, FC_GREEN);
214 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
216 DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
217 leveldir_current->first_level,
218 leveldir_current->last_level);
220 if (leveldir_current->readonly)
222 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
223 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
227 initCursor(i, (i == 1 || i == 6 ? IMG_ARROW_BLUE_RIGHT : IMG_BALL_BLUE));
230 DrawGraphic(10, 3, IMG_ARROW_BLUE_LEFT, 0);
231 DrawGraphic(14, 3, IMG_ARROW_BLUE_RIGHT, 0);
233 drawCursorXY(10, 1, IMG_ARROW_BLUE_LEFT);
234 drawCursorXY(14, 1, IMG_ARROW_BLUE_RIGHT);
237 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
240 if (leveldir_current->name)
242 int len = strlen(leveldir_current->name);
243 int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
244 int lypos = SY + 352;
246 DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
251 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
254 if (TAPE_IS_EMPTY(tape))
256 DrawCompleteVideoDisplay();
258 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
265 static void gotoTopLevelDir()
267 /* move upwards to top level directory */
268 while (leveldir_current->node_parent)
270 /* write a "path" into level tree for easy navigation to last level */
271 if (leveldir_current->node_parent->node_group->cl_first == -1)
273 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
274 int leveldir_pos = posTreeInfo(leveldir_current);
275 int num_page_entries;
276 int cl_first, cl_cursor;
278 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
279 num_page_entries = num_leveldirs;
281 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
283 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
284 cl_cursor = leveldir_pos - cl_first;
286 leveldir_current->node_parent->node_group->cl_first = cl_first;
287 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
290 leveldir_current = leveldir_current->node_parent;
294 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
296 static int choice = 0;
300 if (button == MB_MENU_INITIALIZE)
302 drawCursor(choice, FC_RED);
306 if (mx || my) /* mouse input */
309 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
311 else if (dx || dy) /* keyboard input */
313 if (dx && choice == 1)
314 x = (dx < 0 ? 10 : 14);
319 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
320 (x == 14 && level_nr < leveldir_current->last_level)) &&
323 static unsigned long level_delay = 0;
324 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
325 int new_level_nr, old_level_nr = level_nr;
326 int font_color = (leveldir_current->readonly ? FC_RED : FC_YELLOW);
328 new_level_nr = level_nr + (x == 10 ? -step : +step);
329 if (new_level_nr < leveldir_current->first_level)
330 new_level_nr = leveldir_current->first_level;
331 if (new_level_nr > leveldir_current->last_level)
332 new_level_nr = leveldir_current->last_level;
334 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
335 new_level_nr = leveldir_current->handicap_level;
337 if (old_level_nr == new_level_nr ||
338 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
341 level_nr = new_level_nr;
343 DrawText(SX + 11 * 32, SY + 3 * 32, int2str(level_nr, 3),
347 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
351 DrawCompleteVideoDisplay();
353 /* needed because DrawMicroLevel() takes some time */
356 DelayReached(&level_delay, 0); /* reset delay counter */
358 else if (x == 0 && y >= 0 && y <= 7)
364 drawCursor(y, FC_RED);
365 drawCursor(choice, FC_BLUE);
373 game_status = TYPENAME;
374 HandleTypeName(strlen(setup.player_name), 0);
380 game_status = CHOOSELEVEL;
381 SaveLevelSetup_LastSeries();
382 SaveLevelSetup_SeriesInfo();
391 game_status = HALLOFFAME;
396 if (leveldir_current->readonly &&
397 strcmp(setup.player_name, "Artsoft") != 0)
398 Request("This level is read only !", REQ_CONFIRM);
399 game_status = LEVELED;
404 game_status = HELPSCREEN;
409 if (setup.autorecord)
410 TapeStartRecording();
412 #if defined(PLATFORM_UNIX)
414 SendToServer_StartPlaying();
418 game_status = PLAYING;
426 setup_mode = SETUP_MODE_MAIN;
431 SaveLevelSetup_LastSeries();
432 SaveLevelSetup_SeriesInfo();
433 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
434 game_status = EXITGAME;
443 if (game_status == MAINMENU)
445 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
451 #define MAX_HELPSCREEN_ELS 10
455 static long helpscreen_state;
456 static int helpscreen_step[MAX_HELPSCREEN_ELS];
457 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
459 static int OLD_helpscreen_action[] =
461 GFX_SPIELER1_DOWN,4,2,
463 GFX_SPIELER1_LEFT,4,2,
464 GFX_SPIELER1_RIGHT,4,2,
465 GFX_SPIELER1_PUSH_LEFT,4,2,
466 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
467 GFX_ERDREICH,1,100, HA_NEXT,
468 GFX_LEERRAUM,1,100, HA_NEXT,
469 GFX_MORAST_LEER,1,100, HA_NEXT,
470 GFX_BETON,1,100, HA_NEXT,
471 GFX_MAUERWERK,1,100, HA_NEXT,
472 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
473 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
474 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
475 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
476 GFX_UNSICHTBAR,1,100, HA_NEXT,
477 GFX_FELSBODEN,1,100, HA_NEXT,
478 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
479 GFX_EDELSTEIN,2,5, HA_NEXT,
480 GFX_DIAMANT,2,5, HA_NEXT,
481 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
482 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
483 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
484 GFX_FELSBROCKEN,4,5, HA_NEXT,
485 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
486 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
487 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
488 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
489 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
490 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
491 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
492 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
493 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
494 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
495 GFX_GEBLUBBER,4,4, HA_NEXT,
496 GFX_SCHLUESSEL1,4,25, HA_NEXT,
497 GFX_PFORTE1,4,25, HA_NEXT,
498 GFX_PFORTE1X,4,25, HA_NEXT,
499 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
500 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
501 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
502 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
503 GFX_LEERRAUM,1,10, HA_NEXT,
504 GFX_DYNABOMB_NR,1,100, HA_NEXT,
505 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
506 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
507 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
508 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
509 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
510 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
511 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
512 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
513 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
514 GFX_BUTTERFLY,2,2, HA_NEXT,
515 GFX_FIREFLY,2,2, HA_NEXT,
516 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
517 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
518 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
519 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
520 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
521 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
522 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
523 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
524 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
525 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
529 GFX_MOLE_RIGHT,4,2, HA_NEXT,
530 GFX_PINGUIN_DOWN,4,2,
532 GFX_PINGUIN_LEFT,4,2,
533 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
534 GFX_SCHWEIN_DOWN,4,2,
536 GFX_SCHWEIN_LEFT,4,2,
537 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
541 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
542 GFX_SONDE_START,8,1, HA_NEXT,
543 GFX_ABLENK,4,1, HA_NEXT,
544 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
545 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
546 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
547 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
548 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
549 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
550 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
551 GFX_DIAMANT,1,10, HA_NEXT,
552 GFX_LIFE,1,100, HA_NEXT,
553 GFX_LIFE_ASYNC,1,100, HA_NEXT,
554 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
555 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
556 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
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_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
560 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
561 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
562 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
563 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
564 GFX_SPEED_PILL,1,100, HA_NEXT,
569 static int helpscreen_action[] =
571 IMG_PLAYER1_DOWN_MOVING, 16,
572 IMG_PLAYER1_UP_MOVING, 16,
573 IMG_PLAYER1_LEFT_MOVING, 16,
574 IMG_PLAYER1_RIGHT_MOVING, 16,
575 IMG_PLAYER1_LEFT_PUSHING, 16,
576 IMG_PLAYER1_RIGHT_PUSHING, 16, HA_NEXT,
578 IMG_SAND, -1, HA_NEXT,
580 IMG_EMPTY_SPACE, -1, HA_NEXT,
582 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
584 IMG_STEELWALL, -1, HA_NEXT,
586 IMG_WALL, -1, HA_NEXT,
588 IMG_WALL_GROWING_ACTIVE_LEFT, 20,
591 IMG_WALL_GROWING_ACTIVE_RIGHT, 20,
594 IMG_WALL_GROWING_ACTIVE_UP, 20,
597 IMG_WALL_GROWING_ACTIVE_DOWN, 20,
599 IMG_EMPTY_SPACE, 20, HA_NEXT,
601 IMG_INVISIBLE_WALL, -1, HA_NEXT,
603 IMG_WALL_CRUMBLED, -1, HA_NEXT,
605 IMG_INFO_FONT_EM_1, 160,
606 IMG_INFO_FONT_EM_2, 160,
607 IMG_INFO_FONT_EM_3, 160,
608 IMG_INFO_FONT_EM_4, 160,
609 IMG_INFO_FONT_EM_5, 40, HA_NEXT,
611 IMG_EMERALD, -1, HA_NEXT,
613 IMG_DIAMOND, -1, HA_NEXT,
615 IMG_BD_DIAMOND, -1, HA_NEXT,
617 IMG_EMERALD_YELLOW, 50,
619 IMG_EMERALD_PURPLE, 50, HA_NEXT,
621 IMG_BD_ROCK, -1, HA_NEXT,
625 IMG_EMPTY_SPACE, 10, HA_NEXT,
629 IMG_EMERALD, 20, HA_NEXT,
631 IMG_WALL_EMERALD, 100,
633 IMG_EMERALD, 20, HA_NEXT,
635 IMG_WALL_DIAMOND, 100,
637 IMG_DIAMOND, 20, HA_NEXT,
639 IMG_WALL_BD_DIAMOND, 100,
641 IMG_BD_DIAMOND, 20, HA_NEXT,
643 IMG_WALL_EMERALD_YELLOW, 100,
645 IMG_EMERALD_YELLOW, 20,
646 IMG_WALL_EMERALD_RED, 100,
649 IMG_WALL_EMERALD_PURPLE, 100,
651 IMG_EMERALD_PURPLE, 20, HA_NEXT,
653 IMG_ACID, -1, HA_NEXT,
658 IMG_KEY4, 50, HA_NEXT,
663 IMG_GATE4, 50, HA_NEXT,
668 IMG_GATE4_GRAY, 50, HA_NEXT,
670 IMG_DYNAMITE, -1, HA_NEXT,
672 IMG_DYNAMITE_ACTIVE, 96,
674 IMG_EMPTY_SPACE, 20, HA_NEXT,
676 IMG_DYNABOMB_ACTIVE, 100,
678 IMG_EMPTY_SPACE, 20, HA_NEXT,
680 IMG_DYNABOMB_NR, -1, HA_NEXT,
682 IMG_DYNABOMB_SZ, -1, HA_NEXT,
684 IMG_SPACESHIP_RIGHT, 16,
685 IMG_SPACESHIP_UP, 16,
686 IMG_SPACESHIP_LEFT, 16,
687 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
692 IMG_BUG_DOWN, 16, HA_NEXT,
694 IMG_BD_BUTTERFLY, -1, HA_NEXT,
696 IMG_BD_FIREFLY, -1, HA_NEXT,
698 IMG_PACMAN_RIGHT, 16,
701 IMG_PACMAN_DOWN, 16, HA_NEXT,
703 IMG_YAMYAM, -1, HA_NEXT,
705 IMG_DARK_YAMYAM, -1, HA_NEXT,
707 IMG_ROBOT, -1, HA_NEXT,
709 IMG_MOLE_RIGHT_MOVING, 16,
710 IMG_MOLE_UP_MOVING, 16,
711 IMG_MOLE_LEFT_MOVING, 16,
712 IMG_MOLE_DOWN_MOVING, 16, HA_NEXT,
714 IMG_PENGUIN_RIGHT_MOVING, 16,
715 IMG_PENGUIN_UP_MOVING, 16,
716 IMG_PENGUIN_LEFT_MOVING, 16,
717 IMG_PENGUIN_DOWN_MOVING, 16, HA_NEXT,
719 IMG_PIG_RIGHT_MOVING, 16,
720 IMG_PIG_UP_MOVING, 16,
721 IMG_PIG_LEFT_MOVING, 16,
722 IMG_PIG_DOWN_MOVING, 16, HA_NEXT,
724 IMG_DRAGON_RIGHT_MOVING, 16,
725 IMG_DRAGON_UP_MOVING, 16,
726 IMG_DRAGON_LEFT_MOVING, 16,
727 IMG_DRAGON_DOWN_MOVING, 16, HA_NEXT,
729 IMG_SATELLITE, -1, HA_NEXT,
732 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
735 IMG_LAMP_ACTIVE, 50, HA_NEXT,
737 IMG_TIME_ORB_FULL, 50,
738 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
741 IMG_AMOEBA_CREATING, 6,
742 IMG_AMOEBA_WET, 20, HA_NEXT,
744 IMG_AMOEBA_DEAD, -1, HA_NEXT,
746 IMG_AMOEBA_WET, -1, HA_NEXT,
749 IMG_AMOEBA_CREATING, 6, HA_NEXT,
754 IMG_DIAMOND, 20, HA_NEXT,
756 IMG_GAMEOFLIFE, -1, HA_NEXT,
758 IMG_BIOMAZE, -1, HA_NEXT,
760 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
762 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
764 IMG_EXIT_CLOSED, 200,
765 IMG_EXIT_OPENING, 16,
766 IMG_EXIT_OPEN, 100, HA_NEXT,
768 IMG_EXIT_OPEN, -1, HA_NEXT,
770 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
772 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
774 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
776 IMG_SPEED_PILL, -1, HA_NEXT,
780 static char *helpscreen_eltext[][2] =
782 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
783 {"Normal sand:", "You can dig through it"},
784 {"Empty field:", "You can walk through it"},
785 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
786 {"Massive Wall:", "Nothing can go through it"},
787 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
788 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
789 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
790 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
791 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
792 {"Emerald: You must collect enough of","them to finish a level"},
793 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
794 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
795 {"Colorful Gems:", "Seem to behave like Emeralds"},
796 {"Rock: Smashes several things;", "Can be moved by the player"},
797 {"Bomb: You can move it, but be", "careful when dropping it"},
798 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
799 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
800 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
801 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
802 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
803 {"Acid: Things that fall in are gone", "forever (including our hero)"},
804 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
805 {"Door: Can be opened by the key", "with the same color"},
806 {"Door: You have to find out the", "right color of the key for it"},
807 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
808 {"Dynamite: This one explodes after", "a few seconds"},
809 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
810 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
811 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
812 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
813 {"Bug: Moves at the right side", "of walls; don't touch it!"},
814 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
815 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
816 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
817 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
818 {"Cruncher (BD style):", "Eats almost everything"},
819 {"Robot: Tries to kill the player", ""},
820 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
821 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
822 {"The Pig: Harmless, but eats all", "gems it can get"},
823 {"The Dragon: Breathes fire,", "especially to some monsters"},
824 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
825 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
826 {"Light Bulb: All of them must be", "switched on to finish a level"},
827 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
828 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
829 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
830 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
831 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
832 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
833 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
834 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
835 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
836 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
837 {"Exit door: Opens if you have enough","emeralds to finish the level"},
838 {"Open exit door: Enter here to leave","the level and exit the actual game"},
839 {"Sokoban element: Object which must", "be pushed to an empty field"},
840 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
841 {"Sokoban element: Field with object", "which can be pushed away"},
842 {"Speed pill: Lets the player run", "twice as fast as normally"},
844 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
846 static char *helpscreen_music[][3] =
848 { "Alchemy", "Ian Boddy", "Drive" },
849 { "The Chase", "Propaganda", "A Secret Wish" },
850 { "Network 23", "Tangerine Dream", "Exit" },
851 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
852 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
853 { "Voyager", "The Alan Parsons Project","Pyramid" },
854 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
856 static int num_helpscreen_music = 7;
857 static int helpscreen_musicpos;
860 void OLD_DrawHelpScreenElAction(int start)
864 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
866 while(helpscreen_action[j] != HA_END)
868 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
870 else if (i<start || helpscreen_delay[i-start])
872 if (i>=start && helpscreen_delay[i-start])
873 helpscreen_delay[i-start]--;
875 while(helpscreen_action[j] != HA_NEXT)
882 j += 3*helpscreen_step[i-start];
883 graphic = helpscreen_action[j++];
885 if (helpscreen_frame[i-start])
887 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
888 helpscreen_frame[i-start]--;
893 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
896 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
898 if (helpscreen_action[j] == HA_NEXT)
900 if (!helpscreen_frame[i-start])
901 helpscreen_step[i-start] = 0;
905 if (!helpscreen_frame[i-start])
906 helpscreen_step[i-start]++;
907 while(helpscreen_action[j] != HA_NEXT)
912 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
924 void DrawHelpScreenElAction(int start)
927 int xstart = SX + 16;
928 int ystart = SY + 64 + 2 * 32;
929 int ystep = TILEY + 4;
935 while (helpscreen_action[j] != HA_END)
937 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
941 while (helpscreen_action[j] != HA_NEXT)
950 j += 2 * helpscreen_step[i-start];
951 graphic = helpscreen_action[j++];
952 frame_count = helpscreen_action[j++];
953 if (frame_count == -1)
954 frame_count = 1000000;
956 if (helpscreen_frame[i-start] == 0)
959 helpscreen_frame[i-start] = frame_count - 1;
963 sync_frame = frame_count - helpscreen_frame[i-start];
964 helpscreen_frame[i-start]--;
967 if (helpscreen_action[j] == HA_NEXT)
969 if (!helpscreen_frame[i-start])
970 helpscreen_step[i-start] = 0;
974 if (!helpscreen_frame[i-start])
975 helpscreen_step[i-start]++;
976 while(helpscreen_action[j] != HA_NEXT)
981 frame = getGraphicAnimationFrame(graphic, sync_frame);
983 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
998 void DrawHelpScreenElText(int start)
1001 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
1002 int ybottom = SYSIZE - 20;
1007 DrawTextFCentered(100, FC_GREEN, "The game elements:");
1009 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1012 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1013 helpscreen_eltext[i][0], FS_SMALL, FC_YELLOW);
1014 DrawText(xstart, ystart + (i - start) * ystep + 16,
1015 helpscreen_eltext[i][1], FS_SMALL, FC_YELLOW);
1018 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1021 void DrawHelpScreenMusicText(int num)
1023 int ystart = 150, ystep = 30;
1024 int ybottom = SYSIZE - 20;
1030 DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
1032 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1034 DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
1035 helpscreen_music[num][0]);
1036 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
1038 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
1039 "%s", helpscreen_music[num][1]);
1040 DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
1042 DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
1043 helpscreen_music[num][2]);
1045 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1048 PlaySoundLoop(background_loop[num]);
1052 void DrawHelpScreenCreditsText()
1054 int ystart = 150, ystep = 30;
1055 int ybottom = SYSIZE - 20;
1061 DrawTextFCentered(100, FC_GREEN,
1063 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1064 "DOS port of the game:");
1065 DrawTextFCentered(ystart + 1 * ystep, FC_RED,
1067 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
1068 "Additional toons:");
1069 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
1071 DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
1072 "...and many thanks to all contributors");
1073 DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
1076 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
1079 void DrawHelpScreenContactText()
1081 int ystart = 150, ystep = 30;
1082 int ybottom = SYSIZE - 20;
1087 DrawTextFCentered(100, FC_GREEN, "Program information:");
1089 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
1090 "This game is Freeware!");
1091 DrawTextFCentered(ystart + 1 * ystep, FC_YELLOW,
1092 "If you like it, send e-mail to:");
1093 DrawTextFCentered(ystart + 2 * ystep, FC_RED,
1094 "info@artsoft.org");
1095 DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
1096 "or SnailMail to:");
1097 DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
1099 DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
1100 "Detmolder Strasse 189");
1101 DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
1103 DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
1106 DrawTextFCentered(ystart + 7 * ystep, FC_YELLOW,
1107 "If you have created new levels,");
1108 DrawTextFCentered(ystart + 8 * ystep, FC_YELLOW,
1109 "send them to me to include them!");
1110 DrawTextFCentered(ystart + 9 * ystep, FC_YELLOW,
1113 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
1116 void DrawHelpScreen()
1121 CloseDoor(DOOR_CLOSE_2);
1123 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1124 helpscreen_step[i] = helpscreen_frame[i] = 0;
1125 helpscreen_musicpos = 0;
1126 helpscreen_state = 0;
1127 DrawHelpScreenElText(0);
1128 DrawHelpScreenElAction(0);
1132 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1135 void HandleHelpScreen(int button)
1137 static unsigned long hs_delay = 0;
1138 int num_helpscreen_els_pages =
1139 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1140 int button_released = !button;
1143 if (button_released)
1145 if (helpscreen_state < num_helpscreen_els_pages - 1)
1147 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1148 helpscreen_step[i] = helpscreen_frame[i] = 0;
1152 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1153 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1155 else if (helpscreen_state <
1156 num_helpscreen_els_pages + num_helpscreen_music - 1)
1159 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1161 else if (helpscreen_state ==
1162 num_helpscreen_els_pages + num_helpscreen_music - 1)
1165 DrawHelpScreenCreditsText();
1167 else if (helpscreen_state ==
1168 num_helpscreen_els_pages + num_helpscreen_music)
1171 DrawHelpScreenContactText();
1177 game_status = MAINMENU;
1182 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1184 if (helpscreen_state < num_helpscreen_els_pages)
1185 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1188 /* !!! workaround for playing "music" that is really a sound loop (and
1189 must therefore periodically be reactivated with the current sound
1191 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1199 void HandleTypeName(int newxpos, Key key)
1201 static int xpos = 0, ypos = 2;
1206 DrawText(SX + 6 * 32, SY + ypos * 32, setup.player_name,
1208 drawCursorXY(xpos + 6, ypos - 2, IMG_BALL_RED);
1213 if (((key >= KSYM_A && key <= KSYM_Z) ||
1214 (key >= KSYM_a && key <= KSYM_z)) &&
1215 xpos < MAX_PLAYER_NAME_LEN)
1219 if (key >= KSYM_A && key <= KSYM_Z)
1220 ascii = 'A' + (char)(key - KSYM_A);
1222 ascii = 'a' + (char)(key - KSYM_a);
1224 setup.player_name[xpos] = ascii;
1225 setup.player_name[xpos + 1] = 0;
1228 DrawText(SX + 6 * 32, SY + ypos * 32, setup.player_name,
1230 drawCursorXY(xpos + 6, ypos - 2, IMG_BALL_RED);
1232 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1235 setup.player_name[xpos] = 0;
1237 DrawBackground(SX + (xpos + 6) * 32, SY + ypos * 32, 2 * TILEX, TILEY);
1238 drawCursorXY(xpos + 6, ypos - 2, IMG_BALL_RED);
1240 else if (key == KSYM_Return && xpos > 0)
1242 DrawText(SX + 6 * 32, SY + ypos * 32, setup.player_name, FS_BIG, FC_RED);
1243 DrawBackground(SX + (xpos + 6) * 32, SY + ypos * 32, TILEX, TILEY);
1246 game_status = MAINMENU;
1252 static void DrawChooseTree(TreeInfo **ti_ptr)
1255 CloseDoor(DOOR_CLOSE_2);
1258 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1259 MapChooseTreeGadgets(*ti_ptr);
1265 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1267 struct GadgetInfo *gi = screen_gadget[id];
1268 int items_max, items_visible, item_position;
1270 items_max = numTreeInfoInGroup(ti);
1271 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1272 item_position = first_entry;
1274 if (item_position > items_max - items_visible)
1275 item_position = items_max - items_visible;
1277 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1278 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1281 static void drawChooseTreeList(int first_entry, int num_page_entries,
1285 char buffer[SCR_FIELDX * 2];
1286 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1287 int num_entries = numTreeInfoInGroup(ti);
1288 char *title_string = NULL;
1289 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1291 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1292 redraw_mask |= REDRAW_FIELD;
1295 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1296 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1297 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1298 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1300 DrawText(SX + offset, SY + offset, title_string, FS_BIG,
1301 (ti->type == TREE_TYPE_LEVEL_DIR ? FC_GREEN : FC_YELLOW));
1303 for(i=0; i<num_page_entries; i++)
1305 TreeInfo *node, *node_first;
1306 int entry_pos = first_entry + i;
1307 int ypos = MENU_SCREEN_START_YPOS + i;
1309 node_first = getTreeInfoFirstGroupEntry(ti);
1310 node = getTreeInfoFromPos(node_first, entry_pos);
1312 strncpy(buffer, node->name , max_buffer_len);
1313 buffer[max_buffer_len] = '\0';
1315 DrawText(SX + 32, SY + ypos * 32, buffer, FS_MEDIUM, node->color);
1317 if (node->parent_link)
1318 initCursor(i, IMG_ARROW_BLUE_LEFT);
1319 else if (node->level_group)
1320 initCursor(i, IMG_ARROW_BLUE_RIGHT);
1322 initCursor(i, IMG_BALL_BLUE);
1325 if (first_entry > 0)
1329 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1330 DrawGraphicThruMask(0, ypos, IMG_ARROW_BLUE_UP, 0);
1333 if (first_entry + num_page_entries < num_entries)
1335 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1337 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1338 DrawGraphicThruMask(0, ypos, IMG_ARROW_BLUE_DOWN, 0);
1342 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1344 TreeInfo *node, *node_first;
1345 int x, last_redraw_mask = redraw_mask;
1347 if (ti->type != TREE_TYPE_LEVEL_DIR)
1350 node_first = getTreeInfoFirstGroupEntry(ti);
1351 node = getTreeInfoFromPos(node_first, entry_pos);
1353 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1355 if (node->parent_link)
1356 DrawTextFCentered(40, FC_RED, "leave group \"%s\"", node->class_desc);
1357 else if (node->level_group)
1358 DrawTextFCentered(40, FC_RED, "enter group \"%s\"", node->class_desc);
1359 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1360 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
1361 node->levels, node->class_desc);
1363 /* let BackToFront() redraw only what is needed */
1364 redraw_mask = last_redraw_mask | REDRAW_TILES;
1365 for (x=0; x<SCR_FIELDX; x++)
1366 MarkTileDirty(x, 1);
1369 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1372 static unsigned long choose_delay = 0;
1373 TreeInfo *ti = *ti_ptr;
1375 int y = ti->cl_cursor;
1376 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1377 int num_entries = numTreeInfoInGroup(ti);
1378 int num_page_entries;
1380 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1381 num_page_entries = num_entries;
1383 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1385 if (button == MB_MENU_INITIALIZE)
1387 int entry_pos = posTreeInfo(ti);
1389 if (ti->cl_first == -1)
1391 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1393 entry_pos - ti->cl_first;
1396 if (dx == 999) /* first entry is set by scrollbar position */
1399 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1402 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1403 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1404 drawCursor(ti->cl_cursor, FC_RED);
1407 else if (button == MB_MENU_LEAVE)
1409 if (ti->node_parent)
1411 *ti_ptr = ti->node_parent;
1412 DrawChooseTree(ti_ptr);
1414 else if (game_status == SETUP)
1420 game_status = MAINMENU;
1427 if (mx || my) /* mouse input */
1430 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1432 else if (dx || dy) /* keyboard input */
1435 y = ti->cl_cursor + dy;
1437 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1440 step = num_page_entries - 1;
1441 y = (dy < 0 ? -1 : num_page_entries);
1445 if (x == 0 && y == -1)
1447 if (ti->cl_first > 0 &&
1448 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1450 ti->cl_first -= step;
1451 if (ti->cl_first < 0)
1454 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1455 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1456 drawCursor(ti->cl_cursor, FC_RED);
1457 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1462 else if (x == 0 && y > num_page_entries - 1)
1464 if (ti->cl_first + num_page_entries < num_entries &&
1465 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1467 ti->cl_first += step;
1468 if (ti->cl_first + num_page_entries > num_entries)
1469 ti->cl_first = MAX(0, num_entries - num_page_entries);
1471 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1472 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1473 drawCursor(ti->cl_cursor, FC_RED);
1474 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1482 TreeInfo *node_first, *node_cursor;
1483 int entry_pos = ti->cl_first + y;
1485 node_first = getTreeInfoFirstGroupEntry(ti);
1486 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1488 if (node_cursor->node_group)
1490 node_cursor->cl_first = ti->cl_first;
1491 node_cursor->cl_cursor = ti->cl_cursor;
1492 *ti_ptr = node_cursor->node_group;
1493 DrawChooseTree(ti_ptr);
1497 else if (dx == -1 && ti->node_parent)
1499 *ti_ptr = ti->node_parent;
1500 DrawChooseTree(ti_ptr);
1504 if (x == 0 && y >= 0 && y < num_page_entries)
1508 if (y != ti->cl_cursor)
1510 drawCursor(y, FC_RED);
1511 drawCursor(ti->cl_cursor, FC_BLUE);
1512 drawChooseTreeInfo(ti->cl_first + y, ti);
1518 TreeInfo *node_first, *node_cursor;
1519 int entry_pos = ti->cl_first + y;
1521 node_first = getTreeInfoFirstGroupEntry(ti);
1522 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1524 if (node_cursor->node_group)
1526 node_cursor->cl_first = ti->cl_first;
1527 node_cursor->cl_cursor = ti->cl_cursor;
1528 *ti_ptr = node_cursor->node_group;
1529 DrawChooseTree(ti_ptr);
1531 else if (node_cursor->parent_link)
1533 *ti_ptr = node_cursor->node_parent;
1534 DrawChooseTree(ti_ptr);
1538 node_cursor->cl_first = ti->cl_first;
1539 node_cursor->cl_cursor = ti->cl_cursor;
1540 *ti_ptr = node_cursor;
1542 if (ti->type == TREE_TYPE_LEVEL_DIR)
1544 LoadLevelSetup_SeriesInfo();
1546 SaveLevelSetup_LastSeries();
1547 SaveLevelSetup_SeriesInfo();
1551 if (game_status == SETUP)
1557 game_status = MAINMENU;
1566 if (game_status == CHOOSELEVEL || game_status == SETUP)
1570 void DrawChooseLevel()
1572 DrawChooseTree(&leveldir_current);
1575 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1577 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1580 void DrawHallOfFame(int highlight_position)
1584 CloseDoor(DOOR_CLOSE_2);
1586 if (highlight_position < 0)
1587 LoadScore(level_nr);
1591 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1592 PlaySound(SND_MENU_HALL_OF_FAME);
1595 static void drawHallOfFameList(int first_entry, int highlight_position)
1600 DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1601 DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1603 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1605 int entry = first_entry + i;
1606 int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1609 DrawText(SX, SY + 64 + i * 32, ".................", FS_BIG, color);
1610 DrawText(SX, SY + 64 + i * 32, highscore[i].Name, FS_BIG, color);
1611 DrawText(SX + 12 * 32, SY + 64 + i * 32,
1612 int2str(highscore[i].Score, 5), FS_BIG, color);
1614 DrawText(SX, SY + 64 + i * 32, "..................................",
1615 FS_MEDIUM, FC_YELLOW);
1616 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1617 FS_MEDIUM, FC_YELLOW);
1618 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name, FS_BIG, color);
1619 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1620 int2str(highscore[entry].Score, 5), FS_MEDIUM, color);
1625 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1627 static int first_entry = 0;
1628 static int highlight_position = 0;
1629 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1630 int button_released = !button;
1632 if (button == MB_MENU_INITIALIZE)
1635 highlight_position = mx;
1636 drawHallOfFameList(first_entry, highlight_position);
1640 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1641 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1645 if (first_entry > 0)
1647 first_entry -= step;
1648 if (first_entry < 0)
1651 drawHallOfFameList(first_entry, highlight_position);
1657 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1659 first_entry += step;
1660 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1661 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1663 drawHallOfFameList(first_entry, highlight_position);
1668 if (button_released)
1670 FadeSound(SND_MENU_HALL_OF_FAME);
1671 game_status = MAINMENU;
1677 if (game_status == HALLOFFAME)
1682 /* ========================================================================= */
1683 /* setup screen functions */
1684 /* ========================================================================= */
1686 static struct TokenInfo *setup_info;
1687 static int num_setup_info;
1689 static char *graphics_set_name;
1690 static char *sounds_set_name;
1691 static char *music_set_name;
1693 static void execSetupMain()
1695 setup_mode = SETUP_MODE_MAIN;
1699 static void execSetupGame()
1701 setup_mode = SETUP_MODE_GAME;
1705 static void execSetupEditor()
1707 setup_mode = SETUP_MODE_EDITOR;
1711 static void execSetupGraphics()
1713 setup_mode = SETUP_MODE_GRAPHICS;
1717 static void execSetupSound()
1719 setup_mode = SETUP_MODE_SOUND;
1723 static void execSetupArtwork()
1725 /* needed if last screen (setup choice) changed graphics, sounds or music */
1726 ReloadCustomArtwork();
1728 setup.graphics_set = artwork.gfx_current->identifier;
1729 setup.sounds_set = artwork.snd_current->identifier;
1730 setup.music_set = artwork.mus_current->identifier;
1732 /* needed for displaying artwork name instead of artwork identifier */
1733 graphics_set_name = artwork.gfx_current->name;
1734 sounds_set_name = artwork.snd_current->name;
1735 music_set_name = artwork.mus_current->name;
1737 setup_mode = SETUP_MODE_ARTWORK;
1741 static void execSetupChooseGraphics()
1743 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1747 static void execSetupChooseSounds()
1749 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1753 static void execSetupChooseMusic()
1755 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1759 static void execSetupInput()
1761 setup_mode = SETUP_MODE_INPUT;
1765 static void execSetupShortcut()
1767 setup_mode = SETUP_MODE_SHORTCUT;
1771 static void execExitSetup()
1773 game_status = MAINMENU;
1777 static void execSaveAndExitSetup()
1783 static struct TokenInfo setup_info_main[] =
1785 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1786 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1787 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1788 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1789 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1790 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1791 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1792 { TYPE_EMPTY, NULL, "" },
1793 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1794 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1798 static struct TokenInfo setup_info_game[] =
1800 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1801 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1802 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1803 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1804 { TYPE_EMPTY, NULL, "" },
1805 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1809 static struct TokenInfo setup_info_editor[] =
1811 { TYPE_STRING, NULL, "Offer Special Elements:"},
1812 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1813 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1814 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1815 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1816 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1817 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1818 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1819 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1820 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1821 { TYPE_EMPTY, NULL, "" },
1822 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1826 static struct TokenInfo setup_info_graphics[] =
1828 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1829 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1830 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1832 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1833 { TYPE_SWITCH, &setup.fading, "Fading:" },
1835 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1836 { TYPE_SWITCH, &setup.toons, "Toons:" },
1837 { TYPE_EMPTY, NULL, "" },
1838 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1842 static struct TokenInfo setup_info_sound[] =
1844 { TYPE_SWITCH, &setup.sound, "Sound:", },
1845 { TYPE_EMPTY, NULL, "" },
1846 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1847 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1848 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1849 { TYPE_EMPTY, NULL, "" },
1850 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1854 static struct TokenInfo setup_info_artwork[] =
1856 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1857 { TYPE_STRING, &graphics_set_name, "" },
1858 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1859 { TYPE_STRING, &sounds_set_name, "" },
1860 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1861 { TYPE_STRING, &music_set_name, "" },
1862 { TYPE_EMPTY, NULL, "" },
1863 { TYPE_STRING, NULL, "Override Level Artwork:"},
1864 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1865 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1866 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1867 { TYPE_EMPTY, NULL, "" },
1868 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1872 static struct TokenInfo setup_info_shortcut[] =
1874 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1875 { TYPE_KEY, &setup.shortcut.save_game, "" },
1876 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1877 { TYPE_KEY, &setup.shortcut.load_game, "" },
1878 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1879 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1880 { TYPE_EMPTY, NULL, "" },
1881 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1882 { TYPE_EMPTY, NULL, "" },
1883 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1887 static Key getSetupKey()
1889 Key key = KSYM_UNDEFINED;
1890 boolean got_key_event = FALSE;
1892 while (!got_key_event)
1894 if (PendingEvent()) /* got event */
1902 case EVENT_KEYPRESS:
1904 key = GetEventKey((KeyEvent *)&event, TRUE);
1906 /* press 'Escape' or 'Enter' to keep the existing key binding */
1907 if (key == KSYM_Escape || key == KSYM_Return)
1908 key = KSYM_UNDEFINED; /* keep old value */
1910 got_key_event = TRUE;
1914 case EVENT_KEYRELEASE:
1915 key_joystick_mapping = 0;
1919 HandleOtherEvents(&event);
1927 /* don't eat all CPU time */
1934 static void drawSetupValue(int pos)
1936 int xpos = MENU_SCREEN_VALUE_XPOS;
1937 int ypos = MENU_SCREEN_START_YPOS + pos;
1938 int font_size = FS_BIG;
1939 int font_color = FC_YELLOW;
1940 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1941 setup_info[pos].value);
1943 if (value_string == NULL)
1946 if (setup_info[pos].type & TYPE_KEY)
1950 if (setup_info[pos].type & TYPE_QUERY)
1952 value_string = "<press key>";
1953 font_color = FC_RED;
1956 else if (setup_info[pos].type & TYPE_STRING)
1958 int max_value_len = (SCR_FIELDX - 2) * 2;
1961 font_size = FS_MEDIUM;
1963 if (strlen(value_string) > max_value_len)
1964 value_string[max_value_len] = '\0';
1966 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
1967 !*(boolean *)(setup_info[pos].value))
1968 font_color = FC_BLUE;
1970 DrawText(SX + xpos * 32, SY + ypos * 32,
1971 (xpos == 3 ? " " : " "), FS_BIG, FC_YELLOW);
1972 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, font_size,font_color);
1975 static void changeSetupValue(int pos)
1977 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1979 *(boolean *)setup_info[pos].value ^= TRUE;
1981 else if (setup_info[pos].type & TYPE_KEY)
1985 setup_info[pos].type |= TYPE_QUERY;
1986 drawSetupValue(pos);
1987 setup_info[pos].type &= ~TYPE_QUERY;
1989 key = getSetupKey();
1990 if (key != KSYM_UNDEFINED)
1991 *(Key *)setup_info[pos].value = key;
1994 drawSetupValue(pos);
1997 static void DrawSetupScreen_Generic()
1999 char *title_string = NULL;
2003 CloseDoor(DOOR_CLOSE_2);
2006 if (setup_mode == SETUP_MODE_MAIN)
2008 setup_info = setup_info_main;
2009 title_string = "Setup";
2011 else if (setup_mode == SETUP_MODE_GAME)
2013 setup_info = setup_info_game;
2014 title_string = "Setup Game";
2016 else if (setup_mode == SETUP_MODE_EDITOR)
2018 setup_info = setup_info_editor;
2019 title_string = "Setup Editor";
2021 else if (setup_mode == SETUP_MODE_GRAPHICS)
2023 setup_info = setup_info_graphics;
2024 title_string = "Setup Graphics";
2026 else if (setup_mode == SETUP_MODE_SOUND)
2028 setup_info = setup_info_sound;
2029 title_string = "Setup Sound";
2031 else if (setup_mode == SETUP_MODE_ARTWORK)
2033 setup_info = setup_info_artwork;
2034 title_string = "Custom Artwork";
2036 else if (setup_mode == SETUP_MODE_SHORTCUT)
2038 setup_info = setup_info_shortcut;
2039 title_string = "Setup Shortcuts";
2042 DrawText(SX + 16, SY + 16, title_string, FS_BIG, FC_YELLOW);
2045 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2047 void *value_ptr = setup_info[i].value;
2048 int ypos = MENU_SCREEN_START_YPOS + i;
2049 int font_size = FS_BIG;
2051 /* set some entries to "unchangeable" according to other variables */
2052 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2053 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2054 (value_ptr == &setup.sound_music && !audio.music_available) ||
2055 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2056 setup_info[i].type |= TYPE_GHOSTED;
2058 if (setup_info[i].type & TYPE_STRING)
2059 font_size = FS_MEDIUM;
2061 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, font_size, FC_GREEN);
2063 if (setup_info[i].type & TYPE_ENTER_MENU)
2064 initCursor(i, IMG_ARROW_BLUE_RIGHT);
2065 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2066 initCursor(i, IMG_ARROW_BLUE_LEFT);
2067 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2068 initCursor(i, IMG_BALL_BLUE);
2070 if (setup_info[i].type & TYPE_VALUE)
2078 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2081 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2083 static int choice_store[MAX_SETUP_MODES];
2084 int choice = choice_store[setup_mode]; /* always starts with 0 */
2088 if (button == MB_MENU_INITIALIZE)
2090 /* advance to first valid menu entry */
2091 while (choice < num_setup_info &&
2092 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2094 choice_store[setup_mode] = choice;
2096 drawCursor(choice, FC_RED);
2099 else if (button == MB_MENU_LEAVE)
2101 for (y=0; y<num_setup_info; y++)
2103 if (setup_info[y].type & TYPE_LEAVE_MENU)
2105 void (*menu_callback_function)(void) = setup_info[y].value;
2107 menu_callback_function();
2108 break; /* absolutely needed because function changes 'setup_info'! */
2115 if (mx || my) /* mouse input */
2118 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2120 else if (dx || dy) /* keyboard input */
2124 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2126 if ((setup_info[choice].type & menu_navigation_type) ||
2127 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2128 button = MB_MENU_CHOICE;
2133 /* jump to next non-empty menu entry (up or down) */
2134 while (y > 0 && y < num_setup_info - 1 &&
2135 (setup_info[y].type & TYPE_SKIP_ENTRY))
2139 if (x == 0 && y >= 0 && y < num_setup_info &&
2140 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2146 drawCursor(y, FC_RED);
2147 drawCursor(choice, FC_BLUE);
2148 choice = choice_store[setup_mode] = y;
2151 else if (!(setup_info[y].type & TYPE_GHOSTED))
2153 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2155 void (*menu_callback_function)(void) = setup_info[choice].value;
2157 menu_callback_function();
2161 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2162 (setup_info[y + 1].type & TYPE_KEY))
2165 if (setup_info[y].type & TYPE_VALUE)
2166 changeSetupValue(y);
2173 if (game_status == SETUP)
2177 void DrawSetupScreen_Input()
2180 DrawText(SX+16, SY+16, "Setup Input", FS_BIG, FC_YELLOW);
2182 initCursor(0, IMG_BALL_BLUE);
2183 initCursor(1, IMG_BALL_BLUE);
2184 initCursor(2, IMG_ARROW_BLUE_RIGHT);
2185 initCursor(13, IMG_ARROW_BLUE_LEFT);
2187 drawCursorXY(10, 0, IMG_ARROW_BLUE_LEFT);
2188 drawCursorXY(12, 0, IMG_ARROW_BLUE_RIGHT);
2190 DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
2191 DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
2192 DrawText(SX+32, SY+15*32, "Back", FS_BIG, FC_GREEN);
2195 DeactivateJoystickForCalibration();
2196 DrawTextFCentered(SYSIZE - 20, FC_BLUE,
2197 "Joysticks deactivated on this screen");
2200 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2205 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2207 if (device_name == NULL)
2210 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2213 if (strlen(device_name) > 1)
2215 char c1 = device_name[strlen(device_name) - 1];
2216 char c2 = device_name[strlen(device_name) - 2];
2218 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2219 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2222 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2223 strlen(device_name));
2226 static void drawPlayerSetupInputInfo(int player_nr)
2229 static struct SetupKeyboardInfo custom_key;
2236 { &custom_key.left, "Joystick Left" },
2237 { &custom_key.right, "Joystick Right" },
2238 { &custom_key.up, "Joystick Up" },
2239 { &custom_key.down, "Joystick Down" },
2240 { &custom_key.snap, "Button 1" },
2241 { &custom_key.bomb, "Button 2" }
2243 static char *joystick_name[MAX_PLAYERS] =
2251 custom_key = setup.input[player_nr].key;
2253 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
2254 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER1, player_nr), 0);
2256 if (setup.input[player_nr].use_joystick)
2258 char *device_name = setup.input[player_nr].joy.device_name;
2260 DrawText(SX+8*32, SY+3*32,
2261 joystick_name[getJoystickNrFromDeviceName(device_name)],
2263 DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
2267 DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
2268 DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
2271 DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
2272 drawCursorXY(1, 4, IMG_ARROW_BLUE_LEFT);
2273 drawCursorXY(1, 5, IMG_ARROW_BLUE_RIGHT);
2274 drawCursorXY(1, 6, IMG_ARROW_BLUE_UP);
2275 drawCursorXY(1, 7, IMG_ARROW_BLUE_DOWN);
2276 DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
2277 DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
2278 DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
2279 DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
2280 DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
2281 DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
2285 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2287 DrawText(SX + 3*32, SY + ypos*32,
2288 " ", FS_BIG, FC_YELLOW);
2289 DrawText(SX + 3*32, SY + ypos*32,
2290 (setup.input[player_nr].use_joystick ?
2292 getKeyNameFromKey(*custom[i].key)),
2297 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2299 static int choice = 0;
2300 static int player_nr = 0;
2303 int pos_start = SETUPINPUT_SCREEN_POS_START;
2304 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2305 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2306 int pos_end = SETUPINPUT_SCREEN_POS_END;
2308 if (button == MB_MENU_INITIALIZE)
2310 drawPlayerSetupInputInfo(player_nr);
2311 drawCursor(choice, FC_RED);
2314 else if (button == MB_MENU_LEAVE)
2316 setup_mode = SETUP_MODE_MAIN;
2321 if (mx || my) /* mouse input */
2324 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2326 else if (dx || dy) /* keyboard input */
2328 if (dx && choice == 0)
2329 x = (dx < 0 ? 10 : 12);
2330 else if ((dx && choice == 1) ||
2331 (dx == +1 && choice == 2) ||
2332 (dx == -1 && choice == pos_end))
2333 button = MB_MENU_CHOICE;
2337 if (y >= pos_empty1 && y <= pos_empty2)
2338 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2341 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2343 static unsigned long delay = 0;
2345 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2348 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2350 drawPlayerSetupInputInfo(player_nr);
2352 else if (x == 0 && y >= pos_start && y <= pos_end &&
2353 !(y >= pos_empty1 && y <= pos_empty2))
2359 drawCursor(y, FC_RED);
2360 drawCursor(choice, FC_BLUE);
2368 char *device_name = setup.input[player_nr].joy.device_name;
2370 if (!setup.input[player_nr].use_joystick)
2372 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2374 setJoystickDeviceToNr(device_name, new_device_nr);
2375 setup.input[player_nr].use_joystick = TRUE;
2379 int device_nr = getJoystickNrFromDeviceName(device_name);
2380 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2382 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2383 setup.input[player_nr].use_joystick = FALSE;
2385 setJoystickDeviceToNr(device_name, new_device_nr);
2388 drawPlayerSetupInputInfo(player_nr);
2392 if (setup.input[player_nr].use_joystick)
2395 CalibrateJoystick(player_nr);
2398 CustomizeKeyboard(player_nr);
2400 else if (y == pos_end)
2404 setup_mode = SETUP_MODE_MAIN;
2414 if (game_status == SETUP)
2418 void CustomizeKeyboard(int player_nr)
2422 boolean finished = FALSE;
2423 static struct SetupKeyboardInfo custom_key;
2428 } customize_step[] =
2430 { &custom_key.left, "Move Left" },
2431 { &custom_key.right, "Move Right" },
2432 { &custom_key.up, "Move Up" },
2433 { &custom_key.down, "Move Down" },
2434 { &custom_key.snap, "Snap Field" },
2435 { &custom_key.bomb, "Place Bomb" }
2438 /* read existing key bindings from player setup */
2439 custom_key = setup.input[player_nr].key;
2442 DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
2448 DrawText(SX, SY + (2+2*step_nr)*32,
2449 customize_step[step_nr].text, FS_BIG, FC_RED);
2450 DrawText(SX, SY + (2+2*step_nr+1)*32,
2451 "Key:", FS_BIG, FC_RED);
2452 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2453 getKeyNameFromKey(*customize_step[step_nr].key),
2458 if (PendingEvent()) /* got event */
2466 case EVENT_KEYPRESS:
2468 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2470 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2476 /* all keys configured -- wait for "Escape" or "Return" key */
2480 /* press 'Enter' to keep the existing key binding */
2481 if (key == KSYM_Return)
2482 key = *customize_step[step_nr].key;
2484 /* check if key already used */
2485 for (i=0; i<step_nr; i++)
2486 if (*customize_step[i].key == key)
2491 /* got new key binding */
2492 *customize_step[step_nr].key = key;
2493 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2494 " ", FS_BIG, FC_YELLOW);
2495 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2496 getKeyNameFromKey(key), FS_BIG, FC_YELLOW);
2499 /* un-highlight last query */
2500 DrawText(SX, SY+(2+2*(step_nr-1))*32,
2501 customize_step[step_nr-1].text, FS_BIG, FC_GREEN);
2502 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
2503 "Key:", FS_BIG, FC_GREEN);
2505 /* press 'Enter' to leave */
2508 DrawText(SX + 16, SY + 15*32+16,
2509 "Press Enter", FS_BIG, FC_YELLOW);
2513 /* query next key binding */
2514 DrawText(SX, SY+(2+2*step_nr)*32,
2515 customize_step[step_nr].text, FS_BIG, FC_RED);
2516 DrawText(SX, SY+(2+2*step_nr+1)*32,
2517 "Key:", FS_BIG, FC_RED);
2518 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
2519 getKeyNameFromKey(*customize_step[step_nr].key),
2524 case EVENT_KEYRELEASE:
2525 key_joystick_mapping = 0;
2529 HandleOtherEvents(&event);
2537 /* don't eat all CPU time */
2541 /* write new key bindings back to player setup */
2542 setup.input[player_nr].key = custom_key;
2545 DrawSetupScreen_Input();
2548 static boolean CalibrateJoystickMain(int player_nr)
2550 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2551 int new_joystick_xright = JOYSTICK_XMIDDLE;
2552 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2553 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2554 int new_joystick_xmiddle, new_joystick_ymiddle;
2556 int joystick_fd = joystick.fd[player_nr];
2557 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2558 boolean check[3][3];
2559 int check_remaining = 3 * 3;
2564 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2567 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2576 check[x][y] = FALSE;
2577 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_BALL_BLUE, 0);
2581 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
2582 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
2583 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
2584 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
2585 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FS_BIG, FC_YELLOW);
2586 DrawText(SX, SY + 12 * 32, " AND ", FS_BIG, FC_YELLOW);
2587 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
2589 joy_value = Joystick(player_nr);
2590 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2591 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2593 /* eventually uncalibrated center position (joystick could be uncentered) */
2594 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2597 new_joystick_xmiddle = joy_x;
2598 new_joystick_ymiddle = joy_y;
2600 DrawGraphic(xpos + last_x, ypos + last_y, IMG_BALL_RED, 0);
2603 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2608 if (PendingEvent()) /* got event */
2616 case EVENT_KEYPRESS:
2617 switch(GetEventKey((KeyEvent *)&event, TRUE))
2620 if (check_remaining == 0)
2633 case EVENT_KEYRELEASE:
2634 key_joystick_mapping = 0;
2638 HandleOtherEvents(&event);
2643 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2646 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2647 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2648 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2649 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2651 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2652 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2653 setup.input[player_nr].joy.xright = new_joystick_xright;
2654 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2655 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2656 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2658 CheckJoystickData();
2660 joy_value = Joystick(player_nr);
2662 if (joy_value & JOY_BUTTON && check_remaining == 0)
2665 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2666 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2668 if (x != last_x || y != last_y)
2670 DrawGraphic(xpos + last_x, ypos + last_y, IMG_BALL_YELLOW, 0);
2671 DrawGraphic(xpos + x, ypos + y, IMG_BALL_RED, 0);
2676 if (check_remaining > 0 && !check[x+1][y+1])
2678 check[x+1][y+1] = TRUE;
2684 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2685 setup.input[player_nr].joy.xleft,
2686 setup.input[player_nr].joy.xmiddle,
2687 setup.input[player_nr].joy.xright);
2688 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2689 setup.input[player_nr].joy.yupper,
2690 setup.input[player_nr].joy.ymiddle,
2691 setup.input[player_nr].joy.ylower);
2700 /* don't eat all CPU time */
2704 /* calibrated center position (joystick should now be centered) */
2705 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2708 new_joystick_xmiddle = joy_x;
2709 new_joystick_ymiddle = joy_y;
2713 DrawSetupScreen_Input();
2715 /* wait until the last pressed button was released */
2716 while (Joystick(player_nr) & JOY_BUTTON)
2718 if (PendingEvent()) /* got event */
2723 HandleOtherEvents(&event);
2732 void CalibrateJoystick(int player_nr)
2734 if (!CalibrateJoystickMain(player_nr))
2738 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
2739 DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
2741 Delay(2000); /* show error message for two seconds */
2745 void DrawSetupScreen()
2747 DeactivateJoystick();
2749 if (setup_mode == SETUP_MODE_INPUT)
2750 DrawSetupScreen_Input();
2751 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2752 DrawChooseTree(&artwork.gfx_current);
2753 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2754 DrawChooseTree(&artwork.snd_current);
2755 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2756 DrawChooseTree(&artwork.mus_current);
2758 DrawSetupScreen_Generic();
2761 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2763 if (setup_mode == SETUP_MODE_INPUT)
2764 HandleSetupScreen_Input(mx, my, dx, dy, button);
2765 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2766 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2767 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2768 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2769 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2770 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2772 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2775 void HandleGameActions()
2777 if (game_status != PLAYING)
2780 if (local_player->LevelSolved)
2783 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2791 /* ---------- new screen button stuff -------------------------------------- */
2793 /* graphic position and size values for buttons and scrollbars */
2794 #define SC_SCROLLBUTTON_XSIZE 32
2795 #define SC_SCROLLBUTTON_YSIZE 32
2797 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2798 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2799 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2800 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2801 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2802 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2803 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2804 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2806 #define SC_BORDER_SIZE 14
2810 int gfx_unpressed, gfx_pressed;
2814 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2817 IMG_ARROW_BLUE_UP, IMG_ARROW_RED_UP,
2818 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2819 SCREEN_CTRL_ID_SCROLL_UP,
2823 IMG_ARROW_BLUE_DOWN, IMG_ARROW_RED_DOWN,
2824 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2825 SCREEN_CTRL_ID_SCROLL_DOWN,
2833 int gfx_unpressed, gfx_pressed;
2835 Bitmap **gfx_unpressed, **gfx_pressed;
2842 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2846 IMG_SCROLLBAR_BLUE, IMG_SCROLLBAR_RED,
2848 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2850 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2851 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2852 GD_TYPE_SCROLLBAR_VERTICAL,
2853 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2854 "scroll level series vertically"
2858 static void CreateScreenScrollbuttons()
2860 struct GadgetInfo *gi;
2861 unsigned long event_mask;
2864 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2866 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2867 int gfx_unpressed, gfx_pressed;
2868 int x, y, width, height;
2869 int gd_x1, gd_x2, gd_y1, gd_y2;
2870 int id = scrollbutton_info[i].gadget_id;
2872 x = scrollbutton_info[i].x;
2873 y = scrollbutton_info[i].y;
2875 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2879 width = SC_SCROLLBUTTON_XSIZE;
2880 height = SC_SCROLLBUTTON_YSIZE;
2882 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2883 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2884 gd_bitmap_unpressed = new_graphic_info[gfx_unpressed].bitmap;
2885 gd_bitmap_pressed = new_graphic_info[gfx_pressed].bitmap;
2886 gd_x1 = new_graphic_info[gfx_unpressed].src_x;
2887 gd_y1 = new_graphic_info[gfx_unpressed].src_y;
2888 gd_x2 = new_graphic_info[gfx_pressed].src_x;
2889 gd_y2 = new_graphic_info[gfx_pressed].src_y;
2891 gi = CreateGadget(GDI_CUSTOM_ID, id,
2892 GDI_CUSTOM_TYPE_ID, i,
2893 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2898 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2899 GDI_STATE, GD_BUTTON_UNPRESSED,
2900 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2901 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2902 GDI_EVENT_MASK, event_mask,
2903 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2907 Error(ERR_EXIT, "cannot create gadget");
2909 screen_gadget[id] = gi;
2913 static void CreateScreenScrollbars()
2917 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2919 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2921 int gfx_unpressed, gfx_pressed;
2923 int gd_x1, gd_x2, gd_y1, gd_y2;
2924 struct GadgetInfo *gi;
2925 int items_max, items_visible, item_position;
2926 unsigned long event_mask;
2927 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2928 int id = scrollbar_info[i].gadget_id;
2930 items_max = num_page_entries;
2931 items_visible = num_page_entries;
2934 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2937 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2938 gfx_pressed = scrollbar_info[i].gfx_pressed;
2939 gd_bitmap_unpressed = new_graphic_info[gfx_unpressed].bitmap;
2940 gd_bitmap_pressed = new_graphic_info[gfx_pressed].bitmap;
2941 gd_x1 = new_graphic_info[gfx_unpressed].src_x;
2942 gd_y1 = new_graphic_info[gfx_unpressed].src_y;
2943 gd_x2 = new_graphic_info[gfx_pressed].src_x;
2944 gd_y2 = new_graphic_info[gfx_pressed].src_y;
2946 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
2947 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
2954 gi = CreateGadget(GDI_CUSTOM_ID, id,
2955 GDI_CUSTOM_TYPE_ID, i,
2956 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2957 GDI_X, scrollbar_info[i].x,
2958 GDI_Y, scrollbar_info[i].y,
2959 GDI_WIDTH, scrollbar_info[i].width,
2960 GDI_HEIGHT, scrollbar_info[i].height,
2961 GDI_TYPE, scrollbar_info[i].type,
2962 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2963 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2964 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2965 GDI_STATE, GD_BUTTON_UNPRESSED,
2966 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2967 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2968 GDI_BORDER_SIZE, SC_BORDER_SIZE,
2969 GDI_EVENT_MASK, event_mask,
2970 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2974 Error(ERR_EXIT, "cannot create gadget");
2976 screen_gadget[id] = gi;
2980 void CreateScreenGadgets()
2986 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
2988 #if defined(TARGET_X11_NATIVE)
2989 /* copy pointers to clip mask and GC */
2990 scrollbar_bitmap[i]->clip_mask =
2991 new_graphic_info[IMG_SCROLLBAR_BLUE + i].clip_mask;
2992 scrollbar_bitmap[i]->stored_clip_gc =
2993 new_graphic_info[IMG_SCROLLBAR_BLUE + i].clip_gc;
2996 BlitBitmap(new_graphic_info[IMG_SCROLLBAR_BLUE + i].bitmap,
2997 scrollbar_bitmap[i],
2998 new_graphic_info[IMG_SCROLLBAR_BLUE + i].src_x,
2999 new_graphic_info[IMG_SCROLLBAR_BLUE + i].src_y,
3000 TILEX, TILEY, 0, 0);
3003 SDL_SetColorKey(scrollbar_bitmap[i]->surface, SDL_SRCCOLORKEY,
3004 SDL_MapRGB(scrollbar_bitmap[i]->surface->format,
3006 if ((scrollbar_bitmap[i]->surface_masked =
3007 SDL_DisplayFormat(scrollbar_bitmap[i]->surface)) == NULL)
3009 SetError("SDL_DisplayFormat(): %s", SDL_GetError());
3010 Error(ERR_EXIT, "CreateScreenGadgets() failed: %s", GetError());
3012 SDL_SetColorKey(scrollbar_bitmap[i]->surface, 0, 0);
3016 CreateScreenScrollbuttons();
3017 CreateScreenScrollbars();
3020 void FreeScreenGadgets()
3026 #if defined(TARGET_X11_NATIVE)
3027 /* prevent freeing clip mask and GC twice */
3028 scrollbar_bitmap[i]->clip_mask = None;
3029 scrollbar_bitmap[i]->stored_clip_gc = None;
3032 FreeBitmap(scrollbar_bitmap[i]);
3035 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3036 FreeGadget(screen_gadget[i]);
3039 void MapChooseTreeGadgets(TreeInfo *ti)
3041 int num_entries = numTreeInfoInGroup(ti);
3044 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
3047 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3048 MapGadget(screen_gadget[i]);
3051 void UnmapChooseTreeGadgets()
3055 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3056 UnmapGadget(screen_gadget[i]);
3059 static void HandleScreenGadgets(struct GadgetInfo *gi)
3061 int id = gi->custom_id;
3063 if (game_status != CHOOSELEVEL && game_status != SETUP)
3068 case SCREEN_CTRL_ID_SCROLL_UP:
3069 if (game_status == CHOOSELEVEL)
3070 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3071 else if (game_status == SETUP)
3072 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3075 case SCREEN_CTRL_ID_SCROLL_DOWN:
3076 if (game_status == CHOOSELEVEL)
3077 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3078 else if (game_status == SETUP)
3079 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3082 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3083 if (game_status == CHOOSELEVEL)
3084 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3085 else if (game_status == SETUP)
3086 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);