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
31 /* for DrawSetupScreen(), HandleSetupScreen() */
32 #define SETUP_SCREEN_POS_START 0
33 #define SETUP_SCREEN_POS_END (SCR_FIELDY - 3)
34 #define SETUP_SCREEN_POS_EMPTY1 (SETUP_SCREEN_POS_END - 2)
35 #define SETUP_SCREEN_POS_EMPTY2 (SETUP_SCREEN_POS_END - 2)
37 /* for HandleSetupInputScreen() */
38 #define SETUPINPUT_SCREEN_POS_START 0
39 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
40 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
41 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
43 /* for HandleChooseLevel() */
44 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
45 #define MENU_SCREEN_START_YPOS 2
46 #define MENU_SCREEN_VALUE_XPOS 14
48 /* buttons and scrollbars identifiers */
49 #define SCREEN_CTRL_ID_SCROLL_UP 0
50 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
51 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
53 #define NUM_SCREEN_SCROLLBUTTONS 2
54 #define NUM_SCREEN_SCROLLBARS 1
55 #define NUM_SCREEN_GADGETS 3
57 /* forward declaration for internal use */
58 static void HandleScreenGadgets(struct GadgetInfo *);
60 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
62 static void drawCursorExt(int pos, int color, int graphic)
64 static int cursor_array[SCR_FIELDY];
67 cursor_array[pos] = graphic;
69 graphic = cursor_array[pos];
72 graphic = (graphic == GFX_ARROW_BLUE_LEFT ? GFX_ARROW_RED_LEFT :
73 graphic == GFX_ARROW_BLUE_RIGHT ? GFX_ARROW_RED_RIGHT :
76 DrawGraphic(0, MENU_SCREEN_START_YPOS + pos, graphic);
79 static void initCursor(int pos, int graphic)
81 drawCursorExt(pos, FC_BLUE, graphic);
84 static void drawCursor(int pos, int color)
86 drawCursorExt(pos, color, 0);
91 int x = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * FONT1_XSIZE) / 2;
93 DrawText(x, SY + 8, PROGRAM_TITLE_STRING, FS_BIG, FC_YELLOW);
94 DrawTextFCentered(46, FC_RED, WINDOW_SUBTITLE_STRING);
97 static void ToggleFullscreenIfNeeded()
99 if (setup.fullscreen != video.fullscreen_enabled)
101 /* save old door content */
102 BlitBitmap(backbuffer, pix[PIX_DB_DOOR],
103 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
105 /* toggle fullscreen */
106 ChangeVideoModeIfNeeded(setup.fullscreen);
107 setup.fullscreen = video.fullscreen_enabled;
109 /* redraw background to newly created backbuffer */
110 BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
112 /* restore old door content */
113 BlitBitmap(pix[PIX_DB_DOOR], backbuffer,
114 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
116 redraw_mask = REDRAW_ALL;
122 static struct LevelDirInfo *leveldir_last_valid = NULL;
124 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
128 KeyboardAutoRepeatOn();
129 ActivateJoystickIfAvailable();
131 /* needed if last screen was the playing screen, invoked from level editor */
132 if (level_editor_test_game)
134 game_status = LEVELED;
139 /* needed if last screen was the editor screen */
140 UndrawSpecialEditorDoor();
142 /* needed if last screen was the setup screen and fullscreen state changed */
143 ToggleFullscreenIfNeeded();
146 SetDrawtoField(DRAW_BACKBUFFER);
149 /* map gadgets for main menu screen */
152 /* leveldir_current may be invalid (level group, parent link) */
153 if (!validLevelSeries(leveldir_current))
154 leveldir_current = getFirstValidLevelSeries(leveldir_last_valid);
156 /* store valid level series information */
157 leveldir_last_valid = leveldir_current;
159 /* level_nr may have been set to value over handicap with level editor */
160 if (setup.handicap && level_nr > leveldir_current->handicap_level)
161 level_nr = leveldir_current->handicap_level;
168 DrawText(SX + 32, SY + 2*32, name_text, FS_BIG, FC_GREEN);
169 DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
170 DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
171 DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
172 (leveldir_current->readonly ? FC_RED : FC_YELLOW));
173 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
174 DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
175 DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
176 DrawText(SX + 32, SY + 7*32, "Start Game", FS_BIG, FC_GREEN);
177 DrawText(SX + 32, SY + 8*32, "Setup", FS_BIG, FC_GREEN);
178 DrawText(SX + 32, SY + 9*32, "Quit", FS_BIG, FC_GREEN);
180 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
182 DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
183 leveldir_current->first_level,
184 leveldir_current->last_level);
186 if (leveldir_current->readonly)
188 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
189 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
193 initCursor(i, (i == 1 || i == 6 ? GFX_ARROW_BLUE_RIGHT : GFX_KUGEL_BLAU));
195 DrawGraphic(10, 3, GFX_ARROW_BLUE_LEFT);
196 DrawGraphic(14, 3, GFX_ARROW_BLUE_RIGHT);
198 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
201 if (leveldir_current->name)
203 int len = strlen(leveldir_current->name);
204 int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
205 int lypos = SY + 352;
207 DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
212 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
215 if (TAPE_IS_EMPTY(tape))
217 DrawCompleteVideoDisplay();
219 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
227 static void gotoTopLevelDir()
229 /* move upwards to top level directory */
230 while (leveldir_current->node_parent)
232 /* write a "path" into level tree for easy navigation to last level */
233 if (leveldir_current->node_parent->node_group->cl_first == -1)
235 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
236 int leveldir_pos = posLevelDirInfo(leveldir_current);
237 int num_page_entries;
238 int cl_first, cl_cursor;
240 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
241 num_page_entries = num_leveldirs;
243 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
245 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
246 cl_cursor = leveldir_pos - cl_first;
248 leveldir_current->node_parent->node_group->cl_first = cl_first;
249 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
252 leveldir_current = leveldir_current->node_parent;
256 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
258 static int choice = 0;
262 if (button == MB_MENU_INITIALIZE)
264 drawCursor(choice, FC_RED);
268 if (mx || my) /* mouse input */
271 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
273 else if (dx || dy) /* keyboard input */
275 if (dx && choice == 1)
276 x = (dx < 0 ? 10 : 14);
281 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
282 (x == 14 && level_nr < leveldir_current->last_level)) &&
285 static unsigned long level_delay = 0;
286 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
287 int new_level_nr, old_level_nr = level_nr;
288 int font_color = (leveldir_current->readonly ? FC_RED : FC_YELLOW);
290 new_level_nr = level_nr + (x == 10 ? -step : +step);
291 if (new_level_nr < leveldir_current->first_level)
292 new_level_nr = leveldir_current->first_level;
293 if (new_level_nr > leveldir_current->last_level)
294 new_level_nr = leveldir_current->last_level;
296 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
297 new_level_nr = leveldir_current->handicap_level;
299 if (old_level_nr == new_level_nr ||
300 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
303 level_nr = new_level_nr;
305 DrawTextExt(drawto, SX + 11 * 32, SY + 3 * 32,
306 int2str(level_nr, 3), FS_BIG, font_color);
307 DrawTextExt(window, SX + 11 * 32, SY + 3 * 32,
308 int2str(level_nr, 3), FS_BIG, font_color);
311 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
315 DrawCompleteVideoDisplay();
317 /* needed because DrawMicroLevel() takes some time */
320 DelayReached(&level_delay, 0); /* reset delay counter */
322 else if (x == 0 && y >= 0 && y <= 7)
328 drawCursor(y, FC_RED);
329 drawCursor(choice, FC_BLUE);
337 game_status = TYPENAME;
338 HandleTypeName(strlen(setup.player_name), 0);
344 game_status = CHOOSELEVEL;
345 SaveLevelSetup_LastSeries();
346 SaveLevelSetup_SeriesInfo();
355 game_status = HALLOFFAME;
360 if (leveldir_current->readonly &&
361 strcmp(setup.player_name, "Artsoft") != 0)
362 Request("This level is read only !", REQ_CONFIRM);
363 game_status = LEVELED;
368 game_status = HELPSCREEN;
373 if (setup.autorecord)
374 TapeStartRecording();
376 #if defined(PLATFORM_UNIX)
378 SendToServer_StartPlaying();
382 game_status = PLAYING;
394 SaveLevelSetup_LastSeries();
395 SaveLevelSetup_SeriesInfo();
396 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
397 game_status = EXITGAME;
406 if (game_status == MAINMENU)
408 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
414 #define MAX_HELPSCREEN_ELS 10
418 static long helpscreen_state;
419 static int helpscreen_step[MAX_HELPSCREEN_ELS];
420 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
421 static int helpscreen_delay[MAX_HELPSCREEN_ELS];
422 static int helpscreen_action[] =
424 GFX_SPIELER1_DOWN,4,2,
426 GFX_SPIELER1_LEFT,4,2,
427 GFX_SPIELER1_RIGHT,4,2,
428 GFX_SPIELER1_PUSH_LEFT,4,2,
429 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
430 GFX_ERDREICH,1,100, HA_NEXT,
431 GFX_LEERRAUM,1,100, HA_NEXT,
432 GFX_MORAST_LEER,1,100, HA_NEXT,
433 GFX_BETON,1,100, HA_NEXT,
434 GFX_MAUERWERK,1,100, HA_NEXT,
435 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
436 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
437 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
438 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
439 GFX_UNSICHTBAR,1,100, HA_NEXT,
440 GFX_FELSBODEN,1,100, HA_NEXT,
441 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
442 GFX_EDELSTEIN,2,5, HA_NEXT,
443 GFX_DIAMANT,2,5, HA_NEXT,
444 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
445 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
446 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
447 GFX_FELSBROCKEN,4,5, HA_NEXT,
448 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
449 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
450 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
451 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
452 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
453 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
454 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
455 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
456 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
457 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
458 GFX_GEBLUBBER,4,4, HA_NEXT,
459 GFX_SCHLUESSEL1,4,25, HA_NEXT,
460 GFX_PFORTE1,4,25, HA_NEXT,
461 GFX_PFORTE1X,4,25, HA_NEXT,
462 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
463 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
464 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
465 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
466 GFX_LEERRAUM,1,10, HA_NEXT,
467 GFX_DYNABOMB_NR,1,100, HA_NEXT,
468 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
469 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
470 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
471 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
472 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
473 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
474 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
475 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
476 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
477 GFX_BUTTERFLY,2,2, HA_NEXT,
478 GFX_FIREFLY,2,2, HA_NEXT,
479 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
480 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
481 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
482 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
483 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
484 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
485 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
486 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
487 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
488 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
492 GFX_MOLE_RIGHT,4,2, HA_NEXT,
493 GFX_PINGUIN_DOWN,4,2,
495 GFX_PINGUIN_LEFT,4,2,
496 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
497 GFX_SCHWEIN_DOWN,4,2,
499 GFX_SCHWEIN_LEFT,4,2,
500 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
504 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
505 GFX_SONDE_START,8,1, HA_NEXT,
506 GFX_ABLENK,4,1, HA_NEXT,
507 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
508 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
509 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
510 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
511 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
512 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
513 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
514 GFX_DIAMANT,1,10, HA_NEXT,
515 GFX_LIFE,1,100, HA_NEXT,
516 GFX_LIFE_ASYNC,1,100, HA_NEXT,
517 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
518 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
519 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
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_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
523 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
524 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
525 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
526 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
527 GFX_SPEED_PILL,1,100, HA_NEXT,
530 static char *helpscreen_eltext[][2] =
532 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
533 {"Normal sand:", "You can dig through it"},
534 {"Empty field:", "You can walk through it"},
535 {"Quicksand: You cannot pass it,", "but rocks can fall though it"},
536 {"Massive Wall:", "Nothing can go through it"},
537 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
538 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
539 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
540 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
541 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
542 {"Emerald: You must collect enough of","them to finish a level"},
543 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
544 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
545 {"Colorful Gems:", "Seem to behave like Emeralds"},
546 {"Rock: Smashes several things;", "Can be moved by the player"},
547 {"Bomb: You can move it, but be", "careful when dropping it"},
548 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
549 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
550 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
551 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
552 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
553 {"Acid: Things that fall in are gone", "forever (including our hero)"},
554 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
555 {"Door: Can be opened by the key", "with the same color"},
556 {"Door: You have to find out the", "right color of the key for it"},
557 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
558 {"Dynamite: This one explodes after", "a few seconds"},
559 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
560 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
561 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
562 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
563 {"Bug: Moves at the right side", "of walls; don't touch it!"},
564 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
565 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
566 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
567 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
568 {"Cruncher (BD style):", "Eats almost everything"},
569 {"Robot: Tries to kill the player", ""},
570 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
571 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
572 {"The Pig: Harmless, but eats all", "gems it can get"},
573 {"The Dragon: Breathes fire,", "especially to some monsters"},
574 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
575 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
576 {"Light Bulb: All of them must be", "switched on to finish a level"},
577 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
578 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
579 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
580 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
581 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
582 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
583 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
584 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
585 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
586 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
587 {"Exit door: Opens if you have enough","emeralds to finish the level"},
588 {"Open exit door: Enter here to leave","the level and exit the actual game"},
589 {"Sokoban element: Object which must", "be pushed to an empty field"},
590 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
591 {"Sokoban element: Field with object", "which can be pushed away"},
592 {"Speed pill: Lets the player run", "twice as fast as normally"},
594 static int num_helpscreen_els = sizeof(helpscreen_eltext)/(2*sizeof(char *));
596 static char *helpscreen_music[][3] =
598 { "Alchemy", "Ian Boddy", "Drive" },
599 { "The Chase", "Propaganda", "A Secret Wish" },
600 { "Network 23", "Tangerine Dream", "Exit" },
601 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
602 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
603 { "Voyager", "The Alan Parsons Project","Pyramid" },
604 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
606 static int num_helpscreen_music = 7;
607 static int helpscreen_musicpos;
609 void DrawHelpScreenElAction(int start)
613 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
615 while(helpscreen_action[j] != HA_END)
617 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
619 else if (i<start || helpscreen_delay[i-start])
621 if (i>=start && helpscreen_delay[i-start])
622 helpscreen_delay[i-start]--;
624 while(helpscreen_action[j] != HA_NEXT)
631 j += 3*helpscreen_step[i-start];
632 graphic = helpscreen_action[j++];
634 if (helpscreen_frame[i-start])
636 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
637 helpscreen_frame[i-start]--;
642 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
645 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
647 if (helpscreen_action[j] == HA_NEXT)
649 if (!helpscreen_frame[i-start])
650 helpscreen_step[i-start] = 0;
654 if (!helpscreen_frame[i-start])
655 helpscreen_step[i-start]++;
656 while(helpscreen_action[j] != HA_NEXT)
661 DrawGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
672 void DrawHelpScreenElText(int start)
675 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
676 int ybottom = SYSIZE - 20;
681 DrawTextFCentered(100, FC_GREEN, "The game elements:");
683 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
686 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
687 helpscreen_eltext[i][0], FS_SMALL, FC_YELLOW);
688 DrawText(xstart, ystart + (i - start) * ystep + 16,
689 helpscreen_eltext[i][1], FS_SMALL, FC_YELLOW);
692 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
695 void DrawHelpScreenMusicText(int num)
697 int ystart = 150, ystep = 30;
698 int ybottom = SYSIZE - 20;
704 DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
706 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
708 DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
709 helpscreen_music[num][0]);
710 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
712 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
713 "%s", helpscreen_music[num][1]);
714 DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
716 DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
717 helpscreen_music[num][2]);
719 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
722 PlaySoundLoop(background_loop[num]);
726 void DrawHelpScreenCreditsText()
728 int ystart = 150, ystep = 30;
729 int ybottom = SYSIZE - 20;
735 DrawTextFCentered(100, FC_GREEN,
737 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
738 "DOS port of the game:");
739 DrawTextFCentered(ystart + 1 * ystep, FC_RED,
741 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
742 "Additional toons:");
743 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
745 DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
746 "...and many thanks to all contributors");
747 DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
750 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
753 void DrawHelpScreenContactText()
755 int ystart = 150, ystep = 30;
756 int ybottom = SYSIZE - 20;
761 DrawTextFCentered(100, FC_GREEN, "Program information:");
763 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
764 "This game is Freeware!");
765 DrawTextFCentered(ystart + 1 * ystep, FC_YELLOW,
766 "If you like it, send e-mail to:");
767 DrawTextFCentered(ystart + 2 * ystep, FC_RED,
769 DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
771 DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
773 DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
774 "Detmolder Strasse 189");
775 DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
777 DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
780 DrawTextFCentered(ystart + 7 * ystep, FC_YELLOW,
781 "If you have created new levels,");
782 DrawTextFCentered(ystart + 8 * ystep, FC_YELLOW,
783 "send them to me to include them!");
784 DrawTextFCentered(ystart + 9 * ystep, FC_YELLOW,
787 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
790 void DrawHelpScreen()
795 CloseDoor(DOOR_CLOSE_2);
797 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
798 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
799 helpscreen_musicpos = 0;
800 helpscreen_state = 0;
801 DrawHelpScreenElText(0);
802 DrawHelpScreenElAction(0);
806 PlaySoundLoop(SND_RHYTHMLOOP);
809 void HandleHelpScreen(int button)
811 static unsigned long hs_delay = 0;
812 int num_helpscreen_els_pages =
813 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
814 int button_released = !button;
819 if (helpscreen_state < num_helpscreen_els_pages - 1)
821 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
822 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
824 DrawHelpScreenElText(helpscreen_state*MAX_HELPSCREEN_ELS);
825 DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
827 else if (helpscreen_state <
828 num_helpscreen_els_pages + num_helpscreen_music - 1)
831 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
833 else if (helpscreen_state ==
834 num_helpscreen_els_pages + num_helpscreen_music - 1)
837 DrawHelpScreenCreditsText();
839 else if (helpscreen_state ==
840 num_helpscreen_els_pages + num_helpscreen_music)
843 DrawHelpScreenContactText();
849 game_status = MAINMENU;
854 if (DelayReached(&hs_delay,GAME_FRAME_DELAY * 2))
856 if (helpscreen_state<num_helpscreen_els_pages)
857 DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
865 void HandleTypeName(int newxpos, Key key)
867 static int xpos = 0, ypos = 2;
872 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
873 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
877 if (((key >= KSYM_A && key <= KSYM_Z) ||
878 (key >= KSYM_a && key <= KSYM_z)) &&
879 xpos < MAX_PLAYER_NAME_LEN)
883 if (key >= KSYM_A && key <= KSYM_Z)
884 ascii = 'A' + (char)(key - KSYM_A);
886 ascii = 'a' + (char)(key - KSYM_a);
888 setup.player_name[xpos] = ascii;
889 setup.player_name[xpos + 1] = 0;
891 DrawTextExt(drawto, SX + 6*32, SY + ypos*32,
892 setup.player_name, FS_BIG, FC_YELLOW);
893 DrawTextExt(window, SX + 6*32, SY + ypos*32,
894 setup.player_name, FS_BIG, FC_YELLOW);
895 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
897 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
900 setup.player_name[xpos] = 0;
901 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
902 DrawGraphic(xpos + 7, ypos, GFX_LEERRAUM);
904 else if (key == KSYM_Return && xpos > 0)
906 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_RED);
907 DrawGraphic(xpos + 6, ypos, GFX_LEERRAUM);
910 game_status = MAINMENU;
916 void DrawChooseLevel()
919 CloseDoor(DOOR_CLOSE_2);
922 HandleChooseLevel(0,0, 0,0, MB_MENU_INITIALIZE);
923 MapChooseLevelGadgets();
929 static void AdjustChooseLevelScrollbar(int id, int first_entry)
931 struct GadgetInfo *gi = screen_gadget[id];
932 int items_max, items_visible, item_position;
934 items_max = numLevelDirInfoInGroup(leveldir_current);
935 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
936 item_position = first_entry;
938 if (item_position > items_max - items_visible)
939 item_position = items_max - items_visible;
941 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
942 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
945 static void drawChooseLevelList(int first_entry, int num_page_entries)
948 char buffer[SCR_FIELDX * 2];
949 int max_buffer_len = (SCR_FIELDX - 2) * 2;
950 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
952 ClearRectangle(backbuffer, SX, SY, SXSIZE - 32, SYSIZE);
953 redraw_mask |= REDRAW_FIELD;
955 DrawText(SX, SY, "Level Directories", FS_BIG, FC_GREEN);
957 for(i=0; i<num_page_entries; i++)
959 struct LevelDirInfo *node, *node_first;
960 int leveldir_pos = first_entry + i;
961 int ypos = MENU_SCREEN_START_YPOS + i;
963 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
964 node = getLevelDirInfoFromPos(node_first, leveldir_pos);
966 strncpy(buffer, node->name , max_buffer_len);
967 buffer[max_buffer_len] = '\0';
969 DrawText(SX + 32, SY + ypos * 32, buffer, FS_MEDIUM, node->color);
971 if (node->parent_link)
972 initCursor(i, GFX_ARROW_BLUE_LEFT);
973 else if (node->level_group)
974 initCursor(i, GFX_ARROW_BLUE_RIGHT);
976 initCursor(i, GFX_KUGEL_BLAU);
980 DrawGraphic(0, 1, GFX_ARROW_BLUE_UP);
982 if (first_entry + num_page_entries < num_leveldirs)
983 DrawGraphic(0, MAX_MENU_ENTRIES_ON_SCREEN + 1, GFX_ARROW_BLUE_DOWN);
986 static void drawChooseLevelInfo(int leveldir_pos)
988 struct LevelDirInfo *node, *node_first;
989 int x, last_redraw_mask = redraw_mask;
991 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
992 node = getLevelDirInfoFromPos(node_first, leveldir_pos);
994 ClearRectangle(drawto, SX + 32, SY + 32, SXSIZE - 64, 32);
996 if (node->parent_link)
997 DrawTextFCentered(40, FC_RED, "leave group \"%s\"", node->class_desc);
998 else if (node->level_group)
999 DrawTextFCentered(40, FC_RED, "enter group \"%s\"", node->class_desc);
1001 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
1002 node->levels, node->class_desc);
1004 /* let BackToFront() redraw only what is needed */
1005 redraw_mask = last_redraw_mask | REDRAW_TILES;
1006 for (x=0; x<SCR_FIELDX; x++)
1007 MarkTileDirty(x, 1);
1010 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1012 static unsigned long choose_delay = 0;
1014 int y = leveldir_current->cl_cursor;
1015 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1016 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
1017 int num_page_entries;
1019 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
1020 num_page_entries = num_leveldirs;
1022 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1024 if (button == MB_MENU_INITIALIZE)
1026 int leveldir_pos = posLevelDirInfo(leveldir_current);
1028 if (leveldir_current->cl_first == -1)
1030 leveldir_current->cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1031 leveldir_current->cl_cursor =
1032 leveldir_pos - leveldir_current->cl_first;
1035 if (dx == 999) /* first entry is set by scrollbar position */
1036 leveldir_current->cl_first = dy;
1038 AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1039 leveldir_current->cl_first);
1041 drawChooseLevelList(leveldir_current->cl_first, num_page_entries);
1042 drawChooseLevelInfo(leveldir_current->cl_first +
1043 leveldir_current->cl_cursor);
1044 drawCursor(leveldir_current->cl_cursor, FC_RED);
1047 else if (button == MB_MENU_LEAVE)
1049 if (leveldir_current->node_parent)
1051 leveldir_current = leveldir_current->node_parent;
1056 game_status = MAINMENU;
1062 if (mx || my) /* mouse input */
1065 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1067 else if (dx || dy) /* keyboard input */
1070 y = leveldir_current->cl_cursor + dy;
1072 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1075 step = num_page_entries - 1;
1076 y = (dy < 0 ? -1 : num_page_entries);
1080 if (x == 0 && y == -1)
1082 if (leveldir_current->cl_first > 0 &&
1083 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1085 leveldir_current->cl_first -= step;
1086 if (leveldir_current->cl_first < 0)
1087 leveldir_current->cl_first = 0;
1089 drawChooseLevelList(leveldir_current->cl_first, num_page_entries);
1090 drawChooseLevelInfo(leveldir_current->cl_first +
1091 leveldir_current->cl_cursor);
1092 drawCursor(leveldir_current->cl_cursor, FC_RED);
1093 AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1094 leveldir_current->cl_first);
1098 else if (x == 0 && y > num_page_entries - 1)
1100 if (leveldir_current->cl_first + num_page_entries < num_leveldirs &&
1101 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1103 leveldir_current->cl_first += step;
1104 if (leveldir_current->cl_first + num_page_entries > num_leveldirs)
1105 leveldir_current->cl_first = MAX(0, num_leveldirs - num_page_entries);
1107 drawChooseLevelList(leveldir_current->cl_first, num_page_entries);
1108 drawChooseLevelInfo(leveldir_current->cl_first +
1109 leveldir_current->cl_cursor);
1110 drawCursor(leveldir_current->cl_cursor, FC_RED);
1111 AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1112 leveldir_current->cl_first);
1119 struct LevelDirInfo *node_first, *node_cursor;
1120 int leveldir_pos = leveldir_current->cl_first + y;
1122 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
1123 node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos);
1125 if (node_cursor->node_group)
1127 node_cursor->cl_first = leveldir_current->cl_first;
1128 node_cursor->cl_cursor = leveldir_current->cl_cursor;
1129 leveldir_current = node_cursor->node_group;
1134 else if (dx == -1 && leveldir_current->node_parent)
1136 leveldir_current = leveldir_current->node_parent;
1141 if (x == 0 && y >= 0 && y < num_page_entries)
1145 if (y != leveldir_current->cl_cursor)
1147 drawCursor(y, FC_RED);
1148 drawCursor(leveldir_current->cl_cursor, FC_BLUE);
1149 drawChooseLevelInfo(leveldir_current->cl_first + y);
1150 leveldir_current->cl_cursor = y;
1155 struct LevelDirInfo *node_first, *node_cursor;
1156 int leveldir_pos = leveldir_current->cl_first + y;
1158 node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
1159 node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos);
1161 if (node_cursor->node_group)
1163 node_cursor->cl_first = leveldir_current->cl_first;
1164 node_cursor->cl_cursor = leveldir_current->cl_cursor;
1165 leveldir_current = node_cursor->node_group;
1169 else if (node_cursor->parent_link)
1171 leveldir_current = node_cursor->node_parent;
1177 node_cursor->cl_first = leveldir_current->cl_first;
1178 node_cursor->cl_cursor = leveldir_current->cl_cursor;
1179 leveldir_current = node_cursor;
1181 LoadLevelSetup_SeriesInfo();
1183 SaveLevelSetup_LastSeries();
1184 SaveLevelSetup_SeriesInfo();
1187 game_status = MAINMENU;
1195 if (game_status == CHOOSELEVEL)
1199 void DrawHallOfFame(int highlight_position)
1203 CloseDoor(DOOR_CLOSE_2);
1205 if (highlight_position < 0)
1206 LoadScore(level_nr);
1210 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1211 PlaySound(SND_HALLOFFAME);
1214 static void drawHallOfFameList(int first_entry, int highlight_position)
1219 DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1220 DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1222 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1224 int entry = first_entry + i;
1225 int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1228 DrawText(SX, SY + 64 + i * 32, ".................", FS_BIG, color);
1229 DrawText(SX, SY + 64 + i * 32, highscore[i].Name, FS_BIG, color);
1230 DrawText(SX + 12 * 32, SY + 64 + i * 32,
1231 int2str(highscore[i].Score, 5), FS_BIG, color);
1233 DrawText(SX, SY + 64 + i * 32, "..................................",
1234 FS_MEDIUM, FC_YELLOW);
1235 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1236 FS_MEDIUM, FC_YELLOW);
1237 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name, FS_BIG, color);
1238 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1239 int2str(highscore[entry].Score, 5), FS_MEDIUM, color);
1244 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1246 static int first_entry = 0;
1247 static int highlight_position = 0;
1248 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1249 int button_released = !button;
1251 if (button == MB_MENU_INITIALIZE)
1254 highlight_position = mx;
1255 drawHallOfFameList(first_entry, highlight_position);
1259 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1260 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1264 if (first_entry > 0)
1266 first_entry -= step;
1267 if (first_entry < 0)
1270 drawHallOfFameList(first_entry, highlight_position);
1276 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1278 first_entry += step;
1279 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1280 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1282 drawHallOfFameList(first_entry, highlight_position);
1287 if (button_released)
1289 FadeSound(SND_HALLOFFAME);
1290 game_status = MAINMENU;
1296 if (game_status == HALLOFFAME)
1301 /* ========================================================================= */
1302 /* setup screen functions */
1303 /* ========================================================================= */
1305 static struct TokenInfo *setup_info;
1306 static int num_setup_info;
1307 static int setup_mode = SETUP_MODE_MAIN;
1309 static void execSetupInput()
1311 setup_mode = SETUP_MODE_INPUT;
1312 DrawSetupInputScreen();
1315 static void execExitSetup()
1317 game_status = MAINMENU;
1321 static void execSaveAndExitSetup()
1327 static struct TokenInfo setup_main_info[] =
1329 { TYPE_SWITCH, &setup.sound, "Sound:", },
1330 { TYPE_SWITCH, &setup.sound_loops, " Sound Loops:" },
1331 { TYPE_SWITCH, &setup.sound_music, " Game Music:" },
1333 { TYPE_SWITCH, &setup.toons, "Toons:" },
1334 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1336 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1337 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1339 { TYPE_SWITCH, &setup.fading, "Fading:" },
1341 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1342 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1343 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1344 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1345 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1346 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1347 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1348 { TYPE_EMPTY, NULL, "" },
1349 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1350 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and exit" },
1354 static void drawSetupValue(int pos)
1356 int xpos = MENU_SCREEN_VALUE_XPOS;
1357 int ypos = MENU_SCREEN_START_YPOS + pos;
1358 int value_color = FC_YELLOW;
1359 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1360 setup_info[pos].value);
1362 if (setup_info[pos].type & TYPE_SWITCH ||
1363 setup_info[pos].type & TYPE_YES_NO)
1365 boolean value = *(boolean *)(setup_info[pos].value);
1366 int value_length = 3;
1369 value_color = FC_BLUE;
1371 if (strlen(value_string) < value_length)
1372 strcat(value_string, " ");
1375 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, FS_BIG, value_color);
1378 static void DrawSetupMainScreen()
1383 CloseDoor(DOOR_CLOSE_2);
1386 DrawText(SX + 16, SY + 16, "SETUP",FS_BIG,FC_YELLOW);
1387 setup_info = setup_main_info;
1390 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1392 void *value_ptr = setup_info[i].value;
1393 int ypos = MENU_SCREEN_START_YPOS + i;
1395 /* set some entries to "unchangeable" according to other variables */
1396 if ((value_ptr == &setup.sound && !audio.sound_available) ||
1397 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
1398 (value_ptr == &setup.sound_music && !audio.music_available) ||
1399 (value_ptr == &setup.sound_music && !audio.music_available) ||
1400 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
1401 setup_info[i].type |= TYPE_GHOSTED;
1403 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, FS_BIG, FC_GREEN);
1405 if (setup_info[i].type & TYPE_ENTER_MENU)
1406 initCursor(i, GFX_ARROW_BLUE_RIGHT);
1407 else if (setup_info[i].type & TYPE_LEAVE_MENU)
1408 initCursor(i, GFX_ARROW_BLUE_LEFT);
1409 else if (setup_info[i].type != TYPE_EMPTY)
1410 initCursor(i, GFX_KUGEL_BLAU);
1412 if (setup_info[i].type & TYPE_BOOLEAN_STYLE)
1420 HandleSetupScreen(0,0,0,0,MB_MENU_INITIALIZE);
1423 void HandleSetupMainScreen(int mx, int my, int dx, int dy, int button)
1425 static int choice = 0;
1429 if (button == MB_MENU_INITIALIZE)
1431 drawCursor(choice, FC_RED);
1434 else if (button == MB_MENU_LEAVE)
1436 for (y=0; y<num_setup_info; y++)
1438 if (setup_info[y].type & TYPE_LEAVE_MENU)
1440 void (*menu_callback_function)(void) = setup_info[y].value;
1442 menu_callback_function();
1448 if (mx || my) /* mouse input */
1451 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1453 else if (dx || dy) /* keyboard input */
1457 int type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
1459 if (!(setup_info[choice].type & TYPE_ENTER_OR_LEAVE_MENU) ||
1460 setup_info[choice].type == type)
1461 button = MB_MENU_CHOICE;
1466 /* jump to next non-empty menu entry (up or down) */
1467 while (y > 0 && y < num_setup_info - 1 &&
1468 setup_info[y].type == TYPE_EMPTY)
1472 if (x == 0 && y >= 0 && y < num_setup_info &&
1473 setup_info[y].type != TYPE_EMPTY)
1479 drawCursor(y, FC_RED);
1480 drawCursor(choice, FC_BLUE);
1484 else if (!(setup_info[y].type & TYPE_GHOSTED))
1486 if (setup_info[y].type & TYPE_BOOLEAN_STYLE)
1488 boolean new_value = !*(boolean *)(setup_info[y].value);
1490 *(boolean *)setup_info[y].value = new_value;
1493 else if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
1495 void (*menu_callback_function)(void) = setup_info[choice].value;
1497 menu_callback_function();
1504 if (game_status == SETUP)
1508 void DrawSetupInputScreen()
1511 DrawText(SX+16, SY+16, "SETUP INPUT", FS_BIG, FC_YELLOW);
1513 initCursor(0, GFX_KUGEL_BLAU);
1514 initCursor(1, GFX_KUGEL_BLAU);
1515 initCursor(2, GFX_ARROW_BLUE_RIGHT);
1516 initCursor(13, GFX_ARROW_BLUE_LEFT);
1518 DrawGraphic(10, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_LEFT);
1519 DrawGraphic(12, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_RIGHT);
1521 DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
1522 DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
1523 DrawText(SX+32, SY+15*32, "Exit", FS_BIG, FC_GREEN);
1525 DeactivateJoystickForCalibration();
1526 DrawTextFCentered(SYSIZE - 20, FC_BLUE,
1527 "Joysticks deactivated on this screen");
1529 HandleSetupInputScreen(0,0, 0,0, MB_MENU_INITIALIZE);
1534 static void setJoystickDeviceToNr(char *device_name, int device_nr)
1536 if (device_name == NULL)
1539 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
1542 if (strlen(device_name) > 1)
1544 char c1 = device_name[strlen(device_name) - 1];
1545 char c2 = device_name[strlen(device_name) - 2];
1547 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
1548 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
1551 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
1552 strlen(device_name));
1555 static void drawPlayerSetupInputInfo(int player_nr)
1558 static struct SetupKeyboardInfo custom_key;
1565 { &custom_key.left, "Joystick Left" },
1566 { &custom_key.right, "Joystick Right" },
1567 { &custom_key.up, "Joystick Up" },
1568 { &custom_key.down, "Joystick Down" },
1569 { &custom_key.snap, "Button 1" },
1570 { &custom_key.bomb, "Button 2" }
1572 static char *joystick_name[MAX_PLAYERS] =
1580 custom_key = setup.input[player_nr].key;
1582 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
1583 DrawGraphic(8, 2, GFX_SPIELER1 + player_nr);
1585 if (setup.input[player_nr].use_joystick)
1587 char *device_name = setup.input[player_nr].joy.device_name;
1589 DrawText(SX+8*32, SY+3*32,
1590 joystick_name[getJoystickNrFromDeviceName(device_name)],
1592 DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
1596 DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
1597 DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
1600 DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
1601 DrawGraphic(1, 6, GFX_ARROW_BLUE_LEFT);
1602 DrawGraphic(1, 7, GFX_ARROW_BLUE_RIGHT);
1603 DrawGraphic(1, 8, GFX_ARROW_BLUE_UP);
1604 DrawGraphic(1, 9, GFX_ARROW_BLUE_DOWN);
1605 DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
1606 DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
1607 DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
1608 DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
1609 DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
1610 DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
1614 int ypos = 6 + i + (i > 3 ? i-3 : 0);
1616 DrawText(SX + 3*32, SY + ypos*32,
1617 " ", FS_BIG, FC_YELLOW);
1618 DrawText(SX + 3*32, SY + ypos*32,
1619 (setup.input[player_nr].use_joystick ?
1621 getKeyNameFromKey(*custom[i].key)),
1626 void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button)
1628 static int choice = 0;
1629 static int player_nr = 0;
1632 int pos_start = SETUPINPUT_SCREEN_POS_START;
1633 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
1634 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
1635 int pos_end = SETUPINPUT_SCREEN_POS_END;
1637 if (button == MB_MENU_INITIALIZE)
1639 drawPlayerSetupInputInfo(player_nr);
1640 drawCursor(choice, FC_RED);
1643 else if (button == MB_MENU_LEAVE)
1645 setup_mode = SETUP_MODE_MAIN;
1650 if (mx || my) /* mouse input */
1653 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1655 else if (dx || dy) /* keyboard input */
1657 if (dx && choice == 0)
1658 x = (dx < 0 ? 10 : 12);
1659 else if ((dx && choice == 1) ||
1660 (dx == +1 && choice == 2) ||
1661 (dx == -1 && choice == pos_end))
1662 button = MB_MENU_CHOICE;
1666 if (y >= pos_empty1 && y <= pos_empty2)
1667 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
1670 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
1672 static unsigned long delay = 0;
1674 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
1677 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
1679 drawPlayerSetupInputInfo(player_nr);
1681 else if (x == 0 && y >= pos_start && y <= pos_end &&
1682 !(y >= pos_empty1 && y <= pos_empty2))
1688 drawCursor(y, FC_RED);
1689 drawCursor(choice, FC_BLUE);
1697 char *device_name = setup.input[player_nr].joy.device_name;
1699 if (!setup.input[player_nr].use_joystick)
1701 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
1703 setJoystickDeviceToNr(device_name, new_device_nr);
1704 setup.input[player_nr].use_joystick = TRUE;
1708 int device_nr = getJoystickNrFromDeviceName(device_name);
1709 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
1711 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
1712 setup.input[player_nr].use_joystick = FALSE;
1714 setJoystickDeviceToNr(device_name, new_device_nr);
1717 drawPlayerSetupInputInfo(player_nr);
1721 if (setup.input[player_nr].use_joystick)
1724 CalibrateJoystick(player_nr);
1727 CustomizeKeyboard(player_nr);
1729 else if (y == pos_end)
1733 setup_mode = SETUP_MODE_MAIN;
1743 if (game_status == SETUP)
1747 void DrawSetupScreen()
1749 if (setup_mode == SETUP_MODE_MAIN)
1750 DrawSetupMainScreen();
1751 else if (setup_mode == SETUP_MODE_INPUT)
1752 DrawSetupInputScreen();
1755 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
1757 if (setup_mode == SETUP_MODE_MAIN)
1758 HandleSetupMainScreen(mx, my, dx, dy, button);
1759 else if (setup_mode == SETUP_MODE_INPUT)
1760 HandleSetupInputScreen(mx, my, dx, dy, button);
1763 void CustomizeKeyboard(int player_nr)
1767 boolean finished = FALSE;
1768 static struct SetupKeyboardInfo custom_key;
1773 } customize_step[] =
1775 { &custom_key.left, "Move Left" },
1776 { &custom_key.right, "Move Right" },
1777 { &custom_key.up, "Move Up" },
1778 { &custom_key.down, "Move Down" },
1779 { &custom_key.snap, "Snap Field" },
1780 { &custom_key.bomb, "Place Bomb" }
1783 /* read existing key bindings from player setup */
1784 custom_key = setup.input[player_nr].key;
1787 DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
1793 DrawText(SX, SY + (2+2*step_nr)*32,
1794 customize_step[step_nr].text, FS_BIG, FC_RED);
1795 DrawText(SX, SY + (2+2*step_nr+1)*32,
1796 "Key:", FS_BIG, FC_RED);
1797 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1798 getKeyNameFromKey(*customize_step[step_nr].key),
1803 if (PendingEvent()) /* got event */
1811 case EVENT_KEYPRESS:
1813 Key key = GetEventKey((KeyEvent *)&event, TRUE);
1815 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
1821 /* all keys configured -- wait for "Escape" or "Return" key */
1825 /* press 'Enter' to keep the existing key binding */
1826 if (key == KSYM_Return)
1827 key = *customize_step[step_nr].key;
1829 /* check if key already used */
1830 for (i=0; i<step_nr; i++)
1831 if (*customize_step[i].key == key)
1836 /* got new key binding */
1837 *customize_step[step_nr].key = key;
1838 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1839 " ", FS_BIG, FC_YELLOW);
1840 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1841 getKeyNameFromKey(key), FS_BIG, FC_YELLOW);
1844 /* un-highlight last query */
1845 DrawText(SX, SY+(2+2*(step_nr-1))*32,
1846 customize_step[step_nr-1].text, FS_BIG, FC_GREEN);
1847 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
1848 "Key:", FS_BIG, FC_GREEN);
1850 /* press 'Enter' to leave */
1853 DrawText(SX + 16, SY + 15*32+16,
1854 "Press Enter", FS_BIG, FC_YELLOW);
1858 /* query next key binding */
1859 DrawText(SX, SY+(2+2*step_nr)*32,
1860 customize_step[step_nr].text, FS_BIG, FC_RED);
1861 DrawText(SX, SY+(2+2*step_nr+1)*32,
1862 "Key:", FS_BIG, FC_RED);
1863 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
1864 getKeyNameFromKey(*customize_step[step_nr].key),
1869 case EVENT_KEYRELEASE:
1870 key_joystick_mapping = 0;
1874 HandleOtherEvents(&event);
1882 /* don't eat all CPU time */
1886 /* write new key bindings back to player setup */
1887 setup.input[player_nr].key = custom_key;
1890 DrawSetupInputScreen();
1893 static boolean CalibrateJoystickMain(int player_nr)
1895 int new_joystick_xleft = JOYSTICK_XMIDDLE;
1896 int new_joystick_xright = JOYSTICK_XMIDDLE;
1897 int new_joystick_yupper = JOYSTICK_YMIDDLE;
1898 int new_joystick_ylower = JOYSTICK_YMIDDLE;
1899 int new_joystick_xmiddle, new_joystick_ymiddle;
1901 int joystick_fd = joystick.fd[player_nr];
1902 int x, y, last_x, last_y, xpos = 8, ypos = 3;
1903 boolean check[3][3];
1904 int check_remaining = 3 * 3;
1909 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
1912 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
1921 check[x][y] = FALSE;
1922 DrawGraphic(xpos + x - 1, ypos + y - 1, GFX_KUGEL_BLAU);
1926 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
1927 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
1928 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
1929 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
1930 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FS_BIG, FC_YELLOW);
1931 DrawText(SX, SY + 12 * 32, " AND ", FS_BIG, FC_YELLOW);
1932 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
1934 joy_value = Joystick(player_nr);
1935 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
1936 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
1938 /* eventually uncalibrated center position (joystick could be uncentered) */
1939 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
1942 new_joystick_xmiddle = joy_x;
1943 new_joystick_ymiddle = joy_y;
1945 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
1948 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
1953 if (PendingEvent()) /* got event */
1961 case EVENT_KEYPRESS:
1962 switch(GetEventKey((KeyEvent *)&event, TRUE))
1965 if (check_remaining == 0)
1978 case EVENT_KEYRELEASE:
1979 key_joystick_mapping = 0;
1983 HandleOtherEvents(&event);
1988 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
1991 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
1992 new_joystick_xright = MAX(new_joystick_xright, joy_x);
1993 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
1994 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
1996 setup.input[player_nr].joy.xleft = new_joystick_xleft;
1997 setup.input[player_nr].joy.yupper = new_joystick_yupper;
1998 setup.input[player_nr].joy.xright = new_joystick_xright;
1999 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2000 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2001 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2003 CheckJoystickData();
2005 joy_value = Joystick(player_nr);
2007 if (joy_value & JOY_BUTTON && check_remaining == 0)
2010 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2011 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2013 if (x != last_x || y != last_y)
2015 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_GELB);
2016 DrawGraphic(xpos + x, ypos + y, GFX_KUGEL_ROT);
2021 if (check_remaining > 0 && !check[x+1][y+1])
2023 check[x+1][y+1] = TRUE;
2029 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2030 setup.input[player_nr].joy.xleft,
2031 setup.input[player_nr].joy.xmiddle,
2032 setup.input[player_nr].joy.xright);
2033 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2034 setup.input[player_nr].joy.yupper,
2035 setup.input[player_nr].joy.ymiddle,
2036 setup.input[player_nr].joy.ylower);
2045 /* don't eat all CPU time */
2049 /* calibrated center position (joystick should now be centered) */
2050 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2053 new_joystick_xmiddle = joy_x;
2054 new_joystick_ymiddle = joy_y;
2058 DrawSetupInputScreen();
2060 /* wait until the last pressed button was released */
2061 while (Joystick(player_nr) & JOY_BUTTON)
2063 if (PendingEvent()) /* got event */
2068 HandleOtherEvents(&event);
2077 void CalibrateJoystick(int player_nr)
2079 if (!CalibrateJoystickMain(player_nr))
2083 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
2084 DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
2086 Delay(2000); /* show error message for two seconds */
2090 void HandleGameActions()
2092 if (game_status != PLAYING)
2095 if (local_player->LevelSolved)
2098 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2106 /* ---------- new screen button stuff -------------------------------------- */
2108 /* graphic position and size values for buttons and scrollbars */
2109 #define SC_SCROLLBUTTON_XPOS 64
2110 #define SC_SCROLLBUTTON_YPOS 0
2111 #define SC_SCROLLBAR_XPOS 0
2112 #define SC_SCROLLBAR_YPOS 64
2114 #define SC_SCROLLBUTTON_XSIZE 32
2115 #define SC_SCROLLBUTTON_YSIZE 32
2117 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2118 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2119 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2120 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2121 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2122 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2123 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2124 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2126 #define SC_BORDER_SIZE 14
2134 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2137 SC_SCROLLBUTTON_XPOS + 0 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
2138 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2139 SCREEN_CTRL_ID_SCROLL_UP,
2140 "scroll level series up"
2143 SC_SCROLLBUTTON_XPOS + 1 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
2144 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2145 SCREEN_CTRL_ID_SCROLL_DOWN,
2146 "scroll level series down"
2158 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2161 SC_SCROLLBAR_XPOS, SC_SCROLLBAR_YPOS,
2162 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2163 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2164 GD_TYPE_SCROLLBAR_VERTICAL,
2165 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2166 "scroll level series vertically"
2170 static void CreateScreenScrollbuttons()
2172 Bitmap *gd_bitmap = pix[PIX_MORE];
2173 struct GadgetInfo *gi;
2174 unsigned long event_mask;
2177 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2179 int id = scrollbutton_info[i].gadget_id;
2180 int x, y, width, height;
2181 int gd_x1, gd_x2, gd_y1, gd_y2;
2183 x = scrollbutton_info[i].x;
2184 y = scrollbutton_info[i].y;
2186 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2190 width = SC_SCROLLBUTTON_XSIZE;
2191 height = SC_SCROLLBUTTON_YSIZE;
2192 gd_x1 = scrollbutton_info[i].xpos;
2193 gd_y1 = scrollbutton_info[i].ypos;
2195 gd_y2 = gd_y1 + SC_SCROLLBUTTON_YSIZE;
2197 gi = CreateGadget(GDI_CUSTOM_ID, id,
2198 GDI_CUSTOM_TYPE_ID, i,
2199 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2204 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2205 GDI_STATE, GD_BUTTON_UNPRESSED,
2206 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
2207 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
2208 GDI_EVENT_MASK, event_mask,
2209 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2213 Error(ERR_EXIT, "cannot create gadget");
2215 screen_gadget[id] = gi;
2219 static void CreateScreenScrollbars()
2223 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2225 int id = scrollbar_info[i].gadget_id;
2226 Bitmap *gd_bitmap = pix[PIX_MORE];
2227 int gd_x1, gd_x2, gd_y1, gd_y2;
2228 struct GadgetInfo *gi;
2229 int items_max, items_visible, item_position;
2230 unsigned long event_mask;
2231 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2234 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
2235 num_page_entries = num_leveldirs;
2237 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2239 items_max = MAX(num_leveldirs, num_page_entries);
2240 items_visible = num_page_entries;
2243 items_max = num_page_entries;
2244 items_visible = num_page_entries;
2248 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2250 gd_x1 = scrollbar_info[i].xpos;
2251 gd_x2 = gd_x1 + scrollbar_info[i].width;
2252 gd_y1 = scrollbar_info[i].ypos;
2253 gd_y2 = scrollbar_info[i].ypos;
2255 gi = CreateGadget(GDI_CUSTOM_ID, id,
2256 GDI_CUSTOM_TYPE_ID, i,
2257 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2258 GDI_X, scrollbar_info[i].x,
2259 GDI_Y, scrollbar_info[i].y,
2260 GDI_WIDTH, scrollbar_info[i].width,
2261 GDI_HEIGHT, scrollbar_info[i].height,
2262 GDI_TYPE, scrollbar_info[i].type,
2263 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2264 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2265 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2266 GDI_STATE, GD_BUTTON_UNPRESSED,
2267 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
2268 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
2269 GDI_BORDER_SIZE, SC_BORDER_SIZE,
2270 GDI_EVENT_MASK, event_mask,
2271 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2275 Error(ERR_EXIT, "cannot create gadget");
2277 screen_gadget[id] = gi;
2281 void CreateScreenGadgets()
2283 CreateScreenScrollbuttons();
2284 CreateScreenScrollbars();
2287 void MapChooseLevelGadgets()
2289 int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
2292 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
2295 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2296 MapGadget(screen_gadget[i]);
2299 void UnmapChooseLevelGadgets()
2303 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2304 UnmapGadget(screen_gadget[i]);
2307 static void HandleScreenGadgets(struct GadgetInfo *gi)
2309 int id = gi->custom_id;
2311 if (game_status != CHOOSELEVEL)
2316 case SCREEN_CTRL_ID_SCROLL_UP:
2317 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
2320 case SCREEN_CTRL_ID_SCROLL_DOWN:
2321 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
2324 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
2325 HandleChooseLevel(0,0, 999,gi->event.item_position, MB_MENU_INITIALIZE);