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();
202 SetMouseCursor(CURSOR_DEFAULT);
204 SetDrawDeactivationMask(REDRAW_NONE);
205 SetDrawBackgroundMask(REDRAW_FIELD);
207 audio.sound_deactivated = FALSE;
209 /* needed if last screen was the playing screen, invoked from level editor */
210 if (level_editor_test_game)
212 game_status = LEVELED;
217 /* needed if last screen was the editor screen */
218 UndrawSpecialEditorDoor();
220 /* needed if last screen was the setup screen and fullscreen state changed */
221 ToggleFullscreenIfNeeded();
223 /* needed if last screen (level choice) changed graphics, sounds or music */
224 ReloadCustomArtwork();
227 SetDrawtoField(DRAW_BACKBUFFER);
230 /* map gadgets for main menu screen */
233 /* leveldir_current may be invalid (level group, parent link) */
234 if (!validLevelSeries(leveldir_current))
235 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
237 /* store valid level series information */
238 leveldir_last_valid = leveldir_current;
240 /* level_nr may have been set to value over handicap with level editor */
241 if (setup.handicap && level_nr > leveldir_current->handicap_level)
242 level_nr = leveldir_current->handicap_level;
247 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
252 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
253 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
254 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
255 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
256 DrawText(mSY + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
257 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
258 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
259 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
261 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT);
262 DrawText(mSX + level_width + 5 * 32, mSY + 3*32, int2str(level_nr,3),
265 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
267 DrawTextF(mSX + 32 + level_width - 2, mSY + 3*32 + 1, FONT_TEXT_3, "%d-%d",
268 leveldir_current->first_level, leveldir_current->last_level);
271 if (leveldir_current->readonly)
274 DrawTextF(mSX + level_width + 9*32 - 2,
275 mSY + 3*32 + 1 - 7, FONT_TEXT_3, "READ");
276 DrawTextF(mSX + level_width + 9*32 - 2,
277 mSY + 3*32 + 1 + 7, FONT_TEXT_3, "ONLY");
281 initCursor(i, (i == 1 || i == 6 ? IMG_MENU_BUTTON_RIGHT :IMG_MENU_BUTTON));
283 drawCursorXY(level_width/32 + 4, 1, IMG_MENU_BUTTON_LEFT);
284 drawCursorXY(level_width/32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
286 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment", FONT_TITLE_2);
290 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
293 if (TAPE_IS_EMPTY(tape))
295 DrawCompleteVideoDisplay();
297 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
304 static void gotoTopLevelDir()
306 /* move upwards to top level directory */
307 while (leveldir_current->node_parent)
309 /* write a "path" into level tree for easy navigation to last level */
310 if (leveldir_current->node_parent->node_group->cl_first == -1)
312 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
313 int leveldir_pos = posTreeInfo(leveldir_current);
314 int num_page_entries;
315 int cl_first, cl_cursor;
317 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
318 num_page_entries = num_leveldirs;
320 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
322 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
323 cl_cursor = leveldir_pos - cl_first;
325 leveldir_current->node_parent->node_group->cl_first = cl_first;
326 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
329 leveldir_current = leveldir_current->node_parent;
333 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
335 static int choice = 0;
339 if (button == MB_MENU_INITIALIZE)
341 drawCursor(choice, FC_RED);
345 if (mx || my) /* mouse input */
348 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
350 else if (dx || dy) /* keyboard input */
352 if (dx && choice == 1)
353 x = (dx < 0 ? 10 : 14);
358 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
359 (x == 14 && level_nr < leveldir_current->last_level)) &&
362 static unsigned long level_delay = 0;
363 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
364 int new_level_nr, old_level_nr = level_nr;
366 new_level_nr = level_nr + (x == 10 ? -step : +step);
367 if (new_level_nr < leveldir_current->first_level)
368 new_level_nr = leveldir_current->first_level;
369 if (new_level_nr > leveldir_current->last_level)
370 new_level_nr = leveldir_current->last_level;
372 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
373 new_level_nr = leveldir_current->handicap_level;
375 if (old_level_nr == new_level_nr ||
376 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
379 level_nr = new_level_nr;
381 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
384 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
388 DrawCompleteVideoDisplay();
390 /* needed because DrawMicroLevel() takes some time */
393 DelayReached(&level_delay, 0); /* reset delay counter */
395 else if (x == 0 && y >= 0 && y <= 7)
401 drawCursor(y, FC_RED);
402 drawCursor(choice, FC_BLUE);
410 game_status = TYPENAME;
411 HandleTypeName(strlen(setup.player_name), 0);
417 game_status = CHOOSELEVEL;
418 SaveLevelSetup_LastSeries();
419 SaveLevelSetup_SeriesInfo();
428 game_status = HALLOFFAME;
433 if (leveldir_current->readonly &&
434 strcmp(setup.player_name, "Artsoft") != 0)
435 Request("This level is read only !", REQ_CONFIRM);
436 game_status = LEVELED;
441 game_status = HELPSCREEN;
446 if (setup.autorecord)
447 TapeStartRecording();
449 #if defined(PLATFORM_UNIX)
451 SendToServer_StartPlaying();
455 game_status = PLAYING;
463 setup_mode = SETUP_MODE_MAIN;
468 SaveLevelSetup_LastSeries();
469 SaveLevelSetup_SeriesInfo();
470 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
471 game_status = EXITGAME;
480 if (game_status == MAINMENU)
482 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
488 #define MAX_HELPSCREEN_ELS 10
492 static long helpscreen_state;
493 static int helpscreen_step[MAX_HELPSCREEN_ELS];
494 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
496 static int OLD_helpscreen_action[] =
498 GFX_SPIELER1_DOWN,4,2,
500 GFX_SPIELER1_LEFT,4,2,
501 GFX_SPIELER1_RIGHT,4,2,
502 GFX_SPIELER1_PUSH_LEFT,4,2,
503 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
504 GFX_ERDREICH,1,100, HA_NEXT,
505 GFX_LEERRAUM,1,100, HA_NEXT,
506 GFX_MORAST_LEER,1,100, HA_NEXT,
507 GFX_BETON,1,100, HA_NEXT,
508 GFX_MAUERWERK,1,100, HA_NEXT,
509 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
510 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
511 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
512 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
513 GFX_UNSICHTBAR,1,100, HA_NEXT,
514 GFX_FELSBODEN,1,100, HA_NEXT,
515 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
516 GFX_EDELSTEIN,2,5, HA_NEXT,
517 GFX_DIAMANT,2,5, HA_NEXT,
518 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
519 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
520 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
521 GFX_FELSBROCKEN,4,5, HA_NEXT,
522 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
523 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
524 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
525 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
526 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
527 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
528 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
529 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
530 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
531 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
532 GFX_GEBLUBBER,4,4, HA_NEXT,
533 GFX_SCHLUESSEL1,4,25, HA_NEXT,
534 GFX_PFORTE1,4,25, HA_NEXT,
535 GFX_PFORTE1X,4,25, HA_NEXT,
536 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
537 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
538 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
539 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
540 GFX_LEERRAUM,1,10, HA_NEXT,
541 GFX_DYNABOMB_NR,1,100, HA_NEXT,
542 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
543 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
544 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
545 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
546 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
547 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
548 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
549 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
550 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
551 GFX_BUTTERFLY,2,2, HA_NEXT,
552 GFX_FIREFLY,2,2, HA_NEXT,
553 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
554 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
555 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
556 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
557 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
558 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
559 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
560 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
561 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
562 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
566 GFX_MOLE_RIGHT,4,2, HA_NEXT,
567 GFX_PINGUIN_DOWN,4,2,
569 GFX_PINGUIN_LEFT,4,2,
570 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
571 GFX_SCHWEIN_DOWN,4,2,
573 GFX_SCHWEIN_LEFT,4,2,
574 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
578 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
579 GFX_SONDE_START,8,1, HA_NEXT,
580 GFX_ABLENK,4,1, HA_NEXT,
581 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
582 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
583 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
584 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
585 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
586 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
587 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
588 GFX_DIAMANT,1,10, HA_NEXT,
589 GFX_LIFE,1,100, HA_NEXT,
590 GFX_LIFE_ASYNC,1,100, HA_NEXT,
591 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
592 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
593 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
594 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
595 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
596 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
597 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
598 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
599 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
600 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
601 GFX_SPEED_PILL,1,100, HA_NEXT,
606 static int helpscreen_action[] =
608 IMG_PLAYER_1_MOVING_DOWN, 16,
609 IMG_PLAYER_1_MOVING_UP, 16,
610 IMG_PLAYER_1_MOVING_LEFT, 16,
611 IMG_PLAYER_1_MOVING_RIGHT, 16,
612 IMG_PLAYER_1_PUSHING_LEFT, 16,
613 IMG_PLAYER_1_PUSHING_RIGHT, 16, HA_NEXT,
615 IMG_SAND, -1, HA_NEXT,
617 IMG_EMPTY_SPACE, -1, HA_NEXT,
619 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
621 IMG_STEELWALL, -1, HA_NEXT,
623 IMG_WALL, -1, HA_NEXT,
625 IMG_EXPANDABLE_WALL_GROWING_LEFT, 20,
628 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 20,
631 IMG_EXPANDABLE_WALL_GROWING_UP, 20,
634 IMG_EXPANDABLE_WALL_GROWING_DOWN, 20,
636 IMG_EMPTY_SPACE, 20, HA_NEXT,
638 IMG_INVISIBLE_WALL, -1, HA_NEXT,
640 IMG_WALL_CRUMBLED, -1, HA_NEXT,
642 IMG_INFO_FONT_EM_1, 160,
643 IMG_INFO_FONT_EM_2, 160,
644 IMG_INFO_FONT_EM_3, 160,
645 IMG_INFO_FONT_EM_4, 160,
646 IMG_INFO_FONT_EM_5, 40, HA_NEXT,
648 IMG_EMERALD, -1, HA_NEXT,
650 IMG_DIAMOND, -1, HA_NEXT,
652 IMG_BD_DIAMOND, -1, HA_NEXT,
654 IMG_EMERALD_YELLOW, 50,
656 IMG_EMERALD_PURPLE, 50, HA_NEXT,
658 IMG_BD_ROCK, -1, HA_NEXT,
662 IMG_EMPTY_SPACE, 10, HA_NEXT,
666 IMG_EMERALD, 20, HA_NEXT,
668 IMG_WALL_EMERALD, 100,
670 IMG_EMERALD, 20, HA_NEXT,
672 IMG_WALL_DIAMOND, 100,
674 IMG_DIAMOND, 20, HA_NEXT,
676 IMG_WALL_BD_DIAMOND, 100,
678 IMG_BD_DIAMOND, 20, HA_NEXT,
680 IMG_WALL_EMERALD_YELLOW, 100,
682 IMG_EMERALD_YELLOW, 20,
683 IMG_WALL_EMERALD_RED, 100,
686 IMG_WALL_EMERALD_PURPLE, 100,
688 IMG_EMERALD_PURPLE, 20, HA_NEXT,
690 IMG_ACID, -1, HA_NEXT,
695 IMG_KEY_4, 50, HA_NEXT,
700 IMG_GATE_4, 50, HA_NEXT,
705 IMG_GATE_4_GRAY, 50, HA_NEXT,
707 IMG_DYNAMITE, -1, HA_NEXT,
709 IMG_DYNAMITE_ACTIVE, 96,
711 IMG_EMPTY_SPACE, 20, HA_NEXT,
713 IMG_DYNABOMB_ACTIVE, 100,
715 IMG_EMPTY_SPACE, 20, HA_NEXT,
717 EL_DYNABOMB_INCREASE_NUMBER, -1, HA_NEXT,
719 EL_DYNABOMB_INCREASE_SIZE, -1, HA_NEXT,
721 IMG_SPACESHIP_RIGHT, 16,
722 IMG_SPACESHIP_UP, 16,
723 IMG_SPACESHIP_LEFT, 16,
724 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
729 IMG_BUG_DOWN, 16, HA_NEXT,
731 IMG_BD_BUTTERFLY, -1, HA_NEXT,
733 IMG_BD_FIREFLY, -1, HA_NEXT,
735 IMG_PACMAN_RIGHT, 16,
738 IMG_PACMAN_DOWN, 16, HA_NEXT,
740 IMG_YAMYAM, -1, HA_NEXT,
742 IMG_DARK_YAMYAM, -1, HA_NEXT,
744 IMG_ROBOT, -1, HA_NEXT,
746 IMG_MOLE_MOVING_RIGHT, 16,
747 IMG_MOLE_MOVING_UP, 16,
748 IMG_MOLE_MOVING_LEFT, 16,
749 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
751 IMG_PENGUIN_MOVING_RIGHT, 16,
752 IMG_PENGUIN_MOVING_UP, 16,
753 IMG_PENGUIN_MOVING_LEFT, 16,
754 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
756 IMG_PIG_MOVING_RIGHT, 16,
757 IMG_PIG_MOVING_UP, 16,
758 IMG_PIG_MOVING_LEFT, 16,
759 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
761 IMG_DRAGON_MOVING_RIGHT, 16,
762 IMG_DRAGON_MOVING_UP, 16,
763 IMG_DRAGON_MOVING_LEFT, 16,
764 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
766 IMG_SATELLITE, -1, HA_NEXT,
769 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
772 IMG_LAMP_ACTIVE, 50, HA_NEXT,
774 IMG_TIME_ORB_FULL, 50,
775 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
778 IMG_AMOEBA_GROWING, 6,
779 IMG_AMOEBA_WET, 20, HA_NEXT,
781 IMG_AMOEBA_DEAD, -1, HA_NEXT,
783 IMG_AMOEBA_WET, -1, HA_NEXT,
786 IMG_AMOEBA_GROWING, 6, HA_NEXT,
791 IMG_DIAMOND, 20, HA_NEXT,
793 IMG_GAME_OF_LIFE, -1, HA_NEXT,
795 IMG_BIOMAZE, -1, HA_NEXT,
797 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
799 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
801 IMG_EXIT_CLOSED, 200,
802 IMG_EXIT_OPENING, 16,
803 IMG_EXIT_OPEN, 100, HA_NEXT,
805 IMG_EXIT_OPEN, -1, HA_NEXT,
807 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
809 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
811 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
813 IMG_SPEED_PILL, -1, HA_NEXT,
817 static char *helpscreen_eltext[][2] =
819 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
820 {"Normal sand:", "You can dig through it"},
821 {"Empty field:", "You can walk through it"},
822 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
823 {"Massive Wall:", "Nothing can go through it"},
824 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
825 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
826 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
827 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
828 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
829 {"Emerald: You must collect enough of","them to finish a level"},
830 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
831 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
832 {"Colorful Gems:", "Seem to behave like Emeralds"},
833 {"Rock: Smashes several things;", "Can be moved by the player"},
834 {"Bomb: You can move it, but be", "careful when dropping it"},
835 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
836 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
837 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
838 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
839 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
840 {"Acid: Things that fall in are gone", "forever (including our hero)"},
841 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
842 {"Door: Can be opened by the key", "with the same color"},
843 {"Door: You have to find out the", "right color of the key for it"},
844 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
845 {"Dynamite: This one explodes after", "a few seconds"},
846 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
847 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
848 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
849 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
850 {"Bug: Moves at the right side", "of walls; don't touch it!"},
851 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
852 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
853 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
854 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
855 {"Cruncher (BD style):", "Eats almost everything"},
856 {"Robot: Tries to kill the player", ""},
857 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
858 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
859 {"The Pig: Harmless, but eats all", "gems it can get"},
860 {"The Dragon: Breathes fire,", "especially to some monsters"},
861 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
862 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
863 {"Light Bulb: All of them must be", "switched on to finish a level"},
864 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
865 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
866 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
867 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
868 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
869 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
870 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
871 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
872 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
873 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
874 {"Exit door: Opens if you have enough","emeralds to finish the level"},
875 {"Open exit door: Enter here to leave","the level and exit the actual game"},
876 {"Sokoban element: Object which must", "be pushed to an empty field"},
877 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
878 {"Sokoban element: Field with object", "which can be pushed away"},
879 {"Speed pill: Lets the player run", "twice as fast as normally"},
881 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
883 static char *helpscreen_music[][3] =
885 { "Alchemy", "Ian Boddy", "Drive" },
886 { "The Chase", "Propaganda", "A Secret Wish" },
887 { "Network 23", "Tangerine Dream", "Exit" },
888 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
889 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
890 { "Voyager", "The Alan Parsons Project","Pyramid" },
891 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
893 static int num_helpscreen_music = 7;
894 static int helpscreen_musicpos;
897 void OLD_DrawHelpScreenElAction(int start)
901 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
903 while(helpscreen_action[j] != HA_END)
905 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
907 else if (i<start || helpscreen_delay[i-start])
909 if (i>=start && helpscreen_delay[i-start])
910 helpscreen_delay[i-start]--;
912 while(helpscreen_action[j] != HA_NEXT)
919 j += 3*helpscreen_step[i-start];
920 graphic = helpscreen_action[j++];
922 if (helpscreen_frame[i-start])
924 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
925 helpscreen_frame[i-start]--;
930 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
933 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
935 if (helpscreen_action[j] == HA_NEXT)
937 if (!helpscreen_frame[i-start])
938 helpscreen_step[i-start] = 0;
942 if (!helpscreen_frame[i-start])
943 helpscreen_step[i-start]++;
944 while(helpscreen_action[j] != HA_NEXT)
949 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
961 void DrawHelpScreenElAction(int start)
964 int xstart = mSX + 16;
965 int ystart = mSY + 64 + 2 * 32;
966 int ystep = TILEY + 4;
972 while (helpscreen_action[j] != HA_END)
974 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
978 while (helpscreen_action[j] != HA_NEXT)
987 j += 2 * helpscreen_step[i-start];
988 graphic = helpscreen_action[j++];
989 frame_count = helpscreen_action[j++];
990 if (frame_count == -1)
991 frame_count = 1000000;
993 if (helpscreen_frame[i-start] == 0)
996 helpscreen_frame[i-start] = frame_count - 1;
1000 sync_frame = frame_count - helpscreen_frame[i-start];
1001 helpscreen_frame[i-start]--;
1004 if (helpscreen_action[j] == HA_NEXT)
1006 if (!helpscreen_frame[i-start])
1007 helpscreen_step[i-start] = 0;
1011 if (!helpscreen_frame[i-start])
1012 helpscreen_step[i-start]++;
1013 while(helpscreen_action[j] != HA_NEXT)
1018 frame = getGraphicAnimationFrame(graphic, sync_frame);
1020 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
1028 MarkTileDirty(0, i);
1029 MarkTileDirty(1, i);
1035 void DrawHelpScreenElText(int start)
1038 int xstart = mSX + 56, ystart = mSY + 65 + 2 * 32, ystep = TILEY + 4;
1039 int ybottom = SYSIZE - 20;
1041 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1045 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
1047 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1050 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1051 helpscreen_eltext[i][0], FONT_TEXT_2);
1052 DrawText(xstart, ystart + (i - start) * ystep + 16,
1053 helpscreen_eltext[i][1], FONT_TEXT_2);
1056 DrawTextFCentered(ybottom, FONT_TEXT_4,
1057 "Press any key or button for next page");
1060 void DrawHelpScreenMusicText(int num)
1062 int ystart = 150, ystep = 30;
1063 int ybottom = SYSIZE - 20;
1069 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
1071 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
1072 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
1073 "\"%s\"", helpscreen_music[num][0]);
1074 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
1075 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
1076 "%s", helpscreen_music[num][1]);
1077 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1078 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
1079 "\"%s\"", helpscreen_music[num][2]);
1081 DrawTextFCentered(ybottom, FONT_TEXT_4,
1082 "Press any key or button for next page");
1085 PlaySoundLoop(background_loop[num]);
1089 void DrawHelpScreenCreditsText()
1091 int ystart = 150, ystep = 30;
1092 int ybottom = SYSIZE - 20;
1098 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
1099 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1100 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1101 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1102 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1103 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
1104 "...and many thanks to all contributors");
1105 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1107 DrawTextFCentered(ybottom, FONT_TEXT_4,
1108 "Press any key or button for next page");
1111 void DrawHelpScreenContactText()
1113 int ystart = 150, ystep = 30;
1114 int ybottom = SYSIZE - 20;
1119 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1121 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1122 "This game is Freeware!");
1123 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1124 "If you like it, send e-mail to:");
1125 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1126 "info@artsoft.org");
1127 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1128 "or SnailMail to:");
1129 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1131 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1132 "Detmolder Strasse 189");
1133 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1135 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1138 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1139 "If you have created new levels,");
1140 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1141 "send them to me to include them!");
1142 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1145 DrawTextFCentered(ybottom, FONT_TEXT_4,
1146 "Press any key or button for main menu");
1149 void DrawHelpScreen()
1154 CloseDoor(DOOR_CLOSE_2);
1156 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1157 helpscreen_step[i] = helpscreen_frame[i] = 0;
1158 helpscreen_musicpos = 0;
1159 helpscreen_state = 0;
1161 DrawHelpScreenElText(0);
1162 DrawHelpScreenElAction(0);
1168 PlaySoundLoop(SND_BACKGROUND_INFO);
1170 PlaySound_Menu_Start(SND_BACKGROUND_INFO);
1174 void HandleHelpScreen(int button)
1176 static unsigned long hs_delay = 0;
1177 int num_helpscreen_els_pages =
1178 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1179 int button_released = !button;
1182 if (button_released)
1184 if (helpscreen_state < num_helpscreen_els_pages - 1)
1186 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1187 helpscreen_step[i] = helpscreen_frame[i] = 0;
1191 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1192 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1194 else if (helpscreen_state <
1195 num_helpscreen_els_pages + num_helpscreen_music - 1)
1198 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1200 else if (helpscreen_state ==
1201 num_helpscreen_els_pages + num_helpscreen_music - 1)
1204 DrawHelpScreenCreditsText();
1206 else if (helpscreen_state ==
1207 num_helpscreen_els_pages + num_helpscreen_music)
1210 DrawHelpScreenContactText();
1216 game_status = MAINMENU;
1222 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1224 if (helpscreen_state < num_helpscreen_els_pages)
1225 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1228 /* !!! workaround for playing "music" that is really a sound loop (and
1229 must therefore periodically be reactivated with the current sound
1232 PlaySoundLoop(SND_BACKGROUND_INFO);
1234 PlaySound_Menu_Continue(SND_BACKGROUND_INFO);
1243 void HandleTypeName(int newxpos, Key key)
1245 static int xpos = 0, ypos = 2;
1246 int font_width = getFontWidth(FONT_INPUT_ACTIVE);
1247 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1248 int startx = mSX + 32 + name_width;
1249 int starty = mSY + ypos * 32;
1255 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1256 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1261 if (((key >= KSYM_A && key <= KSYM_Z) ||
1262 (key >= KSYM_a && key <= KSYM_z)) &&
1263 xpos < MAX_PLAYER_NAME_LEN)
1267 if (key >= KSYM_A && key <= KSYM_Z)
1268 ascii = 'A' + (char)(key - KSYM_A);
1270 ascii = 'a' + (char)(key - KSYM_a);
1272 setup.player_name[xpos] = ascii;
1273 setup.player_name[xpos + 1] = 0;
1276 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1277 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1279 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1282 setup.player_name[xpos] = 0;
1284 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_ACTIVE);
1286 else if (key == KSYM_Return && xpos > 0)
1288 DrawText(startx, starty, setup.player_name, FONT_INPUT);
1289 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_ACTIVE);
1292 game_status = MAINMENU;
1298 static void DrawChooseTree(TreeInfo **ti_ptr)
1301 CloseDoor(DOOR_CLOSE_2);
1305 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1306 MapChooseTreeGadgets(*ti_ptr);
1312 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1314 struct GadgetInfo *gi = screen_gadget[id];
1315 int items_max, items_visible, item_position;
1317 items_max = numTreeInfoInGroup(ti);
1318 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1319 item_position = first_entry;
1321 if (item_position > items_max - items_visible)
1322 item_position = items_max - items_visible;
1324 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1325 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1328 static void drawChooseTreeList(int first_entry, int num_page_entries,
1332 char buffer[SCR_FIELDX * 2];
1333 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1334 int num_entries = numTreeInfoInGroup(ti);
1335 char *title_string = NULL;
1336 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1337 int last_game_status = game_status; /* save current game status */
1339 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1340 redraw_mask |= REDRAW_FIELD;
1343 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1344 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1345 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1346 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1348 DrawText(SX + offset, SY + offset, title_string, FONT_TITLE_1);
1350 game_status = CHOOSELEVEL; /* force LEVELS font on artwork setup screen */
1352 for(i=0; i<num_page_entries; i++)
1354 TreeInfo *node, *node_first;
1355 int entry_pos = first_entry + i;
1356 int ypos = MENU_SCREEN_START_YPOS + i;
1358 node_first = getTreeInfoFirstGroupEntry(ti);
1359 node = getTreeInfoFromPos(node_first, entry_pos);
1361 strncpy(buffer, node->name , max_buffer_len);
1362 buffer[max_buffer_len] = '\0';
1364 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1366 if (node->parent_link)
1367 initCursor(i, IMG_MENU_BUTTON_LEFT);
1368 else if (node->level_group)
1369 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1371 initCursor(i, IMG_MENU_BUTTON);
1374 if (first_entry > 0)
1378 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1379 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_UP, 0);
1382 if (first_entry + num_page_entries < num_entries)
1384 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1386 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1387 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_DOWN, 0);
1390 game_status = last_game_status; /* restore current game status */
1393 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1395 TreeInfo *node, *node_first;
1396 int x, last_redraw_mask = redraw_mask;
1398 if (ti->type != TREE_TYPE_LEVEL_DIR)
1401 node_first = getTreeInfoFirstGroupEntry(ti);
1402 node = getTreeInfoFromPos(node_first, entry_pos);
1404 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1406 if (node->parent_link)
1407 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1409 else if (node->level_group)
1410 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1412 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1413 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1414 node->levels, node->class_desc);
1416 /* let BackToFront() redraw only what is needed */
1417 redraw_mask = last_redraw_mask | REDRAW_TILES;
1418 for (x=0; x<SCR_FIELDX; x++)
1419 MarkTileDirty(x, 1);
1422 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1425 static unsigned long choose_delay = 0;
1426 TreeInfo *ti = *ti_ptr;
1428 int y = ti->cl_cursor;
1429 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1430 int num_entries = numTreeInfoInGroup(ti);
1431 int num_page_entries;
1433 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1434 num_page_entries = num_entries;
1436 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1438 if (button == MB_MENU_INITIALIZE)
1440 int entry_pos = posTreeInfo(ti);
1442 if (ti->cl_first == -1)
1444 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1446 entry_pos - ti->cl_first;
1449 if (dx == 999) /* first entry is set by scrollbar position */
1452 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1455 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1456 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1457 drawCursor(ti->cl_cursor, FC_RED);
1460 else if (button == MB_MENU_LEAVE)
1462 if (ti->node_parent)
1464 *ti_ptr = ti->node_parent;
1465 DrawChooseTree(ti_ptr);
1467 else if (game_status == SETUP)
1473 game_status = MAINMENU;
1480 if (mx || my) /* mouse input */
1483 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1485 else if (dx || dy) /* keyboard input */
1488 y = ti->cl_cursor + dy;
1490 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1493 step = num_page_entries - 1;
1494 y = (dy < 0 ? -1 : num_page_entries);
1498 if (x == 0 && y == -1)
1500 if (ti->cl_first > 0 &&
1501 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1503 ti->cl_first -= step;
1504 if (ti->cl_first < 0)
1507 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1508 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1509 drawCursor(ti->cl_cursor, FC_RED);
1510 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1515 else if (x == 0 && y > num_page_entries - 1)
1517 if (ti->cl_first + num_page_entries < num_entries &&
1518 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1520 ti->cl_first += step;
1521 if (ti->cl_first + num_page_entries > num_entries)
1522 ti->cl_first = MAX(0, num_entries - num_page_entries);
1524 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1525 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1526 drawCursor(ti->cl_cursor, FC_RED);
1527 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1535 TreeInfo *node_first, *node_cursor;
1536 int entry_pos = ti->cl_first + y;
1538 node_first = getTreeInfoFirstGroupEntry(ti);
1539 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1541 if (node_cursor->node_group)
1543 node_cursor->cl_first = ti->cl_first;
1544 node_cursor->cl_cursor = ti->cl_cursor;
1545 *ti_ptr = node_cursor->node_group;
1546 DrawChooseTree(ti_ptr);
1550 else if (dx == -1 && ti->node_parent)
1552 *ti_ptr = ti->node_parent;
1553 DrawChooseTree(ti_ptr);
1557 if (x == 0 && y >= 0 && y < num_page_entries)
1561 if (y != ti->cl_cursor)
1563 drawCursor(y, FC_RED);
1564 drawCursor(ti->cl_cursor, FC_BLUE);
1565 drawChooseTreeInfo(ti->cl_first + y, ti);
1571 TreeInfo *node_first, *node_cursor;
1572 int entry_pos = ti->cl_first + y;
1574 node_first = getTreeInfoFirstGroupEntry(ti);
1575 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1577 if (node_cursor->node_group)
1579 node_cursor->cl_first = ti->cl_first;
1580 node_cursor->cl_cursor = ti->cl_cursor;
1581 *ti_ptr = node_cursor->node_group;
1582 DrawChooseTree(ti_ptr);
1584 else if (node_cursor->parent_link)
1586 *ti_ptr = node_cursor->node_parent;
1587 DrawChooseTree(ti_ptr);
1591 node_cursor->cl_first = ti->cl_first;
1592 node_cursor->cl_cursor = ti->cl_cursor;
1593 *ti_ptr = node_cursor;
1595 if (ti->type == TREE_TYPE_LEVEL_DIR)
1597 LoadLevelSetup_SeriesInfo();
1599 SaveLevelSetup_LastSeries();
1600 SaveLevelSetup_SeriesInfo();
1604 if (game_status == SETUP)
1610 game_status = MAINMENU;
1619 if (game_status == CHOOSELEVEL || game_status == SETUP)
1623 void DrawChooseLevel()
1625 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1627 DrawChooseTree(&leveldir_current);
1630 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1632 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1635 void DrawHallOfFame(int highlight_position)
1639 CloseDoor(DOOR_CLOSE_2);
1641 if (highlight_position < 0)
1642 LoadScore(level_nr);
1647 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1650 PlaySound(SND_BACKGROUND_SCORES);
1652 PlaySound_Menu_Start(SND_BACKGROUND_SCORES);
1656 static void drawHallOfFameList(int first_entry, int highlight_position)
1660 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1663 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1664 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1666 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1668 int entry = first_entry + i;
1670 DrawText(mSX, mSY + 64 + i * 32, "..................................",
1671 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1672 DrawText(mSX, mSY + 64 + i * 32, int2str(entry + 1, 3),
1673 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1674 DrawText(mSX + 64, mSY + 64 + i * 32, highscore[entry].Name,
1675 (entry == highlight_position ? FONT_TEXT_3 : FONT_TEXT_1));
1676 DrawText(mSX + 14 * 32 + 16, mSY + 64 + i * 32,
1677 int2str(highscore[entry].Score, 5),
1678 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1682 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1684 static int first_entry = 0;
1685 static int highlight_position = 0;
1686 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1687 int button_released = !button;
1689 if (button == MB_MENU_INITIALIZE)
1692 highlight_position = mx;
1693 drawHallOfFameList(first_entry, highlight_position);
1697 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1698 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1702 if (first_entry > 0)
1704 first_entry -= step;
1705 if (first_entry < 0)
1708 drawHallOfFameList(first_entry, highlight_position);
1714 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1716 first_entry += step;
1717 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1718 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1720 drawHallOfFameList(first_entry, highlight_position);
1725 if (button_released)
1727 FadeSound(SND_BACKGROUND_SCORES);
1728 game_status = MAINMENU;
1734 if (game_status == HALLOFFAME)
1738 PlaySound_Menu_Continue(SND_BACKGROUND_SCORES);
1744 /* ========================================================================= */
1745 /* setup screen functions */
1746 /* ========================================================================= */
1748 static struct TokenInfo *setup_info;
1749 static int num_setup_info;
1751 static char *graphics_set_name;
1752 static char *sounds_set_name;
1753 static char *music_set_name;
1755 static void execSetupMain()
1757 setup_mode = SETUP_MODE_MAIN;
1761 static void execSetupGame()
1763 setup_mode = SETUP_MODE_GAME;
1767 static void execSetupEditor()
1769 setup_mode = SETUP_MODE_EDITOR;
1773 static void execSetupGraphics()
1775 setup_mode = SETUP_MODE_GRAPHICS;
1779 static void execSetupSound()
1781 setup_mode = SETUP_MODE_SOUND;
1785 static void execSetupArtwork()
1787 /* needed if last screen (setup choice) changed graphics, sounds or music */
1788 ReloadCustomArtwork();
1790 setup.graphics_set = artwork.gfx_current->identifier;
1791 setup.sounds_set = artwork.snd_current->identifier;
1792 setup.music_set = artwork.mus_current->identifier;
1794 /* needed for displaying artwork name instead of artwork identifier */
1795 graphics_set_name = artwork.gfx_current->name;
1796 sounds_set_name = artwork.snd_current->name;
1797 music_set_name = artwork.mus_current->name;
1799 setup_mode = SETUP_MODE_ARTWORK;
1803 static void execSetupChooseGraphics()
1805 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1809 static void execSetupChooseSounds()
1811 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1815 static void execSetupChooseMusic()
1817 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1821 static void execSetupInput()
1823 setup_mode = SETUP_MODE_INPUT;
1827 static void execSetupShortcut()
1829 setup_mode = SETUP_MODE_SHORTCUT;
1833 static void execExitSetup()
1835 game_status = MAINMENU;
1839 static void execSaveAndExitSetup()
1845 static struct TokenInfo setup_info_main[] =
1847 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1848 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1849 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1850 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1851 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1852 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1853 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1854 { TYPE_EMPTY, NULL, "" },
1855 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1856 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1860 static struct TokenInfo setup_info_game[] =
1862 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1863 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1864 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1865 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1866 { TYPE_EMPTY, NULL, "" },
1867 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1871 static struct TokenInfo setup_info_editor[] =
1873 { TYPE_STRING, NULL, "Offer Special Elements:"},
1874 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1875 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1876 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1877 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1878 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1879 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1880 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1881 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1882 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1883 { TYPE_EMPTY, NULL, "" },
1884 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1888 static struct TokenInfo setup_info_graphics[] =
1890 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1891 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1892 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1894 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1895 { TYPE_SWITCH, &setup.fading, "Fading:" },
1897 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1898 { TYPE_SWITCH, &setup.toons, "Toons:" },
1899 { TYPE_EMPTY, NULL, "" },
1900 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1904 static struct TokenInfo setup_info_sound[] =
1906 { TYPE_SWITCH, &setup.sound, "Sound:", },
1907 { TYPE_EMPTY, NULL, "" },
1908 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1909 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1910 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1911 { TYPE_EMPTY, NULL, "" },
1912 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1916 static struct TokenInfo setup_info_artwork[] =
1918 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1919 { TYPE_STRING, &graphics_set_name, "" },
1920 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1921 { TYPE_STRING, &sounds_set_name, "" },
1922 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1923 { TYPE_STRING, &music_set_name, "" },
1924 { TYPE_EMPTY, NULL, "" },
1925 { TYPE_STRING, NULL, "Override Level Artwork:"},
1926 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1927 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1928 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1929 { TYPE_EMPTY, NULL, "" },
1930 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1934 static struct TokenInfo setup_info_shortcut[] =
1936 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1937 { TYPE_KEY, &setup.shortcut.save_game, "" },
1938 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1939 { TYPE_KEY, &setup.shortcut.load_game, "" },
1940 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1941 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1942 { TYPE_EMPTY, NULL, "" },
1943 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1944 { TYPE_EMPTY, NULL, "" },
1945 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1949 static Key getSetupKey()
1951 Key key = KSYM_UNDEFINED;
1952 boolean got_key_event = FALSE;
1954 while (!got_key_event)
1956 if (PendingEvent()) /* got event */
1964 case EVENT_KEYPRESS:
1966 key = GetEventKey((KeyEvent *)&event, TRUE);
1968 /* press 'Escape' or 'Enter' to keep the existing key binding */
1969 if (key == KSYM_Escape || key == KSYM_Return)
1970 key = KSYM_UNDEFINED; /* keep old value */
1972 got_key_event = TRUE;
1976 case EVENT_KEYRELEASE:
1977 key_joystick_mapping = 0;
1981 HandleOtherEvents(&event);
1989 /* don't eat all CPU time */
1996 static void drawSetupValue(int pos)
1998 int xpos = MENU_SCREEN_VALUE_XPOS;
1999 int ypos = MENU_SCREEN_START_YPOS + pos;
2000 int font_nr = FONT_VALUE_1;
2001 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
2002 setup_info[pos].value);
2004 if (value_string == NULL)
2007 if (setup_info[pos].type & TYPE_KEY)
2011 if (setup_info[pos].type & TYPE_QUERY)
2013 value_string = "<press key>";
2014 font_nr = FONT_INPUT_ACTIVE;
2017 else if (setup_info[pos].type & TYPE_STRING)
2019 int max_value_len = (SCR_FIELDX - 2) * 2;
2022 font_nr = FONT_VALUE_2;
2024 if (strlen(value_string) > max_value_len)
2025 value_string[max_value_len] = '\0';
2027 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
2028 !*(boolean *)(setup_info[pos].value))
2029 font_nr = FONT_OPTION_OFF;
2031 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2032 (xpos == 3 ? " " : " "), font_nr);
2033 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2036 static void changeSetupValue(int pos)
2038 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2040 *(boolean *)setup_info[pos].value ^= TRUE;
2042 else if (setup_info[pos].type & TYPE_KEY)
2046 setup_info[pos].type |= TYPE_QUERY;
2047 drawSetupValue(pos);
2048 setup_info[pos].type &= ~TYPE_QUERY;
2050 key = getSetupKey();
2051 if (key != KSYM_UNDEFINED)
2052 *(Key *)setup_info[pos].value = key;
2055 drawSetupValue(pos);
2058 static void DrawSetupScreen_Generic()
2060 char *title_string = NULL;
2064 CloseDoor(DOOR_CLOSE_2);
2068 if (setup_mode == SETUP_MODE_MAIN)
2070 setup_info = setup_info_main;
2071 title_string = "Setup";
2073 else if (setup_mode == SETUP_MODE_GAME)
2075 setup_info = setup_info_game;
2076 title_string = "Setup Game";
2078 else if (setup_mode == SETUP_MODE_EDITOR)
2080 setup_info = setup_info_editor;
2081 title_string = "Setup Editor";
2083 else if (setup_mode == SETUP_MODE_GRAPHICS)
2085 setup_info = setup_info_graphics;
2086 title_string = "Setup Graphics";
2088 else if (setup_mode == SETUP_MODE_SOUND)
2090 setup_info = setup_info_sound;
2091 title_string = "Setup Sound";
2093 else if (setup_mode == SETUP_MODE_ARTWORK)
2095 setup_info = setup_info_artwork;
2096 title_string = "Custom Artwork";
2098 else if (setup_mode == SETUP_MODE_SHORTCUT)
2100 setup_info = setup_info_shortcut;
2101 title_string = "Setup Shortcuts";
2104 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2107 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2109 void *value_ptr = setup_info[i].value;
2110 int ypos = MENU_SCREEN_START_YPOS + i;
2111 int font_nr = FONT_MENU_1;
2113 /* set some entries to "unchangeable" according to other variables */
2114 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2115 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2116 (value_ptr == &setup.sound_music && !audio.music_available) ||
2117 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2118 setup_info[i].type |= TYPE_GHOSTED;
2120 if (setup_info[i].type & TYPE_STRING)
2121 font_nr = FONT_MENU_2;
2123 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2125 if (setup_info[i].type & TYPE_ENTER_MENU)
2126 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2127 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2128 initCursor(i, IMG_MENU_BUTTON_LEFT);
2129 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2130 initCursor(i, IMG_MENU_BUTTON);
2132 if (setup_info[i].type & TYPE_VALUE)
2140 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2143 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2145 static int choice_store[MAX_SETUP_MODES];
2146 int choice = choice_store[setup_mode]; /* always starts with 0 */
2150 if (button == MB_MENU_INITIALIZE)
2152 /* advance to first valid menu entry */
2153 while (choice < num_setup_info &&
2154 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2156 choice_store[setup_mode] = choice;
2158 drawCursor(choice, FC_RED);
2161 else if (button == MB_MENU_LEAVE)
2163 for (y=0; y<num_setup_info; y++)
2165 if (setup_info[y].type & TYPE_LEAVE_MENU)
2167 void (*menu_callback_function)(void) = setup_info[y].value;
2169 menu_callback_function();
2170 break; /* absolutely needed because function changes 'setup_info'! */
2177 if (mx || my) /* mouse input */
2180 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2182 else if (dx || dy) /* keyboard input */
2186 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2188 if ((setup_info[choice].type & menu_navigation_type) ||
2189 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2190 button = MB_MENU_CHOICE;
2195 /* jump to next non-empty menu entry (up or down) */
2196 while (y > 0 && y < num_setup_info - 1 &&
2197 (setup_info[y].type & TYPE_SKIP_ENTRY))
2201 if (x == 0 && y >= 0 && y < num_setup_info &&
2202 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2208 drawCursor(y, FC_RED);
2209 drawCursor(choice, FC_BLUE);
2210 choice = choice_store[setup_mode] = y;
2213 else if (!(setup_info[y].type & TYPE_GHOSTED))
2215 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2217 void (*menu_callback_function)(void) = setup_info[choice].value;
2219 menu_callback_function();
2223 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2224 (setup_info[y + 1].type & TYPE_KEY))
2227 if (setup_info[y].type & TYPE_VALUE)
2228 changeSetupValue(y);
2235 if (game_status == SETUP)
2239 void DrawSetupScreen_Input()
2243 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2245 initCursor(0, IMG_MENU_BUTTON);
2246 initCursor(1, IMG_MENU_BUTTON);
2247 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2248 initCursor(13, IMG_MENU_BUTTON_LEFT);
2250 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2251 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2253 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2254 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2255 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2258 DeactivateJoystickForCalibration();
2259 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2260 "Joysticks deactivated on this screen");
2263 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2268 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2270 if (device_name == NULL)
2273 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2276 if (strlen(device_name) > 1)
2278 char c1 = device_name[strlen(device_name) - 1];
2279 char c2 = device_name[strlen(device_name) - 2];
2281 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2282 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2285 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2286 strlen(device_name));
2289 static void drawPlayerSetupInputInfo(int player_nr)
2292 static struct SetupKeyboardInfo custom_key;
2299 { &custom_key.left, "Joystick Left" },
2300 { &custom_key.right, "Joystick Right" },
2301 { &custom_key.up, "Joystick Up" },
2302 { &custom_key.down, "Joystick Down" },
2303 { &custom_key.snap, "Button 1" },
2304 { &custom_key.bomb, "Button 2" }
2306 static char *joystick_name[MAX_PLAYERS] =
2314 custom_key = setup.input[player_nr].key;
2316 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr + 1, 1), FONT_INPUT_ACTIVE);
2318 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2319 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2321 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2324 if (setup.input[player_nr].use_joystick)
2326 char *device_name = setup.input[player_nr].joy.device_name;
2328 DrawText(mSX+8*32, mSY+3*32,
2329 joystick_name[getJoystickNrFromDeviceName(device_name)],
2331 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2335 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2336 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2339 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2340 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2341 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2342 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2343 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2344 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2345 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2346 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2347 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2348 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2349 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2353 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2355 DrawText(mSX + 3*32, mSY + ypos*32,
2357 DrawText(mSX + 3*32, mSY + ypos*32,
2358 (setup.input[player_nr].use_joystick ?
2360 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2364 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2366 static int choice = 0;
2367 static int player_nr = 0;
2370 int pos_start = SETUPINPUT_SCREEN_POS_START;
2371 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2372 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2373 int pos_end = SETUPINPUT_SCREEN_POS_END;
2375 if (button == MB_MENU_INITIALIZE)
2377 drawPlayerSetupInputInfo(player_nr);
2378 drawCursor(choice, FC_RED);
2381 else if (button == MB_MENU_LEAVE)
2383 setup_mode = SETUP_MODE_MAIN;
2388 if (mx || my) /* mouse input */
2391 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2393 else if (dx || dy) /* keyboard input */
2395 if (dx && choice == 0)
2396 x = (dx < 0 ? 10 : 12);
2397 else if ((dx && choice == 1) ||
2398 (dx == +1 && choice == 2) ||
2399 (dx == -1 && choice == pos_end))
2400 button = MB_MENU_CHOICE;
2404 if (y >= pos_empty1 && y <= pos_empty2)
2405 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2408 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2410 static unsigned long delay = 0;
2412 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2415 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2417 drawPlayerSetupInputInfo(player_nr);
2419 else if (x == 0 && y >= pos_start && y <= pos_end &&
2420 !(y >= pos_empty1 && y <= pos_empty2))
2426 drawCursor(y, FC_RED);
2427 drawCursor(choice, FC_BLUE);
2435 char *device_name = setup.input[player_nr].joy.device_name;
2437 if (!setup.input[player_nr].use_joystick)
2439 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2441 setJoystickDeviceToNr(device_name, new_device_nr);
2442 setup.input[player_nr].use_joystick = TRUE;
2446 int device_nr = getJoystickNrFromDeviceName(device_name);
2447 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2449 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2450 setup.input[player_nr].use_joystick = FALSE;
2452 setJoystickDeviceToNr(device_name, new_device_nr);
2455 drawPlayerSetupInputInfo(player_nr);
2459 if (setup.input[player_nr].use_joystick)
2462 CalibrateJoystick(player_nr);
2465 CustomizeKeyboard(player_nr);
2467 else if (y == pos_end)
2471 setup_mode = SETUP_MODE_MAIN;
2481 if (game_status == SETUP)
2485 void CustomizeKeyboard(int player_nr)
2489 boolean finished = FALSE;
2490 static struct SetupKeyboardInfo custom_key;
2495 } customize_step[] =
2497 { &custom_key.left, "Move Left" },
2498 { &custom_key.right, "Move Right" },
2499 { &custom_key.up, "Move Up" },
2500 { &custom_key.down, "Move Down" },
2501 { &custom_key.snap, "Snap Field" },
2502 { &custom_key.bomb, "Place Bomb" }
2505 /* read existing key bindings from player setup */
2506 custom_key = setup.input[player_nr].key;
2509 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2515 DrawText(mSX, mSY + (2+2*step_nr)*32,
2516 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2517 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2518 "Key:", FONT_INPUT_ACTIVE);
2519 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2520 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2524 if (PendingEvent()) /* got event */
2532 case EVENT_KEYPRESS:
2534 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2536 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2542 /* all keys configured -- wait for "Escape" or "Return" key */
2546 /* press 'Enter' to keep the existing key binding */
2547 if (key == KSYM_Return)
2548 key = *customize_step[step_nr].key;
2550 /* check if key already used */
2551 for (i=0; i<step_nr; i++)
2552 if (*customize_step[i].key == key)
2557 /* got new key binding */
2558 *customize_step[step_nr].key = key;
2559 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2561 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2562 getKeyNameFromKey(key), FONT_VALUE_1);
2565 /* un-highlight last query */
2566 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2567 customize_step[step_nr-1].text, FONT_MENU_1);
2568 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2569 "Key:", FONT_MENU_1);
2571 /* press 'Enter' to leave */
2574 DrawText(mSX + 16, mSY + 15*32+16,
2575 "Press Enter", FONT_TITLE_1);
2579 /* query next key binding */
2580 DrawText(mSX, mSY+(2+2*step_nr)*32,
2581 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2582 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2583 "Key:", FONT_INPUT_ACTIVE);
2584 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2585 getKeyNameFromKey(*customize_step[step_nr].key),
2590 case EVENT_KEYRELEASE:
2591 key_joystick_mapping = 0;
2595 HandleOtherEvents(&event);
2603 /* don't eat all CPU time */
2607 /* write new key bindings back to player setup */
2608 setup.input[player_nr].key = custom_key;
2611 DrawSetupScreen_Input();
2614 static boolean CalibrateJoystickMain(int player_nr)
2616 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2617 int new_joystick_xright = JOYSTICK_XMIDDLE;
2618 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2619 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2620 int new_joystick_xmiddle, new_joystick_ymiddle;
2622 int joystick_fd = joystick.fd[player_nr];
2623 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2624 boolean check[3][3];
2625 int check_remaining = 3 * 3;
2630 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2633 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2638 for(y=0; y < 3; y++)
2640 for(x=0; x < 3; x++)
2642 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2643 check[x][y] = FALSE;
2647 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2648 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2649 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2650 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2651 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2652 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2653 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2655 joy_value = Joystick(player_nr);
2656 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2657 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2659 /* eventually uncalibrated center position (joystick could be uncentered) */
2660 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2663 new_joystick_xmiddle = joy_x;
2664 new_joystick_ymiddle = joy_y;
2666 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2669 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2674 if (PendingEvent()) /* got event */
2682 case EVENT_KEYPRESS:
2683 switch(GetEventKey((KeyEvent *)&event, TRUE))
2686 if (check_remaining == 0)
2699 case EVENT_KEYRELEASE:
2700 key_joystick_mapping = 0;
2704 HandleOtherEvents(&event);
2709 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2712 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2713 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2714 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2715 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2717 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2718 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2719 setup.input[player_nr].joy.xright = new_joystick_xright;
2720 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2721 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2722 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2724 CheckJoystickData();
2726 joy_value = Joystick(player_nr);
2728 if (joy_value & JOY_BUTTON && check_remaining == 0)
2731 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2732 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2734 if (x != last_x || y != last_y)
2736 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2737 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2742 if (check_remaining > 0 && !check[x+1][y+1])
2744 check[x+1][y+1] = TRUE;
2750 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2751 setup.input[player_nr].joy.xleft,
2752 setup.input[player_nr].joy.xmiddle,
2753 setup.input[player_nr].joy.xright);
2754 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2755 setup.input[player_nr].joy.yupper,
2756 setup.input[player_nr].joy.ymiddle,
2757 setup.input[player_nr].joy.ylower);
2766 /* don't eat all CPU time */
2770 /* calibrated center position (joystick should now be centered) */
2771 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2774 new_joystick_xmiddle = joy_x;
2775 new_joystick_ymiddle = joy_y;
2779 DrawSetupScreen_Input();
2781 /* wait until the last pressed button was released */
2782 while (Joystick(player_nr) & JOY_BUTTON)
2784 if (PendingEvent()) /* got event */
2789 HandleOtherEvents(&event);
2798 void CalibrateJoystick(int player_nr)
2800 if (!CalibrateJoystickMain(player_nr))
2804 DrawText(mSX + 16, mSY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2805 DrawText(mSX, mSY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2807 Delay(2000); /* show error message for two seconds */
2811 void DrawSetupScreen()
2813 DeactivateJoystick();
2815 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2817 if (setup_mode == SETUP_MODE_INPUT)
2818 DrawSetupScreen_Input();
2819 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2820 DrawChooseTree(&artwork.gfx_current);
2821 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2822 DrawChooseTree(&artwork.snd_current);
2823 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2824 DrawChooseTree(&artwork.mus_current);
2826 DrawSetupScreen_Generic();
2829 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2831 if (setup_mode == SETUP_MODE_INPUT)
2832 HandleSetupScreen_Input(mx, my, dx, dy, button);
2833 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2834 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2835 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2836 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2837 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2838 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2840 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2843 void HandleGameActions()
2845 if (game_status != PLAYING)
2848 if (local_player->LevelSolved)
2851 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2859 /* ---------- new screen button stuff -------------------------------------- */
2861 /* graphic position and size values for buttons and scrollbars */
2862 #define SC_SCROLLBUTTON_XSIZE 32
2863 #define SC_SCROLLBUTTON_YSIZE 32
2865 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2866 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2867 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2868 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2869 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2870 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2871 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2872 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2874 #define SC_BORDER_SIZE 14
2878 int gfx_unpressed, gfx_pressed;
2882 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2885 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2886 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2887 SCREEN_CTRL_ID_SCROLL_UP,
2891 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2892 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2893 SCREEN_CTRL_ID_SCROLL_DOWN,
2900 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2901 Bitmap **gfx_unpressed, **gfx_pressed;
2903 int gfx_unpressed, gfx_pressed;
2910 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2913 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2914 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2916 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2918 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2919 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2920 GD_TYPE_SCROLLBAR_VERTICAL,
2921 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2922 "scroll level series vertically"
2926 static void CreateScreenScrollbuttons()
2928 struct GadgetInfo *gi;
2929 unsigned long event_mask;
2932 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2934 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2935 int gfx_unpressed, gfx_pressed;
2936 int x, y, width, height;
2937 int gd_x1, gd_x2, gd_y1, gd_y2;
2938 int id = scrollbutton_info[i].gadget_id;
2940 x = scrollbutton_info[i].x;
2941 y = scrollbutton_info[i].y;
2943 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2947 width = SC_SCROLLBUTTON_XSIZE;
2948 height = SC_SCROLLBUTTON_YSIZE;
2950 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2951 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2952 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2953 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2954 gd_x1 = graphic_info[gfx_unpressed].src_x;
2955 gd_y1 = graphic_info[gfx_unpressed].src_y;
2956 gd_x2 = graphic_info[gfx_pressed].src_x;
2957 gd_y2 = graphic_info[gfx_pressed].src_y;
2959 gi = CreateGadget(GDI_CUSTOM_ID, id,
2960 GDI_CUSTOM_TYPE_ID, i,
2961 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2966 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2967 GDI_STATE, GD_BUTTON_UNPRESSED,
2968 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2969 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2970 GDI_EVENT_MASK, event_mask,
2971 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2975 Error(ERR_EXIT, "cannot create gadget");
2977 screen_gadget[id] = gi;
2981 static void CreateScreenScrollbars()
2985 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2987 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2988 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2989 int gfx_unpressed, gfx_pressed;
2991 int gd_x1, gd_x2, gd_y1, gd_y2;
2992 struct GadgetInfo *gi;
2993 int items_max, items_visible, item_position;
2994 unsigned long event_mask;
2995 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2996 int id = scrollbar_info[i].gadget_id;
2998 items_max = num_page_entries;
2999 items_visible = num_page_entries;
3002 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3004 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3005 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3006 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3012 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3013 gfx_pressed = scrollbar_info[i].gfx_pressed;
3014 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3015 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3016 gd_x1 = graphic_info[gfx_unpressed].src_x;
3017 gd_y1 = graphic_info[gfx_unpressed].src_y;
3018 gd_x2 = graphic_info[gfx_pressed].src_x;
3019 gd_y2 = graphic_info[gfx_pressed].src_y;
3022 gi = CreateGadget(GDI_CUSTOM_ID, id,
3023 GDI_CUSTOM_TYPE_ID, i,
3024 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3025 GDI_X, scrollbar_info[i].x,
3026 GDI_Y, scrollbar_info[i].y,
3027 GDI_WIDTH, scrollbar_info[i].width,
3028 GDI_HEIGHT, scrollbar_info[i].height,
3029 GDI_TYPE, scrollbar_info[i].type,
3030 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3031 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3032 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3033 GDI_STATE, GD_BUTTON_UNPRESSED,
3034 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3035 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3036 GDI_BORDER_SIZE, SC_BORDER_SIZE,
3037 GDI_EVENT_MASK, event_mask,
3038 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3042 Error(ERR_EXIT, "cannot create gadget");
3044 screen_gadget[id] = gi;
3048 void CreateScreenGadgets()
3050 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3053 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3055 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3057 /* copy pointers to clip mask and GC */
3058 scrollbar_bitmap[i]->clip_mask =
3059 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3060 scrollbar_bitmap[i]->stored_clip_gc =
3061 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3063 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3064 scrollbar_bitmap[i],
3065 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3066 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3067 TILEX, TILEY, 0, 0);
3071 CreateScreenScrollbuttons();
3072 CreateScreenScrollbars();
3075 void FreeScreenGadgets()
3079 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3080 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3082 /* prevent freeing clip mask and GC twice */
3083 scrollbar_bitmap[i]->clip_mask = None;
3084 scrollbar_bitmap[i]->stored_clip_gc = None;
3086 FreeBitmap(scrollbar_bitmap[i]);
3090 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3091 FreeGadget(screen_gadget[i]);
3094 void MapChooseTreeGadgets(TreeInfo *ti)
3096 int num_entries = numTreeInfoInGroup(ti);
3099 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
3102 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3103 MapGadget(screen_gadget[i]);
3106 void UnmapChooseTreeGadgets()
3110 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3111 UnmapGadget(screen_gadget[i]);
3114 static void HandleScreenGadgets(struct GadgetInfo *gi)
3116 int id = gi->custom_id;
3118 if (game_status != CHOOSELEVEL && game_status != SETUP)
3123 case SCREEN_CTRL_ID_SCROLL_UP:
3124 if (game_status == CHOOSELEVEL)
3125 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3126 else if (game_status == SETUP)
3127 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3130 case SCREEN_CTRL_ID_SCROLL_DOWN:
3131 if (game_status == CHOOSELEVEL)
3132 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3133 else if (game_status == SETUP)
3134 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3137 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3138 if (game_status == CHOOSELEVEL)
3139 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3140 else if (game_status == SETUP)
3141 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);