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;
78 #define mSX (SX + (game_status == MAINMENU ? global.menu_draw_xoffset_MAIN : \
79 global.menu_draw_xoffset))
80 #define mSY (SY + (game_status == MAINMENU ? global.menu_draw_yoffset_MAIN : \
81 global.menu_draw_yoffset))
84 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
85 #define NUM_SCROLLBAR_BITMAPS 2
86 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
90 static void drawCursorExt(int xpos, int ypos, int color, int graphic)
92 static int cursor_array[SCR_FIELDY];
97 cursor_array[ypos] = graphic;
99 graphic = cursor_array[ypos];
103 graphic = (graphic == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
104 graphic == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE:
105 IMG_MENU_BUTTON_ACTIVE);
107 ypos += MENU_SCREEN_START_YPOS;
109 DrawBackground(SX + xpos * 32, SY + ypos * 32, TILEX, TILEY);
110 DrawGraphicThruMask(xpos, ypos, graphic, 0);
113 static void initCursor(int ypos, int graphic)
115 drawCursorExt(0, ypos, FC_BLUE, graphic);
118 static void drawCursor(int ypos, int color)
120 drawCursorExt(0, ypos, color, 0);
123 static void drawCursorXY(int xpos, int ypos, int graphic)
125 drawCursorExt(xpos, ypos, -1, graphic);
128 static void PlaySound_Menu_Start(int sound)
130 if (sound_info[sound].loop)
131 PlaySoundLoop(sound);
136 static void PlaySound_Menu_Continue(int sound)
138 if (sound_info[sound].loop)
139 PlaySoundLoop(sound);
144 int font1_xsize = getFontWidth(FONT_TITLE_1);
145 int font2_xsize = getFontWidth(FONT_TITLE_2);
146 int x1 = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * font1_xsize) / 2;
147 int x2 = SX + (SXSIZE - strlen(WINDOW_SUBTITLE_STRING) * font2_xsize) / 2;
149 DrawText(x1, SY + 8, PROGRAM_TITLE_STRING, FONT_TITLE_1);
150 DrawText(x2, SY + 46, WINDOW_SUBTITLE_STRING, FONT_TITLE_2);
153 static void ToggleFullscreenIfNeeded()
155 if (setup.fullscreen != video.fullscreen_enabled)
157 /* save old door content */
158 BlitBitmap(backbuffer, bitmap_db_door,
159 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
161 /* toggle fullscreen */
162 ChangeVideoModeIfNeeded(setup.fullscreen);
163 setup.fullscreen = video.fullscreen_enabled;
165 /* redraw background to newly created backbuffer */
166 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
167 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
169 /* restore old door content */
170 BlitBitmap(bitmap_db_door, backbuffer,
171 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
173 redraw_mask = REDRAW_ALL;
179 static LevelDirTree *leveldir_last_valid = NULL;
180 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
181 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
185 mSX = SX + global.menu_draw_xoffset;
186 mSY = SY + global.menu_draw_yoffset;
192 KeyboardAutoRepeatOn();
195 SetDrawDeactivationMask(REDRAW_NONE);
196 SetDrawBackgroundMask(REDRAW_FIELD);
198 audio.sound_deactivated = FALSE;
200 /* needed if last screen was the playing screen, invoked from level editor */
201 if (level_editor_test_game)
203 game_status = LEVELED;
208 /* needed if last screen was the editor screen */
209 UndrawSpecialEditorDoor();
211 /* needed if last screen was the setup screen and fullscreen state changed */
212 ToggleFullscreenIfNeeded();
214 /* needed if last screen (level choice) changed graphics, sounds or music */
215 ReloadCustomArtwork();
218 SetDrawtoField(DRAW_BACKBUFFER);
221 /* map gadgets for main menu screen */
224 /* leveldir_current may be invalid (level group, parent link) */
225 if (!validLevelSeries(leveldir_current))
226 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
228 /* store valid level series information */
229 leveldir_last_valid = leveldir_current;
231 /* level_nr may have been set to value over handicap with level editor */
232 if (setup.handicap && level_nr > leveldir_current->handicap_level)
233 level_nr = leveldir_current->handicap_level;
238 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
243 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
244 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT);
245 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
246 DrawText(mSX + 11 * 32, mSY + 3*32, int2str(level_nr,3), FONT_VALUE_1);
247 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
248 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
249 DrawText(mSY + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
250 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
251 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
252 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
254 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
256 DrawTextF(7*32 + 6, 3*32 + 9, FONT_TEXT_3, "%d-%d",
257 leveldir_current->first_level,
258 leveldir_current->last_level);
260 if (leveldir_current->readonly)
262 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FONT_TEXT_3, "READ");
263 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FONT_TEXT_3, "ONLY");
267 initCursor(i, (i == 1 || i == 6 ? IMG_MENU_BUTTON_RIGHT :IMG_MENU_BUTTON));
270 DrawGraphic(10, 3, IMG_MENU_BUTTON_LEFT, 0);
271 DrawGraphic(14, 3, IMG_MENU_BUTTON_RIGHT, 0);
273 drawCursorXY(10, 1, IMG_MENU_BUTTON_LEFT);
274 drawCursorXY(14, 1, IMG_MENU_BUTTON_RIGHT);
277 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment", FONT_TITLE_2);
281 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
284 if (TAPE_IS_EMPTY(tape))
286 DrawCompleteVideoDisplay();
288 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
295 static void gotoTopLevelDir()
297 /* move upwards to top level directory */
298 while (leveldir_current->node_parent)
300 /* write a "path" into level tree for easy navigation to last level */
301 if (leveldir_current->node_parent->node_group->cl_first == -1)
303 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
304 int leveldir_pos = posTreeInfo(leveldir_current);
305 int num_page_entries;
306 int cl_first, cl_cursor;
308 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
309 num_page_entries = num_leveldirs;
311 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
313 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
314 cl_cursor = leveldir_pos - cl_first;
316 leveldir_current->node_parent->node_group->cl_first = cl_first;
317 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
320 leveldir_current = leveldir_current->node_parent;
324 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
326 static int choice = 0;
330 if (button == MB_MENU_INITIALIZE)
332 drawCursor(choice, FC_RED);
336 if (mx || my) /* mouse input */
339 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
341 else if (dx || dy) /* keyboard input */
343 if (dx && choice == 1)
344 x = (dx < 0 ? 10 : 14);
349 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
350 (x == 14 && level_nr < leveldir_current->last_level)) &&
353 static unsigned long level_delay = 0;
354 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
355 int new_level_nr, old_level_nr = level_nr;
357 new_level_nr = level_nr + (x == 10 ? -step : +step);
358 if (new_level_nr < leveldir_current->first_level)
359 new_level_nr = leveldir_current->first_level;
360 if (new_level_nr > leveldir_current->last_level)
361 new_level_nr = leveldir_current->last_level;
363 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
364 new_level_nr = leveldir_current->handicap_level;
366 if (old_level_nr == new_level_nr ||
367 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
370 level_nr = new_level_nr;
372 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
375 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
379 DrawCompleteVideoDisplay();
381 /* needed because DrawMicroLevel() takes some time */
384 DelayReached(&level_delay, 0); /* reset delay counter */
386 else if (x == 0 && y >= 0 && y <= 7)
392 drawCursor(y, FC_RED);
393 drawCursor(choice, FC_BLUE);
401 game_status = TYPENAME;
402 HandleTypeName(strlen(setup.player_name), 0);
408 game_status = CHOOSELEVEL;
409 SaveLevelSetup_LastSeries();
410 SaveLevelSetup_SeriesInfo();
419 game_status = HALLOFFAME;
424 if (leveldir_current->readonly &&
425 strcmp(setup.player_name, "Artsoft") != 0)
426 Request("This level is read only !", REQ_CONFIRM);
427 game_status = LEVELED;
432 game_status = HELPSCREEN;
437 if (setup.autorecord)
438 TapeStartRecording();
440 #if defined(PLATFORM_UNIX)
442 SendToServer_StartPlaying();
446 game_status = PLAYING;
454 setup_mode = SETUP_MODE_MAIN;
459 SaveLevelSetup_LastSeries();
460 SaveLevelSetup_SeriesInfo();
461 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
462 game_status = EXITGAME;
471 if (game_status == MAINMENU)
473 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
479 #define MAX_HELPSCREEN_ELS 10
483 static long helpscreen_state;
484 static int helpscreen_step[MAX_HELPSCREEN_ELS];
485 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
487 static int OLD_helpscreen_action[] =
489 GFX_SPIELER1_DOWN,4,2,
491 GFX_SPIELER1_LEFT,4,2,
492 GFX_SPIELER1_RIGHT,4,2,
493 GFX_SPIELER1_PUSH_LEFT,4,2,
494 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
495 GFX_ERDREICH,1,100, HA_NEXT,
496 GFX_LEERRAUM,1,100, HA_NEXT,
497 GFX_MORAST_LEER,1,100, HA_NEXT,
498 GFX_BETON,1,100, HA_NEXT,
499 GFX_MAUERWERK,1,100, HA_NEXT,
500 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
501 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
502 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
503 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
504 GFX_UNSICHTBAR,1,100, HA_NEXT,
505 GFX_FELSBODEN,1,100, HA_NEXT,
506 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
507 GFX_EDELSTEIN,2,5, HA_NEXT,
508 GFX_DIAMANT,2,5, HA_NEXT,
509 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
510 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
511 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
512 GFX_FELSBROCKEN,4,5, HA_NEXT,
513 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
514 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
515 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
516 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
517 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
518 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
519 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
520 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
521 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
522 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
523 GFX_GEBLUBBER,4,4, HA_NEXT,
524 GFX_SCHLUESSEL1,4,25, HA_NEXT,
525 GFX_PFORTE1,4,25, HA_NEXT,
526 GFX_PFORTE1X,4,25, HA_NEXT,
527 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
528 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
529 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
530 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
531 GFX_LEERRAUM,1,10, HA_NEXT,
532 GFX_DYNABOMB_NR,1,100, HA_NEXT,
533 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
534 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
535 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
536 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
537 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
538 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
539 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
540 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
541 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
542 GFX_BUTTERFLY,2,2, HA_NEXT,
543 GFX_FIREFLY,2,2, HA_NEXT,
544 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
545 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
546 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
547 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
548 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
549 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
550 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
551 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
552 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
553 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
557 GFX_MOLE_RIGHT,4,2, HA_NEXT,
558 GFX_PINGUIN_DOWN,4,2,
560 GFX_PINGUIN_LEFT,4,2,
561 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
562 GFX_SCHWEIN_DOWN,4,2,
564 GFX_SCHWEIN_LEFT,4,2,
565 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
569 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
570 GFX_SONDE_START,8,1, HA_NEXT,
571 GFX_ABLENK,4,1, HA_NEXT,
572 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
573 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
574 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
575 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
576 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
577 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
578 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
579 GFX_DIAMANT,1,10, HA_NEXT,
580 GFX_LIFE,1,100, HA_NEXT,
581 GFX_LIFE_ASYNC,1,100, HA_NEXT,
582 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
583 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
584 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
585 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
586 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
587 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
588 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
589 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
590 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
591 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
592 GFX_SPEED_PILL,1,100, HA_NEXT,
597 static int helpscreen_action[] =
599 IMG_PLAYER_1_MOVING_DOWN, 16,
600 IMG_PLAYER_1_MOVING_UP, 16,
601 IMG_PLAYER_1_MOVING_LEFT, 16,
602 IMG_PLAYER_1_MOVING_RIGHT, 16,
603 IMG_PLAYER_1_PUSHING_LEFT, 16,
604 IMG_PLAYER_1_PUSHING_RIGHT, 16, HA_NEXT,
606 IMG_SAND, -1, HA_NEXT,
608 IMG_EMPTY_SPACE, -1, HA_NEXT,
610 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
612 IMG_STEELWALL, -1, HA_NEXT,
614 IMG_WALL, -1, HA_NEXT,
616 IMG_EXPANDABLE_WALL_GROWING_LEFT, 20,
619 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 20,
622 IMG_EXPANDABLE_WALL_GROWING_UP, 20,
625 IMG_EXPANDABLE_WALL_GROWING_DOWN, 20,
627 IMG_EMPTY_SPACE, 20, HA_NEXT,
629 IMG_INVISIBLE_WALL, -1, HA_NEXT,
631 IMG_WALL_CRUMBLED, -1, HA_NEXT,
633 IMG_INFO_FONT_EM_1, 160,
634 IMG_INFO_FONT_EM_2, 160,
635 IMG_INFO_FONT_EM_3, 160,
636 IMG_INFO_FONT_EM_4, 160,
637 IMG_INFO_FONT_EM_5, 40, HA_NEXT,
639 IMG_EMERALD, -1, HA_NEXT,
641 IMG_DIAMOND, -1, HA_NEXT,
643 IMG_BD_DIAMOND, -1, HA_NEXT,
645 IMG_EMERALD_YELLOW, 50,
647 IMG_EMERALD_PURPLE, 50, HA_NEXT,
649 IMG_BD_ROCK, -1, HA_NEXT,
653 IMG_EMPTY_SPACE, 10, HA_NEXT,
657 IMG_EMERALD, 20, HA_NEXT,
659 IMG_WALL_EMERALD, 100,
661 IMG_EMERALD, 20, HA_NEXT,
663 IMG_WALL_DIAMOND, 100,
665 IMG_DIAMOND, 20, HA_NEXT,
667 IMG_WALL_BD_DIAMOND, 100,
669 IMG_BD_DIAMOND, 20, HA_NEXT,
671 IMG_WALL_EMERALD_YELLOW, 100,
673 IMG_EMERALD_YELLOW, 20,
674 IMG_WALL_EMERALD_RED, 100,
677 IMG_WALL_EMERALD_PURPLE, 100,
679 IMG_EMERALD_PURPLE, 20, HA_NEXT,
681 IMG_ACID, -1, HA_NEXT,
686 IMG_KEY_4, 50, HA_NEXT,
691 IMG_GATE_4, 50, HA_NEXT,
696 IMG_GATE_4_GRAY, 50, HA_NEXT,
698 IMG_DYNAMITE, -1, HA_NEXT,
700 IMG_DYNAMITE_ACTIVE, 96,
702 IMG_EMPTY_SPACE, 20, HA_NEXT,
704 IMG_DYNABOMB_ACTIVE, 100,
706 IMG_EMPTY_SPACE, 20, HA_NEXT,
708 EL_DYNABOMB_INCREASE_NUMBER, -1, HA_NEXT,
710 EL_DYNABOMB_INCREASE_SIZE, -1, HA_NEXT,
712 IMG_SPACESHIP_RIGHT, 16,
713 IMG_SPACESHIP_UP, 16,
714 IMG_SPACESHIP_LEFT, 16,
715 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
720 IMG_BUG_DOWN, 16, HA_NEXT,
722 IMG_BD_BUTTERFLY, -1, HA_NEXT,
724 IMG_BD_FIREFLY, -1, HA_NEXT,
726 IMG_PACMAN_RIGHT, 16,
729 IMG_PACMAN_DOWN, 16, HA_NEXT,
731 IMG_YAMYAM, -1, HA_NEXT,
733 IMG_DARK_YAMYAM, -1, HA_NEXT,
735 IMG_ROBOT, -1, HA_NEXT,
737 IMG_MOLE_MOVING_RIGHT, 16,
738 IMG_MOLE_MOVING_UP, 16,
739 IMG_MOLE_MOVING_LEFT, 16,
740 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
742 IMG_PENGUIN_MOVING_RIGHT, 16,
743 IMG_PENGUIN_MOVING_UP, 16,
744 IMG_PENGUIN_MOVING_LEFT, 16,
745 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
747 IMG_PIG_MOVING_RIGHT, 16,
748 IMG_PIG_MOVING_UP, 16,
749 IMG_PIG_MOVING_LEFT, 16,
750 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
752 IMG_DRAGON_MOVING_RIGHT, 16,
753 IMG_DRAGON_MOVING_UP, 16,
754 IMG_DRAGON_MOVING_LEFT, 16,
755 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
757 IMG_SATELLITE, -1, HA_NEXT,
760 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
763 IMG_LAMP_ACTIVE, 50, HA_NEXT,
765 IMG_TIME_ORB_FULL, 50,
766 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
769 IMG_AMOEBA_GROWING, 6,
770 IMG_AMOEBA_WET, 20, HA_NEXT,
772 IMG_AMOEBA_DEAD, -1, HA_NEXT,
774 IMG_AMOEBA_WET, -1, HA_NEXT,
777 IMG_AMOEBA_GROWING, 6, HA_NEXT,
782 IMG_DIAMOND, 20, HA_NEXT,
784 IMG_GAME_OF_LIFE, -1, HA_NEXT,
786 IMG_BIOMAZE, -1, HA_NEXT,
788 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
790 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
792 IMG_EXIT_CLOSED, 200,
793 IMG_EXIT_OPENING, 16,
794 IMG_EXIT_OPEN, 100, HA_NEXT,
796 IMG_EXIT_OPEN, -1, HA_NEXT,
798 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
800 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
802 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
804 IMG_SPEED_PILL, -1, HA_NEXT,
808 static char *helpscreen_eltext[][2] =
810 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
811 {"Normal sand:", "You can dig through it"},
812 {"Empty field:", "You can walk through it"},
813 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
814 {"Massive Wall:", "Nothing can go through it"},
815 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
816 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
817 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
818 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
819 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
820 {"Emerald: You must collect enough of","them to finish a level"},
821 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
822 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
823 {"Colorful Gems:", "Seem to behave like Emeralds"},
824 {"Rock: Smashes several things;", "Can be moved by the player"},
825 {"Bomb: You can move it, but be", "careful when dropping it"},
826 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
827 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
828 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
829 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
830 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
831 {"Acid: Things that fall in are gone", "forever (including our hero)"},
832 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
833 {"Door: Can be opened by the key", "with the same color"},
834 {"Door: You have to find out the", "right color of the key for it"},
835 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
836 {"Dynamite: This one explodes after", "a few seconds"},
837 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
838 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
839 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
840 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
841 {"Bug: Moves at the right side", "of walls; don't touch it!"},
842 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
843 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
844 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
845 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
846 {"Cruncher (BD style):", "Eats almost everything"},
847 {"Robot: Tries to kill the player", ""},
848 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
849 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
850 {"The Pig: Harmless, but eats all", "gems it can get"},
851 {"The Dragon: Breathes fire,", "especially to some monsters"},
852 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
853 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
854 {"Light Bulb: All of them must be", "switched on to finish a level"},
855 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
856 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
857 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
858 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
859 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
860 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
861 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
862 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
863 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
864 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
865 {"Exit door: Opens if you have enough","emeralds to finish the level"},
866 {"Open exit door: Enter here to leave","the level and exit the actual game"},
867 {"Sokoban element: Object which must", "be pushed to an empty field"},
868 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
869 {"Sokoban element: Field with object", "which can be pushed away"},
870 {"Speed pill: Lets the player run", "twice as fast as normally"},
872 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
874 static char *helpscreen_music[][3] =
876 { "Alchemy", "Ian Boddy", "Drive" },
877 { "The Chase", "Propaganda", "A Secret Wish" },
878 { "Network 23", "Tangerine Dream", "Exit" },
879 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
880 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
881 { "Voyager", "The Alan Parsons Project","Pyramid" },
882 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
884 static int num_helpscreen_music = 7;
885 static int helpscreen_musicpos;
888 void OLD_DrawHelpScreenElAction(int start)
892 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
894 while(helpscreen_action[j] != HA_END)
896 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
898 else if (i<start || helpscreen_delay[i-start])
900 if (i>=start && helpscreen_delay[i-start])
901 helpscreen_delay[i-start]--;
903 while(helpscreen_action[j] != HA_NEXT)
910 j += 3*helpscreen_step[i-start];
911 graphic = helpscreen_action[j++];
913 if (helpscreen_frame[i-start])
915 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
916 helpscreen_frame[i-start]--;
921 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
924 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
926 if (helpscreen_action[j] == HA_NEXT)
928 if (!helpscreen_frame[i-start])
929 helpscreen_step[i-start] = 0;
933 if (!helpscreen_frame[i-start])
934 helpscreen_step[i-start]++;
935 while(helpscreen_action[j] != HA_NEXT)
940 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
952 void DrawHelpScreenElAction(int start)
955 int xstart = mSX + 16;
956 int ystart = mSY + 64 + 2 * 32;
957 int ystep = TILEY + 4;
963 while (helpscreen_action[j] != HA_END)
965 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
969 while (helpscreen_action[j] != HA_NEXT)
978 j += 2 * helpscreen_step[i-start];
979 graphic = helpscreen_action[j++];
980 frame_count = helpscreen_action[j++];
981 if (frame_count == -1)
982 frame_count = 1000000;
984 if (helpscreen_frame[i-start] == 0)
987 helpscreen_frame[i-start] = frame_count - 1;
991 sync_frame = frame_count - helpscreen_frame[i-start];
992 helpscreen_frame[i-start]--;
995 if (helpscreen_action[j] == HA_NEXT)
997 if (!helpscreen_frame[i-start])
998 helpscreen_step[i-start] = 0;
1002 if (!helpscreen_frame[i-start])
1003 helpscreen_step[i-start]++;
1004 while(helpscreen_action[j] != HA_NEXT)
1009 frame = getGraphicAnimationFrame(graphic, sync_frame);
1011 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
1019 MarkTileDirty(0, i);
1020 MarkTileDirty(1, i);
1026 void DrawHelpScreenElText(int start)
1029 int xstart = mSX + 56, ystart = mSY + 65 + 2 * 32, ystep = TILEY + 4;
1030 int ybottom = SYSIZE - 20;
1032 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1036 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
1038 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1041 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1042 helpscreen_eltext[i][0], FONT_TEXT_2);
1043 DrawText(xstart, ystart + (i - start) * ystep + 16,
1044 helpscreen_eltext[i][1], FONT_TEXT_2);
1047 DrawTextFCentered(ybottom, FONT_TEXT_4,
1048 "Press any key or button for next page");
1051 void DrawHelpScreenMusicText(int num)
1053 int ystart = 150, ystep = 30;
1054 int ybottom = SYSIZE - 20;
1060 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
1062 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
1063 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
1064 "\"%s\"", helpscreen_music[num][0]);
1065 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
1066 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
1067 "%s", helpscreen_music[num][1]);
1068 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1069 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
1070 "\"%s\"", helpscreen_music[num][2]);
1072 DrawTextFCentered(ybottom, FONT_TEXT_4,
1073 "Press any key or button for next page");
1076 PlaySoundLoop(background_loop[num]);
1080 void DrawHelpScreenCreditsText()
1082 int ystart = 150, ystep = 30;
1083 int ybottom = SYSIZE - 20;
1089 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
1090 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1091 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1092 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1093 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1094 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
1095 "...and many thanks to all contributors");
1096 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1098 DrawTextFCentered(ybottom, FONT_TEXT_4,
1099 "Press any key or button for next page");
1102 void DrawHelpScreenContactText()
1104 int ystart = 150, ystep = 30;
1105 int ybottom = SYSIZE - 20;
1110 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1112 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1113 "This game is Freeware!");
1114 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1115 "If you like it, send e-mail to:");
1116 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1117 "info@artsoft.org");
1118 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1119 "or SnailMail to:");
1120 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1122 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1123 "Detmolder Strasse 189");
1124 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1126 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1129 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1130 "If you have created new levels,");
1131 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1132 "send them to me to include them!");
1133 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1136 DrawTextFCentered(ybottom, FONT_TEXT_4,
1137 "Press any key or button for main menu");
1140 void DrawHelpScreen()
1145 CloseDoor(DOOR_CLOSE_2);
1147 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1148 helpscreen_step[i] = helpscreen_frame[i] = 0;
1149 helpscreen_musicpos = 0;
1150 helpscreen_state = 0;
1152 DrawHelpScreenElText(0);
1153 DrawHelpScreenElAction(0);
1159 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1161 PlaySound_Menu_Start(SND_MENU_INFO_SCREEN);
1165 void HandleHelpScreen(int button)
1167 static unsigned long hs_delay = 0;
1168 int num_helpscreen_els_pages =
1169 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1170 int button_released = !button;
1173 if (button_released)
1175 if (helpscreen_state < num_helpscreen_els_pages - 1)
1177 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1178 helpscreen_step[i] = helpscreen_frame[i] = 0;
1182 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1183 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1185 else if (helpscreen_state <
1186 num_helpscreen_els_pages + num_helpscreen_music - 1)
1189 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1191 else if (helpscreen_state ==
1192 num_helpscreen_els_pages + num_helpscreen_music - 1)
1195 DrawHelpScreenCreditsText();
1197 else if (helpscreen_state ==
1198 num_helpscreen_els_pages + num_helpscreen_music)
1201 DrawHelpScreenContactText();
1207 game_status = MAINMENU;
1213 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1215 if (helpscreen_state < num_helpscreen_els_pages)
1216 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1219 /* !!! workaround for playing "music" that is really a sound loop (and
1220 must therefore periodically be reactivated with the current sound
1223 PlaySoundLoop(SND_MENU_INFO_SCREEN);
1225 PlaySound_Menu_Continue(SND_MENU_INFO_SCREEN);
1234 void HandleTypeName(int newxpos, Key key)
1236 static int xpos = 0, ypos = 2;
1237 int font_width = getFontWidth(FONT_INPUT_ACTIVE);
1238 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1239 int startx = mSX + 32 + name_width;
1240 int starty = mSY + ypos * 32;
1246 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1247 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1252 if (((key >= KSYM_A && key <= KSYM_Z) ||
1253 (key >= KSYM_a && key <= KSYM_z)) &&
1254 xpos < MAX_PLAYER_NAME_LEN)
1258 if (key >= KSYM_A && key <= KSYM_Z)
1259 ascii = 'A' + (char)(key - KSYM_A);
1261 ascii = 'a' + (char)(key - KSYM_a);
1263 setup.player_name[xpos] = ascii;
1264 setup.player_name[xpos + 1] = 0;
1267 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1268 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1270 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1273 setup.player_name[xpos] = 0;
1275 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_ACTIVE);
1277 else if (key == KSYM_Return && xpos > 0)
1279 DrawText(startx, starty, setup.player_name, FONT_INPUT);
1280 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_ACTIVE);
1283 game_status = MAINMENU;
1289 static void DrawChooseTree(TreeInfo **ti_ptr)
1292 CloseDoor(DOOR_CLOSE_2);
1296 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1297 MapChooseTreeGadgets(*ti_ptr);
1303 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1305 struct GadgetInfo *gi = screen_gadget[id];
1306 int items_max, items_visible, item_position;
1308 items_max = numTreeInfoInGroup(ti);
1309 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1310 item_position = first_entry;
1312 if (item_position > items_max - items_visible)
1313 item_position = items_max - items_visible;
1315 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1316 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1319 static void drawChooseTreeList(int first_entry, int num_page_entries,
1323 char buffer[SCR_FIELDX * 2];
1324 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1325 int num_entries = numTreeInfoInGroup(ti);
1326 char *title_string = NULL;
1327 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1328 int last_game_status = game_status; /* save current game status */
1330 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1331 redraw_mask |= REDRAW_FIELD;
1334 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1335 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1336 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1337 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1339 DrawText(SX + offset, SY + offset, title_string, FONT_TITLE_1);
1341 game_status = CHOOSELEVEL; /* force LEVELS font on artwork setup screen */
1343 for(i=0; i<num_page_entries; i++)
1345 TreeInfo *node, *node_first;
1346 int entry_pos = first_entry + i;
1347 int ypos = MENU_SCREEN_START_YPOS + i;
1349 node_first = getTreeInfoFirstGroupEntry(ti);
1350 node = getTreeInfoFromPos(node_first, entry_pos);
1352 strncpy(buffer, node->name , max_buffer_len);
1353 buffer[max_buffer_len] = '\0';
1355 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1357 if (node->parent_link)
1358 initCursor(i, IMG_MENU_BUTTON_LEFT);
1359 else if (node->level_group)
1360 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1362 initCursor(i, IMG_MENU_BUTTON);
1365 if (first_entry > 0)
1369 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1370 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_UP, 0);
1373 if (first_entry + num_page_entries < num_entries)
1375 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1377 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1378 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_DOWN, 0);
1381 game_status = last_game_status; /* restore current game status */
1384 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1386 TreeInfo *node, *node_first;
1387 int x, last_redraw_mask = redraw_mask;
1389 if (ti->type != TREE_TYPE_LEVEL_DIR)
1392 node_first = getTreeInfoFirstGroupEntry(ti);
1393 node = getTreeInfoFromPos(node_first, entry_pos);
1395 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1397 if (node->parent_link)
1398 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1400 else if (node->level_group)
1401 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1403 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1404 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1405 node->levels, node->class_desc);
1407 /* let BackToFront() redraw only what is needed */
1408 redraw_mask = last_redraw_mask | REDRAW_TILES;
1409 for (x=0; x<SCR_FIELDX; x++)
1410 MarkTileDirty(x, 1);
1413 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1416 static unsigned long choose_delay = 0;
1417 TreeInfo *ti = *ti_ptr;
1419 int y = ti->cl_cursor;
1420 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1421 int num_entries = numTreeInfoInGroup(ti);
1422 int num_page_entries;
1424 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1425 num_page_entries = num_entries;
1427 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1429 if (button == MB_MENU_INITIALIZE)
1431 int entry_pos = posTreeInfo(ti);
1433 if (ti->cl_first == -1)
1435 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1437 entry_pos - ti->cl_first;
1440 if (dx == 999) /* first entry is set by scrollbar position */
1443 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1446 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1447 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1448 drawCursor(ti->cl_cursor, FC_RED);
1451 else if (button == MB_MENU_LEAVE)
1453 if (ti->node_parent)
1455 *ti_ptr = ti->node_parent;
1456 DrawChooseTree(ti_ptr);
1458 else if (game_status == SETUP)
1464 game_status = MAINMENU;
1471 if (mx || my) /* mouse input */
1474 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1476 else if (dx || dy) /* keyboard input */
1479 y = ti->cl_cursor + dy;
1481 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1484 step = num_page_entries - 1;
1485 y = (dy < 0 ? -1 : num_page_entries);
1489 if (x == 0 && y == -1)
1491 if (ti->cl_first > 0 &&
1492 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1494 ti->cl_first -= step;
1495 if (ti->cl_first < 0)
1498 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1499 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1500 drawCursor(ti->cl_cursor, FC_RED);
1501 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1506 else if (x == 0 && y > num_page_entries - 1)
1508 if (ti->cl_first + num_page_entries < num_entries &&
1509 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1511 ti->cl_first += step;
1512 if (ti->cl_first + num_page_entries > num_entries)
1513 ti->cl_first = MAX(0, num_entries - num_page_entries);
1515 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1516 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1517 drawCursor(ti->cl_cursor, FC_RED);
1518 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1526 TreeInfo *node_first, *node_cursor;
1527 int entry_pos = ti->cl_first + y;
1529 node_first = getTreeInfoFirstGroupEntry(ti);
1530 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1532 if (node_cursor->node_group)
1534 node_cursor->cl_first = ti->cl_first;
1535 node_cursor->cl_cursor = ti->cl_cursor;
1536 *ti_ptr = node_cursor->node_group;
1537 DrawChooseTree(ti_ptr);
1541 else if (dx == -1 && ti->node_parent)
1543 *ti_ptr = ti->node_parent;
1544 DrawChooseTree(ti_ptr);
1548 if (x == 0 && y >= 0 && y < num_page_entries)
1552 if (y != ti->cl_cursor)
1554 drawCursor(y, FC_RED);
1555 drawCursor(ti->cl_cursor, FC_BLUE);
1556 drawChooseTreeInfo(ti->cl_first + y, ti);
1562 TreeInfo *node_first, *node_cursor;
1563 int entry_pos = ti->cl_first + y;
1565 node_first = getTreeInfoFirstGroupEntry(ti);
1566 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1568 if (node_cursor->node_group)
1570 node_cursor->cl_first = ti->cl_first;
1571 node_cursor->cl_cursor = ti->cl_cursor;
1572 *ti_ptr = node_cursor->node_group;
1573 DrawChooseTree(ti_ptr);
1575 else if (node_cursor->parent_link)
1577 *ti_ptr = node_cursor->node_parent;
1578 DrawChooseTree(ti_ptr);
1582 node_cursor->cl_first = ti->cl_first;
1583 node_cursor->cl_cursor = ti->cl_cursor;
1584 *ti_ptr = node_cursor;
1586 if (ti->type == TREE_TYPE_LEVEL_DIR)
1588 LoadLevelSetup_SeriesInfo();
1590 SaveLevelSetup_LastSeries();
1591 SaveLevelSetup_SeriesInfo();
1595 if (game_status == SETUP)
1601 game_status = MAINMENU;
1610 if (game_status == CHOOSELEVEL || game_status == SETUP)
1614 void DrawChooseLevel()
1616 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1618 DrawChooseTree(&leveldir_current);
1621 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1623 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1626 void DrawHallOfFame(int highlight_position)
1630 CloseDoor(DOOR_CLOSE_2);
1632 if (highlight_position < 0)
1633 LoadScore(level_nr);
1638 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1641 PlaySound(SND_MENU_HALL_OF_FAME);
1643 PlaySound_Menu_Start(SND_MENU_HALL_OF_FAME);
1647 static void drawHallOfFameList(int first_entry, int highlight_position)
1651 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1654 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1655 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1657 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1659 int entry = first_entry + i;
1661 DrawText(mSX, mSY + 64 + i * 32, "..................................",
1662 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1663 DrawText(mSX, mSY + 64 + i * 32, int2str(entry + 1, 3),
1664 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1665 DrawText(mSX + 64, mSY + 64 + i * 32, highscore[entry].Name,
1666 (entry == highlight_position ? FONT_TEXT_3 : FONT_TEXT_1));
1667 DrawText(mSX + 14 * 32 + 16, mSY + 64 + i * 32,
1668 int2str(highscore[entry].Score, 5),
1669 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1673 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1675 static int first_entry = 0;
1676 static int highlight_position = 0;
1677 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1678 int button_released = !button;
1680 if (button == MB_MENU_INITIALIZE)
1683 highlight_position = mx;
1684 drawHallOfFameList(first_entry, highlight_position);
1688 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1689 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1693 if (first_entry > 0)
1695 first_entry -= step;
1696 if (first_entry < 0)
1699 drawHallOfFameList(first_entry, highlight_position);
1705 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1707 first_entry += step;
1708 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1709 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1711 drawHallOfFameList(first_entry, highlight_position);
1716 if (button_released)
1718 FadeSound(SND_MENU_HALL_OF_FAME);
1719 game_status = MAINMENU;
1725 if (game_status == HALLOFFAME)
1729 PlaySound_Menu_Continue(SND_MENU_HALL_OF_FAME);
1735 /* ========================================================================= */
1736 /* setup screen functions */
1737 /* ========================================================================= */
1739 static struct TokenInfo *setup_info;
1740 static int num_setup_info;
1742 static char *graphics_set_name;
1743 static char *sounds_set_name;
1744 static char *music_set_name;
1746 static void execSetupMain()
1748 setup_mode = SETUP_MODE_MAIN;
1752 static void execSetupGame()
1754 setup_mode = SETUP_MODE_GAME;
1758 static void execSetupEditor()
1760 setup_mode = SETUP_MODE_EDITOR;
1764 static void execSetupGraphics()
1766 setup_mode = SETUP_MODE_GRAPHICS;
1770 static void execSetupSound()
1772 setup_mode = SETUP_MODE_SOUND;
1776 static void execSetupArtwork()
1778 /* needed if last screen (setup choice) changed graphics, sounds or music */
1779 ReloadCustomArtwork();
1781 setup.graphics_set = artwork.gfx_current->identifier;
1782 setup.sounds_set = artwork.snd_current->identifier;
1783 setup.music_set = artwork.mus_current->identifier;
1785 /* needed for displaying artwork name instead of artwork identifier */
1786 graphics_set_name = artwork.gfx_current->name;
1787 sounds_set_name = artwork.snd_current->name;
1788 music_set_name = artwork.mus_current->name;
1790 setup_mode = SETUP_MODE_ARTWORK;
1794 static void execSetupChooseGraphics()
1796 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1800 static void execSetupChooseSounds()
1802 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1806 static void execSetupChooseMusic()
1808 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1812 static void execSetupInput()
1814 setup_mode = SETUP_MODE_INPUT;
1818 static void execSetupShortcut()
1820 setup_mode = SETUP_MODE_SHORTCUT;
1824 static void execExitSetup()
1826 game_status = MAINMENU;
1830 static void execSaveAndExitSetup()
1836 static struct TokenInfo setup_info_main[] =
1838 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1839 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1840 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1841 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1842 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1843 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1844 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1845 { TYPE_EMPTY, NULL, "" },
1846 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1847 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1851 static struct TokenInfo setup_info_game[] =
1853 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1854 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1855 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1856 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1857 { TYPE_EMPTY, NULL, "" },
1858 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1862 static struct TokenInfo setup_info_editor[] =
1864 { TYPE_STRING, NULL, "Offer Special Elements:"},
1865 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1866 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1867 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1868 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1869 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1870 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1871 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1872 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1873 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1874 { TYPE_EMPTY, NULL, "" },
1875 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1879 static struct TokenInfo setup_info_graphics[] =
1881 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1882 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1883 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1885 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1886 { TYPE_SWITCH, &setup.fading, "Fading:" },
1888 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1889 { TYPE_SWITCH, &setup.toons, "Toons:" },
1890 { TYPE_EMPTY, NULL, "" },
1891 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1895 static struct TokenInfo setup_info_sound[] =
1897 { TYPE_SWITCH, &setup.sound, "Sound:", },
1898 { TYPE_EMPTY, NULL, "" },
1899 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1900 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1901 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1902 { TYPE_EMPTY, NULL, "" },
1903 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1907 static struct TokenInfo setup_info_artwork[] =
1909 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1910 { TYPE_STRING, &graphics_set_name, "" },
1911 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1912 { TYPE_STRING, &sounds_set_name, "" },
1913 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1914 { TYPE_STRING, &music_set_name, "" },
1915 { TYPE_EMPTY, NULL, "" },
1916 { TYPE_STRING, NULL, "Override Level Artwork:"},
1917 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1918 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1919 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1920 { TYPE_EMPTY, NULL, "" },
1921 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1925 static struct TokenInfo setup_info_shortcut[] =
1927 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1928 { TYPE_KEY, &setup.shortcut.save_game, "" },
1929 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1930 { TYPE_KEY, &setup.shortcut.load_game, "" },
1931 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1932 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1933 { TYPE_EMPTY, NULL, "" },
1934 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1935 { TYPE_EMPTY, NULL, "" },
1936 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1940 static Key getSetupKey()
1942 Key key = KSYM_UNDEFINED;
1943 boolean got_key_event = FALSE;
1945 while (!got_key_event)
1947 if (PendingEvent()) /* got event */
1955 case EVENT_KEYPRESS:
1957 key = GetEventKey((KeyEvent *)&event, TRUE);
1959 /* press 'Escape' or 'Enter' to keep the existing key binding */
1960 if (key == KSYM_Escape || key == KSYM_Return)
1961 key = KSYM_UNDEFINED; /* keep old value */
1963 got_key_event = TRUE;
1967 case EVENT_KEYRELEASE:
1968 key_joystick_mapping = 0;
1972 HandleOtherEvents(&event);
1980 /* don't eat all CPU time */
1987 static void drawSetupValue(int pos)
1989 int xpos = MENU_SCREEN_VALUE_XPOS;
1990 int ypos = MENU_SCREEN_START_YPOS + pos;
1991 int font_nr = FONT_VALUE_1;
1992 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1993 setup_info[pos].value);
1995 if (value_string == NULL)
1998 if (setup_info[pos].type & TYPE_KEY)
2002 if (setup_info[pos].type & TYPE_QUERY)
2004 value_string = "<press key>";
2005 font_nr = FONT_INPUT_ACTIVE;
2008 else if (setup_info[pos].type & TYPE_STRING)
2010 int max_value_len = (SCR_FIELDX - 2) * 2;
2013 font_nr = FONT_VALUE_2;
2015 if (strlen(value_string) > max_value_len)
2016 value_string[max_value_len] = '\0';
2018 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
2019 !*(boolean *)(setup_info[pos].value))
2020 font_nr = FONT_OPTION_OFF;
2022 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2023 (xpos == 3 ? " " : " "), font_nr);
2024 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2027 static void changeSetupValue(int pos)
2029 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2031 *(boolean *)setup_info[pos].value ^= TRUE;
2033 else if (setup_info[pos].type & TYPE_KEY)
2037 setup_info[pos].type |= TYPE_QUERY;
2038 drawSetupValue(pos);
2039 setup_info[pos].type &= ~TYPE_QUERY;
2041 key = getSetupKey();
2042 if (key != KSYM_UNDEFINED)
2043 *(Key *)setup_info[pos].value = key;
2046 drawSetupValue(pos);
2049 static void DrawSetupScreen_Generic()
2051 char *title_string = NULL;
2055 CloseDoor(DOOR_CLOSE_2);
2059 if (setup_mode == SETUP_MODE_MAIN)
2061 setup_info = setup_info_main;
2062 title_string = "Setup";
2064 else if (setup_mode == SETUP_MODE_GAME)
2066 setup_info = setup_info_game;
2067 title_string = "Setup Game";
2069 else if (setup_mode == SETUP_MODE_EDITOR)
2071 setup_info = setup_info_editor;
2072 title_string = "Setup Editor";
2074 else if (setup_mode == SETUP_MODE_GRAPHICS)
2076 setup_info = setup_info_graphics;
2077 title_string = "Setup Graphics";
2079 else if (setup_mode == SETUP_MODE_SOUND)
2081 setup_info = setup_info_sound;
2082 title_string = "Setup Sound";
2084 else if (setup_mode == SETUP_MODE_ARTWORK)
2086 setup_info = setup_info_artwork;
2087 title_string = "Custom Artwork";
2089 else if (setup_mode == SETUP_MODE_SHORTCUT)
2091 setup_info = setup_info_shortcut;
2092 title_string = "Setup Shortcuts";
2095 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2098 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2100 void *value_ptr = setup_info[i].value;
2101 int ypos = MENU_SCREEN_START_YPOS + i;
2102 int font_nr = FONT_MENU_1;
2104 /* set some entries to "unchangeable" according to other variables */
2105 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2106 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2107 (value_ptr == &setup.sound_music && !audio.music_available) ||
2108 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2109 setup_info[i].type |= TYPE_GHOSTED;
2111 if (setup_info[i].type & TYPE_STRING)
2112 font_nr = FONT_MENU_2;
2114 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2116 if (setup_info[i].type & TYPE_ENTER_MENU)
2117 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2118 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2119 initCursor(i, IMG_MENU_BUTTON_LEFT);
2120 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2121 initCursor(i, IMG_MENU_BUTTON);
2123 if (setup_info[i].type & TYPE_VALUE)
2131 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2134 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2136 static int choice_store[MAX_SETUP_MODES];
2137 int choice = choice_store[setup_mode]; /* always starts with 0 */
2141 if (button == MB_MENU_INITIALIZE)
2143 /* advance to first valid menu entry */
2144 while (choice < num_setup_info &&
2145 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2147 choice_store[setup_mode] = choice;
2149 drawCursor(choice, FC_RED);
2152 else if (button == MB_MENU_LEAVE)
2154 for (y=0; y<num_setup_info; y++)
2156 if (setup_info[y].type & TYPE_LEAVE_MENU)
2158 void (*menu_callback_function)(void) = setup_info[y].value;
2160 menu_callback_function();
2161 break; /* absolutely needed because function changes 'setup_info'! */
2168 if (mx || my) /* mouse input */
2171 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2173 else if (dx || dy) /* keyboard input */
2177 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2179 if ((setup_info[choice].type & menu_navigation_type) ||
2180 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2181 button = MB_MENU_CHOICE;
2186 /* jump to next non-empty menu entry (up or down) */
2187 while (y > 0 && y < num_setup_info - 1 &&
2188 (setup_info[y].type & TYPE_SKIP_ENTRY))
2192 if (x == 0 && y >= 0 && y < num_setup_info &&
2193 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2199 drawCursor(y, FC_RED);
2200 drawCursor(choice, FC_BLUE);
2201 choice = choice_store[setup_mode] = y;
2204 else if (!(setup_info[y].type & TYPE_GHOSTED))
2206 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2208 void (*menu_callback_function)(void) = setup_info[choice].value;
2210 menu_callback_function();
2214 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2215 (setup_info[y + 1].type & TYPE_KEY))
2218 if (setup_info[y].type & TYPE_VALUE)
2219 changeSetupValue(y);
2226 if (game_status == SETUP)
2230 void DrawSetupScreen_Input()
2234 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2236 initCursor(0, IMG_MENU_BUTTON);
2237 initCursor(1, IMG_MENU_BUTTON);
2238 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2239 initCursor(13, IMG_MENU_BUTTON_LEFT);
2241 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2242 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2244 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2245 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2246 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2249 DeactivateJoystickForCalibration();
2250 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2251 "Joysticks deactivated on this screen");
2254 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2259 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2261 if (device_name == NULL)
2264 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2267 if (strlen(device_name) > 1)
2269 char c1 = device_name[strlen(device_name) - 1];
2270 char c2 = device_name[strlen(device_name) - 2];
2272 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2273 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2276 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2277 strlen(device_name));
2280 static void drawPlayerSetupInputInfo(int player_nr)
2283 static struct SetupKeyboardInfo custom_key;
2290 { &custom_key.left, "Joystick Left" },
2291 { &custom_key.right, "Joystick Right" },
2292 { &custom_key.up, "Joystick Up" },
2293 { &custom_key.down, "Joystick Down" },
2294 { &custom_key.snap, "Button 1" },
2295 { &custom_key.bomb, "Button 2" }
2297 static char *joystick_name[MAX_PLAYERS] =
2305 custom_key = setup.input[player_nr].key;
2307 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr + 1, 1), FONT_INPUT_ACTIVE);
2308 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2310 if (setup.input[player_nr].use_joystick)
2312 char *device_name = setup.input[player_nr].joy.device_name;
2314 DrawText(mSX+8*32, mSY+3*32,
2315 joystick_name[getJoystickNrFromDeviceName(device_name)],
2317 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2321 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2322 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2325 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2326 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2327 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2328 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2329 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2330 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2331 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2332 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2333 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2334 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2335 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2339 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2341 DrawText(mSX + 3*32, mSY + ypos*32,
2343 DrawText(mSX + 3*32, mSY + ypos*32,
2344 (setup.input[player_nr].use_joystick ?
2346 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2350 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2352 static int choice = 0;
2353 static int player_nr = 0;
2356 int pos_start = SETUPINPUT_SCREEN_POS_START;
2357 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2358 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2359 int pos_end = SETUPINPUT_SCREEN_POS_END;
2361 if (button == MB_MENU_INITIALIZE)
2363 drawPlayerSetupInputInfo(player_nr);
2364 drawCursor(choice, FC_RED);
2367 else if (button == MB_MENU_LEAVE)
2369 setup_mode = SETUP_MODE_MAIN;
2374 if (mx || my) /* mouse input */
2377 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2379 else if (dx || dy) /* keyboard input */
2381 if (dx && choice == 0)
2382 x = (dx < 0 ? 10 : 12);
2383 else if ((dx && choice == 1) ||
2384 (dx == +1 && choice == 2) ||
2385 (dx == -1 && choice == pos_end))
2386 button = MB_MENU_CHOICE;
2390 if (y >= pos_empty1 && y <= pos_empty2)
2391 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2394 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2396 static unsigned long delay = 0;
2398 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2401 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2403 drawPlayerSetupInputInfo(player_nr);
2405 else if (x == 0 && y >= pos_start && y <= pos_end &&
2406 !(y >= pos_empty1 && y <= pos_empty2))
2412 drawCursor(y, FC_RED);
2413 drawCursor(choice, FC_BLUE);
2421 char *device_name = setup.input[player_nr].joy.device_name;
2423 if (!setup.input[player_nr].use_joystick)
2425 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2427 setJoystickDeviceToNr(device_name, new_device_nr);
2428 setup.input[player_nr].use_joystick = TRUE;
2432 int device_nr = getJoystickNrFromDeviceName(device_name);
2433 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2435 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2436 setup.input[player_nr].use_joystick = FALSE;
2438 setJoystickDeviceToNr(device_name, new_device_nr);
2441 drawPlayerSetupInputInfo(player_nr);
2445 if (setup.input[player_nr].use_joystick)
2448 CalibrateJoystick(player_nr);
2451 CustomizeKeyboard(player_nr);
2453 else if (y == pos_end)
2457 setup_mode = SETUP_MODE_MAIN;
2467 if (game_status == SETUP)
2471 void CustomizeKeyboard(int player_nr)
2475 boolean finished = FALSE;
2476 static struct SetupKeyboardInfo custom_key;
2481 } customize_step[] =
2483 { &custom_key.left, "Move Left" },
2484 { &custom_key.right, "Move Right" },
2485 { &custom_key.up, "Move Up" },
2486 { &custom_key.down, "Move Down" },
2487 { &custom_key.snap, "Snap Field" },
2488 { &custom_key.bomb, "Place Bomb" }
2491 /* read existing key bindings from player setup */
2492 custom_key = setup.input[player_nr].key;
2495 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2501 DrawText(mSX, mSY + (2+2*step_nr)*32,
2502 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2503 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2504 "Key:", FONT_INPUT_ACTIVE);
2505 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2506 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2510 if (PendingEvent()) /* got event */
2518 case EVENT_KEYPRESS:
2520 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2522 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2528 /* all keys configured -- wait for "Escape" or "Return" key */
2532 /* press 'Enter' to keep the existing key binding */
2533 if (key == KSYM_Return)
2534 key = *customize_step[step_nr].key;
2536 /* check if key already used */
2537 for (i=0; i<step_nr; i++)
2538 if (*customize_step[i].key == key)
2543 /* got new key binding */
2544 *customize_step[step_nr].key = key;
2545 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2547 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2548 getKeyNameFromKey(key), FONT_VALUE_1);
2551 /* un-highlight last query */
2552 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2553 customize_step[step_nr-1].text, FONT_MENU_1);
2554 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2555 "Key:", FONT_MENU_1);
2557 /* press 'Enter' to leave */
2560 DrawText(mSX + 16, mSY + 15*32+16,
2561 "Press Enter", FONT_TITLE_1);
2565 /* query next key binding */
2566 DrawText(mSX, mSY+(2+2*step_nr)*32,
2567 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2568 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2569 "Key:", FONT_INPUT_ACTIVE);
2570 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2571 getKeyNameFromKey(*customize_step[step_nr].key),
2576 case EVENT_KEYRELEASE:
2577 key_joystick_mapping = 0;
2581 HandleOtherEvents(&event);
2589 /* don't eat all CPU time */
2593 /* write new key bindings back to player setup */
2594 setup.input[player_nr].key = custom_key;
2597 DrawSetupScreen_Input();
2600 static boolean CalibrateJoystickMain(int player_nr)
2602 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2603 int new_joystick_xright = JOYSTICK_XMIDDLE;
2604 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2605 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2606 int new_joystick_xmiddle, new_joystick_ymiddle;
2608 int joystick_fd = joystick.fd[player_nr];
2609 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2610 boolean check[3][3];
2611 int check_remaining = 3 * 3;
2616 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2619 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2624 for(y=0; y < 3; y++)
2626 for(x=0; x < 3; x++)
2628 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2629 check[x][y] = FALSE;
2633 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2634 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2635 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2636 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2637 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2638 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2639 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2641 joy_value = Joystick(player_nr);
2642 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2643 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2645 /* eventually uncalibrated center position (joystick could be uncentered) */
2646 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2649 new_joystick_xmiddle = joy_x;
2650 new_joystick_ymiddle = joy_y;
2652 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2655 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2660 if (PendingEvent()) /* got event */
2668 case EVENT_KEYPRESS:
2669 switch(GetEventKey((KeyEvent *)&event, TRUE))
2672 if (check_remaining == 0)
2685 case EVENT_KEYRELEASE:
2686 key_joystick_mapping = 0;
2690 HandleOtherEvents(&event);
2695 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2698 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2699 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2700 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2701 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2703 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2704 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2705 setup.input[player_nr].joy.xright = new_joystick_xright;
2706 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2707 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2708 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2710 CheckJoystickData();
2712 joy_value = Joystick(player_nr);
2714 if (joy_value & JOY_BUTTON && check_remaining == 0)
2717 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2718 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2720 if (x != last_x || y != last_y)
2722 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2723 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2728 if (check_remaining > 0 && !check[x+1][y+1])
2730 check[x+1][y+1] = TRUE;
2736 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2737 setup.input[player_nr].joy.xleft,
2738 setup.input[player_nr].joy.xmiddle,
2739 setup.input[player_nr].joy.xright);
2740 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2741 setup.input[player_nr].joy.yupper,
2742 setup.input[player_nr].joy.ymiddle,
2743 setup.input[player_nr].joy.ylower);
2752 /* don't eat all CPU time */
2756 /* calibrated center position (joystick should now be centered) */
2757 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2760 new_joystick_xmiddle = joy_x;
2761 new_joystick_ymiddle = joy_y;
2765 DrawSetupScreen_Input();
2767 /* wait until the last pressed button was released */
2768 while (Joystick(player_nr) & JOY_BUTTON)
2770 if (PendingEvent()) /* got event */
2775 HandleOtherEvents(&event);
2784 void CalibrateJoystick(int player_nr)
2786 if (!CalibrateJoystickMain(player_nr))
2790 DrawText(mSX + 16, mSY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2791 DrawText(mSX, mSY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2793 Delay(2000); /* show error message for two seconds */
2797 void DrawSetupScreen()
2799 DeactivateJoystick();
2801 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2803 if (setup_mode == SETUP_MODE_INPUT)
2804 DrawSetupScreen_Input();
2805 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2806 DrawChooseTree(&artwork.gfx_current);
2807 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2808 DrawChooseTree(&artwork.snd_current);
2809 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2810 DrawChooseTree(&artwork.mus_current);
2812 DrawSetupScreen_Generic();
2815 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2817 if (setup_mode == SETUP_MODE_INPUT)
2818 HandleSetupScreen_Input(mx, my, dx, dy, button);
2819 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2820 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2821 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2822 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2823 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2824 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2826 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2829 void HandleGameActions()
2831 if (game_status != PLAYING)
2834 if (local_player->LevelSolved)
2837 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2845 /* ---------- new screen button stuff -------------------------------------- */
2847 /* graphic position and size values for buttons and scrollbars */
2848 #define SC_SCROLLBUTTON_XSIZE 32
2849 #define SC_SCROLLBUTTON_YSIZE 32
2851 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2852 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2853 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2854 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2855 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2856 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2857 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2858 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2860 #define SC_BORDER_SIZE 14
2864 int gfx_unpressed, gfx_pressed;
2868 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2871 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2872 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2873 SCREEN_CTRL_ID_SCROLL_UP,
2877 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2878 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2879 SCREEN_CTRL_ID_SCROLL_DOWN,
2886 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2887 Bitmap **gfx_unpressed, **gfx_pressed;
2889 int gfx_unpressed, gfx_pressed;
2896 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2899 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2900 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2902 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2904 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2905 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2906 GD_TYPE_SCROLLBAR_VERTICAL,
2907 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2908 "scroll level series vertically"
2912 static void CreateScreenScrollbuttons()
2914 struct GadgetInfo *gi;
2915 unsigned long event_mask;
2918 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2920 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2921 int gfx_unpressed, gfx_pressed;
2922 int x, y, width, height;
2923 int gd_x1, gd_x2, gd_y1, gd_y2;
2924 int id = scrollbutton_info[i].gadget_id;
2926 x = scrollbutton_info[i].x;
2927 y = scrollbutton_info[i].y;
2929 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2933 width = SC_SCROLLBUTTON_XSIZE;
2934 height = SC_SCROLLBUTTON_YSIZE;
2936 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2937 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2938 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2939 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2940 gd_x1 = graphic_info[gfx_unpressed].src_x;
2941 gd_y1 = graphic_info[gfx_unpressed].src_y;
2942 gd_x2 = graphic_info[gfx_pressed].src_x;
2943 gd_y2 = graphic_info[gfx_pressed].src_y;
2945 gi = CreateGadget(GDI_CUSTOM_ID, id,
2946 GDI_CUSTOM_TYPE_ID, i,
2947 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2952 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2953 GDI_STATE, GD_BUTTON_UNPRESSED,
2954 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2955 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2956 GDI_EVENT_MASK, event_mask,
2957 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2961 Error(ERR_EXIT, "cannot create gadget");
2963 screen_gadget[id] = gi;
2967 static void CreateScreenScrollbars()
2971 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2973 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2974 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2975 int gfx_unpressed, gfx_pressed;
2977 int gd_x1, gd_x2, gd_y1, gd_y2;
2978 struct GadgetInfo *gi;
2979 int items_max, items_visible, item_position;
2980 unsigned long event_mask;
2981 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2982 int id = scrollbar_info[i].gadget_id;
2984 items_max = num_page_entries;
2985 items_visible = num_page_entries;
2988 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2990 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2991 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
2992 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
2998 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2999 gfx_pressed = scrollbar_info[i].gfx_pressed;
3000 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3001 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3002 gd_x1 = graphic_info[gfx_unpressed].src_x;
3003 gd_y1 = graphic_info[gfx_unpressed].src_y;
3004 gd_x2 = graphic_info[gfx_pressed].src_x;
3005 gd_y2 = graphic_info[gfx_pressed].src_y;
3008 gi = CreateGadget(GDI_CUSTOM_ID, id,
3009 GDI_CUSTOM_TYPE_ID, i,
3010 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3011 GDI_X, scrollbar_info[i].x,
3012 GDI_Y, scrollbar_info[i].y,
3013 GDI_WIDTH, scrollbar_info[i].width,
3014 GDI_HEIGHT, scrollbar_info[i].height,
3015 GDI_TYPE, scrollbar_info[i].type,
3016 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3017 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3018 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3019 GDI_STATE, GD_BUTTON_UNPRESSED,
3020 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3021 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3022 GDI_BORDER_SIZE, SC_BORDER_SIZE,
3023 GDI_EVENT_MASK, event_mask,
3024 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3028 Error(ERR_EXIT, "cannot create gadget");
3030 screen_gadget[id] = gi;
3034 void CreateScreenGadgets()
3036 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3039 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3041 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3043 /* copy pointers to clip mask and GC */
3044 scrollbar_bitmap[i]->clip_mask =
3045 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3046 scrollbar_bitmap[i]->stored_clip_gc =
3047 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3049 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3050 scrollbar_bitmap[i],
3051 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3052 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3053 TILEX, TILEY, 0, 0);
3057 CreateScreenScrollbuttons();
3058 CreateScreenScrollbars();
3061 void FreeScreenGadgets()
3065 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3066 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3068 /* prevent freeing clip mask and GC twice */
3069 scrollbar_bitmap[i]->clip_mask = None;
3070 scrollbar_bitmap[i]->stored_clip_gc = None;
3072 FreeBitmap(scrollbar_bitmap[i]);
3076 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3077 FreeGadget(screen_gadget[i]);
3080 void MapChooseTreeGadgets(TreeInfo *ti)
3082 int num_entries = numTreeInfoInGroup(ti);
3085 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
3088 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3089 MapGadget(screen_gadget[i]);
3092 void UnmapChooseTreeGadgets()
3096 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3097 UnmapGadget(screen_gadget[i]);
3100 static void HandleScreenGadgets(struct GadgetInfo *gi)
3102 int id = gi->custom_id;
3104 if (game_status != CHOOSELEVEL && game_status != SETUP)
3109 case SCREEN_CTRL_ID_SCROLL_UP:
3110 if (game_status == CHOOSELEVEL)
3111 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3112 else if (game_status == SETUP)
3113 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3116 case SCREEN_CTRL_ID_SCROLL_DOWN:
3117 if (game_status == CHOOSELEVEL)
3118 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3119 else if (game_status == SETUP)
3120 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3123 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3124 if (game_status == CHOOSELEVEL)
3125 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3126 else if (game_status == SETUP)
3127 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);