1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
27 /* screens in the setup menu */
28 #define SETUP_MODE_MAIN 0
29 #define SETUP_MODE_GAME 1
30 #define SETUP_MODE_EDITOR 2
31 #define SETUP_MODE_INPUT 3
32 #define SETUP_MODE_SHORTCUT 4
33 #define SETUP_MODE_GRAPHICS 5
34 #define SETUP_MODE_SOUND 6
35 #define SETUP_MODE_ARTWORK 7
36 #define SETUP_MODE_CHOOSE_GRAPHICS 8
37 #define SETUP_MODE_CHOOSE_SOUNDS 9
38 #define SETUP_MODE_CHOOSE_MUSIC 10
40 #define MAX_SETUP_MODES 11
42 /* for input setup functions */
43 #define SETUPINPUT_SCREEN_POS_START 0
44 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
45 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
46 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
48 /* for various menu stuff */
49 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
50 #define MENU_SCREEN_START_YPOS 2
51 #define MENU_SCREEN_VALUE_XPOS 14
53 /* buttons and scrollbars identifiers */
54 #define SCREEN_CTRL_ID_SCROLL_UP 0
55 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
56 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
58 #define NUM_SCREEN_SCROLLBUTTONS 2
59 #define NUM_SCREEN_SCROLLBARS 1
60 #define NUM_SCREEN_GADGETS 3
62 /* forward declarations of internal functions */
63 static void HandleScreenGadgets(struct GadgetInfo *);
64 static void HandleSetupScreen_Generic(int, int, int, int, int);
65 static void HandleSetupScreen_Input(int, int, int, int, int);
66 static void CustomizeKeyboard(int);
67 static void CalibrateJoystick(int);
68 static void execSetupArtwork(void);
69 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
71 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
72 static int setup_mode = SETUP_MODE_MAIN;
74 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
75 #define NUM_SCROLLBAR_BITMAPS 2
76 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
80 static void drawCursorExt(int xpos, int ypos, int color, int graphic)
82 static int cursor_array[SCR_FIELDY];
87 cursor_array[ypos] = graphic;
89 graphic = cursor_array[ypos];
93 graphic = (graphic == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
94 graphic == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE:
95 IMG_MENU_BUTTON_ACTIVE);
97 ypos += MENU_SCREEN_START_YPOS;
99 DrawBackground(SX + xpos * 32, SY + ypos * 32, TILEX, TILEY);
100 DrawGraphicThruMask(xpos, ypos, graphic, 0);
103 static void initCursor(int ypos, int graphic)
105 drawCursorExt(0, ypos, FC_BLUE, graphic);
108 static void drawCursor(int ypos, int color)
110 drawCursorExt(0, ypos, color, 0);
113 static void drawCursorXY(int xpos, int ypos, int graphic)
115 drawCursorExt(xpos, ypos, -1, graphic);
118 static void PlaySound_Menu_Start(int sound)
120 if (sound_info[sound].loop)
121 PlaySoundLoop(sound);
126 static void PlaySound_Menu_Continue(int sound)
128 if (sound_info[sound].loop)
129 PlaySoundLoop(sound);
132 void DrawTextStatic(int x, int y, char *text, int font_nr)
134 if (game_status == MAINMENU && gfx.menu_main_hide_static_text)
137 DrawText(x, y, text, font_nr);
142 int font1_xsize = getFontWidth(FONT_TITLE_1);
143 int font2_xsize = getFontWidth(FONT_TITLE_2);
144 int x1 = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * font1_xsize) / 2;
145 int x2 = SX + (SXSIZE - strlen(WINDOW_SUBTITLE_STRING) * font2_xsize) / 2;
147 DrawTextStatic(x1, SY + 8, PROGRAM_TITLE_STRING, FONT_TITLE_1);
148 DrawTextStatic(x2, SY + 46, WINDOW_SUBTITLE_STRING, FONT_TITLE_2);
151 static void ToggleFullscreenIfNeeded()
153 if (setup.fullscreen != video.fullscreen_enabled)
155 /* save old door content */
156 BlitBitmap(backbuffer, bitmap_db_door,
157 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
159 /* toggle fullscreen */
160 ChangeVideoModeIfNeeded(setup.fullscreen);
161 setup.fullscreen = video.fullscreen_enabled;
163 /* redraw background to newly created backbuffer */
164 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
165 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
167 /* restore old door content */
168 BlitBitmap(bitmap_db_door, backbuffer,
169 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
171 redraw_mask = REDRAW_ALL;
177 static LevelDirTree *leveldir_last_valid = NULL;
178 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
179 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
185 KeyboardAutoRepeatOn();
188 SetDrawDeactivationMask(REDRAW_NONE);
189 SetDrawBackgroundMask(REDRAW_FIELD);
191 audio.sound_deactivated = FALSE;
193 /* needed if last screen was the playing screen, invoked from level editor */
194 if (level_editor_test_game)
196 game_status = LEVELED;
201 /* needed if last screen was the editor screen */
202 UndrawSpecialEditorDoor();
204 /* needed if last screen was the setup screen and fullscreen state changed */
205 ToggleFullscreenIfNeeded();
207 /* needed if last screen (level choice) changed graphics, sounds or music */
208 ReloadCustomArtwork();
211 SetDrawtoField(DRAW_BACKBUFFER);
214 /* map gadgets for main menu screen */
217 /* leveldir_current may be invalid (level group, parent link) */
218 if (!validLevelSeries(leveldir_current))
219 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
221 /* store valid level series information */
222 leveldir_last_valid = leveldir_current;
224 /* level_nr may have been set to value over handicap with level editor */
225 if (setup.handicap && level_nr > leveldir_current->handicap_level)
226 level_nr = leveldir_current->handicap_level;
231 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
236 DrawTextStatic(SX + 32, SY + 2*32, name_text, FONT_MENU_1);
237 DrawText(SX + 32 + name_width, SY + 2*32, setup.player_name, FONT_INPUT);
238 DrawTextStatic(SX + 32, SY + 3*32, "Level:", FONT_MENU_1);
239 DrawText(SX + 11 * 32, SY + 3*32, int2str(level_nr,3), FONT_VALUE_1);
240 DrawTextStatic(SX + 32, SY + 4*32, "Hall Of Fame", FONT_MENU_1);
241 DrawTextStatic(SX + 32, SY + 5*32, "Level Creator", FONT_MENU_1);
242 DrawTextStatic(SY + 32, SY + 6*32, "Info Screen", FONT_MENU_1);
243 DrawTextStatic(SX + 32, SY + 7*32, "Start Game", FONT_MENU_1);
244 DrawTextStatic(SX + 32, SY + 8*32, "Setup", FONT_MENU_1);
245 DrawTextStatic(SX + 32, SY + 9*32, "Quit", FONT_MENU_1);
247 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
249 DrawTextF(7*32 + 6, 3*32 + 9, FONT_TEXT_3, "%d-%d",
250 leveldir_current->first_level,
251 leveldir_current->last_level);
253 if (leveldir_current->readonly)
255 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FONT_TEXT_3, "READ");
256 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FONT_TEXT_3, "ONLY");
260 initCursor(i, (i == 1 || i == 6 ? IMG_MENU_BUTTON_RIGHT :IMG_MENU_BUTTON));
263 DrawGraphic(10, 3, IMG_MENU_BUTTON_LEFT, 0);
264 DrawGraphic(14, 3, IMG_MENU_BUTTON_RIGHT, 0);
266 drawCursorXY(10, 1, IMG_MENU_BUTTON_LEFT);
267 drawCursorXY(14, 1, IMG_MENU_BUTTON_RIGHT);
270 DrawTextStatic(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
275 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
278 if (TAPE_IS_EMPTY(tape))
280 DrawCompleteVideoDisplay();
282 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
289 static void gotoTopLevelDir()
291 /* move upwards to top level directory */
292 while (leveldir_current->node_parent)
294 /* write a "path" into level tree for easy navigation to last level */
295 if (leveldir_current->node_parent->node_group->cl_first == -1)
297 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
298 int leveldir_pos = posTreeInfo(leveldir_current);
299 int num_page_entries;
300 int cl_first, cl_cursor;
302 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
303 num_page_entries = num_leveldirs;
305 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
307 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
308 cl_cursor = leveldir_pos - cl_first;
310 leveldir_current->node_parent->node_group->cl_first = cl_first;
311 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
314 leveldir_current = leveldir_current->node_parent;
318 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
320 static int choice = 0;
324 if (button == MB_MENU_INITIALIZE)
326 drawCursor(choice, FC_RED);
330 if (mx || my) /* mouse input */
333 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
335 else if (dx || dy) /* keyboard input */
337 if (dx && choice == 1)
338 x = (dx < 0 ? 10 : 14);
343 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
344 (x == 14 && level_nr < leveldir_current->last_level)) &&
347 static unsigned long level_delay = 0;
348 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
349 int new_level_nr, old_level_nr = level_nr;
351 new_level_nr = level_nr + (x == 10 ? -step : +step);
352 if (new_level_nr < leveldir_current->first_level)
353 new_level_nr = leveldir_current->first_level;
354 if (new_level_nr > leveldir_current->last_level)
355 new_level_nr = leveldir_current->last_level;
357 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
358 new_level_nr = leveldir_current->handicap_level;
360 if (old_level_nr == new_level_nr ||
361 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
364 level_nr = new_level_nr;
366 DrawText(SX + 11 * 32, SY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
369 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
373 DrawCompleteVideoDisplay();
375 /* needed because DrawMicroLevel() takes some time */
378 DelayReached(&level_delay, 0); /* reset delay counter */
380 else if (x == 0 && y >= 0 && y <= 7)
386 drawCursor(y, FC_RED);
387 drawCursor(choice, FC_BLUE);
395 game_status = TYPENAME;
396 HandleTypeName(strlen(setup.player_name), 0);
402 game_status = CHOOSELEVEL;
403 SaveLevelSetup_LastSeries();
404 SaveLevelSetup_SeriesInfo();
413 game_status = HALLOFFAME;
418 if (leveldir_current->readonly &&
419 strcmp(setup.player_name, "Artsoft") != 0)
420 Request("This level is read only !", REQ_CONFIRM);
421 game_status = LEVELED;
426 game_status = HELPSCREEN;
431 if (setup.autorecord)
432 TapeStartRecording();
434 #if defined(PLATFORM_UNIX)
436 SendToServer_StartPlaying();
440 game_status = PLAYING;
448 setup_mode = SETUP_MODE_MAIN;
453 SaveLevelSetup_LastSeries();
454 SaveLevelSetup_SeriesInfo();
455 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
456 game_status = EXITGAME;
465 if (game_status == MAINMENU)
467 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
473 #define MAX_HELPSCREEN_ELS 10
477 static long helpscreen_state;
478 static int helpscreen_step[MAX_HELPSCREEN_ELS];
479 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
481 static int OLD_helpscreen_action[] =
483 GFX_SPIELER1_DOWN,4,2,
485 GFX_SPIELER1_LEFT,4,2,
486 GFX_SPIELER1_RIGHT,4,2,
487 GFX_SPIELER1_PUSH_LEFT,4,2,
488 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
489 GFX_ERDREICH,1,100, HA_NEXT,
490 GFX_LEERRAUM,1,100, HA_NEXT,
491 GFX_MORAST_LEER,1,100, HA_NEXT,
492 GFX_BETON,1,100, HA_NEXT,
493 GFX_MAUERWERK,1,100, HA_NEXT,
494 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
495 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
496 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
497 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
498 GFX_UNSICHTBAR,1,100, HA_NEXT,
499 GFX_FELSBODEN,1,100, HA_NEXT,
500 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
501 GFX_EDELSTEIN,2,5, HA_NEXT,
502 GFX_DIAMANT,2,5, HA_NEXT,
503 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
504 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
505 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
506 GFX_FELSBROCKEN,4,5, HA_NEXT,
507 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
508 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
509 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
510 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
511 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
512 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
513 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
514 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
515 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
516 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
517 GFX_GEBLUBBER,4,4, HA_NEXT,
518 GFX_SCHLUESSEL1,4,25, HA_NEXT,
519 GFX_PFORTE1,4,25, HA_NEXT,
520 GFX_PFORTE1X,4,25, HA_NEXT,
521 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
522 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
523 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
524 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
525 GFX_LEERRAUM,1,10, HA_NEXT,
526 GFX_DYNABOMB_NR,1,100, HA_NEXT,
527 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
528 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
529 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
530 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
531 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
532 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
533 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
534 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
535 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
536 GFX_BUTTERFLY,2,2, HA_NEXT,
537 GFX_FIREFLY,2,2, HA_NEXT,
538 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
539 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
540 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
541 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
542 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
543 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
544 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
545 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
546 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
547 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
551 GFX_MOLE_RIGHT,4,2, HA_NEXT,
552 GFX_PINGUIN_DOWN,4,2,
554 GFX_PINGUIN_LEFT,4,2,
555 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
556 GFX_SCHWEIN_DOWN,4,2,
558 GFX_SCHWEIN_LEFT,4,2,
559 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
563 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
564 GFX_SONDE_START,8,1, HA_NEXT,
565 GFX_ABLENK,4,1, HA_NEXT,
566 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
567 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
568 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
569 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
570 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
571 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
572 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
573 GFX_DIAMANT,1,10, HA_NEXT,
574 GFX_LIFE,1,100, HA_NEXT,
575 GFX_LIFE_ASYNC,1,100, HA_NEXT,
576 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
577 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
578 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
579 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
580 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
581 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
582 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
583 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
584 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
585 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
586 GFX_SPEED_PILL,1,100, HA_NEXT,
591 static int helpscreen_action[] =
593 IMG_PLAYER1_MOVING_DOWN, 16,
594 IMG_PLAYER1_MOVING_UP, 16,
595 IMG_PLAYER1_MOVING_LEFT, 16,
596 IMG_PLAYER1_MOVING_RIGHT, 16,
597 IMG_PLAYER1_PUSHING_LEFT, 16,
598 IMG_PLAYER1_PUSHING_RIGHT, 16, HA_NEXT,
600 IMG_SAND, -1, HA_NEXT,
602 IMG_EMPTY_SPACE, -1, HA_NEXT,
604 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
606 IMG_STEELWALL, -1, HA_NEXT,
608 IMG_WALL, -1, HA_NEXT,
610 IMG_WALL_GROWING_ACTIVE_LEFT, 20,
613 IMG_WALL_GROWING_ACTIVE_RIGHT, 20,
616 IMG_WALL_GROWING_ACTIVE_UP, 20,
619 IMG_WALL_GROWING_ACTIVE_DOWN, 20,
621 IMG_EMPTY_SPACE, 20, HA_NEXT,
623 IMG_INVISIBLE_WALL, -1, HA_NEXT,
625 IMG_WALL_CRUMBLED, -1, HA_NEXT,
627 IMG_INFO_FONT_EM_1, 160,
628 IMG_INFO_FONT_EM_2, 160,
629 IMG_INFO_FONT_EM_3, 160,
630 IMG_INFO_FONT_EM_4, 160,
631 IMG_INFO_FONT_EM_5, 40, HA_NEXT,
633 IMG_EMERALD, -1, HA_NEXT,
635 IMG_DIAMOND, -1, HA_NEXT,
637 IMG_BD_DIAMOND, -1, HA_NEXT,
639 IMG_EMERALD_YELLOW, 50,
641 IMG_EMERALD_PURPLE, 50, HA_NEXT,
643 IMG_BD_ROCK, -1, HA_NEXT,
647 IMG_EMPTY_SPACE, 10, HA_NEXT,
651 IMG_EMERALD, 20, HA_NEXT,
653 IMG_WALL_EMERALD, 100,
655 IMG_EMERALD, 20, HA_NEXT,
657 IMG_WALL_DIAMOND, 100,
659 IMG_DIAMOND, 20, HA_NEXT,
661 IMG_WALL_BD_DIAMOND, 100,
663 IMG_BD_DIAMOND, 20, HA_NEXT,
665 IMG_WALL_EMERALD_YELLOW, 100,
667 IMG_EMERALD_YELLOW, 20,
668 IMG_WALL_EMERALD_RED, 100,
671 IMG_WALL_EMERALD_PURPLE, 100,
673 IMG_EMERALD_PURPLE, 20, HA_NEXT,
675 IMG_ACID, -1, HA_NEXT,
680 IMG_KEY4, 50, HA_NEXT,
685 IMG_GATE4, 50, HA_NEXT,
690 IMG_GATE4_GRAY, 50, HA_NEXT,
692 IMG_DYNAMITE, -1, HA_NEXT,
694 IMG_DYNAMITE_ACTIVE, 96,
696 IMG_EMPTY_SPACE, 20, HA_NEXT,
698 IMG_DYNABOMB_ACTIVE, 100,
700 IMG_EMPTY_SPACE, 20, HA_NEXT,
702 IMG_DYNABOMB_NR, -1, HA_NEXT,
704 IMG_DYNABOMB_SZ, -1, HA_NEXT,
706 IMG_SPACESHIP_RIGHT, 16,
707 IMG_SPACESHIP_UP, 16,
708 IMG_SPACESHIP_LEFT, 16,
709 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
714 IMG_BUG_DOWN, 16, HA_NEXT,
716 IMG_BD_BUTTERFLY, -1, HA_NEXT,
718 IMG_BD_FIREFLY, -1, HA_NEXT,
720 IMG_PACMAN_RIGHT, 16,
723 IMG_PACMAN_DOWN, 16, HA_NEXT,
725 IMG_YAMYAM, -1, HA_NEXT,
727 IMG_DARK_YAMYAM, -1, HA_NEXT,
729 IMG_ROBOT, -1, HA_NEXT,
731 IMG_MOLE_MOVING_RIGHT, 16,
732 IMG_MOLE_MOVING_UP, 16,
733 IMG_MOLE_MOVING_LEFT, 16,
734 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
736 IMG_PENGUIN_MOVING_RIGHT, 16,
737 IMG_PENGUIN_MOVING_UP, 16,
738 IMG_PENGUIN_MOVING_LEFT, 16,
739 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
741 IMG_PIG_MOVING_RIGHT, 16,
742 IMG_PIG_MOVING_UP, 16,
743 IMG_PIG_MOVING_LEFT, 16,
744 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
746 IMG_DRAGON_MOVING_RIGHT, 16,
747 IMG_DRAGON_MOVING_UP, 16,
748 IMG_DRAGON_MOVING_LEFT, 16,
749 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
751 IMG_SATELLITE, -1, HA_NEXT,
754 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
757 IMG_LAMP_ACTIVE, 50, HA_NEXT,
759 IMG_TIME_ORB_FULL, 50,
760 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
763 IMG_AMOEBA_CREATING, 6,
764 IMG_AMOEBA_WET, 20, HA_NEXT,
766 IMG_AMOEBA_DEAD, -1, HA_NEXT,
768 IMG_AMOEBA_WET, -1, HA_NEXT,
771 IMG_AMOEBA_CREATING, 6, HA_NEXT,
776 IMG_DIAMOND, 20, HA_NEXT,
778 IMG_GAMEOFLIFE, -1, HA_NEXT,
780 IMG_BIOMAZE, -1, HA_NEXT,
782 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
784 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
786 IMG_EXIT_CLOSED, 200,
787 IMG_EXIT_OPENING, 16,
788 IMG_EXIT_OPEN, 100, HA_NEXT,
790 IMG_EXIT_OPEN, -1, HA_NEXT,
792 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
794 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
796 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
798 IMG_SPEED_PILL, -1, HA_NEXT,
802 static char *helpscreen_eltext[][2] =
804 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
805 {"Normal sand:", "You can dig through it"},
806 {"Empty field:", "You can walk through it"},
807 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
808 {"Massive Wall:", "Nothing can go through it"},
809 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
810 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
811 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
812 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
813 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
814 {"Emerald: You must collect enough of","them to finish a level"},
815 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
816 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
817 {"Colorful Gems:", "Seem to behave like Emeralds"},
818 {"Rock: Smashes several things;", "Can be moved by the player"},
819 {"Bomb: You can move it, but be", "careful when dropping it"},
820 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
821 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
822 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
823 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
824 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
825 {"Acid: Things that fall in are gone", "forever (including our hero)"},
826 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
827 {"Door: Can be opened by the key", "with the same color"},
828 {"Door: You have to find out the", "right color of the key for it"},
829 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
830 {"Dynamite: This one explodes after", "a few seconds"},
831 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
832 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
833 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
834 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
835 {"Bug: Moves at the right side", "of walls; don't touch it!"},
836 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
837 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
838 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
839 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
840 {"Cruncher (BD style):", "Eats almost everything"},
841 {"Robot: Tries to kill the player", ""},
842 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
843 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
844 {"The Pig: Harmless, but eats all", "gems it can get"},
845 {"The Dragon: Breathes fire,", "especially to some monsters"},
846 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
847 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
848 {"Light Bulb: All of them must be", "switched on to finish a level"},
849 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
850 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
851 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
852 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
853 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
854 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
855 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
856 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
857 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
858 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
859 {"Exit door: Opens if you have enough","emeralds to finish the level"},
860 {"Open exit door: Enter here to leave","the level and exit the actual game"},
861 {"Sokoban element: Object which must", "be pushed to an empty field"},
862 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
863 {"Sokoban element: Field with object", "which can be pushed away"},
864 {"Speed pill: Lets the player run", "twice as fast as normally"},
866 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
868 static char *helpscreen_music[][3] =
870 { "Alchemy", "Ian Boddy", "Drive" },
871 { "The Chase", "Propaganda", "A Secret Wish" },
872 { "Network 23", "Tangerine Dream", "Exit" },
873 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
874 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
875 { "Voyager", "The Alan Parsons Project","Pyramid" },
876 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
878 static int num_helpscreen_music = 7;
879 static int helpscreen_musicpos;
882 void OLD_DrawHelpScreenElAction(int start)
886 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
888 while(helpscreen_action[j] != HA_END)
890 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
892 else if (i<start || helpscreen_delay[i-start])
894 if (i>=start && helpscreen_delay[i-start])
895 helpscreen_delay[i-start]--;
897 while(helpscreen_action[j] != HA_NEXT)
904 j += 3*helpscreen_step[i-start];
905 graphic = helpscreen_action[j++];
907 if (helpscreen_frame[i-start])
909 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
910 helpscreen_frame[i-start]--;
915 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
918 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
920 if (helpscreen_action[j] == HA_NEXT)
922 if (!helpscreen_frame[i-start])
923 helpscreen_step[i-start] = 0;
927 if (!helpscreen_frame[i-start])
928 helpscreen_step[i-start]++;
929 while(helpscreen_action[j] != HA_NEXT)
934 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
946 void DrawHelpScreenElAction(int start)
949 int xstart = SX + 16;
950 int ystart = SY + 64 + 2 * 32;
951 int ystep = TILEY + 4;
957 while (helpscreen_action[j] != HA_END)
959 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
963 while (helpscreen_action[j] != HA_NEXT)
972 j += 2 * helpscreen_step[i-start];
973 graphic = helpscreen_action[j++];
974 frame_count = helpscreen_action[j++];
975 if (frame_count == -1)
976 frame_count = 1000000;
978 if (helpscreen_frame[i-start] == 0)
981 helpscreen_frame[i-start] = frame_count - 1;
985 sync_frame = frame_count - helpscreen_frame[i-start];
986 helpscreen_frame[i-start]--;
989 if (helpscreen_action[j] == HA_NEXT)
991 if (!helpscreen_frame[i-start])
992 helpscreen_step[i-start] = 0;
996 if (!helpscreen_frame[i-start])
997 helpscreen_step[i-start]++;
998 while(helpscreen_action[j] != HA_NEXT)
1003 frame = getGraphicAnimationFrame(graphic, sync_frame);
1005 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
1013 MarkTileDirty(0, i);
1014 MarkTileDirty(1, i);
1020 void DrawHelpScreenElText(int start)
1023 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
1024 int ybottom = SYSIZE - 20;
1026 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1030 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
1032 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1035 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1036 helpscreen_eltext[i][0], FONT_TEXT_2);
1037 DrawText(xstart, ystart + (i - start) * ystep + 16,
1038 helpscreen_eltext[i][1], FONT_TEXT_2);
1041 DrawTextFCentered(ybottom, FONT_TEXT_4,
1042 "Press any key or button for next page");
1045 void DrawHelpScreenMusicText(int num)
1047 int ystart = 150, ystep = 30;
1048 int ybottom = SYSIZE - 20;
1054 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
1056 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
1057 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
1058 "\"%s\"", helpscreen_music[num][0]);
1059 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
1060 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
1061 "%s", helpscreen_music[num][1]);
1062 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1063 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
1064 "\"%s\"", helpscreen_music[num][2]);
1066 DrawTextFCentered(ybottom, FONT_TEXT_4,
1067 "Press any key or button for next page");
1070 PlaySoundLoop(background_loop[num]);
1074 void DrawHelpScreenCreditsText()
1076 int ystart = 150, ystep = 30;
1077 int ybottom = SYSIZE - 20;
1083 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
1084 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1085 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1086 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1087 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1088 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
1089 "...and many thanks to all contributors");
1090 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1092 DrawTextFCentered(ybottom, FONT_TEXT_4,
1093 "Press any key or button for next page");
1096 void DrawHelpScreenContactText()
1098 int ystart = 150, ystep = 30;
1099 int ybottom = SYSIZE - 20;
1104 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1106 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1107 "This game is Freeware!");
1108 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1109 "If you like it, send e-mail to:");
1110 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1111 "info@artsoft.org");
1112 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1113 "or SnailMail to:");
1114 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1116 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1117 "Detmolder Strasse 189");
1118 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1120 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1123 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1124 "If you have created new levels,");
1125 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1126 "send them to me to include them!");
1127 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1130 DrawTextFCentered(ybottom, FONT_TEXT_4,
1131 "Press any key or button for main menu");
1134 void DrawHelpScreen()
1139 CloseDoor(DOOR_CLOSE_2);
1141 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1142 helpscreen_step[i] = helpscreen_frame[i] = 0;
1143 helpscreen_musicpos = 0;
1144 helpscreen_state = 0;
1146 DrawHelpScreenElText(0);
1147 DrawHelpScreenElAction(0);
1153 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1155 PlaySound_Menu_Start(SND_MENU_INFO_SCREEN);
1159 void HandleHelpScreen(int button)
1161 static unsigned long hs_delay = 0;
1162 int num_helpscreen_els_pages =
1163 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1164 int button_released = !button;
1167 if (button_released)
1169 if (helpscreen_state < num_helpscreen_els_pages - 1)
1171 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1172 helpscreen_step[i] = helpscreen_frame[i] = 0;
1176 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1177 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1179 else if (helpscreen_state <
1180 num_helpscreen_els_pages + num_helpscreen_music - 1)
1183 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1185 else if (helpscreen_state ==
1186 num_helpscreen_els_pages + num_helpscreen_music - 1)
1189 DrawHelpScreenCreditsText();
1191 else if (helpscreen_state ==
1192 num_helpscreen_els_pages + num_helpscreen_music)
1195 DrawHelpScreenContactText();
1201 game_status = MAINMENU;
1206 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1208 if (helpscreen_state < num_helpscreen_els_pages)
1209 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1212 /* !!! workaround for playing "music" that is really a sound loop (and
1213 must therefore periodically be reactivated with the current sound
1216 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1218 PlaySound_Menu_Continue(SND_MENU_INFO_SCREEN);
1227 void HandleTypeName(int newxpos, Key key)
1229 static int xpos = 0, ypos = 2;
1230 int font_width = getFontWidth(FONT_INPUT_ACTIVE);
1231 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1232 int startx = SX + 32 + name_width;
1233 int starty = SY + ypos * 32;
1239 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1240 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1245 if (((key >= KSYM_A && key <= KSYM_Z) ||
1246 (key >= KSYM_a && key <= KSYM_z)) &&
1247 xpos < MAX_PLAYER_NAME_LEN)
1251 if (key >= KSYM_A && key <= KSYM_Z)
1252 ascii = 'A' + (char)(key - KSYM_A);
1254 ascii = 'a' + (char)(key - KSYM_a);
1256 setup.player_name[xpos] = ascii;
1257 setup.player_name[xpos + 1] = 0;
1260 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1261 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1263 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1266 setup.player_name[xpos] = 0;
1268 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_ACTIVE);
1270 else if (key == KSYM_Return && xpos > 0)
1272 DrawText(startx, starty, setup.player_name, FONT_INPUT);
1273 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_ACTIVE);
1276 game_status = MAINMENU;
1282 static void DrawChooseTree(TreeInfo **ti_ptr)
1285 CloseDoor(DOOR_CLOSE_2);
1289 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1290 MapChooseTreeGadgets(*ti_ptr);
1296 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1298 struct GadgetInfo *gi = screen_gadget[id];
1299 int items_max, items_visible, item_position;
1301 items_max = numTreeInfoInGroup(ti);
1302 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1303 item_position = first_entry;
1305 if (item_position > items_max - items_visible)
1306 item_position = items_max - items_visible;
1308 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1309 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1312 static void drawChooseTreeList(int first_entry, int num_page_entries,
1316 char buffer[SCR_FIELDX * 2];
1317 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1318 int num_entries = numTreeInfoInGroup(ti);
1319 char *title_string = NULL;
1320 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1321 int last_game_status = game_status; /* save current game status */
1323 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1324 redraw_mask |= REDRAW_FIELD;
1327 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1328 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1329 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1330 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1332 DrawText(SX + offset, SY + offset, title_string, FONT_TITLE_1);
1334 game_status = CHOOSELEVEL; /* force LEVELS font on artwork setup screen */
1336 for(i=0; i<num_page_entries; i++)
1338 TreeInfo *node, *node_first;
1339 int entry_pos = first_entry + i;
1340 int ypos = MENU_SCREEN_START_YPOS + i;
1342 node_first = getTreeInfoFirstGroupEntry(ti);
1343 node = getTreeInfoFromPos(node_first, entry_pos);
1345 strncpy(buffer, node->name , max_buffer_len);
1346 buffer[max_buffer_len] = '\0';
1348 DrawText(SX + 32, SY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1350 if (node->parent_link)
1351 initCursor(i, IMG_MENU_BUTTON_LEFT);
1352 else if (node->level_group)
1353 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1355 initCursor(i, IMG_MENU_BUTTON);
1358 if (first_entry > 0)
1362 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1363 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_UP, 0);
1366 if (first_entry + num_page_entries < num_entries)
1368 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1370 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1371 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_DOWN, 0);
1374 game_status = last_game_status; /* restore current game status */
1377 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1379 TreeInfo *node, *node_first;
1380 int x, last_redraw_mask = redraw_mask;
1382 if (ti->type != TREE_TYPE_LEVEL_DIR)
1385 node_first = getTreeInfoFirstGroupEntry(ti);
1386 node = getTreeInfoFromPos(node_first, entry_pos);
1388 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1390 if (node->parent_link)
1391 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1393 else if (node->level_group)
1394 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1396 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1397 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1398 node->levels, node->class_desc);
1400 /* let BackToFront() redraw only what is needed */
1401 redraw_mask = last_redraw_mask | REDRAW_TILES;
1402 for (x=0; x<SCR_FIELDX; x++)
1403 MarkTileDirty(x, 1);
1406 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1409 static unsigned long choose_delay = 0;
1410 TreeInfo *ti = *ti_ptr;
1412 int y = ti->cl_cursor;
1413 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1414 int num_entries = numTreeInfoInGroup(ti);
1415 int num_page_entries;
1417 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1418 num_page_entries = num_entries;
1420 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1422 if (button == MB_MENU_INITIALIZE)
1424 int entry_pos = posTreeInfo(ti);
1426 if (ti->cl_first == -1)
1428 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1430 entry_pos - ti->cl_first;
1433 if (dx == 999) /* first entry is set by scrollbar position */
1436 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1439 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1440 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1441 drawCursor(ti->cl_cursor, FC_RED);
1444 else if (button == MB_MENU_LEAVE)
1446 if (ti->node_parent)
1448 *ti_ptr = ti->node_parent;
1449 DrawChooseTree(ti_ptr);
1451 else if (game_status == SETUP)
1457 game_status = MAINMENU;
1464 if (mx || my) /* mouse input */
1467 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1469 else if (dx || dy) /* keyboard input */
1472 y = ti->cl_cursor + dy;
1474 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1477 step = num_page_entries - 1;
1478 y = (dy < 0 ? -1 : num_page_entries);
1482 if (x == 0 && y == -1)
1484 if (ti->cl_first > 0 &&
1485 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1487 ti->cl_first -= step;
1488 if (ti->cl_first < 0)
1491 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1492 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1493 drawCursor(ti->cl_cursor, FC_RED);
1494 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1499 else if (x == 0 && y > num_page_entries - 1)
1501 if (ti->cl_first + num_page_entries < num_entries &&
1502 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1504 ti->cl_first += step;
1505 if (ti->cl_first + num_page_entries > num_entries)
1506 ti->cl_first = MAX(0, num_entries - num_page_entries);
1508 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1509 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1510 drawCursor(ti->cl_cursor, FC_RED);
1511 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1519 TreeInfo *node_first, *node_cursor;
1520 int entry_pos = ti->cl_first + y;
1522 node_first = getTreeInfoFirstGroupEntry(ti);
1523 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1525 if (node_cursor->node_group)
1527 node_cursor->cl_first = ti->cl_first;
1528 node_cursor->cl_cursor = ti->cl_cursor;
1529 *ti_ptr = node_cursor->node_group;
1530 DrawChooseTree(ti_ptr);
1534 else if (dx == -1 && ti->node_parent)
1536 *ti_ptr = ti->node_parent;
1537 DrawChooseTree(ti_ptr);
1541 if (x == 0 && y >= 0 && y < num_page_entries)
1545 if (y != ti->cl_cursor)
1547 drawCursor(y, FC_RED);
1548 drawCursor(ti->cl_cursor, FC_BLUE);
1549 drawChooseTreeInfo(ti->cl_first + y, ti);
1555 TreeInfo *node_first, *node_cursor;
1556 int entry_pos = ti->cl_first + y;
1558 node_first = getTreeInfoFirstGroupEntry(ti);
1559 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1561 if (node_cursor->node_group)
1563 node_cursor->cl_first = ti->cl_first;
1564 node_cursor->cl_cursor = ti->cl_cursor;
1565 *ti_ptr = node_cursor->node_group;
1566 DrawChooseTree(ti_ptr);
1568 else if (node_cursor->parent_link)
1570 *ti_ptr = node_cursor->node_parent;
1571 DrawChooseTree(ti_ptr);
1575 node_cursor->cl_first = ti->cl_first;
1576 node_cursor->cl_cursor = ti->cl_cursor;
1577 *ti_ptr = node_cursor;
1579 if (ti->type == TREE_TYPE_LEVEL_DIR)
1581 LoadLevelSetup_SeriesInfo();
1583 SaveLevelSetup_LastSeries();
1584 SaveLevelSetup_SeriesInfo();
1588 if (game_status == SETUP)
1594 game_status = MAINMENU;
1603 if (game_status == CHOOSELEVEL || game_status == SETUP)
1607 void DrawChooseLevel()
1609 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1611 DrawChooseTree(&leveldir_current);
1614 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1616 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1619 void DrawHallOfFame(int highlight_position)
1623 CloseDoor(DOOR_CLOSE_2);
1625 if (highlight_position < 0)
1626 LoadScore(level_nr);
1631 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1634 PlaySound(SND_MENU_HALL_OF_FAME);
1636 PlaySound_Menu_Start(SND_MENU_HALL_OF_FAME);
1640 static void drawHallOfFameList(int first_entry, int highlight_position)
1644 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1647 DrawText(SX + 80, SY + 8, "Hall Of Fame", FONT_TITLE_1);
1648 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1650 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1652 int entry = first_entry + i;
1654 DrawText(SX, SY + 64 + i * 32, "..................................",
1655 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1656 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1657 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1658 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name,
1659 (entry == highlight_position ? FONT_TEXT_3 : FONT_TEXT_1));
1660 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1661 int2str(highscore[entry].Score, 5),
1662 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1666 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1668 static int first_entry = 0;
1669 static int highlight_position = 0;
1670 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1671 int button_released = !button;
1673 if (button == MB_MENU_INITIALIZE)
1676 highlight_position = mx;
1677 drawHallOfFameList(first_entry, highlight_position);
1681 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1682 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1686 if (first_entry > 0)
1688 first_entry -= step;
1689 if (first_entry < 0)
1692 drawHallOfFameList(first_entry, highlight_position);
1698 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1700 first_entry += step;
1701 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1702 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1704 drawHallOfFameList(first_entry, highlight_position);
1709 if (button_released)
1711 FadeSound(SND_MENU_HALL_OF_FAME);
1712 game_status = MAINMENU;
1718 if (game_status == HALLOFFAME)
1722 PlaySound_Menu_Continue(SND_MENU_HALL_OF_FAME);
1728 /* ========================================================================= */
1729 /* setup screen functions */
1730 /* ========================================================================= */
1732 static struct TokenInfo *setup_info;
1733 static int num_setup_info;
1735 static char *graphics_set_name;
1736 static char *sounds_set_name;
1737 static char *music_set_name;
1739 static void execSetupMain()
1741 setup_mode = SETUP_MODE_MAIN;
1745 static void execSetupGame()
1747 setup_mode = SETUP_MODE_GAME;
1751 static void execSetupEditor()
1753 setup_mode = SETUP_MODE_EDITOR;
1757 static void execSetupGraphics()
1759 setup_mode = SETUP_MODE_GRAPHICS;
1763 static void execSetupSound()
1765 setup_mode = SETUP_MODE_SOUND;
1769 static void execSetupArtwork()
1771 /* needed if last screen (setup choice) changed graphics, sounds or music */
1772 ReloadCustomArtwork();
1774 setup.graphics_set = artwork.gfx_current->identifier;
1775 setup.sounds_set = artwork.snd_current->identifier;
1776 setup.music_set = artwork.mus_current->identifier;
1778 /* needed for displaying artwork name instead of artwork identifier */
1779 graphics_set_name = artwork.gfx_current->name;
1780 sounds_set_name = artwork.snd_current->name;
1781 music_set_name = artwork.mus_current->name;
1783 setup_mode = SETUP_MODE_ARTWORK;
1787 static void execSetupChooseGraphics()
1789 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1793 static void execSetupChooseSounds()
1795 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1799 static void execSetupChooseMusic()
1801 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1805 static void execSetupInput()
1807 setup_mode = SETUP_MODE_INPUT;
1811 static void execSetupShortcut()
1813 setup_mode = SETUP_MODE_SHORTCUT;
1817 static void execExitSetup()
1819 game_status = MAINMENU;
1823 static void execSaveAndExitSetup()
1829 static struct TokenInfo setup_info_main[] =
1831 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1832 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1833 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1834 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1835 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1836 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1837 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1838 { TYPE_EMPTY, NULL, "" },
1839 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1840 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1844 static struct TokenInfo setup_info_game[] =
1846 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1847 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1848 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1849 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1850 { TYPE_EMPTY, NULL, "" },
1851 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1855 static struct TokenInfo setup_info_editor[] =
1857 { TYPE_STRING, NULL, "Offer Special Elements:"},
1858 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1859 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1860 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1861 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1862 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1863 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1864 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1865 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1866 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1867 { TYPE_EMPTY, NULL, "" },
1868 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1872 static struct TokenInfo setup_info_graphics[] =
1874 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1875 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1876 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1878 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1879 { TYPE_SWITCH, &setup.fading, "Fading:" },
1881 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1882 { TYPE_SWITCH, &setup.toons, "Toons:" },
1883 { TYPE_EMPTY, NULL, "" },
1884 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1888 static struct TokenInfo setup_info_sound[] =
1890 { TYPE_SWITCH, &setup.sound, "Sound:", },
1891 { TYPE_EMPTY, NULL, "" },
1892 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1893 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1894 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1895 { TYPE_EMPTY, NULL, "" },
1896 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1900 static struct TokenInfo setup_info_artwork[] =
1902 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1903 { TYPE_STRING, &graphics_set_name, "" },
1904 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1905 { TYPE_STRING, &sounds_set_name, "" },
1906 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1907 { TYPE_STRING, &music_set_name, "" },
1908 { TYPE_EMPTY, NULL, "" },
1909 { TYPE_STRING, NULL, "Override Level Artwork:"},
1910 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1911 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1912 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1913 { TYPE_EMPTY, NULL, "" },
1914 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1918 static struct TokenInfo setup_info_shortcut[] =
1920 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1921 { TYPE_KEY, &setup.shortcut.save_game, "" },
1922 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1923 { TYPE_KEY, &setup.shortcut.load_game, "" },
1924 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1925 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1926 { TYPE_EMPTY, NULL, "" },
1927 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1928 { TYPE_EMPTY, NULL, "" },
1929 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1933 static Key getSetupKey()
1935 Key key = KSYM_UNDEFINED;
1936 boolean got_key_event = FALSE;
1938 while (!got_key_event)
1940 if (PendingEvent()) /* got event */
1948 case EVENT_KEYPRESS:
1950 key = GetEventKey((KeyEvent *)&event, TRUE);
1952 /* press 'Escape' or 'Enter' to keep the existing key binding */
1953 if (key == KSYM_Escape || key == KSYM_Return)
1954 key = KSYM_UNDEFINED; /* keep old value */
1956 got_key_event = TRUE;
1960 case EVENT_KEYRELEASE:
1961 key_joystick_mapping = 0;
1965 HandleOtherEvents(&event);
1973 /* don't eat all CPU time */
1980 static void drawSetupValue(int pos)
1982 int xpos = MENU_SCREEN_VALUE_XPOS;
1983 int ypos = MENU_SCREEN_START_YPOS + pos;
1984 int font_nr = FONT_VALUE_1;
1985 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1986 setup_info[pos].value);
1988 if (value_string == NULL)
1991 if (setup_info[pos].type & TYPE_KEY)
1995 if (setup_info[pos].type & TYPE_QUERY)
1997 value_string = "<press key>";
1998 font_nr = FONT_INPUT_ACTIVE;
2001 else if (setup_info[pos].type & TYPE_STRING)
2003 int max_value_len = (SCR_FIELDX - 2) * 2;
2006 font_nr = FONT_VALUE_2;
2008 if (strlen(value_string) > max_value_len)
2009 value_string[max_value_len] = '\0';
2011 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
2012 !*(boolean *)(setup_info[pos].value))
2013 font_nr = FONT_OPTION_OFF;
2015 DrawText(SX + xpos * 32, SY + ypos * 32,
2016 (xpos == 3 ? " " : " "), font_nr);
2017 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, font_nr);
2020 static void changeSetupValue(int pos)
2022 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2024 *(boolean *)setup_info[pos].value ^= TRUE;
2026 else if (setup_info[pos].type & TYPE_KEY)
2030 setup_info[pos].type |= TYPE_QUERY;
2031 drawSetupValue(pos);
2032 setup_info[pos].type &= ~TYPE_QUERY;
2034 key = getSetupKey();
2035 if (key != KSYM_UNDEFINED)
2036 *(Key *)setup_info[pos].value = key;
2039 drawSetupValue(pos);
2042 static void DrawSetupScreen_Generic()
2044 char *title_string = NULL;
2048 CloseDoor(DOOR_CLOSE_2);
2052 if (setup_mode == SETUP_MODE_MAIN)
2054 setup_info = setup_info_main;
2055 title_string = "Setup";
2057 else if (setup_mode == SETUP_MODE_GAME)
2059 setup_info = setup_info_game;
2060 title_string = "Setup Game";
2062 else if (setup_mode == SETUP_MODE_EDITOR)
2064 setup_info = setup_info_editor;
2065 title_string = "Setup Editor";
2067 else if (setup_mode == SETUP_MODE_GRAPHICS)
2069 setup_info = setup_info_graphics;
2070 title_string = "Setup Graphics";
2072 else if (setup_mode == SETUP_MODE_SOUND)
2074 setup_info = setup_info_sound;
2075 title_string = "Setup Sound";
2077 else if (setup_mode == SETUP_MODE_ARTWORK)
2079 setup_info = setup_info_artwork;
2080 title_string = "Custom Artwork";
2082 else if (setup_mode == SETUP_MODE_SHORTCUT)
2084 setup_info = setup_info_shortcut;
2085 title_string = "Setup Shortcuts";
2088 DrawText(SX + 16, SY + 16, title_string, FONT_TITLE_1);
2091 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2093 void *value_ptr = setup_info[i].value;
2094 int ypos = MENU_SCREEN_START_YPOS + i;
2095 int font_nr = FONT_MENU_1;
2097 /* set some entries to "unchangeable" according to other variables */
2098 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2099 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2100 (value_ptr == &setup.sound_music && !audio.music_available) ||
2101 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2102 setup_info[i].type |= TYPE_GHOSTED;
2104 if (setup_info[i].type & TYPE_STRING)
2105 font_nr = FONT_MENU_2;
2107 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, font_nr);
2109 if (setup_info[i].type & TYPE_ENTER_MENU)
2110 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2111 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2112 initCursor(i, IMG_MENU_BUTTON_LEFT);
2113 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2114 initCursor(i, IMG_MENU_BUTTON);
2116 if (setup_info[i].type & TYPE_VALUE)
2124 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2127 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2129 static int choice_store[MAX_SETUP_MODES];
2130 int choice = choice_store[setup_mode]; /* always starts with 0 */
2134 if (button == MB_MENU_INITIALIZE)
2136 /* advance to first valid menu entry */
2137 while (choice < num_setup_info &&
2138 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2140 choice_store[setup_mode] = choice;
2142 drawCursor(choice, FC_RED);
2145 else if (button == MB_MENU_LEAVE)
2147 for (y=0; y<num_setup_info; y++)
2149 if (setup_info[y].type & TYPE_LEAVE_MENU)
2151 void (*menu_callback_function)(void) = setup_info[y].value;
2153 menu_callback_function();
2154 break; /* absolutely needed because function changes 'setup_info'! */
2161 if (mx || my) /* mouse input */
2164 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2166 else if (dx || dy) /* keyboard input */
2170 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2172 if ((setup_info[choice].type & menu_navigation_type) ||
2173 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2174 button = MB_MENU_CHOICE;
2179 /* jump to next non-empty menu entry (up or down) */
2180 while (y > 0 && y < num_setup_info - 1 &&
2181 (setup_info[y].type & TYPE_SKIP_ENTRY))
2185 if (x == 0 && y >= 0 && y < num_setup_info &&
2186 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2192 drawCursor(y, FC_RED);
2193 drawCursor(choice, FC_BLUE);
2194 choice = choice_store[setup_mode] = y;
2197 else if (!(setup_info[y].type & TYPE_GHOSTED))
2199 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2201 void (*menu_callback_function)(void) = setup_info[choice].value;
2203 menu_callback_function();
2207 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2208 (setup_info[y + 1].type & TYPE_KEY))
2211 if (setup_info[y].type & TYPE_VALUE)
2212 changeSetupValue(y);
2219 if (game_status == SETUP)
2223 void DrawSetupScreen_Input()
2227 DrawText(SX+16, SY+16, "Setup Input", FONT_TITLE_1);
2229 initCursor(0, IMG_MENU_BUTTON);
2230 initCursor(1, IMG_MENU_BUTTON);
2231 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2232 initCursor(13, IMG_MENU_BUTTON_LEFT);
2234 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2235 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2237 DrawText(SX+32, SY+2*32, "Player:", FONT_MENU_1);
2238 DrawText(SX+32, SY+3*32, "Device:", FONT_MENU_1);
2239 DrawText(SX+32, SY+15*32, "Back", FONT_MENU_1);
2242 DeactivateJoystickForCalibration();
2243 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2244 "Joysticks deactivated on this screen");
2247 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2252 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2254 if (device_name == NULL)
2257 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2260 if (strlen(device_name) > 1)
2262 char c1 = device_name[strlen(device_name) - 1];
2263 char c2 = device_name[strlen(device_name) - 2];
2265 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2266 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2269 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2270 strlen(device_name));
2273 static void drawPlayerSetupInputInfo(int player_nr)
2276 static struct SetupKeyboardInfo custom_key;
2283 { &custom_key.left, "Joystick Left" },
2284 { &custom_key.right, "Joystick Right" },
2285 { &custom_key.up, "Joystick Up" },
2286 { &custom_key.down, "Joystick Down" },
2287 { &custom_key.snap, "Button 1" },
2288 { &custom_key.bomb, "Button 2" }
2290 static char *joystick_name[MAX_PLAYERS] =
2298 custom_key = setup.input[player_nr].key;
2300 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FONT_INPUT_ACTIVE);
2301 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER1, player_nr), 0);
2303 if (setup.input[player_nr].use_joystick)
2305 char *device_name = setup.input[player_nr].joy.device_name;
2307 DrawText(SX+8*32, SY+3*32,
2308 joystick_name[getJoystickNrFromDeviceName(device_name)],
2310 DrawText(SX+32, SY+4*32, "Calibrate", FONT_MENU_1);
2314 DrawText(SX+8*32, SY+3*32, "Keyboard ", FONT_VALUE_1);
2315 DrawText(SX+32, SY+4*32, "Customize", FONT_MENU_1);
2318 DrawText(SX+32, SY+5*32, "Actual Settings:", FONT_MENU_1);
2319 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2320 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2321 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2322 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2323 DrawText(SX+2*32, SY+6*32, ":", FONT_VALUE_OLD);
2324 DrawText(SX+2*32, SY+7*32, ":", FONT_VALUE_OLD);
2325 DrawText(SX+2*32, SY+8*32, ":", FONT_VALUE_OLD);
2326 DrawText(SX+2*32, SY+9*32, ":", FONT_VALUE_OLD);
2327 DrawText(SX+32, SY+10*32, "Snap Field:", FONT_VALUE_OLD);
2328 DrawText(SX+32, SY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2332 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2334 DrawText(SX + 3*32, SY + ypos*32,
2336 DrawText(SX + 3*32, SY + ypos*32,
2337 (setup.input[player_nr].use_joystick ?
2339 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2343 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2345 static int choice = 0;
2346 static int player_nr = 0;
2349 int pos_start = SETUPINPUT_SCREEN_POS_START;
2350 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2351 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2352 int pos_end = SETUPINPUT_SCREEN_POS_END;
2354 if (button == MB_MENU_INITIALIZE)
2356 drawPlayerSetupInputInfo(player_nr);
2357 drawCursor(choice, FC_RED);
2360 else if (button == MB_MENU_LEAVE)
2362 setup_mode = SETUP_MODE_MAIN;
2367 if (mx || my) /* mouse input */
2370 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2372 else if (dx || dy) /* keyboard input */
2374 if (dx && choice == 0)
2375 x = (dx < 0 ? 10 : 12);
2376 else if ((dx && choice == 1) ||
2377 (dx == +1 && choice == 2) ||
2378 (dx == -1 && choice == pos_end))
2379 button = MB_MENU_CHOICE;
2383 if (y >= pos_empty1 && y <= pos_empty2)
2384 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2387 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2389 static unsigned long delay = 0;
2391 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2394 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2396 drawPlayerSetupInputInfo(player_nr);
2398 else if (x == 0 && y >= pos_start && y <= pos_end &&
2399 !(y >= pos_empty1 && y <= pos_empty2))
2405 drawCursor(y, FC_RED);
2406 drawCursor(choice, FC_BLUE);
2414 char *device_name = setup.input[player_nr].joy.device_name;
2416 if (!setup.input[player_nr].use_joystick)
2418 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2420 setJoystickDeviceToNr(device_name, new_device_nr);
2421 setup.input[player_nr].use_joystick = TRUE;
2425 int device_nr = getJoystickNrFromDeviceName(device_name);
2426 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2428 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2429 setup.input[player_nr].use_joystick = FALSE;
2431 setJoystickDeviceToNr(device_name, new_device_nr);
2434 drawPlayerSetupInputInfo(player_nr);
2438 if (setup.input[player_nr].use_joystick)
2441 CalibrateJoystick(player_nr);
2444 CustomizeKeyboard(player_nr);
2446 else if (y == pos_end)
2450 setup_mode = SETUP_MODE_MAIN;
2460 if (game_status == SETUP)
2464 void CustomizeKeyboard(int player_nr)
2468 boolean finished = FALSE;
2469 static struct SetupKeyboardInfo custom_key;
2474 } customize_step[] =
2476 { &custom_key.left, "Move Left" },
2477 { &custom_key.right, "Move Right" },
2478 { &custom_key.up, "Move Up" },
2479 { &custom_key.down, "Move Down" },
2480 { &custom_key.snap, "Snap Field" },
2481 { &custom_key.bomb, "Place Bomb" }
2484 /* read existing key bindings from player setup */
2485 custom_key = setup.input[player_nr].key;
2488 DrawText(SX + 16, SY + 16, "Keyboard Input", FONT_TITLE_1);
2494 DrawText(SX, SY + (2+2*step_nr)*32,
2495 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2496 DrawText(SX, SY + (2+2*step_nr+1)*32,
2497 "Key:", FONT_INPUT_ACTIVE);
2498 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2499 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2503 if (PendingEvent()) /* got event */
2511 case EVENT_KEYPRESS:
2513 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2515 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2521 /* all keys configured -- wait for "Escape" or "Return" key */
2525 /* press 'Enter' to keep the existing key binding */
2526 if (key == KSYM_Return)
2527 key = *customize_step[step_nr].key;
2529 /* check if key already used */
2530 for (i=0; i<step_nr; i++)
2531 if (*customize_step[i].key == key)
2536 /* got new key binding */
2537 *customize_step[step_nr].key = key;
2538 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2540 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2541 getKeyNameFromKey(key), FONT_VALUE_1);
2544 /* un-highlight last query */
2545 DrawText(SX, SY+(2+2*(step_nr-1))*32,
2546 customize_step[step_nr-1].text, FONT_MENU_1);
2547 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
2548 "Key:", FONT_MENU_1);
2550 /* press 'Enter' to leave */
2553 DrawText(SX + 16, SY + 15*32+16,
2554 "Press Enter", FONT_TITLE_1);
2558 /* query next key binding */
2559 DrawText(SX, SY+(2+2*step_nr)*32,
2560 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2561 DrawText(SX, SY+(2+2*step_nr+1)*32,
2562 "Key:", FONT_INPUT_ACTIVE);
2563 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
2564 getKeyNameFromKey(*customize_step[step_nr].key),
2569 case EVENT_KEYRELEASE:
2570 key_joystick_mapping = 0;
2574 HandleOtherEvents(&event);
2582 /* don't eat all CPU time */
2586 /* write new key bindings back to player setup */
2587 setup.input[player_nr].key = custom_key;
2590 DrawSetupScreen_Input();
2593 static boolean CalibrateJoystickMain(int player_nr)
2595 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2596 int new_joystick_xright = JOYSTICK_XMIDDLE;
2597 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2598 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2599 int new_joystick_xmiddle, new_joystick_ymiddle;
2601 int joystick_fd = joystick.fd[player_nr];
2602 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2603 boolean check[3][3];
2604 int check_remaining = 3 * 3;
2609 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2612 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2617 for(y=0; y < 3; y++)
2619 for(x=0; x < 3; x++)
2621 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2622 check[x][y] = FALSE;
2626 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2627 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2628 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2629 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2630 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2631 DrawText(SX, SY + 12 * 32, " AND ", FONT_TITLE_1);
2632 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2634 joy_value = Joystick(player_nr);
2635 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2636 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2638 /* eventually uncalibrated center position (joystick could be uncentered) */
2639 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2642 new_joystick_xmiddle = joy_x;
2643 new_joystick_ymiddle = joy_y;
2645 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2648 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2653 if (PendingEvent()) /* got event */
2661 case EVENT_KEYPRESS:
2662 switch(GetEventKey((KeyEvent *)&event, TRUE))
2665 if (check_remaining == 0)
2678 case EVENT_KEYRELEASE:
2679 key_joystick_mapping = 0;
2683 HandleOtherEvents(&event);
2688 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2691 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2692 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2693 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2694 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2696 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2697 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2698 setup.input[player_nr].joy.xright = new_joystick_xright;
2699 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2700 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2701 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2703 CheckJoystickData();
2705 joy_value = Joystick(player_nr);
2707 if (joy_value & JOY_BUTTON && check_remaining == 0)
2710 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2711 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2713 if (x != last_x || y != last_y)
2715 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2716 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2721 if (check_remaining > 0 && !check[x+1][y+1])
2723 check[x+1][y+1] = TRUE;
2729 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2730 setup.input[player_nr].joy.xleft,
2731 setup.input[player_nr].joy.xmiddle,
2732 setup.input[player_nr].joy.xright);
2733 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2734 setup.input[player_nr].joy.yupper,
2735 setup.input[player_nr].joy.ymiddle,
2736 setup.input[player_nr].joy.ylower);
2745 /* don't eat all CPU time */
2749 /* calibrated center position (joystick should now be centered) */
2750 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2753 new_joystick_xmiddle = joy_x;
2754 new_joystick_ymiddle = joy_y;
2758 DrawSetupScreen_Input();
2760 /* wait until the last pressed button was released */
2761 while (Joystick(player_nr) & JOY_BUTTON)
2763 if (PendingEvent()) /* got event */
2768 HandleOtherEvents(&event);
2777 void CalibrateJoystick(int player_nr)
2779 if (!CalibrateJoystickMain(player_nr))
2783 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2784 DrawText(SX, SY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2786 Delay(2000); /* show error message for two seconds */
2790 void DrawSetupScreen()
2792 DeactivateJoystick();
2794 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2796 if (setup_mode == SETUP_MODE_INPUT)
2797 DrawSetupScreen_Input();
2798 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2799 DrawChooseTree(&artwork.gfx_current);
2800 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2801 DrawChooseTree(&artwork.snd_current);
2802 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2803 DrawChooseTree(&artwork.mus_current);
2805 DrawSetupScreen_Generic();
2808 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2810 if (setup_mode == SETUP_MODE_INPUT)
2811 HandleSetupScreen_Input(mx, my, dx, dy, button);
2812 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2813 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2814 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2815 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2816 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2817 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2819 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2822 void HandleGameActions()
2824 if (game_status != PLAYING)
2827 if (local_player->LevelSolved)
2830 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2838 /* ---------- new screen button stuff -------------------------------------- */
2840 /* graphic position and size values for buttons and scrollbars */
2841 #define SC_SCROLLBUTTON_XSIZE 32
2842 #define SC_SCROLLBUTTON_YSIZE 32
2844 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2845 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2846 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2847 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2848 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2849 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2850 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2851 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2853 #define SC_BORDER_SIZE 14
2857 int gfx_unpressed, gfx_pressed;
2861 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2864 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2865 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2866 SCREEN_CTRL_ID_SCROLL_UP,
2870 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2871 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2872 SCREEN_CTRL_ID_SCROLL_DOWN,
2879 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2880 Bitmap **gfx_unpressed, **gfx_pressed;
2882 int gfx_unpressed, gfx_pressed;
2889 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2892 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2893 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2895 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2897 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2898 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2899 GD_TYPE_SCROLLBAR_VERTICAL,
2900 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2901 "scroll level series vertically"
2905 static void CreateScreenScrollbuttons()
2907 struct GadgetInfo *gi;
2908 unsigned long event_mask;
2911 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2913 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2914 int gfx_unpressed, gfx_pressed;
2915 int x, y, width, height;
2916 int gd_x1, gd_x2, gd_y1, gd_y2;
2917 int id = scrollbutton_info[i].gadget_id;
2919 x = scrollbutton_info[i].x;
2920 y = scrollbutton_info[i].y;
2922 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2926 width = SC_SCROLLBUTTON_XSIZE;
2927 height = SC_SCROLLBUTTON_YSIZE;
2929 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2930 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2931 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2932 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2933 gd_x1 = graphic_info[gfx_unpressed].src_x;
2934 gd_y1 = graphic_info[gfx_unpressed].src_y;
2935 gd_x2 = graphic_info[gfx_pressed].src_x;
2936 gd_y2 = graphic_info[gfx_pressed].src_y;
2938 gi = CreateGadget(GDI_CUSTOM_ID, id,
2939 GDI_CUSTOM_TYPE_ID, i,
2940 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2945 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2946 GDI_STATE, GD_BUTTON_UNPRESSED,
2947 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2948 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2949 GDI_EVENT_MASK, event_mask,
2950 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2954 Error(ERR_EXIT, "cannot create gadget");
2956 screen_gadget[id] = gi;
2960 static void CreateScreenScrollbars()
2964 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2966 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2967 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2968 int gfx_unpressed, gfx_pressed;
2970 int gd_x1, gd_x2, gd_y1, gd_y2;
2971 struct GadgetInfo *gi;
2972 int items_max, items_visible, item_position;
2973 unsigned long event_mask;
2974 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2975 int id = scrollbar_info[i].gadget_id;
2977 items_max = num_page_entries;
2978 items_visible = num_page_entries;
2981 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2983 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2984 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
2985 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
2991 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2992 gfx_pressed = scrollbar_info[i].gfx_pressed;
2993 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2994 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2995 gd_x1 = graphic_info[gfx_unpressed].src_x;
2996 gd_y1 = graphic_info[gfx_unpressed].src_y;
2997 gd_x2 = graphic_info[gfx_pressed].src_x;
2998 gd_y2 = graphic_info[gfx_pressed].src_y;
3001 gi = CreateGadget(GDI_CUSTOM_ID, id,
3002 GDI_CUSTOM_TYPE_ID, i,
3003 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3004 GDI_X, scrollbar_info[i].x,
3005 GDI_Y, scrollbar_info[i].y,
3006 GDI_WIDTH, scrollbar_info[i].width,
3007 GDI_HEIGHT, scrollbar_info[i].height,
3008 GDI_TYPE, scrollbar_info[i].type,
3009 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3010 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3011 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3012 GDI_STATE, GD_BUTTON_UNPRESSED,
3013 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3014 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3015 GDI_BORDER_SIZE, SC_BORDER_SIZE,
3016 GDI_EVENT_MASK, event_mask,
3017 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3021 Error(ERR_EXIT, "cannot create gadget");
3023 screen_gadget[id] = gi;
3027 void CreateScreenGadgets()
3029 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3032 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3034 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3036 /* copy pointers to clip mask and GC */
3037 scrollbar_bitmap[i]->clip_mask =
3038 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3039 scrollbar_bitmap[i]->stored_clip_gc =
3040 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3042 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3043 scrollbar_bitmap[i],
3044 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3045 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3046 TILEX, TILEY, 0, 0);
3050 CreateScreenScrollbuttons();
3051 CreateScreenScrollbars();
3054 void FreeScreenGadgets()
3058 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3059 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3061 /* prevent freeing clip mask and GC twice */
3062 scrollbar_bitmap[i]->clip_mask = None;
3063 scrollbar_bitmap[i]->stored_clip_gc = None;
3065 FreeBitmap(scrollbar_bitmap[i]);
3069 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3070 FreeGadget(screen_gadget[i]);
3073 void MapChooseTreeGadgets(TreeInfo *ti)
3075 int num_entries = numTreeInfoInGroup(ti);
3078 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
3081 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3082 MapGadget(screen_gadget[i]);
3085 void UnmapChooseTreeGadgets()
3089 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3090 UnmapGadget(screen_gadget[i]);
3093 static void HandleScreenGadgets(struct GadgetInfo *gi)
3095 int id = gi->custom_id;
3097 if (game_status != CHOOSELEVEL && game_status != SETUP)
3102 case SCREEN_CTRL_ID_SCROLL_UP:
3103 if (game_status == CHOOSELEVEL)
3104 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3105 else if (game_status == SETUP)
3106 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3109 case SCREEN_CTRL_ID_SCROLL_DOWN:
3110 if (game_status == CHOOSELEVEL)
3111 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3112 else if (game_status == SETUP)
3113 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3116 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3117 if (game_status == CHOOSELEVEL)
3118 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3119 else if (game_status == SETUP)
3120 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);