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);
134 int font1_xsize = getFontWidth(FONT_TITLE_1);
135 int font2_xsize = getFontWidth(FONT_TITLE_2);
136 int x1 = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * font1_xsize) / 2;
137 int x2 = SX + (SXSIZE - strlen(WINDOW_SUBTITLE_STRING) * font2_xsize) / 2;
139 DrawText(x1, SY + 8, PROGRAM_TITLE_STRING, FONT_TITLE_1);
140 DrawText(x2, SY + 46, WINDOW_SUBTITLE_STRING, FONT_TITLE_2);
143 static void ToggleFullscreenIfNeeded()
145 if (setup.fullscreen != video.fullscreen_enabled)
147 /* save old door content */
148 BlitBitmap(backbuffer, bitmap_db_door,
149 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
151 /* toggle fullscreen */
152 ChangeVideoModeIfNeeded(setup.fullscreen);
153 setup.fullscreen = video.fullscreen_enabled;
155 /* redraw background to newly created backbuffer */
156 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
157 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
159 /* restore old door content */
160 BlitBitmap(bitmap_db_door, backbuffer,
161 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
163 redraw_mask = REDRAW_ALL;
169 static LevelDirTree *leveldir_last_valid = NULL;
170 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
171 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
177 KeyboardAutoRepeatOn();
180 SetDrawDeactivationMask(REDRAW_NONE);
181 SetDrawBackgroundMask(REDRAW_FIELD);
183 audio.sound_deactivated = FALSE;
185 /* needed if last screen was the playing screen, invoked from level editor */
186 if (level_editor_test_game)
188 game_status = LEVELED;
193 /* needed if last screen was the editor screen */
194 UndrawSpecialEditorDoor();
196 /* needed if last screen was the setup screen and fullscreen state changed */
197 ToggleFullscreenIfNeeded();
199 /* needed if last screen (level choice) changed graphics, sounds or music */
200 ReloadCustomArtwork();
203 SetDrawtoField(DRAW_BACKBUFFER);
206 /* map gadgets for main menu screen */
209 /* leveldir_current may be invalid (level group, parent link) */
210 if (!validLevelSeries(leveldir_current))
211 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
213 /* store valid level series information */
214 leveldir_last_valid = leveldir_current;
216 /* level_nr may have been set to value over handicap with level editor */
217 if (setup.handicap && level_nr > leveldir_current->handicap_level)
218 level_nr = leveldir_current->handicap_level;
223 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
228 DrawText(SX + 32, SY + 2*32, name_text, FONT_MENU_1);
229 DrawText(SX + 32 + name_width, SY + 2*32, setup.player_name, FONT_INPUT);
230 DrawText(SX + 32, SY + 3*32, "Level:", FONT_MENU_1);
231 DrawText(SX + 11 * 32, SY + 3*32, int2str(level_nr,3), FONT_VALUE_1);
232 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FONT_MENU_1);
233 DrawText(SX + 32, SY + 5*32, "Level Creator", FONT_MENU_1);
234 DrawText(SY + 32, SY + 6*32, "Info Screen", FONT_MENU_1);
235 DrawText(SX + 32, SY + 7*32, "Start Game", FONT_MENU_1);
236 DrawText(SX + 32, SY + 8*32, "Setup", FONT_MENU_1);
237 DrawText(SX + 32, SY + 9*32, "Quit", FONT_MENU_1);
239 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
241 DrawTextF(7*32 + 6, 3*32 + 9, FONT_TEXT_3, "%d-%d",
242 leveldir_current->first_level,
243 leveldir_current->last_level);
245 if (leveldir_current->readonly)
247 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FONT_TEXT_3, "READ");
248 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FONT_TEXT_3, "ONLY");
252 initCursor(i, (i == 1 || i == 6 ? IMG_MENU_BUTTON_RIGHT :IMG_MENU_BUTTON));
255 DrawGraphic(10, 3, IMG_MENU_BUTTON_LEFT, 0);
256 DrawGraphic(14, 3, IMG_MENU_BUTTON_RIGHT, 0);
258 drawCursorXY(10, 1, IMG_MENU_BUTTON_LEFT);
259 drawCursorXY(14, 1, IMG_MENU_BUTTON_RIGHT);
262 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment", FONT_TITLE_2);
266 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
269 if (TAPE_IS_EMPTY(tape))
271 DrawCompleteVideoDisplay();
273 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
280 static void gotoTopLevelDir()
282 /* move upwards to top level directory */
283 while (leveldir_current->node_parent)
285 /* write a "path" into level tree for easy navigation to last level */
286 if (leveldir_current->node_parent->node_group->cl_first == -1)
288 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
289 int leveldir_pos = posTreeInfo(leveldir_current);
290 int num_page_entries;
291 int cl_first, cl_cursor;
293 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
294 num_page_entries = num_leveldirs;
296 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
298 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
299 cl_cursor = leveldir_pos - cl_first;
301 leveldir_current->node_parent->node_group->cl_first = cl_first;
302 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
305 leveldir_current = leveldir_current->node_parent;
309 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
311 static int choice = 0;
315 if (button == MB_MENU_INITIALIZE)
317 drawCursor(choice, FC_RED);
321 if (mx || my) /* mouse input */
324 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
326 else if (dx || dy) /* keyboard input */
328 if (dx && choice == 1)
329 x = (dx < 0 ? 10 : 14);
334 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
335 (x == 14 && level_nr < leveldir_current->last_level)) &&
338 static unsigned long level_delay = 0;
339 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
340 int new_level_nr, old_level_nr = level_nr;
342 new_level_nr = level_nr + (x == 10 ? -step : +step);
343 if (new_level_nr < leveldir_current->first_level)
344 new_level_nr = leveldir_current->first_level;
345 if (new_level_nr > leveldir_current->last_level)
346 new_level_nr = leveldir_current->last_level;
348 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
349 new_level_nr = leveldir_current->handicap_level;
351 if (old_level_nr == new_level_nr ||
352 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
355 level_nr = new_level_nr;
357 DrawText(SX + 11 * 32, SY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
360 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
364 DrawCompleteVideoDisplay();
366 /* needed because DrawMicroLevel() takes some time */
369 DelayReached(&level_delay, 0); /* reset delay counter */
371 else if (x == 0 && y >= 0 && y <= 7)
377 drawCursor(y, FC_RED);
378 drawCursor(choice, FC_BLUE);
386 game_status = TYPENAME;
387 HandleTypeName(strlen(setup.player_name), 0);
393 game_status = CHOOSELEVEL;
394 SaveLevelSetup_LastSeries();
395 SaveLevelSetup_SeriesInfo();
404 game_status = HALLOFFAME;
409 if (leveldir_current->readonly &&
410 strcmp(setup.player_name, "Artsoft") != 0)
411 Request("This level is read only !", REQ_CONFIRM);
412 game_status = LEVELED;
417 game_status = HELPSCREEN;
422 if (setup.autorecord)
423 TapeStartRecording();
425 #if defined(PLATFORM_UNIX)
427 SendToServer_StartPlaying();
431 game_status = PLAYING;
439 setup_mode = SETUP_MODE_MAIN;
444 SaveLevelSetup_LastSeries();
445 SaveLevelSetup_SeriesInfo();
446 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
447 game_status = EXITGAME;
456 if (game_status == MAINMENU)
458 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
464 #define MAX_HELPSCREEN_ELS 10
468 static long helpscreen_state;
469 static int helpscreen_step[MAX_HELPSCREEN_ELS];
470 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
472 static int OLD_helpscreen_action[] =
474 GFX_SPIELER1_DOWN,4,2,
476 GFX_SPIELER1_LEFT,4,2,
477 GFX_SPIELER1_RIGHT,4,2,
478 GFX_SPIELER1_PUSH_LEFT,4,2,
479 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
480 GFX_ERDREICH,1,100, HA_NEXT,
481 GFX_LEERRAUM,1,100, HA_NEXT,
482 GFX_MORAST_LEER,1,100, HA_NEXT,
483 GFX_BETON,1,100, HA_NEXT,
484 GFX_MAUERWERK,1,100, HA_NEXT,
485 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
486 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
487 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
488 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
489 GFX_UNSICHTBAR,1,100, HA_NEXT,
490 GFX_FELSBODEN,1,100, HA_NEXT,
491 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
492 GFX_EDELSTEIN,2,5, HA_NEXT,
493 GFX_DIAMANT,2,5, HA_NEXT,
494 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
495 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
496 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
497 GFX_FELSBROCKEN,4,5, HA_NEXT,
498 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
499 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
500 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
501 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
502 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
503 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
504 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
505 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
506 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
507 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
508 GFX_GEBLUBBER,4,4, HA_NEXT,
509 GFX_SCHLUESSEL1,4,25, HA_NEXT,
510 GFX_PFORTE1,4,25, HA_NEXT,
511 GFX_PFORTE1X,4,25, HA_NEXT,
512 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
513 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
514 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
515 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
516 GFX_LEERRAUM,1,10, HA_NEXT,
517 GFX_DYNABOMB_NR,1,100, HA_NEXT,
518 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
519 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
520 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
521 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
522 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
523 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
524 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
525 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
526 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
527 GFX_BUTTERFLY,2,2, HA_NEXT,
528 GFX_FIREFLY,2,2, HA_NEXT,
529 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
530 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
531 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
532 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
533 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
534 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
535 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
536 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
537 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
538 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
542 GFX_MOLE_RIGHT,4,2, HA_NEXT,
543 GFX_PINGUIN_DOWN,4,2,
545 GFX_PINGUIN_LEFT,4,2,
546 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
547 GFX_SCHWEIN_DOWN,4,2,
549 GFX_SCHWEIN_LEFT,4,2,
550 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
554 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
555 GFX_SONDE_START,8,1, HA_NEXT,
556 GFX_ABLENK,4,1, HA_NEXT,
557 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
558 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
559 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
560 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
561 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
562 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
563 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
564 GFX_DIAMANT,1,10, HA_NEXT,
565 GFX_LIFE,1,100, HA_NEXT,
566 GFX_LIFE_ASYNC,1,100, HA_NEXT,
567 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
568 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
569 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
570 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
571 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
572 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
573 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
574 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
575 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
576 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
577 GFX_SPEED_PILL,1,100, HA_NEXT,
582 static int helpscreen_action[] =
584 IMG_PLAYER_1_MOVING_DOWN, 16,
585 IMG_PLAYER_1_MOVING_UP, 16,
586 IMG_PLAYER_1_MOVING_LEFT, 16,
587 IMG_PLAYER_1_MOVING_RIGHT, 16,
588 IMG_PLAYER_1_PUSHING_LEFT, 16,
589 IMG_PLAYER_1_PUSHING_RIGHT, 16, HA_NEXT,
591 IMG_SAND, -1, HA_NEXT,
593 IMG_EMPTY_SPACE, -1, HA_NEXT,
595 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
597 IMG_STEELWALL, -1, HA_NEXT,
599 IMG_WALL, -1, HA_NEXT,
601 IMG_EXPANDABLE_WALL_GROWING_LEFT, 20,
604 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 20,
607 IMG_EXPANDABLE_WALL_GROWING_UP, 20,
610 IMG_EXPANDABLE_WALL_GROWING_DOWN, 20,
612 IMG_EMPTY_SPACE, 20, HA_NEXT,
614 IMG_INVISIBLE_WALL, -1, HA_NEXT,
616 IMG_WALL_CRUMBLED, -1, HA_NEXT,
618 IMG_INFO_FONT_EM_1, 160,
619 IMG_INFO_FONT_EM_2, 160,
620 IMG_INFO_FONT_EM_3, 160,
621 IMG_INFO_FONT_EM_4, 160,
622 IMG_INFO_FONT_EM_5, 40, HA_NEXT,
624 IMG_EMERALD, -1, HA_NEXT,
626 IMG_DIAMOND, -1, HA_NEXT,
628 IMG_BD_DIAMOND, -1, HA_NEXT,
630 IMG_EMERALD_YELLOW, 50,
632 IMG_EMERALD_PURPLE, 50, HA_NEXT,
634 IMG_BD_ROCK, -1, HA_NEXT,
638 IMG_EMPTY_SPACE, 10, HA_NEXT,
642 IMG_EMERALD, 20, HA_NEXT,
644 IMG_WALL_EMERALD, 100,
646 IMG_EMERALD, 20, HA_NEXT,
648 IMG_WALL_DIAMOND, 100,
650 IMG_DIAMOND, 20, HA_NEXT,
652 IMG_WALL_BD_DIAMOND, 100,
654 IMG_BD_DIAMOND, 20, HA_NEXT,
656 IMG_WALL_EMERALD_YELLOW, 100,
658 IMG_EMERALD_YELLOW, 20,
659 IMG_WALL_EMERALD_RED, 100,
662 IMG_WALL_EMERALD_PURPLE, 100,
664 IMG_EMERALD_PURPLE, 20, HA_NEXT,
666 IMG_ACID, -1, HA_NEXT,
671 IMG_KEY_4, 50, HA_NEXT,
676 IMG_GATE_4, 50, HA_NEXT,
681 IMG_GATE_4_GRAY, 50, HA_NEXT,
683 IMG_DYNAMITE, -1, HA_NEXT,
685 IMG_DYNAMITE_ACTIVE, 96,
687 IMG_EMPTY_SPACE, 20, HA_NEXT,
689 IMG_DYNABOMB_ACTIVE, 100,
691 IMG_EMPTY_SPACE, 20, HA_NEXT,
693 EL_DYNABOMB_INCREASE_NUMBER, -1, HA_NEXT,
695 EL_DYNABOMB_INCREASE_SIZE, -1, HA_NEXT,
697 IMG_SPACESHIP_RIGHT, 16,
698 IMG_SPACESHIP_UP, 16,
699 IMG_SPACESHIP_LEFT, 16,
700 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
705 IMG_BUG_DOWN, 16, HA_NEXT,
707 IMG_BD_BUTTERFLY, -1, HA_NEXT,
709 IMG_BD_FIREFLY, -1, HA_NEXT,
711 IMG_PACMAN_RIGHT, 16,
714 IMG_PACMAN_DOWN, 16, HA_NEXT,
716 IMG_YAMYAM, -1, HA_NEXT,
718 IMG_DARK_YAMYAM, -1, HA_NEXT,
720 IMG_ROBOT, -1, HA_NEXT,
722 IMG_MOLE_MOVING_RIGHT, 16,
723 IMG_MOLE_MOVING_UP, 16,
724 IMG_MOLE_MOVING_LEFT, 16,
725 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
727 IMG_PENGUIN_MOVING_RIGHT, 16,
728 IMG_PENGUIN_MOVING_UP, 16,
729 IMG_PENGUIN_MOVING_LEFT, 16,
730 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
732 IMG_PIG_MOVING_RIGHT, 16,
733 IMG_PIG_MOVING_UP, 16,
734 IMG_PIG_MOVING_LEFT, 16,
735 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
737 IMG_DRAGON_MOVING_RIGHT, 16,
738 IMG_DRAGON_MOVING_UP, 16,
739 IMG_DRAGON_MOVING_LEFT, 16,
740 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
742 IMG_SATELLITE, -1, HA_NEXT,
745 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
748 IMG_LAMP_ACTIVE, 50, HA_NEXT,
750 IMG_TIME_ORB_FULL, 50,
751 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
754 IMG_AMOEBA_GROWING, 6,
755 IMG_AMOEBA_WET, 20, HA_NEXT,
757 IMG_AMOEBA_DEAD, -1, HA_NEXT,
759 IMG_AMOEBA_WET, -1, HA_NEXT,
762 IMG_AMOEBA_GROWING, 6, HA_NEXT,
767 IMG_DIAMOND, 20, HA_NEXT,
769 IMG_GAME_OF_LIFE, -1, HA_NEXT,
771 IMG_BIOMAZE, -1, HA_NEXT,
773 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
775 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
777 IMG_EXIT_CLOSED, 200,
778 IMG_EXIT_OPENING, 16,
779 IMG_EXIT_OPEN, 100, HA_NEXT,
781 IMG_EXIT_OPEN, -1, HA_NEXT,
783 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
785 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
787 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
789 IMG_SPEED_PILL, -1, HA_NEXT,
793 static char *helpscreen_eltext[][2] =
795 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
796 {"Normal sand:", "You can dig through it"},
797 {"Empty field:", "You can walk through it"},
798 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
799 {"Massive Wall:", "Nothing can go through it"},
800 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
801 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
802 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
803 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
804 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
805 {"Emerald: You must collect enough of","them to finish a level"},
806 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
807 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
808 {"Colorful Gems:", "Seem to behave like Emeralds"},
809 {"Rock: Smashes several things;", "Can be moved by the player"},
810 {"Bomb: You can move it, but be", "careful when dropping it"},
811 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
812 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
813 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
814 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
815 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
816 {"Acid: Things that fall in are gone", "forever (including our hero)"},
817 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
818 {"Door: Can be opened by the key", "with the same color"},
819 {"Door: You have to find out the", "right color of the key for it"},
820 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
821 {"Dynamite: This one explodes after", "a few seconds"},
822 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
823 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
824 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
825 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
826 {"Bug: Moves at the right side", "of walls; don't touch it!"},
827 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
828 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
829 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
830 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
831 {"Cruncher (BD style):", "Eats almost everything"},
832 {"Robot: Tries to kill the player", ""},
833 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
834 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
835 {"The Pig: Harmless, but eats all", "gems it can get"},
836 {"The Dragon: Breathes fire,", "especially to some monsters"},
837 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
838 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
839 {"Light Bulb: All of them must be", "switched on to finish a level"},
840 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
841 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
842 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
843 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
844 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
845 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
846 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
847 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
848 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
849 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
850 {"Exit door: Opens if you have enough","emeralds to finish the level"},
851 {"Open exit door: Enter here to leave","the level and exit the actual game"},
852 {"Sokoban element: Object which must", "be pushed to an empty field"},
853 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
854 {"Sokoban element: Field with object", "which can be pushed away"},
855 {"Speed pill: Lets the player run", "twice as fast as normally"},
857 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
859 static char *helpscreen_music[][3] =
861 { "Alchemy", "Ian Boddy", "Drive" },
862 { "The Chase", "Propaganda", "A Secret Wish" },
863 { "Network 23", "Tangerine Dream", "Exit" },
864 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
865 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
866 { "Voyager", "The Alan Parsons Project","Pyramid" },
867 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
869 static int num_helpscreen_music = 7;
870 static int helpscreen_musicpos;
873 void OLD_DrawHelpScreenElAction(int start)
877 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
879 while(helpscreen_action[j] != HA_END)
881 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
883 else if (i<start || helpscreen_delay[i-start])
885 if (i>=start && helpscreen_delay[i-start])
886 helpscreen_delay[i-start]--;
888 while(helpscreen_action[j] != HA_NEXT)
895 j += 3*helpscreen_step[i-start];
896 graphic = helpscreen_action[j++];
898 if (helpscreen_frame[i-start])
900 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
901 helpscreen_frame[i-start]--;
906 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
909 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
911 if (helpscreen_action[j] == HA_NEXT)
913 if (!helpscreen_frame[i-start])
914 helpscreen_step[i-start] = 0;
918 if (!helpscreen_frame[i-start])
919 helpscreen_step[i-start]++;
920 while(helpscreen_action[j] != HA_NEXT)
925 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
937 void DrawHelpScreenElAction(int start)
940 int xstart = SX + 16;
941 int ystart = SY + 64 + 2 * 32;
942 int ystep = TILEY + 4;
948 while (helpscreen_action[j] != HA_END)
950 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
954 while (helpscreen_action[j] != HA_NEXT)
963 j += 2 * helpscreen_step[i-start];
964 graphic = helpscreen_action[j++];
965 frame_count = helpscreen_action[j++];
966 if (frame_count == -1)
967 frame_count = 1000000;
969 if (helpscreen_frame[i-start] == 0)
972 helpscreen_frame[i-start] = frame_count - 1;
976 sync_frame = frame_count - helpscreen_frame[i-start];
977 helpscreen_frame[i-start]--;
980 if (helpscreen_action[j] == HA_NEXT)
982 if (!helpscreen_frame[i-start])
983 helpscreen_step[i-start] = 0;
987 if (!helpscreen_frame[i-start])
988 helpscreen_step[i-start]++;
989 while(helpscreen_action[j] != HA_NEXT)
994 frame = getGraphicAnimationFrame(graphic, sync_frame);
996 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
1004 MarkTileDirty(0, i);
1005 MarkTileDirty(1, i);
1011 void DrawHelpScreenElText(int start)
1014 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
1015 int ybottom = SYSIZE - 20;
1017 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1021 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
1023 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1026 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1027 helpscreen_eltext[i][0], FONT_TEXT_2);
1028 DrawText(xstart, ystart + (i - start) * ystep + 16,
1029 helpscreen_eltext[i][1], FONT_TEXT_2);
1032 DrawTextFCentered(ybottom, FONT_TEXT_4,
1033 "Press any key or button for next page");
1036 void DrawHelpScreenMusicText(int num)
1038 int ystart = 150, ystep = 30;
1039 int ybottom = SYSIZE - 20;
1045 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
1047 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
1048 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
1049 "\"%s\"", helpscreen_music[num][0]);
1050 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
1051 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
1052 "%s", helpscreen_music[num][1]);
1053 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1054 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
1055 "\"%s\"", helpscreen_music[num][2]);
1057 DrawTextFCentered(ybottom, FONT_TEXT_4,
1058 "Press any key or button for next page");
1061 PlaySoundLoop(background_loop[num]);
1065 void DrawHelpScreenCreditsText()
1067 int ystart = 150, ystep = 30;
1068 int ybottom = SYSIZE - 20;
1074 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
1075 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1076 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1077 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1078 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1079 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
1080 "...and many thanks to all contributors");
1081 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1083 DrawTextFCentered(ybottom, FONT_TEXT_4,
1084 "Press any key or button for next page");
1087 void DrawHelpScreenContactText()
1089 int ystart = 150, ystep = 30;
1090 int ybottom = SYSIZE - 20;
1095 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1097 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1098 "This game is Freeware!");
1099 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1100 "If you like it, send e-mail to:");
1101 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1102 "info@artsoft.org");
1103 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1104 "or SnailMail to:");
1105 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1107 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1108 "Detmolder Strasse 189");
1109 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1111 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1114 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1115 "If you have created new levels,");
1116 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1117 "send them to me to include them!");
1118 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1121 DrawTextFCentered(ybottom, FONT_TEXT_4,
1122 "Press any key or button for main menu");
1125 void DrawHelpScreen()
1130 CloseDoor(DOOR_CLOSE_2);
1132 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1133 helpscreen_step[i] = helpscreen_frame[i] = 0;
1134 helpscreen_musicpos = 0;
1135 helpscreen_state = 0;
1137 DrawHelpScreenElText(0);
1138 DrawHelpScreenElAction(0);
1144 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1146 PlaySound_Menu_Start(SND_MENU_INFO_SCREEN);
1150 void HandleHelpScreen(int button)
1152 static unsigned long hs_delay = 0;
1153 int num_helpscreen_els_pages =
1154 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1155 int button_released = !button;
1158 if (button_released)
1160 if (helpscreen_state < num_helpscreen_els_pages - 1)
1162 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1163 helpscreen_step[i] = helpscreen_frame[i] = 0;
1167 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1168 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1170 else if (helpscreen_state <
1171 num_helpscreen_els_pages + num_helpscreen_music - 1)
1174 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1176 else if (helpscreen_state ==
1177 num_helpscreen_els_pages + num_helpscreen_music - 1)
1180 DrawHelpScreenCreditsText();
1182 else if (helpscreen_state ==
1183 num_helpscreen_els_pages + num_helpscreen_music)
1186 DrawHelpScreenContactText();
1192 game_status = MAINMENU;
1198 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1200 if (helpscreen_state < num_helpscreen_els_pages)
1201 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1204 /* !!! workaround for playing "music" that is really a sound loop (and
1205 must therefore periodically be reactivated with the current sound
1208 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1210 PlaySound_Menu_Continue(SND_MENU_INFO_SCREEN);
1219 void HandleTypeName(int newxpos, Key key)
1221 static int xpos = 0, ypos = 2;
1222 int font_width = getFontWidth(FONT_INPUT_ACTIVE);
1223 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1224 int startx = SX + 32 + name_width;
1225 int starty = SY + ypos * 32;
1231 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1232 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1237 if (((key >= KSYM_A && key <= KSYM_Z) ||
1238 (key >= KSYM_a && key <= KSYM_z)) &&
1239 xpos < MAX_PLAYER_NAME_LEN)
1243 if (key >= KSYM_A && key <= KSYM_Z)
1244 ascii = 'A' + (char)(key - KSYM_A);
1246 ascii = 'a' + (char)(key - KSYM_a);
1248 setup.player_name[xpos] = ascii;
1249 setup.player_name[xpos + 1] = 0;
1252 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1253 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1255 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1258 setup.player_name[xpos] = 0;
1260 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_ACTIVE);
1262 else if (key == KSYM_Return && xpos > 0)
1264 DrawText(startx, starty, setup.player_name, FONT_INPUT);
1265 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_ACTIVE);
1268 game_status = MAINMENU;
1274 static void DrawChooseTree(TreeInfo **ti_ptr)
1277 CloseDoor(DOOR_CLOSE_2);
1281 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1282 MapChooseTreeGadgets(*ti_ptr);
1288 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1290 struct GadgetInfo *gi = screen_gadget[id];
1291 int items_max, items_visible, item_position;
1293 items_max = numTreeInfoInGroup(ti);
1294 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1295 item_position = first_entry;
1297 if (item_position > items_max - items_visible)
1298 item_position = items_max - items_visible;
1300 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1301 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1304 static void drawChooseTreeList(int first_entry, int num_page_entries,
1308 char buffer[SCR_FIELDX * 2];
1309 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1310 int num_entries = numTreeInfoInGroup(ti);
1311 char *title_string = NULL;
1312 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1313 int last_game_status = game_status; /* save current game status */
1315 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1316 redraw_mask |= REDRAW_FIELD;
1319 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1320 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1321 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1322 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1324 DrawText(SX + offset, SY + offset, title_string, FONT_TITLE_1);
1326 game_status = CHOOSELEVEL; /* force LEVELS font on artwork setup screen */
1328 for(i=0; i<num_page_entries; i++)
1330 TreeInfo *node, *node_first;
1331 int entry_pos = first_entry + i;
1332 int ypos = MENU_SCREEN_START_YPOS + i;
1334 node_first = getTreeInfoFirstGroupEntry(ti);
1335 node = getTreeInfoFromPos(node_first, entry_pos);
1337 strncpy(buffer, node->name , max_buffer_len);
1338 buffer[max_buffer_len] = '\0';
1340 DrawText(SX + 32, SY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1342 if (node->parent_link)
1343 initCursor(i, IMG_MENU_BUTTON_LEFT);
1344 else if (node->level_group)
1345 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1347 initCursor(i, IMG_MENU_BUTTON);
1350 if (first_entry > 0)
1354 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1355 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_UP, 0);
1358 if (first_entry + num_page_entries < num_entries)
1360 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1362 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1363 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_DOWN, 0);
1366 game_status = last_game_status; /* restore current game status */
1369 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1371 TreeInfo *node, *node_first;
1372 int x, last_redraw_mask = redraw_mask;
1374 if (ti->type != TREE_TYPE_LEVEL_DIR)
1377 node_first = getTreeInfoFirstGroupEntry(ti);
1378 node = getTreeInfoFromPos(node_first, entry_pos);
1380 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1382 if (node->parent_link)
1383 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1385 else if (node->level_group)
1386 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1388 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1389 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1390 node->levels, node->class_desc);
1392 /* let BackToFront() redraw only what is needed */
1393 redraw_mask = last_redraw_mask | REDRAW_TILES;
1394 for (x=0; x<SCR_FIELDX; x++)
1395 MarkTileDirty(x, 1);
1398 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1401 static unsigned long choose_delay = 0;
1402 TreeInfo *ti = *ti_ptr;
1404 int y = ti->cl_cursor;
1405 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1406 int num_entries = numTreeInfoInGroup(ti);
1407 int num_page_entries;
1409 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1410 num_page_entries = num_entries;
1412 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1414 if (button == MB_MENU_INITIALIZE)
1416 int entry_pos = posTreeInfo(ti);
1418 if (ti->cl_first == -1)
1420 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1422 entry_pos - ti->cl_first;
1425 if (dx == 999) /* first entry is set by scrollbar position */
1428 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1431 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1432 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1433 drawCursor(ti->cl_cursor, FC_RED);
1436 else if (button == MB_MENU_LEAVE)
1438 if (ti->node_parent)
1440 *ti_ptr = ti->node_parent;
1441 DrawChooseTree(ti_ptr);
1443 else if (game_status == SETUP)
1449 game_status = MAINMENU;
1456 if (mx || my) /* mouse input */
1459 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1461 else if (dx || dy) /* keyboard input */
1464 y = ti->cl_cursor + dy;
1466 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1469 step = num_page_entries - 1;
1470 y = (dy < 0 ? -1 : num_page_entries);
1474 if (x == 0 && y == -1)
1476 if (ti->cl_first > 0 &&
1477 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1479 ti->cl_first -= step;
1480 if (ti->cl_first < 0)
1483 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1484 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1485 drawCursor(ti->cl_cursor, FC_RED);
1486 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1491 else if (x == 0 && y > num_page_entries - 1)
1493 if (ti->cl_first + num_page_entries < num_entries &&
1494 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1496 ti->cl_first += step;
1497 if (ti->cl_first + num_page_entries > num_entries)
1498 ti->cl_first = MAX(0, num_entries - num_page_entries);
1500 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1501 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1502 drawCursor(ti->cl_cursor, FC_RED);
1503 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1511 TreeInfo *node_first, *node_cursor;
1512 int entry_pos = ti->cl_first + y;
1514 node_first = getTreeInfoFirstGroupEntry(ti);
1515 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1517 if (node_cursor->node_group)
1519 node_cursor->cl_first = ti->cl_first;
1520 node_cursor->cl_cursor = ti->cl_cursor;
1521 *ti_ptr = node_cursor->node_group;
1522 DrawChooseTree(ti_ptr);
1526 else if (dx == -1 && ti->node_parent)
1528 *ti_ptr = ti->node_parent;
1529 DrawChooseTree(ti_ptr);
1533 if (x == 0 && y >= 0 && y < num_page_entries)
1537 if (y != ti->cl_cursor)
1539 drawCursor(y, FC_RED);
1540 drawCursor(ti->cl_cursor, FC_BLUE);
1541 drawChooseTreeInfo(ti->cl_first + y, ti);
1547 TreeInfo *node_first, *node_cursor;
1548 int entry_pos = ti->cl_first + y;
1550 node_first = getTreeInfoFirstGroupEntry(ti);
1551 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1553 if (node_cursor->node_group)
1555 node_cursor->cl_first = ti->cl_first;
1556 node_cursor->cl_cursor = ti->cl_cursor;
1557 *ti_ptr = node_cursor->node_group;
1558 DrawChooseTree(ti_ptr);
1560 else if (node_cursor->parent_link)
1562 *ti_ptr = node_cursor->node_parent;
1563 DrawChooseTree(ti_ptr);
1567 node_cursor->cl_first = ti->cl_first;
1568 node_cursor->cl_cursor = ti->cl_cursor;
1569 *ti_ptr = node_cursor;
1571 if (ti->type == TREE_TYPE_LEVEL_DIR)
1573 LoadLevelSetup_SeriesInfo();
1575 SaveLevelSetup_LastSeries();
1576 SaveLevelSetup_SeriesInfo();
1580 if (game_status == SETUP)
1586 game_status = MAINMENU;
1595 if (game_status == CHOOSELEVEL || game_status == SETUP)
1599 void DrawChooseLevel()
1601 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1603 DrawChooseTree(&leveldir_current);
1606 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1608 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1611 void DrawHallOfFame(int highlight_position)
1615 CloseDoor(DOOR_CLOSE_2);
1617 if (highlight_position < 0)
1618 LoadScore(level_nr);
1623 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1626 PlaySound(SND_MENU_HALL_OF_FAME);
1628 PlaySound_Menu_Start(SND_MENU_HALL_OF_FAME);
1632 static void drawHallOfFameList(int first_entry, int highlight_position)
1636 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1639 DrawText(SX + 80, SY + 8, "Hall Of Fame", FONT_TITLE_1);
1640 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1642 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1644 int entry = first_entry + i;
1646 DrawText(SX, SY + 64 + i * 32, "..................................",
1647 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1648 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1649 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1650 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name,
1651 (entry == highlight_position ? FONT_TEXT_3 : FONT_TEXT_1));
1652 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1653 int2str(highscore[entry].Score, 5),
1654 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1658 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1660 static int first_entry = 0;
1661 static int highlight_position = 0;
1662 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1663 int button_released = !button;
1665 if (button == MB_MENU_INITIALIZE)
1668 highlight_position = mx;
1669 drawHallOfFameList(first_entry, highlight_position);
1673 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1674 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1678 if (first_entry > 0)
1680 first_entry -= step;
1681 if (first_entry < 0)
1684 drawHallOfFameList(first_entry, highlight_position);
1690 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1692 first_entry += step;
1693 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1694 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1696 drawHallOfFameList(first_entry, highlight_position);
1701 if (button_released)
1703 FadeSound(SND_MENU_HALL_OF_FAME);
1704 game_status = MAINMENU;
1710 if (game_status == HALLOFFAME)
1714 PlaySound_Menu_Continue(SND_MENU_HALL_OF_FAME);
1720 /* ========================================================================= */
1721 /* setup screen functions */
1722 /* ========================================================================= */
1724 static struct TokenInfo *setup_info;
1725 static int num_setup_info;
1727 static char *graphics_set_name;
1728 static char *sounds_set_name;
1729 static char *music_set_name;
1731 static void execSetupMain()
1733 setup_mode = SETUP_MODE_MAIN;
1737 static void execSetupGame()
1739 setup_mode = SETUP_MODE_GAME;
1743 static void execSetupEditor()
1745 setup_mode = SETUP_MODE_EDITOR;
1749 static void execSetupGraphics()
1751 setup_mode = SETUP_MODE_GRAPHICS;
1755 static void execSetupSound()
1757 setup_mode = SETUP_MODE_SOUND;
1761 static void execSetupArtwork()
1763 /* needed if last screen (setup choice) changed graphics, sounds or music */
1764 ReloadCustomArtwork();
1766 setup.graphics_set = artwork.gfx_current->identifier;
1767 setup.sounds_set = artwork.snd_current->identifier;
1768 setup.music_set = artwork.mus_current->identifier;
1770 /* needed for displaying artwork name instead of artwork identifier */
1771 graphics_set_name = artwork.gfx_current->name;
1772 sounds_set_name = artwork.snd_current->name;
1773 music_set_name = artwork.mus_current->name;
1775 setup_mode = SETUP_MODE_ARTWORK;
1779 static void execSetupChooseGraphics()
1781 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1785 static void execSetupChooseSounds()
1787 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1791 static void execSetupChooseMusic()
1793 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1797 static void execSetupInput()
1799 setup_mode = SETUP_MODE_INPUT;
1803 static void execSetupShortcut()
1805 setup_mode = SETUP_MODE_SHORTCUT;
1809 static void execExitSetup()
1811 game_status = MAINMENU;
1815 static void execSaveAndExitSetup()
1821 static struct TokenInfo setup_info_main[] =
1823 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1824 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1825 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1826 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1827 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1828 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1829 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1830 { TYPE_EMPTY, NULL, "" },
1831 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1832 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1836 static struct TokenInfo setup_info_game[] =
1838 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1839 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1840 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1841 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1842 { TYPE_EMPTY, NULL, "" },
1843 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1847 static struct TokenInfo setup_info_editor[] =
1849 { TYPE_STRING, NULL, "Offer Special Elements:"},
1850 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1851 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1852 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1853 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1854 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1855 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1856 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1857 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1858 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1859 { TYPE_EMPTY, NULL, "" },
1860 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1864 static struct TokenInfo setup_info_graphics[] =
1866 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1867 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1868 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1870 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1871 { TYPE_SWITCH, &setup.fading, "Fading:" },
1873 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1874 { TYPE_SWITCH, &setup.toons, "Toons:" },
1875 { TYPE_EMPTY, NULL, "" },
1876 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1880 static struct TokenInfo setup_info_sound[] =
1882 { TYPE_SWITCH, &setup.sound, "Sound:", },
1883 { TYPE_EMPTY, NULL, "" },
1884 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1885 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1886 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1887 { TYPE_EMPTY, NULL, "" },
1888 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1892 static struct TokenInfo setup_info_artwork[] =
1894 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1895 { TYPE_STRING, &graphics_set_name, "" },
1896 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1897 { TYPE_STRING, &sounds_set_name, "" },
1898 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1899 { TYPE_STRING, &music_set_name, "" },
1900 { TYPE_EMPTY, NULL, "" },
1901 { TYPE_STRING, NULL, "Override Level Artwork:"},
1902 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1903 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1904 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1905 { TYPE_EMPTY, NULL, "" },
1906 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1910 static struct TokenInfo setup_info_shortcut[] =
1912 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1913 { TYPE_KEY, &setup.shortcut.save_game, "" },
1914 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1915 { TYPE_KEY, &setup.shortcut.load_game, "" },
1916 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1917 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1918 { TYPE_EMPTY, NULL, "" },
1919 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1920 { TYPE_EMPTY, NULL, "" },
1921 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1925 static Key getSetupKey()
1927 Key key = KSYM_UNDEFINED;
1928 boolean got_key_event = FALSE;
1930 while (!got_key_event)
1932 if (PendingEvent()) /* got event */
1940 case EVENT_KEYPRESS:
1942 key = GetEventKey((KeyEvent *)&event, TRUE);
1944 /* press 'Escape' or 'Enter' to keep the existing key binding */
1945 if (key == KSYM_Escape || key == KSYM_Return)
1946 key = KSYM_UNDEFINED; /* keep old value */
1948 got_key_event = TRUE;
1952 case EVENT_KEYRELEASE:
1953 key_joystick_mapping = 0;
1957 HandleOtherEvents(&event);
1965 /* don't eat all CPU time */
1972 static void drawSetupValue(int pos)
1974 int xpos = MENU_SCREEN_VALUE_XPOS;
1975 int ypos = MENU_SCREEN_START_YPOS + pos;
1976 int font_nr = FONT_VALUE_1;
1977 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1978 setup_info[pos].value);
1980 if (value_string == NULL)
1983 if (setup_info[pos].type & TYPE_KEY)
1987 if (setup_info[pos].type & TYPE_QUERY)
1989 value_string = "<press key>";
1990 font_nr = FONT_INPUT_ACTIVE;
1993 else if (setup_info[pos].type & TYPE_STRING)
1995 int max_value_len = (SCR_FIELDX - 2) * 2;
1998 font_nr = FONT_VALUE_2;
2000 if (strlen(value_string) > max_value_len)
2001 value_string[max_value_len] = '\0';
2003 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
2004 !*(boolean *)(setup_info[pos].value))
2005 font_nr = FONT_OPTION_OFF;
2007 DrawText(SX + xpos * 32, SY + ypos * 32,
2008 (xpos == 3 ? " " : " "), font_nr);
2009 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, font_nr);
2012 static void changeSetupValue(int pos)
2014 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2016 *(boolean *)setup_info[pos].value ^= TRUE;
2018 else if (setup_info[pos].type & TYPE_KEY)
2022 setup_info[pos].type |= TYPE_QUERY;
2023 drawSetupValue(pos);
2024 setup_info[pos].type &= ~TYPE_QUERY;
2026 key = getSetupKey();
2027 if (key != KSYM_UNDEFINED)
2028 *(Key *)setup_info[pos].value = key;
2031 drawSetupValue(pos);
2034 static void DrawSetupScreen_Generic()
2036 char *title_string = NULL;
2040 CloseDoor(DOOR_CLOSE_2);
2044 if (setup_mode == SETUP_MODE_MAIN)
2046 setup_info = setup_info_main;
2047 title_string = "Setup";
2049 else if (setup_mode == SETUP_MODE_GAME)
2051 setup_info = setup_info_game;
2052 title_string = "Setup Game";
2054 else if (setup_mode == SETUP_MODE_EDITOR)
2056 setup_info = setup_info_editor;
2057 title_string = "Setup Editor";
2059 else if (setup_mode == SETUP_MODE_GRAPHICS)
2061 setup_info = setup_info_graphics;
2062 title_string = "Setup Graphics";
2064 else if (setup_mode == SETUP_MODE_SOUND)
2066 setup_info = setup_info_sound;
2067 title_string = "Setup Sound";
2069 else if (setup_mode == SETUP_MODE_ARTWORK)
2071 setup_info = setup_info_artwork;
2072 title_string = "Custom Artwork";
2074 else if (setup_mode == SETUP_MODE_SHORTCUT)
2076 setup_info = setup_info_shortcut;
2077 title_string = "Setup Shortcuts";
2080 DrawText(SX + 16, SY + 16, title_string, FONT_TITLE_1);
2083 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2085 void *value_ptr = setup_info[i].value;
2086 int ypos = MENU_SCREEN_START_YPOS + i;
2087 int font_nr = FONT_MENU_1;
2089 /* set some entries to "unchangeable" according to other variables */
2090 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2091 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2092 (value_ptr == &setup.sound_music && !audio.music_available) ||
2093 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2094 setup_info[i].type |= TYPE_GHOSTED;
2096 if (setup_info[i].type & TYPE_STRING)
2097 font_nr = FONT_MENU_2;
2099 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, font_nr);
2101 if (setup_info[i].type & TYPE_ENTER_MENU)
2102 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2103 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2104 initCursor(i, IMG_MENU_BUTTON_LEFT);
2105 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2106 initCursor(i, IMG_MENU_BUTTON);
2108 if (setup_info[i].type & TYPE_VALUE)
2116 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2119 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2121 static int choice_store[MAX_SETUP_MODES];
2122 int choice = choice_store[setup_mode]; /* always starts with 0 */
2126 if (button == MB_MENU_INITIALIZE)
2128 /* advance to first valid menu entry */
2129 while (choice < num_setup_info &&
2130 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2132 choice_store[setup_mode] = choice;
2134 drawCursor(choice, FC_RED);
2137 else if (button == MB_MENU_LEAVE)
2139 for (y=0; y<num_setup_info; y++)
2141 if (setup_info[y].type & TYPE_LEAVE_MENU)
2143 void (*menu_callback_function)(void) = setup_info[y].value;
2145 menu_callback_function();
2146 break; /* absolutely needed because function changes 'setup_info'! */
2153 if (mx || my) /* mouse input */
2156 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2158 else if (dx || dy) /* keyboard input */
2162 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2164 if ((setup_info[choice].type & menu_navigation_type) ||
2165 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2166 button = MB_MENU_CHOICE;
2171 /* jump to next non-empty menu entry (up or down) */
2172 while (y > 0 && y < num_setup_info - 1 &&
2173 (setup_info[y].type & TYPE_SKIP_ENTRY))
2177 if (x == 0 && y >= 0 && y < num_setup_info &&
2178 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2184 drawCursor(y, FC_RED);
2185 drawCursor(choice, FC_BLUE);
2186 choice = choice_store[setup_mode] = y;
2189 else if (!(setup_info[y].type & TYPE_GHOSTED))
2191 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2193 void (*menu_callback_function)(void) = setup_info[choice].value;
2195 menu_callback_function();
2199 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2200 (setup_info[y + 1].type & TYPE_KEY))
2203 if (setup_info[y].type & TYPE_VALUE)
2204 changeSetupValue(y);
2211 if (game_status == SETUP)
2215 void DrawSetupScreen_Input()
2219 DrawText(SX+16, SY+16, "Setup Input", FONT_TITLE_1);
2221 initCursor(0, IMG_MENU_BUTTON);
2222 initCursor(1, IMG_MENU_BUTTON);
2223 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2224 initCursor(13, IMG_MENU_BUTTON_LEFT);
2226 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2227 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2229 DrawText(SX+32, SY+2*32, "Player:", FONT_MENU_1);
2230 DrawText(SX+32, SY+3*32, "Device:", FONT_MENU_1);
2231 DrawText(SX+32, SY+15*32, "Back", FONT_MENU_1);
2234 DeactivateJoystickForCalibration();
2235 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2236 "Joysticks deactivated on this screen");
2239 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2244 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2246 if (device_name == NULL)
2249 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2252 if (strlen(device_name) > 1)
2254 char c1 = device_name[strlen(device_name) - 1];
2255 char c2 = device_name[strlen(device_name) - 2];
2257 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2258 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2261 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2262 strlen(device_name));
2265 static void drawPlayerSetupInputInfo(int player_nr)
2268 static struct SetupKeyboardInfo custom_key;
2275 { &custom_key.left, "Joystick Left" },
2276 { &custom_key.right, "Joystick Right" },
2277 { &custom_key.up, "Joystick Up" },
2278 { &custom_key.down, "Joystick Down" },
2279 { &custom_key.snap, "Button 1" },
2280 { &custom_key.bomb, "Button 2" }
2282 static char *joystick_name[MAX_PLAYERS] =
2290 custom_key = setup.input[player_nr].key;
2292 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FONT_INPUT_ACTIVE);
2293 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2295 if (setup.input[player_nr].use_joystick)
2297 char *device_name = setup.input[player_nr].joy.device_name;
2299 DrawText(SX+8*32, SY+3*32,
2300 joystick_name[getJoystickNrFromDeviceName(device_name)],
2302 DrawText(SX+32, SY+4*32, "Calibrate", FONT_MENU_1);
2306 DrawText(SX+8*32, SY+3*32, "Keyboard ", FONT_VALUE_1);
2307 DrawText(SX+32, SY+4*32, "Customize", FONT_MENU_1);
2310 DrawText(SX+32, SY+5*32, "Actual Settings:", FONT_MENU_1);
2311 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2312 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2313 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2314 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2315 DrawText(SX+2*32, SY+6*32, ":", FONT_VALUE_OLD);
2316 DrawText(SX+2*32, SY+7*32, ":", FONT_VALUE_OLD);
2317 DrawText(SX+2*32, SY+8*32, ":", FONT_VALUE_OLD);
2318 DrawText(SX+2*32, SY+9*32, ":", FONT_VALUE_OLD);
2319 DrawText(SX+32, SY+10*32, "Snap Field:", FONT_VALUE_OLD);
2320 DrawText(SX+32, SY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2324 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2326 DrawText(SX + 3*32, SY + ypos*32,
2328 DrawText(SX + 3*32, SY + ypos*32,
2329 (setup.input[player_nr].use_joystick ?
2331 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2335 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2337 static int choice = 0;
2338 static int player_nr = 0;
2341 int pos_start = SETUPINPUT_SCREEN_POS_START;
2342 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2343 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2344 int pos_end = SETUPINPUT_SCREEN_POS_END;
2346 if (button == MB_MENU_INITIALIZE)
2348 drawPlayerSetupInputInfo(player_nr);
2349 drawCursor(choice, FC_RED);
2352 else if (button == MB_MENU_LEAVE)
2354 setup_mode = SETUP_MODE_MAIN;
2359 if (mx || my) /* mouse input */
2362 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2364 else if (dx || dy) /* keyboard input */
2366 if (dx && choice == 0)
2367 x = (dx < 0 ? 10 : 12);
2368 else if ((dx && choice == 1) ||
2369 (dx == +1 && choice == 2) ||
2370 (dx == -1 && choice == pos_end))
2371 button = MB_MENU_CHOICE;
2375 if (y >= pos_empty1 && y <= pos_empty2)
2376 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2379 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2381 static unsigned long delay = 0;
2383 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2386 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2388 drawPlayerSetupInputInfo(player_nr);
2390 else if (x == 0 && y >= pos_start && y <= pos_end &&
2391 !(y >= pos_empty1 && y <= pos_empty2))
2397 drawCursor(y, FC_RED);
2398 drawCursor(choice, FC_BLUE);
2406 char *device_name = setup.input[player_nr].joy.device_name;
2408 if (!setup.input[player_nr].use_joystick)
2410 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2412 setJoystickDeviceToNr(device_name, new_device_nr);
2413 setup.input[player_nr].use_joystick = TRUE;
2417 int device_nr = getJoystickNrFromDeviceName(device_name);
2418 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2420 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2421 setup.input[player_nr].use_joystick = FALSE;
2423 setJoystickDeviceToNr(device_name, new_device_nr);
2426 drawPlayerSetupInputInfo(player_nr);
2430 if (setup.input[player_nr].use_joystick)
2433 CalibrateJoystick(player_nr);
2436 CustomizeKeyboard(player_nr);
2438 else if (y == pos_end)
2442 setup_mode = SETUP_MODE_MAIN;
2452 if (game_status == SETUP)
2456 void CustomizeKeyboard(int player_nr)
2460 boolean finished = FALSE;
2461 static struct SetupKeyboardInfo custom_key;
2466 } customize_step[] =
2468 { &custom_key.left, "Move Left" },
2469 { &custom_key.right, "Move Right" },
2470 { &custom_key.up, "Move Up" },
2471 { &custom_key.down, "Move Down" },
2472 { &custom_key.snap, "Snap Field" },
2473 { &custom_key.bomb, "Place Bomb" }
2476 /* read existing key bindings from player setup */
2477 custom_key = setup.input[player_nr].key;
2480 DrawText(SX + 16, SY + 16, "Keyboard Input", FONT_TITLE_1);
2486 DrawText(SX, SY + (2+2*step_nr)*32,
2487 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2488 DrawText(SX, SY + (2+2*step_nr+1)*32,
2489 "Key:", FONT_INPUT_ACTIVE);
2490 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2491 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2495 if (PendingEvent()) /* got event */
2503 case EVENT_KEYPRESS:
2505 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2507 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2513 /* all keys configured -- wait for "Escape" or "Return" key */
2517 /* press 'Enter' to keep the existing key binding */
2518 if (key == KSYM_Return)
2519 key = *customize_step[step_nr].key;
2521 /* check if key already used */
2522 for (i=0; i<step_nr; i++)
2523 if (*customize_step[i].key == key)
2528 /* got new key binding */
2529 *customize_step[step_nr].key = key;
2530 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2532 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2533 getKeyNameFromKey(key), FONT_VALUE_1);
2536 /* un-highlight last query */
2537 DrawText(SX, SY+(2+2*(step_nr-1))*32,
2538 customize_step[step_nr-1].text, FONT_MENU_1);
2539 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
2540 "Key:", FONT_MENU_1);
2542 /* press 'Enter' to leave */
2545 DrawText(SX + 16, SY + 15*32+16,
2546 "Press Enter", FONT_TITLE_1);
2550 /* query next key binding */
2551 DrawText(SX, SY+(2+2*step_nr)*32,
2552 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2553 DrawText(SX, SY+(2+2*step_nr+1)*32,
2554 "Key:", FONT_INPUT_ACTIVE);
2555 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
2556 getKeyNameFromKey(*customize_step[step_nr].key),
2561 case EVENT_KEYRELEASE:
2562 key_joystick_mapping = 0;
2566 HandleOtherEvents(&event);
2574 /* don't eat all CPU time */
2578 /* write new key bindings back to player setup */
2579 setup.input[player_nr].key = custom_key;
2582 DrawSetupScreen_Input();
2585 static boolean CalibrateJoystickMain(int player_nr)
2587 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2588 int new_joystick_xright = JOYSTICK_XMIDDLE;
2589 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2590 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2591 int new_joystick_xmiddle, new_joystick_ymiddle;
2593 int joystick_fd = joystick.fd[player_nr];
2594 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2595 boolean check[3][3];
2596 int check_remaining = 3 * 3;
2601 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2604 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2609 for(y=0; y < 3; y++)
2611 for(x=0; x < 3; x++)
2613 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2614 check[x][y] = FALSE;
2618 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2619 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2620 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2621 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2622 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2623 DrawText(SX, SY + 12 * 32, " AND ", FONT_TITLE_1);
2624 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2626 joy_value = Joystick(player_nr);
2627 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2628 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2630 /* eventually uncalibrated center position (joystick could be uncentered) */
2631 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2634 new_joystick_xmiddle = joy_x;
2635 new_joystick_ymiddle = joy_y;
2637 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2640 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2645 if (PendingEvent()) /* got event */
2653 case EVENT_KEYPRESS:
2654 switch(GetEventKey((KeyEvent *)&event, TRUE))
2657 if (check_remaining == 0)
2670 case EVENT_KEYRELEASE:
2671 key_joystick_mapping = 0;
2675 HandleOtherEvents(&event);
2680 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2683 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2684 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2685 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2686 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2688 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2689 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2690 setup.input[player_nr].joy.xright = new_joystick_xright;
2691 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2692 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2693 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2695 CheckJoystickData();
2697 joy_value = Joystick(player_nr);
2699 if (joy_value & JOY_BUTTON && check_remaining == 0)
2702 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2703 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2705 if (x != last_x || y != last_y)
2707 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2708 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2713 if (check_remaining > 0 && !check[x+1][y+1])
2715 check[x+1][y+1] = TRUE;
2721 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2722 setup.input[player_nr].joy.xleft,
2723 setup.input[player_nr].joy.xmiddle,
2724 setup.input[player_nr].joy.xright);
2725 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2726 setup.input[player_nr].joy.yupper,
2727 setup.input[player_nr].joy.ymiddle,
2728 setup.input[player_nr].joy.ylower);
2737 /* don't eat all CPU time */
2741 /* calibrated center position (joystick should now be centered) */
2742 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2745 new_joystick_xmiddle = joy_x;
2746 new_joystick_ymiddle = joy_y;
2750 DrawSetupScreen_Input();
2752 /* wait until the last pressed button was released */
2753 while (Joystick(player_nr) & JOY_BUTTON)
2755 if (PendingEvent()) /* got event */
2760 HandleOtherEvents(&event);
2769 void CalibrateJoystick(int player_nr)
2771 if (!CalibrateJoystickMain(player_nr))
2775 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2776 DrawText(SX, SY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2778 Delay(2000); /* show error message for two seconds */
2782 void DrawSetupScreen()
2784 DeactivateJoystick();
2786 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2788 if (setup_mode == SETUP_MODE_INPUT)
2789 DrawSetupScreen_Input();
2790 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2791 DrawChooseTree(&artwork.gfx_current);
2792 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2793 DrawChooseTree(&artwork.snd_current);
2794 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2795 DrawChooseTree(&artwork.mus_current);
2797 DrawSetupScreen_Generic();
2800 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2802 if (setup_mode == SETUP_MODE_INPUT)
2803 HandleSetupScreen_Input(mx, my, dx, dy, button);
2804 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2805 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2806 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2807 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2808 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2809 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2811 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2814 void HandleGameActions()
2816 if (game_status != PLAYING)
2819 if (local_player->LevelSolved)
2822 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2830 /* ---------- new screen button stuff -------------------------------------- */
2832 /* graphic position and size values for buttons and scrollbars */
2833 #define SC_SCROLLBUTTON_XSIZE 32
2834 #define SC_SCROLLBUTTON_YSIZE 32
2836 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2837 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2838 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2839 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2840 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2841 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2842 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2843 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2845 #define SC_BORDER_SIZE 14
2849 int gfx_unpressed, gfx_pressed;
2853 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2856 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2857 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2858 SCREEN_CTRL_ID_SCROLL_UP,
2862 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2863 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2864 SCREEN_CTRL_ID_SCROLL_DOWN,
2871 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2872 Bitmap **gfx_unpressed, **gfx_pressed;
2874 int gfx_unpressed, gfx_pressed;
2881 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2884 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2885 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2887 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2889 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2890 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2891 GD_TYPE_SCROLLBAR_VERTICAL,
2892 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2893 "scroll level series vertically"
2897 static void CreateScreenScrollbuttons()
2899 struct GadgetInfo *gi;
2900 unsigned long event_mask;
2903 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2905 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2906 int gfx_unpressed, gfx_pressed;
2907 int x, y, width, height;
2908 int gd_x1, gd_x2, gd_y1, gd_y2;
2909 int id = scrollbutton_info[i].gadget_id;
2911 x = scrollbutton_info[i].x;
2912 y = scrollbutton_info[i].y;
2914 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2918 width = SC_SCROLLBUTTON_XSIZE;
2919 height = SC_SCROLLBUTTON_YSIZE;
2921 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2922 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2923 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2924 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2925 gd_x1 = graphic_info[gfx_unpressed].src_x;
2926 gd_y1 = graphic_info[gfx_unpressed].src_y;
2927 gd_x2 = graphic_info[gfx_pressed].src_x;
2928 gd_y2 = graphic_info[gfx_pressed].src_y;
2930 gi = CreateGadget(GDI_CUSTOM_ID, id,
2931 GDI_CUSTOM_TYPE_ID, i,
2932 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2937 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2938 GDI_STATE, GD_BUTTON_UNPRESSED,
2939 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2940 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2941 GDI_EVENT_MASK, event_mask,
2942 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2946 Error(ERR_EXIT, "cannot create gadget");
2948 screen_gadget[id] = gi;
2952 static void CreateScreenScrollbars()
2956 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2958 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2959 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2960 int gfx_unpressed, gfx_pressed;
2962 int gd_x1, gd_x2, gd_y1, gd_y2;
2963 struct GadgetInfo *gi;
2964 int items_max, items_visible, item_position;
2965 unsigned long event_mask;
2966 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2967 int id = scrollbar_info[i].gadget_id;
2969 items_max = num_page_entries;
2970 items_visible = num_page_entries;
2973 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2975 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2976 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
2977 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
2983 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2984 gfx_pressed = scrollbar_info[i].gfx_pressed;
2985 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2986 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2987 gd_x1 = graphic_info[gfx_unpressed].src_x;
2988 gd_y1 = graphic_info[gfx_unpressed].src_y;
2989 gd_x2 = graphic_info[gfx_pressed].src_x;
2990 gd_y2 = graphic_info[gfx_pressed].src_y;
2993 gi = CreateGadget(GDI_CUSTOM_ID, id,
2994 GDI_CUSTOM_TYPE_ID, i,
2995 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2996 GDI_X, scrollbar_info[i].x,
2997 GDI_Y, scrollbar_info[i].y,
2998 GDI_WIDTH, scrollbar_info[i].width,
2999 GDI_HEIGHT, scrollbar_info[i].height,
3000 GDI_TYPE, scrollbar_info[i].type,
3001 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3002 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3003 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3004 GDI_STATE, GD_BUTTON_UNPRESSED,
3005 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3006 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3007 GDI_BORDER_SIZE, SC_BORDER_SIZE,
3008 GDI_EVENT_MASK, event_mask,
3009 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3013 Error(ERR_EXIT, "cannot create gadget");
3015 screen_gadget[id] = gi;
3019 void CreateScreenGadgets()
3021 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3024 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3026 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3028 /* copy pointers to clip mask and GC */
3029 scrollbar_bitmap[i]->clip_mask =
3030 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3031 scrollbar_bitmap[i]->stored_clip_gc =
3032 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3034 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3035 scrollbar_bitmap[i],
3036 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3037 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3038 TILEX, TILEY, 0, 0);
3042 CreateScreenScrollbuttons();
3043 CreateScreenScrollbars();
3046 void FreeScreenGadgets()
3050 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3051 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3053 /* prevent freeing clip mask and GC twice */
3054 scrollbar_bitmap[i]->clip_mask = None;
3055 scrollbar_bitmap[i]->stored_clip_gc = None;
3057 FreeBitmap(scrollbar_bitmap[i]);
3061 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3062 FreeGadget(screen_gadget[i]);
3065 void MapChooseTreeGadgets(TreeInfo *ti)
3067 int num_entries = numTreeInfoInGroup(ti);
3070 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
3073 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3074 MapGadget(screen_gadget[i]);
3077 void UnmapChooseTreeGadgets()
3081 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3082 UnmapGadget(screen_gadget[i]);
3085 static void HandleScreenGadgets(struct GadgetInfo *gi)
3087 int id = gi->custom_id;
3089 if (game_status != CHOOSELEVEL && game_status != SETUP)
3094 case SCREEN_CTRL_ID_SCROLL_UP:
3095 if (game_status == CHOOSELEVEL)
3096 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3097 else if (game_status == SETUP)
3098 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3101 case SCREEN_CTRL_ID_SCROLL_DOWN:
3102 if (game_status == CHOOSELEVEL)
3103 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3104 else if (game_status == SETUP)
3105 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3108 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3109 if (game_status == CHOOSELEVEL)
3110 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3111 else if (game_status == SETUP)
3112 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);