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];
520 static int helpscreen_action[] =
522 IMG_PLAYER_1_MOVING_DOWN, 16,
523 IMG_PLAYER_1_MOVING_UP, 16,
524 IMG_PLAYER_1_MOVING_LEFT, 16,
525 IMG_PLAYER_1_MOVING_RIGHT, 16,
526 IMG_PLAYER_1_PUSHING_LEFT, 16,
527 IMG_PLAYER_1_PUSHING_RIGHT, 16, HA_NEXT,
529 IMG_SAND, -1, HA_NEXT,
531 IMG_EMPTY_SPACE, -1, HA_NEXT,
533 IMG_QUICKSAND_EMPTY, -1, HA_NEXT,
535 IMG_STEELWALL, -1, HA_NEXT,
537 IMG_WALL, -1, HA_NEXT,
539 IMG_EXPANDABLE_WALL_GROWING_LEFT, 20,
542 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 20,
545 IMG_EXPANDABLE_WALL_GROWING_UP, 20,
548 IMG_EXPANDABLE_WALL_GROWING_DOWN, 20,
550 IMG_EMPTY_SPACE, 20, HA_NEXT,
552 IMG_INVISIBLE_WALL, -1, HA_NEXT,
554 IMG_WALL_SLIPPERY, -1, HA_NEXT,
556 IMG_FONT_GAME_INFO, -1, HA_NEXT,
558 IMG_EMERALD, -1, HA_NEXT,
560 IMG_DIAMOND, -1, HA_NEXT,
562 IMG_BD_DIAMOND, -1, HA_NEXT,
564 IMG_EMERALD_YELLOW, 50,
566 IMG_EMERALD_PURPLE, 50, HA_NEXT,
568 IMG_BD_ROCK, -1, HA_NEXT,
572 IMG_EMPTY_SPACE, 10, HA_NEXT,
576 IMG_EMERALD, 20, HA_NEXT,
578 IMG_WALL_EMERALD, 100,
580 IMG_EMERALD, 20, HA_NEXT,
582 IMG_WALL_DIAMOND, 100,
584 IMG_DIAMOND, 20, HA_NEXT,
586 IMG_WALL_BD_DIAMOND, 100,
588 IMG_BD_DIAMOND, 20, HA_NEXT,
590 IMG_WALL_EMERALD_YELLOW, 100,
592 IMG_EMERALD_YELLOW, 20,
593 IMG_WALL_EMERALD_RED, 100,
596 IMG_WALL_EMERALD_PURPLE, 100,
598 IMG_EMERALD_PURPLE, 20, HA_NEXT,
600 IMG_ACID, -1, HA_NEXT,
605 IMG_KEY_4, 50, HA_NEXT,
610 IMG_GATE_4, 50, HA_NEXT,
615 IMG_GATE_4_GRAY, 50, HA_NEXT,
617 IMG_DYNAMITE, -1, HA_NEXT,
619 IMG_DYNAMITE_ACTIVE, 96,
621 IMG_EMPTY_SPACE, 20, HA_NEXT,
623 IMG_DYNABOMB_ACTIVE, 100,
625 IMG_EMPTY_SPACE, 20, HA_NEXT,
627 IMG_DYNABOMB_INCREASE_NUMBER, -1, HA_NEXT,
629 IMG_DYNABOMB_INCREASE_SIZE, -1, HA_NEXT,
631 IMG_DYNABOMB_INCREASE_POWER, -1, HA_NEXT,
633 IMG_SPACESHIP_RIGHT, 16,
634 IMG_SPACESHIP_UP, 16,
635 IMG_SPACESHIP_LEFT, 16,
636 IMG_SPACESHIP_DOWN, 16, HA_NEXT,
641 IMG_BUG_DOWN, 16, HA_NEXT,
643 IMG_BD_BUTTERFLY, -1, HA_NEXT,
645 IMG_BD_FIREFLY, -1, HA_NEXT,
647 IMG_PACMAN_RIGHT, 16,
650 IMG_PACMAN_DOWN, 16, HA_NEXT,
652 IMG_YAMYAM, -1, HA_NEXT,
654 IMG_DARK_YAMYAM, -1, HA_NEXT,
656 IMG_ROBOT, -1, HA_NEXT,
658 IMG_MOLE_MOVING_RIGHT, 16,
659 IMG_MOLE_MOVING_UP, 16,
660 IMG_MOLE_MOVING_LEFT, 16,
661 IMG_MOLE_MOVING_DOWN, 16, HA_NEXT,
663 IMG_PENGUIN_MOVING_RIGHT, 16,
664 IMG_PENGUIN_MOVING_UP, 16,
665 IMG_PENGUIN_MOVING_LEFT, 16,
666 IMG_PENGUIN_MOVING_DOWN, 16, HA_NEXT,
668 IMG_PIG_MOVING_RIGHT, 16,
669 IMG_PIG_MOVING_UP, 16,
670 IMG_PIG_MOVING_LEFT, 16,
671 IMG_PIG_MOVING_DOWN, 16, HA_NEXT,
673 IMG_DRAGON_MOVING_RIGHT, 16,
674 IMG_DRAGON_MOVING_UP, 16,
675 IMG_DRAGON_MOVING_LEFT, 16,
676 IMG_DRAGON_MOVING_DOWN, 16, HA_NEXT,
678 IMG_SATELLITE, -1, HA_NEXT,
681 IMG_ROBOT_WHEEL_ACTIVE, 100, HA_NEXT,
684 IMG_LAMP_ACTIVE, 50, HA_NEXT,
686 IMG_TIME_ORB_FULL, 50,
687 IMG_TIME_ORB_EMPTY, 50, HA_NEXT,
690 IMG_AMOEBA_GROWING, 6,
691 IMG_AMOEBA_WET, 20, HA_NEXT,
693 IMG_AMOEBA_DEAD, -1, HA_NEXT,
695 IMG_AMOEBA_WET, -1, HA_NEXT,
698 IMG_AMOEBA_GROWING, 6, HA_NEXT,
703 IMG_DIAMOND, 20, HA_NEXT,
705 IMG_GAME_OF_LIFE, -1, HA_NEXT,
707 IMG_BIOMAZE, -1, HA_NEXT,
709 IMG_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
711 IMG_BD_MAGIC_WALL_ACTIVE, -1, HA_NEXT,
713 IMG_EXIT_CLOSED, 200,
714 IMG_EXIT_OPENING, 16,
715 IMG_EXIT_OPEN, 100, HA_NEXT,
717 IMG_EXIT_OPEN, -1, HA_NEXT,
719 IMG_SOKOBAN_OBJECT, -1, HA_NEXT,
721 IMG_SOKOBAN_FIELD_EMPTY, -1, HA_NEXT,
723 IMG_SOKOBAN_FIELD_FULL, -1, HA_NEXT,
725 IMG_SPEED_PILL, -1, HA_NEXT,
731 static char *helpscreen_eltext[][2] =
733 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
734 {"Normal sand:", "You can dig through it"},
735 {"Empty field:", "You can walk through it"},
736 {"Quicksand: You cannot pass it,", "but rocks can fall through it"},
737 {"Massive Wall:", "Nothing can go through it"},
738 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
739 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
740 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
741 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
742 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
743 {"Emerald: You must collect enough of","them to finish a level"},
744 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
745 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
746 {"Colorful Gems:", "Seem to behave like Emeralds"},
747 {"Rock: Smashes several things;", "Can be moved by the player"},
748 {"Bomb: You can move it, but be", "careful when dropping it"},
749 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
750 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
751 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
752 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
753 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
754 {"Acid: Things that fall in are gone", "forever (including our hero)"},
755 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
756 {"Door: Can be opened by the key", "with the same color"},
757 {"Door: You have to find out the", "right color of the key for it"},
758 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
759 {"Dynamite: This one explodes after", "a few seconds"},
760 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
761 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
762 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
763 {"Dyna Bomb: Increases the power of", "explosion of dyna bombs"},
764 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
765 {"Bug: Moves at the right side", "of walls; don't touch it!"},
766 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
767 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
768 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
769 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
770 {"Cruncher (BD style):", "Eats almost everything"},
771 {"Robot: Tries to kill the player", ""},
772 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
773 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
774 {"The Pig: Harmless, but eats all", "gems it can get"},
775 {"The Dragon: Breathes fire,", "especially to some monsters"},
776 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
777 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
778 {"Light Bulb: All of them must be", "switched on to finish a level"},
779 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
780 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
781 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
782 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
783 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
784 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
785 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
786 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
787 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
788 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
789 {"Exit door: Opens if you have enough","emeralds to finish the level"},
790 {"Open exit door: Enter here to leave","the level and exit the actual game"},
791 {"Sokoban element: Object which must", "be pushed to an empty field"},
792 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
793 {"Sokoban element: Field with object", "which can be pushed away"},
794 {"Speed pill: Lets the player run", "twice as fast as normally"},
796 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
799 static char *helpscreen_music[][3] =
801 { "Alchemy", "Ian Boddy", "Drive" },
802 { "The Chase", "Propaganda", "A Secret Wish" },
803 { "Network 23", "Tangerine Dream", "Exit" },
804 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
805 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
806 { "Voyager", "The Alan Parsons Project","Pyramid" },
807 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
811 static int num_helpscreen_music = 7;
812 static int helpscreen_musicpos;
815 void DrawHelpScreenElAction(int start)
818 int xstart = mSX + 16;
819 int ystart = mSY + 64 + 2 * 32;
820 int ystep = TILEY + 4;
821 int element, action, direction;
826 while (info_animation_info[j].element != -999)
828 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
832 while (info_animation_info[j].element != -1)
841 j += helpscreen_step[i - start];
843 element = info_animation_info[j].element;
844 action = info_animation_info[j].action;
845 direction = info_animation_info[j].direction;
847 if (action != -1 && direction != -1)
848 graphic = el_act_dir2img(element, action, direction);
849 else if (action != -1)
850 graphic = el_act2img(element, action);
851 else if (direction != -1)
852 graphic = el_act2img(element, direction);
854 graphic = el2img(element);
856 delay = info_animation_info[j++].delay;
861 if (helpscreen_frame[i - start] == 0)
864 helpscreen_frame[i - start] = delay - 1;
868 sync_frame = delay - helpscreen_frame[i - start];
869 helpscreen_frame[i - start]--;
872 if (info_animation_info[j].element == -1)
874 if (!helpscreen_frame[i - start])
875 helpscreen_step[i - start] = 0;
879 if (!helpscreen_frame[i - start])
880 helpscreen_step[i - start]++;
881 while(info_animation_info[j].element != -1)
887 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
889 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
890 graphic, sync_frame, USE_MASKING);
895 redraw_mask |= REDRAW_FIELD;
902 void DrawHelpScreenElAction(int start)
905 int xstart = mSX + 16;
906 int ystart = mSY + 64 + 2 * 32;
907 int ystep = TILEY + 4;
912 while (helpscreen_action[j] != HA_END)
914 if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
918 while (helpscreen_action[j] != HA_NEXT)
927 j += 2 * helpscreen_step[i-start];
928 graphic = helpscreen_action[j++];
929 frame_count = helpscreen_action[j++];
930 if (frame_count == -1)
931 frame_count = 1000000;
933 if (helpscreen_frame[i-start] == 0)
936 helpscreen_frame[i-start] = frame_count - 1;
940 sync_frame = frame_count - helpscreen_frame[i-start];
941 helpscreen_frame[i-start]--;
944 if (helpscreen_action[j] == HA_NEXT)
946 if (!helpscreen_frame[i-start])
947 helpscreen_step[i-start] = 0;
951 if (!helpscreen_frame[i-start])
952 helpscreen_step[i-start]++;
953 while(helpscreen_action[j] != HA_NEXT)
959 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
961 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
962 graphic, sync_frame, USE_MASKING);
964 frame = getGraphicAnimationFrame(graphic, sync_frame);
966 DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
974 redraw_mask |= REDRAW_FIELD;
987 void DrawHelpScreenElText(int start)
990 int xstart = mSX + 56, ystart = mSY + 65 + 2 * 32, ystep = TILEY + 4;
991 int ybottom = SYSIZE - 20;
993 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
997 DrawTextFCentered(100, FONT_TEXT_1, "The game elements:");
999 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
1002 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
1003 helpscreen_eltext[i][0], FONT_TEXT_2);
1004 DrawText(xstart, ystart + (i - start) * ystep + 16,
1005 helpscreen_eltext[i][1], FONT_TEXT_2);
1008 DrawTextFCentered(ybottom, FONT_TEXT_4,
1009 "Press any key or button for next page");
1012 void DrawHelpScreenMusicText(int num)
1014 struct MusicFileInfo *list = music_file_info;
1015 int ystart = 150, ystep = 30;
1016 int ybottom = SYSIZE - 20;
1019 for (i=0; i < num && list; i++)
1022 FadeSoundsAndMusic();
1026 DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
1029 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
1030 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "\"%s\"", list->title);
1031 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
1032 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "%s", list->artist);
1033 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1034 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3, "\"%s\"", list->album);
1036 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
1037 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
1038 "\"%s\"", helpscreen_music[num][0]);
1039 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
1040 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3,
1041 "%s", helpscreen_music[num][1]);
1042 DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1043 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
1044 "\"%s\"", helpscreen_music[num][2]);
1047 DrawTextFCentered(ybottom, FONT_TEXT_4,
1048 "Press any key or button for next page");
1051 PlaySoundLoop(background_loop[num]);
1055 void DrawHelpScreenCreditsText()
1057 int ystart = 150, ystep = 30;
1058 int ybottom = SYSIZE - 20;
1060 FadeSoundsAndMusic();
1064 DrawTextFCentered(100, FONT_TEXT_1, "Credits:");
1065 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1066 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1067 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1068 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1069 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_2,
1070 "...and many thanks to all contributors");
1071 DrawTextFCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1073 DrawTextFCentered(ybottom, FONT_TEXT_4,
1074 "Press any key or button for next page");
1077 void DrawHelpScreenContactText()
1079 int ystart = 150, ystep = 30;
1080 int ybottom = SYSIZE - 20;
1085 DrawTextFCentered(100, FONT_TEXT_1, "Program information:");
1087 DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2,
1088 "This game is Freeware!");
1089 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_2,
1090 "If you like it, send e-mail to:");
1091 DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_3,
1092 "info@artsoft.org");
1093 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_2,
1094 "or SnailMail to:");
1095 DrawTextFCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1097 DrawTextFCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1098 "Detmolder Strasse 189");
1099 DrawTextFCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1101 DrawTextFCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1104 DrawTextFCentered(ystart + 7 * ystep, FONT_TEXT_2,
1105 "If you have created new levels,");
1106 DrawTextFCentered(ystart + 8 * ystep, FONT_TEXT_2,
1107 "send them to me to include them!");
1108 DrawTextFCentered(ystart + 9 * ystep, FONT_TEXT_2,
1111 DrawTextFCentered(ybottom, FONT_TEXT_4,
1112 "Press any key or button for main menu");
1115 void DrawHelpScreen()
1117 struct MusicFileInfo *list;
1121 CloseDoor(DOOR_CLOSE_2);
1123 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1124 helpscreen_step[i] = helpscreen_frame[i] = 0;
1125 helpscreen_musicpos = 0;
1126 helpscreen_state = 0;
1128 LoadInfoAnimations();
1131 num_helpscreen_els = 0;
1132 for (i=0; info_animation_info[i].element != -999; i++)
1133 if (info_animation_info[i].element == -1)
1134 num_helpscreen_els++;
1136 num_helpscreen_music = 0;
1137 for (list = music_file_info; list != NULL; list = list->next)
1138 num_helpscreen_music++;
1140 DrawHelpScreenElText(0);
1141 DrawHelpScreenElAction(0);
1150 void HandleHelpScreen(int button)
1152 static unsigned long hs_delay = 0;
1153 int num_helpscreen_els_pages =
1154 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
1155 int button_released = !button;
1158 if (button_released)
1160 if (helpscreen_state < num_helpscreen_els_pages - 1)
1162 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
1163 helpscreen_step[i] = helpscreen_frame[i] = 0;
1167 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
1168 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1170 else if (helpscreen_state <
1171 num_helpscreen_els_pages + num_helpscreen_music - 1)
1174 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
1176 else if (helpscreen_state ==
1177 num_helpscreen_els_pages + num_helpscreen_music - 1)
1180 DrawHelpScreenCreditsText();
1182 else if (helpscreen_state ==
1183 num_helpscreen_els_pages + num_helpscreen_music)
1186 DrawHelpScreenContactText();
1190 FadeSoundsAndMusic();
1192 game_status = GAME_MODE_MAIN;
1198 if (DelayReached(&hs_delay, GAME_FRAME_DELAY))
1200 if (helpscreen_state < num_helpscreen_els_pages)
1201 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
1204 PlayMenuSoundIfLoop();
1211 void HandleTypeName(int newxpos, Key key)
1213 static int xpos = 0, ypos = 2;
1214 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1215 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1216 int startx = mSX + 32 + name_width;
1217 int starty = mSY + ypos * 32;
1223 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1224 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1229 if (((key >= KSYM_A && key <= KSYM_Z) ||
1230 (key >= KSYM_a && key <= KSYM_z)) &&
1231 xpos < MAX_PLAYER_NAME_LEN)
1235 if (key >= KSYM_A && key <= KSYM_Z)
1236 ascii = 'A' + (char)(key - KSYM_A);
1238 ascii = 'a' + (char)(key - KSYM_a);
1240 setup.player_name[xpos] = ascii;
1241 setup.player_name[xpos + 1] = 0;
1244 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1245 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1247 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1250 setup.player_name[xpos] = 0;
1252 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1254 else if (key == KSYM_Return && xpos > 0)
1256 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1257 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1260 game_status = GAME_MODE_MAIN;
1266 static void DrawChooseTree(TreeInfo **ti_ptr)
1270 FreeScreenGadgets();
1271 CreateScreenGadgets();
1273 CloseDoor(DOOR_CLOSE_2);
1277 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
1278 MapChooseTreeGadgets(*ti_ptr);
1284 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1286 struct GadgetInfo *gi = screen_gadget[id];
1287 int items_max, items_visible, item_position;
1289 items_max = numTreeInfoInGroup(ti);
1290 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1291 item_position = first_entry;
1293 if (item_position > items_max - items_visible)
1294 item_position = items_max - items_visible;
1296 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1297 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1298 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1301 static void drawChooseTreeList(int first_entry, int num_page_entries,
1305 char buffer[SCR_FIELDX * 2];
1306 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1307 char *title_string = NULL;
1308 int xoffset_setup = 16;
1309 int yoffset_setup = 16;
1310 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1311 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1312 int last_game_status = game_status; /* save current game status */
1315 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1316 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1317 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1318 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1320 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1322 /* force LEVELS font on artwork setup screen */
1323 game_status = GAME_MODE_LEVELS;
1325 /* clear tree list area, but not title or scrollbar */
1326 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1327 SXSIZE - 32 + menu.scrollbar_xoffset,
1328 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1330 for(i=0; i<num_page_entries; i++)
1332 TreeInfo *node, *node_first;
1333 int entry_pos = first_entry + i;
1334 int ypos = MENU_SCREEN_START_YPOS + i;
1336 node_first = getTreeInfoFirstGroupEntry(ti);
1337 node = getTreeInfoFromPos(node_first, entry_pos);
1339 strncpy(buffer, node->name , max_buffer_len);
1340 buffer[max_buffer_len] = '\0';
1342 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1344 if (node->parent_link)
1345 initCursor(i, IMG_MENU_BUTTON_LEFT);
1346 else if (node->level_group)
1347 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1349 initCursor(i, IMG_MENU_BUTTON);
1352 game_status = last_game_status; /* restore current game status */
1354 redraw_mask |= REDRAW_FIELD;
1357 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1359 TreeInfo *node, *node_first;
1360 int x, last_redraw_mask = redraw_mask;
1362 if (ti->type != TREE_TYPE_LEVEL_DIR)
1365 node_first = getTreeInfoFirstGroupEntry(ti);
1366 node = getTreeInfoFromPos(node_first, entry_pos);
1368 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1370 if (node->parent_link)
1371 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1373 else if (node->level_group)
1374 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1376 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1377 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1378 node->levels, node->class_desc);
1380 /* let BackToFront() redraw only what is needed */
1381 redraw_mask = last_redraw_mask | REDRAW_TILES;
1382 for (x=0; x<SCR_FIELDX; x++)
1383 MarkTileDirty(x, 1);
1386 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1389 TreeInfo *ti = *ti_ptr;
1391 int y = ti->cl_cursor;
1392 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1393 int num_entries = numTreeInfoInGroup(ti);
1394 int num_page_entries;
1395 int last_game_status = game_status; /* save current game status */
1397 /* force LEVELS draw offset on choose level and artwork setup screen */
1398 game_status = GAME_MODE_LEVELS;
1400 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1401 num_page_entries = num_entries;
1403 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1405 game_status = last_game_status; /* restore current game status */
1407 if (button == MB_MENU_INITIALIZE)
1409 int num_entries = numTreeInfoInGroup(ti);
1410 int entry_pos = posTreeInfo(ti);
1412 if (ti->cl_first == -1)
1414 /* only on initialization */
1415 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1416 ti->cl_cursor = entry_pos - ti->cl_first;
1418 else if (ti->cl_cursor >= num_page_entries ||
1419 (num_entries > num_page_entries &&
1420 num_entries - ti->cl_first < num_page_entries))
1422 /* only after change of list size (by custom graphic configuration) */
1423 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1424 ti->cl_cursor = entry_pos - ti->cl_first;
1427 if (dx == 999) /* first entry is set by scrollbar position */
1430 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1433 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1434 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1435 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1439 else if (button == MB_MENU_LEAVE)
1441 if (ti->node_parent)
1443 *ti_ptr = ti->node_parent;
1444 DrawChooseTree(ti_ptr);
1446 else if (game_status == GAME_MODE_SETUP)
1452 game_status = GAME_MODE_MAIN;
1459 if (mx || my) /* mouse input */
1461 int last_game_status = game_status; /* save current game status */
1463 /* force LEVELS draw offset on artwork setup screen */
1464 game_status = GAME_MODE_LEVELS;
1466 x = (mx - mSX) / 32;
1467 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1469 game_status = last_game_status; /* restore current game status */
1471 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1473 /* move cursor instead of scrolling when already at start/end of list */
1474 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1476 else if (dy == +1 * SCROLL_LINE &&
1477 ti->cl_first + num_page_entries == num_entries)
1480 /* handle scrolling screen one line or page */
1481 if (ti->cl_cursor + dy < 0 ||
1482 ti->cl_cursor + dy > num_page_entries - 1)
1484 if (ABS(dy) == SCROLL_PAGE)
1485 step = num_page_entries - 1;
1487 if (dy < 0 && ti->cl_first > 0)
1489 /* scroll page/line up */
1491 ti->cl_first -= step;
1492 if (ti->cl_first < 0)
1495 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1496 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1497 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1498 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1501 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1503 /* scroll page/line down */
1505 ti->cl_first += step;
1506 if (ti->cl_first + num_page_entries > num_entries)
1507 ti->cl_first = MAX(0, num_entries - num_page_entries);
1509 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1510 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1511 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1512 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1519 /* handle moving cursor one line */
1520 y = ti->cl_cursor + dy;
1525 TreeInfo *node_first, *node_cursor;
1526 int entry_pos = ti->cl_first + y;
1528 node_first = getTreeInfoFirstGroupEntry(ti);
1529 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1531 if (node_cursor->node_group)
1533 node_cursor->cl_first = ti->cl_first;
1534 node_cursor->cl_cursor = ti->cl_cursor;
1535 *ti_ptr = node_cursor->node_group;
1536 DrawChooseTree(ti_ptr);
1541 else if (dx == -1 && ti->node_parent)
1543 *ti_ptr = ti->node_parent;
1544 DrawChooseTree(ti_ptr);
1549 if (x == 0 && y >= 0 && y < num_page_entries)
1553 if (y != ti->cl_cursor)
1555 drawChooseTreeCursor(y, FC_RED);
1556 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1557 drawChooseTreeInfo(ti->cl_first + y, ti);
1563 TreeInfo *node_first, *node_cursor;
1564 int entry_pos = ti->cl_first + y;
1566 node_first = getTreeInfoFirstGroupEntry(ti);
1567 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1569 if (node_cursor->node_group)
1571 node_cursor->cl_first = ti->cl_first;
1572 node_cursor->cl_cursor = ti->cl_cursor;
1573 *ti_ptr = node_cursor->node_group;
1574 DrawChooseTree(ti_ptr);
1576 else if (node_cursor->parent_link)
1578 *ti_ptr = node_cursor->node_parent;
1579 DrawChooseTree(ti_ptr);
1583 node_cursor->cl_first = ti->cl_first;
1584 node_cursor->cl_cursor = ti->cl_cursor;
1585 *ti_ptr = node_cursor;
1587 if (ti->type == TREE_TYPE_LEVEL_DIR)
1589 LoadLevelSetup_SeriesInfo();
1591 SaveLevelSetup_LastSeries();
1592 SaveLevelSetup_SeriesInfo();
1596 if (game_status == GAME_MODE_SETUP)
1602 game_status = GAME_MODE_MAIN;
1610 if (game_status == GAME_MODE_LEVELS || game_status == GAME_MODE_SETUP)
1617 void DrawChooseLevel()
1619 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1621 DrawChooseTree(&leveldir_current);
1627 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1629 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1635 void DrawHallOfFame(int highlight_position)
1638 FadeSoundsAndMusic();
1639 CloseDoor(DOOR_CLOSE_2);
1641 if (highlight_position < 0)
1642 LoadScore(level_nr);
1647 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1653 static void drawHallOfFameList(int first_entry, int highlight_position)
1657 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1660 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1661 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1663 for(i=0; i<NUM_MENU_ENTRIES_ON_SCREEN; i++)
1665 int entry = first_entry + i;
1666 boolean active = (entry == highlight_position);
1667 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1668 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1669 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1670 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1671 int dx1 = 3 * getFontWidth(font_nr1);
1672 int dx2 = dx1 + getFontWidth(font_nr1);
1673 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1674 int sy = mSY + 64 + i * 32;
1676 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1677 DrawText(mSX + dx1, sy, ".", font_nr1);
1678 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1679 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1680 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1681 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1684 redraw_mask |= REDRAW_FIELD;
1687 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1689 static int first_entry = 0;
1690 static int highlight_position = 0;
1691 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1692 int button_released = !button;
1694 if (button == MB_MENU_INITIALIZE)
1697 highlight_position = mx;
1698 drawHallOfFameList(first_entry, highlight_position);
1703 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1704 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1708 if (first_entry > 0)
1710 first_entry -= step;
1711 if (first_entry < 0)
1714 drawHallOfFameList(first_entry, highlight_position);
1719 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1721 first_entry += step;
1722 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1723 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1725 drawHallOfFameList(first_entry, highlight_position);
1728 else if (button_released)
1730 FadeSound(SND_BACKGROUND_SCORES);
1731 game_status = GAME_MODE_MAIN;
1735 if (game_status == GAME_MODE_SCORES)
1736 PlayMenuSoundIfLoop();
1743 /* ========================================================================= */
1744 /* setup screen functions */
1745 /* ========================================================================= */
1747 static struct TokenInfo *setup_info;
1748 static int num_setup_info;
1750 static char *graphics_set_name;
1751 static char *sounds_set_name;
1752 static char *music_set_name;
1754 static void execSetupMain()
1756 setup_mode = SETUP_MODE_MAIN;
1760 static void execSetupGame()
1762 setup_mode = SETUP_MODE_GAME;
1766 static void execSetupEditor()
1768 setup_mode = SETUP_MODE_EDITOR;
1772 static void execSetupGraphics()
1774 setup_mode = SETUP_MODE_GRAPHICS;
1778 static void execSetupSound()
1780 setup_mode = SETUP_MODE_SOUND;
1784 static void execSetupArtwork()
1786 setup.graphics_set = artwork.gfx_current->identifier;
1787 setup.sounds_set = artwork.snd_current->identifier;
1788 setup.music_set = artwork.mus_current->identifier;
1790 /* needed if last screen (setup choice) changed graphics, sounds or music */
1791 ReloadCustomArtwork();
1793 /* needed for displaying artwork name instead of artwork identifier */
1794 graphics_set_name = artwork.gfx_current->name;
1795 sounds_set_name = artwork.snd_current->name;
1796 music_set_name = artwork.mus_current->name;
1798 setup_mode = SETUP_MODE_ARTWORK;
1802 static void execSetupChooseGraphics()
1804 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1808 static void execSetupChooseSounds()
1810 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1814 static void execSetupChooseMusic()
1816 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1820 static void execSetupInput()
1822 setup_mode = SETUP_MODE_INPUT;
1826 static void execSetupShortcut()
1828 setup_mode = SETUP_MODE_SHORTCUT;
1832 static void execExitSetup()
1834 game_status = GAME_MODE_MAIN;
1838 static void execSaveAndExitSetup()
1844 static struct TokenInfo setup_info_main[] =
1846 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1847 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1848 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1849 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1850 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1851 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1852 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1853 { TYPE_EMPTY, NULL, "" },
1854 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1855 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1859 static struct TokenInfo setup_info_game[] =
1861 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1862 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1863 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1864 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1865 { TYPE_EMPTY, NULL, "" },
1866 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1870 static struct TokenInfo setup_info_editor[] =
1872 { TYPE_STRING, NULL, "Offer Special Elements:"},
1873 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1874 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1875 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1876 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1877 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1878 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1879 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1880 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1881 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1882 { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" },
1883 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
1884 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
1885 { TYPE_EMPTY, NULL, "" },
1886 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1890 static struct TokenInfo setup_info_graphics[] =
1892 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1893 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1894 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1896 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1897 { TYPE_SWITCH, &setup.fading, "Fading:" },
1899 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1900 { TYPE_SWITCH, &setup.toons, "Toons:" },
1901 { TYPE_EMPTY, NULL, "" },
1902 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1906 static struct TokenInfo setup_info_sound[] =
1908 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1909 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1910 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1911 { TYPE_EMPTY, NULL, "" },
1912 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1916 static struct TokenInfo setup_info_artwork[] =
1918 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1919 { TYPE_STRING, &graphics_set_name, "" },
1920 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1921 { TYPE_STRING, &sounds_set_name, "" },
1922 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1923 { TYPE_STRING, &music_set_name, "" },
1924 { TYPE_EMPTY, NULL, "" },
1925 { TYPE_STRING, NULL, "Override Level Artwork:"},
1926 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1927 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1928 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1929 { TYPE_EMPTY, NULL, "" },
1930 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1934 static struct TokenInfo setup_info_shortcut[] =
1936 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1937 { TYPE_KEY, &setup.shortcut.save_game, "" },
1938 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1939 { TYPE_KEY, &setup.shortcut.load_game, "" },
1940 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1941 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1942 { TYPE_EMPTY, NULL, "" },
1943 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1944 { TYPE_EMPTY, NULL, "" },
1945 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1949 static Key getSetupKey()
1951 Key key = KSYM_UNDEFINED;
1952 boolean got_key_event = FALSE;
1954 while (!got_key_event)
1956 if (PendingEvent()) /* got event */
1964 case EVENT_KEYPRESS:
1966 key = GetEventKey((KeyEvent *)&event, TRUE);
1968 /* press 'Escape' or 'Enter' to keep the existing key binding */
1969 if (key == KSYM_Escape || key == KSYM_Return)
1970 key = KSYM_UNDEFINED; /* keep old value */
1972 got_key_event = TRUE;
1976 case EVENT_KEYRELEASE:
1977 key_joystick_mapping = 0;
1981 HandleOtherEvents(&event);
1989 /* don't eat all CPU time */
1996 static void drawSetupValue(int pos)
1998 int xpos = MENU_SCREEN_VALUE_XPOS;
1999 int ypos = MENU_SCREEN_START_YPOS + pos;
2000 int font_nr = FONT_VALUE_1;
2001 int type = setup_info[pos].type;
2002 void *value = setup_info[pos].value;
2003 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
2006 if (value_string == NULL)
2009 if (type & TYPE_KEY)
2013 if (type & TYPE_QUERY)
2015 value_string = "<press key>";
2016 font_nr = FONT_INPUT_1_ACTIVE;
2019 else if (type & TYPE_STRING)
2021 int max_value_len = (SCR_FIELDX - 2) * 2;
2024 font_nr = FONT_VALUE_2;
2026 if (strlen(value_string) > max_value_len)
2027 value_string[max_value_len] = '\0';
2029 else if (type & TYPE_BOOLEAN_STYLE)
2031 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2034 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2035 (xpos == 3 ? " " : " "), font_nr);
2036 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2039 static void changeSetupValue(int pos)
2041 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2043 *(boolean *)setup_info[pos].value ^= TRUE;
2045 else if (setup_info[pos].type & TYPE_KEY)
2049 setup_info[pos].type |= TYPE_QUERY;
2050 drawSetupValue(pos);
2051 setup_info[pos].type &= ~TYPE_QUERY;
2053 key = getSetupKey();
2054 if (key != KSYM_UNDEFINED)
2055 *(Key *)setup_info[pos].value = key;
2058 drawSetupValue(pos);
2061 static void DrawSetupScreen_Generic()
2063 char *title_string = NULL;
2067 CloseDoor(DOOR_CLOSE_2);
2071 if (setup_mode == SETUP_MODE_MAIN)
2073 setup_info = setup_info_main;
2074 title_string = "Setup";
2076 else if (setup_mode == SETUP_MODE_GAME)
2078 setup_info = setup_info_game;
2079 title_string = "Setup Game";
2081 else if (setup_mode == SETUP_MODE_EDITOR)
2083 setup_info = setup_info_editor;
2084 title_string = "Setup Editor";
2086 else if (setup_mode == SETUP_MODE_GRAPHICS)
2088 setup_info = setup_info_graphics;
2089 title_string = "Setup Graphics";
2091 else if (setup_mode == SETUP_MODE_SOUND)
2093 setup_info = setup_info_sound;
2094 title_string = "Setup Sound";
2096 else if (setup_mode == SETUP_MODE_ARTWORK)
2098 setup_info = setup_info_artwork;
2099 title_string = "Custom Artwork";
2101 else if (setup_mode == SETUP_MODE_SHORTCUT)
2103 setup_info = setup_info_shortcut;
2104 title_string = "Setup Shortcuts";
2107 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2110 for(i=0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2112 void *value_ptr = setup_info[i].value;
2113 int ypos = MENU_SCREEN_START_YPOS + i;
2114 int font_nr = FONT_MENU_1;
2116 /* set some entries to "unchangeable" according to other variables */
2117 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2118 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2119 (value_ptr == &setup.sound_music && !audio.music_available) ||
2120 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2121 setup_info[i].type |= TYPE_GHOSTED;
2123 if (setup_info[i].type & TYPE_STRING)
2124 font_nr = FONT_MENU_2;
2126 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2128 if (setup_info[i].type & TYPE_ENTER_MENU)
2129 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2130 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2131 initCursor(i, IMG_MENU_BUTTON_LEFT);
2132 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2133 initCursor(i, IMG_MENU_BUTTON);
2135 if (setup_info[i].type & TYPE_VALUE)
2143 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
2146 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2148 static int choice_store[MAX_SETUP_MODES];
2149 int choice = choice_store[setup_mode]; /* always starts with 0 */
2153 if (button == MB_MENU_INITIALIZE)
2155 /* advance to first valid menu entry */
2156 while (choice < num_setup_info &&
2157 (setup_info[choice].type & TYPE_SKIP_ENTRY))
2159 choice_store[setup_mode] = choice;
2161 drawCursor(choice, FC_RED);
2164 else if (button == MB_MENU_LEAVE)
2166 for (y=0; y<num_setup_info; y++)
2168 if (setup_info[y].type & TYPE_LEAVE_MENU)
2170 void (*menu_callback_function)(void) = setup_info[y].value;
2172 menu_callback_function();
2173 break; /* absolutely needed because function changes 'setup_info'! */
2180 if (mx || my) /* mouse input */
2182 x = (mx - mSX) / 32;
2183 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2185 else if (dx || dy) /* keyboard input */
2189 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2191 if ((setup_info[choice].type & menu_navigation_type) ||
2192 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
2193 button = MB_MENU_CHOICE;
2198 /* jump to next non-empty menu entry (up or down) */
2199 while (y > 0 && y < num_setup_info - 1 &&
2200 (setup_info[y].type & TYPE_SKIP_ENTRY))
2204 if (x == 0 && y >= 0 && y < num_setup_info &&
2205 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
2211 drawCursor(y, FC_RED);
2212 drawCursor(choice, FC_BLUE);
2213 choice = choice_store[setup_mode] = y;
2216 else if (!(setup_info[y].type & TYPE_GHOSTED))
2218 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2220 void (*menu_callback_function)(void) = setup_info[choice].value;
2222 menu_callback_function();
2226 if ((setup_info[y].type & TYPE_KEYTEXT) &&
2227 (setup_info[y + 1].type & TYPE_KEY))
2230 if (setup_info[y].type & TYPE_VALUE)
2231 changeSetupValue(y);
2239 if (game_status == GAME_MODE_SETUP)
2244 void DrawSetupScreen_Input()
2248 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2250 initCursor(0, IMG_MENU_BUTTON);
2251 initCursor(1, IMG_MENU_BUTTON);
2252 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2253 initCursor(13, IMG_MENU_BUTTON_LEFT);
2255 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2256 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2258 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2259 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2260 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2263 DeactivateJoystickForCalibration();
2264 DrawTextFCentered(SYSIZE - 20, FONT_TEXT_4,
2265 "Joysticks deactivated on this screen");
2268 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
2273 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2275 if (device_name == NULL)
2278 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2281 if (strlen(device_name) > 1)
2283 char c1 = device_name[strlen(device_name) - 1];
2284 char c2 = device_name[strlen(device_name) - 2];
2286 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2287 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2290 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2291 strlen(device_name));
2294 static void drawPlayerSetupInputInfo(int player_nr)
2297 static struct SetupKeyboardInfo custom_key;
2304 { &custom_key.left, "Joystick Left" },
2305 { &custom_key.right, "Joystick Right" },
2306 { &custom_key.up, "Joystick Up" },
2307 { &custom_key.down, "Joystick Down" },
2308 { &custom_key.snap, "Button 1" },
2309 { &custom_key.bomb, "Button 2" }
2311 static char *joystick_name[MAX_PLAYERS] =
2319 custom_key = setup.input[player_nr].key;
2321 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2323 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2324 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2326 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2329 if (setup.input[player_nr].use_joystick)
2331 char *device_name = setup.input[player_nr].joy.device_name;
2333 DrawText(mSX+8*32, mSY+3*32,
2334 joystick_name[getJoystickNrFromDeviceName(device_name)],
2336 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2340 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2341 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2344 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2345 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2346 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2347 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2348 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2349 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2350 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2351 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2352 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2353 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2354 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2358 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2360 DrawText(mSX + 3*32, mSY + ypos*32,
2362 DrawText(mSX + 3*32, mSY + ypos*32,
2363 (setup.input[player_nr].use_joystick ?
2365 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2369 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2371 static int choice = 0;
2372 static int player_nr = 0;
2375 int pos_start = SETUPINPUT_SCREEN_POS_START;
2376 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2377 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2378 int pos_end = SETUPINPUT_SCREEN_POS_END;
2380 if (button == MB_MENU_INITIALIZE)
2382 drawPlayerSetupInputInfo(player_nr);
2383 drawCursor(choice, FC_RED);
2386 else if (button == MB_MENU_LEAVE)
2388 setup_mode = SETUP_MODE_MAIN;
2393 if (mx || my) /* mouse input */
2395 x = (mx - mSX) / 32;
2396 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2398 else if (dx || dy) /* keyboard input */
2400 if (dx && choice == 0)
2401 x = (dx < 0 ? 10 : 12);
2402 else if ((dx && choice == 1) ||
2403 (dx == +1 && choice == 2) ||
2404 (dx == -1 && choice == pos_end))
2405 button = MB_MENU_CHOICE;
2409 if (y >= pos_empty1 && y <= pos_empty2)
2410 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2413 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
2415 static unsigned long delay = 0;
2417 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2424 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2426 drawPlayerSetupInputInfo(player_nr);
2428 else if (x == 0 && y >= pos_start && y <= pos_end &&
2429 !(y >= pos_empty1 && y <= pos_empty2))
2435 drawCursor(y, FC_RED);
2436 drawCursor(choice, FC_BLUE);
2444 char *device_name = setup.input[player_nr].joy.device_name;
2446 if (!setup.input[player_nr].use_joystick)
2448 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2450 setJoystickDeviceToNr(device_name, new_device_nr);
2451 setup.input[player_nr].use_joystick = TRUE;
2455 int device_nr = getJoystickNrFromDeviceName(device_name);
2456 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2458 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2459 setup.input[player_nr].use_joystick = FALSE;
2461 setJoystickDeviceToNr(device_name, new_device_nr);
2464 drawPlayerSetupInputInfo(player_nr);
2468 if (setup.input[player_nr].use_joystick)
2471 CalibrateJoystick(player_nr);
2474 CustomizeKeyboard(player_nr);
2476 else if (y == pos_end)
2480 setup_mode = SETUP_MODE_MAIN;
2491 if (game_status == GAME_MODE_SETUP)
2496 void CustomizeKeyboard(int player_nr)
2500 boolean finished = FALSE;
2501 static struct SetupKeyboardInfo custom_key;
2506 } customize_step[] =
2508 { &custom_key.left, "Move Left" },
2509 { &custom_key.right, "Move Right" },
2510 { &custom_key.up, "Move Up" },
2511 { &custom_key.down, "Move Down" },
2512 { &custom_key.snap, "Snap Field" },
2513 { &custom_key.bomb, "Place Bomb" }
2516 /* read existing key bindings from player setup */
2517 custom_key = setup.input[player_nr].key;
2520 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2526 DrawText(mSX, mSY + (2+2*step_nr)*32,
2527 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2528 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2529 "Key:", FONT_INPUT_1_ACTIVE);
2530 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2531 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2535 if (PendingEvent()) /* got event */
2543 case EVENT_KEYPRESS:
2545 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2547 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2553 /* all keys configured -- wait for "Escape" or "Return" key */
2557 /* press 'Enter' to keep the existing key binding */
2558 if (key == KSYM_Return)
2559 key = *customize_step[step_nr].key;
2561 /* check if key already used */
2562 for (i=0; i<step_nr; i++)
2563 if (*customize_step[i].key == key)
2568 /* got new key binding */
2569 *customize_step[step_nr].key = key;
2570 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2572 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2573 getKeyNameFromKey(key), FONT_VALUE_1);
2576 /* un-highlight last query */
2577 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2578 customize_step[step_nr-1].text, FONT_MENU_1);
2579 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2580 "Key:", FONT_MENU_1);
2582 /* press 'Enter' to leave */
2585 DrawText(mSX + 16, mSY + 15*32+16,
2586 "Press Enter", FONT_TITLE_1);
2590 /* query next key binding */
2591 DrawText(mSX, mSY+(2+2*step_nr)*32,
2592 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2593 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2594 "Key:", FONT_INPUT_1_ACTIVE);
2595 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2596 getKeyNameFromKey(*customize_step[step_nr].key),
2601 case EVENT_KEYRELEASE:
2602 key_joystick_mapping = 0;
2606 HandleOtherEvents(&event);
2614 /* don't eat all CPU time */
2618 /* write new key bindings back to player setup */
2619 setup.input[player_nr].key = custom_key;
2622 DrawSetupScreen_Input();
2625 static boolean CalibrateJoystickMain(int player_nr)
2627 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2628 int new_joystick_xright = JOYSTICK_XMIDDLE;
2629 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2630 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2631 int new_joystick_xmiddle, new_joystick_ymiddle;
2633 int joystick_fd = joystick.fd[player_nr];
2634 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2635 boolean check[3][3];
2636 int check_remaining = 3 * 3;
2641 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2644 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2649 for(y=0; y < 3; y++)
2651 for(x=0; x < 3; x++)
2653 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2654 check[x][y] = FALSE;
2658 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2659 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2660 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2661 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2662 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2663 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2664 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2666 joy_value = Joystick(player_nr);
2667 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2668 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2670 /* eventually uncalibrated center position (joystick could be uncentered) */
2671 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2674 new_joystick_xmiddle = joy_x;
2675 new_joystick_ymiddle = joy_y;
2677 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2680 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2685 if (PendingEvent()) /* got event */
2693 case EVENT_KEYPRESS:
2694 switch(GetEventKey((KeyEvent *)&event, TRUE))
2697 if (check_remaining == 0)
2710 case EVENT_KEYRELEASE:
2711 key_joystick_mapping = 0;
2715 HandleOtherEvents(&event);
2720 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2723 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2724 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2725 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2726 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2728 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2729 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2730 setup.input[player_nr].joy.xright = new_joystick_xright;
2731 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2732 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2733 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2735 CheckJoystickData();
2737 joy_value = Joystick(player_nr);
2739 if (joy_value & JOY_BUTTON && check_remaining == 0)
2742 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2743 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2745 if (x != last_x || y != last_y)
2747 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2748 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2753 if (check_remaining > 0 && !check[x+1][y+1])
2755 check[x+1][y+1] = TRUE;
2761 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2762 setup.input[player_nr].joy.xleft,
2763 setup.input[player_nr].joy.xmiddle,
2764 setup.input[player_nr].joy.xright);
2765 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2766 setup.input[player_nr].joy.yupper,
2767 setup.input[player_nr].joy.ymiddle,
2768 setup.input[player_nr].joy.ylower);
2777 /* don't eat all CPU time */
2781 /* calibrated center position (joystick should now be centered) */
2782 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2785 new_joystick_xmiddle = joy_x;
2786 new_joystick_ymiddle = joy_y;
2790 DrawSetupScreen_Input();
2792 /* wait until the last pressed button was released */
2793 while (Joystick(player_nr) & JOY_BUTTON)
2795 if (PendingEvent()) /* got event */
2800 HandleOtherEvents(&event);
2809 void CalibrateJoystick(int player_nr)
2811 if (!CalibrateJoystickMain(player_nr))
2815 DrawText(mSX + 16, mSY + 6*32, " JOYSTICK NOT ", FONT_TITLE_1);
2816 DrawText(mSX, mSY + 7*32, " AVAILABLE ", FONT_TITLE_1);
2818 Delay(2000); /* show error message for two seconds */
2822 void DrawSetupScreen()
2824 DeactivateJoystick();
2826 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2828 if (setup_mode == SETUP_MODE_INPUT)
2829 DrawSetupScreen_Input();
2830 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2831 DrawChooseTree(&artwork.gfx_current);
2832 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2833 DrawChooseTree(&artwork.snd_current);
2834 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2835 DrawChooseTree(&artwork.mus_current);
2837 DrawSetupScreen_Generic();
2843 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2845 if (setup_mode == SETUP_MODE_INPUT)
2846 HandleSetupScreen_Input(mx, my, dx, dy, button);
2847 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2848 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2849 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2850 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2851 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2852 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2854 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2860 void HandleGameActions()
2862 if (game_status != GAME_MODE_PLAYING)
2865 if (local_player->LevelSolved)
2868 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2876 if (tape.auto_play && !tape.playing)
2877 AutoPlayTape(); /* continue automatically playing next tape */
2881 /* ---------- new screen button stuff -------------------------------------- */
2883 /* graphic position and size values for buttons and scrollbars */
2884 #define SC_SCROLLBUTTON_XSIZE TILEX
2885 #define SC_SCROLLBUTTON_YSIZE TILEY
2887 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2888 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
2889 SC_SCROLLBUTTON_YSIZE)
2890 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2891 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
2892 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2893 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
2894 SC_SCROLLBUTTON_YSIZE)
2895 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2896 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
2897 SC_SCROLL_VERTICAL_YSIZE)
2899 #define SC_BORDER_SIZE 14
2903 int gfx_unpressed, gfx_pressed;
2907 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2910 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2911 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2912 SCREEN_CTRL_ID_SCROLL_UP,
2916 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2917 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2918 SCREEN_CTRL_ID_SCROLL_DOWN,
2925 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2926 Bitmap **gfx_unpressed, **gfx_pressed;
2928 int gfx_unpressed, gfx_pressed;
2935 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2938 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2939 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2941 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2943 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
2944 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2945 GD_TYPE_SCROLLBAR_VERTICAL,
2946 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2947 "scroll level series vertically"
2951 static void CreateScreenScrollbuttons()
2953 struct GadgetInfo *gi;
2954 unsigned long event_mask;
2957 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2959 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2960 int gfx_unpressed, gfx_pressed;
2961 int x, y, width, height;
2962 int gd_x1, gd_x2, gd_y1, gd_y2;
2963 int id = scrollbutton_info[i].gadget_id;
2965 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2967 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
2968 y = mSY + scrollbutton_info[i].y;
2969 width = SC_SCROLLBUTTON_XSIZE;
2970 height = SC_SCROLLBUTTON_YSIZE;
2972 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
2973 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
2974 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
2976 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2977 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2978 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2979 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2980 gd_x1 = graphic_info[gfx_unpressed].src_x;
2981 gd_y1 = graphic_info[gfx_unpressed].src_y;
2982 gd_x2 = graphic_info[gfx_pressed].src_x;
2983 gd_y2 = graphic_info[gfx_pressed].src_y;
2985 gi = CreateGadget(GDI_CUSTOM_ID, id,
2986 GDI_CUSTOM_TYPE_ID, i,
2987 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2992 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2993 GDI_STATE, GD_BUTTON_UNPRESSED,
2994 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2995 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2996 GDI_DIRECT_DRAW, FALSE,
2997 GDI_EVENT_MASK, event_mask,
2998 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3002 Error(ERR_EXIT, "cannot create gadget");
3004 screen_gadget[id] = gi;
3008 static void CreateScreenScrollbars()
3012 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
3014 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3015 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3016 int gfx_unpressed, gfx_pressed;
3018 int x, y, width, height;
3019 int gd_x1, gd_x2, gd_y1, gd_y2;
3020 struct GadgetInfo *gi;
3021 int items_max, items_visible, item_position;
3022 unsigned long event_mask;
3023 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3024 int id = scrollbar_info[i].gadget_id;
3026 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3028 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3029 y = mSY + scrollbar_info[i].y;
3030 width = scrollbar_info[i].width;
3031 height = scrollbar_info[i].height;
3033 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3034 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3036 items_max = num_page_entries;
3037 items_visible = num_page_entries;
3040 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3041 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3042 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3048 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3049 gfx_pressed = scrollbar_info[i].gfx_pressed;
3050 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3051 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3052 gd_x1 = graphic_info[gfx_unpressed].src_x;
3053 gd_y1 = graphic_info[gfx_unpressed].src_y;
3054 gd_x2 = graphic_info[gfx_pressed].src_x;
3055 gd_y2 = graphic_info[gfx_pressed].src_y;
3058 gi = CreateGadget(GDI_CUSTOM_ID, id,
3059 GDI_CUSTOM_TYPE_ID, i,
3060 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3065 GDI_TYPE, scrollbar_info[i].type,
3066 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3067 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3068 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3069 GDI_STATE, GD_BUTTON_UNPRESSED,
3070 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3071 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3072 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3073 GDI_DIRECT_DRAW, FALSE,
3074 GDI_EVENT_MASK, event_mask,
3075 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3079 Error(ERR_EXIT, "cannot create gadget");
3081 screen_gadget[id] = gi;
3085 void CreateScreenGadgets()
3087 int last_game_status = game_status; /* save current game status */
3089 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3092 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3094 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3096 /* copy pointers to clip mask and GC */
3097 scrollbar_bitmap[i]->clip_mask =
3098 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3099 scrollbar_bitmap[i]->stored_clip_gc =
3100 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3102 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3103 scrollbar_bitmap[i],
3104 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3105 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3106 TILEX, TILEY, 0, 0);
3110 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3111 game_status = GAME_MODE_LEVELS;
3113 CreateScreenScrollbuttons();
3114 CreateScreenScrollbars();
3116 game_status = last_game_status; /* restore current game status */
3119 void FreeScreenGadgets()
3123 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3124 for (i=0; i < NUM_SCROLLBAR_BITMAPS; i++)
3126 /* prevent freeing clip mask and GC twice */
3127 scrollbar_bitmap[i]->clip_mask = None;
3128 scrollbar_bitmap[i]->stored_clip_gc = None;
3130 FreeBitmap(scrollbar_bitmap[i]);
3134 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3135 FreeGadget(screen_gadget[i]);
3138 void MapChooseTreeGadgets(TreeInfo *ti)
3140 int num_entries = numTreeInfoInGroup(ti);
3143 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3146 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3147 MapGadget(screen_gadget[i]);
3150 void UnmapChooseTreeGadgets()
3154 for (i=0; i<NUM_SCREEN_GADGETS; i++)
3155 UnmapGadget(screen_gadget[i]);
3158 static void HandleScreenGadgets(struct GadgetInfo *gi)
3160 int id = gi->custom_id;
3162 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3167 case SCREEN_CTRL_ID_SCROLL_UP:
3168 if (game_status == GAME_MODE_LEVELS)
3169 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3170 else if (game_status == GAME_MODE_SETUP)
3171 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3174 case SCREEN_CTRL_ID_SCROLL_DOWN:
3175 if (game_status == GAME_MODE_LEVELS)
3176 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3177 else if (game_status == GAME_MODE_SETUP)
3178 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3181 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3182 if (game_status == GAME_MODE_LEVELS)
3183 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3184 else if (game_status == GAME_MODE_SETUP)
3185 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);