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_FONT_GAME_INFO, -1, HA_NEXT,
644 IMG_EMERALD, -1, HA_NEXT,
646 IMG_DIAMOND, -1, HA_NEXT,
648 IMG_BD_DIAMOND, -1, HA_NEXT,
650 IMG_EMERALD_YELLOW, 50,
652 IMG_EMERALD_PURPLE, 50, HA_NEXT,
654 IMG_BD_ROCK, -1, HA_NEXT,
658 IMG_EMPTY_SPACE, 10, HA_NEXT,
662 IMG_EMERALD, 20, HA_NEXT,
664 IMG_WALL_EMERALD, 100,
666 IMG_EMERALD, 20, HA_NEXT,
668 IMG_WALL_DIAMOND, 100,
670 IMG_DIAMOND, 20, HA_NEXT,
672 IMG_WALL_BD_DIAMOND, 100,
674 IMG_BD_DIAMOND, 20, HA_NEXT,
676 IMG_WALL_EMERALD_YELLOW, 100,
678 IMG_EMERALD_YELLOW, 20,
679 IMG_WALL_EMERALD_RED, 100,
682 IMG_WALL_EMERALD_PURPLE, 100,
684 IMG_EMERALD_PURPLE, 20, HA_NEXT,
686 IMG_ACID, -1, HA_NEXT,
691 IMG_KEY_4, 50, HA_NEXT,
696 IMG_GATE_4, 50, HA_NEXT,
701 IMG_GATE_4_GRAY, 50, HA_NEXT,
703 IMG_DYNAMITE, -1, HA_NEXT,
705 IMG_DYNAMITE_ACTIVE, 96,
707 IMG_EMPTY_SPACE, 20, HA_NEXT,
709 IMG_DYNABOMB_ACTIVE, 100,
711 IMG_EMPTY_SPACE, 20, HA_NEXT,
713 EL_DYNABOMB_INCREASE_NUMBER, -1, HA_NEXT,
715 EL_DYNABOMB_INCREASE_SIZE, -1, HA_NEXT,
717 IMG_SPACESHIP_RIGHT, 16,
718 IMG_SPACESHIP_UP, 16,
719 IMG_SPACESHIP_LEFT, 16,
720 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
725 IMG_BUG_DOWN, 16, HA_NEXT,
727 IMG_BD_BUTTERFLY, -1, HA_NEXT,
729 IMG_BD_FIREFLY, -1, HA_NEXT,
731 IMG_PACMAN_RIGHT, 16,
734 IMG_PACMAN_DOWN, 16, HA_NEXT,
736 IMG_YAMYAM, -1, HA_NEXT,
738 IMG_DARK_YAMYAM, -1, HA_NEXT,
740 IMG_ROBOT, -1, HA_NEXT,
742 IMG_MOLE_MOVING_RIGHT, 16,
743 IMG_MOLE_MOVING_UP, 16,
744 IMG_MOLE_MOVING_LEFT, 16,
745 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
747 IMG_PENGUIN_MOVING_RIGHT, 16,
748 IMG_PENGUIN_MOVING_UP, 16,
749 IMG_PENGUIN_MOVING_LEFT, 16,
750 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
752 IMG_PIG_MOVING_RIGHT, 16,
753 IMG_PIG_MOVING_UP, 16,
754 IMG_PIG_MOVING_LEFT, 16,
755 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
757 IMG_DRAGON_MOVING_RIGHT, 16,
758 IMG_DRAGON_MOVING_UP, 16,
759 IMG_DRAGON_MOVING_LEFT, 16,
760 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
762 IMG_SATELLITE, -1, HA_NEXT,
765 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
768 IMG_LAMP_ACTIVE, 50, HA_NEXT,
770 IMG_TIME_ORB_FULL, 50,
771 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
774 IMG_AMOEBA_GROWING, 6,
775 IMG_AMOEBA_WET, 20, HA_NEXT,
777 IMG_AMOEBA_DEAD, -1, HA_NEXT,
779 IMG_AMOEBA_WET, -1, HA_NEXT,
782 IMG_AMOEBA_GROWING, 6, HA_NEXT,
787 IMG_DIAMOND, 20, HA_NEXT,
789 IMG_GAME_OF_LIFE, -1, HA_NEXT,
791 IMG_BIOMAZE, -1, HA_NEXT,
793 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
795 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
797 IMG_EXIT_CLOSED, 200,
798 IMG_EXIT_OPENING, 16,
799 IMG_EXIT_OPEN, 100, HA_NEXT,
801 IMG_EXIT_OPEN, -1, HA_NEXT,
803 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
805 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
807 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
809 IMG_SPEED_PILL, -1, HA_NEXT,
813 static char *helpscreen_eltext[][2] =
815 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
816 {"Normal sand:", "You can dig through it"},
817 {"Empty field:", "You can walk through it"},
818 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
819 {"Massive Wall:", "Nothing can go through it"},
820 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
821 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
822 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
823 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
824 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
825 {"Emerald: You must collect enough of","them to finish a level"},
826 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
827 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
828 {"Colorful Gems:", "Seem to behave like Emeralds"},
829 {"Rock: Smashes several things;", "Can be moved by the player"},
830 {"Bomb: You can move it, but be", "careful when dropping it"},
831 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
832 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
833 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
834 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
835 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
836 {"Acid: Things that fall in are gone", "forever (including our hero)"},
837 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
838 {"Door: Can be opened by the key", "with the same color"},
839 {"Door: You have to find out the", "right color of the key for it"},
840 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
841 {"Dynamite: This one explodes after", "a few seconds"},
842 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
843 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
844 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
845 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
846 {"Bug: Moves at the right side", "of walls; don't touch it!"},
847 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
848 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
849 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
850 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
851 {"Cruncher (BD style):", "Eats almost everything"},
852 {"Robot: Tries to kill the player", ""},
853 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
854 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
855 {"The Pig: Harmless, but eats all", "gems it can get"},
856 {"The Dragon: Breathes fire,", "especially to some monsters"},
857 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
858 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
859 {"Light Bulb: All of them must be", "switched on to finish a level"},
860 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
861 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
862 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
863 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
864 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
865 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
866 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
867 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
868 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
869 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
870 {"Exit door: Opens if you have enough","emeralds to finish the level"},
871 {"Open exit door: Enter here to leave","the level and exit the actual game"},
872 {"Sokoban element: Object which must", "be pushed to an empty field"},
873 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
874 {"Sokoban element: Field with object", "which can be pushed away"},
875 {"Speed pill: Lets the player run", "twice as fast as normally"},
877 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
879 static char *helpscreen_music[][3] =
881 { "Alchemy", "Ian Boddy", "Drive" },
882 { "The Chase", "Propaganda", "A Secret Wish" },
883 { "Network 23", "Tangerine Dream", "Exit" },
884 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
885 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
886 { "Voyager", "The Alan Parsons Project","Pyramid" },
887 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
889 static int num_helpscreen_music = 7;
890 static int helpscreen_musicpos;
893 void OLD_DrawHelpScreenElAction(int start)
897 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
899 while(helpscreen_action[j] != HA_END)
901 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
903 else if (i<start || helpscreen_delay[i-start])
905 if (i>=start && helpscreen_delay[i-start])
906 helpscreen_delay[i-start]--;
908 while(helpscreen_action[j] != HA_NEXT)
915 j += 3*helpscreen_step[i-start];
916 graphic = helpscreen_action[j++];
918 if (helpscreen_frame[i-start])
920 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
921 helpscreen_frame[i-start]--;
926 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
929 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
931 if (helpscreen_action[j] == HA_NEXT)
933 if (!helpscreen_frame[i-start])
934 helpscreen_step[i-start] = 0;
938 if (!helpscreen_frame[i-start])
939 helpscreen_step[i-start]++;
940 while(helpscreen_action[j] != HA_NEXT)
945 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
957 void DrawHelpScreenElAction(int start)
960 int xstart = mSX + 16;
961 int ystart = mSY + 64 + 2 * 32;
962 int ystep = TILEY + 4;
968 while (helpscreen_action[j] != HA_END)
970 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
974 while (helpscreen_action[j] != HA_NEXT)
983 j += 2 * helpscreen_step[i-start];
984 graphic = helpscreen_action[j++];
985 frame_count = helpscreen_action[j++];
986 if (frame_count == -1)
987 frame_count = 1000000;
989 if (helpscreen_frame[i-start] == 0)
992 helpscreen_frame[i-start] = frame_count - 1;
996 sync_frame = frame_count - helpscreen_frame[i-start];
997 helpscreen_frame[i-start]--;
1000 if (helpscreen_action[j] == HA_NEXT)
1002 if (!helpscreen_frame[i-start])
1003 helpscreen_step[i-start] = 0;
1007 if (!helpscreen_frame[i-start])
1008 helpscreen_step[i-start]++;
1009 while(helpscreen_action[j] != HA_NEXT)
1014 frame = getGraphicAnimationFrame(graphic, sync_frame);
1016 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
1024 MarkTileDirty(0, i);
1025 MarkTileDirty(1, i);
1031 void DrawHelpScreenElText(int start)
1034 int xstart = mSX + 56, ystart = mSY + 65 + 2 * 32, ystep = TILEY + 4;
1035 int ybottom = SYSIZE - 20;
1037 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1041 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
1043 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1046 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1047 helpscreen_eltext[i][0], FONT_TEXT_2);
1048 DrawText(xstart, ystart + (i - start) * ystep + 16,
1049 helpscreen_eltext[i][1], FONT_TEXT_2);
1052 DrawTextFCentered(ybottom, FONT_TEXT_4,
1053 "Press any key or button for next page");
1056 void DrawHelpScreenMusicText(int num)
1058 int ystart = 150, ystep = 30;
1059 int ybottom = SYSIZE - 20;
1065 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
1067 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
1068 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
1069 "\"%s\"", helpscreen_music[num][0]);
1070 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
1071 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
1072 "%s", helpscreen_music[num][1]);
1073 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1074 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
1075 "\"%s\"", helpscreen_music[num][2]);
1077 DrawTextFCentered(ybottom, FONT_TEXT_4,
1078 "Press any key or button for next page");
1081 PlaySoundLoop(background_loop[num]);
1085 void DrawHelpScreenCreditsText()
1087 int ystart = 150, ystep = 30;
1088 int ybottom = SYSIZE - 20;
1094 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
1095 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1096 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1097 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1098 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1099 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
1100 "...and many thanks to all contributors");
1101 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1103 DrawTextFCentered(ybottom, FONT_TEXT_4,
1104 "Press any key or button for next page");
1107 void DrawHelpScreenContactText()
1109 int ystart = 150, ystep = 30;
1110 int ybottom = SYSIZE - 20;
1115 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1117 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1118 "This game is Freeware!");
1119 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1120 "If you like it, send e-mail to:");
1121 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1122 "info@artsoft.org");
1123 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1124 "or SnailMail to:");
1125 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1127 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1128 "Detmolder Strasse 189");
1129 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1131 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1134 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1135 "If you have created new levels,");
1136 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1137 "send them to me to include them!");
1138 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1141 DrawTextFCentered(ybottom, FONT_TEXT_4,
1142 "Press any key or button for main menu");
1145 void DrawHelpScreen()
1150 CloseDoor(DOOR_CLOSE_2);
1152 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1153 helpscreen_step[i] = helpscreen_frame[i] = 0;
1154 helpscreen_musicpos = 0;
1155 helpscreen_state = 0;
1157 DrawHelpScreenElText(0);
1158 DrawHelpScreenElAction(0);
1164 PlaySoundLoop(SND_BACKGROUND_INFO);
1166 PlaySound_Menu_Start(SND_BACKGROUND_INFO);
1170 void HandleHelpScreen(int button)
1172 static unsigned long hs_delay = 0;
1173 int num_helpscreen_els_pages =
1174 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1175 int button_released = !button;
1178 if (button_released)
1180 if (helpscreen_state < num_helpscreen_els_pages - 1)
1182 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1183 helpscreen_step[i] = helpscreen_frame[i] = 0;
1187 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1188 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1190 else if (helpscreen_state <
1191 num_helpscreen_els_pages + num_helpscreen_music - 1)
1194 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1196 else if (helpscreen_state ==
1197 num_helpscreen_els_pages + num_helpscreen_music - 1)
1200 DrawHelpScreenCreditsText();
1202 else if (helpscreen_state ==
1203 num_helpscreen_els_pages + num_helpscreen_music)
1206 DrawHelpScreenContactText();
1212 game_status = MAINMENU;
1218 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1220 if (helpscreen_state < num_helpscreen_els_pages)
1221 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1224 /* !!! workaround for playing "music" that is really a sound loop (and
1225 must therefore periodically be reactivated with the current sound
1228 PlaySoundLoop(SND_BACKGROUND_INFO);
1230 PlaySound_Menu_Continue(SND_BACKGROUND_INFO);
1239 void HandleTypeName(int newxpos, Key key)
1241 static int xpos = 0, ypos = 2;
1242 int font_width = getFontWidth(FONT_INPUT_ACTIVE);
1243 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1244 int startx = mSX + 32 + name_width;
1245 int starty = mSY + ypos * 32;
1251 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1252 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1257 if (((key >= KSYM_A && key <= KSYM_Z) ||
1258 (key >= KSYM_a && key <= KSYM_z)) &&
1259 xpos < MAX_PLAYER_NAME_LEN)
1263 if (key >= KSYM_A && key <= KSYM_Z)
1264 ascii = 'A' + (char)(key - KSYM_A);
1266 ascii = 'a' + (char)(key - KSYM_a);
1268 setup.player_name[xpos] = ascii;
1269 setup.player_name[xpos + 1] = 0;
1272 DrawText(startx, starty, setup.player_name, FONT_INPUT_ACTIVE);
1273 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_ACTIVE);
1275 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1278 setup.player_name[xpos] = 0;
1280 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_ACTIVE);
1282 else if (key == KSYM_Return && xpos > 0)
1284 DrawText(startx, starty, setup.player_name, FONT_INPUT);
1285 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_ACTIVE);
1288 game_status = MAINMENU;
1294 static void DrawChooseTree(TreeInfo **ti_ptr)
1297 CloseDoor(DOOR_CLOSE_2);
1301 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1302 MapChooseTreeGadgets(*ti_ptr);
1308 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1310 struct GadgetInfo *gi = screen_gadget[id];
1311 int items_max, items_visible, item_position;
1313 items_max = numTreeInfoInGroup(ti);
1314 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1315 item_position = first_entry;
1317 if (item_position > items_max - items_visible)
1318 item_position = items_max - items_visible;
1320 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1321 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1324 static void drawChooseTreeList(int first_entry, int num_page_entries,
1328 char buffer[SCR_FIELDX * 2];
1329 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1330 int num_entries = numTreeInfoInGroup(ti);
1331 char *title_string = NULL;
1332 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1333 int last_game_status = game_status; /* save current game status */
1335 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1336 redraw_mask |= REDRAW_FIELD;
1339 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1340 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1341 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1342 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1344 DrawText(SX + offset, SY + offset, title_string, FONT_TITLE_1);
1346 game_status = CHOOSELEVEL; /* force LEVELS font on artwork setup screen */
1348 for(i=0; i<num_page_entries; i++)
1350 TreeInfo *node, *node_first;
1351 int entry_pos = first_entry + i;
1352 int ypos = MENU_SCREEN_START_YPOS + i;
1354 node_first = getTreeInfoFirstGroupEntry(ti);
1355 node = getTreeInfoFromPos(node_first, entry_pos);
1357 strncpy(buffer, node->name , max_buffer_len);
1358 buffer[max_buffer_len] = '\0';
1360 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1362 if (node->parent_link)
1363 initCursor(i, IMG_MENU_BUTTON_LEFT);
1364 else if (node->level_group)
1365 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1367 initCursor(i, IMG_MENU_BUTTON);
1370 if (first_entry > 0)
1374 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1375 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_UP, 0);
1378 if (first_entry + num_page_entries < num_entries)
1380 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1382 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1383 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_DOWN, 0);
1386 game_status = last_game_status; /* restore current game status */
1389 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1391 TreeInfo *node, *node_first;
1392 int x, last_redraw_mask = redraw_mask;
1394 if (ti->type != TREE_TYPE_LEVEL_DIR)
1397 node_first = getTreeInfoFirstGroupEntry(ti);
1398 node = getTreeInfoFromPos(node_first, entry_pos);
1400 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1402 if (node->parent_link)
1403 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1405 else if (node->level_group)
1406 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1408 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1409 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1410 node->levels, node->class_desc);
1412 /* let BackToFront() redraw only what is needed */
1413 redraw_mask = last_redraw_mask | REDRAW_TILES;
1414 for (x=0; x<SCR_FIELDX; x++)
1415 MarkTileDirty(x, 1);
1418 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1421 static unsigned long choose_delay = 0;
1422 TreeInfo *ti = *ti_ptr;
1424 int y = ti->cl_cursor;
1425 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1426 int num_entries = numTreeInfoInGroup(ti);
1427 int num_page_entries;
1429 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1430 num_page_entries = num_entries;
1432 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1434 if (button == MB_MENU_INITIALIZE)
1436 int entry_pos = posTreeInfo(ti);
1438 if (ti->cl_first == -1)
1440 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1442 entry_pos - ti->cl_first;
1445 if (dx == 999) /* first entry is set by scrollbar position */
1448 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1451 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1452 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1453 drawCursor(ti->cl_cursor, FC_RED);
1456 else if (button == MB_MENU_LEAVE)
1458 if (ti->node_parent)
1460 *ti_ptr = ti->node_parent;
1461 DrawChooseTree(ti_ptr);
1463 else if (game_status == SETUP)
1469 game_status = MAINMENU;
1476 if (mx || my) /* mouse input */
1479 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1481 else if (dx || dy) /* keyboard input */
1484 y = ti->cl_cursor + dy;
1486 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1489 step = num_page_entries - 1;
1490 y = (dy < 0 ? -1 : num_page_entries);
1494 if (x == 0 && y == -1)
1496 if (ti->cl_first > 0 &&
1497 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1499 ti->cl_first -= step;
1500 if (ti->cl_first < 0)
1503 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1504 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1505 drawCursor(ti->cl_cursor, FC_RED);
1506 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1511 else if (x == 0 && y > num_page_entries - 1)
1513 if (ti->cl_first + num_page_entries < num_entries &&
1514 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1516 ti->cl_first += step;
1517 if (ti->cl_first + num_page_entries > num_entries)
1518 ti->cl_first = MAX(0, num_entries - num_page_entries);
1520 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1521 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1522 drawCursor(ti->cl_cursor, FC_RED);
1523 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1531 TreeInfo *node_first, *node_cursor;
1532 int entry_pos = ti->cl_first + y;
1534 node_first = getTreeInfoFirstGroupEntry(ti);
1535 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1537 if (node_cursor->node_group)
1539 node_cursor->cl_first = ti->cl_first;
1540 node_cursor->cl_cursor = ti->cl_cursor;
1541 *ti_ptr = node_cursor->node_group;
1542 DrawChooseTree(ti_ptr);
1546 else if (dx == -1 && ti->node_parent)
1548 *ti_ptr = ti->node_parent;
1549 DrawChooseTree(ti_ptr);
1553 if (x == 0 && y >= 0 && y < num_page_entries)
1557 if (y != ti->cl_cursor)
1559 drawCursor(y, FC_RED);
1560 drawCursor(ti->cl_cursor, FC_BLUE);
1561 drawChooseTreeInfo(ti->cl_first + y, ti);
1567 TreeInfo *node_first, *node_cursor;
1568 int entry_pos = ti->cl_first + y;
1570 node_first = getTreeInfoFirstGroupEntry(ti);
1571 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1573 if (node_cursor->node_group)
1575 node_cursor->cl_first = ti->cl_first;
1576 node_cursor->cl_cursor = ti->cl_cursor;
1577 *ti_ptr = node_cursor->node_group;
1578 DrawChooseTree(ti_ptr);
1580 else if (node_cursor->parent_link)
1582 *ti_ptr = node_cursor->node_parent;
1583 DrawChooseTree(ti_ptr);
1587 node_cursor->cl_first = ti->cl_first;
1588 node_cursor->cl_cursor = ti->cl_cursor;
1589 *ti_ptr = node_cursor;
1591 if (ti->type == TREE_TYPE_LEVEL_DIR)
1593 LoadLevelSetup_SeriesInfo();
1595 SaveLevelSetup_LastSeries();
1596 SaveLevelSetup_SeriesInfo();
1600 if (game_status == SETUP)
1606 game_status = MAINMENU;
1615 if (game_status == CHOOSELEVEL || game_status == SETUP)
1619 void DrawChooseLevel()
1621 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1623 DrawChooseTree(&leveldir_current);
1626 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1628 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1631 void DrawHallOfFame(int highlight_position)
1635 CloseDoor(DOOR_CLOSE_2);
1637 if (highlight_position < 0)
1638 LoadScore(level_nr);
1643 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1646 PlaySound(SND_BACKGROUND_SCORES);
1648 PlaySound_Menu_Start(SND_BACKGROUND_SCORES);
1652 static void drawHallOfFameList(int first_entry, int highlight_position)
1656 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1659 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1660 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1662 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1664 int entry = first_entry + i;
1666 DrawText(mSX, mSY + 64 + i * 32, "..................................",
1667 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1668 DrawText(mSX, mSY + 64 + i * 32, int2str(entry + 1, 3),
1669 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1670 DrawText(mSX + 64, mSY + 64 + i * 32, highscore[entry].Name,
1671 (entry == highlight_position ? FONT_TEXT_3 : FONT_TEXT_1));
1672 DrawText(mSX + 14 * 32 + 16, mSY + 64 + i * 32,
1673 int2str(highscore[entry].Score, 5),
1674 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1678 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1680 static int first_entry = 0;
1681 static int highlight_position = 0;
1682 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1683 int button_released = !button;
1685 if (button == MB_MENU_INITIALIZE)
1688 highlight_position = mx;
1689 drawHallOfFameList(first_entry, highlight_position);
1693 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1694 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1698 if (first_entry > 0)
1700 first_entry -= step;
1701 if (first_entry < 0)
1704 drawHallOfFameList(first_entry, highlight_position);
1710 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1712 first_entry += step;
1713 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1714 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1716 drawHallOfFameList(first_entry, highlight_position);
1721 if (button_released)
1723 FadeSound(SND_BACKGROUND_SCORES);
1724 game_status = MAINMENU;
1730 if (game_status == HALLOFFAME)
1734 PlaySound_Menu_Continue(SND_BACKGROUND_SCORES);
1740 /* ========================================================================= */
1741 /* setup screen functions */
1742 /* ========================================================================= */
1744 static struct TokenInfo *setup_info;
1745 static int num_setup_info;
1747 static char *graphics_set_name;
1748 static char *sounds_set_name;
1749 static char *music_set_name;
1751 static void execSetupMain()
1753 setup_mode = SETUP_MODE_MAIN;
1757 static void execSetupGame()
1759 setup_mode = SETUP_MODE_GAME;
1763 static void execSetupEditor()
1765 setup_mode = SETUP_MODE_EDITOR;
1769 static void execSetupGraphics()
1771 setup_mode = SETUP_MODE_GRAPHICS;
1775 static void execSetupSound()
1777 setup_mode = SETUP_MODE_SOUND;
1781 static void execSetupArtwork()
1783 /* needed if last screen (setup choice) changed graphics, sounds or music */
1784 ReloadCustomArtwork();
1786 setup.graphics_set = artwork.gfx_current->identifier;
1787 setup.sounds_set = artwork.snd_current->identifier;
1788 setup.music_set = artwork.mus_current->identifier;
1790 /* needed for displaying artwork name instead of artwork identifier */
1791 graphics_set_name = artwork.gfx_current->name;
1792 sounds_set_name = artwork.snd_current->name;
1793 music_set_name = artwork.mus_current->name;
1795 setup_mode = SETUP_MODE_ARTWORK;
1799 static void execSetupChooseGraphics()
1801 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1805 static void execSetupChooseSounds()
1807 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1811 static void execSetupChooseMusic()
1813 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1817 static void execSetupInput()
1819 setup_mode = SETUP_MODE_INPUT;
1823 static void execSetupShortcut()
1825 setup_mode = SETUP_MODE_SHORTCUT;
1829 static void execExitSetup()
1831 game_status = MAINMENU;
1835 static void execSaveAndExitSetup()
1841 static struct TokenInfo setup_info_main[] =
1843 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1844 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1845 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1846 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1847 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1848 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1849 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1850 { TYPE_EMPTY, NULL, "" },
1851 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1852 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1856 static struct TokenInfo setup_info_game[] =
1858 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1859 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1860 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1861 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1862 { TYPE_EMPTY, NULL, "" },
1863 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1867 static struct TokenInfo setup_info_editor[] =
1869 { TYPE_STRING, NULL, "Offer Special Elements:"},
1870 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1871 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1872 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1873 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1874 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1875 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1876 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1877 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1878 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1879 { TYPE_EMPTY, NULL, "" },
1880 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1884 static struct TokenInfo setup_info_graphics[] =
1886 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1887 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1888 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1890 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1891 { TYPE_SWITCH, &setup.fading, "Fading:" },
1893 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1894 { TYPE_SWITCH, &setup.toons, "Toons:" },
1895 { TYPE_EMPTY, NULL, "" },
1896 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1900 static struct TokenInfo setup_info_sound[] =
1902 { TYPE_SWITCH, &setup.sound, "Sound:", },
1903 { TYPE_EMPTY, NULL, "" },
1904 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1905 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1906 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1907 { TYPE_EMPTY, NULL, "" },
1908 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1912 static struct TokenInfo setup_info_artwork[] =
1914 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1915 { TYPE_STRING, &graphics_set_name, "" },
1916 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1917 { TYPE_STRING, &sounds_set_name, "" },
1918 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1919 { TYPE_STRING, &music_set_name, "" },
1920 { TYPE_EMPTY, NULL, "" },
1921 { TYPE_STRING, NULL, "Override Level Artwork:"},
1922 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1923 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1924 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1925 { TYPE_EMPTY, NULL, "" },
1926 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1930 static struct TokenInfo setup_info_shortcut[] =
1932 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1933 { TYPE_KEY, &setup.shortcut.save_game, "" },
1934 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1935 { TYPE_KEY, &setup.shortcut.load_game, "" },
1936 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1937 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1938 { TYPE_EMPTY, NULL, "" },
1939 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1940 { TYPE_EMPTY, NULL, "" },
1941 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1945 static Key getSetupKey()
1947 Key key = KSYM_UNDEFINED;
1948 boolean got_key_event = FALSE;
1950 while (!got_key_event)
1952 if (PendingEvent()) /* got event */
1960 case EVENT_KEYPRESS:
1962 key = GetEventKey((KeyEvent *)&event, TRUE);
1964 /* press 'Escape' or 'Enter' to keep the existing key binding */
1965 if (key == KSYM_Escape || key == KSYM_Return)
1966 key = KSYM_UNDEFINED; /* keep old value */
1968 got_key_event = TRUE;
1972 case EVENT_KEYRELEASE:
1973 key_joystick_mapping = 0;
1977 HandleOtherEvents(&event);
1985 /* don't eat all CPU time */
1992 static void drawSetupValue(int pos)
1994 int xpos = MENU_SCREEN_VALUE_XPOS;
1995 int ypos = MENU_SCREEN_START_YPOS + pos;
1996 int font_nr = FONT_VALUE_1;
1997 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1998 setup_info[pos].value);
2000 if (value_string == NULL)
2003 if (setup_info[pos].type & TYPE_KEY)
2007 if (setup_info[pos].type & TYPE_QUERY)
2009 value_string = "<press key>";
2010 font_nr = FONT_INPUT_ACTIVE;
2013 else if (setup_info[pos].type & TYPE_STRING)
2015 int max_value_len = (SCR_FIELDX - 2) * 2;
2018 font_nr = FONT_VALUE_2;
2020 if (strlen(value_string) > max_value_len)
2021 value_string[max_value_len] = '\0';
2023 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
2024 !*(boolean *)(setup_info[pos].value))
2025 font_nr = FONT_OPTION_OFF;
2027 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2028 (xpos == 3 ? " " : " "), font_nr);
2029 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2032 static void changeSetupValue(int pos)
2034 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2036 *(boolean *)setup_info[pos].value ^= TRUE;
2038 else if (setup_info[pos].type & TYPE_KEY)
2042 setup_info[pos].type |= TYPE_QUERY;
2043 drawSetupValue(pos);
2044 setup_info[pos].type &= ~TYPE_QUERY;
2046 key = getSetupKey();
2047 if (key != KSYM_UNDEFINED)
2048 *(Key *)setup_info[pos].value = key;
2051 drawSetupValue(pos);
2054 static void DrawSetupScreen_Generic()
2056 char *title_string = NULL;
2060 CloseDoor(DOOR_CLOSE_2);
2064 if (setup_mode == SETUP_MODE_MAIN)
2066 setup_info = setup_info_main;
2067 title_string = "Setup";
2069 else if (setup_mode == SETUP_MODE_GAME)
2071 setup_info = setup_info_game;
2072 title_string = "Setup Game";
2074 else if (setup_mode == SETUP_MODE_EDITOR)
2076 setup_info = setup_info_editor;
2077 title_string = "Setup Editor";
2079 else if (setup_mode == SETUP_MODE_GRAPHICS)
2081 setup_info = setup_info_graphics;
2082 title_string = "Setup Graphics";
2084 else if (setup_mode == SETUP_MODE_SOUND)
2086 setup_info = setup_info_sound;
2087 title_string = "Setup Sound";
2089 else if (setup_mode == SETUP_MODE_ARTWORK)
2091 setup_info = setup_info_artwork;
2092 title_string = "Custom Artwork";
2094 else if (setup_mode == SETUP_MODE_SHORTCUT)
2096 setup_info = setup_info_shortcut;
2097 title_string = "Setup Shortcuts";
2100 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2103 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2105 void *value_ptr = setup_info[i].value;
2106 int ypos = MENU_SCREEN_START_YPOS + i;
2107 int font_nr = FONT_MENU_1;
2109 /* set some entries to "unchangeable" according to other variables */
2110 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2111 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2112 (value_ptr == &setup.sound_music && !audio.music_available) ||
2113 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2114 setup_info[i].type |= TYPE_GHOSTED;
2116 if (setup_info[i].type & TYPE_STRING)
2117 font_nr = FONT_MENU_2;
2119 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2121 if (setup_info[i].type & TYPE_ENTER_MENU)
2122 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2123 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2124 initCursor(i, IMG_MENU_BUTTON_LEFT);
2125 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2126 initCursor(i, IMG_MENU_BUTTON);
2128 if (setup_info[i].type & TYPE_VALUE)
2136 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2139 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2141 static int choice_store[MAX_SETUP_MODES];
2142 int choice = choice_store[setup_mode]; /* always starts with 0 */
2146 if (button == MB_MENU_INITIALIZE)
2148 /* advance to first valid menu entry */
2149 while (choice < num_setup_info &&
2150 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2152 choice_store[setup_mode] = choice;
2154 drawCursor(choice, FC_RED);
2157 else if (button == MB_MENU_LEAVE)
2159 for (y=0; y<num_setup_info; y++)
2161 if (setup_info[y].type & TYPE_LEAVE_MENU)
2163 void (*menu_callback_function)(void) = setup_info[y].value;
2165 menu_callback_function();
2166 break; /* absolutely needed because function changes 'setup_info'! */
2173 if (mx || my) /* mouse input */
2176 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2178 else if (dx || dy) /* keyboard input */
2182 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2184 if ((setup_info[choice].type & menu_navigation_type) ||
2185 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2186 button = MB_MENU_CHOICE;
2191 /* jump to next non-empty menu entry (up or down) */
2192 while (y > 0 && y < num_setup_info - 1 &&
2193 (setup_info[y].type & TYPE_SKIP_ENTRY))
2197 if (x == 0 && y >= 0 && y < num_setup_info &&
2198 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2204 drawCursor(y, FC_RED);
2205 drawCursor(choice, FC_BLUE);
2206 choice = choice_store[setup_mode] = y;
2209 else if (!(setup_info[y].type & TYPE_GHOSTED))
2211 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2213 void (*menu_callback_function)(void) = setup_info[choice].value;
2215 menu_callback_function();
2219 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2220 (setup_info[y + 1].type & TYPE_KEY))
2223 if (setup_info[y].type & TYPE_VALUE)
2224 changeSetupValue(y);
2231 if (game_status == SETUP)
2235 void DrawSetupScreen_Input()
2239 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2241 initCursor(0, IMG_MENU_BUTTON);
2242 initCursor(1, IMG_MENU_BUTTON);
2243 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2244 initCursor(13, IMG_MENU_BUTTON_LEFT);
2246 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2247 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2249 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2250 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2251 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2254 DeactivateJoystickForCalibration();
2255 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2256 "Joysticks deactivated on this screen");
2259 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2264 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2266 if (device_name == NULL)
2269 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2272 if (strlen(device_name) > 1)
2274 char c1 = device_name[strlen(device_name) - 1];
2275 char c2 = device_name[strlen(device_name) - 2];
2277 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2278 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2281 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2282 strlen(device_name));
2285 static void drawPlayerSetupInputInfo(int player_nr)
2288 static struct SetupKeyboardInfo custom_key;
2295 { &custom_key.left, "Joystick Left" },
2296 { &custom_key.right, "Joystick Right" },
2297 { &custom_key.up, "Joystick Up" },
2298 { &custom_key.down, "Joystick Down" },
2299 { &custom_key.snap, "Button 1" },
2300 { &custom_key.bomb, "Button 2" }
2302 static char *joystick_name[MAX_PLAYERS] =
2310 custom_key = setup.input[player_nr].key;
2312 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr + 1, 1), FONT_INPUT_ACTIVE);
2314 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2315 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2317 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2320 if (setup.input[player_nr].use_joystick)
2322 char *device_name = setup.input[player_nr].joy.device_name;
2324 DrawText(mSX+8*32, mSY+3*32,
2325 joystick_name[getJoystickNrFromDeviceName(device_name)],
2327 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2331 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2332 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2335 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2336 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2337 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2338 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2339 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2340 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2341 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2342 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2343 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2344 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2345 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2349 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2351 DrawText(mSX + 3*32, mSY + ypos*32,
2353 DrawText(mSX + 3*32, mSY + ypos*32,
2354 (setup.input[player_nr].use_joystick ?
2356 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2360 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2362 static int choice = 0;
2363 static int player_nr = 0;
2366 int pos_start = SETUPINPUT_SCREEN_POS_START;
2367 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2368 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2369 int pos_end = SETUPINPUT_SCREEN_POS_END;
2371 if (button == MB_MENU_INITIALIZE)
2373 drawPlayerSetupInputInfo(player_nr);
2374 drawCursor(choice, FC_RED);
2377 else if (button == MB_MENU_LEAVE)
2379 setup_mode = SETUP_MODE_MAIN;
2384 if (mx || my) /* mouse input */
2387 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2389 else if (dx || dy) /* keyboard input */
2391 if (dx && choice == 0)
2392 x = (dx < 0 ? 10 : 12);
2393 else if ((dx && choice == 1) ||
2394 (dx == +1 && choice == 2) ||
2395 (dx == -1 && choice == pos_end))
2396 button = MB_MENU_CHOICE;
2400 if (y >= pos_empty1 && y <= pos_empty2)
2401 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2404 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2406 static unsigned long delay = 0;
2408 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2411 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2413 drawPlayerSetupInputInfo(player_nr);
2415 else if (x == 0 && y >= pos_start && y <= pos_end &&
2416 !(y >= pos_empty1 && y <= pos_empty2))
2422 drawCursor(y, FC_RED);
2423 drawCursor(choice, FC_BLUE);
2431 char *device_name = setup.input[player_nr].joy.device_name;
2433 if (!setup.input[player_nr].use_joystick)
2435 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2437 setJoystickDeviceToNr(device_name, new_device_nr);
2438 setup.input[player_nr].use_joystick = TRUE;
2442 int device_nr = getJoystickNrFromDeviceName(device_name);
2443 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2445 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2446 setup.input[player_nr].use_joystick = FALSE;
2448 setJoystickDeviceToNr(device_name, new_device_nr);
2451 drawPlayerSetupInputInfo(player_nr);
2455 if (setup.input[player_nr].use_joystick)
2458 CalibrateJoystick(player_nr);
2461 CustomizeKeyboard(player_nr);
2463 else if (y == pos_end)
2467 setup_mode = SETUP_MODE_MAIN;
2477 if (game_status == SETUP)
2481 void CustomizeKeyboard(int player_nr)
2485 boolean finished = FALSE;
2486 static struct SetupKeyboardInfo custom_key;
2491 } customize_step[] =
2493 { &custom_key.left, "Move Left" },
2494 { &custom_key.right, "Move Right" },
2495 { &custom_key.up, "Move Up" },
2496 { &custom_key.down, "Move Down" },
2497 { &custom_key.snap, "Snap Field" },
2498 { &custom_key.bomb, "Place Bomb" }
2501 /* read existing key bindings from player setup */
2502 custom_key = setup.input[player_nr].key;
2505 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2511 DrawText(mSX, mSY + (2+2*step_nr)*32,
2512 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2513 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2514 "Key:", FONT_INPUT_ACTIVE);
2515 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2516 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2520 if (PendingEvent()) /* got event */
2528 case EVENT_KEYPRESS:
2530 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2532 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2538 /* all keys configured -- wait for "Escape" or "Return" key */
2542 /* press 'Enter' to keep the existing key binding */
2543 if (key == KSYM_Return)
2544 key = *customize_step[step_nr].key;
2546 /* check if key already used */
2547 for (i=0; i<step_nr; i++)
2548 if (*customize_step[i].key == key)
2553 /* got new key binding */
2554 *customize_step[step_nr].key = key;
2555 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2557 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2558 getKeyNameFromKey(key), FONT_VALUE_1);
2561 /* un-highlight last query */
2562 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2563 customize_step[step_nr-1].text, FONT_MENU_1);
2564 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2565 "Key:", FONT_MENU_1);
2567 /* press 'Enter' to leave */
2570 DrawText(mSX + 16, mSY + 15*32+16,
2571 "Press Enter", FONT_TITLE_1);
2575 /* query next key binding */
2576 DrawText(mSX, mSY+(2+2*step_nr)*32,
2577 customize_step[step_nr].text, FONT_INPUT_ACTIVE);
2578 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2579 "Key:", FONT_INPUT_ACTIVE);
2580 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2581 getKeyNameFromKey(*customize_step[step_nr].key),
2586 case EVENT_KEYRELEASE:
2587 key_joystick_mapping = 0;
2591 HandleOtherEvents(&event);
2599 /* don't eat all CPU time */
2603 /* write new key bindings back to player setup */
2604 setup.input[player_nr].key = custom_key;
2607 DrawSetupScreen_Input();
2610 static boolean CalibrateJoystickMain(int player_nr)
2612 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2613 int new_joystick_xright = JOYSTICK_XMIDDLE;
2614 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2615 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2616 int new_joystick_xmiddle, new_joystick_ymiddle;
2618 int joystick_fd = joystick.fd[player_nr];
2619 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2620 boolean check[3][3];
2621 int check_remaining = 3 * 3;
2626 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2629 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2634 for(y=0; y < 3; y++)
2636 for(x=0; x < 3; x++)
2638 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2639 check[x][y] = FALSE;
2643 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2644 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2645 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2646 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2647 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2648 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2649 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2651 joy_value = Joystick(player_nr);
2652 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2653 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2655 /* eventually uncalibrated center position (joystick could be uncentered) */
2656 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2659 new_joystick_xmiddle = joy_x;
2660 new_joystick_ymiddle = joy_y;
2662 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2665 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2670 if (PendingEvent()) /* got event */
2678 case EVENT_KEYPRESS:
2679 switch(GetEventKey((KeyEvent *)&event, TRUE))
2682 if (check_remaining == 0)
2695 case EVENT_KEYRELEASE:
2696 key_joystick_mapping = 0;
2700 HandleOtherEvents(&event);
2705 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2708 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2709 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2710 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2711 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2713 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2714 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2715 setup.input[player_nr].joy.xright = new_joystick_xright;
2716 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2717 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2718 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2720 CheckJoystickData();
2722 joy_value = Joystick(player_nr);
2724 if (joy_value & JOY_BUTTON && check_remaining == 0)
2727 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2728 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2730 if (x != last_x || y != last_y)
2732 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2733 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2738 if (check_remaining > 0 && !check[x+1][y+1])
2740 check[x+1][y+1] = TRUE;
2746 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2747 setup.input[player_nr].joy.xleft,
2748 setup.input[player_nr].joy.xmiddle,
2749 setup.input[player_nr].joy.xright);
2750 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2751 setup.input[player_nr].joy.yupper,
2752 setup.input[player_nr].joy.ymiddle,
2753 setup.input[player_nr].joy.ylower);
2762 /* don't eat all CPU time */
2766 /* calibrated center position (joystick should now be centered) */
2767 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2770 new_joystick_xmiddle = joy_x;
2771 new_joystick_ymiddle = joy_y;
2775 DrawSetupScreen_Input();
2777 /* wait until the last pressed button was released */
2778 while (Joystick(player_nr) & JOY_BUTTON)
2780 if (PendingEvent()) /* got event */
2785 HandleOtherEvents(&event);
2794 void CalibrateJoystick(int player_nr)
2796 if (!CalibrateJoystickMain(player_nr))
2800 DrawText(mSX + 16, mSY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2801 DrawText(mSX, mSY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2803 Delay(2000); /* show error message for two seconds */
2807 void DrawSetupScreen()
2809 DeactivateJoystick();
2811 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2813 if (setup_mode == SETUP_MODE_INPUT)
2814 DrawSetupScreen_Input();
2815 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2816 DrawChooseTree(&artwork.gfx_current);
2817 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2818 DrawChooseTree(&artwork.snd_current);
2819 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2820 DrawChooseTree(&artwork.mus_current);
2822 DrawSetupScreen_Generic();
2825 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2827 if (setup_mode == SETUP_MODE_INPUT)
2828 HandleSetupScreen_Input(mx, my, dx, dy, button);
2829 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2830 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2831 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2832 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2833 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2834 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2836 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2839 void HandleGameActions()
2841 if (game_status != PLAYING)
2844 if (local_player->LevelSolved)
2847 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2855 /* ---------- new screen button stuff -------------------------------------- */
2857 /* graphic position and size values for buttons and scrollbars */
2858 #define SC_SCROLLBUTTON_XSIZE 32
2859 #define SC_SCROLLBUTTON_YSIZE 32
2861 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2862 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2863 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2864 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2865 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2866 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2867 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2868 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2870 #define SC_BORDER_SIZE 14
2874 int gfx_unpressed, gfx_pressed;
2878 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2881 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2882 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2883 SCREEN_CTRL_ID_SCROLL_UP,
2887 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2888 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2889 SCREEN_CTRL_ID_SCROLL_DOWN,
2896 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2897 Bitmap **gfx_unpressed, **gfx_pressed;
2899 int gfx_unpressed, gfx_pressed;
2906 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2909 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2910 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2912 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2914 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2915 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2916 GD_TYPE_SCROLLBAR_VERTICAL,
2917 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2918 "scroll level series vertically"
2922 static void CreateScreenScrollbuttons()
2924 struct GadgetInfo *gi;
2925 unsigned long event_mask;
2928 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2930 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2931 int gfx_unpressed, gfx_pressed;
2932 int x, y, width, height;
2933 int gd_x1, gd_x2, gd_y1, gd_y2;
2934 int id = scrollbutton_info[i].gadget_id;
2936 x = scrollbutton_info[i].x;
2937 y = scrollbutton_info[i].y;
2939 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2943 width = SC_SCROLLBUTTON_XSIZE;
2944 height = SC_SCROLLBUTTON_YSIZE;
2946 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2947 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2948 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2949 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2950 gd_x1 = graphic_info[gfx_unpressed].src_x;
2951 gd_y1 = graphic_info[gfx_unpressed].src_y;
2952 gd_x2 = graphic_info[gfx_pressed].src_x;
2953 gd_y2 = graphic_info[gfx_pressed].src_y;
2955 gi = CreateGadget(GDI_CUSTOM_ID, id,
2956 GDI_CUSTOM_TYPE_ID, i,
2957 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2962 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2963 GDI_STATE, GD_BUTTON_UNPRESSED,
2964 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2965 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2966 GDI_EVENT_MASK, event_mask,
2967 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2971 Error(ERR_EXIT, "cannot create gadget");
2973 screen_gadget[id] = gi;
2977 static void CreateScreenScrollbars()
2981 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2983 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2984 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2985 int gfx_unpressed, gfx_pressed;
2987 int gd_x1, gd_x2, gd_y1, gd_y2;
2988 struct GadgetInfo *gi;
2989 int items_max, items_visible, item_position;
2990 unsigned long event_mask;
2991 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2992 int id = scrollbar_info[i].gadget_id;
2994 items_max = num_page_entries;
2995 items_visible = num_page_entries;
2998 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3000 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3001 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3002 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3008 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3009 gfx_pressed = scrollbar_info[i].gfx_pressed;
3010 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3011 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3012 gd_x1 = graphic_info[gfx_unpressed].src_x;
3013 gd_y1 = graphic_info[gfx_unpressed].src_y;
3014 gd_x2 = graphic_info[gfx_pressed].src_x;
3015 gd_y2 = graphic_info[gfx_pressed].src_y;
3018 gi = CreateGadget(GDI_CUSTOM_ID, id,
3019 GDI_CUSTOM_TYPE_ID, i,
3020 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3021 GDI_X, scrollbar_info[i].x,
3022 GDI_Y, scrollbar_info[i].y,
3023 GDI_WIDTH, scrollbar_info[i].width,
3024 GDI_HEIGHT, scrollbar_info[i].height,
3025 GDI_TYPE, scrollbar_info[i].type,
3026 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3027 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3028 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3029 GDI_STATE, GD_BUTTON_UNPRESSED,
3030 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3031 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3032 GDI_BORDER_SIZE, SC_BORDER_SIZE,
3033 GDI_EVENT_MASK, event_mask,
3034 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3038 Error(ERR_EXIT, "cannot create gadget");
3040 screen_gadget[id] = gi;
3044 void CreateScreenGadgets()
3046 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3049 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3051 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3053 /* copy pointers to clip mask and GC */
3054 scrollbar_bitmap[i]->clip_mask =
3055 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3056 scrollbar_bitmap[i]->stored_clip_gc =
3057 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3059 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3060 scrollbar_bitmap[i],
3061 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3062 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3063 TILEX, TILEY, 0, 0);
3067 CreateScreenScrollbuttons();
3068 CreateScreenScrollbars();
3071 void FreeScreenGadgets()
3075 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3076 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3078 /* prevent freeing clip mask and GC twice */
3079 scrollbar_bitmap[i]->clip_mask = None;
3080 scrollbar_bitmap[i]->stored_clip_gc = None;
3082 FreeBitmap(scrollbar_bitmap[i]);
3086 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3087 FreeGadget(screen_gadget[i]);
3090 void MapChooseTreeGadgets(TreeInfo *ti)
3092 int num_entries = numTreeInfoInGroup(ti);
3095 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
3098 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3099 MapGadget(screen_gadget[i]);
3102 void UnmapChooseTreeGadgets()
3106 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3107 UnmapGadget(screen_gadget[i]);
3110 static void HandleScreenGadgets(struct GadgetInfo *gi)
3112 int id = gi->custom_id;
3114 if (game_status != CHOOSELEVEL && game_status != SETUP)
3119 case SCREEN_CTRL_ID_SCROLL_UP:
3120 if (game_status == CHOOSELEVEL)
3121 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3122 else if (game_status == SETUP)
3123 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3126 case SCREEN_CTRL_ID_SCROLL_DOWN:
3127 if (game_status == CHOOSELEVEL)
3128 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3129 else if (game_status == SETUP)
3130 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3133 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3134 if (game_status == CHOOSELEVEL)
3135 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3136 else if (game_status == SETUP)
3137 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);