1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2001 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_INPUT 1
30 #define SETUP_MODE_GRAPHICS 2
31 #define SETUP_MODE_SOUND 3
33 #define MAX_SETUP_MODES 4
35 /* for HandleSetupInputScreen() */
36 #define SETUPINPUT_SCREEN_POS_START 0
37 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
38 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
39 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
41 /* for HandleChooseLevel() */
42 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
43 #define MENU_SCREEN_START_YPOS 2
44 #define MENU_SCREEN_VALUE_XPOS 14
46 /* buttons and scrollbars identifiers */
47 #define SCREEN_CTRL_ID_SCROLL_UP 0
48 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
49 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
51 #define NUM_SCREEN_SCROLLBUTTONS 2
52 #define NUM_SCREEN_SCROLLBARS 1
53 #define NUM_SCREEN_GADGETS 3
55 /* forward declaration for internal use */
56 static void HandleScreenGadgets(struct GadgetInfo *);
58 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
60 static void drawCursorExt(int pos, int color, int graphic)
62 static int cursor_array[SCR_FIELDY];
65 cursor_array[pos] = graphic;
67 graphic = cursor_array[pos];
70 graphic = (graphic == GFX_ARROW_BLUE_LEFT ? GFX_ARROW_RED_LEFT :
71 graphic == GFX_ARROW_BLUE_RIGHT ? GFX_ARROW_RED_RIGHT :
74 DrawGraphic(0, MENU_SCREEN_START_YPOS + pos, graphic);
77 static void initCursor(int pos, int graphic)
79 drawCursorExt(pos, FC_BLUE, graphic);
82 static void drawCursor(int pos, int color)
84 drawCursorExt(pos, color, 0);
89 int x = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * FONT1_XSIZE) / 2;
91 DrawText(x, SY + 8, PROGRAM_TITLE_STRING, FS_BIG, FC_YELLOW);
92 DrawTextFCentered(46, FC_RED, WINDOW_SUBTITLE_STRING);
95 static void ToggleFullscreenIfNeeded()
97 if (setup.fullscreen != video.fullscreen_enabled)
99 /* save old door content */
100 BlitBitmap(backbuffer, pix[PIX_DB_DOOR],
101 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
103 /* toggle fullscreen */
104 ChangeVideoModeIfNeeded(setup.fullscreen);
105 setup.fullscreen = video.fullscreen_enabled;
107 /* redraw background to newly created backbuffer */
108 BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
110 /* restore old door content */
111 BlitBitmap(pix[PIX_DB_DOOR], backbuffer,
112 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
114 redraw_mask = REDRAW_ALL;
120 static struct LevelDirInfo *leveldir_last_valid = NULL;
122 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
126 KeyboardAutoRepeatOn();
127 ActivateJoystickIfAvailable();
128 SetDrawDeactivationMask(REDRAW_NONE);
130 /* needed if last screen was the playing screen, invoked from level editor */
131 if (level_editor_test_game)
133 game_status = LEVELED;
138 /* needed if last screen was the editor screen */
139 UndrawSpecialEditorDoor();
141 /* needed if last screen was the setup screen and fullscreen state changed */
142 ToggleFullscreenIfNeeded();
145 SetDrawtoField(DRAW_BACKBUFFER);
148 /* map gadgets for main menu screen */
151 /* leveldir_current may be invalid (level group, parent link) */
152 if (!validLevelSeries(leveldir_current))
153 leveldir_current = getFirstValidLevelSeries(leveldir_last_valid);
155 /* store valid level series information */
156 leveldir_last_valid = leveldir_current;
158 /* level_nr may have been set to value over handicap with level editor */
159 if (setup.handicap && level_nr > leveldir_current->handicap_level)
160 level_nr = leveldir_current->handicap_level;
167 DrawText(SX + 32, SY + 2*32, name_text, FS_BIG, FC_GREEN);
168 DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
169 DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
170 DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
171 (leveldir_current->readonly ? FC_RED : FC_YELLOW));
172 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
173 DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
174 DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
175 DrawText(SX + 32, SY + 7*32, "Start Game", FS_BIG, FC_GREEN);
176 DrawText(SX + 32, SY + 8*32, "Setup", FS_BIG, FC_GREEN);
177 DrawText(SX + 32, SY + 9*32, "Quit", FS_BIG, FC_GREEN);
179 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
181 DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
182 leveldir_current->first_level,
183 leveldir_current->last_level);
185 if (leveldir_current->readonly)
187 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
188 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
192 initCursor(i, (i == 1 || i == 6 ? GFX_ARROW_BLUE_RIGHT : GFX_KUGEL_BLAU));
194 DrawGraphic(10, 3, GFX_ARROW_BLUE_LEFT);
195 DrawGraphic(14, 3, GFX_ARROW_BLUE_RIGHT);
197 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
200 if (leveldir_current->name)
202 int len = strlen(leveldir_current->name);
203 int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
204 int lypos = SY + 352;
206 DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
211 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
214 if (TAPE_IS_EMPTY(tape))
216 DrawCompleteVideoDisplay();
218 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
226 static void gotoTopLevelDir()
228 /* move upwards to top level directory */
229 while (leveldir_current->node_parent)
231 /* write a "path" into level tree for easy navigation to last level */
232 if (leveldir_current->node_parent->node_group->cl_first == -1)
234 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
235 int leveldir_pos = posLevelDirInfo(leveldir_current);
236 int num_page_entries;
237 int cl_first, cl_cursor;
239 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
240 num_page_entries = num_leveldirs;
242 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
244 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
245 cl_cursor = leveldir_pos - cl_first;
247 leveldir_current->node_parent->node_group->cl_first = cl_first;
248 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
251 leveldir_current = leveldir_current->node_parent;
255 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
257 static int choice = 0;
261 if (button == MB_MENU_INITIALIZE)
263 drawCursor(choice, FC_RED);
267 if (mx || my) /* mouse input */
270 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
272 else if (dx || dy) /* keyboard input */
274 if (dx && choice == 1)
275 x = (dx < 0 ? 10 : 14);
280 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
281 (x == 14 && level_nr < leveldir_current->last_level)) &&
284 static unsigned long level_delay = 0;
285 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
286 int new_level_nr, old_level_nr = level_nr;
287 int font_color = (leveldir_current->readonly ? FC_RED : FC_YELLOW);
289 new_level_nr = level_nr + (x == 10 ? -step : +step);
290 if (new_level_nr < leveldir_current->first_level)
291 new_level_nr = leveldir_current->first_level;
292 if (new_level_nr > leveldir_current->last_level)
293 new_level_nr = leveldir_current->last_level;
295 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
296 new_level_nr = leveldir_current->handicap_level;
298 if (old_level_nr == new_level_nr ||
299 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
302 level_nr = new_level_nr;
304 DrawTextExt(drawto, SX + 11 * 32, SY + 3 * 32,
305 int2str(level_nr, 3), FS_BIG, font_color);
306 DrawTextExt(window, SX + 11 * 32, SY + 3 * 32,
307 int2str(level_nr, 3), FS_BIG, font_color);
310 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
314 DrawCompleteVideoDisplay();
316 /* needed because DrawMicroLevel() takes some time */
319 DelayReached(&level_delay, 0); /* reset delay counter */
321 else if (x == 0 && y >= 0 && y <= 7)
327 drawCursor(y, FC_RED);
328 drawCursor(choice, FC_BLUE);
336 game_status = TYPENAME;
337 HandleTypeName(strlen(setup.player_name), 0);
343 game_status = CHOOSELEVEL;
344 SaveLevelSetup_LastSeries();
345 SaveLevelSetup_SeriesInfo();
354 game_status = HALLOFFAME;
359 if (leveldir_current->readonly &&
360 strcmp(setup.player_name, "Artsoft") != 0)
361 Request("This level is read only !", REQ_CONFIRM);
362 game_status = LEVELED;
367 game_status = HELPSCREEN;
372 if (setup.autorecord)
373 TapeStartRecording();
375 #if defined(PLATFORM_UNIX)
377 SendToServer_StartPlaying();
381 game_status = PLAYING;
393 SaveLevelSetup_LastSeries();
394 SaveLevelSetup_SeriesInfo();
395 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
396 game_status = EXITGAME;
405 if (game_status == MAINMENU)
407 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
413 #define MAX_HELPSCREEN_ELS 10
417 static long helpscreen_state;
418 static int helpscreen_step[MAX_HELPSCREEN_ELS];
419 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
420 static int helpscreen_delay[MAX_HELPSCREEN_ELS];
421 static int helpscreen_action[] =
423 GFX_SPIELER1_DOWN,4,2,
425 GFX_SPIELER1_LEFT,4,2,
426 GFX_SPIELER1_RIGHT,4,2,
427 GFX_SPIELER1_PUSH_LEFT,4,2,
428 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
429 GFX_ERDREICH,1,100, HA_NEXT,
430 GFX_LEERRAUM,1,100, HA_NEXT,
431 GFX_MORAST_LEER,1,100, HA_NEXT,
432 GFX_BETON,1,100, HA_NEXT,
433 GFX_MAUERWERK,1,100, HA_NEXT,
434 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
435 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
436 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
437 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
438 GFX_UNSICHTBAR,1,100, HA_NEXT,
439 GFX_FELSBODEN,1,100, HA_NEXT,
440 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
441 GFX_EDELSTEIN,2,5, HA_NEXT,
442 GFX_DIAMANT,2,5, HA_NEXT,
443 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
444 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
445 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
446 GFX_FELSBROCKEN,4,5, HA_NEXT,
447 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
448 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
449 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
450 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
451 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
452 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
453 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
454 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
455 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
456 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
457 GFX_GEBLUBBER,4,4, HA_NEXT,
458 GFX_SCHLUESSEL1,4,25, HA_NEXT,
459 GFX_PFORTE1,4,25, HA_NEXT,
460 GFX_PFORTE1X,4,25, HA_NEXT,
461 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
462 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
463 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
464 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
465 GFX_LEERRAUM,1,10, HA_NEXT,
466 GFX_DYNABOMB_NR,1,100, HA_NEXT,
467 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
468 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
469 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
470 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
471 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
472 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
473 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
474 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
475 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
476 GFX_BUTTERFLY,2,2, HA_NEXT,
477 GFX_FIREFLY,2,2, HA_NEXT,
478 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
479 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
480 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
481 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
482 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
483 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
484 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
485 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
486 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
487 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
491 GFX_MOLE_RIGHT,4,2, HA_NEXT,
492 GFX_PINGUIN_DOWN,4,2,
494 GFX_PINGUIN_LEFT,4,2,
495 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
496 GFX_SCHWEIN_DOWN,4,2,
498 GFX_SCHWEIN_LEFT,4,2,
499 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
503 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
504 GFX_SONDE_START,8,1, HA_NEXT,
505 GFX_ABLENK,4,1, HA_NEXT,
506 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
507 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
508 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
509 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
510 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
511 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
512 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
513 GFX_DIAMANT,1,10, HA_NEXT,
514 GFX_LIFE,1,100, HA_NEXT,
515 GFX_LIFE_ASYNC,1,100, HA_NEXT,
516 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
517 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
518 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
519 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
520 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
521 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
522 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
523 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
524 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
525 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
526 GFX_SPEED_PILL,1,100, HA_NEXT,
529 static char *helpscreen_eltext[][2] =
531 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
532 {"Normal sand:", "You can dig through it"},
533 {"Empty field:", "You can walk through it"},
534 {"Quicksand: You cannot pass it,", "but rocks can fall though it"},
535 {"Massive Wall:", "Nothing can go through it"},
536 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
537 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
538 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
539 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
540 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
541 {"Emerald: You must collect enough of","them to finish a level"},
542 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
543 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
544 {"Colorful Gems:", "Seem to behave like Emeralds"},
545 {"Rock: Smashes several things;", "Can be moved by the player"},
546 {"Bomb: You can move it, but be", "careful when dropping it"},
547 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
548 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
549 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
550 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
551 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
552 {"Acid: Things that fall in are gone", "forever (including our hero)"},
553 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
554 {"Door: Can be opened by the key", "with the same color"},
555 {"Door: You have to find out the", "right color of the key for it"},
556 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
557 {"Dynamite: This one explodes after", "a few seconds"},
558 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
559 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
560 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
561 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
562 {"Bug: Moves at the right side", "of walls; don't touch it!"},
563 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
564 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
565 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
566 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
567 {"Cruncher (BD style):", "Eats almost everything"},
568 {"Robot: Tries to kill the player", ""},
569 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
570 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
571 {"The Pig: Harmless, but eats all", "gems it can get"},
572 {"The Dragon: Breathes fire,", "especially to some monsters"},
573 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
574 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
575 {"Light Bulb: All of them must be", "switched on to finish a level"},
576 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
577 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
578 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
579 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
580 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
581 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
582 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
583 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
584 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
585 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
586 {"Exit door: Opens if you have enough","emeralds to finish the level"},
587 {"Open exit door: Enter here to leave","the level and exit the actual game"},
588 {"Sokoban element: Object which must", "be pushed to an empty field"},
589 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
590 {"Sokoban element: Field with object", "which can be pushed away"},
591 {"Speed pill: Lets the player run", "twice as fast as normally"},
593 static int num_helpscreen_els = sizeof(helpscreen_eltext)/(2*sizeof(char *));
595 static char *helpscreen_music[][3] =
597 { "Alchemy", "Ian Boddy", "Drive" },
598 { "The Chase", "Propaganda", "A Secret Wish" },
599 { "Network 23", "Tangerine Dream", "Exit" },
600 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
601 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
602 { "Voyager", "The Alan Parsons Project","Pyramid" },
603 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
605 static int num_helpscreen_music = 7;
606 static int helpscreen_musicpos;
608 void DrawHelpScreenElAction(int start)
612 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
614 while(helpscreen_action[j] != HA_END)
616 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
618 else if (i<start || helpscreen_delay[i-start])
620 if (i>=start && helpscreen_delay[i-start])
621 helpscreen_delay[i-start]--;
623 while(helpscreen_action[j] != HA_NEXT)
630 j += 3*helpscreen_step[i-start];
631 graphic = helpscreen_action[j++];
633 if (helpscreen_frame[i-start])
635 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
636 helpscreen_frame[i-start]--;
641 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
644 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
646 if (helpscreen_action[j] == HA_NEXT)
648 if (!helpscreen_frame[i-start])
649 helpscreen_step[i-start] = 0;
653 if (!helpscreen_frame[i-start])
654 helpscreen_step[i-start]++;
655 while(helpscreen_action[j] != HA_NEXT)
660 DrawGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
671 void DrawHelpScreenElText(int start)
674 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
675 int ybottom = SYSIZE - 20;
680 DrawTextFCentered(100, FC_GREEN, "The game elements:");
682 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
685 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
686 helpscreen_eltext[i][0], FS_SMALL, FC_YELLOW);
687 DrawText(xstart, ystart + (i - start) * ystep + 16,
688 helpscreen_eltext[i][1], FS_SMALL, FC_YELLOW);
691 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
694 void DrawHelpScreenMusicText(int num)
696 int ystart = 150, ystep = 30;
697 int ybottom = SYSIZE - 20;
703 DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
705 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
707 DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
708 helpscreen_music[num][0]);
709 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
711 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
712 "%s", helpscreen_music[num][1]);
713 DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
715 DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
716 helpscreen_music[num][2]);
718 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
721 PlaySoundLoop(background_loop[num]);
725 void DrawHelpScreenCreditsText()
727 int ystart = 150, ystep = 30;
728 int ybottom = SYSIZE - 20;
734 DrawTextFCentered(100, FC_GREEN,
736 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
737 "DOS port of the game:");
738 DrawTextFCentered(ystart + 1 * ystep, FC_RED,
740 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
741 "Additional toons:");
742 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
744 DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
745 "...and many thanks to all contributors");
746 DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
749 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
752 void DrawHelpScreenContactText()
754 int ystart = 150, ystep = 30;
755 int ybottom = SYSIZE - 20;
760 DrawTextFCentered(100, FC_GREEN, "Program information:");
762 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
763 "This game is Freeware!");
764 DrawTextFCentered(ystart + 1 * ystep, FC_YELLOW,
765 "If you like it, send e-mail to:");
766 DrawTextFCentered(ystart + 2 * ystep, FC_RED,
768 DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
770 DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
772 DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
773 "Detmolder Strasse 189");
774 DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
776 DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
779 DrawTextFCentered(ystart + 7 * ystep, FC_YELLOW,
780 "If you have created new levels,");
781 DrawTextFCentered(ystart + 8 * ystep, FC_YELLOW,
782 "send them to me to include them!");
783 DrawTextFCentered(ystart + 9 * ystep, FC_YELLOW,
786 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
789 void DrawHelpScreen()
794 CloseDoor(DOOR_CLOSE_2);
796 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
797 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
798 helpscreen_musicpos = 0;
799 helpscreen_state = 0;
800 DrawHelpScreenElText(0);
801 DrawHelpScreenElAction(0);
805 PlaySoundLoop(SND_RHYTHMLOOP);
808 void HandleHelpScreen(int button)
810 static unsigned long hs_delay = 0;
811 int num_helpscreen_els_pages =
812 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
813 int button_released = !button;
818 if (helpscreen_state < num_helpscreen_els_pages - 1)
820 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
821 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
823 DrawHelpScreenElText(helpscreen_state*MAX_HELPSCREEN_ELS);
824 DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
826 else if (helpscreen_state <
827 num_helpscreen_els_pages + num_helpscreen_music - 1)
830 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
832 else if (helpscreen_state ==
833 num_helpscreen_els_pages + num_helpscreen_music - 1)
836 DrawHelpScreenCreditsText();
838 else if (helpscreen_state ==
839 num_helpscreen_els_pages + num_helpscreen_music)
842 DrawHelpScreenContactText();
848 game_status = MAINMENU;
853 if (DelayReached(&hs_delay,GAME_FRAME_DELAY * 2))
855 if (helpscreen_state<num_helpscreen_els_pages)
856 DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
864 void HandleTypeName(int newxpos, Key key)
866 static int xpos = 0, ypos = 2;
871 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
872 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
876 if (((key >= KSYM_A && key <= KSYM_Z) ||
877 (key >= KSYM_a && key <= KSYM_z)) &&
878 xpos < MAX_PLAYER_NAME_LEN)
882 if (key >= KSYM_A && key <= KSYM_Z)
883 ascii = 'A' + (char)(key - KSYM_A);
885 ascii = 'a' + (char)(key - KSYM_a);
887 setup.player_name[xpos] = ascii;
888 setup.player_name[xpos + 1] = 0;
890 DrawTextExt(drawto, SX + 6*32, SY + ypos*32,
891 setup.player_name, FS_BIG, FC_YELLOW);
892 DrawTextExt(window, SX + 6*32, SY + ypos*32,
893 setup.player_name, FS_BIG, FC_YELLOW);
894 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
896 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
899 setup.player_name[xpos] = 0;
900 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
901 DrawGraphic(xpos + 7, ypos, GFX_LEERRAUM);
903 else if (key == KSYM_Return && xpos > 0)
905 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_RED);
906 DrawGraphic(xpos + 6, ypos, GFX_LEERRAUM);
909 game_status = MAINMENU;
915 void DrawChooseLevel()
918 CloseDoor(DOOR_CLOSE_2);
921 HandleChooseLevel(0,0, 0,0, MB_MENU_INITIALIZE);
922 MapChooseLevelGadgets();
928 static void AdjustChooseLevelScrollbar(int id, int first_entry)
930 struct GadgetInfo *gi = screen_gadget[id];
931 int items_max, items_visible, item_position;
933 items_max = numLevelDirInfoInGroup(leveldir_current);
934 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
935 item_position = first_entry;
937 if (item_position > items_max - items_visible)
938 item_position = items_max - items_visible;
940 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
941 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
944 static void drawChooseLevelList(int first_entry, int num_page_entries)
947 char buffer[SCR_FIELDX * 2];
948 int max_buffer_len = (SCR_FIELDX - 2) * 2;
949 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
951 ClearRectangle(backbuffer, SX, SY, SXSIZE - 32, SYSIZE);
952 redraw_mask |= REDRAW_FIELD;
954 DrawText(SX, SY, "Level Directories", FS_BIG, FC_GREEN);
956 for(i=0; i<num_page_entries; i++)
958 struct LevelDirInfo *node, *node_first;
959 int leveldir_pos = first_entry + i;
960 int ypos = MENU_SCREEN_START_YPOS + i;
962 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
963 node = getLevelDirInfoFromPos(node_first, leveldir_pos);
965 strncpy(buffer, node->name , max_buffer_len);
966 buffer[max_buffer_len] = '\0';
968 DrawText(SX + 32, SY + ypos * 32, buffer, FS_MEDIUM, node->color);
970 if (node->parent_link)
971 initCursor(i, GFX_ARROW_BLUE_LEFT);
972 else if (node->level_group)
973 initCursor(i, GFX_ARROW_BLUE_RIGHT);
975 initCursor(i, GFX_KUGEL_BLAU);
979 DrawGraphic(0, 1, GFX_ARROW_BLUE_UP);
981 if (first_entry + num_page_entries < num_leveldirs)
982 DrawGraphic(0, MAX_MENU_ENTRIES_ON_SCREEN + 1, GFX_ARROW_BLUE_DOWN);
985 static void drawChooseLevelInfo(int leveldir_pos)
987 struct LevelDirInfo *node, *node_first;
988 int x, last_redraw_mask = redraw_mask;
990 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
991 node = getLevelDirInfoFromPos(node_first, leveldir_pos);
993 ClearRectangle(drawto, SX + 32, SY + 32, SXSIZE - 64, 32);
995 if (node->parent_link)
996 DrawTextFCentered(40, FC_RED, "leave group \"%s\"", node->class_desc);
997 else if (node->level_group)
998 DrawTextFCentered(40, FC_RED, "enter group \"%s\"", node->class_desc);
1000 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
1001 node->levels, node->class_desc);
1003 /* let BackToFront() redraw only what is needed */
1004 redraw_mask = last_redraw_mask | REDRAW_TILES;
1005 for (x=0; x<SCR_FIELDX; x++)
1006 MarkTileDirty(x, 1);
1009 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1011 static unsigned long choose_delay = 0;
1013 int y = leveldir_current->cl_cursor;
1014 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1015 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
1016 int num_page_entries;
1018 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
1019 num_page_entries = num_leveldirs;
1021 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1023 if (button == MB_MENU_INITIALIZE)
1025 int leveldir_pos = posLevelDirInfo(leveldir_current);
1027 if (leveldir_current->cl_first == -1)
1029 leveldir_current->cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1030 leveldir_current->cl_cursor =
1031 leveldir_pos - leveldir_current->cl_first;
1034 if (dx == 999) /* first entry is set by scrollbar position */
1035 leveldir_current->cl_first = dy;
1037 AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1038 leveldir_current->cl_first);
1040 drawChooseLevelList(leveldir_current->cl_first, num_page_entries);
1041 drawChooseLevelInfo(leveldir_current->cl_first +
1042 leveldir_current->cl_cursor);
1043 drawCursor(leveldir_current->cl_cursor, FC_RED);
1046 else if (button == MB_MENU_LEAVE)
1048 if (leveldir_current->node_parent)
1050 leveldir_current = leveldir_current->node_parent;
1055 game_status = MAINMENU;
1061 if (mx || my) /* mouse input */
1064 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1066 else if (dx || dy) /* keyboard input */
1069 y = leveldir_current->cl_cursor + dy;
1071 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1074 step = num_page_entries - 1;
1075 y = (dy < 0 ? -1 : num_page_entries);
1079 if (x == 0 && y == -1)
1081 if (leveldir_current->cl_first > 0 &&
1082 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1084 leveldir_current->cl_first -= step;
1085 if (leveldir_current->cl_first < 0)
1086 leveldir_current->cl_first = 0;
1088 drawChooseLevelList(leveldir_current->cl_first, num_page_entries);
1089 drawChooseLevelInfo(leveldir_current->cl_first +
1090 leveldir_current->cl_cursor);
1091 drawCursor(leveldir_current->cl_cursor, FC_RED);
1092 AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1093 leveldir_current->cl_first);
1097 else if (x == 0 && y > num_page_entries - 1)
1099 if (leveldir_current->cl_first + num_page_entries < num_leveldirs &&
1100 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1102 leveldir_current->cl_first += step;
1103 if (leveldir_current->cl_first + num_page_entries > num_leveldirs)
1104 leveldir_current->cl_first = MAX(0, num_leveldirs - num_page_entries);
1106 drawChooseLevelList(leveldir_current->cl_first, num_page_entries);
1107 drawChooseLevelInfo(leveldir_current->cl_first +
1108 leveldir_current->cl_cursor);
1109 drawCursor(leveldir_current->cl_cursor, FC_RED);
1110 AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1111 leveldir_current->cl_first);
1118 struct LevelDirInfo *node_first, *node_cursor;
1119 int leveldir_pos = leveldir_current->cl_first + y;
1121 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
1122 node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos);
1124 if (node_cursor->node_group)
1126 node_cursor->cl_first = leveldir_current->cl_first;
1127 node_cursor->cl_cursor = leveldir_current->cl_cursor;
1128 leveldir_current = node_cursor->node_group;
1133 else if (dx == -1 && leveldir_current->node_parent)
1135 leveldir_current = leveldir_current->node_parent;
1140 if (x == 0 && y >= 0 && y < num_page_entries)
1144 if (y != leveldir_current->cl_cursor)
1146 drawCursor(y, FC_RED);
1147 drawCursor(leveldir_current->cl_cursor, FC_BLUE);
1148 drawChooseLevelInfo(leveldir_current->cl_first + y);
1149 leveldir_current->cl_cursor = y;
1154 struct LevelDirInfo *node_first, *node_cursor;
1155 int leveldir_pos = leveldir_current->cl_first + y;
1157 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
1158 node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos);
1160 if (node_cursor->node_group)
1162 node_cursor->cl_first = leveldir_current->cl_first;
1163 node_cursor->cl_cursor = leveldir_current->cl_cursor;
1164 leveldir_current = node_cursor->node_group;
1168 else if (node_cursor->parent_link)
1170 leveldir_current = node_cursor->node_parent;
1176 node_cursor->cl_first = leveldir_current->cl_first;
1177 node_cursor->cl_cursor = leveldir_current->cl_cursor;
1178 leveldir_current = node_cursor;
1180 LoadLevelSetup_SeriesInfo();
1182 SaveLevelSetup_LastSeries();
1183 SaveLevelSetup_SeriesInfo();
1186 game_status = MAINMENU;
1194 if (game_status == CHOOSELEVEL)
1198 void DrawHallOfFame(int highlight_position)
1202 CloseDoor(DOOR_CLOSE_2);
1204 if (highlight_position < 0)
1205 LoadScore(level_nr);
1209 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1210 PlaySound(SND_HALLOFFAME);
1213 static void drawHallOfFameList(int first_entry, int highlight_position)
1218 DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1219 DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1221 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1223 int entry = first_entry + i;
1224 int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1227 DrawText(SX, SY + 64 + i * 32, ".................", FS_BIG, color);
1228 DrawText(SX, SY + 64 + i * 32, highscore[i].Name, FS_BIG, color);
1229 DrawText(SX + 12 * 32, SY + 64 + i * 32,
1230 int2str(highscore[i].Score, 5), FS_BIG, color);
1232 DrawText(SX, SY + 64 + i * 32, "..................................",
1233 FS_MEDIUM, FC_YELLOW);
1234 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1235 FS_MEDIUM, FC_YELLOW);
1236 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name, FS_BIG, color);
1237 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1238 int2str(highscore[entry].Score, 5), FS_MEDIUM, color);
1243 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1245 static int first_entry = 0;
1246 static int highlight_position = 0;
1247 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1248 int button_released = !button;
1250 if (button == MB_MENU_INITIALIZE)
1253 highlight_position = mx;
1254 drawHallOfFameList(first_entry, highlight_position);
1258 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1259 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1263 if (first_entry > 0)
1265 first_entry -= step;
1266 if (first_entry < 0)
1269 drawHallOfFameList(first_entry, highlight_position);
1275 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1277 first_entry += step;
1278 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1279 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1281 drawHallOfFameList(first_entry, highlight_position);
1286 if (button_released)
1288 FadeSound(SND_HALLOFFAME);
1289 game_status = MAINMENU;
1295 if (game_status == HALLOFFAME)
1300 /* ========================================================================= */
1301 /* setup screen functions */
1302 /* ========================================================================= */
1304 static struct TokenInfo *setup_info;
1305 static int num_setup_info;
1306 static int setup_mode = SETUP_MODE_MAIN;
1308 static void execSetupMain()
1310 setup_mode = SETUP_MODE_MAIN;
1314 static void execSetupSound()
1316 setup_mode = SETUP_MODE_SOUND;
1320 static void execSetupInput()
1322 setup_mode = SETUP_MODE_INPUT;
1326 static void execExitSetup()
1328 game_status = MAINMENU;
1332 static void execSaveAndExitSetup()
1338 static struct TokenInfo setup_info_main[] =
1340 { TYPE_ENTER_MENU, execSetupSound, "Sound Setup" },
1341 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1342 { TYPE_EMPTY, NULL, "" },
1344 { TYPE_SWITCH, &setup.sound, "Sound:", },
1345 { TYPE_SWITCH, &setup.sound_loops, " Sound Loops:" },
1346 { TYPE_SWITCH, &setup.sound_music, " Game Music:" },
1348 { TYPE_SWITCH, &setup.toons, "Toons:" },
1350 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1352 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1353 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1355 { TYPE_SWITCH, &setup.fading, "Fading:" },
1357 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1358 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1359 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1360 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1361 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1362 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1363 { TYPE_EMPTY, NULL, "" },
1364 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1365 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and exit" },
1369 static struct TokenInfo setup_info_sound[] =
1371 { TYPE_SWITCH, &setup.sound, "Sound:", },
1372 { TYPE_EMPTY, NULL, "" },
1373 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1374 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1375 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1376 { TYPE_EMPTY, NULL, "" },
1377 { TYPE_LEAVE_MENU, execSetupMain, "Exit" },
1381 static void drawSetupValue(int pos)
1383 int xpos = MENU_SCREEN_VALUE_XPOS;
1384 int ypos = MENU_SCREEN_START_YPOS + pos;
1385 int value_color = FC_YELLOW;
1386 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1387 setup_info[pos].value);
1389 if (setup_info[pos].type & TYPE_SWITCH ||
1390 setup_info[pos].type & TYPE_YES_NO)
1392 boolean value = *(boolean *)(setup_info[pos].value);
1393 int value_length = 3;
1396 value_color = FC_BLUE;
1398 if (strlen(value_string) < value_length)
1399 strcat(value_string, " ");
1402 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, FS_BIG, value_color);
1405 static void DrawGenericSetupScreen()
1407 char *title_string = NULL;
1411 CloseDoor(DOOR_CLOSE_2);
1414 if (setup_mode == SETUP_MODE_MAIN)
1416 setup_info = setup_info_main;
1417 title_string = "Setup";
1419 else if (setup_mode == SETUP_MODE_SOUND)
1421 setup_info = setup_info_sound;
1422 title_string = "Sound Setup";
1425 DrawText(SX + 16, SY + 16, title_string, FS_BIG, FC_YELLOW);
1428 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1430 void *value_ptr = setup_info[i].value;
1431 int ypos = MENU_SCREEN_START_YPOS + i;
1433 /* set some entries to "unchangeable" according to other variables */
1434 if ((value_ptr == &setup.sound && !audio.sound_available) ||
1435 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
1436 (value_ptr == &setup.sound_music && !audio.music_available) ||
1437 (value_ptr == &setup.sound_music && !audio.music_available) ||
1438 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
1439 setup_info[i].type |= TYPE_GHOSTED;
1441 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, FS_BIG, FC_GREEN);
1443 if (setup_info[i].type & TYPE_ENTER_MENU)
1444 initCursor(i, GFX_ARROW_BLUE_RIGHT);
1445 else if (setup_info[i].type & TYPE_LEAVE_MENU)
1446 initCursor(i, GFX_ARROW_BLUE_LEFT);
1447 else if (setup_info[i].type != TYPE_EMPTY)
1448 initCursor(i, GFX_KUGEL_BLAU);
1450 if (setup_info[i].type & TYPE_BOOLEAN_STYLE)
1458 HandleSetupScreen(0,0,0,0,MB_MENU_INITIALIZE);
1461 void HandleGenericSetupScreen(int mx, int my, int dx, int dy, int button)
1463 static int choice_store[MAX_SETUP_MODES];
1464 int choice = choice_store[setup_mode];
1468 if (button == MB_MENU_INITIALIZE)
1470 drawCursor(choice, FC_RED);
1473 else if (button == MB_MENU_LEAVE)
1475 for (y=0; y<num_setup_info; y++)
1477 if (setup_info[y].type & TYPE_LEAVE_MENU)
1479 void (*menu_callback_function)(void) = setup_info[y].value;
1481 menu_callback_function();
1482 break; /* absolutely needed because 'setup_info' has changed! */
1489 if (mx || my) /* mouse input */
1492 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1494 else if (dx || dy) /* keyboard input */
1498 int type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
1500 if (!(setup_info[choice].type & TYPE_ENTER_OR_LEAVE_MENU) ||
1501 setup_info[choice].type == type)
1502 button = MB_MENU_CHOICE;
1507 /* jump to next non-empty menu entry (up or down) */
1508 while (y > 0 && y < num_setup_info - 1 &&
1509 setup_info[y].type == TYPE_EMPTY)
1513 if (x == 0 && y >= 0 && y < num_setup_info &&
1514 setup_info[y].type != TYPE_EMPTY)
1520 drawCursor(y, FC_RED);
1521 drawCursor(choice, FC_BLUE);
1522 choice = choice_store[setup_mode] = y;
1525 else if (!(setup_info[y].type & TYPE_GHOSTED))
1527 if (setup_info[y].type & TYPE_BOOLEAN_STYLE)
1529 boolean new_value = !*(boolean *)(setup_info[y].value);
1531 *(boolean *)setup_info[y].value = new_value;
1534 else if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
1536 void (*menu_callback_function)(void) = setup_info[choice].value;
1538 menu_callback_function();
1545 if (game_status == SETUP)
1549 void DrawSetupInputScreen()
1552 DrawText(SX+16, SY+16, "SETUP INPUT", FS_BIG, FC_YELLOW);
1554 initCursor(0, GFX_KUGEL_BLAU);
1555 initCursor(1, GFX_KUGEL_BLAU);
1556 initCursor(2, GFX_ARROW_BLUE_RIGHT);
1557 initCursor(13, GFX_ARROW_BLUE_LEFT);
1559 DrawGraphic(10, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_LEFT);
1560 DrawGraphic(12, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_RIGHT);
1562 DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
1563 DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
1564 DrawText(SX+32, SY+15*32, "Exit", FS_BIG, FC_GREEN);
1566 DeactivateJoystickForCalibration();
1567 DrawTextFCentered(SYSIZE - 20, FC_BLUE,
1568 "Joysticks deactivated on this screen");
1570 HandleSetupInputScreen(0,0, 0,0, MB_MENU_INITIALIZE);
1575 static void setJoystickDeviceToNr(char *device_name, int device_nr)
1577 if (device_name == NULL)
1580 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
1583 if (strlen(device_name) > 1)
1585 char c1 = device_name[strlen(device_name) - 1];
1586 char c2 = device_name[strlen(device_name) - 2];
1588 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
1589 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
1592 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
1593 strlen(device_name));
1596 static void drawPlayerSetupInputInfo(int player_nr)
1599 static struct SetupKeyboardInfo custom_key;
1606 { &custom_key.left, "Joystick Left" },
1607 { &custom_key.right, "Joystick Right" },
1608 { &custom_key.up, "Joystick Up" },
1609 { &custom_key.down, "Joystick Down" },
1610 { &custom_key.snap, "Button 1" },
1611 { &custom_key.bomb, "Button 2" }
1613 static char *joystick_name[MAX_PLAYERS] =
1621 custom_key = setup.input[player_nr].key;
1623 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
1624 DrawGraphic(8, 2, GFX_SPIELER1 + player_nr);
1626 if (setup.input[player_nr].use_joystick)
1628 char *device_name = setup.input[player_nr].joy.device_name;
1630 DrawText(SX+8*32, SY+3*32,
1631 joystick_name[getJoystickNrFromDeviceName(device_name)],
1633 DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
1637 DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
1638 DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
1641 DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
1642 DrawGraphic(1, 6, GFX_ARROW_BLUE_LEFT);
1643 DrawGraphic(1, 7, GFX_ARROW_BLUE_RIGHT);
1644 DrawGraphic(1, 8, GFX_ARROW_BLUE_UP);
1645 DrawGraphic(1, 9, GFX_ARROW_BLUE_DOWN);
1646 DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
1647 DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
1648 DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
1649 DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
1650 DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
1651 DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
1655 int ypos = 6 + i + (i > 3 ? i-3 : 0);
1657 DrawText(SX + 3*32, SY + ypos*32,
1658 " ", FS_BIG, FC_YELLOW);
1659 DrawText(SX + 3*32, SY + ypos*32,
1660 (setup.input[player_nr].use_joystick ?
1662 getKeyNameFromKey(*custom[i].key)),
1667 void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button)
1669 static int choice = 0;
1670 static int player_nr = 0;
1673 int pos_start = SETUPINPUT_SCREEN_POS_START;
1674 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
1675 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
1676 int pos_end = SETUPINPUT_SCREEN_POS_END;
1678 if (button == MB_MENU_INITIALIZE)
1680 drawPlayerSetupInputInfo(player_nr);
1681 drawCursor(choice, FC_RED);
1684 else if (button == MB_MENU_LEAVE)
1686 setup_mode = SETUP_MODE_MAIN;
1691 if (mx || my) /* mouse input */
1694 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1696 else if (dx || dy) /* keyboard input */
1698 if (dx && choice == 0)
1699 x = (dx < 0 ? 10 : 12);
1700 else if ((dx && choice == 1) ||
1701 (dx == +1 && choice == 2) ||
1702 (dx == -1 && choice == pos_end))
1703 button = MB_MENU_CHOICE;
1707 if (y >= pos_empty1 && y <= pos_empty2)
1708 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
1711 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
1713 static unsigned long delay = 0;
1715 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
1718 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
1720 drawPlayerSetupInputInfo(player_nr);
1722 else if (x == 0 && y >= pos_start && y <= pos_end &&
1723 !(y >= pos_empty1 && y <= pos_empty2))
1729 drawCursor(y, FC_RED);
1730 drawCursor(choice, FC_BLUE);
1738 char *device_name = setup.input[player_nr].joy.device_name;
1740 if (!setup.input[player_nr].use_joystick)
1742 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
1744 setJoystickDeviceToNr(device_name, new_device_nr);
1745 setup.input[player_nr].use_joystick = TRUE;
1749 int device_nr = getJoystickNrFromDeviceName(device_name);
1750 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
1752 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
1753 setup.input[player_nr].use_joystick = FALSE;
1755 setJoystickDeviceToNr(device_name, new_device_nr);
1758 drawPlayerSetupInputInfo(player_nr);
1762 if (setup.input[player_nr].use_joystick)
1765 CalibrateJoystick(player_nr);
1768 CustomizeKeyboard(player_nr);
1770 else if (y == pos_end)
1774 setup_mode = SETUP_MODE_MAIN;
1784 if (game_status == SETUP)
1788 void DrawSetupScreen()
1790 if (setup_mode == SETUP_MODE_INPUT)
1791 DrawSetupInputScreen();
1793 DrawGenericSetupScreen();
1796 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
1798 if (setup_mode == SETUP_MODE_INPUT)
1799 HandleSetupInputScreen(mx, my, dx, dy, button);
1801 HandleGenericSetupScreen(mx, my, dx, dy, button);
1804 void CustomizeKeyboard(int player_nr)
1808 boolean finished = FALSE;
1809 static struct SetupKeyboardInfo custom_key;
1814 } customize_step[] =
1816 { &custom_key.left, "Move Left" },
1817 { &custom_key.right, "Move Right" },
1818 { &custom_key.up, "Move Up" },
1819 { &custom_key.down, "Move Down" },
1820 { &custom_key.snap, "Snap Field" },
1821 { &custom_key.bomb, "Place Bomb" }
1824 /* read existing key bindings from player setup */
1825 custom_key = setup.input[player_nr].key;
1828 DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
1834 DrawText(SX, SY + (2+2*step_nr)*32,
1835 customize_step[step_nr].text, FS_BIG, FC_RED);
1836 DrawText(SX, SY + (2+2*step_nr+1)*32,
1837 "Key:", FS_BIG, FC_RED);
1838 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1839 getKeyNameFromKey(*customize_step[step_nr].key),
1844 if (PendingEvent()) /* got event */
1852 case EVENT_KEYPRESS:
1854 Key key = GetEventKey((KeyEvent *)&event, TRUE);
1856 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
1862 /* all keys configured -- wait for "Escape" or "Return" key */
1866 /* press 'Enter' to keep the existing key binding */
1867 if (key == KSYM_Return)
1868 key = *customize_step[step_nr].key;
1870 /* check if key already used */
1871 for (i=0; i<step_nr; i++)
1872 if (*customize_step[i].key == key)
1877 /* got new key binding */
1878 *customize_step[step_nr].key = key;
1879 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1880 " ", FS_BIG, FC_YELLOW);
1881 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1882 getKeyNameFromKey(key), FS_BIG, FC_YELLOW);
1885 /* un-highlight last query */
1886 DrawText(SX, SY+(2+2*(step_nr-1))*32,
1887 customize_step[step_nr-1].text, FS_BIG, FC_GREEN);
1888 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
1889 "Key:", FS_BIG, FC_GREEN);
1891 /* press 'Enter' to leave */
1894 DrawText(SX + 16, SY + 15*32+16,
1895 "Press Enter", FS_BIG, FC_YELLOW);
1899 /* query next key binding */
1900 DrawText(SX, SY+(2+2*step_nr)*32,
1901 customize_step[step_nr].text, FS_BIG, FC_RED);
1902 DrawText(SX, SY+(2+2*step_nr+1)*32,
1903 "Key:", FS_BIG, FC_RED);
1904 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
1905 getKeyNameFromKey(*customize_step[step_nr].key),
1910 case EVENT_KEYRELEASE:
1911 key_joystick_mapping = 0;
1915 HandleOtherEvents(&event);
1923 /* don't eat all CPU time */
1927 /* write new key bindings back to player setup */
1928 setup.input[player_nr].key = custom_key;
1931 DrawSetupInputScreen();
1934 static boolean CalibrateJoystickMain(int player_nr)
1936 int new_joystick_xleft = JOYSTICK_XMIDDLE;
1937 int new_joystick_xright = JOYSTICK_XMIDDLE;
1938 int new_joystick_yupper = JOYSTICK_YMIDDLE;
1939 int new_joystick_ylower = JOYSTICK_YMIDDLE;
1940 int new_joystick_xmiddle, new_joystick_ymiddle;
1942 int joystick_fd = joystick.fd[player_nr];
1943 int x, y, last_x, last_y, xpos = 8, ypos = 3;
1944 boolean check[3][3];
1945 int check_remaining = 3 * 3;
1950 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
1953 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
1962 check[x][y] = FALSE;
1963 DrawGraphic(xpos + x - 1, ypos + y - 1, GFX_KUGEL_BLAU);
1967 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
1968 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
1969 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
1970 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
1971 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FS_BIG, FC_YELLOW);
1972 DrawText(SX, SY + 12 * 32, " AND ", FS_BIG, FC_YELLOW);
1973 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
1975 joy_value = Joystick(player_nr);
1976 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
1977 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
1979 /* eventually uncalibrated center position (joystick could be uncentered) */
1980 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
1983 new_joystick_xmiddle = joy_x;
1984 new_joystick_ymiddle = joy_y;
1986 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
1989 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
1994 if (PendingEvent()) /* got event */
2002 case EVENT_KEYPRESS:
2003 switch(GetEventKey((KeyEvent *)&event, TRUE))
2006 if (check_remaining == 0)
2019 case EVENT_KEYRELEASE:
2020 key_joystick_mapping = 0;
2024 HandleOtherEvents(&event);
2029 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2032 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2033 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2034 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2035 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2037 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2038 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2039 setup.input[player_nr].joy.xright = new_joystick_xright;
2040 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2041 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2042 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2044 CheckJoystickData();
2046 joy_value = Joystick(player_nr);
2048 if (joy_value & JOY_BUTTON && check_remaining == 0)
2051 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2052 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2054 if (x != last_x || y != last_y)
2056 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_GELB);
2057 DrawGraphic(xpos + x, ypos + y, GFX_KUGEL_ROT);
2062 if (check_remaining > 0 && !check[x+1][y+1])
2064 check[x+1][y+1] = TRUE;
2070 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2071 setup.input[player_nr].joy.xleft,
2072 setup.input[player_nr].joy.xmiddle,
2073 setup.input[player_nr].joy.xright);
2074 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2075 setup.input[player_nr].joy.yupper,
2076 setup.input[player_nr].joy.ymiddle,
2077 setup.input[player_nr].joy.ylower);
2086 /* don't eat all CPU time */
2090 /* calibrated center position (joystick should now be centered) */
2091 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2094 new_joystick_xmiddle = joy_x;
2095 new_joystick_ymiddle = joy_y;
2099 DrawSetupInputScreen();
2101 /* wait until the last pressed button was released */
2102 while (Joystick(player_nr) & JOY_BUTTON)
2104 if (PendingEvent()) /* got event */
2109 HandleOtherEvents(&event);
2118 void CalibrateJoystick(int player_nr)
2120 if (!CalibrateJoystickMain(player_nr))
2124 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
2125 DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
2127 Delay(2000); /* show error message for two seconds */
2131 void HandleGameActions()
2133 if (game_status != PLAYING)
2136 if (local_player->LevelSolved)
2139 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2147 /* ---------- new screen button stuff -------------------------------------- */
2149 /* graphic position and size values for buttons and scrollbars */
2150 #define SC_SCROLLBUTTON_XPOS 64
2151 #define SC_SCROLLBUTTON_YPOS 0
2152 #define SC_SCROLLBAR_XPOS 0
2153 #define SC_SCROLLBAR_YPOS 64
2155 #define SC_SCROLLBUTTON_XSIZE 32
2156 #define SC_SCROLLBUTTON_YSIZE 32
2158 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2159 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2160 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2161 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2162 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2163 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2164 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2165 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2167 #define SC_BORDER_SIZE 14
2175 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2178 SC_SCROLLBUTTON_XPOS + 0 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
2179 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2180 SCREEN_CTRL_ID_SCROLL_UP,
2181 "scroll level series up"
2184 SC_SCROLLBUTTON_XPOS + 1 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
2185 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2186 SCREEN_CTRL_ID_SCROLL_DOWN,
2187 "scroll level series down"
2199 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2202 SC_SCROLLBAR_XPOS, SC_SCROLLBAR_YPOS,
2203 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2204 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2205 GD_TYPE_SCROLLBAR_VERTICAL,
2206 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2207 "scroll level series vertically"
2211 static void CreateScreenScrollbuttons()
2213 Bitmap *gd_bitmap = pix[PIX_MORE];
2214 struct GadgetInfo *gi;
2215 unsigned long event_mask;
2218 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2220 int id = scrollbutton_info[i].gadget_id;
2221 int x, y, width, height;
2222 int gd_x1, gd_x2, gd_y1, gd_y2;
2224 x = scrollbutton_info[i].x;
2225 y = scrollbutton_info[i].y;
2227 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2231 width = SC_SCROLLBUTTON_XSIZE;
2232 height = SC_SCROLLBUTTON_YSIZE;
2233 gd_x1 = scrollbutton_info[i].xpos;
2234 gd_y1 = scrollbutton_info[i].ypos;
2236 gd_y2 = gd_y1 + SC_SCROLLBUTTON_YSIZE;
2238 gi = CreateGadget(GDI_CUSTOM_ID, id,
2239 GDI_CUSTOM_TYPE_ID, i,
2240 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2245 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2246 GDI_STATE, GD_BUTTON_UNPRESSED,
2247 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
2248 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
2249 GDI_EVENT_MASK, event_mask,
2250 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2254 Error(ERR_EXIT, "cannot create gadget");
2256 screen_gadget[id] = gi;
2260 static void CreateScreenScrollbars()
2264 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2266 int id = scrollbar_info[i].gadget_id;
2267 Bitmap *gd_bitmap = pix[PIX_MORE];
2268 int gd_x1, gd_x2, gd_y1, gd_y2;
2269 struct GadgetInfo *gi;
2270 int items_max, items_visible, item_position;
2271 unsigned long event_mask;
2272 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2275 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
2276 num_page_entries = num_leveldirs;
2278 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2280 items_max = MAX(num_leveldirs, num_page_entries);
2281 items_visible = num_page_entries;
2284 items_max = num_page_entries;
2285 items_visible = num_page_entries;
2289 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2291 gd_x1 = scrollbar_info[i].xpos;
2292 gd_x2 = gd_x1 + scrollbar_info[i].width;
2293 gd_y1 = scrollbar_info[i].ypos;
2294 gd_y2 = scrollbar_info[i].ypos;
2296 gi = CreateGadget(GDI_CUSTOM_ID, id,
2297 GDI_CUSTOM_TYPE_ID, i,
2298 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2299 GDI_X, scrollbar_info[i].x,
2300 GDI_Y, scrollbar_info[i].y,
2301 GDI_WIDTH, scrollbar_info[i].width,
2302 GDI_HEIGHT, scrollbar_info[i].height,
2303 GDI_TYPE, scrollbar_info[i].type,
2304 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2305 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2306 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2307 GDI_STATE, GD_BUTTON_UNPRESSED,
2308 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
2309 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
2310 GDI_BORDER_SIZE, SC_BORDER_SIZE,
2311 GDI_EVENT_MASK, event_mask,
2312 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2316 Error(ERR_EXIT, "cannot create gadget");
2318 screen_gadget[id] = gi;
2322 void CreateScreenGadgets()
2324 CreateScreenScrollbuttons();
2325 CreateScreenScrollbars();
2328 void MapChooseLevelGadgets()
2330 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
2333 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
2336 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2337 MapGadget(screen_gadget[i]);
2340 void UnmapChooseLevelGadgets()
2344 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2345 UnmapGadget(screen_gadget[i]);
2348 static void HandleScreenGadgets(struct GadgetInfo *gi)
2350 int id = gi->custom_id;
2352 if (game_status != CHOOSELEVEL)
2357 case SCREEN_CTRL_ID_SCROLL_UP:
2358 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
2361 case SCREEN_CTRL_ID_SCROLL_DOWN:
2362 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
2365 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
2366 HandleChooseLevel(0,0, 999,gi->event.item_position, MB_MENU_INITIALIZE);