1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
27 /* screens in the setup menu */
28 #define SETUP_MODE_MAIN 0
29 #define SETUP_MODE_GAME 1
30 #define SETUP_MODE_EDITOR 2
31 #define SETUP_MODE_INPUT 3
32 #define SETUP_MODE_SHORTCUT 4
33 #define SETUP_MODE_GRAPHICS 5
34 #define SETUP_MODE_SOUND 6
35 #define SETUP_MODE_ARTWORK 7
36 #define SETUP_MODE_CHOOSE_GRAPHICS 8
37 #define SETUP_MODE_CHOOSE_SOUNDS 9
38 #define SETUP_MODE_CHOOSE_MUSIC 10
40 #define MAX_SETUP_MODES 11
42 /* for input setup functions */
43 #define SETUPINPUT_SCREEN_POS_START 0
44 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
45 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
46 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
48 /* for various menu stuff */
49 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
50 #define MENU_SCREEN_START_YPOS 2
51 #define MENU_SCREEN_VALUE_XPOS 14
53 /* buttons and scrollbars identifiers */
54 #define SCREEN_CTRL_ID_SCROLL_UP 0
55 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
56 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
58 #define NUM_SCREEN_SCROLLBUTTONS 2
59 #define NUM_SCREEN_SCROLLBARS 1
60 #define NUM_SCREEN_GADGETS 3
62 /* forward declarations of internal functions */
63 static void HandleScreenGadgets(struct GadgetInfo *);
64 static void HandleSetupScreen_Generic(int, int, int, int, int);
65 static void HandleSetupScreen_Input(int, int, int, int, int);
66 static void CustomizeKeyboard(int);
67 static void CalibrateJoystick(int);
68 static void execSetupArtwork(void);
69 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
71 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
72 static int setup_mode = SETUP_MODE_MAIN;
78 #define mSX (SX + (game_status == MAINMENU ? global.menu_draw_xoffset_MAIN : \
79 global.menu_draw_xoffset))
80 #define mSY (SY + (game_status == MAINMENU ? global.menu_draw_yoffset_MAIN : \
81 global.menu_draw_yoffset))
84 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
85 #define NUM_SCROLLBAR_BITMAPS 2
86 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
90 static void drawCursorExt(int xpos, int ypos, int color, int graphic)
92 static int cursor_array[SCR_FIELDY];
97 cursor_array[ypos] = graphic;
99 graphic = cursor_array[ypos];
103 graphic = (graphic == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
104 graphic == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE:
105 IMG_MENU_BUTTON_ACTIVE);
107 ypos += MENU_SCREEN_START_YPOS;
110 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
111 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY,
114 DrawBackground(SX + xpos * 32, SY + ypos * 32, TILEX, TILEY);
115 DrawGraphicThruMask(xpos, ypos, graphic, 0);
119 static void initCursor(int ypos, int graphic)
121 drawCursorExt(0, ypos, FC_BLUE, graphic);
124 static void drawCursor(int ypos, int color)
126 drawCursorExt(0, ypos, color, 0);
129 static void drawCursorXY(int xpos, int ypos, int graphic)
131 drawCursorExt(xpos, ypos, -1, graphic);
134 static void PlaySound_Menu_Start(int sound)
136 if (sound_info[sound].loop)
137 PlaySoundLoop(sound);
142 static void PlaySound_Menu_Continue(int sound)
144 if (sound_info[sound].loop)
145 PlaySoundLoop(sound);
150 int font1_width = getFontWidth(FONT_TITLE_1);
151 int font2_width = getFontWidth(FONT_TITLE_2);
152 int x1 = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * font1_width) / 2;
153 int x2 = SX + (SXSIZE - strlen(WINDOW_SUBTITLE_STRING) * font2_width) / 2;
155 DrawText(x1, SY + 8, PROGRAM_TITLE_STRING, FONT_TITLE_1);
156 DrawText(x2, SY + 46, WINDOW_SUBTITLE_STRING, FONT_TITLE_2);
159 static void ToggleFullscreenIfNeeded()
161 if (setup.fullscreen != video.fullscreen_enabled)
163 /* save old door content */
164 BlitBitmap(backbuffer, bitmap_db_door,
165 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
167 /* toggle fullscreen */
168 ChangeVideoModeIfNeeded(setup.fullscreen);
169 setup.fullscreen = video.fullscreen_enabled;
171 /* redraw background to newly created backbuffer */
172 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
173 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
175 /* restore old door content */
176 BlitBitmap(bitmap_db_door, backbuffer,
177 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
179 redraw_mask = REDRAW_ALL;
185 static LevelDirTree *leveldir_last_valid = NULL;
186 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
187 int font_width = getFontWidth(FONT_MENU_1);
188 int name_width = font_width * strlen("Name:");
189 int level_width = font_width * strlen("Level:");
193 mSX = SX + global.menu_draw_xoffset;
194 mSY = SY + global.menu_draw_yoffset;
200 KeyboardAutoRepeatOn();
203 SetDrawDeactivationMask(REDRAW_NONE);
204 SetDrawBackgroundMask(REDRAW_FIELD);
206 audio.sound_deactivated = FALSE;
208 /* needed if last screen was the playing screen, invoked from level editor */
209 if (level_editor_test_game)
211 game_status = LEVELED;
216 /* needed if last screen was the editor screen */
217 UndrawSpecialEditorDoor();
219 /* needed if last screen was the setup screen and fullscreen state changed */
220 ToggleFullscreenIfNeeded();
222 /* needed if last screen (level choice) changed graphics, sounds or music */
223 ReloadCustomArtwork();
226 SetDrawtoField(DRAW_BACKBUFFER);
229 /* map gadgets for main menu screen */
232 /* leveldir_current may be invalid (level group, parent link) */
233 if (!validLevelSeries(leveldir_current))
234 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
236 /* store valid level series information */
237 leveldir_last_valid = leveldir_current;
239 /* level_nr may have been set to value over handicap with level editor */
240 if (setup.handicap && level_nr > leveldir_current->handicap_level)
241 level_nr = leveldir_current->handicap_level;
246 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
251 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
252 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
253 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
254 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
255 DrawText(mSY + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
256 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
257 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
258 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
260 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT_1);
261 DrawText(mSX + level_width + 5 * 32, mSY + 3*32, int2str(level_nr,3),
264 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
266 DrawTextF(mSX + 32 + level_width - 2, mSY + 3*32 + 1, FONT_TEXT_3, "%d-%d",
267 leveldir_current->first_level, leveldir_current->last_level);
270 if (leveldir_current->readonly)
273 DrawTextF(mSX + level_width + 9*32 - 2,
274 mSY + 3*32 + 1 - 7, FONT_TEXT_3, "READ");
275 DrawTextF(mSX + level_width + 9*32 - 2,
276 mSY + 3*32 + 1 + 7, FONT_TEXT_3, "ONLY");
280 initCursor(i, (i == 1 || i == 6 ? IMG_MENU_BUTTON_RIGHT :IMG_MENU_BUTTON));
282 drawCursorXY(level_width/32 + 4, 1, IMG_MENU_BUTTON_LEFT);
283 drawCursorXY(level_width/32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
285 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment", FONT_TITLE_2);
289 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
292 if (TAPE_IS_EMPTY(tape))
294 DrawCompleteVideoDisplay();
296 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
303 static void gotoTopLevelDir()
305 /* move upwards to top level directory */
306 while (leveldir_current->node_parent)
308 /* write a "path" into level tree for easy navigation to last level */
309 if (leveldir_current->node_parent->node_group->cl_first == -1)
311 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
312 int leveldir_pos = posTreeInfo(leveldir_current);
313 int num_page_entries;
314 int cl_first, cl_cursor;
316 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
317 num_page_entries = num_leveldirs;
319 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
321 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
322 cl_cursor = leveldir_pos - cl_first;
324 leveldir_current->node_parent->node_group->cl_first = cl_first;
325 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
328 leveldir_current = leveldir_current->node_parent;
332 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
334 static int choice = 0;
338 if (button == MB_MENU_INITIALIZE)
340 drawCursor(choice, FC_RED);
344 if (mx || my) /* mouse input */
347 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
349 else if (dx || dy) /* keyboard input */
351 if (dx && choice == 1)
352 x = (dx < 0 ? 10 : 14);
357 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
358 (x == 14 && level_nr < leveldir_current->last_level)) &&
361 static unsigned long level_delay = 0;
362 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
363 int new_level_nr, old_level_nr = level_nr;
365 new_level_nr = level_nr + (x == 10 ? -step : +step);
366 if (new_level_nr < leveldir_current->first_level)
367 new_level_nr = leveldir_current->first_level;
368 if (new_level_nr > leveldir_current->last_level)
369 new_level_nr = leveldir_current->last_level;
371 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
372 new_level_nr = leveldir_current->handicap_level;
374 if (old_level_nr == new_level_nr ||
375 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
378 level_nr = new_level_nr;
380 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
383 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
387 DrawCompleteVideoDisplay();
389 /* needed because DrawMicroLevel() takes some time */
392 DelayReached(&level_delay, 0); /* reset delay counter */
394 else if (x == 0 && y >= 0 && y <= 7)
400 drawCursor(y, FC_RED);
401 drawCursor(choice, FC_BLUE);
409 game_status = TYPENAME;
410 HandleTypeName(strlen(setup.player_name), 0);
416 game_status = CHOOSELEVEL;
417 SaveLevelSetup_LastSeries();
418 SaveLevelSetup_SeriesInfo();
427 game_status = HALLOFFAME;
432 if (leveldir_current->readonly &&
433 strcmp(setup.player_name, "Artsoft") != 0)
434 Request("This level is read only !", REQ_CONFIRM);
435 game_status = LEVELED;
440 game_status = HELPSCREEN;
445 if (setup.autorecord)
446 TapeStartRecording();
448 #if defined(PLATFORM_UNIX)
450 SendToServer_StartPlaying();
454 game_status = PLAYING;
462 setup_mode = SETUP_MODE_MAIN;
467 SaveLevelSetup_LastSeries();
468 SaveLevelSetup_SeriesInfo();
469 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
470 game_status = EXITGAME;
479 if (game_status == MAINMENU)
481 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
487 #define MAX_HELPSCREEN_ELS 10
491 static long helpscreen_state;
492 static int helpscreen_step[MAX_HELPSCREEN_ELS];
493 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
495 static int helpscreen_action[] =
497 IMG_PLAYER_1_MOVING_DOWN, 16,
498 IMG_PLAYER_1_MOVING_UP, 16,
499 IMG_PLAYER_1_MOVING_LEFT, 16,
500 IMG_PLAYER_1_MOVING_RIGHT, 16,
501 IMG_PLAYER_1_PUSHING_LEFT, 16,
502 IMG_PLAYER_1_PUSHING_RIGHT, 16, HA_NEXT,
504 IMG_SAND, -1, HA_NEXT,
506 IMG_EMPTY_SPACE, -1, HA_NEXT,
508 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
510 IMG_STEELWALL, -1, HA_NEXT,
512 IMG_WALL, -1, HA_NEXT,
514 IMG_EXPANDABLE_WALL_GROWING_LEFT, 20,
517 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 20,
520 IMG_EXPANDABLE_WALL_GROWING_UP, 20,
523 IMG_EXPANDABLE_WALL_GROWING_DOWN, 20,
525 IMG_EMPTY_SPACE, 20, HA_NEXT,
527 IMG_INVISIBLE_WALL, -1, HA_NEXT,
529 IMG_WALL_CRUMBLED, -1, HA_NEXT,
531 IMG_FONT_GAME_INFO, -1, HA_NEXT,
533 IMG_EMERALD, -1, HA_NEXT,
535 IMG_DIAMOND, -1, HA_NEXT,
537 IMG_BD_DIAMOND, -1, HA_NEXT,
539 IMG_EMERALD_YELLOW, 50,
541 IMG_EMERALD_PURPLE, 50, HA_NEXT,
543 IMG_BD_ROCK, -1, HA_NEXT,
547 IMG_EMPTY_SPACE, 10, HA_NEXT,
551 IMG_EMERALD, 20, HA_NEXT,
553 IMG_WALL_EMERALD, 100,
555 IMG_EMERALD, 20, HA_NEXT,
557 IMG_WALL_DIAMOND, 100,
559 IMG_DIAMOND, 20, HA_NEXT,
561 IMG_WALL_BD_DIAMOND, 100,
563 IMG_BD_DIAMOND, 20, HA_NEXT,
565 IMG_WALL_EMERALD_YELLOW, 100,
567 IMG_EMERALD_YELLOW, 20,
568 IMG_WALL_EMERALD_RED, 100,
571 IMG_WALL_EMERALD_PURPLE, 100,
573 IMG_EMERALD_PURPLE, 20, HA_NEXT,
575 IMG_ACID, -1, HA_NEXT,
580 IMG_KEY_4, 50, HA_NEXT,
585 IMG_GATE_4, 50, HA_NEXT,
590 IMG_GATE_4_GRAY, 50, HA_NEXT,
592 IMG_DYNAMITE, -1, HA_NEXT,
594 IMG_DYNAMITE_ACTIVE, 96,
596 IMG_EMPTY_SPACE, 20, HA_NEXT,
598 IMG_DYNABOMB_ACTIVE, 100,
600 IMG_EMPTY_SPACE, 20, HA_NEXT,
602 IMG_DYNABOMB_INCREASE_NUMBER, -1, HA_NEXT,
604 IMG_DYNABOMB_INCREASE_SIZE, -1, HA_NEXT,
606 IMG_DYNABOMB_INCREASE_POWER, -1, HA_NEXT,
608 IMG_SPACESHIP_RIGHT, 16,
609 IMG_SPACESHIP_UP, 16,
610 IMG_SPACESHIP_LEFT, 16,
611 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
616 IMG_BUG_DOWN, 16, HA_NEXT,
618 IMG_BD_BUTTERFLY, -1, HA_NEXT,
620 IMG_BD_FIREFLY, -1, HA_NEXT,
622 IMG_PACMAN_RIGHT, 16,
625 IMG_PACMAN_DOWN, 16, HA_NEXT,
627 IMG_YAMYAM, -1, HA_NEXT,
629 IMG_DARK_YAMYAM, -1, HA_NEXT,
631 IMG_ROBOT, -1, HA_NEXT,
633 IMG_MOLE_MOVING_RIGHT, 16,
634 IMG_MOLE_MOVING_UP, 16,
635 IMG_MOLE_MOVING_LEFT, 16,
636 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
638 IMG_PENGUIN_MOVING_RIGHT, 16,
639 IMG_PENGUIN_MOVING_UP, 16,
640 IMG_PENGUIN_MOVING_LEFT, 16,
641 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
643 IMG_PIG_MOVING_RIGHT, 16,
644 IMG_PIG_MOVING_UP, 16,
645 IMG_PIG_MOVING_LEFT, 16,
646 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
648 IMG_DRAGON_MOVING_RIGHT, 16,
649 IMG_DRAGON_MOVING_UP, 16,
650 IMG_DRAGON_MOVING_LEFT, 16,
651 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
653 IMG_SATELLITE, -1, HA_NEXT,
656 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
659 IMG_LAMP_ACTIVE, 50, HA_NEXT,
661 IMG_TIME_ORB_FULL, 50,
662 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
665 IMG_AMOEBA_GROWING, 6,
666 IMG_AMOEBA_WET, 20, HA_NEXT,
668 IMG_AMOEBA_DEAD, -1, HA_NEXT,
670 IMG_AMOEBA_WET, -1, HA_NEXT,
673 IMG_AMOEBA_GROWING, 6, HA_NEXT,
678 IMG_DIAMOND, 20, HA_NEXT,
680 IMG_GAME_OF_LIFE, -1, HA_NEXT,
682 IMG_BIOMAZE, -1, HA_NEXT,
684 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
686 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
688 IMG_EXIT_CLOSED, 200,
689 IMG_EXIT_OPENING, 16,
690 IMG_EXIT_OPEN, 100, HA_NEXT,
692 IMG_EXIT_OPEN, -1, HA_NEXT,
694 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
696 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
698 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
700 IMG_SPEED_PILL, -1, HA_NEXT,
704 static char *helpscreen_eltext[][2] =
706 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
707 {"Normal sand:", "You can dig through it"},
708 {"Empty field:", "You can walk through it"},
709 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
710 {"Massive Wall:", "Nothing can go through it"},
711 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
712 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
713 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
714 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
715 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
716 {"Emerald: You must collect enough of","them to finish a level"},
717 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
718 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
719 {"Colorful Gems:", "Seem to behave like Emeralds"},
720 {"Rock: Smashes several things;", "Can be moved by the player"},
721 {"Bomb: You can move it, but be", "careful when dropping it"},
722 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
723 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
724 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
725 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
726 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
727 {"Acid: Things that fall in are gone", "forever (including our hero)"},
728 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
729 {"Door: Can be opened by the key", "with the same color"},
730 {"Door: You have to find out the", "right color of the key for it"},
731 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
732 {"Dynamite: This one explodes after", "a few seconds"},
733 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
734 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
735 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
736 {"Dyna Bomb: Increases the power of", "explosion of dyna bombs"},
737 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
738 {"Bug: Moves at the right side", "of walls; don't touch it!"},
739 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
740 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
741 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
742 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
743 {"Cruncher (BD style):", "Eats almost everything"},
744 {"Robot: Tries to kill the player", ""},
745 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
746 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
747 {"The Pig: Harmless, but eats all", "gems it can get"},
748 {"The Dragon: Breathes fire,", "especially to some monsters"},
749 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
750 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
751 {"Light Bulb: All of them must be", "switched on to finish a level"},
752 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
753 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
754 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
755 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
756 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
757 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
758 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
759 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
760 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
761 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
762 {"Exit door: Opens if you have enough","emeralds to finish the level"},
763 {"Open exit door: Enter here to leave","the level and exit the actual game"},
764 {"Sokoban element: Object which must", "be pushed to an empty field"},
765 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
766 {"Sokoban element: Field with object", "which can be pushed away"},
767 {"Speed pill: Lets the player run", "twice as fast as normally"},
769 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
771 static char *helpscreen_music[][3] =
773 { "Alchemy", "Ian Boddy", "Drive" },
774 { "The Chase", "Propaganda", "A Secret Wish" },
775 { "Network 23", "Tangerine Dream", "Exit" },
776 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
777 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
778 { "Voyager", "The Alan Parsons Project","Pyramid" },
779 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
781 static int num_helpscreen_music = 7;
782 static int helpscreen_musicpos;
785 void OLD_DrawHelpScreenElAction(int start)
789 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
791 while(helpscreen_action[j] != HA_END)
793 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
795 else if (i<start || helpscreen_delay[i-start])
797 if (i>=start && helpscreen_delay[i-start])
798 helpscreen_delay[i-start]--;
800 while(helpscreen_action[j] != HA_NEXT)
807 j += 3*helpscreen_step[i-start];
808 graphic = helpscreen_action[j++];
810 if (helpscreen_frame[i-start])
812 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
813 helpscreen_frame[i-start]--;
818 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
821 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
823 if (helpscreen_action[j] == HA_NEXT)
825 if (!helpscreen_frame[i-start])
826 helpscreen_step[i-start] = 0;
830 if (!helpscreen_frame[i-start])
831 helpscreen_step[i-start]++;
832 while(helpscreen_action[j] != HA_NEXT)
837 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
849 void DrawHelpScreenElAction(int start)
852 int xstart = mSX + 16;
853 int ystart = mSY + 64 + 2 * 32;
854 int ystep = TILEY + 4;
860 while (helpscreen_action[j] != HA_END)
862 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
866 while (helpscreen_action[j] != HA_NEXT)
875 j += 2 * helpscreen_step[i-start];
876 graphic = helpscreen_action[j++];
877 frame_count = helpscreen_action[j++];
878 if (frame_count == -1)
879 frame_count = 1000000;
881 if (helpscreen_frame[i-start] == 0)
884 helpscreen_frame[i-start] = frame_count - 1;
888 sync_frame = frame_count - helpscreen_frame[i-start];
889 helpscreen_frame[i-start]--;
892 if (helpscreen_action[j] == HA_NEXT)
894 if (!helpscreen_frame[i-start])
895 helpscreen_step[i-start] = 0;
899 if (!helpscreen_frame[i-start])
900 helpscreen_step[i-start]++;
901 while(helpscreen_action[j] != HA_NEXT)
906 frame = getGraphicAnimationFrame(graphic, sync_frame);
908 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
923 void DrawHelpScreenElText(int start)
926 int xstart = mSX + 56, ystart = mSY + 65 + 2 * 32, ystep = TILEY + 4;
927 int ybottom = SYSIZE - 20;
929 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
933 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
935 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
938 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
939 helpscreen_eltext[i][0], FONT_TEXT_2);
940 DrawText(xstart, ystart + (i - start) * ystep + 16,
941 helpscreen_eltext[i][1], FONT_TEXT_2);
944 DrawTextFCentered(ybottom, FONT_TEXT_4,
945 "Press any key or button for next page");
948 void DrawHelpScreenMusicText(int num)
950 int ystart = 150, ystep = 30;
951 int ybottom = SYSIZE - 20;
957 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
959 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
960 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
961 "\"%s\"", helpscreen_music[num][0]);
962 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
963 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
964 "%s", helpscreen_music[num][1]);
965 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
966 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
967 "\"%s\"", helpscreen_music[num][2]);
969 DrawTextFCentered(ybottom, FONT_TEXT_4,
970 "Press any key or button for next page");
973 PlaySoundLoop(background_loop[num]);
977 void DrawHelpScreenCreditsText()
979 int ystart = 150, ystep = 30;
980 int ybottom = SYSIZE - 20;
986 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
987 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
988 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
989 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
990 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
991 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
992 "...and many thanks to all contributors");
993 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
995 DrawTextFCentered(ybottom, FONT_TEXT_4,
996 "Press any key or button for next page");
999 void DrawHelpScreenContactText()
1001 int ystart = 150, ystep = 30;
1002 int ybottom = SYSIZE - 20;
1007 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1009 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1010 "This game is Freeware!");
1011 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1012 "If you like it, send e-mail to:");
1013 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1014 "info@artsoft.org");
1015 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1016 "or SnailMail to:");
1017 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1019 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1020 "Detmolder Strasse 189");
1021 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1023 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1026 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1027 "If you have created new levels,");
1028 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1029 "send them to me to include them!");
1030 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1033 DrawTextFCentered(ybottom, FONT_TEXT_4,
1034 "Press any key or button for main menu");
1037 void DrawHelpScreen()
1042 CloseDoor(DOOR_CLOSE_2);
1044 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1045 helpscreen_step[i] = helpscreen_frame[i] = 0;
1046 helpscreen_musicpos = 0;
1047 helpscreen_state = 0;
1049 DrawHelpScreenElText(0);
1050 DrawHelpScreenElAction(0);
1056 PlaySoundLoop(SND_BACKGROUND_INFO);
1058 PlaySound_Menu_Start(SND_BACKGROUND_INFO);
1062 void HandleHelpScreen(int button)
1064 static unsigned long hs_delay = 0;
1065 int num_helpscreen_els_pages =
1066 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1067 int button_released = !button;
1070 if (button_released)
1072 if (helpscreen_state < num_helpscreen_els_pages - 1)
1074 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1075 helpscreen_step[i] = helpscreen_frame[i] = 0;
1079 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1080 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1082 else if (helpscreen_state <
1083 num_helpscreen_els_pages + num_helpscreen_music - 1)
1086 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1088 else if (helpscreen_state ==
1089 num_helpscreen_els_pages + num_helpscreen_music - 1)
1092 DrawHelpScreenCreditsText();
1094 else if (helpscreen_state ==
1095 num_helpscreen_els_pages + num_helpscreen_music)
1098 DrawHelpScreenContactText();
1104 game_status = MAINMENU;
1110 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1112 if (helpscreen_state < num_helpscreen_els_pages)
1113 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1116 /* !!! workaround for playing "music" that is really a sound loop (and
1117 must therefore periodically be reactivated with the current sound
1120 PlaySoundLoop(SND_BACKGROUND_INFO);
1122 PlaySound_Menu_Continue(SND_BACKGROUND_INFO);
1131 void HandleTypeName(int newxpos, Key key)
1133 static int xpos = 0, ypos = 2;
1134 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1135 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1136 int startx = mSX + 32 + name_width;
1137 int starty = mSY + ypos * 32;
1143 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1144 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1149 if (((key >= KSYM_A && key <= KSYM_Z) ||
1150 (key >= KSYM_a && key <= KSYM_z)) &&
1151 xpos < MAX_PLAYER_NAME_LEN)
1155 if (key >= KSYM_A && key <= KSYM_Z)
1156 ascii = 'A' + (char)(key - KSYM_A);
1158 ascii = 'a' + (char)(key - KSYM_a);
1160 setup.player_name[xpos] = ascii;
1161 setup.player_name[xpos + 1] = 0;
1164 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1165 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1167 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1170 setup.player_name[xpos] = 0;
1172 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1174 else if (key == KSYM_Return && xpos > 0)
1176 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1177 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1180 game_status = MAINMENU;
1186 static void DrawChooseTree(TreeInfo **ti_ptr)
1189 CloseDoor(DOOR_CLOSE_2);
1193 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1194 MapChooseTreeGadgets(*ti_ptr);
1200 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1202 struct GadgetInfo *gi = screen_gadget[id];
1203 int items_max, items_visible, item_position;
1205 items_max = numTreeInfoInGroup(ti);
1206 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1207 item_position = first_entry;
1209 if (item_position > items_max - items_visible)
1210 item_position = items_max - items_visible;
1212 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1213 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1216 static void drawChooseTreeList(int first_entry, int num_page_entries,
1220 char buffer[SCR_FIELDX * 2];
1221 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1222 int num_entries = numTreeInfoInGroup(ti);
1223 char *title_string = NULL;
1224 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
1225 int last_game_status = game_status; /* save current game status */
1227 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1228 redraw_mask |= REDRAW_FIELD;
1231 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1232 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1233 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1234 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1236 DrawText(SX + offset, SY + offset, title_string, FONT_TITLE_1);
1238 game_status = CHOOSELEVEL; /* force LEVELS font on artwork setup screen */
1240 for(i=0; i<num_page_entries; i++)
1242 TreeInfo *node, *node_first;
1243 int entry_pos = first_entry + i;
1244 int ypos = MENU_SCREEN_START_YPOS + i;
1246 node_first = getTreeInfoFirstGroupEntry(ti);
1247 node = getTreeInfoFromPos(node_first, entry_pos);
1249 strncpy(buffer, node->name , max_buffer_len);
1250 buffer[max_buffer_len] = '\0';
1252 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1254 if (node->parent_link)
1255 initCursor(i, IMG_MENU_BUTTON_LEFT);
1256 else if (node->level_group)
1257 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1259 initCursor(i, IMG_MENU_BUTTON);
1262 if (first_entry > 0)
1266 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1267 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_UP, 0);
1270 if (first_entry + num_page_entries < num_entries)
1272 int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
1274 DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
1275 DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_DOWN, 0);
1278 game_status = last_game_status; /* restore current game status */
1281 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1283 TreeInfo *node, *node_first;
1284 int x, last_redraw_mask = redraw_mask;
1286 if (ti->type != TREE_TYPE_LEVEL_DIR)
1289 node_first = getTreeInfoFirstGroupEntry(ti);
1290 node = getTreeInfoFromPos(node_first, entry_pos);
1292 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1294 if (node->parent_link)
1295 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1297 else if (node->level_group)
1298 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1300 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1301 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1302 node->levels, node->class_desc);
1304 /* let BackToFront() redraw only what is needed */
1305 redraw_mask = last_redraw_mask | REDRAW_TILES;
1306 for (x=0; x<SCR_FIELDX; x++)
1307 MarkTileDirty(x, 1);
1310 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1313 static unsigned long choose_delay = 0;
1314 TreeInfo *ti = *ti_ptr;
1316 int y = ti->cl_cursor;
1317 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1318 int num_entries = numTreeInfoInGroup(ti);
1319 int num_page_entries;
1321 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1322 num_page_entries = num_entries;
1324 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1326 if (button == MB_MENU_INITIALIZE)
1328 int entry_pos = posTreeInfo(ti);
1330 if (ti->cl_first == -1)
1332 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1334 entry_pos - ti->cl_first;
1337 if (dx == 999) /* first entry is set by scrollbar position */
1340 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1343 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1344 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1345 drawCursor(ti->cl_cursor, FC_RED);
1348 else if (button == MB_MENU_LEAVE)
1350 if (ti->node_parent)
1352 *ti_ptr = ti->node_parent;
1353 DrawChooseTree(ti_ptr);
1355 else if (game_status == SETUP)
1361 game_status = MAINMENU;
1368 if (mx || my) /* mouse input */
1371 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1373 else if (dx || dy) /* keyboard input */
1376 y = ti->cl_cursor + dy;
1378 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1381 step = num_page_entries - 1;
1382 y = (dy < 0 ? -1 : num_page_entries);
1386 if (x == 0 && y == -1)
1388 if (ti->cl_first > 0 &&
1389 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1391 ti->cl_first -= step;
1392 if (ti->cl_first < 0)
1395 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1396 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1397 drawCursor(ti->cl_cursor, FC_RED);
1398 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1403 else if (x == 0 && y > num_page_entries - 1)
1405 if (ti->cl_first + num_page_entries < num_entries &&
1406 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1408 ti->cl_first += step;
1409 if (ti->cl_first + num_page_entries > num_entries)
1410 ti->cl_first = MAX(0, num_entries - num_page_entries);
1412 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1413 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1414 drawCursor(ti->cl_cursor, FC_RED);
1415 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1423 TreeInfo *node_first, *node_cursor;
1424 int entry_pos = ti->cl_first + y;
1426 node_first = getTreeInfoFirstGroupEntry(ti);
1427 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1429 if (node_cursor->node_group)
1431 node_cursor->cl_first = ti->cl_first;
1432 node_cursor->cl_cursor = ti->cl_cursor;
1433 *ti_ptr = node_cursor->node_group;
1434 DrawChooseTree(ti_ptr);
1438 else if (dx == -1 && ti->node_parent)
1440 *ti_ptr = ti->node_parent;
1441 DrawChooseTree(ti_ptr);
1445 if (x == 0 && y >= 0 && y < num_page_entries)
1449 if (y != ti->cl_cursor)
1451 drawCursor(y, FC_RED);
1452 drawCursor(ti->cl_cursor, FC_BLUE);
1453 drawChooseTreeInfo(ti->cl_first + y, ti);
1459 TreeInfo *node_first, *node_cursor;
1460 int entry_pos = ti->cl_first + y;
1462 node_first = getTreeInfoFirstGroupEntry(ti);
1463 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1465 if (node_cursor->node_group)
1467 node_cursor->cl_first = ti->cl_first;
1468 node_cursor->cl_cursor = ti->cl_cursor;
1469 *ti_ptr = node_cursor->node_group;
1470 DrawChooseTree(ti_ptr);
1472 else if (node_cursor->parent_link)
1474 *ti_ptr = node_cursor->node_parent;
1475 DrawChooseTree(ti_ptr);
1479 node_cursor->cl_first = ti->cl_first;
1480 node_cursor->cl_cursor = ti->cl_cursor;
1481 *ti_ptr = node_cursor;
1483 if (ti->type == TREE_TYPE_LEVEL_DIR)
1485 LoadLevelSetup_SeriesInfo();
1487 SaveLevelSetup_LastSeries();
1488 SaveLevelSetup_SeriesInfo();
1492 if (game_status == SETUP)
1498 game_status = MAINMENU;
1507 if (game_status == CHOOSELEVEL || game_status == SETUP)
1511 void DrawChooseLevel()
1513 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1515 DrawChooseTree(&leveldir_current);
1518 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1520 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1523 void DrawHallOfFame(int highlight_position)
1527 CloseDoor(DOOR_CLOSE_2);
1529 if (highlight_position < 0)
1530 LoadScore(level_nr);
1535 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1538 PlaySound(SND_BACKGROUND_SCORES);
1540 PlaySound_Menu_Start(SND_BACKGROUND_SCORES);
1544 static void drawHallOfFameList(int first_entry, int highlight_position)
1548 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1551 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1552 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1554 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1556 int entry = first_entry + i;
1558 DrawText(mSX, mSY + 64 + i * 32, "..................................",
1559 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1560 DrawText(mSX, mSY + 64 + i * 32, int2str(entry + 1, 3),
1561 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1562 DrawText(mSX + 64, mSY + 64 + i * 32, highscore[entry].Name,
1563 (entry == highlight_position ? FONT_TEXT_3 : FONT_TEXT_1));
1564 DrawText(mSX + 14 * 32 + 16, mSY + 64 + i * 32,
1565 int2str(highscore[entry].Score, 5),
1566 (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
1570 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1572 static int first_entry = 0;
1573 static int highlight_position = 0;
1574 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1575 int button_released = !button;
1577 if (button == MB_MENU_INITIALIZE)
1580 highlight_position = mx;
1581 drawHallOfFameList(first_entry, highlight_position);
1585 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1586 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1590 if (first_entry > 0)
1592 first_entry -= step;
1593 if (first_entry < 0)
1596 drawHallOfFameList(first_entry, highlight_position);
1602 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1604 first_entry += step;
1605 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1606 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1608 drawHallOfFameList(first_entry, highlight_position);
1613 if (button_released)
1615 FadeSound(SND_BACKGROUND_SCORES);
1616 game_status = MAINMENU;
1622 if (game_status == HALLOFFAME)
1626 PlaySound_Menu_Continue(SND_BACKGROUND_SCORES);
1632 /* ========================================================================= */
1633 /* setup screen functions */
1634 /* ========================================================================= */
1636 static struct TokenInfo *setup_info;
1637 static int num_setup_info;
1639 static char *graphics_set_name;
1640 static char *sounds_set_name;
1641 static char *music_set_name;
1643 static void execSetupMain()
1645 setup_mode = SETUP_MODE_MAIN;
1649 static void execSetupGame()
1651 setup_mode = SETUP_MODE_GAME;
1655 static void execSetupEditor()
1657 setup_mode = SETUP_MODE_EDITOR;
1661 static void execSetupGraphics()
1663 setup_mode = SETUP_MODE_GRAPHICS;
1667 static void execSetupSound()
1669 setup_mode = SETUP_MODE_SOUND;
1673 static void execSetupArtwork()
1675 /* needed if last screen (setup choice) changed graphics, sounds or music */
1676 ReloadCustomArtwork();
1678 setup.graphics_set = artwork.gfx_current->identifier;
1679 setup.sounds_set = artwork.snd_current->identifier;
1680 setup.music_set = artwork.mus_current->identifier;
1682 /* needed for displaying artwork name instead of artwork identifier */
1683 graphics_set_name = artwork.gfx_current->name;
1684 sounds_set_name = artwork.snd_current->name;
1685 music_set_name = artwork.mus_current->name;
1687 setup_mode = SETUP_MODE_ARTWORK;
1691 static void execSetupChooseGraphics()
1693 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1697 static void execSetupChooseSounds()
1699 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1703 static void execSetupChooseMusic()
1705 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1709 static void execSetupInput()
1711 setup_mode = SETUP_MODE_INPUT;
1715 static void execSetupShortcut()
1717 setup_mode = SETUP_MODE_SHORTCUT;
1721 static void execExitSetup()
1723 game_status = MAINMENU;
1727 static void execSaveAndExitSetup()
1733 static struct TokenInfo setup_info_main[] =
1735 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1736 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1737 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1738 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1739 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1740 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1741 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1742 { TYPE_EMPTY, NULL, "" },
1743 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1744 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1748 static struct TokenInfo setup_info_game[] =
1750 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1751 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1752 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1753 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1754 { TYPE_EMPTY, NULL, "" },
1755 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1759 static struct TokenInfo setup_info_editor[] =
1761 { TYPE_STRING, NULL, "Offer Special Elements:"},
1762 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1763 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1764 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1765 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1766 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1767 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1768 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1769 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1770 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1771 { TYPE_EMPTY, NULL, "" },
1772 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1776 static struct TokenInfo setup_info_graphics[] =
1778 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1779 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1780 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1782 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1783 { TYPE_SWITCH, &setup.fading, "Fading:" },
1785 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1786 { TYPE_SWITCH, &setup.toons, "Toons:" },
1787 { TYPE_EMPTY, NULL, "" },
1788 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1792 static struct TokenInfo setup_info_sound[] =
1794 { TYPE_SWITCH, &setup.sound, "Sound:", },
1795 { TYPE_EMPTY, NULL, "" },
1796 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1797 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1798 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1799 { TYPE_EMPTY, NULL, "" },
1800 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1804 static struct TokenInfo setup_info_artwork[] =
1806 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1807 { TYPE_STRING, &graphics_set_name, "" },
1808 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1809 { TYPE_STRING, &sounds_set_name, "" },
1810 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1811 { TYPE_STRING, &music_set_name, "" },
1812 { TYPE_EMPTY, NULL, "" },
1813 { TYPE_STRING, NULL, "Override Level Artwork:"},
1814 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1815 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1816 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1817 { TYPE_EMPTY, NULL, "" },
1818 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1822 static struct TokenInfo setup_info_shortcut[] =
1824 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1825 { TYPE_KEY, &setup.shortcut.save_game, "" },
1826 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1827 { TYPE_KEY, &setup.shortcut.load_game, "" },
1828 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1829 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1830 { TYPE_EMPTY, NULL, "" },
1831 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1832 { TYPE_EMPTY, NULL, "" },
1833 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1837 static Key getSetupKey()
1839 Key key = KSYM_UNDEFINED;
1840 boolean got_key_event = FALSE;
1842 while (!got_key_event)
1844 if (PendingEvent()) /* got event */
1852 case EVENT_KEYPRESS:
1854 key = GetEventKey((KeyEvent *)&event, TRUE);
1856 /* press 'Escape' or 'Enter' to keep the existing key binding */
1857 if (key == KSYM_Escape || key == KSYM_Return)
1858 key = KSYM_UNDEFINED; /* keep old value */
1860 got_key_event = TRUE;
1864 case EVENT_KEYRELEASE:
1865 key_joystick_mapping = 0;
1869 HandleOtherEvents(&event);
1877 /* don't eat all CPU time */
1884 static void drawSetupValue(int pos)
1886 int xpos = MENU_SCREEN_VALUE_XPOS;
1887 int ypos = MENU_SCREEN_START_YPOS + pos;
1888 int font_nr = FONT_VALUE_1;
1889 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1890 setup_info[pos].value);
1892 if (value_string == NULL)
1895 if (setup_info[pos].type & TYPE_KEY)
1899 if (setup_info[pos].type & TYPE_QUERY)
1901 value_string = "<press key>";
1902 font_nr = FONT_INPUT_1_ACTIVE;
1905 else if (setup_info[pos].type & TYPE_STRING)
1907 int max_value_len = (SCR_FIELDX - 2) * 2;
1910 font_nr = FONT_VALUE_2;
1912 if (strlen(value_string) > max_value_len)
1913 value_string[max_value_len] = '\0';
1915 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
1916 !*(boolean *)(setup_info[pos].value))
1917 font_nr = FONT_OPTION_OFF;
1919 DrawText(mSX + xpos * 32, mSY + ypos * 32,
1920 (xpos == 3 ? " " : " "), font_nr);
1921 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
1924 static void changeSetupValue(int pos)
1926 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1928 *(boolean *)setup_info[pos].value ^= TRUE;
1930 else if (setup_info[pos].type & TYPE_KEY)
1934 setup_info[pos].type |= TYPE_QUERY;
1935 drawSetupValue(pos);
1936 setup_info[pos].type &= ~TYPE_QUERY;
1938 key = getSetupKey();
1939 if (key != KSYM_UNDEFINED)
1940 *(Key *)setup_info[pos].value = key;
1943 drawSetupValue(pos);
1946 static void DrawSetupScreen_Generic()
1948 char *title_string = NULL;
1952 CloseDoor(DOOR_CLOSE_2);
1956 if (setup_mode == SETUP_MODE_MAIN)
1958 setup_info = setup_info_main;
1959 title_string = "Setup";
1961 else if (setup_mode == SETUP_MODE_GAME)
1963 setup_info = setup_info_game;
1964 title_string = "Setup Game";
1966 else if (setup_mode == SETUP_MODE_EDITOR)
1968 setup_info = setup_info_editor;
1969 title_string = "Setup Editor";
1971 else if (setup_mode == SETUP_MODE_GRAPHICS)
1973 setup_info = setup_info_graphics;
1974 title_string = "Setup Graphics";
1976 else if (setup_mode == SETUP_MODE_SOUND)
1978 setup_info = setup_info_sound;
1979 title_string = "Setup Sound";
1981 else if (setup_mode == SETUP_MODE_ARTWORK)
1983 setup_info = setup_info_artwork;
1984 title_string = "Custom Artwork";
1986 else if (setup_mode == SETUP_MODE_SHORTCUT)
1988 setup_info = setup_info_shortcut;
1989 title_string = "Setup Shortcuts";
1992 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
1995 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1997 void *value_ptr = setup_info[i].value;
1998 int ypos = MENU_SCREEN_START_YPOS + i;
1999 int font_nr = FONT_MENU_1;
2001 /* set some entries to "unchangeable" according to other variables */
2002 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2003 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2004 (value_ptr == &setup.sound_music && !audio.music_available) ||
2005 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2006 setup_info[i].type |= TYPE_GHOSTED;
2008 if (setup_info[i].type & TYPE_STRING)
2009 font_nr = FONT_MENU_2;
2011 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2013 if (setup_info[i].type & TYPE_ENTER_MENU)
2014 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2015 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2016 initCursor(i, IMG_MENU_BUTTON_LEFT);
2017 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2018 initCursor(i, IMG_MENU_BUTTON);
2020 if (setup_info[i].type & TYPE_VALUE)
2028 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2031 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2033 static int choice_store[MAX_SETUP_MODES];
2034 int choice = choice_store[setup_mode]; /* always starts with 0 */
2038 if (button == MB_MENU_INITIALIZE)
2040 /* advance to first valid menu entry */
2041 while (choice < num_setup_info &&
2042 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2044 choice_store[setup_mode] = choice;
2046 drawCursor(choice, FC_RED);
2049 else if (button == MB_MENU_LEAVE)
2051 for (y=0; y<num_setup_info; y++)
2053 if (setup_info[y].type & TYPE_LEAVE_MENU)
2055 void (*menu_callback_function)(void) = setup_info[y].value;
2057 menu_callback_function();
2058 break; /* absolutely needed because function changes 'setup_info'! */
2065 if (mx || my) /* mouse input */
2068 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2070 else if (dx || dy) /* keyboard input */
2074 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2076 if ((setup_info[choice].type & menu_navigation_type) ||
2077 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2078 button = MB_MENU_CHOICE;
2083 /* jump to next non-empty menu entry (up or down) */
2084 while (y > 0 && y < num_setup_info - 1 &&
2085 (setup_info[y].type & TYPE_SKIP_ENTRY))
2089 if (x == 0 && y >= 0 && y < num_setup_info &&
2090 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2096 drawCursor(y, FC_RED);
2097 drawCursor(choice, FC_BLUE);
2098 choice = choice_store[setup_mode] = y;
2101 else if (!(setup_info[y].type & TYPE_GHOSTED))
2103 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2105 void (*menu_callback_function)(void) = setup_info[choice].value;
2107 menu_callback_function();
2111 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2112 (setup_info[y + 1].type & TYPE_KEY))
2115 if (setup_info[y].type & TYPE_VALUE)
2116 changeSetupValue(y);
2123 if (game_status == SETUP)
2127 void DrawSetupScreen_Input()
2131 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2133 initCursor(0, IMG_MENU_BUTTON);
2134 initCursor(1, IMG_MENU_BUTTON);
2135 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2136 initCursor(13, IMG_MENU_BUTTON_LEFT);
2138 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2139 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2141 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2142 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2143 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2146 DeactivateJoystickForCalibration();
2147 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2148 "Joysticks deactivated on this screen");
2151 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2156 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2158 if (device_name == NULL)
2161 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2164 if (strlen(device_name) > 1)
2166 char c1 = device_name[strlen(device_name) - 1];
2167 char c2 = device_name[strlen(device_name) - 2];
2169 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2170 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2173 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2174 strlen(device_name));
2177 static void drawPlayerSetupInputInfo(int player_nr)
2180 static struct SetupKeyboardInfo custom_key;
2187 { &custom_key.left, "Joystick Left" },
2188 { &custom_key.right, "Joystick Right" },
2189 { &custom_key.up, "Joystick Up" },
2190 { &custom_key.down, "Joystick Down" },
2191 { &custom_key.snap, "Button 1" },
2192 { &custom_key.bomb, "Button 2" }
2194 static char *joystick_name[MAX_PLAYERS] =
2202 custom_key = setup.input[player_nr].key;
2204 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2206 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2207 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2209 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2212 if (setup.input[player_nr].use_joystick)
2214 char *device_name = setup.input[player_nr].joy.device_name;
2216 DrawText(mSX+8*32, mSY+3*32,
2217 joystick_name[getJoystickNrFromDeviceName(device_name)],
2219 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2223 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2224 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2227 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2228 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2229 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2230 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2231 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2232 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2233 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2234 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2235 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2236 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2237 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2241 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2243 DrawText(mSX + 3*32, mSY + ypos*32,
2245 DrawText(mSX + 3*32, mSY + ypos*32,
2246 (setup.input[player_nr].use_joystick ?
2248 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2252 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2254 static int choice = 0;
2255 static int player_nr = 0;
2258 int pos_start = SETUPINPUT_SCREEN_POS_START;
2259 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2260 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2261 int pos_end = SETUPINPUT_SCREEN_POS_END;
2263 if (button == MB_MENU_INITIALIZE)
2265 drawPlayerSetupInputInfo(player_nr);
2266 drawCursor(choice, FC_RED);
2269 else if (button == MB_MENU_LEAVE)
2271 setup_mode = SETUP_MODE_MAIN;
2276 if (mx || my) /* mouse input */
2279 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
2281 else if (dx || dy) /* keyboard input */
2283 if (dx && choice == 0)
2284 x = (dx < 0 ? 10 : 12);
2285 else if ((dx && choice == 1) ||
2286 (dx == +1 && choice == 2) ||
2287 (dx == -1 && choice == pos_end))
2288 button = MB_MENU_CHOICE;
2292 if (y >= pos_empty1 && y <= pos_empty2)
2293 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2296 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2298 static unsigned long delay = 0;
2300 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2303 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2305 drawPlayerSetupInputInfo(player_nr);
2307 else if (x == 0 && y >= pos_start && y <= pos_end &&
2308 !(y >= pos_empty1 && y <= pos_empty2))
2314 drawCursor(y, FC_RED);
2315 drawCursor(choice, FC_BLUE);
2323 char *device_name = setup.input[player_nr].joy.device_name;
2325 if (!setup.input[player_nr].use_joystick)
2327 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2329 setJoystickDeviceToNr(device_name, new_device_nr);
2330 setup.input[player_nr].use_joystick = TRUE;
2334 int device_nr = getJoystickNrFromDeviceName(device_name);
2335 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2337 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2338 setup.input[player_nr].use_joystick = FALSE;
2340 setJoystickDeviceToNr(device_name, new_device_nr);
2343 drawPlayerSetupInputInfo(player_nr);
2347 if (setup.input[player_nr].use_joystick)
2350 CalibrateJoystick(player_nr);
2353 CustomizeKeyboard(player_nr);
2355 else if (y == pos_end)
2359 setup_mode = SETUP_MODE_MAIN;
2369 if (game_status == SETUP)
2373 void CustomizeKeyboard(int player_nr)
2377 boolean finished = FALSE;
2378 static struct SetupKeyboardInfo custom_key;
2383 } customize_step[] =
2385 { &custom_key.left, "Move Left" },
2386 { &custom_key.right, "Move Right" },
2387 { &custom_key.up, "Move Up" },
2388 { &custom_key.down, "Move Down" },
2389 { &custom_key.snap, "Snap Field" },
2390 { &custom_key.bomb, "Place Bomb" }
2393 /* read existing key bindings from player setup */
2394 custom_key = setup.input[player_nr].key;
2397 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2403 DrawText(mSX, mSY + (2+2*step_nr)*32,
2404 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2405 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2406 "Key:", FONT_INPUT_1_ACTIVE);
2407 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2408 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2412 if (PendingEvent()) /* got event */
2420 case EVENT_KEYPRESS:
2422 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2424 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2430 /* all keys configured -- wait for "Escape" or "Return" key */
2434 /* press 'Enter' to keep the existing key binding */
2435 if (key == KSYM_Return)
2436 key = *customize_step[step_nr].key;
2438 /* check if key already used */
2439 for (i=0; i<step_nr; i++)
2440 if (*customize_step[i].key == key)
2445 /* got new key binding */
2446 *customize_step[step_nr].key = key;
2447 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2449 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2450 getKeyNameFromKey(key), FONT_VALUE_1);
2453 /* un-highlight last query */
2454 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2455 customize_step[step_nr-1].text, FONT_MENU_1);
2456 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2457 "Key:", FONT_MENU_1);
2459 /* press 'Enter' to leave */
2462 DrawText(mSX + 16, mSY + 15*32+16,
2463 "Press Enter", FONT_TITLE_1);
2467 /* query next key binding */
2468 DrawText(mSX, mSY+(2+2*step_nr)*32,
2469 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2470 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2471 "Key:", FONT_INPUT_1_ACTIVE);
2472 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2473 getKeyNameFromKey(*customize_step[step_nr].key),
2478 case EVENT_KEYRELEASE:
2479 key_joystick_mapping = 0;
2483 HandleOtherEvents(&event);
2491 /* don't eat all CPU time */
2495 /* write new key bindings back to player setup */
2496 setup.input[player_nr].key = custom_key;
2499 DrawSetupScreen_Input();
2502 static boolean CalibrateJoystickMain(int player_nr)
2504 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2505 int new_joystick_xright = JOYSTICK_XMIDDLE;
2506 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2507 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2508 int new_joystick_xmiddle, new_joystick_ymiddle;
2510 int joystick_fd = joystick.fd[player_nr];
2511 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2512 boolean check[3][3];
2513 int check_remaining = 3 * 3;
2518 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2521 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2526 for(y=0; y < 3; y++)
2528 for(x=0; x < 3; x++)
2530 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2531 check[x][y] = FALSE;
2535 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2536 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2537 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2538 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2539 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2540 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2541 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2543 joy_value = Joystick(player_nr);
2544 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2545 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2547 /* eventually uncalibrated center position (joystick could be uncentered) */
2548 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2551 new_joystick_xmiddle = joy_x;
2552 new_joystick_ymiddle = joy_y;
2554 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2557 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2562 if (PendingEvent()) /* got event */
2570 case EVENT_KEYPRESS:
2571 switch(GetEventKey((KeyEvent *)&event, TRUE))
2574 if (check_remaining == 0)
2587 case EVENT_KEYRELEASE:
2588 key_joystick_mapping = 0;
2592 HandleOtherEvents(&event);
2597 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2600 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2601 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2602 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2603 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2605 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2606 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2607 setup.input[player_nr].joy.xright = new_joystick_xright;
2608 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2609 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2610 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2612 CheckJoystickData();
2614 joy_value = Joystick(player_nr);
2616 if (joy_value & JOY_BUTTON && check_remaining == 0)
2619 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2620 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2622 if (x != last_x || y != last_y)
2624 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2625 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2630 if (check_remaining > 0 && !check[x+1][y+1])
2632 check[x+1][y+1] = TRUE;
2638 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2639 setup.input[player_nr].joy.xleft,
2640 setup.input[player_nr].joy.xmiddle,
2641 setup.input[player_nr].joy.xright);
2642 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2643 setup.input[player_nr].joy.yupper,
2644 setup.input[player_nr].joy.ymiddle,
2645 setup.input[player_nr].joy.ylower);
2654 /* don't eat all CPU time */
2658 /* calibrated center position (joystick should now be centered) */
2659 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2662 new_joystick_xmiddle = joy_x;
2663 new_joystick_ymiddle = joy_y;
2667 DrawSetupScreen_Input();
2669 /* wait until the last pressed button was released */
2670 while (Joystick(player_nr) & JOY_BUTTON)
2672 if (PendingEvent()) /* got event */
2677 HandleOtherEvents(&event);
2686 void CalibrateJoystick(int player_nr)
2688 if (!CalibrateJoystickMain(player_nr))
2692 DrawText(mSX + 16, mSY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2693 DrawText(mSX, mSY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2695 Delay(2000); /* show error message for two seconds */
2699 void DrawSetupScreen()
2701 DeactivateJoystick();
2703 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2705 if (setup_mode == SETUP_MODE_INPUT)
2706 DrawSetupScreen_Input();
2707 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2708 DrawChooseTree(&artwork.gfx_current);
2709 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2710 DrawChooseTree(&artwork.snd_current);
2711 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2712 DrawChooseTree(&artwork.mus_current);
2714 DrawSetupScreen_Generic();
2717 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2719 if (setup_mode == SETUP_MODE_INPUT)
2720 HandleSetupScreen_Input(mx, my, dx, dy, button);
2721 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2722 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2723 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2724 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2725 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2726 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2728 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2731 void HandleGameActions()
2733 if (game_status != PLAYING)
2736 if (local_player->LevelSolved)
2739 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2747 /* ---------- new screen button stuff -------------------------------------- */
2749 /* graphic position and size values for buttons and scrollbars */
2750 #define SC_SCROLLBUTTON_XSIZE 32
2751 #define SC_SCROLLBUTTON_YSIZE 32
2753 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2754 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2755 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2756 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2757 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2758 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2759 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2760 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2762 #define SC_BORDER_SIZE 14
2766 int gfx_unpressed, gfx_pressed;
2770 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2773 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2774 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2775 SCREEN_CTRL_ID_SCROLL_UP,
2779 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2780 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2781 SCREEN_CTRL_ID_SCROLL_DOWN,
2788 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2789 Bitmap **gfx_unpressed, **gfx_pressed;
2791 int gfx_unpressed, gfx_pressed;
2798 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2801 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2802 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2804 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2806 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2807 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2808 GD_TYPE_SCROLLBAR_VERTICAL,
2809 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2810 "scroll level series vertically"
2814 static void CreateScreenScrollbuttons()
2816 struct GadgetInfo *gi;
2817 unsigned long event_mask;
2820 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2822 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2823 int gfx_unpressed, gfx_pressed;
2824 int x, y, width, height;
2825 int gd_x1, gd_x2, gd_y1, gd_y2;
2826 int id = scrollbutton_info[i].gadget_id;
2828 x = scrollbutton_info[i].x;
2829 y = scrollbutton_info[i].y;
2831 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2835 width = SC_SCROLLBUTTON_XSIZE;
2836 height = SC_SCROLLBUTTON_YSIZE;
2838 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2839 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2840 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2841 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2842 gd_x1 = graphic_info[gfx_unpressed].src_x;
2843 gd_y1 = graphic_info[gfx_unpressed].src_y;
2844 gd_x2 = graphic_info[gfx_pressed].src_x;
2845 gd_y2 = graphic_info[gfx_pressed].src_y;
2847 gi = CreateGadget(GDI_CUSTOM_ID, id,
2848 GDI_CUSTOM_TYPE_ID, i,
2849 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2854 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2855 GDI_STATE, GD_BUTTON_UNPRESSED,
2856 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2857 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2858 GDI_EVENT_MASK, event_mask,
2859 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2863 Error(ERR_EXIT, "cannot create gadget");
2865 screen_gadget[id] = gi;
2869 static void CreateScreenScrollbars()
2873 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2875 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2876 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2877 int gfx_unpressed, gfx_pressed;
2879 int gd_x1, gd_x2, gd_y1, gd_y2;
2880 struct GadgetInfo *gi;
2881 int items_max, items_visible, item_position;
2882 unsigned long event_mask;
2883 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2884 int id = scrollbar_info[i].gadget_id;
2886 items_max = num_page_entries;
2887 items_visible = num_page_entries;
2890 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2892 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2893 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
2894 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
2900 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2901 gfx_pressed = scrollbar_info[i].gfx_pressed;
2902 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2903 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2904 gd_x1 = graphic_info[gfx_unpressed].src_x;
2905 gd_y1 = graphic_info[gfx_unpressed].src_y;
2906 gd_x2 = graphic_info[gfx_pressed].src_x;
2907 gd_y2 = graphic_info[gfx_pressed].src_y;
2910 gi = CreateGadget(GDI_CUSTOM_ID, id,
2911 GDI_CUSTOM_TYPE_ID, i,
2912 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2913 GDI_X, scrollbar_info[i].x,
2914 GDI_Y, scrollbar_info[i].y,
2915 GDI_WIDTH, scrollbar_info[i].width,
2916 GDI_HEIGHT, scrollbar_info[i].height,
2917 GDI_TYPE, scrollbar_info[i].type,
2918 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2919 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2920 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2921 GDI_STATE, GD_BUTTON_UNPRESSED,
2922 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2923 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2924 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
2925 GDI_EVENT_MASK, event_mask,
2926 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2930 Error(ERR_EXIT, "cannot create gadget");
2932 screen_gadget[id] = gi;
2936 void CreateScreenGadgets()
2938 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2941 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
2943 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
2945 /* copy pointers to clip mask and GC */
2946 scrollbar_bitmap[i]->clip_mask =
2947 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
2948 scrollbar_bitmap[i]->stored_clip_gc =
2949 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
2951 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
2952 scrollbar_bitmap[i],
2953 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
2954 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
2955 TILEX, TILEY, 0, 0);
2959 CreateScreenScrollbuttons();
2960 CreateScreenScrollbars();
2963 void FreeScreenGadgets()
2967 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2968 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
2970 /* prevent freeing clip mask and GC twice */
2971 scrollbar_bitmap[i]->clip_mask = None;
2972 scrollbar_bitmap[i]->stored_clip_gc = None;
2974 FreeBitmap(scrollbar_bitmap[i]);
2978 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2979 FreeGadget(screen_gadget[i]);
2982 void MapChooseTreeGadgets(TreeInfo *ti)
2984 int num_entries = numTreeInfoInGroup(ti);
2987 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
2990 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2991 MapGadget(screen_gadget[i]);
2994 void UnmapChooseTreeGadgets()
2998 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2999 UnmapGadget(screen_gadget[i]);
3002 static void HandleScreenGadgets(struct GadgetInfo *gi)
3004 int id = gi->custom_id;
3006 if (game_status != CHOOSELEVEL && game_status != SETUP)
3011 case SCREEN_CTRL_ID_SCROLL_UP:
3012 if (game_status == CHOOSELEVEL)
3013 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
3014 else if (game_status == SETUP)
3015 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
3018 case SCREEN_CTRL_ID_SCROLL_DOWN:
3019 if (game_status == CHOOSELEVEL)
3020 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3021 else if (game_status == SETUP)
3022 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
3025 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3026 if (game_status == CHOOSELEVEL)
3027 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3028 else if (game_status == SETUP)
3029 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);