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;
74 #define mSX (SX + (game_status >= GAME_MODE_MAIN && \
75 game_status <= GAME_MODE_SETUP ? \
76 menu.draw_xoffset[game_status] : menu.draw_xoffset_default))
77 #define mSY (SY + (game_status >= GAME_MODE_MAIN && \
78 game_status <= GAME_MODE_SETUP ? \
79 menu.draw_yoffset[game_status] : menu.draw_yoffset_default))
81 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
82 menu.list_size[game_status] : \
83 MAX_MENU_ENTRIES_ON_SCREEN)
85 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
86 #define NUM_SCROLLBAR_BITMAPS 2
87 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
91 static void drawCursorExt(int xpos, int ypos, int color, int graphic)
93 static int cursor_array[SCR_FIELDY];
98 cursor_array[ypos] = graphic;
100 graphic = cursor_array[ypos];
104 graphic = (graphic == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
105 graphic == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE:
106 IMG_MENU_BUTTON_ACTIVE);
108 ypos += MENU_SCREEN_START_YPOS;
110 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
111 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY,
115 static void initCursor(int ypos, int graphic)
117 drawCursorExt(0, ypos, FC_BLUE, graphic);
120 static void drawCursor(int ypos, int color)
122 drawCursorExt(0, ypos, color, 0);
125 static void drawCursorXY(int xpos, int ypos, int graphic)
127 drawCursorExt(xpos, ypos, -1, graphic);
130 static void drawChooseTreeCursor(int ypos, int color)
132 int last_game_status = game_status; /* save current game status */
134 /* force LEVELS draw offset on artwork setup screen */
135 game_status = GAME_MODE_LEVELS;
137 drawCursorExt(0, ypos, color, 0);
139 game_status = last_game_status; /* restore current game status */
142 static void PlaySound_Menu_Start(int sound)
144 if (sound_info[sound].loop)
145 PlaySoundLoop(sound);
150 static void PlaySound_Menu_Continue(int sound)
152 if (sound_info[sound].loop)
153 PlaySoundLoop(sound);
158 int font1_width = getFontWidth(FONT_TITLE_1);
159 int font2_width = getFontWidth(FONT_TITLE_2);
160 int x1 = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * font1_width) / 2;
161 int x2 = SX + (SXSIZE - strlen(WINDOW_SUBTITLE_STRING) * font2_width) / 2;
163 DrawText(x1, SY + 8, PROGRAM_TITLE_STRING, FONT_TITLE_1);
164 DrawText(x2, SY + 46, WINDOW_SUBTITLE_STRING, FONT_TITLE_2);
167 static void ToggleFullscreenIfNeeded()
169 if (setup.fullscreen != video.fullscreen_enabled)
171 /* save old door content */
172 BlitBitmap(backbuffer, bitmap_db_door,
173 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
175 /* toggle fullscreen */
176 ChangeVideoModeIfNeeded(setup.fullscreen);
177 setup.fullscreen = video.fullscreen_enabled;
179 /* redraw background to newly created backbuffer */
180 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
181 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
183 /* restore old door content */
184 BlitBitmap(bitmap_db_door, backbuffer,
185 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
187 redraw_mask = REDRAW_ALL;
193 static LevelDirTree *leveldir_last_valid = NULL;
194 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
195 int font_width = getFontWidth(FONT_MENU_1);
196 int name_width = font_width * strlen("Name:");
197 int level_width = font_width * strlen("Level:");
203 KeyboardAutoRepeatOn();
206 SetDrawDeactivationMask(REDRAW_NONE);
207 SetDrawBackgroundMask(REDRAW_FIELD);
209 audio.sound_deactivated = FALSE;
211 /* needed if last screen was the playing screen, invoked from level editor */
212 if (level_editor_test_game)
214 game_status = GAME_MODE_EDITOR;
219 /* needed if last screen was the editor screen */
220 UndrawSpecialEditorDoor();
222 /* needed if last screen was the setup screen and fullscreen state changed */
223 ToggleFullscreenIfNeeded();
225 /* needed if last screen (level choice) changed graphics, sounds or music */
226 ReloadCustomArtwork();
229 SetDrawtoField(DRAW_BACKBUFFER);
232 /* map gadgets for main menu screen */
235 /* leveldir_current may be invalid (level group, parent link) */
236 if (!validLevelSeries(leveldir_current))
237 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
239 /* store valid level series information */
240 leveldir_last_valid = leveldir_current;
242 /* level_nr may have been set to value over handicap with level editor */
243 if (setup.handicap && level_nr > leveldir_current->handicap_level)
244 level_nr = leveldir_current->handicap_level;
249 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
254 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
255 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
256 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
257 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
258 DrawText(mSX + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
259 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
260 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
261 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
263 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT_1);
264 DrawText(mSX + level_width + 5 * 32, mSY + 3*32, int2str(level_nr,3),
267 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
269 DrawTextF(mSX + 32 + level_width - 2, mSY + 3*32 + 1, FONT_TEXT_3, "%d-%d",
270 leveldir_current->first_level, leveldir_current->last_level);
272 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 <= NUM_MENU_ENTRIES_ON_SCREEN)
318 num_page_entries = num_leveldirs;
320 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
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 - mSY) / 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 = GAME_MODE_PSEUDO_TYPENAME;
411 HandleTypeName(strlen(setup.player_name), 0);
417 game_status = GAME_MODE_LEVELS;
418 SaveLevelSetup_LastSeries();
419 SaveLevelSetup_SeriesInfo();
428 game_status = GAME_MODE_SCORES;
433 if (leveldir_current->readonly &&
434 strcmp(setup.player_name, "Artsoft") != 0)
435 Request("This level is read only !", REQ_CONFIRM);
436 game_status = GAME_MODE_EDITOR;
441 game_status = GAME_MODE_INFO;
446 if (setup.autorecord)
447 TapeStartRecording();
449 #if defined(PLATFORM_UNIX)
451 SendToServer_StartPlaying();
455 game_status = GAME_MODE_PLAYING;
462 game_status = GAME_MODE_SETUP;
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 = GAME_MODE_QUIT;
480 if (game_status == GAME_MODE_MAIN)
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 helpscreen_action[] =
498 IMG_PLAYER_1_MOVING_DOWN, 16,
499 IMG_PLAYER_1_MOVING_UP, 16,
500 IMG_PLAYER_1_MOVING_LEFT, 16,
501 IMG_PLAYER_1_MOVING_RIGHT, 16,
502 IMG_PLAYER_1_PUSHING_LEFT, 16,
503 IMG_PLAYER_1_PUSHING_RIGHT, 16, HA_NEXT,
505 IMG_SAND, -1, HA_NEXT,
507 IMG_EMPTY_SPACE, -1, HA_NEXT,
509 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
511 IMG_STEELWALL, -1, HA_NEXT,
513 IMG_WALL, -1, HA_NEXT,
515 IMG_EXPANDABLE_WALL_GROWING_LEFT, 20,
518 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 20,
521 IMG_EXPANDABLE_WALL_GROWING_UP, 20,
524 IMG_EXPANDABLE_WALL_GROWING_DOWN, 20,
526 IMG_EMPTY_SPACE, 20, HA_NEXT,
528 IMG_INVISIBLE_WALL, -1, HA_NEXT,
530 IMG_WALL_CRUMBLED, -1, HA_NEXT,
532 IMG_FONT_GAME_INFO, -1, HA_NEXT,
534 IMG_EMERALD, -1, HA_NEXT,
536 IMG_DIAMOND, -1, HA_NEXT,
538 IMG_BD_DIAMOND, -1, HA_NEXT,
540 IMG_EMERALD_YELLOW, 50,
542 IMG_EMERALD_PURPLE, 50, HA_NEXT,
544 IMG_BD_ROCK, -1, HA_NEXT,
548 IMG_EMPTY_SPACE, 10, HA_NEXT,
552 IMG_EMERALD, 20, HA_NEXT,
554 IMG_WALL_EMERALD, 100,
556 IMG_EMERALD, 20, HA_NEXT,
558 IMG_WALL_DIAMOND, 100,
560 IMG_DIAMOND, 20, HA_NEXT,
562 IMG_WALL_BD_DIAMOND, 100,
564 IMG_BD_DIAMOND, 20, HA_NEXT,
566 IMG_WALL_EMERALD_YELLOW, 100,
568 IMG_EMERALD_YELLOW, 20,
569 IMG_WALL_EMERALD_RED, 100,
572 IMG_WALL_EMERALD_PURPLE, 100,
574 IMG_EMERALD_PURPLE, 20, HA_NEXT,
576 IMG_ACID, -1, HA_NEXT,
581 IMG_KEY_4, 50, HA_NEXT,
586 IMG_GATE_4, 50, HA_NEXT,
591 IMG_GATE_4_GRAY, 50, HA_NEXT,
593 IMG_DYNAMITE, -1, HA_NEXT,
595 IMG_DYNAMITE_ACTIVE, 96,
597 IMG_EMPTY_SPACE, 20, HA_NEXT,
599 IMG_DYNABOMB_ACTIVE, 100,
601 IMG_EMPTY_SPACE, 20, HA_NEXT,
603 IMG_DYNABOMB_INCREASE_NUMBER, -1, HA_NEXT,
605 IMG_DYNABOMB_INCREASE_SIZE, -1, HA_NEXT,
607 IMG_DYNABOMB_INCREASE_POWER, -1, HA_NEXT,
609 IMG_SPACESHIP_RIGHT, 16,
610 IMG_SPACESHIP_UP, 16,
611 IMG_SPACESHIP_LEFT, 16,
612 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
617 IMG_BUG_DOWN, 16, HA_NEXT,
619 IMG_BD_BUTTERFLY, -1, HA_NEXT,
621 IMG_BD_FIREFLY, -1, HA_NEXT,
623 IMG_PACMAN_RIGHT, 16,
626 IMG_PACMAN_DOWN, 16, HA_NEXT,
628 IMG_YAMYAM, -1, HA_NEXT,
630 IMG_DARK_YAMYAM, -1, HA_NEXT,
632 IMG_ROBOT, -1, HA_NEXT,
634 IMG_MOLE_MOVING_RIGHT, 16,
635 IMG_MOLE_MOVING_UP, 16,
636 IMG_MOLE_MOVING_LEFT, 16,
637 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
639 IMG_PENGUIN_MOVING_RIGHT, 16,
640 IMG_PENGUIN_MOVING_UP, 16,
641 IMG_PENGUIN_MOVING_LEFT, 16,
642 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
644 IMG_PIG_MOVING_RIGHT, 16,
645 IMG_PIG_MOVING_UP, 16,
646 IMG_PIG_MOVING_LEFT, 16,
647 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
649 IMG_DRAGON_MOVING_RIGHT, 16,
650 IMG_DRAGON_MOVING_UP, 16,
651 IMG_DRAGON_MOVING_LEFT, 16,
652 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
654 IMG_SATELLITE, -1, HA_NEXT,
657 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
660 IMG_LAMP_ACTIVE, 50, HA_NEXT,
662 IMG_TIME_ORB_FULL, 50,
663 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
666 IMG_AMOEBA_GROWING, 6,
667 IMG_AMOEBA_WET, 20, HA_NEXT,
669 IMG_AMOEBA_DEAD, -1, HA_NEXT,
671 IMG_AMOEBA_WET, -1, HA_NEXT,
674 IMG_AMOEBA_GROWING, 6, HA_NEXT,
679 IMG_DIAMOND, 20, HA_NEXT,
681 IMG_GAME_OF_LIFE, -1, HA_NEXT,
683 IMG_BIOMAZE, -1, HA_NEXT,
685 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
687 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
689 IMG_EXIT_CLOSED, 200,
690 IMG_EXIT_OPENING, 16,
691 IMG_EXIT_OPEN, 100, HA_NEXT,
693 IMG_EXIT_OPEN, -1, HA_NEXT,
695 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
697 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
699 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
701 IMG_SPEED_PILL, -1, HA_NEXT,
705 static char *helpscreen_eltext[][2] =
707 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
708 {"Normal sand:", "You can dig through it"},
709 {"Empty field:", "You can walk through it"},
710 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
711 {"Massive Wall:", "Nothing can go through it"},
712 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
713 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
714 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
715 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
716 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
717 {"Emerald: You must collect enough of","them to finish a level"},
718 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
719 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
720 {"Colorful Gems:", "Seem to behave like Emeralds"},
721 {"Rock: Smashes several things;", "Can be moved by the player"},
722 {"Bomb: You can move it, but be", "careful when dropping it"},
723 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
724 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
725 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
726 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
727 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
728 {"Acid: Things that fall in are gone", "forever (including our hero)"},
729 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
730 {"Door: Can be opened by the key", "with the same color"},
731 {"Door: You have to find out the", "right color of the key for it"},
732 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
733 {"Dynamite: This one explodes after", "a few seconds"},
734 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
735 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
736 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
737 {"Dyna Bomb: Increases the power of", "explosion of dyna bombs"},
738 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
739 {"Bug: Moves at the right side", "of walls; don't touch it!"},
740 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
741 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
742 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
743 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
744 {"Cruncher (BD style):", "Eats almost everything"},
745 {"Robot: Tries to kill the player", ""},
746 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
747 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
748 {"The Pig: Harmless, but eats all", "gems it can get"},
749 {"The Dragon: Breathes fire,", "especially to some monsters"},
750 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
751 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
752 {"Light Bulb: All of them must be", "switched on to finish a level"},
753 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
754 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
755 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
756 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
757 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
758 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
759 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
760 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
761 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
762 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
763 {"Exit door: Opens if you have enough","emeralds to finish the level"},
764 {"Open exit door: Enter here to leave","the level and exit the actual game"},
765 {"Sokoban element: Object which must", "be pushed to an empty field"},
766 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
767 {"Sokoban element: Field with object", "which can be pushed away"},
768 {"Speed pill: Lets the player run", "twice as fast as normally"},
770 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
772 static char *helpscreen_music[][3] =
774 { "Alchemy", "Ian Boddy", "Drive" },
775 { "The Chase", "Propaganda", "A Secret Wish" },
776 { "Network 23", "Tangerine Dream", "Exit" },
777 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
778 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
779 { "Voyager", "The Alan Parsons Project","Pyramid" },
780 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
782 static int num_helpscreen_music = 7;
783 static int helpscreen_musicpos;
786 void OLD_DrawHelpScreenElAction(int start)
790 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
792 while(helpscreen_action[j] != HA_END)
794 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
796 else if (i<start || helpscreen_delay[i-start])
798 if (i>=start && helpscreen_delay[i-start])
799 helpscreen_delay[i-start]--;
801 while(helpscreen_action[j] != HA_NEXT)
808 j += 3*helpscreen_step[i-start];
809 graphic = helpscreen_action[j++];
811 if (helpscreen_frame[i-start])
813 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
814 helpscreen_frame[i-start]--;
819 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
822 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
824 if (helpscreen_action[j] == HA_NEXT)
826 if (!helpscreen_frame[i-start])
827 helpscreen_step[i-start] = 0;
831 if (!helpscreen_frame[i-start])
832 helpscreen_step[i-start]++;
833 while(helpscreen_action[j] != HA_NEXT)
838 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
850 void DrawHelpScreenElAction(int start)
853 int xstart = mSX + 16;
854 int ystart = mSY + 64 + 2 * 32;
855 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)
907 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
909 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
910 graphic, sync_frame, USE_MASKING);
912 frame = getGraphicAnimationFrame(graphic, sync_frame);
914 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
930 void DrawHelpScreenElText(int start)
933 int xstart = mSX + 56, ystart = mSY + 65 + 2 * 32, ystep = TILEY + 4;
934 int ybottom = SYSIZE - 20;
936 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
940 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
942 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
945 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
946 helpscreen_eltext[i][0], FONT_TEXT_2);
947 DrawText(xstart, ystart + (i - start) * ystep + 16,
948 helpscreen_eltext[i][1], FONT_TEXT_2);
951 DrawTextFCentered(ybottom, FONT_TEXT_4,
952 "Press any key or button for next page");
955 void DrawHelpScreenMusicText(int num)
957 int ystart = 150, ystep = 30;
958 int ybottom = SYSIZE - 20;
964 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
966 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
967 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
968 "\"%s\"", helpscreen_music[num][0]);
969 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
970 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
971 "%s", helpscreen_music[num][1]);
972 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
973 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
974 "\"%s\"", helpscreen_music[num][2]);
976 DrawTextFCentered(ybottom, FONT_TEXT_4,
977 "Press any key or button for next page");
980 PlaySoundLoop(background_loop[num]);
984 void DrawHelpScreenCreditsText()
986 int ystart = 150, ystep = 30;
987 int ybottom = SYSIZE - 20;
993 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
994 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
995 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
996 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
997 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
998 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
999 "...and many thanks to all contributors");
1000 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1002 DrawTextFCentered(ybottom, FONT_TEXT_4,
1003 "Press any key or button for next page");
1006 void DrawHelpScreenContactText()
1008 int ystart = 150, ystep = 30;
1009 int ybottom = SYSIZE - 20;
1014 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1016 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1017 "This game is Freeware!");
1018 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1019 "If you like it, send e-mail to:");
1020 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1021 "info@artsoft.org");
1022 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1023 "or SnailMail to:");
1024 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1026 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1027 "Detmolder Strasse 189");
1028 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1030 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1033 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1034 "If you have created new levels,");
1035 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1036 "send them to me to include them!");
1037 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1040 DrawTextFCentered(ybottom, FONT_TEXT_4,
1041 "Press any key or button for main menu");
1044 void DrawHelpScreen()
1049 CloseDoor(DOOR_CLOSE_2);
1051 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1052 helpscreen_step[i] = helpscreen_frame[i] = 0;
1053 helpscreen_musicpos = 0;
1054 helpscreen_state = 0;
1056 DrawHelpScreenElText(0);
1057 DrawHelpScreenElAction(0);
1063 PlaySoundLoop(SND_BACKGROUND_INFO);
1065 PlaySound_Menu_Start(SND_BACKGROUND_INFO);
1069 void HandleHelpScreen(int button)
1071 static unsigned long hs_delay = 0;
1072 int num_helpscreen_els_pages =
1073 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1074 int button_released = !button;
1077 if (button_released)
1079 if (helpscreen_state < num_helpscreen_els_pages - 1)
1081 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1082 helpscreen_step[i] = helpscreen_frame[i] = 0;
1086 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1087 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1089 else if (helpscreen_state <
1090 num_helpscreen_els_pages + num_helpscreen_music - 1)
1093 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1095 else if (helpscreen_state ==
1096 num_helpscreen_els_pages + num_helpscreen_music - 1)
1099 DrawHelpScreenCreditsText();
1101 else if (helpscreen_state ==
1102 num_helpscreen_els_pages + num_helpscreen_music)
1105 DrawHelpScreenContactText();
1111 game_status = GAME_MODE_MAIN;
1117 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1119 if (helpscreen_state < num_helpscreen_els_pages)
1120 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1123 /* !!! workaround for playing "music" that is really a sound loop (and
1124 must therefore periodically be reactivated with the current sound
1127 PlaySoundLoop(SND_BACKGROUND_INFO);
1129 PlaySound_Menu_Continue(SND_BACKGROUND_INFO);
1138 void HandleTypeName(int newxpos, Key key)
1140 static int xpos = 0, ypos = 2;
1141 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1142 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1143 int startx = mSX + 32 + name_width;
1144 int starty = mSY + ypos * 32;
1150 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1151 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1156 if (((key >= KSYM_A && key <= KSYM_Z) ||
1157 (key >= KSYM_a && key <= KSYM_z)) &&
1158 xpos < MAX_PLAYER_NAME_LEN)
1162 if (key >= KSYM_A && key <= KSYM_Z)
1163 ascii = 'A' + (char)(key - KSYM_A);
1165 ascii = 'a' + (char)(key - KSYM_a);
1167 setup.player_name[xpos] = ascii;
1168 setup.player_name[xpos + 1] = 0;
1171 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1172 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1174 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1177 setup.player_name[xpos] = 0;
1179 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1181 else if (key == KSYM_Return && xpos > 0)
1183 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1184 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1187 game_status = GAME_MODE_MAIN;
1193 static void DrawChooseTree(TreeInfo **ti_ptr)
1197 FreeScreenGadgets();
1198 CreateScreenGadgets();
1200 CloseDoor(DOOR_CLOSE_2);
1204 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1205 MapChooseTreeGadgets(*ti_ptr);
1211 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1213 struct GadgetInfo *gi = screen_gadget[id];
1214 int items_max, items_visible, item_position;
1216 items_max = numTreeInfoInGroup(ti);
1217 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1218 item_position = first_entry;
1220 if (item_position > items_max - items_visible)
1221 item_position = items_max - items_visible;
1223 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1224 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1225 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1228 static void drawChooseTreeList(int first_entry, int num_page_entries,
1232 char buffer[SCR_FIELDX * 2];
1233 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1234 char *title_string = NULL;
1235 int xoffset_setup = 16;
1236 int yoffset_setup = 16;
1237 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1238 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1239 int last_game_status = game_status; /* save current game status */
1241 DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
1242 redraw_mask |= REDRAW_FIELD;
1245 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1246 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1247 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1248 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1250 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1252 /* force LEVELS font on artwork setup screen */
1253 game_status = GAME_MODE_LEVELS;
1255 for(i=0; i<num_page_entries; i++)
1257 TreeInfo *node, *node_first;
1258 int entry_pos = first_entry + i;
1259 int ypos = MENU_SCREEN_START_YPOS + i;
1261 node_first = getTreeInfoFirstGroupEntry(ti);
1262 node = getTreeInfoFromPos(node_first, entry_pos);
1264 strncpy(buffer, node->name , max_buffer_len);
1265 buffer[max_buffer_len] = '\0';
1267 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1269 if (node->parent_link)
1270 initCursor(i, IMG_MENU_BUTTON_LEFT);
1271 else if (node->level_group)
1272 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1274 initCursor(i, IMG_MENU_BUTTON);
1277 game_status = last_game_status; /* restore current game status */
1280 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1282 TreeInfo *node, *node_first;
1283 int x, last_redraw_mask = redraw_mask;
1285 if (ti->type != TREE_TYPE_LEVEL_DIR)
1288 node_first = getTreeInfoFirstGroupEntry(ti);
1289 node = getTreeInfoFromPos(node_first, entry_pos);
1291 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1293 if (node->parent_link)
1294 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1296 else if (node->level_group)
1297 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1299 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1300 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1301 node->levels, node->class_desc);
1303 /* let BackToFront() redraw only what is needed */
1304 redraw_mask = last_redraw_mask | REDRAW_TILES;
1305 for (x=0; x<SCR_FIELDX; x++)
1306 MarkTileDirty(x, 1);
1309 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1312 TreeInfo *ti = *ti_ptr;
1314 int y = ti->cl_cursor;
1315 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1316 int num_entries = numTreeInfoInGroup(ti);
1317 int num_page_entries;
1318 int last_game_status = game_status; /* save current game status */
1320 /* force LEVELS draw offset on choose level and artwork setup screen */
1321 game_status = GAME_MODE_LEVELS;
1323 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1324 num_page_entries = num_entries;
1326 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1328 game_status = last_game_status; /* restore current game status */
1330 if (button == MB_MENU_INITIALIZE)
1332 int num_entries = numTreeInfoInGroup(ti);
1333 int entry_pos = posTreeInfo(ti);
1335 if (ti->cl_first == -1)
1337 /* only on initialization */
1338 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1339 ti->cl_cursor = entry_pos - ti->cl_first;
1341 else if (ti->cl_cursor >= num_page_entries ||
1342 (num_entries > num_page_entries &&
1343 num_entries - ti->cl_first < num_page_entries))
1345 /* only after change of list size (by custom graphic configuration) */
1346 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1347 ti->cl_cursor = entry_pos - ti->cl_first;
1350 if (dx == 999) /* first entry is set by scrollbar position */
1353 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1356 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1357 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1358 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1362 else if (button == MB_MENU_LEAVE)
1364 if (ti->node_parent)
1366 *ti_ptr = ti->node_parent;
1367 DrawChooseTree(ti_ptr);
1369 else if (game_status == GAME_MODE_SETUP)
1375 game_status = GAME_MODE_MAIN;
1382 if (mx || my) /* mouse input */
1384 int last_game_status = game_status; /* save current game status */
1386 /* force LEVELS draw offset on artwork setup screen */
1387 game_status = GAME_MODE_LEVELS;
1389 x = (mx - mSX) / 32;
1390 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1392 game_status = last_game_status; /* restore current game status */
1394 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1396 /* move cursor instead of scrolling when already at start/end of list */
1397 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1399 else if (dy == +1 * SCROLL_LINE &&
1400 ti->cl_first + num_page_entries == num_entries)
1403 /* handle scrolling screen one line or page */
1404 if (ti->cl_cursor + dy < 0 ||
1405 ti->cl_cursor + dy > num_page_entries - 1)
1407 if (ABS(dy) == SCROLL_PAGE)
1408 step = num_page_entries - 1;
1410 if (dy < 0 && ti->cl_first > 0)
1412 /* scroll page/line up */
1414 ti->cl_first -= step;
1415 if (ti->cl_first < 0)
1418 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1419 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1420 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1421 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1424 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1426 /* scroll page/line down */
1428 ti->cl_first += step;
1429 if (ti->cl_first + num_page_entries > num_entries)
1430 ti->cl_first = MAX(0, num_entries - num_page_entries);
1432 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1433 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1434 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1435 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1442 /* handle moving cursor one line */
1443 y = ti->cl_cursor + dy;
1448 TreeInfo *node_first, *node_cursor;
1449 int entry_pos = ti->cl_first + y;
1451 node_first = getTreeInfoFirstGroupEntry(ti);
1452 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1454 if (node_cursor->node_group)
1456 node_cursor->cl_first = ti->cl_first;
1457 node_cursor->cl_cursor = ti->cl_cursor;
1458 *ti_ptr = node_cursor->node_group;
1459 DrawChooseTree(ti_ptr);
1464 else if (dx == -1 && ti->node_parent)
1466 *ti_ptr = ti->node_parent;
1467 DrawChooseTree(ti_ptr);
1472 if (x == 0 && y >= 0 && y < num_page_entries)
1476 if (y != ti->cl_cursor)
1478 drawChooseTreeCursor(y, FC_RED);
1479 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1480 drawChooseTreeInfo(ti->cl_first + y, ti);
1486 TreeInfo *node_first, *node_cursor;
1487 int entry_pos = ti->cl_first + y;
1489 node_first = getTreeInfoFirstGroupEntry(ti);
1490 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1492 if (node_cursor->node_group)
1494 node_cursor->cl_first = ti->cl_first;
1495 node_cursor->cl_cursor = ti->cl_cursor;
1496 *ti_ptr = node_cursor->node_group;
1497 DrawChooseTree(ti_ptr);
1499 else if (node_cursor->parent_link)
1501 *ti_ptr = node_cursor->node_parent;
1502 DrawChooseTree(ti_ptr);
1506 node_cursor->cl_first = ti->cl_first;
1507 node_cursor->cl_cursor = ti->cl_cursor;
1508 *ti_ptr = node_cursor;
1510 if (ti->type == TREE_TYPE_LEVEL_DIR)
1512 LoadLevelSetup_SeriesInfo();
1514 SaveLevelSetup_LastSeries();
1515 SaveLevelSetup_SeriesInfo();
1519 if (game_status == GAME_MODE_SETUP)
1525 game_status = GAME_MODE_MAIN;
1534 if (game_status == GAME_MODE_LEVELS || game_status == GAME_MODE_SETUP)
1538 void DrawChooseLevel()
1540 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1542 DrawChooseTree(&leveldir_current);
1545 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1547 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1550 void DrawHallOfFame(int highlight_position)
1554 CloseDoor(DOOR_CLOSE_2);
1556 if (highlight_position < 0)
1557 LoadScore(level_nr);
1562 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1565 PlaySound(SND_BACKGROUND_SCORES);
1567 PlaySound_Menu_Start(SND_BACKGROUND_SCORES);
1571 static void drawHallOfFameList(int first_entry, int highlight_position)
1575 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1578 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1579 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1581 for(i=0; i<NUM_MENU_ENTRIES_ON_SCREEN; i++)
1583 int entry = first_entry + i;
1584 boolean active = (entry == highlight_position);
1585 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1586 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1587 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1588 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1589 int dx1 = 3 * getFontWidth(font_nr1);
1590 int dx2 = dx1 + getFontWidth(font_nr1);
1591 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1592 int sy = mSY + 64 + i * 32;
1594 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1595 DrawText(mSX + dx1, sy, ".", font_nr1);
1596 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1597 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1598 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1599 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1603 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1605 static int first_entry = 0;
1606 static int highlight_position = 0;
1607 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1608 int button_released = !button;
1610 if (button == MB_MENU_INITIALIZE)
1613 highlight_position = mx;
1614 drawHallOfFameList(first_entry, highlight_position);
1619 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1620 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1624 if (first_entry > 0)
1626 first_entry -= step;
1627 if (first_entry < 0)
1630 drawHallOfFameList(first_entry, highlight_position);
1637 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1639 first_entry += step;
1640 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1641 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1643 drawHallOfFameList(first_entry, highlight_position);
1649 if (button_released)
1651 FadeSound(SND_BACKGROUND_SCORES);
1652 game_status = GAME_MODE_MAIN;
1658 if (game_status == GAME_MODE_SCORES)
1662 PlaySound_Menu_Continue(SND_BACKGROUND_SCORES);
1668 /* ========================================================================= */
1669 /* setup screen functions */
1670 /* ========================================================================= */
1672 static struct TokenInfo *setup_info;
1673 static int num_setup_info;
1675 static char *graphics_set_name;
1676 static char *sounds_set_name;
1677 static char *music_set_name;
1679 static void execSetupMain()
1681 setup_mode = SETUP_MODE_MAIN;
1685 static void execSetupGame()
1687 setup_mode = SETUP_MODE_GAME;
1691 static void execSetupEditor()
1693 setup_mode = SETUP_MODE_EDITOR;
1697 static void execSetupGraphics()
1699 setup_mode = SETUP_MODE_GRAPHICS;
1703 static void execSetupSound()
1705 setup_mode = SETUP_MODE_SOUND;
1709 static void execSetupArtwork()
1711 setup.graphics_set = artwork.gfx_current->identifier;
1712 setup.sounds_set = artwork.snd_current->identifier;
1713 setup.music_set = artwork.mus_current->identifier;
1715 /* needed if last screen (setup choice) changed graphics, sounds or music */
1716 ReloadCustomArtwork();
1718 /* needed for displaying artwork name instead of artwork identifier */
1719 graphics_set_name = artwork.gfx_current->name;
1720 sounds_set_name = artwork.snd_current->name;
1721 music_set_name = artwork.mus_current->name;
1723 setup_mode = SETUP_MODE_ARTWORK;
1727 static void execSetupChooseGraphics()
1729 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1733 static void execSetupChooseSounds()
1735 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1739 static void execSetupChooseMusic()
1741 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1745 static void execSetupInput()
1747 setup_mode = SETUP_MODE_INPUT;
1751 static void execSetupShortcut()
1753 setup_mode = SETUP_MODE_SHORTCUT;
1757 static void execExitSetup()
1759 game_status = GAME_MODE_MAIN;
1763 static void execSaveAndExitSetup()
1769 static struct TokenInfo setup_info_main[] =
1771 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1772 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1773 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1774 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1775 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1776 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1777 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1778 { TYPE_EMPTY, NULL, "" },
1779 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1780 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1784 static struct TokenInfo setup_info_game[] =
1786 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1787 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1788 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1789 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1790 { TYPE_EMPTY, NULL, "" },
1791 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1795 static struct TokenInfo setup_info_editor[] =
1797 { TYPE_STRING, NULL, "Offer Special Elements:"},
1798 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1799 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1800 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1801 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1802 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1803 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1804 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1805 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1806 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1807 { TYPE_EMPTY, NULL, "" },
1808 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1812 static struct TokenInfo setup_info_graphics[] =
1814 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1815 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1816 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1818 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1819 { TYPE_SWITCH, &setup.fading, "Fading:" },
1821 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1822 { TYPE_SWITCH, &setup.toons, "Toons:" },
1823 { TYPE_EMPTY, NULL, "" },
1824 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1828 static struct TokenInfo setup_info_sound[] =
1830 { TYPE_SWITCH, &setup.sound, "Sound:", },
1831 { TYPE_EMPTY, NULL, "" },
1832 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1833 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1834 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1835 { TYPE_EMPTY, NULL, "" },
1836 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1840 static struct TokenInfo setup_info_artwork[] =
1842 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1843 { TYPE_STRING, &graphics_set_name, "" },
1844 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1845 { TYPE_STRING, &sounds_set_name, "" },
1846 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1847 { TYPE_STRING, &music_set_name, "" },
1848 { TYPE_EMPTY, NULL, "" },
1849 { TYPE_STRING, NULL, "Override Level Artwork:"},
1850 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1851 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1852 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1853 { TYPE_EMPTY, NULL, "" },
1854 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1858 static struct TokenInfo setup_info_shortcut[] =
1860 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1861 { TYPE_KEY, &setup.shortcut.save_game, "" },
1862 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1863 { TYPE_KEY, &setup.shortcut.load_game, "" },
1864 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1865 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1866 { TYPE_EMPTY, NULL, "" },
1867 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1868 { TYPE_EMPTY, NULL, "" },
1869 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1873 static Key getSetupKey()
1875 Key key = KSYM_UNDEFINED;
1876 boolean got_key_event = FALSE;
1878 while (!got_key_event)
1880 if (PendingEvent()) /* got event */
1888 case EVENT_KEYPRESS:
1890 key = GetEventKey((KeyEvent *)&event, TRUE);
1892 /* press 'Escape' or 'Enter' to keep the existing key binding */
1893 if (key == KSYM_Escape || key == KSYM_Return)
1894 key = KSYM_UNDEFINED; /* keep old value */
1896 got_key_event = TRUE;
1900 case EVENT_KEYRELEASE:
1901 key_joystick_mapping = 0;
1905 HandleOtherEvents(&event);
1913 /* don't eat all CPU time */
1920 static void drawSetupValue(int pos)
1922 int xpos = MENU_SCREEN_VALUE_XPOS;
1923 int ypos = MENU_SCREEN_START_YPOS + pos;
1924 int font_nr = FONT_VALUE_1;
1925 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1926 setup_info[pos].value);
1928 if (value_string == NULL)
1931 if (setup_info[pos].type & TYPE_KEY)
1935 if (setup_info[pos].type & TYPE_QUERY)
1937 value_string = "<press key>";
1938 font_nr = FONT_INPUT_1_ACTIVE;
1941 else if (setup_info[pos].type & TYPE_STRING)
1943 int max_value_len = (SCR_FIELDX - 2) * 2;
1946 font_nr = FONT_VALUE_2;
1948 if (strlen(value_string) > max_value_len)
1949 value_string[max_value_len] = '\0';
1951 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1953 font_nr = (*(boolean *)(setup_info[pos].value) ? FONT_OPTION_ON :
1957 DrawText(mSX + xpos * 32, mSY + ypos * 32,
1958 (xpos == 3 ? " " : " "), font_nr);
1959 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
1962 static void changeSetupValue(int pos)
1964 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1966 *(boolean *)setup_info[pos].value ^= TRUE;
1968 else if (setup_info[pos].type & TYPE_KEY)
1972 setup_info[pos].type |= TYPE_QUERY;
1973 drawSetupValue(pos);
1974 setup_info[pos].type &= ~TYPE_QUERY;
1976 key = getSetupKey();
1977 if (key != KSYM_UNDEFINED)
1978 *(Key *)setup_info[pos].value = key;
1981 drawSetupValue(pos);
1984 static void DrawSetupScreen_Generic()
1986 char *title_string = NULL;
1990 CloseDoor(DOOR_CLOSE_2);
1994 if (setup_mode == SETUP_MODE_MAIN)
1996 setup_info = setup_info_main;
1997 title_string = "Setup";
1999 else if (setup_mode == SETUP_MODE_GAME)
2001 setup_info = setup_info_game;
2002 title_string = "Setup Game";
2004 else if (setup_mode == SETUP_MODE_EDITOR)
2006 setup_info = setup_info_editor;
2007 title_string = "Setup Editor";
2009 else if (setup_mode == SETUP_MODE_GRAPHICS)
2011 setup_info = setup_info_graphics;
2012 title_string = "Setup Graphics";
2014 else if (setup_mode == SETUP_MODE_SOUND)
2016 setup_info = setup_info_sound;
2017 title_string = "Setup Sound";
2019 else if (setup_mode == SETUP_MODE_ARTWORK)
2021 setup_info = setup_info_artwork;
2022 title_string = "Custom Artwork";
2024 else if (setup_mode == SETUP_MODE_SHORTCUT)
2026 setup_info = setup_info_shortcut;
2027 title_string = "Setup Shortcuts";
2030 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2033 for(i=0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2035 void *value_ptr = setup_info[i].value;
2036 int ypos = MENU_SCREEN_START_YPOS + i;
2037 int font_nr = FONT_MENU_1;
2039 /* set some entries to "unchangeable" according to other variables */
2040 if ((value_ptr == &setup.sound && !audio.sound_available) ||
2041 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2042 (value_ptr == &setup.sound_music && !audio.music_available) ||
2043 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2044 setup_info[i].type |= TYPE_GHOSTED;
2046 if (setup_info[i].type & TYPE_STRING)
2047 font_nr = FONT_MENU_2;
2049 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2051 if (setup_info[i].type & TYPE_ENTER_MENU)
2052 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2053 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2054 initCursor(i, IMG_MENU_BUTTON_LEFT);
2055 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2056 initCursor(i, IMG_MENU_BUTTON);
2058 if (setup_info[i].type & TYPE_VALUE)
2066 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2069 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2071 static int choice_store[MAX_SETUP_MODES];
2072 int choice = choice_store[setup_mode]; /* always starts with 0 */
2076 if (button == MB_MENU_INITIALIZE)
2078 /* advance to first valid menu entry */
2079 while (choice < num_setup_info &&
2080 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2082 choice_store[setup_mode] = choice;
2084 drawCursor(choice, FC_RED);
2087 else if (button == MB_MENU_LEAVE)
2089 for (y=0; y<num_setup_info; y++)
2091 if (setup_info[y].type & TYPE_LEAVE_MENU)
2093 void (*menu_callback_function)(void) = setup_info[y].value;
2095 menu_callback_function();
2096 break; /* absolutely needed because function changes 'setup_info'! */
2103 if (mx || my) /* mouse input */
2105 x = (mx - mSX) / 32;
2106 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2108 else if (dx || dy) /* keyboard input */
2112 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2114 if ((setup_info[choice].type & menu_navigation_type) ||
2115 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2116 button = MB_MENU_CHOICE;
2121 /* jump to next non-empty menu entry (up or down) */
2122 while (y > 0 && y < num_setup_info - 1 &&
2123 (setup_info[y].type & TYPE_SKIP_ENTRY))
2127 if (x == 0 && y >= 0 && y < num_setup_info &&
2128 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2134 drawCursor(y, FC_RED);
2135 drawCursor(choice, FC_BLUE);
2136 choice = choice_store[setup_mode] = y;
2139 else if (!(setup_info[y].type & TYPE_GHOSTED))
2141 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2143 void (*menu_callback_function)(void) = setup_info[choice].value;
2145 menu_callback_function();
2149 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2150 (setup_info[y + 1].type & TYPE_KEY))
2153 if (setup_info[y].type & TYPE_VALUE)
2154 changeSetupValue(y);
2161 if (game_status == GAME_MODE_SETUP)
2165 void DrawSetupScreen_Input()
2169 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2171 initCursor(0, IMG_MENU_BUTTON);
2172 initCursor(1, IMG_MENU_BUTTON);
2173 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2174 initCursor(13, IMG_MENU_BUTTON_LEFT);
2176 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2177 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2179 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2180 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2181 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2184 DeactivateJoystickForCalibration();
2185 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2186 "Joysticks deactivated on this screen");
2189 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2194 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2196 if (device_name == NULL)
2199 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2202 if (strlen(device_name) > 1)
2204 char c1 = device_name[strlen(device_name) - 1];
2205 char c2 = device_name[strlen(device_name) - 2];
2207 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2208 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2211 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2212 strlen(device_name));
2215 static void drawPlayerSetupInputInfo(int player_nr)
2218 static struct SetupKeyboardInfo custom_key;
2225 { &custom_key.left, "Joystick Left" },
2226 { &custom_key.right, "Joystick Right" },
2227 { &custom_key.up, "Joystick Up" },
2228 { &custom_key.down, "Joystick Down" },
2229 { &custom_key.snap, "Button 1" },
2230 { &custom_key.bomb, "Button 2" }
2232 static char *joystick_name[MAX_PLAYERS] =
2240 custom_key = setup.input[player_nr].key;
2242 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2244 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2245 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2247 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2250 if (setup.input[player_nr].use_joystick)
2252 char *device_name = setup.input[player_nr].joy.device_name;
2254 DrawText(mSX+8*32, mSY+3*32,
2255 joystick_name[getJoystickNrFromDeviceName(device_name)],
2257 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2261 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2262 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2265 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2266 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2267 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2268 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2269 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2270 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2271 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2272 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2273 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2274 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2275 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2279 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2281 DrawText(mSX + 3*32, mSY + ypos*32,
2283 DrawText(mSX + 3*32, mSY + ypos*32,
2284 (setup.input[player_nr].use_joystick ?
2286 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2290 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2292 static int choice = 0;
2293 static int player_nr = 0;
2296 int pos_start = SETUPINPUT_SCREEN_POS_START;
2297 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2298 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2299 int pos_end = SETUPINPUT_SCREEN_POS_END;
2301 if (button == MB_MENU_INITIALIZE)
2303 drawPlayerSetupInputInfo(player_nr);
2304 drawCursor(choice, FC_RED);
2307 else if (button == MB_MENU_LEAVE)
2309 setup_mode = SETUP_MODE_MAIN;
2314 if (mx || my) /* mouse input */
2316 x = (mx - mSX) / 32;
2317 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2319 else if (dx || dy) /* keyboard input */
2321 if (dx && choice == 0)
2322 x = (dx < 0 ? 10 : 12);
2323 else if ((dx && choice == 1) ||
2324 (dx == +1 && choice == 2) ||
2325 (dx == -1 && choice == pos_end))
2326 button = MB_MENU_CHOICE;
2330 if (y >= pos_empty1 && y <= pos_empty2)
2331 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2334 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2336 static unsigned long delay = 0;
2338 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2341 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2343 drawPlayerSetupInputInfo(player_nr);
2345 else if (x == 0 && y >= pos_start && y <= pos_end &&
2346 !(y >= pos_empty1 && y <= pos_empty2))
2352 drawCursor(y, FC_RED);
2353 drawCursor(choice, FC_BLUE);
2361 char *device_name = setup.input[player_nr].joy.device_name;
2363 if (!setup.input[player_nr].use_joystick)
2365 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2367 setJoystickDeviceToNr(device_name, new_device_nr);
2368 setup.input[player_nr].use_joystick = TRUE;
2372 int device_nr = getJoystickNrFromDeviceName(device_name);
2373 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2375 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2376 setup.input[player_nr].use_joystick = FALSE;
2378 setJoystickDeviceToNr(device_name, new_device_nr);
2381 drawPlayerSetupInputInfo(player_nr);
2385 if (setup.input[player_nr].use_joystick)
2388 CalibrateJoystick(player_nr);
2391 CustomizeKeyboard(player_nr);
2393 else if (y == pos_end)
2397 setup_mode = SETUP_MODE_MAIN;
2407 if (game_status == GAME_MODE_SETUP)
2411 void CustomizeKeyboard(int player_nr)
2415 boolean finished = FALSE;
2416 static struct SetupKeyboardInfo custom_key;
2421 } customize_step[] =
2423 { &custom_key.left, "Move Left" },
2424 { &custom_key.right, "Move Right" },
2425 { &custom_key.up, "Move Up" },
2426 { &custom_key.down, "Move Down" },
2427 { &custom_key.snap, "Snap Field" },
2428 { &custom_key.bomb, "Place Bomb" }
2431 /* read existing key bindings from player setup */
2432 custom_key = setup.input[player_nr].key;
2435 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2441 DrawText(mSX, mSY + (2+2*step_nr)*32,
2442 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2443 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2444 "Key:", FONT_INPUT_1_ACTIVE);
2445 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2446 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2450 if (PendingEvent()) /* got event */
2458 case EVENT_KEYPRESS:
2460 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2462 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2468 /* all keys configured -- wait for "Escape" or "Return" key */
2472 /* press 'Enter' to keep the existing key binding */
2473 if (key == KSYM_Return)
2474 key = *customize_step[step_nr].key;
2476 /* check if key already used */
2477 for (i=0; i<step_nr; i++)
2478 if (*customize_step[i].key == key)
2483 /* got new key binding */
2484 *customize_step[step_nr].key = key;
2485 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2487 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2488 getKeyNameFromKey(key), FONT_VALUE_1);
2491 /* un-highlight last query */
2492 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2493 customize_step[step_nr-1].text, FONT_MENU_1);
2494 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2495 "Key:", FONT_MENU_1);
2497 /* press 'Enter' to leave */
2500 DrawText(mSX + 16, mSY + 15*32+16,
2501 "Press Enter", FONT_TITLE_1);
2505 /* query next key binding */
2506 DrawText(mSX, mSY+(2+2*step_nr)*32,
2507 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2508 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2509 "Key:", FONT_INPUT_1_ACTIVE);
2510 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2511 getKeyNameFromKey(*customize_step[step_nr].key),
2516 case EVENT_KEYRELEASE:
2517 key_joystick_mapping = 0;
2521 HandleOtherEvents(&event);
2529 /* don't eat all CPU time */
2533 /* write new key bindings back to player setup */
2534 setup.input[player_nr].key = custom_key;
2537 DrawSetupScreen_Input();
2540 static boolean CalibrateJoystickMain(int player_nr)
2542 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2543 int new_joystick_xright = JOYSTICK_XMIDDLE;
2544 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2545 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2546 int new_joystick_xmiddle, new_joystick_ymiddle;
2548 int joystick_fd = joystick.fd[player_nr];
2549 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2550 boolean check[3][3];
2551 int check_remaining = 3 * 3;
2556 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2559 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2564 for(y=0; y < 3; y++)
2566 for(x=0; x < 3; x++)
2568 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2569 check[x][y] = FALSE;
2573 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2574 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2575 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2576 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2577 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2578 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2579 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2581 joy_value = Joystick(player_nr);
2582 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2583 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2585 /* eventually uncalibrated center position (joystick could be uncentered) */
2586 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2589 new_joystick_xmiddle = joy_x;
2590 new_joystick_ymiddle = joy_y;
2592 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2595 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2600 if (PendingEvent()) /* got event */
2608 case EVENT_KEYPRESS:
2609 switch(GetEventKey((KeyEvent *)&event, TRUE))
2612 if (check_remaining == 0)
2625 case EVENT_KEYRELEASE:
2626 key_joystick_mapping = 0;
2630 HandleOtherEvents(&event);
2635 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2638 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2639 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2640 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2641 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2643 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2644 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2645 setup.input[player_nr].joy.xright = new_joystick_xright;
2646 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2647 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2648 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2650 CheckJoystickData();
2652 joy_value = Joystick(player_nr);
2654 if (joy_value & JOY_BUTTON && check_remaining == 0)
2657 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2658 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2660 if (x != last_x || y != last_y)
2662 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2663 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2668 if (check_remaining > 0 && !check[x+1][y+1])
2670 check[x+1][y+1] = TRUE;
2676 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2677 setup.input[player_nr].joy.xleft,
2678 setup.input[player_nr].joy.xmiddle,
2679 setup.input[player_nr].joy.xright);
2680 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2681 setup.input[player_nr].joy.yupper,
2682 setup.input[player_nr].joy.ymiddle,
2683 setup.input[player_nr].joy.ylower);
2692 /* don't eat all CPU time */
2696 /* calibrated center position (joystick should now be centered) */
2697 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2700 new_joystick_xmiddle = joy_x;
2701 new_joystick_ymiddle = joy_y;
2705 DrawSetupScreen_Input();
2707 /* wait until the last pressed button was released */
2708 while (Joystick(player_nr) & JOY_BUTTON)
2710 if (PendingEvent()) /* got event */
2715 HandleOtherEvents(&event);
2724 void CalibrateJoystick(int player_nr)
2726 if (!CalibrateJoystickMain(player_nr))
2730 DrawText(mSX + 16, mSY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2731 DrawText(mSX, mSY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2733 Delay(2000); /* show error message for two seconds */
2737 void DrawSetupScreen()
2739 DeactivateJoystick();
2741 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2743 if (setup_mode == SETUP_MODE_INPUT)
2744 DrawSetupScreen_Input();
2745 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2746 DrawChooseTree(&artwork.gfx_current);
2747 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2748 DrawChooseTree(&artwork.snd_current);
2749 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2750 DrawChooseTree(&artwork.mus_current);
2752 DrawSetupScreen_Generic();
2755 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2757 if (setup_mode == SETUP_MODE_INPUT)
2758 HandleSetupScreen_Input(mx, my, dx, dy, button);
2759 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2760 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2761 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2762 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2763 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2764 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2766 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2769 void HandleGameActions()
2771 if (game_status != GAME_MODE_PLAYING)
2774 if (local_player->LevelSolved)
2777 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2785 if (tape.auto_play && !tape.playing)
2786 AutoPlayTape(); /* continue automatically playing next tape */
2790 /* ---------- new screen button stuff -------------------------------------- */
2792 /* graphic position and size values for buttons and scrollbars */
2793 #define SC_SCROLLBUTTON_XSIZE TILEX
2794 #define SC_SCROLLBUTTON_YSIZE TILEY
2796 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2797 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
2798 SC_SCROLLBUTTON_YSIZE)
2799 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2800 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
2801 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2802 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
2803 SC_SCROLLBUTTON_YSIZE)
2804 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2805 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
2806 SC_SCROLL_VERTICAL_YSIZE)
2808 #define SC_BORDER_SIZE 14
2812 int gfx_unpressed, gfx_pressed;
2816 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2819 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2820 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2821 SCREEN_CTRL_ID_SCROLL_UP,
2825 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2826 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2827 SCREEN_CTRL_ID_SCROLL_DOWN,
2834 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2835 Bitmap **gfx_unpressed, **gfx_pressed;
2837 int gfx_unpressed, gfx_pressed;
2844 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2847 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2848 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2850 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2852 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
2853 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2854 GD_TYPE_SCROLLBAR_VERTICAL,
2855 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2856 "scroll level series vertically"
2860 static void CreateScreenScrollbuttons()
2862 struct GadgetInfo *gi;
2863 unsigned long event_mask;
2866 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2868 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2869 int gfx_unpressed, gfx_pressed;
2870 int x, y, width, height;
2871 int gd_x1, gd_x2, gd_y1, gd_y2;
2872 int id = scrollbutton_info[i].gadget_id;
2874 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2876 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
2877 y = mSY + scrollbutton_info[i].y;
2878 width = SC_SCROLLBUTTON_XSIZE;
2879 height = SC_SCROLLBUTTON_YSIZE;
2881 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
2882 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
2883 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
2885 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2886 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2887 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2888 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2889 gd_x1 = graphic_info[gfx_unpressed].src_x;
2890 gd_y1 = graphic_info[gfx_unpressed].src_y;
2891 gd_x2 = graphic_info[gfx_pressed].src_x;
2892 gd_y2 = graphic_info[gfx_pressed].src_y;
2894 gi = CreateGadget(GDI_CUSTOM_ID, id,
2895 GDI_CUSTOM_TYPE_ID, i,
2896 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2901 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2902 GDI_STATE, GD_BUTTON_UNPRESSED,
2903 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2904 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2905 GDI_EVENT_MASK, event_mask,
2906 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2910 Error(ERR_EXIT, "cannot create gadget");
2912 screen_gadget[id] = gi;
2916 static void CreateScreenScrollbars()
2920 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2922 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2923 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2924 int gfx_unpressed, gfx_pressed;
2926 int x, y, width, height;
2927 int gd_x1, gd_x2, gd_y1, gd_y2;
2928 struct GadgetInfo *gi;
2929 int items_max, items_visible, item_position;
2930 unsigned long event_mask;
2931 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
2932 int id = scrollbar_info[i].gadget_id;
2934 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2936 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
2937 y = mSY + scrollbar_info[i].y;
2938 width = scrollbar_info[i].width;
2939 height = scrollbar_info[i].height;
2941 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
2942 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
2944 items_max = num_page_entries;
2945 items_visible = num_page_entries;
2948 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2949 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
2950 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
2956 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2957 gfx_pressed = scrollbar_info[i].gfx_pressed;
2958 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2959 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2960 gd_x1 = graphic_info[gfx_unpressed].src_x;
2961 gd_y1 = graphic_info[gfx_unpressed].src_y;
2962 gd_x2 = graphic_info[gfx_pressed].src_x;
2963 gd_y2 = graphic_info[gfx_pressed].src_y;
2966 gi = CreateGadget(GDI_CUSTOM_ID, id,
2967 GDI_CUSTOM_TYPE_ID, i,
2968 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2973 GDI_TYPE, scrollbar_info[i].type,
2974 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2975 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2976 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2977 GDI_STATE, GD_BUTTON_UNPRESSED,
2978 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2979 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2980 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
2981 GDI_EVENT_MASK, event_mask,
2982 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2986 Error(ERR_EXIT, "cannot create gadget");
2988 screen_gadget[id] = gi;
2992 void CreateScreenGadgets()
2994 int last_game_status = game_status; /* save current game status */
2996 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2999 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3001 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3003 /* copy pointers to clip mask and GC */
3004 scrollbar_bitmap[i]->clip_mask =
3005 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3006 scrollbar_bitmap[i]->stored_clip_gc =
3007 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3009 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3010 scrollbar_bitmap[i],
3011 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3012 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3013 TILEX, TILEY, 0, 0);
3017 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3018 game_status = GAME_MODE_LEVELS;
3020 CreateScreenScrollbuttons();
3021 CreateScreenScrollbars();
3023 game_status = last_game_status; /* restore current game status */
3026 void FreeScreenGadgets()
3030 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3031 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3033 /* prevent freeing clip mask and GC twice */
3034 scrollbar_bitmap[i]->clip_mask = None;
3035 scrollbar_bitmap[i]->stored_clip_gc = None;
3037 FreeBitmap(scrollbar_bitmap[i]);
3041 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3042 FreeGadget(screen_gadget[i]);
3045 void MapChooseTreeGadgets(TreeInfo *ti)
3047 int num_entries = numTreeInfoInGroup(ti);
3050 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3053 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3054 MapGadget(screen_gadget[i]);
3057 void UnmapChooseTreeGadgets()
3061 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3062 UnmapGadget(screen_gadget[i]);
3065 static void HandleScreenGadgets(struct GadgetInfo *gi)
3067 int id = gi->custom_id;
3069 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3074 case SCREEN_CTRL_ID_SCROLL_UP:
3075 if (game_status == GAME_MODE_LEVELS)
3076 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3077 else if (game_status == GAME_MODE_SETUP)
3078 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3081 case SCREEN_CTRL_ID_SCROLL_DOWN:
3082 if (game_status == GAME_MODE_LEVELS)
3083 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3084 else if (game_status == GAME_MODE_SETUP)
3085 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3088 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3089 if (game_status == GAME_MODE_LEVELS)
3090 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3091 else if (game_status == GAME_MODE_SETUP)
3092 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);