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 PlayMenuSound()
144 int sound = menu.sound[game_status];
146 if (sound == SND_UNDEFINED)
149 if (sound_info[sound].loop)
150 PlaySoundLoop(sound);
155 static void PlayMenuSoundIfLoop()
157 int sound = menu.sound[game_status];
159 if (sound == SND_UNDEFINED)
162 if (sound_info[sound].loop)
163 PlaySoundLoop(sound);
166 static void PlayMenuMusic()
168 int music = menu.music[game_status];
170 if (music == MUS_UNDEFINED)
178 int text1_width = getTextWidth(PROGRAM_TITLE_STRING, FONT_TITLE_1);
179 int text2_width = getTextWidth(PROGRAM_COPYRIGHT_STRING, FONT_TITLE_2);
180 int x1 = SX + (SXSIZE - text1_width) / 2;
181 int x2 = SX + (SXSIZE - text2_width) / 2;
183 DrawText(x1, SY + 8, PROGRAM_TITLE_STRING, FONT_TITLE_1);
184 DrawText(x2, SY + 46, PROGRAM_COPYRIGHT_STRING, FONT_TITLE_2);
187 static void ToggleFullscreenIfNeeded()
189 if (setup.fullscreen != video.fullscreen_enabled)
191 /* save old door content */
192 BlitBitmap(backbuffer, bitmap_db_door,
193 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
195 /* toggle fullscreen */
196 ChangeVideoModeIfNeeded(setup.fullscreen);
197 setup.fullscreen = video.fullscreen_enabled;
199 /* redraw background to newly created backbuffer */
200 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
201 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
203 /* restore old door content */
204 BlitBitmap(bitmap_db_door, backbuffer,
205 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
207 redraw_mask = REDRAW_ALL;
213 static LevelDirTree *leveldir_last_valid = NULL;
214 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
215 int name_width = getTextWidth("Name:", FONT_MENU_1);
216 int level_width = getTextWidth("Level:", FONT_MENU_1);
220 FadeSoundsAndMusic();
222 KeyboardAutoRepeatOn();
225 SetDrawDeactivationMask(REDRAW_NONE);
226 SetDrawBackgroundMask(REDRAW_FIELD);
228 audio.sound_deactivated = FALSE;
230 /* needed if last screen was the playing screen, invoked from level editor */
231 if (level_editor_test_game)
233 game_status = GAME_MODE_EDITOR;
239 /* needed if last screen was the editor screen */
240 UndrawSpecialEditorDoor();
242 /* needed if last screen was the setup screen and fullscreen state changed */
243 ToggleFullscreenIfNeeded();
245 /* leveldir_current may be invalid (level group, parent link) */
246 if (!validLevelSeries(leveldir_current))
247 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
249 /* store valid level series information */
250 leveldir_last_valid = leveldir_current;
252 /* needed if last screen (level choice) changed graphics, sounds or music */
253 ReloadCustomArtwork();
256 SetDrawtoField(DRAW_BACKBUFFER);
259 /* map gadgets for main menu screen */
262 /* level_nr may have been set to value over handicap with level editor */
263 if (setup.handicap && level_nr > leveldir_current->handicap_level)
264 level_nr = leveldir_current->handicap_level;
269 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
274 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
275 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
276 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
277 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
278 DrawText(mSX + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
279 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
280 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
281 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
283 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT_1);
284 DrawText(mSX + level_width + 5 * 32, mSY + 3*32, int2str(level_nr,3),
287 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
289 DrawTextF(mSX + 32 + level_width - 2, mSY + 3*32 + 1, FONT_TEXT_3, "%d-%d",
290 leveldir_current->first_level, leveldir_current->last_level);
292 if (leveldir_current->readonly)
294 DrawTextF(mSX + level_width + 9 * 32 - 2,
295 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
296 DrawTextF(mSX + level_width + 9 * 32 - 2,
297 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
301 initCursor(i, (i == 1 || i == 6 ? IMG_MENU_BUTTON_RIGHT :IMG_MENU_BUTTON));
303 drawCursorXY(level_width/32 + 4, 1, IMG_MENU_BUTTON_LEFT);
304 drawCursorXY(level_width/32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
306 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment", FONT_TITLE_2);
310 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
313 if (TAPE_IS_EMPTY(tape))
315 DrawCompleteVideoDisplay();
320 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
327 static void gotoTopLevelDir()
329 /* move upwards to top level directory */
330 while (leveldir_current->node_parent)
332 /* write a "path" into level tree for easy navigation to last level */
333 if (leveldir_current->node_parent->node_group->cl_first == -1)
335 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
336 int leveldir_pos = posTreeInfo(leveldir_current);
337 int num_page_entries;
338 int cl_first, cl_cursor;
340 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
341 num_page_entries = num_leveldirs;
343 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
345 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
346 cl_cursor = leveldir_pos - cl_first;
348 leveldir_current->node_parent->node_group->cl_first = cl_first;
349 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
352 leveldir_current = leveldir_current->node_parent;
356 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
358 static int choice = 5;
362 if (button == MB_MENU_INITIALIZE)
364 drawCursor(choice, FC_RED);
368 if (mx || my) /* mouse input */
371 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
373 else if (dx || dy) /* keyboard input */
375 if (dx && choice == 1)
376 x = (dx < 0 ? 10 : 14);
381 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
382 (x == 14 && level_nr < leveldir_current->last_level)) &&
385 static unsigned long level_delay = 0;
386 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
387 int new_level_nr, old_level_nr = level_nr;
389 new_level_nr = level_nr + (x == 10 ? -step : +step);
390 if (new_level_nr < leveldir_current->first_level)
391 new_level_nr = leveldir_current->first_level;
392 if (new_level_nr > leveldir_current->last_level)
393 new_level_nr = leveldir_current->last_level;
395 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
396 new_level_nr = leveldir_current->handicap_level;
398 if (old_level_nr == new_level_nr ||
399 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
402 level_nr = new_level_nr;
404 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
407 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
411 DrawCompleteVideoDisplay();
413 /* needed because DrawMicroLevel() takes some time */
416 DelayReached(&level_delay, 0); /* reset delay counter */
418 else if (x == 0 && y >= 0 && y <= 7)
424 drawCursor(y, FC_RED);
425 drawCursor(choice, FC_BLUE);
433 game_status = GAME_MODE_PSEUDO_TYPENAME;
434 HandleTypeName(strlen(setup.player_name), 0);
440 game_status = GAME_MODE_LEVELS;
441 SaveLevelSetup_LastSeries();
442 SaveLevelSetup_SeriesInfo();
451 game_status = GAME_MODE_SCORES;
456 if (leveldir_current->readonly &&
457 strcmp(setup.player_name, "Artsoft") != 0)
458 Request("This level is read only !", REQ_CONFIRM);
459 game_status = GAME_MODE_EDITOR;
464 game_status = GAME_MODE_INFO;
469 if (setup.autorecord)
470 TapeStartRecording();
472 #if defined(PLATFORM_UNIX)
474 SendToServer_StartPlaying();
478 game_status = GAME_MODE_PLAYING;
485 game_status = GAME_MODE_SETUP;
486 setup_mode = SETUP_MODE_MAIN;
491 SaveLevelSetup_LastSeries();
492 SaveLevelSetup_SeriesInfo();
493 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
494 game_status = GAME_MODE_QUIT;
501 if (game_status == GAME_MODE_MAIN)
503 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
511 #define MAX_HELPSCREEN_ELS 10
515 static long helpscreen_state;
516 static int helpscreen_step[MAX_HELPSCREEN_ELS];
517 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
519 static int helpscreen_action[] =
521 IMG_PLAYER_1_MOVING_DOWN, 16,
522 IMG_PLAYER_1_MOVING_UP, 16,
523 IMG_PLAYER_1_MOVING_LEFT, 16,
524 IMG_PLAYER_1_MOVING_RIGHT, 16,
525 IMG_PLAYER_1_PUSHING_LEFT, 16,
526 IMG_PLAYER_1_PUSHING_RIGHT, 16, HA_NEXT,
528 IMG_SAND, -1, HA_NEXT,
530 IMG_EMPTY_SPACE, -1, HA_NEXT,
532 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
534 IMG_STEELWALL, -1, HA_NEXT,
536 IMG_WALL, -1, HA_NEXT,
538 IMG_EXPANDABLE_WALL_GROWING_LEFT, 20,
541 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 20,
544 IMG_EXPANDABLE_WALL_GROWING_UP, 20,
547 IMG_EXPANDABLE_WALL_GROWING_DOWN, 20,
549 IMG_EMPTY_SPACE, 20, HA_NEXT,
551 IMG_INVISIBLE_WALL, -1, HA_NEXT,
553 IMG_WALL_SLIPPERY, -1, HA_NEXT,
555 IMG_FONT_GAME_INFO, -1, HA_NEXT,
557 IMG_EMERALD, -1, HA_NEXT,
559 IMG_DIAMOND, -1, HA_NEXT,
561 IMG_BD_DIAMOND, -1, HA_NEXT,
563 IMG_EMERALD_YELLOW, 50,
565 IMG_EMERALD_PURPLE, 50, HA_NEXT,
567 IMG_BD_ROCK, -1, HA_NEXT,
571 IMG_EMPTY_SPACE, 10, HA_NEXT,
575 IMG_EMERALD, 20, HA_NEXT,
577 IMG_WALL_EMERALD, 100,
579 IMG_EMERALD, 20, HA_NEXT,
581 IMG_WALL_DIAMOND, 100,
583 IMG_DIAMOND, 20, HA_NEXT,
585 IMG_WALL_BD_DIAMOND, 100,
587 IMG_BD_DIAMOND, 20, HA_NEXT,
589 IMG_WALL_EMERALD_YELLOW, 100,
591 IMG_EMERALD_YELLOW, 20,
592 IMG_WALL_EMERALD_RED, 100,
595 IMG_WALL_EMERALD_PURPLE, 100,
597 IMG_EMERALD_PURPLE, 20, HA_NEXT,
599 IMG_ACID, -1, HA_NEXT,
604 IMG_KEY_4, 50, HA_NEXT,
609 IMG_GATE_4, 50, HA_NEXT,
614 IMG_GATE_4_GRAY, 50, HA_NEXT,
616 IMG_DYNAMITE, -1, HA_NEXT,
618 IMG_DYNAMITE_ACTIVE, 96,
620 IMG_EMPTY_SPACE, 20, HA_NEXT,
622 IMG_DYNABOMB_ACTIVE, 100,
624 IMG_EMPTY_SPACE, 20, HA_NEXT,
626 IMG_DYNABOMB_INCREASE_NUMBER, -1, HA_NEXT,
628 IMG_DYNABOMB_INCREASE_SIZE, -1, HA_NEXT,
630 IMG_DYNABOMB_INCREASE_POWER, -1, HA_NEXT,
632 IMG_SPACESHIP_RIGHT, 16,
633 IMG_SPACESHIP_UP, 16,
634 IMG_SPACESHIP_LEFT, 16,
635 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
640 IMG_BUG_DOWN, 16, HA_NEXT,
642 IMG_BD_BUTTERFLY, -1, HA_NEXT,
644 IMG_BD_FIREFLY, -1, HA_NEXT,
646 IMG_PACMAN_RIGHT, 16,
649 IMG_PACMAN_DOWN, 16, HA_NEXT,
651 IMG_YAMYAM, -1, HA_NEXT,
653 IMG_DARK_YAMYAM, -1, HA_NEXT,
655 IMG_ROBOT, -1, HA_NEXT,
657 IMG_MOLE_MOVING_RIGHT, 16,
658 IMG_MOLE_MOVING_UP, 16,
659 IMG_MOLE_MOVING_LEFT, 16,
660 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
662 IMG_PENGUIN_MOVING_RIGHT, 16,
663 IMG_PENGUIN_MOVING_UP, 16,
664 IMG_PENGUIN_MOVING_LEFT, 16,
665 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
667 IMG_PIG_MOVING_RIGHT, 16,
668 IMG_PIG_MOVING_UP, 16,
669 IMG_PIG_MOVING_LEFT, 16,
670 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
672 IMG_DRAGON_MOVING_RIGHT, 16,
673 IMG_DRAGON_MOVING_UP, 16,
674 IMG_DRAGON_MOVING_LEFT, 16,
675 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
677 IMG_SATELLITE, -1, HA_NEXT,
680 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
683 IMG_LAMP_ACTIVE, 50, HA_NEXT,
685 IMG_TIME_ORB_FULL, 50,
686 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
689 IMG_AMOEBA_GROWING, 6,
690 IMG_AMOEBA_WET, 20, HA_NEXT,
692 IMG_AMOEBA_DEAD, -1, HA_NEXT,
694 IMG_AMOEBA_WET, -1, HA_NEXT,
697 IMG_AMOEBA_GROWING, 6, HA_NEXT,
702 IMG_DIAMOND, 20, HA_NEXT,
704 IMG_GAME_OF_LIFE, -1, HA_NEXT,
706 IMG_BIOMAZE, -1, HA_NEXT,
708 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
710 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
712 IMG_EXIT_CLOSED, 200,
713 IMG_EXIT_OPENING, 16,
714 IMG_EXIT_OPEN, 100, HA_NEXT,
716 IMG_EXIT_OPEN, -1, HA_NEXT,
718 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
720 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
722 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
724 IMG_SPEED_PILL, -1, HA_NEXT,
728 static char *helpscreen_eltext[][2] =
730 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
731 {"Normal sand:", "You can dig through it"},
732 {"Empty field:", "You can walk through it"},
733 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
734 {"Massive Wall:", "Nothing can go through it"},
735 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
736 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
737 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
738 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
739 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
740 {"Emerald: You must collect enough of","them to finish a level"},
741 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
742 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
743 {"Colorful Gems:", "Seem to behave like Emeralds"},
744 {"Rock: Smashes several things;", "Can be moved by the player"},
745 {"Bomb: You can move it, but be", "careful when dropping it"},
746 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
747 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
748 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
749 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
750 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
751 {"Acid: Things that fall in are gone", "forever (including our hero)"},
752 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
753 {"Door: Can be opened by the key", "with the same color"},
754 {"Door: You have to find out the", "right color of the key for it"},
755 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
756 {"Dynamite: This one explodes after", "a few seconds"},
757 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
758 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
759 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
760 {"Dyna Bomb: Increases the power of", "explosion of dyna bombs"},
761 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
762 {"Bug: Moves at the right side", "of walls; don't touch it!"},
763 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
764 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
765 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
766 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
767 {"Cruncher (BD style):", "Eats almost everything"},
768 {"Robot: Tries to kill the player", ""},
769 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
770 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
771 {"The Pig: Harmless, but eats all", "gems it can get"},
772 {"The Dragon: Breathes fire,", "especially to some monsters"},
773 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
774 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
775 {"Light Bulb: All of them must be", "switched on to finish a level"},
776 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
777 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
778 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
779 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
780 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
781 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
782 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
783 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
784 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
785 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
786 {"Exit door: Opens if you have enough","emeralds to finish the level"},
787 {"Open exit door: Enter here to leave","the level and exit the actual game"},
788 {"Sokoban element: Object which must", "be pushed to an empty field"},
789 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
790 {"Sokoban element: Field with object", "which can be pushed away"},
791 {"Speed pill: Lets the player run", "twice as fast as normally"},
793 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
795 static char *helpscreen_music[][3] =
797 { "Alchemy", "Ian Boddy", "Drive" },
798 { "The Chase", "Propaganda", "A Secret Wish" },
799 { "Network 23", "Tangerine Dream", "Exit" },
800 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
801 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
802 { "Voyager", "The Alan Parsons Project","Pyramid" },
803 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
805 static int num_helpscreen_music = 7;
806 static int helpscreen_musicpos;
809 void OLD_DrawHelpScreenElAction(int start)
813 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
815 while(helpscreen_action[j] != HA_END)
817 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
819 else if (i<start || helpscreen_delay[i-start])
821 if (i>=start && helpscreen_delay[i-start])
822 helpscreen_delay[i-start]--;
824 while(helpscreen_action[j] != HA_NEXT)
831 j += 3*helpscreen_step[i-start];
832 graphic = helpscreen_action[j++];
834 if (helpscreen_frame[i-start])
836 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
837 helpscreen_frame[i-start]--;
842 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
845 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
847 if (helpscreen_action[j] == HA_NEXT)
849 if (!helpscreen_frame[i-start])
850 helpscreen_step[i-start] = 0;
854 if (!helpscreen_frame[i-start])
855 helpscreen_step[i-start]++;
856 while(helpscreen_action[j] != HA_NEXT)
861 DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
873 void DrawHelpScreenElAction(int start)
876 int xstart = mSX + 16;
877 int ystart = mSY + 64 + 2 * 32;
878 int ystep = TILEY + 4;
883 while (helpscreen_action[j] != HA_END)
885 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
889 while (helpscreen_action[j] != HA_NEXT)
898 j += 2 * helpscreen_step[i-start];
899 graphic = helpscreen_action[j++];
900 frame_count = helpscreen_action[j++];
901 if (frame_count == -1)
902 frame_count = 1000000;
904 if (helpscreen_frame[i-start] == 0)
907 helpscreen_frame[i-start] = frame_count - 1;
911 sync_frame = frame_count - helpscreen_frame[i-start];
912 helpscreen_frame[i-start]--;
915 if (helpscreen_action[j] == HA_NEXT)
917 if (!helpscreen_frame[i-start])
918 helpscreen_step[i-start] = 0;
922 if (!helpscreen_frame[i-start])
923 helpscreen_step[i-start]++;
924 while(helpscreen_action[j] != HA_NEXT)
930 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
932 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
933 graphic, sync_frame, USE_MASKING);
935 frame = getGraphicAnimationFrame(graphic, sync_frame);
937 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
945 redraw_mask |= REDRAW_FIELD;
957 void DrawHelpScreenElText(int start)
960 int xstart = mSX + 56, ystart = mSY + 65 + 2 * 32, ystep = TILEY + 4;
961 int ybottom = SYSIZE - 20;
963 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
967 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
969 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
972 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
973 helpscreen_eltext[i][0], FONT_TEXT_2);
974 DrawText(xstart, ystart + (i - start) * ystep + 16,
975 helpscreen_eltext[i][1], FONT_TEXT_2);
978 DrawTextFCentered(ybottom, FONT_TEXT_4,
979 "Press any key or button for next page");
982 void DrawHelpScreenMusicText(int num)
984 int ystart = 150, ystep = 30;
985 int ybottom = SYSIZE - 20;
987 FadeSoundsAndMusic();
991 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
993 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
994 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
995 "\"%s\"", helpscreen_music[num][0]);
996 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
997 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
998 "%s", helpscreen_music[num][1]);
999 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1000 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
1001 "\"%s\"", helpscreen_music[num][2]);
1003 DrawTextFCentered(ybottom, FONT_TEXT_4,
1004 "Press any key or button for next page");
1007 PlaySoundLoop(background_loop[num]);
1011 void DrawHelpScreenCreditsText()
1013 int ystart = 150, ystep = 30;
1014 int ybottom = SYSIZE - 20;
1016 FadeSoundsAndMusic();
1020 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
1021 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1022 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1023 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1024 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1025 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
1026 "...and many thanks to all contributors");
1027 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1029 DrawTextFCentered(ybottom, FONT_TEXT_4,
1030 "Press any key or button for next page");
1033 void DrawHelpScreenContactText()
1035 int ystart = 150, ystep = 30;
1036 int ybottom = SYSIZE - 20;
1041 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1043 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1044 "This game is Freeware!");
1045 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1046 "If you like it, send e-mail to:");
1047 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1048 "info@artsoft.org");
1049 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1050 "or SnailMail to:");
1051 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1053 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1054 "Detmolder Strasse 189");
1055 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1057 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1060 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1061 "If you have created new levels,");
1062 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1063 "send them to me to include them!");
1064 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1067 DrawTextFCentered(ybottom, FONT_TEXT_4,
1068 "Press any key or button for main menu");
1071 void DrawHelpScreen()
1076 CloseDoor(DOOR_CLOSE_2);
1078 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1079 helpscreen_step[i] = helpscreen_frame[i] = 0;
1080 helpscreen_musicpos = 0;
1081 helpscreen_state = 0;
1083 DrawHelpScreenElText(0);
1084 DrawHelpScreenElAction(0);
1093 void HandleHelpScreen(int button)
1095 static unsigned long hs_delay = 0;
1096 int num_helpscreen_els_pages =
1097 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1098 int button_released = !button;
1101 if (button_released)
1103 if (helpscreen_state < num_helpscreen_els_pages - 1)
1105 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1106 helpscreen_step[i] = helpscreen_frame[i] = 0;
1110 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1111 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1113 else if (helpscreen_state <
1114 num_helpscreen_els_pages + num_helpscreen_music - 1)
1117 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1119 else if (helpscreen_state ==
1120 num_helpscreen_els_pages + num_helpscreen_music - 1)
1123 DrawHelpScreenCreditsText();
1125 else if (helpscreen_state ==
1126 num_helpscreen_els_pages + num_helpscreen_music)
1129 DrawHelpScreenContactText();
1133 FadeSoundsAndMusic();
1135 game_status = GAME_MODE_MAIN;
1141 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1143 if (helpscreen_state < num_helpscreen_els_pages)
1144 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1147 PlayMenuSoundIfLoop();
1154 void HandleTypeName(int newxpos, Key key)
1156 static int xpos = 0, ypos = 2;
1157 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1158 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1159 int startx = mSX + 32 + name_width;
1160 int starty = mSY + ypos * 32;
1166 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1167 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1172 if (((key >= KSYM_A && key <= KSYM_Z) ||
1173 (key >= KSYM_a && key <= KSYM_z)) &&
1174 xpos < MAX_PLAYER_NAME_LEN)
1178 if (key >= KSYM_A && key <= KSYM_Z)
1179 ascii = 'A' + (char)(key - KSYM_A);
1181 ascii = 'a' + (char)(key - KSYM_a);
1183 setup.player_name[xpos] = ascii;
1184 setup.player_name[xpos + 1] = 0;
1187 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1188 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1190 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1193 setup.player_name[xpos] = 0;
1195 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1197 else if (key == KSYM_Return && xpos > 0)
1199 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1200 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1203 game_status = GAME_MODE_MAIN;
1209 static void DrawChooseTree(TreeInfo **ti_ptr)
1213 FreeScreenGadgets();
1214 CreateScreenGadgets();
1216 CloseDoor(DOOR_CLOSE_2);
1220 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1221 MapChooseTreeGadgets(*ti_ptr);
1227 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1229 struct GadgetInfo *gi = screen_gadget[id];
1230 int items_max, items_visible, item_position;
1232 items_max = numTreeInfoInGroup(ti);
1233 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1234 item_position = first_entry;
1236 if (item_position > items_max - items_visible)
1237 item_position = items_max - items_visible;
1239 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1240 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1241 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1244 static void drawChooseTreeList(int first_entry, int num_page_entries,
1248 char buffer[SCR_FIELDX * 2];
1249 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1250 char *title_string = NULL;
1251 int xoffset_setup = 16;
1252 int yoffset_setup = 16;
1253 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1254 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1255 int last_game_status = game_status; /* save current game status */
1258 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1259 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1260 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1261 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1263 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1265 /* force LEVELS font on artwork setup screen */
1266 game_status = GAME_MODE_LEVELS;
1268 /* clear tree list area, but not title or scrollbar */
1269 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1270 SXSIZE - 32 + menu.scrollbar_xoffset,
1271 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1273 for(i=0; i<num_page_entries; i++)
1275 TreeInfo *node, *node_first;
1276 int entry_pos = first_entry + i;
1277 int ypos = MENU_SCREEN_START_YPOS + i;
1279 node_first = getTreeInfoFirstGroupEntry(ti);
1280 node = getTreeInfoFromPos(node_first, entry_pos);
1282 strncpy(buffer, node->name , max_buffer_len);
1283 buffer[max_buffer_len] = '\0';
1285 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1287 if (node->parent_link)
1288 initCursor(i, IMG_MENU_BUTTON_LEFT);
1289 else if (node->level_group)
1290 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1292 initCursor(i, IMG_MENU_BUTTON);
1295 game_status = last_game_status; /* restore current game status */
1297 redraw_mask |= REDRAW_FIELD;
1300 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1302 TreeInfo *node, *node_first;
1303 int x, last_redraw_mask = redraw_mask;
1305 if (ti->type != TREE_TYPE_LEVEL_DIR)
1308 node_first = getTreeInfoFirstGroupEntry(ti);
1309 node = getTreeInfoFromPos(node_first, entry_pos);
1311 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1313 if (node->parent_link)
1314 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1316 else if (node->level_group)
1317 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1319 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1320 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1321 node->levels, node->class_desc);
1323 /* let BackToFront() redraw only what is needed */
1324 redraw_mask = last_redraw_mask | REDRAW_TILES;
1325 for (x=0; x<SCR_FIELDX; x++)
1326 MarkTileDirty(x, 1);
1329 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1332 TreeInfo *ti = *ti_ptr;
1334 int y = ti->cl_cursor;
1335 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1336 int num_entries = numTreeInfoInGroup(ti);
1337 int num_page_entries;
1338 int last_game_status = game_status; /* save current game status */
1340 /* force LEVELS draw offset on choose level and artwork setup screen */
1341 game_status = GAME_MODE_LEVELS;
1343 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1344 num_page_entries = num_entries;
1346 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1348 game_status = last_game_status; /* restore current game status */
1350 if (button == MB_MENU_INITIALIZE)
1352 int num_entries = numTreeInfoInGroup(ti);
1353 int entry_pos = posTreeInfo(ti);
1355 if (ti->cl_first == -1)
1357 /* only on initialization */
1358 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1359 ti->cl_cursor = entry_pos - ti->cl_first;
1361 else if (ti->cl_cursor >= num_page_entries ||
1362 (num_entries > num_page_entries &&
1363 num_entries - ti->cl_first < num_page_entries))
1365 /* only after change of list size (by custom graphic configuration) */
1366 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1367 ti->cl_cursor = entry_pos - ti->cl_first;
1370 if (dx == 999) /* first entry is set by scrollbar position */
1373 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1376 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1377 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1378 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1382 else if (button == MB_MENU_LEAVE)
1384 if (ti->node_parent)
1386 *ti_ptr = ti->node_parent;
1387 DrawChooseTree(ti_ptr);
1389 else if (game_status == GAME_MODE_SETUP)
1395 game_status = GAME_MODE_MAIN;
1402 if (mx || my) /* mouse input */
1404 int last_game_status = game_status; /* save current game status */
1406 /* force LEVELS draw offset on artwork setup screen */
1407 game_status = GAME_MODE_LEVELS;
1409 x = (mx - mSX) / 32;
1410 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1412 game_status = last_game_status; /* restore current game status */
1414 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1416 /* move cursor instead of scrolling when already at start/end of list */
1417 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1419 else if (dy == +1 * SCROLL_LINE &&
1420 ti->cl_first + num_page_entries == num_entries)
1423 /* handle scrolling screen one line or page */
1424 if (ti->cl_cursor + dy < 0 ||
1425 ti->cl_cursor + dy > num_page_entries - 1)
1427 if (ABS(dy) == SCROLL_PAGE)
1428 step = num_page_entries - 1;
1430 if (dy < 0 && ti->cl_first > 0)
1432 /* scroll page/line up */
1434 ti->cl_first -= step;
1435 if (ti->cl_first < 0)
1438 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1439 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1440 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1441 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1444 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1446 /* scroll page/line down */
1448 ti->cl_first += step;
1449 if (ti->cl_first + num_page_entries > num_entries)
1450 ti->cl_first = MAX(0, num_entries - num_page_entries);
1452 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1453 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1454 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1455 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1462 /* handle moving cursor one line */
1463 y = ti->cl_cursor + dy;
1468 TreeInfo *node_first, *node_cursor;
1469 int entry_pos = ti->cl_first + y;
1471 node_first = getTreeInfoFirstGroupEntry(ti);
1472 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1474 if (node_cursor->node_group)
1476 node_cursor->cl_first = ti->cl_first;
1477 node_cursor->cl_cursor = ti->cl_cursor;
1478 *ti_ptr = node_cursor->node_group;
1479 DrawChooseTree(ti_ptr);
1484 else if (dx == -1 && ti->node_parent)
1486 *ti_ptr = ti->node_parent;
1487 DrawChooseTree(ti_ptr);
1492 if (x == 0 && y >= 0 && y < num_page_entries)
1496 if (y != ti->cl_cursor)
1498 drawChooseTreeCursor(y, FC_RED);
1499 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1500 drawChooseTreeInfo(ti->cl_first + y, ti);
1506 TreeInfo *node_first, *node_cursor;
1507 int entry_pos = ti->cl_first + y;
1509 node_first = getTreeInfoFirstGroupEntry(ti);
1510 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1512 if (node_cursor->node_group)
1514 node_cursor->cl_first = ti->cl_first;
1515 node_cursor->cl_cursor = ti->cl_cursor;
1516 *ti_ptr = node_cursor->node_group;
1517 DrawChooseTree(ti_ptr);
1519 else if (node_cursor->parent_link)
1521 *ti_ptr = node_cursor->node_parent;
1522 DrawChooseTree(ti_ptr);
1526 node_cursor->cl_first = ti->cl_first;
1527 node_cursor->cl_cursor = ti->cl_cursor;
1528 *ti_ptr = node_cursor;
1530 if (ti->type == TREE_TYPE_LEVEL_DIR)
1532 LoadLevelSetup_SeriesInfo();
1534 SaveLevelSetup_LastSeries();
1535 SaveLevelSetup_SeriesInfo();
1539 if (game_status == GAME_MODE_SETUP)
1545 game_status = GAME_MODE_MAIN;
1553 if (game_status == GAME_MODE_LEVELS || game_status == GAME_MODE_SETUP)
1560 void DrawChooseLevel()
1562 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1564 DrawChooseTree(&leveldir_current);
1570 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1572 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1578 void DrawHallOfFame(int highlight_position)
1581 FadeSoundsAndMusic();
1582 CloseDoor(DOOR_CLOSE_2);
1584 if (highlight_position < 0)
1585 LoadScore(level_nr);
1590 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1596 static void drawHallOfFameList(int first_entry, int highlight_position)
1600 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1603 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1604 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1606 for(i=0; i<NUM_MENU_ENTRIES_ON_SCREEN; i++)
1608 int entry = first_entry + i;
1609 boolean active = (entry == highlight_position);
1610 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1611 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1612 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1613 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1614 int dx1 = 3 * getFontWidth(font_nr1);
1615 int dx2 = dx1 + getFontWidth(font_nr1);
1616 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1617 int sy = mSY + 64 + i * 32;
1619 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1620 DrawText(mSX + dx1, sy, ".", font_nr1);
1621 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1622 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1623 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1624 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1627 redraw_mask |= REDRAW_FIELD;
1630 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1632 static int first_entry = 0;
1633 static int highlight_position = 0;
1634 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1635 int button_released = !button;
1637 if (button == MB_MENU_INITIALIZE)
1640 highlight_position = mx;
1641 drawHallOfFameList(first_entry, highlight_position);
1646 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1647 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1651 if (first_entry > 0)
1653 first_entry -= step;
1654 if (first_entry < 0)
1657 drawHallOfFameList(first_entry, highlight_position);
1662 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1664 first_entry += step;
1665 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1666 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1668 drawHallOfFameList(first_entry, highlight_position);
1671 else if (button_released)
1673 FadeSound(SND_BACKGROUND_SCORES);
1674 game_status = GAME_MODE_MAIN;
1678 if (game_status == GAME_MODE_SCORES)
1679 PlayMenuSoundIfLoop();
1686 /* ========================================================================= */
1687 /* setup screen functions */
1688 /* ========================================================================= */
1690 static struct TokenInfo *setup_info;
1691 static int num_setup_info;
1693 static char *graphics_set_name;
1694 static char *sounds_set_name;
1695 static char *music_set_name;
1697 static void execSetupMain()
1699 setup_mode = SETUP_MODE_MAIN;
1703 static void execSetupGame()
1705 setup_mode = SETUP_MODE_GAME;
1709 static void execSetupEditor()
1711 setup_mode = SETUP_MODE_EDITOR;
1715 static void execSetupGraphics()
1717 setup_mode = SETUP_MODE_GRAPHICS;
1721 static void execSetupSound()
1723 setup_mode = SETUP_MODE_SOUND;
1727 static void execSetupArtwork()
1729 setup.graphics_set = artwork.gfx_current->identifier;
1730 setup.sounds_set = artwork.snd_current->identifier;
1731 setup.music_set = artwork.mus_current->identifier;
1733 /* needed if last screen (setup choice) changed graphics, sounds or music */
1734 ReloadCustomArtwork();
1736 /* needed for displaying artwork name instead of artwork identifier */
1737 graphics_set_name = artwork.gfx_current->name;
1738 sounds_set_name = artwork.snd_current->name;
1739 music_set_name = artwork.mus_current->name;
1741 setup_mode = SETUP_MODE_ARTWORK;
1745 static void execSetupChooseGraphics()
1747 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1751 static void execSetupChooseSounds()
1753 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1757 static void execSetupChooseMusic()
1759 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1763 static void execSetupInput()
1765 setup_mode = SETUP_MODE_INPUT;
1769 static void execSetupShortcut()
1771 setup_mode = SETUP_MODE_SHORTCUT;
1775 static void execExitSetup()
1777 game_status = GAME_MODE_MAIN;
1781 static void execSaveAndExitSetup()
1787 static struct TokenInfo setup_info_main[] =
1789 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1790 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1791 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1792 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1793 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1794 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1795 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1796 { TYPE_EMPTY, NULL, "" },
1797 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1798 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1802 static struct TokenInfo setup_info_game[] =
1804 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1805 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1806 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1807 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1808 { TYPE_EMPTY, NULL, "" },
1809 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1813 static struct TokenInfo setup_info_editor[] =
1815 { TYPE_STRING, NULL, "Offer Special Elements:"},
1816 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1817 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1818 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1819 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1820 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1821 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1822 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1823 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1824 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1825 { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" },
1826 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
1827 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
1828 { TYPE_EMPTY, NULL, "" },
1829 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1833 static struct TokenInfo setup_info_graphics[] =
1835 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1836 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1837 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1839 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1840 { TYPE_SWITCH, &setup.fading, "Fading:" },
1842 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1843 { TYPE_SWITCH, &setup.toons, "Toons:" },
1844 { TYPE_EMPTY, NULL, "" },
1845 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1849 static struct TokenInfo setup_info_sound[] =
1851 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1852 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1853 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1854 { TYPE_EMPTY, NULL, "" },
1855 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1859 static struct TokenInfo setup_info_artwork[] =
1861 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1862 { TYPE_STRING, &graphics_set_name, "" },
1863 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1864 { TYPE_STRING, &sounds_set_name, "" },
1865 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1866 { TYPE_STRING, &music_set_name, "" },
1867 { TYPE_EMPTY, NULL, "" },
1868 { TYPE_STRING, NULL, "Override Level Artwork:"},
1869 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1870 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1871 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1872 { TYPE_EMPTY, NULL, "" },
1873 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1877 static struct TokenInfo setup_info_shortcut[] =
1879 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1880 { TYPE_KEY, &setup.shortcut.save_game, "" },
1881 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1882 { TYPE_KEY, &setup.shortcut.load_game, "" },
1883 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1884 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1885 { TYPE_EMPTY, NULL, "" },
1886 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1887 { TYPE_EMPTY, NULL, "" },
1888 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1892 static Key getSetupKey()
1894 Key key = KSYM_UNDEFINED;
1895 boolean got_key_event = FALSE;
1897 while (!got_key_event)
1899 if (PendingEvent()) /* got event */
1907 case EVENT_KEYPRESS:
1909 key = GetEventKey((KeyEvent *)&event, TRUE);
1911 /* press 'Escape' or 'Enter' to keep the existing key binding */
1912 if (key == KSYM_Escape || key == KSYM_Return)
1913 key = KSYM_UNDEFINED; /* keep old value */
1915 got_key_event = TRUE;
1919 case EVENT_KEYRELEASE:
1920 key_joystick_mapping = 0;
1924 HandleOtherEvents(&event);
1932 /* don't eat all CPU time */
1939 static void drawSetupValue(int pos)
1941 int xpos = MENU_SCREEN_VALUE_XPOS;
1942 int ypos = MENU_SCREEN_START_YPOS + pos;
1943 int font_nr = FONT_VALUE_1;
1944 int type = setup_info[pos].type;
1945 void *value = setup_info[pos].value;
1946 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
1949 if (value_string == NULL)
1952 if (type & TYPE_KEY)
1956 if (type & TYPE_QUERY)
1958 value_string = "<press key>";
1959 font_nr = FONT_INPUT_1_ACTIVE;
1962 else if (type & TYPE_STRING)
1964 int max_value_len = (SCR_FIELDX - 2) * 2;
1967 font_nr = FONT_VALUE_2;
1969 if (strlen(value_string) > max_value_len)
1970 value_string[max_value_len] = '\0';
1972 else if (type & TYPE_BOOLEAN_STYLE)
1974 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
1977 DrawText(mSX + xpos * 32, mSY + ypos * 32,
1978 (xpos == 3 ? " " : " "), font_nr);
1979 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
1982 static void changeSetupValue(int pos)
1984 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1986 *(boolean *)setup_info[pos].value ^= TRUE;
1988 else if (setup_info[pos].type & TYPE_KEY)
1992 setup_info[pos].type |= TYPE_QUERY;
1993 drawSetupValue(pos);
1994 setup_info[pos].type &= ~TYPE_QUERY;
1996 key = getSetupKey();
1997 if (key != KSYM_UNDEFINED)
1998 *(Key *)setup_info[pos].value = key;
2001 drawSetupValue(pos);
2004 static void DrawSetupScreen_Generic()
2006 char *title_string = NULL;
2010 CloseDoor(DOOR_CLOSE_2);
2014 if (setup_mode == SETUP_MODE_MAIN)
2016 setup_info = setup_info_main;
2017 title_string = "Setup";
2019 else if (setup_mode == SETUP_MODE_GAME)
2021 setup_info = setup_info_game;
2022 title_string = "Setup Game";
2024 else if (setup_mode == SETUP_MODE_EDITOR)
2026 setup_info = setup_info_editor;
2027 title_string = "Setup Editor";
2029 else if (setup_mode == SETUP_MODE_GRAPHICS)
2031 setup_info = setup_info_graphics;
2032 title_string = "Setup Graphics";
2034 else if (setup_mode == SETUP_MODE_SOUND)
2036 setup_info = setup_info_sound;
2037 title_string = "Setup Sound";
2039 else if (setup_mode == SETUP_MODE_ARTWORK)
2041 setup_info = setup_info_artwork;
2042 title_string = "Custom Artwork";
2044 else if (setup_mode == SETUP_MODE_SHORTCUT)
2046 setup_info = setup_info_shortcut;
2047 title_string = "Setup Shortcuts";
2050 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2053 for(i=0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2055 void *value_ptr = setup_info[i].value;
2056 int ypos = MENU_SCREEN_START_YPOS + i;
2057 int font_nr = FONT_MENU_1;
2059 /* set some entries to "unchangeable" according to other variables */
2060 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2061 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2062 (value_ptr == &setup.sound_music && !audio.music_available) ||
2063 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2064 setup_info[i].type |= TYPE_GHOSTED;
2066 if (setup_info[i].type & TYPE_STRING)
2067 font_nr = FONT_MENU_2;
2069 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2071 if (setup_info[i].type & TYPE_ENTER_MENU)
2072 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2073 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2074 initCursor(i, IMG_MENU_BUTTON_LEFT);
2075 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2076 initCursor(i, IMG_MENU_BUTTON);
2078 if (setup_info[i].type & TYPE_VALUE)
2086 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2089 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2091 static int choice_store[MAX_SETUP_MODES];
2092 int choice = choice_store[setup_mode]; /* always starts with 0 */
2096 if (button == MB_MENU_INITIALIZE)
2098 /* advance to first valid menu entry */
2099 while (choice < num_setup_info &&
2100 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2102 choice_store[setup_mode] = choice;
2104 drawCursor(choice, FC_RED);
2107 else if (button == MB_MENU_LEAVE)
2109 for (y=0; y<num_setup_info; y++)
2111 if (setup_info[y].type & TYPE_LEAVE_MENU)
2113 void (*menu_callback_function)(void) = setup_info[y].value;
2115 menu_callback_function();
2116 break; /* absolutely needed because function changes 'setup_info'! */
2123 if (mx || my) /* mouse input */
2125 x = (mx - mSX) / 32;
2126 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2128 else if (dx || dy) /* keyboard input */
2132 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2134 if ((setup_info[choice].type & menu_navigation_type) ||
2135 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2136 button = MB_MENU_CHOICE;
2141 /* jump to next non-empty menu entry (up or down) */
2142 while (y > 0 && y < num_setup_info - 1 &&
2143 (setup_info[y].type & TYPE_SKIP_ENTRY))
2147 if (x == 0 && y >= 0 && y < num_setup_info &&
2148 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2154 drawCursor(y, FC_RED);
2155 drawCursor(choice, FC_BLUE);
2156 choice = choice_store[setup_mode] = y;
2159 else if (!(setup_info[y].type & TYPE_GHOSTED))
2161 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2163 void (*menu_callback_function)(void) = setup_info[choice].value;
2165 menu_callback_function();
2169 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2170 (setup_info[y + 1].type & TYPE_KEY))
2173 if (setup_info[y].type & TYPE_VALUE)
2174 changeSetupValue(y);
2182 if (game_status == GAME_MODE_SETUP)
2187 void DrawSetupScreen_Input()
2191 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2193 initCursor(0, IMG_MENU_BUTTON);
2194 initCursor(1, IMG_MENU_BUTTON);
2195 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2196 initCursor(13, IMG_MENU_BUTTON_LEFT);
2198 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2199 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2201 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2202 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2203 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2206 DeactivateJoystickForCalibration();
2207 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2208 "Joysticks deactivated on this screen");
2211 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2216 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2218 if (device_name == NULL)
2221 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2224 if (strlen(device_name) > 1)
2226 char c1 = device_name[strlen(device_name) - 1];
2227 char c2 = device_name[strlen(device_name) - 2];
2229 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2230 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2233 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2234 strlen(device_name));
2237 static void drawPlayerSetupInputInfo(int player_nr)
2240 static struct SetupKeyboardInfo custom_key;
2247 { &custom_key.left, "Joystick Left" },
2248 { &custom_key.right, "Joystick Right" },
2249 { &custom_key.up, "Joystick Up" },
2250 { &custom_key.down, "Joystick Down" },
2251 { &custom_key.snap, "Button 1" },
2252 { &custom_key.bomb, "Button 2" }
2254 static char *joystick_name[MAX_PLAYERS] =
2262 custom_key = setup.input[player_nr].key;
2264 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2266 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2267 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2269 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2272 if (setup.input[player_nr].use_joystick)
2274 char *device_name = setup.input[player_nr].joy.device_name;
2276 DrawText(mSX+8*32, mSY+3*32,
2277 joystick_name[getJoystickNrFromDeviceName(device_name)],
2279 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2283 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2284 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2287 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2288 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2289 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2290 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2291 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2292 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2293 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2294 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2295 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2296 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2297 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2301 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2303 DrawText(mSX + 3*32, mSY + ypos*32,
2305 DrawText(mSX + 3*32, mSY + ypos*32,
2306 (setup.input[player_nr].use_joystick ?
2308 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2312 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2314 static int choice = 0;
2315 static int player_nr = 0;
2318 int pos_start = SETUPINPUT_SCREEN_POS_START;
2319 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2320 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2321 int pos_end = SETUPINPUT_SCREEN_POS_END;
2323 if (button == MB_MENU_INITIALIZE)
2325 drawPlayerSetupInputInfo(player_nr);
2326 drawCursor(choice, FC_RED);
2329 else if (button == MB_MENU_LEAVE)
2331 setup_mode = SETUP_MODE_MAIN;
2336 if (mx || my) /* mouse input */
2338 x = (mx - mSX) / 32;
2339 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2341 else if (dx || dy) /* keyboard input */
2343 if (dx && choice == 0)
2344 x = (dx < 0 ? 10 : 12);
2345 else if ((dx && choice == 1) ||
2346 (dx == +1 && choice == 2) ||
2347 (dx == -1 && choice == pos_end))
2348 button = MB_MENU_CHOICE;
2352 if (y >= pos_empty1 && y <= pos_empty2)
2353 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2356 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2358 static unsigned long delay = 0;
2360 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2367 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2369 drawPlayerSetupInputInfo(player_nr);
2371 else if (x == 0 && y >= pos_start && y <= pos_end &&
2372 !(y >= pos_empty1 && y <= pos_empty2))
2378 drawCursor(y, FC_RED);
2379 drawCursor(choice, FC_BLUE);
2387 char *device_name = setup.input[player_nr].joy.device_name;
2389 if (!setup.input[player_nr].use_joystick)
2391 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2393 setJoystickDeviceToNr(device_name, new_device_nr);
2394 setup.input[player_nr].use_joystick = TRUE;
2398 int device_nr = getJoystickNrFromDeviceName(device_name);
2399 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2401 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2402 setup.input[player_nr].use_joystick = FALSE;
2404 setJoystickDeviceToNr(device_name, new_device_nr);
2407 drawPlayerSetupInputInfo(player_nr);
2411 if (setup.input[player_nr].use_joystick)
2414 CalibrateJoystick(player_nr);
2417 CustomizeKeyboard(player_nr);
2419 else if (y == pos_end)
2423 setup_mode = SETUP_MODE_MAIN;
2434 if (game_status == GAME_MODE_SETUP)
2439 void CustomizeKeyboard(int player_nr)
2443 boolean finished = FALSE;
2444 static struct SetupKeyboardInfo custom_key;
2449 } customize_step[] =
2451 { &custom_key.left, "Move Left" },
2452 { &custom_key.right, "Move Right" },
2453 { &custom_key.up, "Move Up" },
2454 { &custom_key.down, "Move Down" },
2455 { &custom_key.snap, "Snap Field" },
2456 { &custom_key.bomb, "Place Bomb" }
2459 /* read existing key bindings from player setup */
2460 custom_key = setup.input[player_nr].key;
2463 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2469 DrawText(mSX, mSY + (2+2*step_nr)*32,
2470 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2471 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2472 "Key:", FONT_INPUT_1_ACTIVE);
2473 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2474 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2478 if (PendingEvent()) /* got event */
2486 case EVENT_KEYPRESS:
2488 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2490 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2496 /* all keys configured -- wait for "Escape" or "Return" key */
2500 /* press 'Enter' to keep the existing key binding */
2501 if (key == KSYM_Return)
2502 key = *customize_step[step_nr].key;
2504 /* check if key already used */
2505 for (i=0; i<step_nr; i++)
2506 if (*customize_step[i].key == key)
2511 /* got new key binding */
2512 *customize_step[step_nr].key = key;
2513 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2515 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2516 getKeyNameFromKey(key), FONT_VALUE_1);
2519 /* un-highlight last query */
2520 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2521 customize_step[step_nr-1].text, FONT_MENU_1);
2522 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2523 "Key:", FONT_MENU_1);
2525 /* press 'Enter' to leave */
2528 DrawText(mSX + 16, mSY + 15*32+16,
2529 "Press Enter", FONT_TITLE_1);
2533 /* query next key binding */
2534 DrawText(mSX, mSY+(2+2*step_nr)*32,
2535 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2536 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2537 "Key:", FONT_INPUT_1_ACTIVE);
2538 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2539 getKeyNameFromKey(*customize_step[step_nr].key),
2544 case EVENT_KEYRELEASE:
2545 key_joystick_mapping = 0;
2549 HandleOtherEvents(&event);
2557 /* don't eat all CPU time */
2561 /* write new key bindings back to player setup */
2562 setup.input[player_nr].key = custom_key;
2565 DrawSetupScreen_Input();
2568 static boolean CalibrateJoystickMain(int player_nr)
2570 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2571 int new_joystick_xright = JOYSTICK_XMIDDLE;
2572 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2573 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2574 int new_joystick_xmiddle, new_joystick_ymiddle;
2576 int joystick_fd = joystick.fd[player_nr];
2577 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2578 boolean check[3][3];
2579 int check_remaining = 3 * 3;
2584 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2587 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2592 for(y=0; y < 3; y++)
2594 for(x=0; x < 3; x++)
2596 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2597 check[x][y] = FALSE;
2601 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2602 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2603 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2604 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2605 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2606 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2607 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2609 joy_value = Joystick(player_nr);
2610 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2611 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2613 /* eventually uncalibrated center position (joystick could be uncentered) */
2614 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2617 new_joystick_xmiddle = joy_x;
2618 new_joystick_ymiddle = joy_y;
2620 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2623 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2628 if (PendingEvent()) /* got event */
2636 case EVENT_KEYPRESS:
2637 switch(GetEventKey((KeyEvent *)&event, TRUE))
2640 if (check_remaining == 0)
2653 case EVENT_KEYRELEASE:
2654 key_joystick_mapping = 0;
2658 HandleOtherEvents(&event);
2663 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2666 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2667 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2668 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2669 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2671 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2672 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2673 setup.input[player_nr].joy.xright = new_joystick_xright;
2674 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2675 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2676 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2678 CheckJoystickData();
2680 joy_value = Joystick(player_nr);
2682 if (joy_value & JOY_BUTTON && check_remaining == 0)
2685 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2686 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2688 if (x != last_x || y != last_y)
2690 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2691 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2696 if (check_remaining > 0 && !check[x+1][y+1])
2698 check[x+1][y+1] = TRUE;
2704 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2705 setup.input[player_nr].joy.xleft,
2706 setup.input[player_nr].joy.xmiddle,
2707 setup.input[player_nr].joy.xright);
2708 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2709 setup.input[player_nr].joy.yupper,
2710 setup.input[player_nr].joy.ymiddle,
2711 setup.input[player_nr].joy.ylower);
2720 /* don't eat all CPU time */
2724 /* calibrated center position (joystick should now be centered) */
2725 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2728 new_joystick_xmiddle = joy_x;
2729 new_joystick_ymiddle = joy_y;
2733 DrawSetupScreen_Input();
2735 /* wait until the last pressed button was released */
2736 while (Joystick(player_nr) & JOY_BUTTON)
2738 if (PendingEvent()) /* got event */
2743 HandleOtherEvents(&event);
2752 void CalibrateJoystick(int player_nr)
2754 if (!CalibrateJoystickMain(player_nr))
2758 DrawText(mSX + 16, mSY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2759 DrawText(mSX, mSY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2761 Delay(2000); /* show error message for two seconds */
2765 void DrawSetupScreen()
2767 DeactivateJoystick();
2769 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2771 if (setup_mode == SETUP_MODE_INPUT)
2772 DrawSetupScreen_Input();
2773 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2774 DrawChooseTree(&artwork.gfx_current);
2775 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2776 DrawChooseTree(&artwork.snd_current);
2777 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2778 DrawChooseTree(&artwork.mus_current);
2780 DrawSetupScreen_Generic();
2786 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2788 if (setup_mode == SETUP_MODE_INPUT)
2789 HandleSetupScreen_Input(mx, my, dx, dy, button);
2790 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2791 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2792 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2793 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2794 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2795 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2797 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2803 void HandleGameActions()
2805 if (game_status != GAME_MODE_PLAYING)
2808 if (local_player->LevelSolved)
2811 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2819 if (tape.auto_play && !tape.playing)
2820 AutoPlayTape(); /* continue automatically playing next tape */
2824 /* ---------- new screen button stuff -------------------------------------- */
2826 /* graphic position and size values for buttons and scrollbars */
2827 #define SC_SCROLLBUTTON_XSIZE TILEX
2828 #define SC_SCROLLBUTTON_YSIZE TILEY
2830 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2831 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
2832 SC_SCROLLBUTTON_YSIZE)
2833 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2834 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
2835 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2836 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
2837 SC_SCROLLBUTTON_YSIZE)
2838 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2839 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
2840 SC_SCROLL_VERTICAL_YSIZE)
2842 #define SC_BORDER_SIZE 14
2846 int gfx_unpressed, gfx_pressed;
2850 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2853 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2854 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2855 SCREEN_CTRL_ID_SCROLL_UP,
2859 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2860 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2861 SCREEN_CTRL_ID_SCROLL_DOWN,
2868 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2869 Bitmap **gfx_unpressed, **gfx_pressed;
2871 int gfx_unpressed, gfx_pressed;
2878 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2881 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2882 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2884 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2886 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
2887 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2888 GD_TYPE_SCROLLBAR_VERTICAL,
2889 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2890 "scroll level series vertically"
2894 static void CreateScreenScrollbuttons()
2896 struct GadgetInfo *gi;
2897 unsigned long event_mask;
2900 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2902 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2903 int gfx_unpressed, gfx_pressed;
2904 int x, y, width, height;
2905 int gd_x1, gd_x2, gd_y1, gd_y2;
2906 int id = scrollbutton_info[i].gadget_id;
2908 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2910 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
2911 y = mSY + scrollbutton_info[i].y;
2912 width = SC_SCROLLBUTTON_XSIZE;
2913 height = SC_SCROLLBUTTON_YSIZE;
2915 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
2916 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
2917 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
2919 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2920 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2921 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2922 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2923 gd_x1 = graphic_info[gfx_unpressed].src_x;
2924 gd_y1 = graphic_info[gfx_unpressed].src_y;
2925 gd_x2 = graphic_info[gfx_pressed].src_x;
2926 gd_y2 = graphic_info[gfx_pressed].src_y;
2928 gi = CreateGadget(GDI_CUSTOM_ID, id,
2929 GDI_CUSTOM_TYPE_ID, i,
2930 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2935 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2936 GDI_STATE, GD_BUTTON_UNPRESSED,
2937 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2938 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2939 GDI_DIRECT_DRAW, FALSE,
2940 GDI_EVENT_MASK, event_mask,
2941 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2945 Error(ERR_EXIT, "cannot create gadget");
2947 screen_gadget[id] = gi;
2951 static void CreateScreenScrollbars()
2955 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2957 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2958 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2959 int gfx_unpressed, gfx_pressed;
2961 int x, y, width, height;
2962 int gd_x1, gd_x2, gd_y1, gd_y2;
2963 struct GadgetInfo *gi;
2964 int items_max, items_visible, item_position;
2965 unsigned long event_mask;
2966 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
2967 int id = scrollbar_info[i].gadget_id;
2969 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2971 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
2972 y = mSY + scrollbar_info[i].y;
2973 width = scrollbar_info[i].width;
2974 height = scrollbar_info[i].height;
2976 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
2977 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
2979 items_max = num_page_entries;
2980 items_visible = num_page_entries;
2983 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2984 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
2985 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
2991 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2992 gfx_pressed = scrollbar_info[i].gfx_pressed;
2993 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2994 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2995 gd_x1 = graphic_info[gfx_unpressed].src_x;
2996 gd_y1 = graphic_info[gfx_unpressed].src_y;
2997 gd_x2 = graphic_info[gfx_pressed].src_x;
2998 gd_y2 = graphic_info[gfx_pressed].src_y;
3001 gi = CreateGadget(GDI_CUSTOM_ID, id,
3002 GDI_CUSTOM_TYPE_ID, i,
3003 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3008 GDI_TYPE, scrollbar_info[i].type,
3009 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3010 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3011 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3012 GDI_STATE, GD_BUTTON_UNPRESSED,
3013 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3014 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3015 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3016 GDI_DIRECT_DRAW, FALSE,
3017 GDI_EVENT_MASK, event_mask,
3018 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3022 Error(ERR_EXIT, "cannot create gadget");
3024 screen_gadget[id] = gi;
3028 void CreateScreenGadgets()
3030 int last_game_status = game_status; /* save current game status */
3032 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3035 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3037 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3039 /* copy pointers to clip mask and GC */
3040 scrollbar_bitmap[i]->clip_mask =
3041 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3042 scrollbar_bitmap[i]->stored_clip_gc =
3043 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3045 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3046 scrollbar_bitmap[i],
3047 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3048 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3049 TILEX, TILEY, 0, 0);
3053 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3054 game_status = GAME_MODE_LEVELS;
3056 CreateScreenScrollbuttons();
3057 CreateScreenScrollbars();
3059 game_status = last_game_status; /* restore current game status */
3062 void FreeScreenGadgets()
3066 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3067 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3069 /* prevent freeing clip mask and GC twice */
3070 scrollbar_bitmap[i]->clip_mask = None;
3071 scrollbar_bitmap[i]->stored_clip_gc = None;
3073 FreeBitmap(scrollbar_bitmap[i]);
3077 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3078 FreeGadget(screen_gadget[i]);
3081 void MapChooseTreeGadgets(TreeInfo *ti)
3083 int num_entries = numTreeInfoInGroup(ti);
3086 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3089 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3090 MapGadget(screen_gadget[i]);
3093 void UnmapChooseTreeGadgets()
3097 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3098 UnmapGadget(screen_gadget[i]);
3101 static void HandleScreenGadgets(struct GadgetInfo *gi)
3103 int id = gi->custom_id;
3105 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3110 case SCREEN_CTRL_ID_SCROLL_UP:
3111 if (game_status == GAME_MODE_LEVELS)
3112 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3113 else if (game_status == GAME_MODE_SETUP)
3114 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3117 case SCREEN_CTRL_ID_SCROLL_DOWN:
3118 if (game_status == GAME_MODE_LEVELS)
3119 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3120 else if (game_status == GAME_MODE_SETUP)
3121 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3124 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3125 if (game_status == GAME_MODE_LEVELS)
3126 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3127 else if (game_status == GAME_MODE_SETUP)
3128 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);