rnd-20020330-2-src
[rocksndiamonds.git] / src / screens.c
1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back!               *
3 *----------------------------------------------------------*
4 * (c) 1995-2001 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * screens.c                                                *
12 ***********************************************************/
13
14 #include "libgame/libgame.h"
15
16 #include "screens.h"
17 #include "events.h"
18 #include "game.h"
19 #include "tools.h"
20 #include "editor.h"
21 #include "files.h"
22 #include "tape.h"
23 #include "cartoons.h"
24 #include "network.h"
25 #include "init.h"
26
27 /* screens in the setup menu */
28 #define SETUP_MODE_MAIN                 0
29 #define SETUP_MODE_INPUT                1
30
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)
36
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)
42
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
47
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
52
53 #define NUM_SCREEN_SCROLLBUTTONS        2
54 #define NUM_SCREEN_SCROLLBARS           1
55 #define NUM_SCREEN_GADGETS              3
56
57 /* forward declaration for internal use */
58 static void HandleScreenGadgets(struct GadgetInfo *);
59
60 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
61
62 static void drawCursorExt(int pos, int color, int graphic)
63 {
64   static int cursor_array[SCR_FIELDY];
65
66   if (graphic)
67     cursor_array[pos] = graphic;
68
69   graphic = cursor_array[pos];
70
71   if (color == FC_RED)
72     graphic = (graphic == GFX_ARROW_BLUE_LEFT  ? GFX_ARROW_RED_LEFT  :
73                graphic == GFX_ARROW_BLUE_RIGHT ? GFX_ARROW_RED_RIGHT :
74                GFX_KUGEL_ROT);
75
76   DrawGraphic(0, MENU_SCREEN_START_YPOS + pos, graphic);
77 }
78
79 static void initCursor(int pos, int graphic)
80 {
81   drawCursorExt(pos, FC_BLUE, graphic);
82 }
83
84 static void drawCursor(int pos, int color)
85 {
86   drawCursorExt(pos, color, 0);
87 }
88
89 void DrawHeadline()
90 {
91   int x = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * FONT1_XSIZE) / 2;
92
93   DrawText(x, SY + 8, PROGRAM_TITLE_STRING, FS_BIG, FC_YELLOW);
94   DrawTextFCentered(46, FC_RED, WINDOW_SUBTITLE_STRING);
95 }
96
97 static void ToggleFullscreenIfNeeded()
98 {
99   if (setup.fullscreen != video.fullscreen_enabled)
100   {
101     /* save old door content */
102     BlitBitmap(backbuffer, pix[PIX_DB_DOOR],
103                DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
104
105     /* toggle fullscreen */
106     ChangeVideoModeIfNeeded(setup.fullscreen);
107     setup.fullscreen = video.fullscreen_enabled;
108
109     /* redraw background to newly created backbuffer */
110     BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
111
112     /* restore old door content */
113     BlitBitmap(pix[PIX_DB_DOOR], backbuffer,
114                DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
115
116     redraw_mask = REDRAW_ALL;
117   }
118 }
119
120 void DrawMainMenu()
121 {
122   static struct LevelDirInfo *leveldir_last_valid = NULL;
123   int i;
124   char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
125
126   UnmapAllGadgets();
127   FadeSounds();
128   KeyboardAutoRepeatOn();
129   ActivateJoystickIfAvailable();
130
131   /* needed if last screen was the playing screen, invoked from level editor */
132   if (level_editor_test_game)
133   {
134     game_status = LEVELED;
135     DrawLevelEd();
136     return;
137   }
138
139   /* needed if last screen was the editor screen */
140   UndrawSpecialEditorDoor();
141
142   /* needed if last screen was the setup screen and fullscreen state changed */
143   ToggleFullscreenIfNeeded();
144
145 #ifdef TARGET_SDL
146   SetDrawtoField(DRAW_BACKBUFFER);
147 #endif
148
149   /* map gadgets for main menu screen */
150   MapTapeButtons();
151
152   /* leveldir_current may be invalid (level group, parent link) */
153   if (!validLevelSeries(leveldir_current))
154     leveldir_current = getFirstValidLevelSeries(leveldir_last_valid);
155
156   /* store valid level series information */
157   leveldir_last_valid = leveldir_current;
158
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;
162
163   GetPlayerConfig();
164   LoadLevel(level_nr);
165
166   ClearWindow();
167   DrawHeadline();
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);
179
180   DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
181
182   DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
183             leveldir_current->first_level,
184             leveldir_current->last_level);
185
186   if (leveldir_current->readonly)
187   {
188     DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
189     DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
190   }
191
192   for(i=0; i<8; i++)
193     initCursor(i, (i == 1 || i == 6 ? GFX_ARROW_BLUE_RIGHT : GFX_KUGEL_BLAU));
194
195   DrawGraphic(10, 3, GFX_ARROW_BLUE_LEFT);
196   DrawGraphic(14, 3, GFX_ARROW_BLUE_RIGHT);
197
198   DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
199            FS_SMALL, FC_RED);
200
201   if (leveldir_current->name)
202   {
203     int len = strlen(leveldir_current->name);
204     int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
205     int lypos = SY + 352;
206
207     DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
208   }
209
210   FadeToFront();
211   InitAnimation();
212   HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
213
214   TapeStop();
215   if (TAPE_IS_EMPTY(tape))
216     LoadTape(level_nr);
217   DrawCompleteVideoDisplay();
218
219   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
220
221 #if 0
222   ClearEventQueue();
223 #endif
224
225 }
226
227 static void gotoTopLevelDir()
228 {
229   /* move upwards to top level directory */
230   while (leveldir_current->node_parent)
231   {
232     /* write a "path" into level tree for easy navigation to last level */
233     if (leveldir_current->node_parent->node_group->cl_first == -1)
234     {
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;
239
240       if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
241         num_page_entries = num_leveldirs;
242       else
243         num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
244
245       cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
246       cl_cursor = leveldir_pos - cl_first;
247
248       leveldir_current->node_parent->node_group->cl_first = cl_first;
249       leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
250     }
251
252     leveldir_current = leveldir_current->node_parent;
253   }
254 }
255
256 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
257 {
258   static int choice = 0;
259   int x = 0;
260   int y = choice;
261
262   if (button == MB_MENU_INITIALIZE)
263   {
264     drawCursor(choice, FC_RED);
265     return;
266   }
267
268   if (mx || my)         /* mouse input */
269   {
270     x = (mx - SX) / 32;
271     y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
272   }
273   else if (dx || dy)    /* keyboard input */
274   {
275     if (dx && choice == 1)
276       x = (dx < 0 ? 10 : 14);
277     else if (dy)
278       y = choice + dy;
279   }
280
281   if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
282                  (x == 14 && level_nr < leveldir_current->last_level)) &&
283       button)
284   {
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);
289
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;
295
296     if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
297       new_level_nr = leveldir_current->handicap_level;
298
299     if (old_level_nr == new_level_nr ||
300         !DelayReached(&level_delay, GADGET_FRAME_DELAY))
301       goto out;
302
303     level_nr = new_level_nr;
304
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);
309
310     LoadLevel(level_nr);
311     DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
312
313     TapeErase();
314     LoadTape(level_nr);
315     DrawCompleteVideoDisplay();
316
317     /* needed because DrawMicroLevel() takes some time */
318     BackToFront();
319     SyncDisplay();
320     DelayReached(&level_delay, 0);      /* reset delay counter */
321   }
322   else if (x == 0 && y >= 0 && y <= 7)
323   {
324     if (button)
325     {
326       if (y != choice)
327       {
328         drawCursor(y, FC_RED);
329         drawCursor(choice, FC_BLUE);
330         choice = y;
331       }
332     }
333     else
334     {
335       if (y == 0)
336       {
337         game_status = TYPENAME;
338         HandleTypeName(strlen(setup.player_name), 0);
339       }
340       else if (y == 1)
341       {
342         if (leveldir_first)
343         {
344           game_status = CHOOSELEVEL;
345           SaveLevelSetup_LastSeries();
346           SaveLevelSetup_SeriesInfo();
347
348           gotoTopLevelDir();
349
350           DrawChooseLevel();
351         }
352       }
353       else if (y == 2)
354       {
355         game_status = HALLOFFAME;
356         DrawHallOfFame(-1);
357       }
358       else if (y == 3)
359       {
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;
364         DrawLevelEd();
365       }
366       else if (y == 4)
367       {
368         game_status = HELPSCREEN;
369         DrawHelpScreen();
370       }
371       else if (y == 5)
372       {
373         if (setup.autorecord)
374           TapeStartRecording();
375
376 #if defined(PLATFORM_UNIX)
377         if (options.network)
378           SendToServer_StartPlaying();
379         else
380 #endif
381         {
382           game_status = PLAYING;
383           StopAnimation();
384           InitGame();
385         }
386       }
387       else if (y == 6)
388       {
389         game_status = SETUP;
390         DrawSetupScreen();
391       }
392       else if (y == 7)
393       {
394         SaveLevelSetup_LastSeries();
395         SaveLevelSetup_SeriesInfo();
396         if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
397           game_status = EXITGAME;
398       }
399     }
400   }
401
402   BackToFront();
403
404   out:
405
406   if (game_status == MAINMENU)
407   {
408     DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
409     DoAnimation();
410   }
411 }
412
413
414 #define MAX_HELPSCREEN_ELS      10
415 #define HA_NEXT                 -999
416 #define HA_END                  -1000
417
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[] =
423 {
424   GFX_SPIELER1_DOWN,4,2,
425   GFX_SPIELER1_UP,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,
489   GFX_MOLE_DOWN,4,2,
490   GFX_MOLE_UP,4,2,
491   GFX_MOLE_LEFT,4,2,
492   GFX_MOLE_RIGHT,4,2,                                           HA_NEXT,
493   GFX_PINGUIN_DOWN,4,2,
494   GFX_PINGUIN_UP,4,2,
495   GFX_PINGUIN_LEFT,4,2,
496   GFX_PINGUIN_RIGHT,4,2,                                        HA_NEXT,
497   GFX_SCHWEIN_DOWN,4,2,
498   GFX_SCHWEIN_UP,4,2,
499   GFX_SCHWEIN_LEFT,4,2,
500   GFX_SCHWEIN_RIGHT,4,2,                                        HA_NEXT,
501   GFX_DRACHE_DOWN,4,2,
502   GFX_DRACHE_UP,4,2,
503   GFX_DRACHE_LEFT,4,2,
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,
528   HA_END
529 };
530 static char *helpscreen_eltext[][2] =
531 {
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"},
593 };
594 static int num_helpscreen_els = sizeof(helpscreen_eltext)/(2*sizeof(char *));
595
596 static char *helpscreen_music[][3] =
597 {
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" }
605 };
606 static int num_helpscreen_music = 7;
607 static int helpscreen_musicpos;
608
609 void DrawHelpScreenElAction(int start)
610 {
611   int i = 0, j = 0;
612   int frame, graphic;
613   int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
614
615   while(helpscreen_action[j] != HA_END)
616   {
617     if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
618       break;
619     else if (i<start || helpscreen_delay[i-start])
620     {
621       if (i>=start && helpscreen_delay[i-start])
622         helpscreen_delay[i-start]--;
623
624       while(helpscreen_action[j] != HA_NEXT)
625         j++;
626       j++;
627       i++;
628       continue;
629     }
630
631     j += 3*helpscreen_step[i-start];
632     graphic = helpscreen_action[j++];
633
634     if (helpscreen_frame[i-start])
635     {
636       frame = helpscreen_action[j++] - helpscreen_frame[i-start];
637       helpscreen_frame[i-start]--;
638     }
639     else
640     {
641       frame = 0;
642       helpscreen_frame[i-start] = helpscreen_action[j++]-1;
643     }
644
645     helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
646
647     if (helpscreen_action[j] == HA_NEXT)
648     {
649       if (!helpscreen_frame[i-start])
650         helpscreen_step[i-start] = 0;
651     }
652     else
653     {
654       if (!helpscreen_frame[i-start])
655         helpscreen_step[i-start]++;
656       while(helpscreen_action[j] != HA_NEXT)
657         j++;
658     }
659     j++;
660
661     DrawGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
662     i++;
663   }
664
665   for(i=2;i<16;i++)
666   {
667     MarkTileDirty(0,i);
668     MarkTileDirty(1,i);
669   }
670 }
671
672 void DrawHelpScreenElText(int start)
673 {
674   int i;
675   int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
676   int ybottom = SYSIZE - 20;
677
678   ClearWindow();
679   DrawHeadline();
680
681   DrawTextFCentered(100, FC_GREEN, "The game elements:");
682
683   for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
684   {
685     DrawText(xstart,
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);
690   }
691
692   DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
693 }
694
695 void DrawHelpScreenMusicText(int num)
696 {
697   int ystart = 150, ystep = 30;
698   int ybottom = SYSIZE - 20;
699
700   FadeSounds();
701   ClearWindow();
702   DrawHeadline();
703
704   DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
705
706   DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
707                     "Excerpt from");
708   DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
709                     helpscreen_music[num][0]);
710   DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
711                     "by");
712   DrawTextFCentered(ystart + 3 * ystep, FC_RED,
713                     "%s", helpscreen_music[num][1]);
714   DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
715                     "from the album");
716   DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
717                     helpscreen_music[num][2]);
718
719   DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
720
721 #if 0
722   PlaySoundLoop(background_loop[num]);
723 #endif
724 }
725
726 void DrawHelpScreenCreditsText()
727 {
728   int ystart = 150, ystep = 30;
729   int ybottom = SYSIZE - 20;
730
731   FadeSounds();
732   ClearWindow();
733   DrawHeadline();
734
735   DrawTextFCentered(100, FC_GREEN,
736                     "Credits:");
737   DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
738                     "DOS port of the game:");
739   DrawTextFCentered(ystart + 1 * ystep, FC_RED,
740                     "Guido Schulz");
741   DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
742                     "Additional toons:");
743   DrawTextFCentered(ystart + 3 * ystep, FC_RED,
744                     "Karl Hörnell");
745   DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
746                     "...and many thanks to all contributors");
747   DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
748                     "of new levels!");
749
750   DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
751 }
752
753 void DrawHelpScreenContactText()
754 {
755   int ystart = 150, ystep = 30;
756   int ybottom = SYSIZE - 20;
757
758   ClearWindow();
759   DrawHeadline();
760
761   DrawTextFCentered(100, FC_GREEN, "Program information:");
762
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,
768                     "info@artsoft.org");
769   DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
770                     "or SnailMail to:");
771   DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
772                     "Holger Schemel");
773   DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
774                     "Detmolder Strasse 189");
775   DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
776                     "33604 Bielefeld");
777   DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
778                     "Germany");
779
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,
785                     ":-)");
786
787   DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
788 }
789
790 void DrawHelpScreen()
791 {
792   int i;
793
794   UnmapAllGadgets();
795   CloseDoor(DOOR_CLOSE_2);
796
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);
803
804   FadeToFront();
805   InitAnimation();
806   PlaySoundLoop(SND_RHYTHMLOOP);
807 }
808
809 void HandleHelpScreen(int button)
810 {
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;
815   int i;
816
817   if (button_released)
818   {
819     if (helpscreen_state < num_helpscreen_els_pages - 1)
820     {
821       for(i=0;i<MAX_HELPSCREEN_ELS;i++)
822         helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
823       helpscreen_state++;
824       DrawHelpScreenElText(helpscreen_state*MAX_HELPSCREEN_ELS);
825       DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
826     }
827     else if (helpscreen_state <
828              num_helpscreen_els_pages + num_helpscreen_music - 1)
829     {
830       helpscreen_state++;
831       DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
832     }
833     else if (helpscreen_state ==
834              num_helpscreen_els_pages + num_helpscreen_music - 1)
835     {
836       helpscreen_state++;
837       DrawHelpScreenCreditsText();
838     }
839     else if (helpscreen_state ==
840              num_helpscreen_els_pages + num_helpscreen_music)
841     {
842       helpscreen_state++;
843       DrawHelpScreenContactText();
844     }
845     else
846     {
847       FadeSounds();
848       DrawMainMenu();
849       game_status = MAINMENU;
850     }
851   }
852   else
853   {
854     if (DelayReached(&hs_delay,GAME_FRAME_DELAY * 2))
855     {
856       if (helpscreen_state<num_helpscreen_els_pages)
857         DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
858     }
859     DoAnimation();
860   }
861
862   BackToFront();
863 }
864
865 void HandleTypeName(int newxpos, Key key)
866 {
867   static int xpos = 0, ypos = 2;
868
869   if (newxpos)
870   {
871     xpos = newxpos;
872     DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
873     DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
874     return;
875   }
876
877   if (((key >= KSYM_A && key <= KSYM_Z) ||
878        (key >= KSYM_a && key <= KSYM_z)) && 
879       xpos < MAX_PLAYER_NAME_LEN)
880   {
881     char ascii;
882
883     if (key >= KSYM_A && key <= KSYM_Z)
884       ascii = 'A' + (char)(key - KSYM_A);
885     else
886       ascii = 'a' + (char)(key - KSYM_a);
887
888     setup.player_name[xpos] = ascii;
889     setup.player_name[xpos + 1] = 0;
890     xpos++;
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);
896   }
897   else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
898   {
899     xpos--;
900     setup.player_name[xpos] = 0;
901     DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
902     DrawGraphic(xpos + 7, ypos, GFX_LEERRAUM);
903   }
904   else if (key == KSYM_Return && xpos > 0)
905   {
906     DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_RED);
907     DrawGraphic(xpos + 6, ypos, GFX_LEERRAUM);
908
909     SaveSetup();
910     game_status = MAINMENU;
911   }
912
913   BackToFront();
914 }
915
916 void DrawChooseLevel()
917 {
918   UnmapAllGadgets();
919   CloseDoor(DOOR_CLOSE_2);
920
921   ClearWindow();
922   HandleChooseLevel(0,0, 0,0, MB_MENU_INITIALIZE);
923   MapChooseLevelGadgets();
924
925   FadeToFront();
926   InitAnimation();
927 }
928
929 static void AdjustChooseLevelScrollbar(int id, int first_entry)
930 {
931   struct GadgetInfo *gi = screen_gadget[id];
932   int items_max, items_visible, item_position;
933
934   items_max = numLevelDirInfoInGroup(leveldir_current);
935   items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
936   item_position = first_entry;
937
938   if (item_position > items_max - items_visible)
939     item_position = items_max - items_visible;
940
941   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
942                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
943 }
944
945 static void drawChooseLevelList(int first_entry, int num_page_entries)
946 {
947   int i;
948   char buffer[SCR_FIELDX * 2];
949   int max_buffer_len = (SCR_FIELDX - 2) * 2;
950   int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
951
952   ClearRectangle(backbuffer, SX, SY, SXSIZE - 32, SYSIZE);
953   redraw_mask |= REDRAW_FIELD;
954
955   DrawText(SX, SY, "Level Directories", FS_BIG, FC_GREEN);
956
957   for(i=0; i<num_page_entries; i++)
958   {
959     struct LevelDirInfo *node, *node_first;
960     int leveldir_pos = first_entry + i;
961     int ypos = MENU_SCREEN_START_YPOS + i;
962
963     node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
964     node = getLevelDirInfoFromPos(node_first, leveldir_pos);
965
966     strncpy(buffer, node->name , max_buffer_len);
967     buffer[max_buffer_len] = '\0';
968
969     DrawText(SX + 32, SY + ypos * 32, buffer, FS_MEDIUM, node->color);
970
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);
975     else
976       initCursor(i, GFX_KUGEL_BLAU);
977   }
978
979   if (first_entry > 0)
980     DrawGraphic(0, 1, GFX_ARROW_BLUE_UP);
981
982   if (first_entry + num_page_entries < num_leveldirs)
983     DrawGraphic(0, MAX_MENU_ENTRIES_ON_SCREEN + 1, GFX_ARROW_BLUE_DOWN);
984 }
985
986 static void drawChooseLevelInfo(int leveldir_pos)
987 {
988   struct LevelDirInfo *node, *node_first;
989   int x, last_redraw_mask = redraw_mask;
990
991   node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
992   node = getLevelDirInfoFromPos(node_first, leveldir_pos);
993
994   ClearRectangle(drawto, SX + 32, SY + 32, SXSIZE - 64, 32);
995
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);
1000   else
1001     DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
1002                       node->levels, node->class_desc);
1003
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);
1008 }
1009
1010 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1011 {
1012   static unsigned long choose_delay = 0;
1013   int x = 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;
1018
1019   if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
1020     num_page_entries = num_leveldirs;
1021   else
1022     num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1023
1024   if (button == MB_MENU_INITIALIZE)
1025   {
1026     int leveldir_pos = posLevelDirInfo(leveldir_current);
1027
1028     if (leveldir_current->cl_first == -1)
1029     {
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;
1033     }
1034
1035     if (dx == 999)      /* first entry is set by scrollbar position */
1036       leveldir_current->cl_first = dy;
1037     else
1038       AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1039                                  leveldir_current->cl_first);
1040
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);
1045     return;
1046   }
1047   else if (button == MB_MENU_LEAVE)
1048   {
1049     if (leveldir_current->node_parent)
1050     {
1051       leveldir_current = leveldir_current->node_parent;
1052       DrawChooseLevel();
1053     }
1054     else
1055     {
1056       game_status = MAINMENU;
1057       DrawMainMenu();
1058     }
1059     return;
1060   }
1061
1062   if (mx || my)         /* mouse input */
1063   {
1064     x = (mx - SX) / 32;
1065     y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1066   }
1067   else if (dx || dy)    /* keyboard input */
1068   {
1069     if (dy)
1070       y = leveldir_current->cl_cursor + dy;
1071
1072     if (ABS(dy) == SCR_FIELDY)  /* handle KSYM_Page_Up, KSYM_Page_Down */
1073     {
1074       dy = SIGN(dy);
1075       step = num_page_entries - 1;
1076       y = (dy < 0 ? -1 : num_page_entries);
1077     }
1078   }
1079
1080   if (x == 0 && y == -1)
1081   {
1082     if (leveldir_current->cl_first > 0 &&
1083         (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1084     {
1085       leveldir_current->cl_first -= step;
1086       if (leveldir_current->cl_first < 0)
1087         leveldir_current->cl_first = 0;
1088
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);
1095       return;
1096     }
1097   }
1098   else if (x == 0 && y > num_page_entries - 1)
1099   {
1100     if (leveldir_current->cl_first + num_page_entries < num_leveldirs &&
1101         (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1102     {
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);
1106
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);
1113       return;
1114     }
1115   }
1116
1117   if (dx == 1)
1118   {
1119     struct LevelDirInfo *node_first, *node_cursor;
1120     int leveldir_pos = leveldir_current->cl_first + y;
1121
1122     node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
1123     node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos);
1124
1125     if (node_cursor->node_group)
1126     {
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;
1130       DrawChooseLevel();
1131       return;
1132     }
1133   }
1134   else if (dx == -1 && leveldir_current->node_parent)
1135   {
1136     leveldir_current = leveldir_current->node_parent;
1137     DrawChooseLevel();
1138     return;
1139   }
1140
1141   if (x == 0 && y >= 0 && y < num_page_entries)
1142   {
1143     if (button)
1144     {
1145       if (y != leveldir_current->cl_cursor)
1146       {
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;
1151       }
1152     }
1153     else
1154     {
1155       struct LevelDirInfo *node_first, *node_cursor;
1156       int leveldir_pos = leveldir_current->cl_first + y;
1157
1158       node_first = getLevelDirInfoFirstGroupEntry(leveldir_current);
1159       node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos);
1160
1161       if (node_cursor->node_group)
1162       {
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;
1166
1167         DrawChooseLevel();
1168       }
1169       else if (node_cursor->parent_link)
1170       {
1171         leveldir_current = node_cursor->node_parent;
1172
1173         DrawChooseLevel();
1174       }
1175       else
1176       {
1177         node_cursor->cl_first = leveldir_current->cl_first;
1178         node_cursor->cl_cursor = leveldir_current->cl_cursor;
1179         leveldir_current = node_cursor;
1180
1181         LoadLevelSetup_SeriesInfo();
1182
1183         SaveLevelSetup_LastSeries();
1184         SaveLevelSetup_SeriesInfo();
1185         TapeErase();
1186
1187         game_status = MAINMENU;
1188         DrawMainMenu();
1189       }
1190     }
1191   }
1192
1193   BackToFront();
1194
1195   if (game_status == CHOOSELEVEL)
1196     DoAnimation();
1197 }
1198
1199 void DrawHallOfFame(int highlight_position)
1200 {
1201   UnmapAllGadgets();
1202   FadeSounds();
1203   CloseDoor(DOOR_CLOSE_2);
1204
1205   if (highlight_position < 0) 
1206     LoadScore(level_nr);
1207
1208   FadeToFront();
1209   InitAnimation();
1210   HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1211   PlaySound(SND_HALLOFFAME);
1212 }
1213
1214 static void drawHallOfFameList(int first_entry, int highlight_position)
1215 {
1216   int i;
1217
1218   ClearWindow();
1219   DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1220   DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1221
1222   for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1223   {
1224     int entry = first_entry + i;
1225     int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1226
1227 #if 0
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);
1232 #else
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);
1240 #endif
1241   }
1242 }
1243
1244 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1245 {
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;
1250
1251   if (button == MB_MENU_INITIALIZE)
1252   {
1253     first_entry = 0;
1254     highlight_position = mx;
1255     drawHallOfFameList(first_entry, highlight_position);
1256     return;
1257   }
1258
1259   if (ABS(dy) == SCR_FIELDY)    /* handle KSYM_Page_Up, KSYM_Page_Down */
1260     step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1261
1262   if (dy < 0)
1263   {
1264     if (first_entry > 0)
1265     {
1266       first_entry -= step;
1267       if (first_entry < 0)
1268         first_entry = 0;
1269
1270       drawHallOfFameList(first_entry, highlight_position);
1271       return;
1272     }
1273   }
1274   else if (dy > 0)
1275   {
1276     if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1277     {
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);
1281
1282       drawHallOfFameList(first_entry, highlight_position);
1283       return;
1284     }
1285   }
1286
1287   if (button_released)
1288   {
1289     FadeSound(SND_HALLOFFAME);
1290     game_status = MAINMENU;
1291     DrawMainMenu();
1292   }
1293
1294   BackToFront();
1295
1296   if (game_status == HALLOFFAME)
1297     DoAnimation();
1298 }
1299
1300
1301 /* ========================================================================= */
1302 /* setup screen functions                                                    */
1303 /* ========================================================================= */
1304
1305 static struct TokenInfo *setup_info;
1306 static int num_setup_info;
1307 static int setup_mode = SETUP_MODE_MAIN;
1308
1309 static void execSetupInput()
1310 {
1311   setup_mode = SETUP_MODE_INPUT;
1312   DrawSetupInputScreen();
1313 }
1314
1315 static void execExitSetup()
1316 {
1317   game_status = MAINMENU;
1318   DrawMainMenu();
1319 }
1320
1321 static void execSaveAndExitSetup()
1322 {
1323   SaveSetup();
1324   execExitSetup();
1325 }
1326
1327 static struct TokenInfo setup_main_info[] =
1328 {
1329   { TYPE_SWITCH,        &setup.sound,           "Sound:",       },
1330   { TYPE_SWITCH,        &setup.sound_loops,     " Sound Loops:" },
1331   { TYPE_SWITCH,        &setup.sound_music,     " Game Music:"  },
1332 #if 0
1333   { TYPE_SWITCH,        &setup.toons,           "Toons:"        },
1334   { TYPE_SWITCH,        &setup.double_buffering,"Buffered gfx:" },
1335 #endif
1336   { TYPE_SWITCH,        &setup.scroll_delay,    "Scroll Delay:" },
1337   { TYPE_SWITCH,        &setup.soft_scrolling,  "Soft Scroll.:" },
1338 #if 0
1339   { TYPE_SWITCH,        &setup.fading,          "Fading:"       },
1340 #endif
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" },
1351   { 0,                  NULL,                   NULL            }
1352 };
1353
1354 static void drawSetupValue(int pos)
1355 {
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);
1361
1362   if (setup_info[pos].type & TYPE_SWITCH ||
1363       setup_info[pos].type & TYPE_YES_NO)
1364   {
1365     boolean value = *(boolean *)(setup_info[pos].value);
1366     int value_length = 3;
1367
1368     if (!value)
1369       value_color = FC_BLUE;
1370
1371     if (strlen(value_string) < value_length)
1372       strcat(value_string, " ");
1373   }
1374
1375   DrawText(SX + xpos * 32, SY + ypos * 32, value_string, FS_BIG, value_color);
1376 }
1377
1378 static void DrawSetupMainScreen()
1379 {
1380   int i;
1381
1382   UnmapAllGadgets();
1383   CloseDoor(DOOR_CLOSE_2);
1384   ClearWindow();
1385
1386   DrawText(SX + 16, SY + 16, "SETUP",FS_BIG,FC_YELLOW);
1387   setup_info = setup_main_info;
1388
1389   num_setup_info = 0;
1390   for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1391   {
1392     void *value_ptr = setup_info[i].value;
1393     int ypos = MENU_SCREEN_START_YPOS + i;
1394
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;
1402
1403     DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, FS_BIG, FC_GREEN);
1404
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);
1411
1412     if (setup_info[i].type & TYPE_BOOLEAN_STYLE)
1413       drawSetupValue(i);
1414
1415     num_setup_info++;
1416   }
1417
1418   FadeToFront();
1419   InitAnimation();
1420   HandleSetupScreen(0,0,0,0,MB_MENU_INITIALIZE);
1421 }
1422
1423 void HandleSetupMainScreen(int mx, int my, int dx, int dy, int button)
1424 {
1425   static int choice = 0;
1426   int x = 0;
1427   int y = choice;
1428
1429   if (button == MB_MENU_INITIALIZE)
1430   {
1431     drawCursor(choice, FC_RED);
1432     return;
1433   }
1434   else if (button == MB_MENU_LEAVE)
1435   {
1436     for (y=0; y<num_setup_info; y++)
1437     {
1438       if (setup_info[y].type & TYPE_LEAVE_MENU)
1439       {
1440         void (*menu_callback_function)(void) = setup_info[y].value;
1441
1442         menu_callback_function();
1443       }
1444     }
1445     return;
1446   }
1447
1448   if (mx || my)         /* mouse input */
1449   {
1450     x = (mx - SX) / 32;
1451     y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1452   }
1453   else if (dx || dy)    /* keyboard input */
1454   {
1455     if (dx)
1456     {
1457       int type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
1458
1459       if (!(setup_info[choice].type & TYPE_ENTER_OR_LEAVE_MENU) ||
1460           setup_info[choice].type == type)
1461         button = MB_MENU_CHOICE;
1462     }
1463     else if (dy)
1464       y = choice + dy;
1465
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)
1469       y += dy;
1470   }
1471
1472   if (x == 0 && y >= 0 && y < num_setup_info &&
1473       setup_info[y].type != TYPE_EMPTY)
1474   {
1475     if (button)
1476     {
1477       if (y != choice)
1478       {
1479         drawCursor(y, FC_RED);
1480         drawCursor(choice, FC_BLUE);
1481         choice = y;
1482       }
1483     }
1484     else if (!(setup_info[y].type & TYPE_GHOSTED))
1485     {
1486       if (setup_info[y].type & TYPE_BOOLEAN_STYLE)
1487       {
1488         boolean new_value = !*(boolean *)(setup_info[y].value);
1489
1490         *(boolean *)setup_info[y].value = new_value;
1491         drawSetupValue(y);
1492       }
1493       else if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
1494       {
1495         void (*menu_callback_function)(void) = setup_info[choice].value;
1496
1497         menu_callback_function();
1498       }
1499     }
1500   }
1501
1502   BackToFront();
1503
1504   if (game_status == SETUP)
1505     DoAnimation();
1506 }
1507
1508 void DrawSetupInputScreen()
1509 {
1510   ClearWindow();
1511   DrawText(SX+16, SY+16, "SETUP INPUT", FS_BIG, FC_YELLOW);
1512
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);
1517
1518   DrawGraphic(10, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_LEFT);
1519   DrawGraphic(12, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_RIGHT);
1520
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);
1524
1525   DeactivateJoystickForCalibration();
1526   DrawTextFCentered(SYSIZE - 20, FC_BLUE,
1527                     "Joysticks deactivated on this screen");
1528
1529   HandleSetupInputScreen(0,0, 0,0, MB_MENU_INITIALIZE);
1530   FadeToFront();
1531   InitAnimation();
1532 }
1533
1534 static void setJoystickDeviceToNr(char *device_name, int device_nr)
1535 {
1536   if (device_name == NULL)
1537     return;
1538
1539   if (device_nr < 0 || device_nr >= MAX_PLAYERS)
1540     device_nr = 0;
1541
1542   if (strlen(device_name) > 1)
1543   {
1544     char c1 = device_name[strlen(device_name) - 1];
1545     char c2 = device_name[strlen(device_name) - 2];
1546
1547     if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
1548       device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
1549   }
1550   else
1551     strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
1552             strlen(device_name));
1553 }
1554
1555 static void drawPlayerSetupInputInfo(int player_nr)
1556 {
1557   int i;
1558   static struct SetupKeyboardInfo custom_key;
1559   static struct
1560   {
1561     Key *key;
1562     char *text;
1563   } custom[] =
1564   {
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"       }
1571   };
1572   static char *joystick_name[MAX_PLAYERS] =
1573   {
1574     "Joystick1",
1575     "Joystick2",
1576     "Joystick3",
1577     "Joystick4"
1578   };
1579
1580   custom_key = setup.input[player_nr].key;
1581
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);
1584
1585   if (setup.input[player_nr].use_joystick)
1586   {
1587     char *device_name = setup.input[player_nr].joy.device_name;
1588
1589     DrawText(SX+8*32, SY+3*32,
1590              joystick_name[getJoystickNrFromDeviceName(device_name)],
1591              FS_BIG, FC_YELLOW);
1592     DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
1593   }
1594   else
1595   {
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);
1598   }
1599
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);
1611
1612   for (i=0; i<6; i++)
1613   {
1614     int ypos = 6 + i + (i > 3 ? i-3 : 0);
1615
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 ?
1620               custom[i].text :
1621               getKeyNameFromKey(*custom[i].key)),
1622              FS_BIG, FC_YELLOW);
1623   }
1624 }
1625
1626 void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button)
1627 {
1628   static int choice = 0;
1629   static int player_nr = 0;
1630   int x = 0;
1631   int y = choice;
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;
1636
1637   if (button == MB_MENU_INITIALIZE)
1638   {
1639     drawPlayerSetupInputInfo(player_nr);
1640     drawCursor(choice, FC_RED);
1641     return;
1642   }
1643   else if (button == MB_MENU_LEAVE)
1644   {
1645     setup_mode = SETUP_MODE_MAIN;
1646     DrawSetupScreen();
1647     InitJoysticks();
1648   }
1649
1650   if (mx || my)         /* mouse input */
1651   {
1652     x = (mx - SX) / 32;
1653     y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1654   }
1655   else if (dx || dy)    /* keyboard input */
1656   {
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;
1663     else if (dy)
1664       y = choice + dy;
1665
1666     if (y >= pos_empty1 && y <= pos_empty2)
1667       y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
1668   }
1669
1670   if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
1671   {
1672     static unsigned long delay = 0;
1673
1674     if (!DelayReached(&delay, GADGET_FRAME_DELAY))
1675       goto out;
1676
1677     player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
1678
1679     drawPlayerSetupInputInfo(player_nr);
1680   }
1681   else if (x == 0 && y >= pos_start && y <= pos_end &&
1682            !(y >= pos_empty1 && y <= pos_empty2))
1683   {
1684     if (button)
1685     {
1686       if (y != choice)
1687       {
1688         drawCursor(y, FC_RED);
1689         drawCursor(choice, FC_BLUE);
1690         choice = y;
1691       }
1692     }
1693     else
1694     {
1695       if (y == 1)
1696       {
1697         char *device_name = setup.input[player_nr].joy.device_name;
1698
1699         if (!setup.input[player_nr].use_joystick)
1700         {
1701           int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
1702
1703           setJoystickDeviceToNr(device_name, new_device_nr);
1704           setup.input[player_nr].use_joystick = TRUE;
1705         }
1706         else
1707         {
1708           int device_nr = getJoystickNrFromDeviceName(device_name);
1709           int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
1710
1711           if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
1712             setup.input[player_nr].use_joystick = FALSE;
1713           else
1714             setJoystickDeviceToNr(device_name, new_device_nr);
1715         }
1716
1717         drawPlayerSetupInputInfo(player_nr);
1718       }
1719       else if (y == 2)
1720       {
1721         if (setup.input[player_nr].use_joystick)
1722         {
1723           InitJoysticks();
1724           CalibrateJoystick(player_nr);
1725         }
1726         else
1727           CustomizeKeyboard(player_nr);
1728       }
1729       else if (y == pos_end)
1730       {
1731         InitJoysticks();
1732
1733         setup_mode = SETUP_MODE_MAIN;
1734         DrawSetupScreen();
1735       }
1736     }
1737   }
1738
1739   BackToFront();
1740
1741   out:
1742
1743   if (game_status == SETUP)
1744     DoAnimation();
1745 }
1746
1747 void DrawSetupScreen()
1748 {
1749   if (setup_mode == SETUP_MODE_MAIN)
1750     DrawSetupMainScreen();
1751   else if (setup_mode == SETUP_MODE_INPUT)
1752     DrawSetupInputScreen();
1753 }
1754
1755 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
1756 {
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);
1761 }
1762
1763 void CustomizeKeyboard(int player_nr)
1764 {
1765   int i;
1766   int step_nr;
1767   boolean finished = FALSE;
1768   static struct SetupKeyboardInfo custom_key;
1769   static struct
1770   {
1771     Key *key;
1772     char *text;
1773   } customize_step[] =
1774   {
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" }
1781   };
1782
1783   /* read existing key bindings from player setup */
1784   custom_key = setup.input[player_nr].key;
1785
1786   ClearWindow();
1787   DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
1788
1789   BackToFront();
1790   InitAnimation();
1791
1792   step_nr = 0;
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),
1799            FS_BIG, FC_BLUE);
1800
1801   while(!finished)
1802   {
1803     if (PendingEvent())         /* got event */
1804     {
1805       Event event;
1806
1807       NextEvent(&event);
1808
1809       switch(event.type)
1810       {
1811         case EVENT_KEYPRESS:
1812           {
1813             Key key = GetEventKey((KeyEvent *)&event, TRUE);
1814
1815             if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
1816             {
1817               finished = TRUE;
1818               break;
1819             }
1820
1821             /* all keys configured -- wait for "Escape" or "Return" key */
1822             if (step_nr == 6)
1823               break;
1824
1825             /* press 'Enter' to keep the existing key binding */
1826             if (key == KSYM_Return)
1827               key = *customize_step[step_nr].key;
1828
1829             /* check if key already used */
1830             for (i=0; i<step_nr; i++)
1831               if (*customize_step[i].key == key)
1832                 break;
1833             if (i < step_nr)
1834               break;
1835
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);
1842             step_nr++;
1843
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);
1849
1850             /* press 'Enter' to leave */
1851             if (step_nr == 6)
1852             {
1853               DrawText(SX + 16, SY + 15*32+16,
1854                        "Press Enter", FS_BIG, FC_YELLOW);
1855               break;
1856             }
1857
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),
1865                      FS_BIG, FC_BLUE);
1866           }
1867           break;
1868
1869         case EVENT_KEYRELEASE:
1870           key_joystick_mapping = 0;
1871           break;
1872
1873         default:
1874           HandleOtherEvents(&event);
1875           break;
1876       }
1877     }
1878
1879     BackToFront();
1880     DoAnimation();
1881
1882     /* don't eat all CPU time */
1883     Delay(10);
1884   }
1885
1886   /* write new key bindings back to player setup */
1887   setup.input[player_nr].key = custom_key;
1888
1889   StopAnimation();
1890   DrawSetupInputScreen();
1891 }
1892
1893 static boolean CalibrateJoystickMain(int player_nr)
1894 {
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;
1900
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;
1905   int joy_x, joy_y;
1906   int joy_value;
1907   int result = -1;
1908
1909   if (joystick.status == JOYSTICK_NOT_AVAILABLE)
1910     return FALSE;
1911
1912   if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
1913     return FALSE;
1914
1915   ClearWindow();
1916
1917   for(y=0; y<3; y++)
1918   {
1919     for(x=0; x<3; x++)
1920     {
1921       check[x][y] = FALSE;
1922       DrawGraphic(xpos + x - 1, ypos + y - 1, GFX_KUGEL_BLAU);
1923     }
1924   }
1925
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);
1933
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);
1937
1938   /* eventually uncalibrated center position (joystick could be uncentered) */
1939   if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
1940     return FALSE;
1941
1942   new_joystick_xmiddle = joy_x;
1943   new_joystick_ymiddle = joy_y;
1944
1945   DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
1946   BackToFront();
1947
1948   while(Joystick(player_nr) & JOY_BUTTON);      /* wait for released button */
1949   InitAnimation();
1950
1951   while(result < 0)
1952   {
1953     if (PendingEvent())         /* got event */
1954     {
1955       Event event;
1956
1957       NextEvent(&event);
1958
1959       switch(event.type)
1960       {
1961         case EVENT_KEYPRESS:
1962           switch(GetEventKey((KeyEvent *)&event, TRUE))
1963           {
1964             case KSYM_Return:
1965               if (check_remaining == 0)
1966                 result = 1;
1967               break;
1968
1969             case KSYM_Escape:
1970               result = 0;
1971               break;
1972
1973             default:
1974               break;
1975           }
1976           break;
1977
1978         case EVENT_KEYRELEASE:
1979           key_joystick_mapping = 0;
1980           break;
1981
1982         default:
1983           HandleOtherEvents(&event);
1984           break;
1985       }
1986     }
1987
1988     if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
1989       return FALSE;
1990
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);
1995
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;
2002
2003     CheckJoystickData();
2004
2005     joy_value = Joystick(player_nr);
2006
2007     if (joy_value & JOY_BUTTON && check_remaining == 0)
2008       result = 1;
2009
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);
2012
2013     if (x != last_x || y != last_y)
2014     {
2015       DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_GELB);
2016       DrawGraphic(xpos + x,      ypos + y,      GFX_KUGEL_ROT);
2017
2018       last_x = x;
2019       last_y = y;
2020
2021       if (check_remaining > 0 && !check[x+1][y+1])
2022       {
2023         check[x+1][y+1] = TRUE;
2024         check_remaining--;
2025       }
2026
2027 #if 0
2028 #ifdef DEBUG
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);
2037 #endif
2038 #endif
2039
2040     }
2041
2042     BackToFront();
2043     DoAnimation();
2044
2045     /* don't eat all CPU time */
2046     Delay(10);
2047   }
2048
2049   /* calibrated center position (joystick should now be centered) */
2050   if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2051     return FALSE;
2052
2053   new_joystick_xmiddle = joy_x;
2054   new_joystick_ymiddle = joy_y;
2055
2056   StopAnimation();
2057
2058   DrawSetupInputScreen();
2059
2060   /* wait until the last pressed button was released */
2061   while (Joystick(player_nr) & JOY_BUTTON)
2062   {
2063     if (PendingEvent())         /* got event */
2064     {
2065       Event event;
2066
2067       NextEvent(&event);
2068       HandleOtherEvents(&event);
2069
2070       Delay(10);
2071     }
2072   }
2073
2074   return TRUE;
2075 }
2076
2077 void CalibrateJoystick(int player_nr)
2078 {
2079   if (!CalibrateJoystickMain(player_nr))
2080   {
2081     ClearWindow();
2082
2083     DrawText(SX + 16, SY + 6*32, "  JOYSTICK NOT  ",  FS_BIG, FC_YELLOW);
2084     DrawText(SX,      SY + 7*32, "    AVAILABLE    ", FS_BIG, FC_YELLOW);
2085     BackToFront();
2086     Delay(2000);        /* show error message for two seconds */
2087   }
2088 }
2089
2090 void HandleGameActions()
2091 {
2092   if (game_status != PLAYING)
2093     return;
2094
2095   if (local_player->LevelSolved)
2096     GameWon();
2097
2098   if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2099     TapeStop();
2100
2101   GameActions();
2102
2103   BackToFront();
2104 }
2105
2106 /* ---------- new screen button stuff -------------------------------------- */
2107
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
2113
2114 #define SC_SCROLLBUTTON_XSIZE           32
2115 #define SC_SCROLLBUTTON_YSIZE           32
2116
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)
2125
2126 #define SC_BORDER_SIZE                  14
2127
2128 static struct
2129 {
2130   int xpos, ypos;
2131   int x, y;
2132   int gadget_id;
2133   char *infotext;
2134 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2135 {
2136   {
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"
2141   },
2142   {
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"
2147   }
2148 };
2149
2150 static struct
2151 {
2152   int xpos, ypos;
2153   int x, y;
2154   int width, height;
2155   int type;
2156   int gadget_id;
2157   char *infotext;
2158 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2159 {
2160   {
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"
2167   }
2168 };
2169
2170 static void CreateScreenScrollbuttons()
2171 {
2172   Bitmap *gd_bitmap = pix[PIX_MORE];
2173   struct GadgetInfo *gi;
2174   unsigned long event_mask;
2175   int i;
2176
2177   for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2178   {
2179     int id = scrollbutton_info[i].gadget_id;
2180     int x, y, width, height;
2181     int gd_x1, gd_x2, gd_y1, gd_y2;
2182
2183     x = scrollbutton_info[i].x;
2184     y = scrollbutton_info[i].y;
2185
2186     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2187
2188     x += SX;
2189     y += SY;
2190     width = SC_SCROLLBUTTON_XSIZE;
2191     height = SC_SCROLLBUTTON_YSIZE;
2192     gd_x1 = scrollbutton_info[i].xpos;
2193     gd_y1 = scrollbutton_info[i].ypos;
2194     gd_x2 = gd_x1;
2195     gd_y2 = gd_y1 + SC_SCROLLBUTTON_YSIZE;
2196
2197     gi = CreateGadget(GDI_CUSTOM_ID, id,
2198                       GDI_CUSTOM_TYPE_ID, i,
2199                       GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2200                       GDI_X, x,
2201                       GDI_Y, y,
2202                       GDI_WIDTH, width,
2203                       GDI_HEIGHT, height,
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,
2210                       GDI_END);
2211
2212     if (gi == NULL)
2213       Error(ERR_EXIT, "cannot create gadget");
2214
2215     screen_gadget[id] = gi;
2216   }
2217 }
2218
2219 static void CreateScreenScrollbars()
2220 {
2221   int i;
2222
2223   for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2224   {
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;
2232
2233 #if 0
2234     if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
2235       num_page_entries = num_leveldirs;
2236     else
2237       num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2238
2239     items_max = MAX(num_leveldirs, num_page_entries);
2240     items_visible = num_page_entries;
2241     item_position = 0;
2242 #else
2243     items_max = num_page_entries;
2244     items_visible = num_page_entries;
2245     item_position = 0;
2246 #endif
2247
2248     event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2249
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;
2254
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,
2272                       GDI_END);
2273
2274     if (gi == NULL)
2275       Error(ERR_EXIT, "cannot create gadget");
2276
2277     screen_gadget[id] = gi;
2278   }
2279 }
2280
2281 void CreateScreenGadgets()
2282 {
2283   CreateScreenScrollbuttons();
2284   CreateScreenScrollbars();
2285 }
2286
2287 void MapChooseLevelGadgets()
2288 {
2289   int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
2290   int i;
2291
2292   if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
2293     return;
2294
2295   for (i=0; i<NUM_SCREEN_GADGETS; i++)
2296     MapGadget(screen_gadget[i]);
2297 }
2298
2299 void UnmapChooseLevelGadgets()
2300 {
2301   int i;
2302
2303   for (i=0; i<NUM_SCREEN_GADGETS; i++)
2304     UnmapGadget(screen_gadget[i]);
2305 }
2306
2307 static void HandleScreenGadgets(struct GadgetInfo *gi)
2308 {
2309   int id = gi->custom_id;
2310
2311   if (game_status != CHOOSELEVEL)
2312     return;
2313
2314   switch (id)
2315   {
2316     case SCREEN_CTRL_ID_SCROLL_UP:
2317       HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
2318       break;
2319
2320     case SCREEN_CTRL_ID_SCROLL_DOWN:
2321       HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
2322       break;
2323
2324     case SCREEN_CTRL_ID_SCROLL_VERTICAL:
2325       HandleChooseLevel(0,0, 999,gi->event.item_position, MB_MENU_INITIALIZE);
2326       break;
2327
2328     default:
2329       break;
2330   }
2331 }