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();
129 /* needed if last screen was the playing screen, invoked from level editor */
130 if (level_editor_test_game)
132 game_status = LEVELED;
137 /* needed if last screen was the editor screen */
138 UndrawSpecialEditorDoor();
140 /* needed if last screen was the setup screen and fullscreen state changed */
141 ToggleFullscreenIfNeeded();
144 SetDrawtoField(DRAW_BACKBUFFER);
147 /* map gadgets for main menu screen */
150 /* leveldir_current may be invalid (level group, parent link) */
151 if (!validLevelSeries(leveldir_current))
152 leveldir_current = getFirstValidLevelSeries(leveldir_last_valid);
154 /* store valid level series information */
155 leveldir_last_valid = leveldir_current;
157 /* level_nr may have been set to value over handicap with level editor */
158 if (setup.handicap && level_nr > leveldir_current->handicap_level)
159 level_nr = leveldir_current->handicap_level;
166 DrawText(SX + 32, SY + 2*32, name_text, FS_BIG, FC_GREEN);
167 DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
168 DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
169 DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
170 (leveldir_current->readonly ? FC_RED : FC_YELLOW));
171 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
172 DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
173 DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
174 DrawText(SX + 32, SY + 7*32, "Start Game", FS_BIG, FC_GREEN);
175 DrawText(SX + 32, SY + 8*32, "Setup", FS_BIG, FC_GREEN);
176 DrawText(SX + 32, SY + 9*32, "Quit", FS_BIG, FC_GREEN);
178 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
180 DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
181 leveldir_current->first_level,
182 leveldir_current->last_level);
184 if (leveldir_current->readonly)
186 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
187 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
191 initCursor(i, (i == 1 || i == 6 ? GFX_ARROW_BLUE_RIGHT : GFX_KUGEL_BLAU));
193 DrawGraphic(10, 3, GFX_ARROW_BLUE_LEFT);
194 DrawGraphic(14, 3, GFX_ARROW_BLUE_RIGHT);
196 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
199 if (leveldir_current->name)
201 int len = strlen(leveldir_current->name);
202 int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
203 int lypos = SY + 352;
205 DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
210 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
213 if (TAPE_IS_EMPTY(tape))
215 DrawCompleteVideoDisplay();
217 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
225 static void gotoTopLevelDir()
227 /* move upwards to top level directory */
228 while (leveldir_current->node_parent)
230 /* write a "path" into level tree for easy navigation to last level */
231 if (leveldir_current->node_parent->node_group->cl_first == -1)
233 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
234 int leveldir_pos = posLevelDirInfo(leveldir_current);
235 int num_page_entries;
236 int cl_first, cl_cursor;
238 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
239 num_page_entries = num_leveldirs;
241 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
243 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
244 cl_cursor = leveldir_pos - cl_first;
246 leveldir_current->node_parent->node_group->cl_first = cl_first;
247 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
250 leveldir_current = leveldir_current->node_parent;
254 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
256 static int choice = 0;
260 if (button == MB_MENU_INITIALIZE)
262 drawCursor(choice, FC_RED);
266 if (mx || my) /* mouse input */
269 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
271 else if (dx || dy) /* keyboard input */
273 if (dx && choice == 1)
274 x = (dx < 0 ? 10 : 14);
279 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
280 (x == 14 && level_nr < leveldir_current->last_level)) &&
283 static unsigned long level_delay = 0;
284 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
285 int new_level_nr, old_level_nr = level_nr;
286 int font_color = (leveldir_current->readonly ? FC_RED : FC_YELLOW);
288 new_level_nr = level_nr + (x == 10 ? -step : +step);
289 if (new_level_nr < leveldir_current->first_level)
290 new_level_nr = leveldir_current->first_level;
291 if (new_level_nr > leveldir_current->last_level)
292 new_level_nr = leveldir_current->last_level;
294 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
295 new_level_nr = leveldir_current->handicap_level;
297 if (old_level_nr == new_level_nr ||
298 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
301 level_nr = new_level_nr;
303 DrawTextExt(drawto, SX + 11 * 32, SY + 3 * 32,
304 int2str(level_nr, 3), FS_BIG, font_color);
305 DrawTextExt(window, SX + 11 * 32, SY + 3 * 32,
306 int2str(level_nr, 3), FS_BIG, font_color);
309 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
313 DrawCompleteVideoDisplay();
315 /* needed because DrawMicroLevel() takes some time */
318 DelayReached(&level_delay, 0); /* reset delay counter */
320 else if (x == 0 && y >= 0 && y <= 7)
326 drawCursor(y, FC_RED);
327 drawCursor(choice, FC_BLUE);
335 game_status = TYPENAME;
336 HandleTypeName(strlen(setup.player_name), 0);
342 game_status = CHOOSELEVEL;
343 SaveLevelSetup_LastSeries();
344 SaveLevelSetup_SeriesInfo();
353 game_status = HALLOFFAME;
358 if (leveldir_current->readonly &&
359 strcmp(setup.player_name, "Artsoft") != 0)
360 Request("This level is read only !", REQ_CONFIRM);
361 game_status = LEVELED;
366 game_status = HELPSCREEN;
371 if (setup.autorecord)
372 TapeStartRecording();
374 #if defined(PLATFORM_UNIX)
376 SendToServer_StartPlaying();
380 game_status = PLAYING;
392 SaveLevelSetup_LastSeries();
393 SaveLevelSetup_SeriesInfo();
394 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
395 game_status = EXITGAME;
404 if (game_status == MAINMENU)
406 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
412 #define MAX_HELPSCREEN_ELS 10
416 static long helpscreen_state;
417 static int helpscreen_step[MAX_HELPSCREEN_ELS];
418 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
419 static int helpscreen_delay[MAX_HELPSCREEN_ELS];
420 static int helpscreen_action[] =
422 GFX_SPIELER1_DOWN,4,2,
424 GFX_SPIELER1_LEFT,4,2,
425 GFX_SPIELER1_RIGHT,4,2,
426 GFX_SPIELER1_PUSH_LEFT,4,2,
427 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
428 GFX_ERDREICH,1,100, HA_NEXT,
429 GFX_LEERRAUM,1,100, HA_NEXT,
430 GFX_MORAST_LEER,1,100, HA_NEXT,
431 GFX_BETON,1,100, HA_NEXT,
432 GFX_MAUERWERK,1,100, HA_NEXT,
433 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
434 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
435 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
436 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
437 GFX_UNSICHTBAR,1,100, HA_NEXT,
438 GFX_FELSBODEN,1,100, HA_NEXT,
439 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
440 GFX_EDELSTEIN,2,5, HA_NEXT,
441 GFX_DIAMANT,2,5, HA_NEXT,
442 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
443 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
444 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
445 GFX_FELSBROCKEN,4,5, HA_NEXT,
446 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
447 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
448 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
449 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
450 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
451 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
452 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
453 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
454 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
455 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
456 GFX_GEBLUBBER,4,4, HA_NEXT,
457 GFX_SCHLUESSEL1,4,25, HA_NEXT,
458 GFX_PFORTE1,4,25, HA_NEXT,
459 GFX_PFORTE1X,4,25, HA_NEXT,
460 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
461 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
462 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
463 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
464 GFX_LEERRAUM,1,10, HA_NEXT,
465 GFX_DYNABOMB_NR,1,100, HA_NEXT,
466 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
467 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
468 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
469 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
470 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
471 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
472 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
473 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
474 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
475 GFX_BUTTERFLY,2,2, HA_NEXT,
476 GFX_FIREFLY,2,2, HA_NEXT,
477 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
478 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
479 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
480 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
481 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
482 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
483 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
484 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
485 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
486 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
490 GFX_MOLE_RIGHT,4,2, HA_NEXT,
491 GFX_PINGUIN_DOWN,4,2,
493 GFX_PINGUIN_LEFT,4,2,
494 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
495 GFX_SCHWEIN_DOWN,4,2,
497 GFX_SCHWEIN_LEFT,4,2,
498 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
502 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
503 GFX_SONDE_START,8,1, HA_NEXT,
504 GFX_ABLENK,4,1, HA_NEXT,
505 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
506 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
507 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
508 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
509 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
510 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
511 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
512 GFX_DIAMANT,1,10, HA_NEXT,
513 GFX_LIFE,1,100, HA_NEXT,
514 GFX_LIFE_ASYNC,1,100, HA_NEXT,
515 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
516 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
517 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
518 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
519 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
520 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
521 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
522 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
523 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
524 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
525 GFX_SPEED_PILL,1,100, HA_NEXT,
528 static char *helpscreen_eltext[][2] =
530 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
531 {"Normal sand:", "You can dig through it"},
532 {"Empty field:", "You can walk through it"},
533 {"Quicksand: You cannot pass it,", "but rocks can fall though it"},
534 {"Massive Wall:", "Nothing can go through it"},
535 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
536 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
537 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
538 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
539 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
540 {"Emerald: You must collect enough of","them to finish a level"},
541 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
542 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
543 {"Colorful Gems:", "Seem to behave like Emeralds"},
544 {"Rock: Smashes several things;", "Can be moved by the player"},
545 {"Bomb: You can move it, but be", "careful when dropping it"},
546 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
547 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
548 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
549 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
550 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
551 {"Acid: Things that fall in are gone", "forever (including our hero)"},
552 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
553 {"Door: Can be opened by the key", "with the same color"},
554 {"Door: You have to find out the", "right color of the key for it"},
555 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
556 {"Dynamite: This one explodes after", "a few seconds"},
557 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
558 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
559 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
560 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
561 {"Bug: Moves at the right side", "of walls; don't touch it!"},
562 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
563 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
564 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
565 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
566 {"Cruncher (BD style):", "Eats almost everything"},
567 {"Robot: Tries to kill the player", ""},
568 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
569 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
570 {"The Pig: Harmless, but eats all", "gems it can get"},
571 {"The Dragon: Breathes fire,", "especially to some monsters"},
572 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
573 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
574 {"Light Bulb: All of them must be", "switched on to finish a level"},
575 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
576 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
577 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
578 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
579 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
580 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
581 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
582 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
583 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
584 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
585 {"Exit door: Opens if you have enough","emeralds to finish the level"},
586 {"Open exit door: Enter here to leave","the level and exit the actual game"},
587 {"Sokoban element: Object which must", "be pushed to an empty field"},
588 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
589 {"Sokoban element: Field with object", "which can be pushed away"},
590 {"Speed pill: Lets the player run", "twice as fast as normally"},
592 static int num_helpscreen_els = sizeof(helpscreen_eltext)/(2*sizeof(char *));
594 static char *helpscreen_music[][3] =
596 { "Alchemy", "Ian Boddy", "Drive" },
597 { "The Chase", "Propaganda", "A Secret Wish" },
598 { "Network 23", "Tangerine Dream", "Exit" },
599 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
600 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
601 { "Voyager", "The Alan Parsons Project","Pyramid" },
602 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
604 static int num_helpscreen_music = 7;
605 static int helpscreen_musicpos;
607 void DrawHelpScreenElAction(int start)
611 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
613 while(helpscreen_action[j] != HA_END)
615 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
617 else if (i<start || helpscreen_delay[i-start])
619 if (i>=start && helpscreen_delay[i-start])
620 helpscreen_delay[i-start]--;
622 while(helpscreen_action[j] != HA_NEXT)
629 j += 3*helpscreen_step[i-start];
630 graphic = helpscreen_action[j++];
632 if (helpscreen_frame[i-start])
634 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
635 helpscreen_frame[i-start]--;
640 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
643 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
645 if (helpscreen_action[j] == HA_NEXT)
647 if (!helpscreen_frame[i-start])
648 helpscreen_step[i-start] = 0;
652 if (!helpscreen_frame[i-start])
653 helpscreen_step[i-start]++;
654 while(helpscreen_action[j] != HA_NEXT)
659 DrawGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
670 void DrawHelpScreenElText(int start)
673 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
674 int ybottom = SYSIZE - 20;
679 DrawTextFCentered(100, FC_GREEN, "The game elements:");
681 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
684 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
685 helpscreen_eltext[i][0], FS_SMALL, FC_YELLOW);
686 DrawText(xstart, ystart + (i - start) * ystep + 16,
687 helpscreen_eltext[i][1], FS_SMALL, FC_YELLOW);
690 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
693 void DrawHelpScreenMusicText(int num)
695 int ystart = 150, ystep = 30;
696 int ybottom = SYSIZE - 20;
702 DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
704 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
706 DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
707 helpscreen_music[num][0]);
708 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
710 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
711 "%s", helpscreen_music[num][1]);
712 DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
714 DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
715 helpscreen_music[num][2]);
717 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
720 PlaySoundLoop(background_loop[num]);
724 void DrawHelpScreenCreditsText()
726 int ystart = 150, ystep = 30;
727 int ybottom = SYSIZE - 20;
733 DrawTextFCentered(100, FC_GREEN,
735 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
736 "DOS port of the game:");
737 DrawTextFCentered(ystart + 1 * ystep, FC_RED,
739 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
740 "Additional toons:");
741 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
743 DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
744 "...and many thanks to all contributors");
745 DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
748 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
751 void DrawHelpScreenContactText()
753 int ystart = 150, ystep = 30;
754 int ybottom = SYSIZE - 20;
759 DrawTextFCentered(100, FC_GREEN, "Program information:");
761 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
762 "This game is Freeware!");
763 DrawTextFCentered(ystart + 1 * ystep, FC_YELLOW,
764 "If you like it, send e-mail to:");
765 DrawTextFCentered(ystart + 2 * ystep, FC_RED,
767 DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
769 DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
771 DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
772 "Detmolder Strasse 189");
773 DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
775 DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
778 DrawTextFCentered(ystart + 7 * ystep, FC_YELLOW,
779 "If you have created new levels,");
780 DrawTextFCentered(ystart + 8 * ystep, FC_YELLOW,
781 "send them to me to include them!");
782 DrawTextFCentered(ystart + 9 * ystep, FC_YELLOW,
785 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
788 void DrawHelpScreen()
793 CloseDoor(DOOR_CLOSE_2);
795 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
796 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
797 helpscreen_musicpos = 0;
798 helpscreen_state = 0;
799 DrawHelpScreenElText(0);
800 DrawHelpScreenElAction(0);
804 PlaySoundLoop(SND_RHYTHMLOOP);
807 void HandleHelpScreen(int button)
809 static unsigned long hs_delay = 0;
810 int num_helpscreen_els_pages =
811 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
812 int button_released = !button;
817 if (helpscreen_state < num_helpscreen_els_pages - 1)
819 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
820 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
822 DrawHelpScreenElText(helpscreen_state*MAX_HELPSCREEN_ELS);
823 DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
825 else if (helpscreen_state <
826 num_helpscreen_els_pages + num_helpscreen_music - 1)
829 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
831 else if (helpscreen_state ==
832 num_helpscreen_els_pages + num_helpscreen_music - 1)
835 DrawHelpScreenCreditsText();
837 else if (helpscreen_state ==
838 num_helpscreen_els_pages + num_helpscreen_music)
841 DrawHelpScreenContactText();
847 game_status = MAINMENU;
852 if (DelayReached(&hs_delay,GAME_FRAME_DELAY * 2))
854 if (helpscreen_state<num_helpscreen_els_pages)
855 DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
863 void HandleTypeName(int newxpos, Key key)
865 static int xpos = 0, ypos = 2;
870 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
871 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
875 if (((key >= KSYM_A && key <= KSYM_Z) ||
876 (key >= KSYM_a && key <= KSYM_z)) &&
877 xpos < MAX_PLAYER_NAME_LEN)
881 if (key >= KSYM_A && key <= KSYM_Z)
882 ascii = 'A' + (char)(key - KSYM_A);
884 ascii = 'a' + (char)(key - KSYM_a);
886 setup.player_name[xpos] = ascii;
887 setup.player_name[xpos + 1] = 0;
889 DrawTextExt(drawto, SX + 6*32, SY + ypos*32,
890 setup.player_name, FS_BIG, FC_YELLOW);
891 DrawTextExt(window, SX + 6*32, SY + ypos*32,
892 setup.player_name, FS_BIG, FC_YELLOW);
893 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
895 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
898 setup.player_name[xpos] = 0;
899 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
900 DrawGraphic(xpos + 7, ypos, GFX_LEERRAUM);
902 else if (key == KSYM_Return && xpos > 0)
904 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_RED);
905 DrawGraphic(xpos + 6, ypos, GFX_LEERRAUM);
908 game_status = MAINMENU;
914 void DrawChooseLevel()
917 CloseDoor(DOOR_CLOSE_2);
920 HandleChooseLevel(0,0, 0,0, MB_MENU_INITIALIZE);
921 MapChooseLevelGadgets();
927 static void AdjustChooseLevelScrollbar(int id, int first_entry)
929 struct GadgetInfo *gi = screen_gadget[id];
930 int items_max, items_visible, item_position;
932 items_max = numLevelDirInfoInGroup(leveldir_current);
933 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
934 item_position = first_entry;
936 if (item_position > items_max - items_visible)
937 item_position = items_max - items_visible;
939 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
940 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
943 static void drawChooseLevelList(int first_entry, int num_page_entries)
946 char buffer[SCR_FIELDX * 2];
947 int max_buffer_len = (SCR_FIELDX - 2) * 2;
948 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
950 ClearRectangle(backbuffer, SX, SY, SXSIZE - 32, SYSIZE);
951 redraw_mask |= REDRAW_FIELD;
953 DrawText(SX, SY, "Level Directories", FS_BIG, FC_GREEN);
955 for(i=0; i<num_page_entries; i++)
957 struct LevelDirInfo *node, *node_first;
958 int leveldir_pos = first_entry + i;
959 int ypos = MENU_SCREEN_START_YPOS + i;
961 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
962 node = getLevelDirInfoFromPos(node_first, leveldir_pos);
964 strncpy(buffer, node->name , max_buffer_len);
965 buffer[max_buffer_len] = '\0';
967 DrawText(SX + 32, SY + ypos * 32, buffer, FS_MEDIUM, node->color);
969 if (node->parent_link)
970 initCursor(i, GFX_ARROW_BLUE_LEFT);
971 else if (node->level_group)
972 initCursor(i, GFX_ARROW_BLUE_RIGHT);
974 initCursor(i, GFX_KUGEL_BLAU);
978 DrawGraphic(0, 1, GFX_ARROW_BLUE_UP);
980 if (first_entry + num_page_entries < num_leveldirs)
981 DrawGraphic(0, MAX_MENU_ENTRIES_ON_SCREEN + 1, GFX_ARROW_BLUE_DOWN);
984 static void drawChooseLevelInfo(int leveldir_pos)
986 struct LevelDirInfo *node, *node_first;
987 int x, last_redraw_mask = redraw_mask;
989 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
990 node = getLevelDirInfoFromPos(node_first, leveldir_pos);
992 ClearRectangle(drawto, SX + 32, SY + 32, SXSIZE - 64, 32);
994 if (node->parent_link)
995 DrawTextFCentered(40, FC_RED, "leave group \"%s\"", node->class_desc);
996 else if (node->level_group)
997 DrawTextFCentered(40, FC_RED, "enter group \"%s\"", node->class_desc);
999 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
1000 node->levels, node->class_desc);
1002 /* let BackToFront() redraw only what is needed */
1003 redraw_mask = last_redraw_mask | REDRAW_TILES;
1004 for (x=0; x<SCR_FIELDX; x++)
1005 MarkTileDirty(x, 1);
1008 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1010 static unsigned long choose_delay = 0;
1012 int y = leveldir_current->cl_cursor;
1013 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1014 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
1015 int num_page_entries;
1017 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
1018 num_page_entries = num_leveldirs;
1020 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1022 if (button == MB_MENU_INITIALIZE)
1024 int leveldir_pos = posLevelDirInfo(leveldir_current);
1026 if (leveldir_current->cl_first == -1)
1028 leveldir_current->cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1029 leveldir_current->cl_cursor =
1030 leveldir_pos - leveldir_current->cl_first;
1033 if (dx == 999) /* first entry is set by scrollbar position */
1034 leveldir_current->cl_first = dy;
1036 AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1037 leveldir_current->cl_first);
1039 drawChooseLevelList(leveldir_current->cl_first, num_page_entries);
1040 drawChooseLevelInfo(leveldir_current->cl_first +
1041 leveldir_current->cl_cursor);
1042 drawCursor(leveldir_current->cl_cursor, FC_RED);
1045 else if (button == MB_MENU_LEAVE)
1047 if (leveldir_current->node_parent)
1049 leveldir_current = leveldir_current->node_parent;
1054 game_status = MAINMENU;
1060 if (mx || my) /* mouse input */
1063 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1065 else if (dx || dy) /* keyboard input */
1068 y = leveldir_current->cl_cursor + dy;
1070 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1073 step = num_page_entries - 1;
1074 y = (dy < 0 ? -1 : num_page_entries);
1078 if (x == 0 && y == -1)
1080 if (leveldir_current->cl_first > 0 &&
1081 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1083 leveldir_current->cl_first -= step;
1084 if (leveldir_current->cl_first < 0)
1085 leveldir_current->cl_first = 0;
1087 drawChooseLevelList(leveldir_current->cl_first, num_page_entries);
1088 drawChooseLevelInfo(leveldir_current->cl_first +
1089 leveldir_current->cl_cursor);
1090 drawCursor(leveldir_current->cl_cursor, FC_RED);
1091 AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1092 leveldir_current->cl_first);
1096 else if (x == 0 && y > num_page_entries - 1)
1098 if (leveldir_current->cl_first + num_page_entries < num_leveldirs &&
1099 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1101 leveldir_current->cl_first += step;
1102 if (leveldir_current->cl_first + num_page_entries > num_leveldirs)
1103 leveldir_current->cl_first = MAX(0, num_leveldirs - num_page_entries);
1105 drawChooseLevelList(leveldir_current->cl_first, num_page_entries);
1106 drawChooseLevelInfo(leveldir_current->cl_first +
1107 leveldir_current->cl_cursor);
1108 drawCursor(leveldir_current->cl_cursor, FC_RED);
1109 AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1110 leveldir_current->cl_first);
1117 struct LevelDirInfo *node_first, *node_cursor;
1118 int leveldir_pos = leveldir_current->cl_first + y;
1120 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
1121 node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos);
1123 if (node_cursor->node_group)
1125 node_cursor->cl_first = leveldir_current->cl_first;
1126 node_cursor->cl_cursor = leveldir_current->cl_cursor;
1127 leveldir_current = node_cursor->node_group;
1132 else if (dx == -1 && leveldir_current->node_parent)
1134 leveldir_current = leveldir_current->node_parent;
1139 if (x == 0 && y >= 0 && y < num_page_entries)
1143 if (y != leveldir_current->cl_cursor)
1145 drawCursor(y, FC_RED);
1146 drawCursor(leveldir_current->cl_cursor, FC_BLUE);
1147 drawChooseLevelInfo(leveldir_current->cl_first + y);
1148 leveldir_current->cl_cursor = y;
1153 struct LevelDirInfo *node_first, *node_cursor;
1154 int leveldir_pos = leveldir_current->cl_first + y;
1156 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
1157 node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos);
1159 if (node_cursor->node_group)
1161 node_cursor->cl_first = leveldir_current->cl_first;
1162 node_cursor->cl_cursor = leveldir_current->cl_cursor;
1163 leveldir_current = node_cursor->node_group;
1167 else if (node_cursor->parent_link)
1169 leveldir_current = node_cursor->node_parent;
1175 node_cursor->cl_first = leveldir_current->cl_first;
1176 node_cursor->cl_cursor = leveldir_current->cl_cursor;
1177 leveldir_current = node_cursor;
1179 LoadLevelSetup_SeriesInfo();
1181 SaveLevelSetup_LastSeries();
1182 SaveLevelSetup_SeriesInfo();
1185 game_status = MAINMENU;
1193 if (game_status == CHOOSELEVEL)
1197 void DrawHallOfFame(int highlight_position)
1201 CloseDoor(DOOR_CLOSE_2);
1203 if (highlight_position < 0)
1204 LoadScore(level_nr);
1208 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1209 PlaySound(SND_HALLOFFAME);
1212 static void drawHallOfFameList(int first_entry, int highlight_position)
1217 DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1218 DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1220 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1222 int entry = first_entry + i;
1223 int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1226 DrawText(SX, SY + 64 + i * 32, ".................", FS_BIG, color);
1227 DrawText(SX, SY + 64 + i * 32, highscore[i].Name, FS_BIG, color);
1228 DrawText(SX + 12 * 32, SY + 64 + i * 32,
1229 int2str(highscore[i].Score, 5), FS_BIG, color);
1231 DrawText(SX, SY + 64 + i * 32, "..................................",
1232 FS_MEDIUM, FC_YELLOW);
1233 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1234 FS_MEDIUM, FC_YELLOW);
1235 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name, FS_BIG, color);
1236 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1237 int2str(highscore[entry].Score, 5), FS_MEDIUM, color);
1242 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1244 static int first_entry = 0;
1245 static int highlight_position = 0;
1246 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1247 int button_released = !button;
1249 if (button == MB_MENU_INITIALIZE)
1252 highlight_position = mx;
1253 drawHallOfFameList(first_entry, highlight_position);
1257 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1258 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1262 if (first_entry > 0)
1264 first_entry -= step;
1265 if (first_entry < 0)
1268 drawHallOfFameList(first_entry, highlight_position);
1274 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1276 first_entry += step;
1277 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1278 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1280 drawHallOfFameList(first_entry, highlight_position);
1285 if (button_released)
1287 FadeSound(SND_HALLOFFAME);
1288 game_status = MAINMENU;
1294 if (game_status == HALLOFFAME)
1299 /* ========================================================================= */
1300 /* setup screen functions */
1301 /* ========================================================================= */
1303 static struct TokenInfo *setup_info;
1304 static int num_setup_info;
1305 static int setup_mode = SETUP_MODE_MAIN;
1307 static void execSetupMain()
1309 setup_mode = SETUP_MODE_MAIN;
1313 static void execSetupSound()
1315 setup_mode = SETUP_MODE_SOUND;
1319 static void execSetupInput()
1321 setup_mode = SETUP_MODE_INPUT;
1325 static void execExitSetup()
1327 game_status = MAINMENU;
1331 static void execSaveAndExitSetup()
1337 static struct TokenInfo setup_info_main[] =
1339 { TYPE_ENTER_MENU, execSetupSound, "Sound Setup" },
1340 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1341 { TYPE_EMPTY, NULL, "" },
1343 { TYPE_SWITCH, &setup.sound, "Sound:", },
1344 { TYPE_SWITCH, &setup.sound_loops, " Sound Loops:" },
1345 { TYPE_SWITCH, &setup.sound_music, " Game Music:" },
1347 { TYPE_SWITCH, &setup.toons, "Toons:" },
1349 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1351 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1352 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1354 { TYPE_SWITCH, &setup.fading, "Fading:" },
1356 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1357 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1358 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1359 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1360 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1361 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1362 { TYPE_EMPTY, NULL, "" },
1363 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1364 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and exit" },
1368 static struct TokenInfo setup_info_sound[] =
1370 { TYPE_SWITCH, &setup.sound, "Sound:", },
1371 { TYPE_EMPTY, NULL, "" },
1372 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1373 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1374 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1375 { TYPE_EMPTY, NULL, "" },
1376 { TYPE_LEAVE_MENU, execSetupMain, "Exit" },
1380 static void drawSetupValue(int pos)
1382 int xpos = MENU_SCREEN_VALUE_XPOS;
1383 int ypos = MENU_SCREEN_START_YPOS + pos;
1384 int value_color = FC_YELLOW;
1385 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1386 setup_info[pos].value);
1388 if (setup_info[pos].type & TYPE_SWITCH ||
1389 setup_info[pos].type & TYPE_YES_NO)
1391 boolean value = *(boolean *)(setup_info[pos].value);
1392 int value_length = 3;
1395 value_color = FC_BLUE;
1397 if (strlen(value_string) < value_length)
1398 strcat(value_string, " ");
1401 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, FS_BIG, value_color);
1404 static void DrawGenericSetupScreen()
1406 char *title_string = NULL;
1410 CloseDoor(DOOR_CLOSE_2);
1413 if (setup_mode == SETUP_MODE_MAIN)
1415 setup_info = setup_info_main;
1416 title_string = "Setup";
1418 else if (setup_mode == SETUP_MODE_SOUND)
1420 setup_info = setup_info_sound;
1421 title_string = "Sound Setup";
1424 DrawText(SX + 16, SY + 16, title_string, FS_BIG, FC_YELLOW);
1427 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1429 void *value_ptr = setup_info[i].value;
1430 int ypos = MENU_SCREEN_START_YPOS + i;
1432 /* set some entries to "unchangeable" according to other variables */
1433 if ((value_ptr == &setup.sound && !audio.sound_available) ||
1434 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
1435 (value_ptr == &setup.sound_music && !audio.music_available) ||
1436 (value_ptr == &setup.sound_music && !audio.music_available) ||
1437 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
1438 setup_info[i].type |= TYPE_GHOSTED;
1440 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, FS_BIG, FC_GREEN);
1442 if (setup_info[i].type & TYPE_ENTER_MENU)
1443 initCursor(i, GFX_ARROW_BLUE_RIGHT);
1444 else if (setup_info[i].type & TYPE_LEAVE_MENU)
1445 initCursor(i, GFX_ARROW_BLUE_LEFT);
1446 else if (setup_info[i].type != TYPE_EMPTY)
1447 initCursor(i, GFX_KUGEL_BLAU);
1449 if (setup_info[i].type & TYPE_BOOLEAN_STYLE)
1457 HandleSetupScreen(0,0,0,0,MB_MENU_INITIALIZE);
1460 void HandleGenericSetupScreen(int mx, int my, int dx, int dy, int button)
1462 static int choice_store[MAX_SETUP_MODES];
1463 int choice = choice_store[setup_mode];
1467 if (button == MB_MENU_INITIALIZE)
1469 drawCursor(choice, FC_RED);
1472 else if (button == MB_MENU_LEAVE)
1474 for (y=0; y<num_setup_info; y++)
1476 if (setup_info[y].type & TYPE_LEAVE_MENU)
1478 void (*menu_callback_function)(void) = setup_info[y].value;
1480 menu_callback_function();
1481 break; /* absolutely needed because 'setup_info' has changed! */
1488 if (mx || my) /* mouse input */
1491 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1493 else if (dx || dy) /* keyboard input */
1497 int type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
1499 if (!(setup_info[choice].type & TYPE_ENTER_OR_LEAVE_MENU) ||
1500 setup_info[choice].type == type)
1501 button = MB_MENU_CHOICE;
1506 /* jump to next non-empty menu entry (up or down) */
1507 while (y > 0 && y < num_setup_info - 1 &&
1508 setup_info[y].type == TYPE_EMPTY)
1512 if (x == 0 && y >= 0 && y < num_setup_info &&
1513 setup_info[y].type != TYPE_EMPTY)
1519 drawCursor(y, FC_RED);
1520 drawCursor(choice, FC_BLUE);
1521 choice = choice_store[setup_mode] = y;
1524 else if (!(setup_info[y].type & TYPE_GHOSTED))
1526 if (setup_info[y].type & TYPE_BOOLEAN_STYLE)
1528 boolean new_value = !*(boolean *)(setup_info[y].value);
1530 *(boolean *)setup_info[y].value = new_value;
1533 else if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
1535 void (*menu_callback_function)(void) = setup_info[choice].value;
1537 menu_callback_function();
1544 if (game_status == SETUP)
1548 void DrawSetupInputScreen()
1551 DrawText(SX+16, SY+16, "SETUP INPUT", FS_BIG, FC_YELLOW);
1553 initCursor(0, GFX_KUGEL_BLAU);
1554 initCursor(1, GFX_KUGEL_BLAU);
1555 initCursor(2, GFX_ARROW_BLUE_RIGHT);
1556 initCursor(13, GFX_ARROW_BLUE_LEFT);
1558 DrawGraphic(10, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_LEFT);
1559 DrawGraphic(12, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_RIGHT);
1561 DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
1562 DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
1563 DrawText(SX+32, SY+15*32, "Exit", FS_BIG, FC_GREEN);
1565 DeactivateJoystickForCalibration();
1566 DrawTextFCentered(SYSIZE - 20, FC_BLUE,
1567 "Joysticks deactivated on this screen");
1569 HandleSetupInputScreen(0,0, 0,0, MB_MENU_INITIALIZE);
1574 static void setJoystickDeviceToNr(char *device_name, int device_nr)
1576 if (device_name == NULL)
1579 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
1582 if (strlen(device_name) > 1)
1584 char c1 = device_name[strlen(device_name) - 1];
1585 char c2 = device_name[strlen(device_name) - 2];
1587 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
1588 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
1591 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
1592 strlen(device_name));
1595 static void drawPlayerSetupInputInfo(int player_nr)
1598 static struct SetupKeyboardInfo custom_key;
1605 { &custom_key.left, "Joystick Left" },
1606 { &custom_key.right, "Joystick Right" },
1607 { &custom_key.up, "Joystick Up" },
1608 { &custom_key.down, "Joystick Down" },
1609 { &custom_key.snap, "Button 1" },
1610 { &custom_key.bomb, "Button 2" }
1612 static char *joystick_name[MAX_PLAYERS] =
1620 custom_key = setup.input[player_nr].key;
1622 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
1623 DrawGraphic(8, 2, GFX_SPIELER1 + player_nr);
1625 if (setup.input[player_nr].use_joystick)
1627 char *device_name = setup.input[player_nr].joy.device_name;
1629 DrawText(SX+8*32, SY+3*32,
1630 joystick_name[getJoystickNrFromDeviceName(device_name)],
1632 DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
1636 DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
1637 DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
1640 DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
1641 DrawGraphic(1, 6, GFX_ARROW_BLUE_LEFT);
1642 DrawGraphic(1, 7, GFX_ARROW_BLUE_RIGHT);
1643 DrawGraphic(1, 8, GFX_ARROW_BLUE_UP);
1644 DrawGraphic(1, 9, GFX_ARROW_BLUE_DOWN);
1645 DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
1646 DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
1647 DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
1648 DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
1649 DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
1650 DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
1654 int ypos = 6 + i + (i > 3 ? i-3 : 0);
1656 DrawText(SX + 3*32, SY + ypos*32,
1657 " ", FS_BIG, FC_YELLOW);
1658 DrawText(SX + 3*32, SY + ypos*32,
1659 (setup.input[player_nr].use_joystick ?
1661 getKeyNameFromKey(*custom[i].key)),
1666 void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button)
1668 static int choice = 0;
1669 static int player_nr = 0;
1672 int pos_start = SETUPINPUT_SCREEN_POS_START;
1673 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
1674 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
1675 int pos_end = SETUPINPUT_SCREEN_POS_END;
1677 if (button == MB_MENU_INITIALIZE)
1679 drawPlayerSetupInputInfo(player_nr);
1680 drawCursor(choice, FC_RED);
1683 else if (button == MB_MENU_LEAVE)
1685 setup_mode = SETUP_MODE_MAIN;
1690 if (mx || my) /* mouse input */
1693 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1695 else if (dx || dy) /* keyboard input */
1697 if (dx && choice == 0)
1698 x = (dx < 0 ? 10 : 12);
1699 else if ((dx && choice == 1) ||
1700 (dx == +1 && choice == 2) ||
1701 (dx == -1 && choice == pos_end))
1702 button = MB_MENU_CHOICE;
1706 if (y >= pos_empty1 && y <= pos_empty2)
1707 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
1710 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
1712 static unsigned long delay = 0;
1714 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
1717 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
1719 drawPlayerSetupInputInfo(player_nr);
1721 else if (x == 0 && y >= pos_start && y <= pos_end &&
1722 !(y >= pos_empty1 && y <= pos_empty2))
1728 drawCursor(y, FC_RED);
1729 drawCursor(choice, FC_BLUE);
1737 char *device_name = setup.input[player_nr].joy.device_name;
1739 if (!setup.input[player_nr].use_joystick)
1741 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
1743 setJoystickDeviceToNr(device_name, new_device_nr);
1744 setup.input[player_nr].use_joystick = TRUE;
1748 int device_nr = getJoystickNrFromDeviceName(device_name);
1749 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
1751 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
1752 setup.input[player_nr].use_joystick = FALSE;
1754 setJoystickDeviceToNr(device_name, new_device_nr);
1757 drawPlayerSetupInputInfo(player_nr);
1761 if (setup.input[player_nr].use_joystick)
1764 CalibrateJoystick(player_nr);
1767 CustomizeKeyboard(player_nr);
1769 else if (y == pos_end)
1773 setup_mode = SETUP_MODE_MAIN;
1783 if (game_status == SETUP)
1787 void DrawSetupScreen()
1789 if (setup_mode == SETUP_MODE_INPUT)
1790 DrawSetupInputScreen();
1792 DrawGenericSetupScreen();
1795 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
1797 if (setup_mode == SETUP_MODE_INPUT)
1798 HandleSetupInputScreen(mx, my, dx, dy, button);
1800 HandleGenericSetupScreen(mx, my, dx, dy, button);
1803 void CustomizeKeyboard(int player_nr)
1807 boolean finished = FALSE;
1808 static struct SetupKeyboardInfo custom_key;
1813 } customize_step[] =
1815 { &custom_key.left, "Move Left" },
1816 { &custom_key.right, "Move Right" },
1817 { &custom_key.up, "Move Up" },
1818 { &custom_key.down, "Move Down" },
1819 { &custom_key.snap, "Snap Field" },
1820 { &custom_key.bomb, "Place Bomb" }
1823 /* read existing key bindings from player setup */
1824 custom_key = setup.input[player_nr].key;
1827 DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
1833 DrawText(SX, SY + (2+2*step_nr)*32,
1834 customize_step[step_nr].text, FS_BIG, FC_RED);
1835 DrawText(SX, SY + (2+2*step_nr+1)*32,
1836 "Key:", FS_BIG, FC_RED);
1837 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1838 getKeyNameFromKey(*customize_step[step_nr].key),
1843 if (PendingEvent()) /* got event */
1851 case EVENT_KEYPRESS:
1853 Key key = GetEventKey((KeyEvent *)&event, TRUE);
1855 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
1861 /* all keys configured -- wait for "Escape" or "Return" key */
1865 /* press 'Enter' to keep the existing key binding */
1866 if (key == KSYM_Return)
1867 key = *customize_step[step_nr].key;
1869 /* check if key already used */
1870 for (i=0; i<step_nr; i++)
1871 if (*customize_step[i].key == key)
1876 /* got new key binding */
1877 *customize_step[step_nr].key = key;
1878 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1879 " ", FS_BIG, FC_YELLOW);
1880 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1881 getKeyNameFromKey(key), FS_BIG, FC_YELLOW);
1884 /* un-highlight last query */
1885 DrawText(SX, SY+(2+2*(step_nr-1))*32,
1886 customize_step[step_nr-1].text, FS_BIG, FC_GREEN);
1887 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
1888 "Key:", FS_BIG, FC_GREEN);
1890 /* press 'Enter' to leave */
1893 DrawText(SX + 16, SY + 15*32+16,
1894 "Press Enter", FS_BIG, FC_YELLOW);
1898 /* query next key binding */
1899 DrawText(SX, SY+(2+2*step_nr)*32,
1900 customize_step[step_nr].text, FS_BIG, FC_RED);
1901 DrawText(SX, SY+(2+2*step_nr+1)*32,
1902 "Key:", FS_BIG, FC_RED);
1903 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
1904 getKeyNameFromKey(*customize_step[step_nr].key),
1909 case EVENT_KEYRELEASE:
1910 key_joystick_mapping = 0;
1914 HandleOtherEvents(&event);
1922 /* don't eat all CPU time */
1926 /* write new key bindings back to player setup */
1927 setup.input[player_nr].key = custom_key;
1930 DrawSetupInputScreen();
1933 static boolean CalibrateJoystickMain(int player_nr)
1935 int new_joystick_xleft = JOYSTICK_XMIDDLE;
1936 int new_joystick_xright = JOYSTICK_XMIDDLE;
1937 int new_joystick_yupper = JOYSTICK_YMIDDLE;
1938 int new_joystick_ylower = JOYSTICK_YMIDDLE;
1939 int new_joystick_xmiddle, new_joystick_ymiddle;
1941 int joystick_fd = joystick.fd[player_nr];
1942 int x, y, last_x, last_y, xpos = 8, ypos = 3;
1943 boolean check[3][3];
1944 int check_remaining = 3 * 3;
1949 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
1952 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
1961 check[x][y] = FALSE;
1962 DrawGraphic(xpos + x - 1, ypos + y - 1, GFX_KUGEL_BLAU);
1966 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
1967 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
1968 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
1969 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
1970 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FS_BIG, FC_YELLOW);
1971 DrawText(SX, SY + 12 * 32, " AND ", FS_BIG, FC_YELLOW);
1972 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
1974 joy_value = Joystick(player_nr);
1975 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
1976 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
1978 /* eventually uncalibrated center position (joystick could be uncentered) */
1979 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
1982 new_joystick_xmiddle = joy_x;
1983 new_joystick_ymiddle = joy_y;
1985 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
1988 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
1993 if (PendingEvent()) /* got event */
2001 case EVENT_KEYPRESS:
2002 switch(GetEventKey((KeyEvent *)&event, TRUE))
2005 if (check_remaining == 0)
2018 case EVENT_KEYRELEASE:
2019 key_joystick_mapping = 0;
2023 HandleOtherEvents(&event);
2028 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2031 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2032 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2033 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2034 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2036 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2037 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2038 setup.input[player_nr].joy.xright = new_joystick_xright;
2039 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2040 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2041 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2043 CheckJoystickData();
2045 joy_value = Joystick(player_nr);
2047 if (joy_value & JOY_BUTTON && check_remaining == 0)
2050 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2051 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2053 if (x != last_x || y != last_y)
2055 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_GELB);
2056 DrawGraphic(xpos + x, ypos + y, GFX_KUGEL_ROT);
2061 if (check_remaining > 0 && !check[x+1][y+1])
2063 check[x+1][y+1] = TRUE;
2069 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2070 setup.input[player_nr].joy.xleft,
2071 setup.input[player_nr].joy.xmiddle,
2072 setup.input[player_nr].joy.xright);
2073 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2074 setup.input[player_nr].joy.yupper,
2075 setup.input[player_nr].joy.ymiddle,
2076 setup.input[player_nr].joy.ylower);
2085 /* don't eat all CPU time */
2089 /* calibrated center position (joystick should now be centered) */
2090 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2093 new_joystick_xmiddle = joy_x;
2094 new_joystick_ymiddle = joy_y;
2098 DrawSetupInputScreen();
2100 /* wait until the last pressed button was released */
2101 while (Joystick(player_nr) & JOY_BUTTON)
2103 if (PendingEvent()) /* got event */
2108 HandleOtherEvents(&event);
2117 void CalibrateJoystick(int player_nr)
2119 if (!CalibrateJoystickMain(player_nr))
2123 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
2124 DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
2126 Delay(2000); /* show error message for two seconds */
2130 void HandleGameActions()
2132 if (game_status != PLAYING)
2135 if (local_player->LevelSolved)
2138 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2146 /* ---------- new screen button stuff -------------------------------------- */
2148 /* graphic position and size values for buttons and scrollbars */
2149 #define SC_SCROLLBUTTON_XPOS 64
2150 #define SC_SCROLLBUTTON_YPOS 0
2151 #define SC_SCROLLBAR_XPOS 0
2152 #define SC_SCROLLBAR_YPOS 64
2154 #define SC_SCROLLBUTTON_XSIZE 32
2155 #define SC_SCROLLBUTTON_YSIZE 32
2157 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2158 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2159 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2160 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2161 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2162 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2163 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2164 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2166 #define SC_BORDER_SIZE 14
2174 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2177 SC_SCROLLBUTTON_XPOS + 0 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
2178 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2179 SCREEN_CTRL_ID_SCROLL_UP,
2180 "scroll level series up"
2183 SC_SCROLLBUTTON_XPOS + 1 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
2184 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2185 SCREEN_CTRL_ID_SCROLL_DOWN,
2186 "scroll level series down"
2198 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2201 SC_SCROLLBAR_XPOS, SC_SCROLLBAR_YPOS,
2202 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2203 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2204 GD_TYPE_SCROLLBAR_VERTICAL,
2205 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2206 "scroll level series vertically"
2210 static void CreateScreenScrollbuttons()
2212 Bitmap *gd_bitmap = pix[PIX_MORE];
2213 struct GadgetInfo *gi;
2214 unsigned long event_mask;
2217 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2219 int id = scrollbutton_info[i].gadget_id;
2220 int x, y, width, height;
2221 int gd_x1, gd_x2, gd_y1, gd_y2;
2223 x = scrollbutton_info[i].x;
2224 y = scrollbutton_info[i].y;
2226 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2230 width = SC_SCROLLBUTTON_XSIZE;
2231 height = SC_SCROLLBUTTON_YSIZE;
2232 gd_x1 = scrollbutton_info[i].xpos;
2233 gd_y1 = scrollbutton_info[i].ypos;
2235 gd_y2 = gd_y1 + SC_SCROLLBUTTON_YSIZE;
2237 gi = CreateGadget(GDI_CUSTOM_ID, id,
2238 GDI_CUSTOM_TYPE_ID, i,
2239 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2244 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2245 GDI_STATE, GD_BUTTON_UNPRESSED,
2246 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
2247 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
2248 GDI_EVENT_MASK, event_mask,
2249 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2253 Error(ERR_EXIT, "cannot create gadget");
2255 screen_gadget[id] = gi;
2259 static void CreateScreenScrollbars()
2263 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2265 int id = scrollbar_info[i].gadget_id;
2266 Bitmap *gd_bitmap = pix[PIX_MORE];
2267 int gd_x1, gd_x2, gd_y1, gd_y2;
2268 struct GadgetInfo *gi;
2269 int items_max, items_visible, item_position;
2270 unsigned long event_mask;
2271 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2274 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
2275 num_page_entries = num_leveldirs;
2277 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2279 items_max = MAX(num_leveldirs, num_page_entries);
2280 items_visible = num_page_entries;
2283 items_max = num_page_entries;
2284 items_visible = num_page_entries;
2288 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2290 gd_x1 = scrollbar_info[i].xpos;
2291 gd_x2 = gd_x1 + scrollbar_info[i].width;
2292 gd_y1 = scrollbar_info[i].ypos;
2293 gd_y2 = scrollbar_info[i].ypos;
2295 gi = CreateGadget(GDI_CUSTOM_ID, id,
2296 GDI_CUSTOM_TYPE_ID, i,
2297 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2298 GDI_X, scrollbar_info[i].x,
2299 GDI_Y, scrollbar_info[i].y,
2300 GDI_WIDTH, scrollbar_info[i].width,
2301 GDI_HEIGHT, scrollbar_info[i].height,
2302 GDI_TYPE, scrollbar_info[i].type,
2303 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2304 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2305 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2306 GDI_STATE, GD_BUTTON_UNPRESSED,
2307 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
2308 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
2309 GDI_BORDER_SIZE, SC_BORDER_SIZE,
2310 GDI_EVENT_MASK, event_mask,
2311 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2315 Error(ERR_EXIT, "cannot create gadget");
2317 screen_gadget[id] = gi;
2321 void CreateScreenGadgets()
2323 CreateScreenScrollbuttons();
2324 CreateScreenScrollbars();
2327 void MapChooseLevelGadgets()
2329 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
2332 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
2335 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2336 MapGadget(screen_gadget[i]);
2339 void UnmapChooseLevelGadgets()
2343 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2344 UnmapGadget(screen_gadget[i]);
2347 static void HandleScreenGadgets(struct GadgetInfo *gi)
2349 int id = gi->custom_id;
2351 if (game_status != CHOOSELEVEL)
2356 case SCREEN_CTRL_ID_SCROLL_UP:
2357 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
2360 case SCREEN_CTRL_ID_SCROLL_DOWN:
2361 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
2364 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
2365 HandleChooseLevel(0,0, 999,gi->event.item_position, MB_MENU_INITIALIZE);