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;
110 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
111 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY,
114 DrawBackground(SX + xpos * 32, SY + ypos * 32, TILEX, TILEY);
115 DrawGraphicThruMask(xpos, ypos, graphic, 0);
119 static void initCursor(int ypos, int graphic)
121 drawCursorExt(0, ypos, FC_BLUE, graphic);
124 static void drawCursor(int ypos, int color)
126 drawCursorExt(0, ypos, color, 0);
129 static void drawCursorXY(int xpos, int ypos, int graphic)
131 drawCursorExt(xpos, ypos, -1, graphic);
134 static void PlaySound_Menu_Start(int sound)
136 if (sound_info[sound].loop)
137 PlaySoundLoop(sound);
142 static void PlaySound_Menu_Continue(int sound)
144 if (sound_info[sound].loop)
145 PlaySoundLoop(sound);
150 int font1_width = getFontWidth(FONT_TITLE_1);
151 int font2_width = getFontWidth(FONT_TITLE_2);
152 int x1 = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * font1_width) / 2;
153 int x2 = SX + (SXSIZE - strlen(WINDOW_SUBTITLE_STRING) * font2_width) / 2;
155 DrawText(x1, SY + 8, PROGRAM_TITLE_STRING, FONT_TITLE_1);
156 DrawText(x2, SY + 46, WINDOW_SUBTITLE_STRING, FONT_TITLE_2);
159 static void ToggleFullscreenIfNeeded()
161 if (setup.fullscreen != video.fullscreen_enabled)
163 /* save old door content */
164 BlitBitmap(backbuffer, bitmap_db_door,
165 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
167 /* toggle fullscreen */
168 ChangeVideoModeIfNeeded(setup.fullscreen);
169 setup.fullscreen = video.fullscreen_enabled;
171 /* redraw background to newly created backbuffer */
172 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
173 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
175 /* restore old door content */
176 BlitBitmap(bitmap_db_door, backbuffer,
177 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
179 redraw_mask = REDRAW_ALL;
185 static LevelDirTree *leveldir_last_valid = NULL;
186 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
187 int font_width = getFontWidth(FONT_MENU_1);
188 int name_width = font_width * strlen("Name:");
189 int level_width = font_width * strlen("Level:");
193 mSX = SX + global.menu_draw_xoffset;
194 mSY = SY + global.menu_draw_yoffset;
200 KeyboardAutoRepeatOn();
203 SetDrawDeactivationMask(REDRAW_NONE);
204 SetDrawBackgroundMask(REDRAW_FIELD);
206 audio.sound_deactivated = FALSE;
208 /* needed if last screen was the playing screen, invoked from level editor */
209 if (level_editor_test_game)
211 game_status = LEVELED;
216 /* needed if last screen was the editor screen */
217 UndrawSpecialEditorDoor();
219 /* needed if last screen was the setup screen and fullscreen state changed */
220 ToggleFullscreenIfNeeded();
222 /* needed if last screen (level choice) changed graphics, sounds or music */
223 ReloadCustomArtwork();
226 SetDrawtoField(DRAW_BACKBUFFER);
229 /* map gadgets for main menu screen */
232 /* leveldir_current may be invalid (level group, parent link) */
233 if (!validLevelSeries(leveldir_current))
234 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
236 /* store valid level series information */
237 leveldir_last_valid = leveldir_current;
239 /* level_nr may have been set to value over handicap with level editor */
240 if (setup.handicap && level_nr > leveldir_current->handicap_level)
241 level_nr = leveldir_current->handicap_level;
246 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
251 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
252 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
253 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
254 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
255 DrawText(mSY + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
256 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
257 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
258 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
260 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT);
261 DrawText(mSX + level_width + 5 * 32, mSY + 3*32, int2str(level_nr,3),
264 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
266 DrawTextF(mSX + 32 + level_width - 2, mSY + 3*32 + 1, FONT_TEXT_3, "%d-%d",
267 leveldir_current->first_level, leveldir_current->last_level);
270 if (leveldir_current->readonly)
273 DrawTextF(mSX + level_width + 9*32 - 2,
274 mSY + 3*32 + 1 - 7, FONT_TEXT_3, "READ");
275 DrawTextF(mSX + level_width + 9*32 - 2,
276 mSY + 3*32 + 1 + 7, FONT_TEXT_3, "ONLY");
280 initCursor(i, (i == 1 || i == 6 ? IMG_MENU_BUTTON_RIGHT :IMG_MENU_BUTTON));
282 drawCursorXY(level_width/32 + 4, 1, IMG_MENU_BUTTON_LEFT);
283 drawCursorXY(level_width/32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
285 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment", FONT_TITLE_2);
289 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
292 if (TAPE_IS_EMPTY(tape))
294 DrawCompleteVideoDisplay();
296 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
303 static void gotoTopLevelDir()
305 /* move upwards to top level directory */
306 while (leveldir_current->node_parent)
308 /* write a "path" into level tree for easy navigation to last level */
309 if (leveldir_current->node_parent->node_group->cl_first == -1)
311 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
312 int leveldir_pos = posTreeInfo(leveldir_current);
313 int num_page_entries;
314 int cl_first, cl_cursor;
316 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
317 num_page_entries = num_leveldirs;
319 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
321 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
322 cl_cursor = leveldir_pos - cl_first;
324 leveldir_current->node_parent->node_group->cl_first = cl_first;
325 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
328 leveldir_current = leveldir_current->node_parent;
332 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
334 static int choice = 0;
338 if (button == MB_MENU_INITIALIZE)
340 drawCursor(choice, FC_RED);
344 if (mx || my) /* mouse input */
347 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
349 else if (dx || dy) /* keyboard input */
351 if (dx && choice == 1)
352 x = (dx < 0 ? 10 : 14);
357 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
358 (x == 14 && level_nr < leveldir_current->last_level)) &&
361 static unsigned long level_delay = 0;
362 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
363 int new_level_nr, old_level_nr = level_nr;
365 new_level_nr = level_nr + (x == 10 ? -step : +step);
366 if (new_level_nr < leveldir_current->first_level)
367 new_level_nr = leveldir_current->first_level;
368 if (new_level_nr > leveldir_current->last_level)
369 new_level_nr = leveldir_current->last_level;
371 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
372 new_level_nr = leveldir_current->handicap_level;
374 if (old_level_nr == new_level_nr ||
375 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
378 level_nr = new_level_nr;
380 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
383 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
387 DrawCompleteVideoDisplay();
389 /* needed because DrawMicroLevel() takes some time */
392 DelayReached(&level_delay, 0); /* reset delay counter */
394 else if (x == 0 && y >= 0 && y <= 7)
400 drawCursor(y, FC_RED);
401 drawCursor(choice, FC_BLUE);
409 game_status = TYPENAME;
410 HandleTypeName(strlen(setup.player_name), 0);
416 game_status = CHOOSELEVEL;
417 SaveLevelSetup_LastSeries();
418 SaveLevelSetup_SeriesInfo();
427 game_status = HALLOFFAME;
432 if (leveldir_current->readonly &&
433 strcmp(setup.player_name, "Artsoft") != 0)
434 Request("This level is read only !", REQ_CONFIRM);
435 game_status = LEVELED;
440 game_status = HELPSCREEN;
445 if (setup.autorecord)
446 TapeStartRecording();
448 #if defined(PLATFORM_UNIX)
450 SendToServer_StartPlaying();
454 game_status = PLAYING;
462 setup_mode = SETUP_MODE_MAIN;
467 SaveLevelSetup_LastSeries();
468 SaveLevelSetup_SeriesInfo();
469 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
470 game_status = EXITGAME;
479 if (game_status == MAINMENU)
481 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
487 #define MAX_HELPSCREEN_ELS 10
491 static long helpscreen_state;
492 static int helpscreen_step[MAX_HELPSCREEN_ELS];
493 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
495 static int OLD_helpscreen_action[] =
497 GFX_SPIELER1_DOWN,4,2,
499 GFX_SPIELER1_LEFT,4,2,
500 GFX_SPIELER1_RIGHT,4,2,
501 GFX_SPIELER1_PUSH_LEFT,4,2,
502 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
503 GFX_ERDREICH,1,100, HA_NEXT,
504 GFX_LEERRAUM,1,100, HA_NEXT,
505 GFX_MORAST_LEER,1,100, HA_NEXT,
506 GFX_BETON,1,100, HA_NEXT,
507 GFX_MAUERWERK,1,100, HA_NEXT,
508 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
509 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
510 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
511 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
512 GFX_UNSICHTBAR,1,100, HA_NEXT,
513 GFX_FELSBODEN,1,100, HA_NEXT,
514 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
515 GFX_EDELSTEIN,2,5, HA_NEXT,
516 GFX_DIAMANT,2,5, HA_NEXT,
517 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
518 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
519 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
520 GFX_FELSBROCKEN,4,5, HA_NEXT,
521 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
522 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
523 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
524 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
525 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
526 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
527 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
528 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
529 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
530 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
531 GFX_GEBLUBBER,4,4, HA_NEXT,
532 GFX_SCHLUESSEL1,4,25, HA_NEXT,
533 GFX_PFORTE1,4,25, HA_NEXT,
534 GFX_PFORTE1X,4,25, HA_NEXT,
535 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
536 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
537 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
538 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
539 GFX_LEERRAUM,1,10, HA_NEXT,
540 GFX_DYNABOMB_NR,1,100, HA_NEXT,
541 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
542 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
543 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
544 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
545 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
546 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
547 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
548 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
549 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
550 GFX_BUTTERFLY,2,2, HA_NEXT,
551 GFX_FIREFLY,2,2, HA_NEXT,
552 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
553 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
554 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
555 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
556 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
557 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
558 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
559 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
560 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
561 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
565 GFX_MOLE_RIGHT,4,2, HA_NEXT,
566 GFX_PINGUIN_DOWN,4,2,
568 GFX_PINGUIN_LEFT,4,2,
569 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
570 GFX_SCHWEIN_DOWN,4,2,
572 GFX_SCHWEIN_LEFT,4,2,
573 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
577 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
578 GFX_SONDE_START,8,1, HA_NEXT,
579 GFX_ABLENK,4,1, HA_NEXT,
580 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
581 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
582 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
583 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
584 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
585 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
586 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
587 GFX_DIAMANT,1,10, HA_NEXT,
588 GFX_LIFE,1,100, HA_NEXT,
589 GFX_LIFE_ASYNC,1,100, HA_NEXT,
590 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
591 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
592 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
593 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
594 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
595 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
596 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
597 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
598 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
599 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
600 GFX_SPEED_PILL,1,100, HA_NEXT,
605 static int helpscreen_action[] =
607 IMG_PLAYER_1_MOVING_DOWN, 16,
608 IMG_PLAYER_1_MOVING_UP, 16,
609 IMG_PLAYER_1_MOVING_LEFT, 16,
610 IMG_PLAYER_1_MOVING_RIGHT, 16,
611 IMG_PLAYER_1_PUSHING_LEFT, 16,
612 IMG_PLAYER_1_PUSHING_RIGHT, 16, HA_NEXT,
614 IMG_SAND, -1, HA_NEXT,
616 IMG_EMPTY_SPACE, -1, HA_NEXT,
618 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
620 IMG_STEELWALL, -1, HA_NEXT,
622 IMG_WALL, -1, HA_NEXT,
624 IMG_EXPANDABLE_WALL_GROWING_LEFT, 20,
627 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 20,
630 IMG_EXPANDABLE_WALL_GROWING_UP, 20,
633 IMG_EXPANDABLE_WALL_GROWING_DOWN, 20,
635 IMG_EMPTY_SPACE, 20, HA_NEXT,
637 IMG_INVISIBLE_WALL, -1, HA_NEXT,
639 IMG_WALL_CRUMBLED, -1, HA_NEXT,
641 IMG_INFO_FONT_EM_1, 160,
642 IMG_INFO_FONT_EM_2, 160,
643 IMG_INFO_FONT_EM_3, 160,
644 IMG_INFO_FONT_EM_4, 160,
645 IMG_INFO_FONT_EM_5, 40, HA_NEXT,
647 IMG_EMERALD, -1, HA_NEXT,
649 IMG_DIAMOND, -1, HA_NEXT,
651 IMG_BD_DIAMOND, -1, HA_NEXT,
653 IMG_EMERALD_YELLOW, 50,
655 IMG_EMERALD_PURPLE, 50, HA_NEXT,
657 IMG_BD_ROCK, -1, HA_NEXT,
661 IMG_EMPTY_SPACE, 10, HA_NEXT,
665 IMG_EMERALD, 20, HA_NEXT,
667 IMG_WALL_EMERALD, 100,
669 IMG_EMERALD, 20, HA_NEXT,
671 IMG_WALL_DIAMOND, 100,
673 IMG_DIAMOND, 20, HA_NEXT,
675 IMG_WALL_BD_DIAMOND, 100,
677 IMG_BD_DIAMOND, 20, HA_NEXT,
679 IMG_WALL_EMERALD_YELLOW, 100,
681 IMG_EMERALD_YELLOW, 20,
682 IMG_WALL_EMERALD_RED, 100,
685 IMG_WALL_EMERALD_PURPLE, 100,
687 IMG_EMERALD_PURPLE, 20, HA_NEXT,
689 IMG_ACID, -1, HA_NEXT,
694 IMG_KEY_4, 50, HA_NEXT,
699 IMG_GATE_4, 50, HA_NEXT,
704 IMG_GATE_4_GRAY, 50, HA_NEXT,
706 IMG_DYNAMITE, -1, HA_NEXT,
708 IMG_DYNAMITE_ACTIVE, 96,
710 IMG_EMPTY_SPACE, 20, HA_NEXT,
712 IMG_DYNABOMB_ACTIVE, 100,
714 IMG_EMPTY_SPACE, 20, HA_NEXT,
716 EL_DYNABOMB_INCREASE_NUMBER, -1, HA_NEXT,
718 EL_DYNABOMB_INCREASE_SIZE, -1, HA_NEXT,
720 IMG_SPACESHIP_RIGHT, 16,
721 IMG_SPACESHIP_UP, 16,
722 IMG_SPACESHIP_LEFT, 16,
723 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
728 IMG_BUG_DOWN, 16, HA_NEXT,
730 IMG_BD_BUTTERFLY, -1, HA_NEXT,
732 IMG_BD_FIREFLY, -1, HA_NEXT,
734 IMG_PACMAN_RIGHT, 16,
737 IMG_PACMAN_DOWN, 16, HA_NEXT,
739 IMG_YAMYAM, -1, HA_NEXT,
741 IMG_DARK_YAMYAM, -1, HA_NEXT,
743 IMG_ROBOT, -1, HA_NEXT,
745 IMG_MOLE_MOVING_RIGHT, 16,
746 IMG_MOLE_MOVING_UP, 16,
747 IMG_MOLE_MOVING_LEFT, 16,
748 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
750 IMG_PENGUIN_MOVING_RIGHT, 16,
751 IMG_PENGUIN_MOVING_UP, 16,
752 IMG_PENGUIN_MOVING_LEFT, 16,
753 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
755 IMG_PIG_MOVING_RIGHT, 16,
756 IMG_PIG_MOVING_UP, 16,
757 IMG_PIG_MOVING_LEFT, 16,
758 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
760 IMG_DRAGON_MOVING_RIGHT, 16,
761 IMG_DRAGON_MOVING_UP, 16,
762 IMG_DRAGON_MOVING_LEFT, 16,
763 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
765 IMG_SATELLITE, -1, HA_NEXT,
768 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
771 IMG_LAMP_ACTIVE, 50, HA_NEXT,
773 IMG_TIME_ORB_FULL, 50,
774 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
777 IMG_AMOEBA_GROWING, 6,
778 IMG_AMOEBA_WET, 20, HA_NEXT,
780 IMG_AMOEBA_DEAD, -1, HA_NEXT,
782 IMG_AMOEBA_WET, -1, HA_NEXT,
785 IMG_AMOEBA_GROWING, 6, HA_NEXT,
790 IMG_DIAMOND, 20, HA_NEXT,
792 IMG_GAME_OF_LIFE, -1, HA_NEXT,
794 IMG_BIOMAZE, -1, HA_NEXT,
796 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
798 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
800 IMG_EXIT_CLOSED, 200,
801 IMG_EXIT_OPENING, 16,
802 IMG_EXIT_OPEN, 100, HA_NEXT,
804 IMG_EXIT_OPEN, -1, HA_NEXT,
806 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
808 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
810 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
812 IMG_SPEED_PILL, -1, HA_NEXT,
816 static char *helpscreen_eltext[][2] =
818 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
819 {"Normal sand:", "You can dig through it"},
820 {"Empty field:", "You can walk through it"},
821 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
822 {"Massive Wall:", "Nothing can go through it"},
823 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
824 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
825 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
826 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
827 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
828 {"Emerald: You must collect enough of","them to finish a level"},
829 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
830 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
831 {"Colorful Gems:", "Seem to behave like Emeralds"},
832 {"Rock: Smashes several things;", "Can be moved by the player"},
833 {"Bomb: You can move it, but be", "careful when dropping it"},
834 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
835 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
836 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
837 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
838 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
839 {"Acid: Things that fall in are gone", "forever (including our hero)"},
840 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
841 {"Door: Can be opened by the key", "with the same color"},
842 {"Door: You have to find out the", "right color of the key for it"},
843 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
844 {"Dynamite: This one explodes after", "a few seconds"},
845 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
846 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
847 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
848 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
849 {"Bug: Moves at the right side", "of walls; don't touch it!"},
850 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
851 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
852 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
853 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
854 {"Cruncher (BD style):", "Eats almost everything"},
855 {"Robot: Tries to kill the player", ""},
856 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
857 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
858 {"The Pig: Harmless, but eats all", "gems it can get"},
859 {"The Dragon: Breathes fire,", "especially to some monsters"},
860 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
861 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
862 {"Light Bulb: All of them must be", "switched on to finish a level"},
863 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
864 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
865 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
866 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
867 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
868 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
869 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
870 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
871 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
872 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
873 {"Exit door: Opens if you have enough","emeralds to finish the level"},
874 {"Open exit door: Enter here to leave","the level and exit the actual game"},
875 {"Sokoban element: Object which must", "be pushed to an empty field"},
876 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
877 {"Sokoban element: Field with object", "which can be pushed away"},
878 {"Speed pill: Lets the player run", "twice as fast as normally"},
880 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
882 static char *helpscreen_music[][3] =
884 { "Alchemy", "Ian Boddy", "Drive" },
885 { "The Chase", "Propaganda", "A Secret Wish" },
886 { "Network 23", "Tangerine Dream", "Exit" },
887 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
888 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
889 { "Voyager", "The Alan Parsons Project","Pyramid" },
890 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
892 static int num_helpscreen_music = 7;
893 static int helpscreen_musicpos;
896 void OLD_DrawHelpScreenElAction(int start)
900 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
902 while(helpscreen_action[j] != HA_END)
904 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
906 else if (i<start || helpscreen_delay[i-start])
908 if (i>=start && helpscreen_delay[i-start])
909 helpscreen_delay[i-start]--;
911 while(helpscreen_action[j] != HA_NEXT)
918 j += 3*helpscreen_step[i-start];
919 graphic = helpscreen_action[j++];
921 if (helpscreen_frame[i-start])
923 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
924 helpscreen_frame[i-start]--;
929 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
932 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
934 if (helpscreen_action[j] == HA_NEXT)
936 if (!helpscreen_frame[i-start])
937 helpscreen_step[i-start] = 0;
941 if (!helpscreen_frame[i-start])
942 helpscreen_step[i-start]++;
943 while(helpscreen_action[j] != HA_NEXT)
948 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
960 void DrawHelpScreenElAction(int start)
963 int xstart = mSX + 16;
964 int ystart = mSY + 64 + 2 * 32;
965 int ystep = TILEY + 4;
971 while (helpscreen_action[j] != HA_END)
973 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
977 while (helpscreen_action[j] != HA_NEXT)
986 j += 2 * helpscreen_step[i-start];
987 graphic = helpscreen_action[j++];
988 frame_count = helpscreen_action[j++];
989 if (frame_count == -1)
990 frame_count = 1000000;
992 if (helpscreen_frame[i-start] == 0)
995 helpscreen_frame[i-start] = frame_count - 1;
999 sync_frame = frame_count - helpscreen_frame[i-start];
1000 helpscreen_frame[i-start]--;
1003 if (helpscreen_action[j] == HA_NEXT)
1005 if (!helpscreen_frame[i-start])
1006 helpscreen_step[i-start] = 0;
1010 if (!helpscreen_frame[i-start])
1011 helpscreen_step[i-start]++;
1012 while(helpscreen_action[j] != HA_NEXT)
1017 frame = getGraphicAnimationFrame(graphic, sync_frame);
1019 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
1027 MarkTileDirty(0, i);
1028 MarkTileDirty(1, i);
1034 void DrawHelpScreenElText(int start)
1037 int xstart = mSX + 56, ystart = mSY + 65 + 2 * 32, ystep = TILEY + 4;
1038 int ybottom = SYSIZE - 20;
1040 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1044 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
1046 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1049 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1050 helpscreen_eltext[i][0], FONT_TEXT_2);
1051 DrawText(xstart, ystart + (i - start) * ystep + 16,
1052 helpscreen_eltext[i][1], FONT_TEXT_2);
1055 DrawTextFCentered(ybottom, FONT_TEXT_4,
1056 "Press any key or button for next page");
1059 void DrawHelpScreenMusicText(int num)
1061 int ystart = 150, ystep = 30;
1062 int ybottom = SYSIZE - 20;
1068 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
1070 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
1071 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
1072 "\"%s\"", helpscreen_music[num][0]);
1073 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
1074 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
1075 "%s", helpscreen_music[num][1]);
1076 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1077 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
1078 "\"%s\"", helpscreen_music[num][2]);
1080 DrawTextFCentered(ybottom, FONT_TEXT_4,
1081 "Press any key or button for next page");
1084 PlaySoundLoop(background_loop[num]);
1088 void DrawHelpScreenCreditsText()
1090 int ystart = 150, ystep = 30;
1091 int ybottom = SYSIZE - 20;
1097 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
1098 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1099 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1100 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1101 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1102 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
1103 "...and many thanks to all contributors");
1104 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1106 DrawTextFCentered(ybottom, FONT_TEXT_4,
1107 "Press any key or button for next page");
1110 void DrawHelpScreenContactText()
1112 int ystart = 150, ystep = 30;
1113 int ybottom = SYSIZE - 20;
1118 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1120 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1121 "This game is Freeware!");
1122 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1123 "If you like it, send e-mail to:");
1124 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1125 "info@artsoft.org");
1126 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1127 "or SnailMail to:");
1128 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1130 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1131 "Detmolder Strasse 189");
1132 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1134 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1137 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1138 "If you have created new levels,");
1139 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1140 "send them to me to include them!");
1141 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1144 DrawTextFCentered(ybottom, FONT_TEXT_4,
1145 "Press any key or button for main menu");
1148 void DrawHelpScreen()
1153 CloseDoor(DOOR_CLOSE_2);
1155 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1156 helpscreen_step[i] = helpscreen_frame[i] = 0;
1157 helpscreen_musicpos = 0;
1158 helpscreen_state = 0;
1160 DrawHelpScreenElText(0);
1161 DrawHelpScreenElAction(0);
1167 PlaySoundLoop(SND_BACKGROUND_INFO);
1169 PlaySound_Menu_Start(SND_BACKGROUND_INFO);
1173 void HandleHelpScreen(int button)
1175 static unsigned long hs_delay = 0;
1176 int num_helpscreen_els_pages =
1177 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1178 int button_released = !button;
1181 if (button_released)
1183 if (helpscreen_state < num_helpscreen_els_pages - 1)
1185 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1186 helpscreen_step[i] = helpscreen_frame[i] = 0;
1190 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1191 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1193 else if (helpscreen_state <
1194 num_helpscreen_els_pages + num_helpscreen_music - 1)
1197 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1199 else if (helpscreen_state ==
1200 num_helpscreen_els_pages + num_helpscreen_music - 1)
1203 DrawHelpScreenCreditsText();
1205 else if (helpscreen_state ==
1206 num_helpscreen_els_pages + num_helpscreen_music)
1209 DrawHelpScreenContactText();
1215 game_status = MAINMENU;
1221 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1223 if (helpscreen_state < num_helpscreen_els_pages)
1224 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1227 /* !!! workaround for playing "music" that is really a sound loop (and
1228 must therefore periodically be reactivated with the current sound
1231 PlaySoundLoop(SND_BACKGROUND_INFO);
1233 PlaySound_Menu_Continue(SND_BACKGROUND_INFO);
1242 void HandleTypeName(int newxpos, Key key)
1244 static int xpos = 0, ypos = 2;
1245 int font_width = getFontWidth(FONT_INPUT_ACTIVE);
1246 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1247 int startx = mSX + 32 + name_width;
1248 int starty = mSY + ypos * 32;
1254 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1255 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1260 if (((key >= KSYM_A && key <= KSYM_Z) ||
1261 (key >= KSYM_a && key <= KSYM_z)) &&
1262 xpos < MAX_PLAYER_NAME_LEN)
1266 if (key >= KSYM_A && key <= KSYM_Z)
1267 ascii = 'A' + (char)(key - KSYM_A);
1269 ascii = 'a' + (char)(key - KSYM_a);
1271 setup.player_name[xpos] = ascii;
1272 setup.player_name[xpos + 1] = 0;
1275 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1276 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1278 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1281 setup.player_name[xpos] = 0;
1283 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_ACTIVE);
1285 else if (key == KSYM_Return && xpos > 0)
1287 DrawText(startx, starty, setup.player_name, FONT_INPUT);
1288 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_ACTIVE);
1291 game_status = MAINMENU;
1297 static void DrawChooseTree(TreeInfo **ti_ptr)
1300 CloseDoor(DOOR_CLOSE_2);
1304 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1305 MapChooseTreeGadgets(*ti_ptr);
1311 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1313 struct GadgetInfo *gi = screen_gadget[id];
1314 int items_max, items_visible, item_position;
1316 items_max = numTreeInfoInGroup(ti);
1317 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1318 item_position = first_entry;
1320 if (item_position > items_max - items_visible)
1321 item_position = items_max - items_visible;
1323 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1324 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1327 static void drawChooseTreeList(int first_entry, int num_page_entries,
1331 char buffer[SCR_FIELDX * 2];
1332 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1333 int num_entries = numTreeInfoInGroup(ti);
1334 char *title_string = NULL;
1335 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1336 int last_game_status = game_status; /* save current game status */
1338 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1339 redraw_mask |= REDRAW_FIELD;
1342 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1343 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1344 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1345 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1347 DrawText(SX + offset, SY + offset, title_string, FONT_TITLE_1);
1349 game_status = CHOOSELEVEL; /* force LEVELS font on artwork setup screen */
1351 for(i=0; i<num_page_entries; i++)
1353 TreeInfo *node, *node_first;
1354 int entry_pos = first_entry + i;
1355 int ypos = MENU_SCREEN_START_YPOS + i;
1357 node_first = getTreeInfoFirstGroupEntry(ti);
1358 node = getTreeInfoFromPos(node_first, entry_pos);
1360 strncpy(buffer, node->name , max_buffer_len);
1361 buffer[max_buffer_len] = '\0';
1363 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1365 if (node->parent_link)
1366 initCursor(i, IMG_MENU_BUTTON_LEFT);
1367 else if (node->level_group)
1368 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1370 initCursor(i, IMG_MENU_BUTTON);
1373 if (first_entry > 0)
1377 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1378 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_UP, 0);
1381 if (first_entry + num_page_entries < num_entries)
1383 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1385 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1386 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_DOWN, 0);
1389 game_status = last_game_status; /* restore current game status */
1392 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1394 TreeInfo *node, *node_first;
1395 int x, last_redraw_mask = redraw_mask;
1397 if (ti->type != TREE_TYPE_LEVEL_DIR)
1400 node_first = getTreeInfoFirstGroupEntry(ti);
1401 node = getTreeInfoFromPos(node_first, entry_pos);
1403 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1405 if (node->parent_link)
1406 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1408 else if (node->level_group)
1409 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1411 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1412 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1413 node->levels, node->class_desc);
1415 /* let BackToFront() redraw only what is needed */
1416 redraw_mask = last_redraw_mask | REDRAW_TILES;
1417 for (x=0; x<SCR_FIELDX; x++)
1418 MarkTileDirty(x, 1);
1421 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1424 static unsigned long choose_delay = 0;
1425 TreeInfo *ti = *ti_ptr;
1427 int y = ti->cl_cursor;
1428 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1429 int num_entries = numTreeInfoInGroup(ti);
1430 int num_page_entries;
1432 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1433 num_page_entries = num_entries;
1435 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1437 if (button == MB_MENU_INITIALIZE)
1439 int entry_pos = posTreeInfo(ti);
1441 if (ti->cl_first == -1)
1443 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1445 entry_pos - ti->cl_first;
1448 if (dx == 999) /* first entry is set by scrollbar position */
1451 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1454 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1455 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1456 drawCursor(ti->cl_cursor, FC_RED);
1459 else if (button == MB_MENU_LEAVE)
1461 if (ti->node_parent)
1463 *ti_ptr = ti->node_parent;
1464 DrawChooseTree(ti_ptr);
1466 else if (game_status == SETUP)
1472 game_status = MAINMENU;
1479 if (mx || my) /* mouse input */
1482 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1484 else if (dx || dy) /* keyboard input */
1487 y = ti->cl_cursor + dy;
1489 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1492 step = num_page_entries - 1;
1493 y = (dy < 0 ? -1 : num_page_entries);
1497 if (x == 0 && y == -1)
1499 if (ti->cl_first > 0 &&
1500 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1502 ti->cl_first -= step;
1503 if (ti->cl_first < 0)
1506 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1507 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1508 drawCursor(ti->cl_cursor, FC_RED);
1509 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1514 else if (x == 0 && y > num_page_entries - 1)
1516 if (ti->cl_first + num_page_entries < num_entries &&
1517 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1519 ti->cl_first += step;
1520 if (ti->cl_first + num_page_entries > num_entries)
1521 ti->cl_first = MAX(0, num_entries - num_page_entries);
1523 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1524 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1525 drawCursor(ti->cl_cursor, FC_RED);
1526 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1534 TreeInfo *node_first, *node_cursor;
1535 int entry_pos = ti->cl_first + y;
1537 node_first = getTreeInfoFirstGroupEntry(ti);
1538 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1540 if (node_cursor->node_group)
1542 node_cursor->cl_first = ti->cl_first;
1543 node_cursor->cl_cursor = ti->cl_cursor;
1544 *ti_ptr = node_cursor->node_group;
1545 DrawChooseTree(ti_ptr);
1549 else if (dx == -1 && ti->node_parent)
1551 *ti_ptr = ti->node_parent;
1552 DrawChooseTree(ti_ptr);
1556 if (x == 0 && y >= 0 && y < num_page_entries)
1560 if (y != ti->cl_cursor)
1562 drawCursor(y, FC_RED);
1563 drawCursor(ti->cl_cursor, FC_BLUE);
1564 drawChooseTreeInfo(ti->cl_first + y, ti);
1570 TreeInfo *node_first, *node_cursor;
1571 int entry_pos = ti->cl_first + y;
1573 node_first = getTreeInfoFirstGroupEntry(ti);
1574 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1576 if (node_cursor->node_group)
1578 node_cursor->cl_first = ti->cl_first;
1579 node_cursor->cl_cursor = ti->cl_cursor;
1580 *ti_ptr = node_cursor->node_group;
1581 DrawChooseTree(ti_ptr);
1583 else if (node_cursor->parent_link)
1585 *ti_ptr = node_cursor->node_parent;
1586 DrawChooseTree(ti_ptr);
1590 node_cursor->cl_first = ti->cl_first;
1591 node_cursor->cl_cursor = ti->cl_cursor;
1592 *ti_ptr = node_cursor;
1594 if (ti->type == TREE_TYPE_LEVEL_DIR)
1596 LoadLevelSetup_SeriesInfo();
1598 SaveLevelSetup_LastSeries();
1599 SaveLevelSetup_SeriesInfo();
1603 if (game_status == SETUP)
1609 game_status = MAINMENU;
1618 if (game_status == CHOOSELEVEL || game_status == SETUP)
1622 void DrawChooseLevel()
1624 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1626 DrawChooseTree(&leveldir_current);
1629 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1631 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1634 void DrawHallOfFame(int highlight_position)
1638 CloseDoor(DOOR_CLOSE_2);
1640 if (highlight_position < 0)
1641 LoadScore(level_nr);
1646 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1649 PlaySound(SND_BACKGROUND_SCORES);
1651 PlaySound_Menu_Start(SND_BACKGROUND_SCORES);
1655 static void drawHallOfFameList(int first_entry, int highlight_position)
1659 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1662 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1663 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1665 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1667 int entry = first_entry + i;
1669 DrawText(mSX, mSY + 64 + i * 32, "..................................",
1670 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1671 DrawText(mSX, mSY + 64 + i * 32, int2str(entry + 1, 3),
1672 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1673 DrawText(mSX + 64, mSY + 64 + i * 32, highscore[entry].Name,
1674 (entry == highlight_position ? FONT_TEXT_3 : FONT_TEXT_1));
1675 DrawText(mSX + 14 * 32 + 16, mSY + 64 + i * 32,
1676 int2str(highscore[entry].Score, 5),
1677 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1681 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1683 static int first_entry = 0;
1684 static int highlight_position = 0;
1685 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1686 int button_released = !button;
1688 if (button == MB_MENU_INITIALIZE)
1691 highlight_position = mx;
1692 drawHallOfFameList(first_entry, highlight_position);
1696 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1697 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1701 if (first_entry > 0)
1703 first_entry -= step;
1704 if (first_entry < 0)
1707 drawHallOfFameList(first_entry, highlight_position);
1713 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1715 first_entry += step;
1716 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1717 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1719 drawHallOfFameList(first_entry, highlight_position);
1724 if (button_released)
1726 FadeSound(SND_BACKGROUND_SCORES);
1727 game_status = MAINMENU;
1733 if (game_status == HALLOFFAME)
1737 PlaySound_Menu_Continue(SND_BACKGROUND_SCORES);
1743 /* ========================================================================= */
1744 /* setup screen functions */
1745 /* ========================================================================= */
1747 static struct TokenInfo *setup_info;
1748 static int num_setup_info;
1750 static char *graphics_set_name;
1751 static char *sounds_set_name;
1752 static char *music_set_name;
1754 static void execSetupMain()
1756 setup_mode = SETUP_MODE_MAIN;
1760 static void execSetupGame()
1762 setup_mode = SETUP_MODE_GAME;
1766 static void execSetupEditor()
1768 setup_mode = SETUP_MODE_EDITOR;
1772 static void execSetupGraphics()
1774 setup_mode = SETUP_MODE_GRAPHICS;
1778 static void execSetupSound()
1780 setup_mode = SETUP_MODE_SOUND;
1784 static void execSetupArtwork()
1786 /* needed if last screen (setup choice) changed graphics, sounds or music */
1787 ReloadCustomArtwork();
1789 setup.graphics_set = artwork.gfx_current->identifier;
1790 setup.sounds_set = artwork.snd_current->identifier;
1791 setup.music_set = artwork.mus_current->identifier;
1793 /* needed for displaying artwork name instead of artwork identifier */
1794 graphics_set_name = artwork.gfx_current->name;
1795 sounds_set_name = artwork.snd_current->name;
1796 music_set_name = artwork.mus_current->name;
1798 setup_mode = SETUP_MODE_ARTWORK;
1802 static void execSetupChooseGraphics()
1804 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1808 static void execSetupChooseSounds()
1810 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1814 static void execSetupChooseMusic()
1816 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1820 static void execSetupInput()
1822 setup_mode = SETUP_MODE_INPUT;
1826 static void execSetupShortcut()
1828 setup_mode = SETUP_MODE_SHORTCUT;
1832 static void execExitSetup()
1834 game_status = MAINMENU;
1838 static void execSaveAndExitSetup()
1844 static struct TokenInfo setup_info_main[] =
1846 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1847 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1848 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1849 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1850 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1851 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1852 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1853 { TYPE_EMPTY, NULL, "" },
1854 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1855 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1859 static struct TokenInfo setup_info_game[] =
1861 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1862 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1863 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1864 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1865 { TYPE_EMPTY, NULL, "" },
1866 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1870 static struct TokenInfo setup_info_editor[] =
1872 { TYPE_STRING, NULL, "Offer Special Elements:"},
1873 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1874 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1875 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1876 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1877 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1878 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1879 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1880 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1881 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1882 { TYPE_EMPTY, NULL, "" },
1883 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1887 static struct TokenInfo setup_info_graphics[] =
1889 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1890 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1891 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1893 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1894 { TYPE_SWITCH, &setup.fading, "Fading:" },
1896 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1897 { TYPE_SWITCH, &setup.toons, "Toons:" },
1898 { TYPE_EMPTY, NULL, "" },
1899 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1903 static struct TokenInfo setup_info_sound[] =
1905 { TYPE_SWITCH, &setup.sound, "Sound:", },
1906 { TYPE_EMPTY, NULL, "" },
1907 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1908 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1909 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1910 { TYPE_EMPTY, NULL, "" },
1911 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1915 static struct TokenInfo setup_info_artwork[] =
1917 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1918 { TYPE_STRING, &graphics_set_name, "" },
1919 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1920 { TYPE_STRING, &sounds_set_name, "" },
1921 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1922 { TYPE_STRING, &music_set_name, "" },
1923 { TYPE_EMPTY, NULL, "" },
1924 { TYPE_STRING, NULL, "Override Level Artwork:"},
1925 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1926 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1927 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1928 { TYPE_EMPTY, NULL, "" },
1929 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1933 static struct TokenInfo setup_info_shortcut[] =
1935 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1936 { TYPE_KEY, &setup.shortcut.save_game, "" },
1937 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1938 { TYPE_KEY, &setup.shortcut.load_game, "" },
1939 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1940 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1941 { TYPE_EMPTY, NULL, "" },
1942 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1943 { TYPE_EMPTY, NULL, "" },
1944 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1948 static Key getSetupKey()
1950 Key key = KSYM_UNDEFINED;
1951 boolean got_key_event = FALSE;
1953 while (!got_key_event)
1955 if (PendingEvent()) /* got event */
1963 case EVENT_KEYPRESS:
1965 key = GetEventKey((KeyEvent *)&event, TRUE);
1967 /* press 'Escape' or 'Enter' to keep the existing key binding */
1968 if (key == KSYM_Escape || key == KSYM_Return)
1969 key = KSYM_UNDEFINED; /* keep old value */
1971 got_key_event = TRUE;
1975 case EVENT_KEYRELEASE:
1976 key_joystick_mapping = 0;
1980 HandleOtherEvents(&event);
1988 /* don't eat all CPU time */
1995 static void drawSetupValue(int pos)
1997 int xpos = MENU_SCREEN_VALUE_XPOS;
1998 int ypos = MENU_SCREEN_START_YPOS + pos;
1999 int font_nr = FONT_VALUE_1;
2000 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
2001 setup_info[pos].value);
2003 if (value_string == NULL)
2006 if (setup_info[pos].type & TYPE_KEY)
2010 if (setup_info[pos].type & TYPE_QUERY)
2012 value_string = "<press key>";
2013 font_nr = FONT_INPUT_ACTIVE;
2016 else if (setup_info[pos].type & TYPE_STRING)
2018 int max_value_len = (SCR_FIELDX - 2) * 2;
2021 font_nr = FONT_VALUE_2;
2023 if (strlen(value_string) > max_value_len)
2024 value_string[max_value_len] = '\0';
2026 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
2027 !*(boolean *)(setup_info[pos].value))
2028 font_nr = FONT_OPTION_OFF;
2030 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2031 (xpos == 3 ? " " : " "), font_nr);
2032 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2035 static void changeSetupValue(int pos)
2037 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2039 *(boolean *)setup_info[pos].value ^= TRUE;
2041 else if (setup_info[pos].type & TYPE_KEY)
2045 setup_info[pos].type |= TYPE_QUERY;
2046 drawSetupValue(pos);
2047 setup_info[pos].type &= ~TYPE_QUERY;
2049 key = getSetupKey();
2050 if (key != KSYM_UNDEFINED)
2051 *(Key *)setup_info[pos].value = key;
2054 drawSetupValue(pos);
2057 static void DrawSetupScreen_Generic()
2059 char *title_string = NULL;
2063 CloseDoor(DOOR_CLOSE_2);
2067 if (setup_mode == SETUP_MODE_MAIN)
2069 setup_info = setup_info_main;
2070 title_string = "Setup";
2072 else if (setup_mode == SETUP_MODE_GAME)
2074 setup_info = setup_info_game;
2075 title_string = "Setup Game";
2077 else if (setup_mode == SETUP_MODE_EDITOR)
2079 setup_info = setup_info_editor;
2080 title_string = "Setup Editor";
2082 else if (setup_mode == SETUP_MODE_GRAPHICS)
2084 setup_info = setup_info_graphics;
2085 title_string = "Setup Graphics";
2087 else if (setup_mode == SETUP_MODE_SOUND)
2089 setup_info = setup_info_sound;
2090 title_string = "Setup Sound";
2092 else if (setup_mode == SETUP_MODE_ARTWORK)
2094 setup_info = setup_info_artwork;
2095 title_string = "Custom Artwork";
2097 else if (setup_mode == SETUP_MODE_SHORTCUT)
2099 setup_info = setup_info_shortcut;
2100 title_string = "Setup Shortcuts";
2103 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2106 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2108 void *value_ptr = setup_info[i].value;
2109 int ypos = MENU_SCREEN_START_YPOS + i;
2110 int font_nr = FONT_MENU_1;
2112 /* set some entries to "unchangeable" according to other variables */
2113 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2114 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2115 (value_ptr == &setup.sound_music && !audio.music_available) ||
2116 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2117 setup_info[i].type |= TYPE_GHOSTED;
2119 if (setup_info[i].type & TYPE_STRING)
2120 font_nr = FONT_MENU_2;
2122 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2124 if (setup_info[i].type & TYPE_ENTER_MENU)
2125 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2126 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2127 initCursor(i, IMG_MENU_BUTTON_LEFT);
2128 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2129 initCursor(i, IMG_MENU_BUTTON);
2131 if (setup_info[i].type & TYPE_VALUE)
2139 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2142 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2144 static int choice_store[MAX_SETUP_MODES];
2145 int choice = choice_store[setup_mode]; /* always starts with 0 */
2149 if (button == MB_MENU_INITIALIZE)
2151 /* advance to first valid menu entry */
2152 while (choice < num_setup_info &&
2153 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2155 choice_store[setup_mode] = choice;
2157 drawCursor(choice, FC_RED);
2160 else if (button == MB_MENU_LEAVE)
2162 for (y=0; y<num_setup_info; y++)
2164 if (setup_info[y].type & TYPE_LEAVE_MENU)
2166 void (*menu_callback_function)(void) = setup_info[y].value;
2168 menu_callback_function();
2169 break; /* absolutely needed because function changes 'setup_info'! */
2176 if (mx || my) /* mouse input */
2179 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2181 else if (dx || dy) /* keyboard input */
2185 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2187 if ((setup_info[choice].type & menu_navigation_type) ||
2188 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2189 button = MB_MENU_CHOICE;
2194 /* jump to next non-empty menu entry (up or down) */
2195 while (y > 0 && y < num_setup_info - 1 &&
2196 (setup_info[y].type & TYPE_SKIP_ENTRY))
2200 if (x == 0 && y >= 0 && y < num_setup_info &&
2201 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2207 drawCursor(y, FC_RED);
2208 drawCursor(choice, FC_BLUE);
2209 choice = choice_store[setup_mode] = y;
2212 else if (!(setup_info[y].type & TYPE_GHOSTED))
2214 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2216 void (*menu_callback_function)(void) = setup_info[choice].value;
2218 menu_callback_function();
2222 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2223 (setup_info[y + 1].type & TYPE_KEY))
2226 if (setup_info[y].type & TYPE_VALUE)
2227 changeSetupValue(y);
2234 if (game_status == SETUP)
2238 void DrawSetupScreen_Input()
2242 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2244 initCursor(0, IMG_MENU_BUTTON);
2245 initCursor(1, IMG_MENU_BUTTON);
2246 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2247 initCursor(13, IMG_MENU_BUTTON_LEFT);
2249 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2250 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2252 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2253 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2254 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2257 DeactivateJoystickForCalibration();
2258 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2259 "Joysticks deactivated on this screen");
2262 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2267 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2269 if (device_name == NULL)
2272 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2275 if (strlen(device_name) > 1)
2277 char c1 = device_name[strlen(device_name) - 1];
2278 char c2 = device_name[strlen(device_name) - 2];
2280 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2281 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2284 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2285 strlen(device_name));
2288 static void drawPlayerSetupInputInfo(int player_nr)
2291 static struct SetupKeyboardInfo custom_key;
2298 { &custom_key.left, "Joystick Left" },
2299 { &custom_key.right, "Joystick Right" },
2300 { &custom_key.up, "Joystick Up" },
2301 { &custom_key.down, "Joystick Down" },
2302 { &custom_key.snap, "Button 1" },
2303 { &custom_key.bomb, "Button 2" }
2305 static char *joystick_name[MAX_PLAYERS] =
2313 custom_key = setup.input[player_nr].key;
2315 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr + 1, 1), FONT_INPUT_ACTIVE);
2317 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2318 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2320 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2323 if (setup.input[player_nr].use_joystick)
2325 char *device_name = setup.input[player_nr].joy.device_name;
2327 DrawText(mSX+8*32, mSY+3*32,
2328 joystick_name[getJoystickNrFromDeviceName(device_name)],
2330 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2334 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2335 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2338 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2339 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2340 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2341 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2342 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2343 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2344 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2345 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2346 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2347 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2348 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2352 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2354 DrawText(mSX + 3*32, mSY + ypos*32,
2356 DrawText(mSX + 3*32, mSY + ypos*32,
2357 (setup.input[player_nr].use_joystick ?
2359 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2363 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2365 static int choice = 0;
2366 static int player_nr = 0;
2369 int pos_start = SETUPINPUT_SCREEN_POS_START;
2370 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2371 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2372 int pos_end = SETUPINPUT_SCREEN_POS_END;
2374 if (button == MB_MENU_INITIALIZE)
2376 drawPlayerSetupInputInfo(player_nr);
2377 drawCursor(choice, FC_RED);
2380 else if (button == MB_MENU_LEAVE)
2382 setup_mode = SETUP_MODE_MAIN;
2387 if (mx || my) /* mouse input */
2390 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2392 else if (dx || dy) /* keyboard input */
2394 if (dx && choice == 0)
2395 x = (dx < 0 ? 10 : 12);
2396 else if ((dx && choice == 1) ||
2397 (dx == +1 && choice == 2) ||
2398 (dx == -1 && choice == pos_end))
2399 button = MB_MENU_CHOICE;
2403 if (y >= pos_empty1 && y <= pos_empty2)
2404 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2407 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2409 static unsigned long delay = 0;
2411 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2414 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2416 drawPlayerSetupInputInfo(player_nr);
2418 else if (x == 0 && y >= pos_start && y <= pos_end &&
2419 !(y >= pos_empty1 && y <= pos_empty2))
2425 drawCursor(y, FC_RED);
2426 drawCursor(choice, FC_BLUE);
2434 char *device_name = setup.input[player_nr].joy.device_name;
2436 if (!setup.input[player_nr].use_joystick)
2438 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2440 setJoystickDeviceToNr(device_name, new_device_nr);
2441 setup.input[player_nr].use_joystick = TRUE;
2445 int device_nr = getJoystickNrFromDeviceName(device_name);
2446 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2448 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2449 setup.input[player_nr].use_joystick = FALSE;
2451 setJoystickDeviceToNr(device_name, new_device_nr);
2454 drawPlayerSetupInputInfo(player_nr);
2458 if (setup.input[player_nr].use_joystick)
2461 CalibrateJoystick(player_nr);
2464 CustomizeKeyboard(player_nr);
2466 else if (y == pos_end)
2470 setup_mode = SETUP_MODE_MAIN;
2480 if (game_status == SETUP)
2484 void CustomizeKeyboard(int player_nr)
2488 boolean finished = FALSE;
2489 static struct SetupKeyboardInfo custom_key;
2494 } customize_step[] =
2496 { &custom_key.left, "Move Left" },
2497 { &custom_key.right, "Move Right" },
2498 { &custom_key.up, "Move Up" },
2499 { &custom_key.down, "Move Down" },
2500 { &custom_key.snap, "Snap Field" },
2501 { &custom_key.bomb, "Place Bomb" }
2504 /* read existing key bindings from player setup */
2505 custom_key = setup.input[player_nr].key;
2508 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2514 DrawText(mSX, mSY + (2+2*step_nr)*32,
2515 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2516 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2517 "Key:", FONT_INPUT_ACTIVE);
2518 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2519 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2523 if (PendingEvent()) /* got event */
2531 case EVENT_KEYPRESS:
2533 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2535 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2541 /* all keys configured -- wait for "Escape" or "Return" key */
2545 /* press 'Enter' to keep the existing key binding */
2546 if (key == KSYM_Return)
2547 key = *customize_step[step_nr].key;
2549 /* check if key already used */
2550 for (i=0; i<step_nr; i++)
2551 if (*customize_step[i].key == key)
2556 /* got new key binding */
2557 *customize_step[step_nr].key = key;
2558 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2560 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2561 getKeyNameFromKey(key), FONT_VALUE_1);
2564 /* un-highlight last query */
2565 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2566 customize_step[step_nr-1].text, FONT_MENU_1);
2567 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2568 "Key:", FONT_MENU_1);
2570 /* press 'Enter' to leave */
2573 DrawText(mSX + 16, mSY + 15*32+16,
2574 "Press Enter", FONT_TITLE_1);
2578 /* query next key binding */
2579 DrawText(mSX, mSY+(2+2*step_nr)*32,
2580 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2581 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2582 "Key:", FONT_INPUT_ACTIVE);
2583 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2584 getKeyNameFromKey(*customize_step[step_nr].key),
2589 case EVENT_KEYRELEASE:
2590 key_joystick_mapping = 0;
2594 HandleOtherEvents(&event);
2602 /* don't eat all CPU time */
2606 /* write new key bindings back to player setup */
2607 setup.input[player_nr].key = custom_key;
2610 DrawSetupScreen_Input();
2613 static boolean CalibrateJoystickMain(int player_nr)
2615 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2616 int new_joystick_xright = JOYSTICK_XMIDDLE;
2617 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2618 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2619 int new_joystick_xmiddle, new_joystick_ymiddle;
2621 int joystick_fd = joystick.fd[player_nr];
2622 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2623 boolean check[3][3];
2624 int check_remaining = 3 * 3;
2629 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2632 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2637 for(y=0; y < 3; y++)
2639 for(x=0; x < 3; x++)
2641 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2642 check[x][y] = FALSE;
2646 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2647 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2648 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2649 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2650 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2651 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2652 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2654 joy_value = Joystick(player_nr);
2655 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2656 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2658 /* eventually uncalibrated center position (joystick could be uncentered) */
2659 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2662 new_joystick_xmiddle = joy_x;
2663 new_joystick_ymiddle = joy_y;
2665 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2668 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2673 if (PendingEvent()) /* got event */
2681 case EVENT_KEYPRESS:
2682 switch(GetEventKey((KeyEvent *)&event, TRUE))
2685 if (check_remaining == 0)
2698 case EVENT_KEYRELEASE:
2699 key_joystick_mapping = 0;
2703 HandleOtherEvents(&event);
2708 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2711 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2712 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2713 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2714 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2716 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2717 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2718 setup.input[player_nr].joy.xright = new_joystick_xright;
2719 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2720 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2721 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2723 CheckJoystickData();
2725 joy_value = Joystick(player_nr);
2727 if (joy_value & JOY_BUTTON && check_remaining == 0)
2730 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2731 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2733 if (x != last_x || y != last_y)
2735 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2736 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2741 if (check_remaining > 0 && !check[x+1][y+1])
2743 check[x+1][y+1] = TRUE;
2749 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2750 setup.input[player_nr].joy.xleft,
2751 setup.input[player_nr].joy.xmiddle,
2752 setup.input[player_nr].joy.xright);
2753 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2754 setup.input[player_nr].joy.yupper,
2755 setup.input[player_nr].joy.ymiddle,
2756 setup.input[player_nr].joy.ylower);
2765 /* don't eat all CPU time */
2769 /* calibrated center position (joystick should now be centered) */
2770 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2773 new_joystick_xmiddle = joy_x;
2774 new_joystick_ymiddle = joy_y;
2778 DrawSetupScreen_Input();
2780 /* wait until the last pressed button was released */
2781 while (Joystick(player_nr) & JOY_BUTTON)
2783 if (PendingEvent()) /* got event */
2788 HandleOtherEvents(&event);
2797 void CalibrateJoystick(int player_nr)
2799 if (!CalibrateJoystickMain(player_nr))
2803 DrawText(mSX + 16, mSY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2804 DrawText(mSX, mSY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2806 Delay(2000); /* show error message for two seconds */
2810 void DrawSetupScreen()
2812 DeactivateJoystick();
2814 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2816 if (setup_mode == SETUP_MODE_INPUT)
2817 DrawSetupScreen_Input();
2818 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2819 DrawChooseTree(&artwork.gfx_current);
2820 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2821 DrawChooseTree(&artwork.snd_current);
2822 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2823 DrawChooseTree(&artwork.mus_current);
2825 DrawSetupScreen_Generic();
2828 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2830 if (setup_mode == SETUP_MODE_INPUT)
2831 HandleSetupScreen_Input(mx, my, dx, dy, button);
2832 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2833 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2834 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2835 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2836 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2837 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2839 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2842 void HandleGameActions()
2844 if (game_status != PLAYING)
2847 if (local_player->LevelSolved)
2850 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2858 /* ---------- new screen button stuff -------------------------------------- */
2860 /* graphic position and size values for buttons and scrollbars */
2861 #define SC_SCROLLBUTTON_XSIZE 32
2862 #define SC_SCROLLBUTTON_YSIZE 32
2864 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2865 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2866 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2867 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2868 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2869 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2870 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2871 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2873 #define SC_BORDER_SIZE 14
2877 int gfx_unpressed, gfx_pressed;
2881 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2884 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2885 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2886 SCREEN_CTRL_ID_SCROLL_UP,
2890 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2891 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2892 SCREEN_CTRL_ID_SCROLL_DOWN,
2899 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2900 Bitmap **gfx_unpressed, **gfx_pressed;
2902 int gfx_unpressed, gfx_pressed;
2909 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2912 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2913 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2915 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2917 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2918 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2919 GD_TYPE_SCROLLBAR_VERTICAL,
2920 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2921 "scroll level series vertically"
2925 static void CreateScreenScrollbuttons()
2927 struct GadgetInfo *gi;
2928 unsigned long event_mask;
2931 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2933 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2934 int gfx_unpressed, gfx_pressed;
2935 int x, y, width, height;
2936 int gd_x1, gd_x2, gd_y1, gd_y2;
2937 int id = scrollbutton_info[i].gadget_id;
2939 x = scrollbutton_info[i].x;
2940 y = scrollbutton_info[i].y;
2942 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2946 width = SC_SCROLLBUTTON_XSIZE;
2947 height = SC_SCROLLBUTTON_YSIZE;
2949 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2950 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2951 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2952 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2953 gd_x1 = graphic_info[gfx_unpressed].src_x;
2954 gd_y1 = graphic_info[gfx_unpressed].src_y;
2955 gd_x2 = graphic_info[gfx_pressed].src_x;
2956 gd_y2 = graphic_info[gfx_pressed].src_y;
2958 gi = CreateGadget(GDI_CUSTOM_ID, id,
2959 GDI_CUSTOM_TYPE_ID, i,
2960 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2965 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2966 GDI_STATE, GD_BUTTON_UNPRESSED,
2967 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2968 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2969 GDI_EVENT_MASK, event_mask,
2970 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2974 Error(ERR_EXIT, "cannot create gadget");
2976 screen_gadget[id] = gi;
2980 static void CreateScreenScrollbars()
2984 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2986 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2987 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2988 int gfx_unpressed, gfx_pressed;
2990 int gd_x1, gd_x2, gd_y1, gd_y2;
2991 struct GadgetInfo *gi;
2992 int items_max, items_visible, item_position;
2993 unsigned long event_mask;
2994 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2995 int id = scrollbar_info[i].gadget_id;
2997 items_max = num_page_entries;
2998 items_visible = num_page_entries;
3001 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3003 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3004 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3005 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3011 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3012 gfx_pressed = scrollbar_info[i].gfx_pressed;
3013 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3014 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3015 gd_x1 = graphic_info[gfx_unpressed].src_x;
3016 gd_y1 = graphic_info[gfx_unpressed].src_y;
3017 gd_x2 = graphic_info[gfx_pressed].src_x;
3018 gd_y2 = graphic_info[gfx_pressed].src_y;
3021 gi = CreateGadget(GDI_CUSTOM_ID, id,
3022 GDI_CUSTOM_TYPE_ID, i,
3023 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3024 GDI_X, scrollbar_info[i].x,
3025 GDI_Y, scrollbar_info[i].y,
3026 GDI_WIDTH, scrollbar_info[i].width,
3027 GDI_HEIGHT, scrollbar_info[i].height,
3028 GDI_TYPE, scrollbar_info[i].type,
3029 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3030 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3031 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3032 GDI_STATE, GD_BUTTON_UNPRESSED,
3033 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3034 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3035 GDI_BORDER_SIZE, SC_BORDER_SIZE,
3036 GDI_EVENT_MASK, event_mask,
3037 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3041 Error(ERR_EXIT, "cannot create gadget");
3043 screen_gadget[id] = gi;
3047 void CreateScreenGadgets()
3049 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3052 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3054 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3056 /* copy pointers to clip mask and GC */
3057 scrollbar_bitmap[i]->clip_mask =
3058 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3059 scrollbar_bitmap[i]->stored_clip_gc =
3060 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3062 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3063 scrollbar_bitmap[i],
3064 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3065 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3066 TILEX, TILEY, 0, 0);
3070 CreateScreenScrollbuttons();
3071 CreateScreenScrollbars();
3074 void FreeScreenGadgets()
3078 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3079 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3081 /* prevent freeing clip mask and GC twice */
3082 scrollbar_bitmap[i]->clip_mask = None;
3083 scrollbar_bitmap[i]->stored_clip_gc = None;
3085 FreeBitmap(scrollbar_bitmap[i]);
3089 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3090 FreeGadget(screen_gadget[i]);
3093 void MapChooseTreeGadgets(TreeInfo *ti)
3095 int num_entries = numTreeInfoInGroup(ti);
3098 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
3101 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3102 MapGadget(screen_gadget[i]);
3105 void UnmapChooseTreeGadgets()
3109 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3110 UnmapGadget(screen_gadget[i]);
3113 static void HandleScreenGadgets(struct GadgetInfo *gi)
3115 int id = gi->custom_id;
3117 if (game_status != CHOOSELEVEL && game_status != SETUP)
3122 case SCREEN_CTRL_ID_SCROLL_UP:
3123 if (game_status == CHOOSELEVEL)
3124 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3125 else if (game_status == SETUP)
3126 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3129 case SCREEN_CTRL_ID_SCROLL_DOWN:
3130 if (game_status == CHOOSELEVEL)
3131 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3132 else if (game_status == SETUP)
3133 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3136 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3137 if (game_status == CHOOSELEVEL)
3138 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3139 else if (game_status == SETUP)
3140 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);