fixed code to compile with current gcc and 64-bit systems
[rocksndiamonds.git] / src / screens.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  ©1995 Artsoft Development                               *
5 *        Holger Schemel                                    *
6 *        33659 Bielefeld-Senne                             *
7 *        Telefon: (0521) 493245                            *
8 *        eMail: aeglos@valinor.owl.de                      *
9 *               aeglos@uni-paderborn.de                    *
10 *               q99492@pbhrzx.uni-paderborn.de             *
11 *----------------------------------------------------------*
12 *  screens.c                                               *
13 *                                                          *
14 *  Letzte Aenderung: 15.06.1995                            *
15 ***********************************************************/
16
17 #include "screens.h"
18 #include "events.h"
19 #include "sound.h"
20 #include "game.h"
21 #include "tools.h"
22 #include "editor.h"
23 #include "misc.h"
24
25 void DrawMainMenu()
26 {
27   int i;
28
29   FadeSounds();
30   GetPlayerConfig();
31   LoadLevel(level_nr);
32
33   ClearWindow();
34   DrawText(SX+16, SY+8,  "ROCKS'N'DIAMONDS",FS_BIG,FC_YELLOW);
35   DrawText(SX+25+16, SY+46, "Copyright ^1995 by Holger Schemel",
36            FS_SMALL,FC_RED);
37   DrawText(SX+32, SY+64, "Name:",FS_BIG,FC_GREEN);
38   DrawText(SX+192,SY+64, player.alias_name,FS_BIG,FC_RED);
39   DrawText(SX+32, SY+96, "Level:",FS_BIG,FC_GREEN);
40   DrawText(SX+352,SY+96, int2str(level_nr,3),FS_BIG,
41            (level_nr<leveldir[leveldir_nr].num_ready ? FC_RED : FC_YELLOW));
42   DrawText(SX+32, SY+128,"Hall Of Fame",FS_BIG,FC_GREEN);
43   DrawText(SX+32, SY+160,"Level Creator",FS_BIG,FC_GREEN);
44   DrawText(SY+32, SY+192,"Info Screen",FS_BIG,FC_GREEN);
45   DrawText(SX+32, SY+224,"Start Game",FS_BIG,FC_GREEN);
46   DrawText(SX+32, SY+256,"Setup",FS_BIG,FC_GREEN);
47   DrawText(SX+32, SY+288,"Quit",FS_BIG,FC_GREEN);
48
49   DrawMicroLevel(MICROLEV_XPOS,MICROLEV_YPOS);
50
51   for(i=2;i<10;i++)
52     DrawGraphic(0,i,GFX_KUGEL_BLAU);
53   DrawGraphic(10,3,GFX_KUGEL_BLAU);
54   DrawGraphic(14,3,GFX_KUGEL_BLAU);
55
56   DrawText(SX+54+16,SY+326,"A Game by Artsoft Development",FS_SMALL,FC_BLUE);
57   DrawText(SX+40+16,SY+344,"Graphics: Deluxe Paint IV Amiga",
58            FS_SMALL,FC_BLUE);
59   DrawText(SX+60+16,SY+362,"Sounds: AudioMaster IV Amiga",
60            FS_SMALL,FC_BLUE);
61
62   FadeToFront();
63   InitAnimation();
64   HandleMainMenu(0,0,0,0,MB_MENU_MARK);
65
66   TapeStop();
67   if (TAPE_IS_EMPTY(tape))
68     LoadLevelTape(level_nr);
69   DrawCompleteVideoDisplay();
70
71   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
72
73   XAutoRepeatOn(display);
74 }
75
76 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
77 {
78   static int choice = 3;
79   static int redraw = TRUE;
80   int x = (mx+32-SX)/32, y = (my+32-SY)/32;
81
82   if (redraw)
83   {
84     DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
85     redraw = FALSE;
86   }
87
88   if (dx || dy)
89   {
90     if (dx && choice==4)
91     {
92       x = (dx<0 ? 11 : 15);
93       y = 4;
94     }
95     else if (dy)
96     {
97       x = 1;
98       y = choice+dy;
99     }
100     else
101       x = y = 0;
102
103     if (y<3)
104       y = 3;
105     else if (y>10)
106       y = 10;
107   }
108
109   if (!mx && !my && !dx && !dy)
110   {
111     x = 1;
112     y = choice;
113   }
114
115   if (y==4 && ((x==11 && level_nr>0) ||
116                (x==15 && level_nr<LEVELDIR_SIZE(leveldir[leveldir_nr]))) &&
117       button)
118   {
119     static int level_delay = 0;
120     int step = (button==1 ? 1 : button==2 ? 5 : 10);
121
122     if (!DelayReached(&level_delay,20))
123       goto out;
124
125     level_nr += (x==11 ? -step : +step);
126     if (level_nr<0)
127       level_nr = 0;
128     if (level_nr>LEVELDIR_SIZE(leveldir[leveldir_nr])-1)
129       level_nr = LEVELDIR_SIZE(leveldir[leveldir_nr])-1;
130
131     if (level_nr>player.handicap && level_nr<leveldir[leveldir_nr].num_ready)
132     {
133       if (x==11 || leveldir[leveldir_nr].num_free==0)
134         level_nr = player.handicap;
135       else
136         level_nr = leveldir[leveldir_nr].num_ready;
137     }
138
139     DrawTextExt(drawto,gc,SX+352,SY+96, int2str(level_nr,3),FS_BIG,
140                 (level_nr<leveldir[leveldir_nr].num_ready ?FC_RED :FC_YELLOW));
141     DrawTextExt(window,gc,SX+352,SY+96, int2str(level_nr,3),FS_BIG,
142                 (level_nr<leveldir[leveldir_nr].num_ready ?FC_RED :FC_YELLOW));
143
144     LoadLevel(level_nr);
145     DrawMicroLevel(MICROLEV_XPOS,MICROLEV_YPOS);
146
147     TapeErase();
148     LoadLevelTape(level_nr);
149     DrawCompleteVideoDisplay();
150   }
151   else if (x==1 && y>=3 && y<=10)
152   {
153     if (button)
154     {
155       if (y!=choice)
156       {
157         DrawGraphic(0,y-1,GFX_KUGEL_ROT);
158         DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
159       }
160       choice = y;
161     }
162     else
163     {
164       if (y==3)
165       {
166         game_status = TYPENAME;
167         HandleTypeName(strlen(player.alias_name),0);
168       }
169       else if (y==4)
170       {
171         if (num_leveldirs)
172         {
173           game_status = CHOOSELEVEL;
174           DrawChooseLevel();
175           redraw = TRUE;
176         }
177       }
178       else if (y==5)
179       {
180         game_status = HALLOFFAME;
181         DrawHallOfFame(-1);
182         redraw = TRUE;
183       }
184       else if (y==6)
185       {
186         game_status = LEVELED;
187         DrawLevelEd();
188         redraw = TRUE;
189       }
190       else if (y==7)
191       {
192         game_status = HELPSCREEN;
193         DrawHelpScreen();
194         redraw = TRUE;
195       }
196       else if (y==8)
197       {
198         if (autorecord_on && !tape.playing)
199           TapeInitRecording();
200
201         game_status = PLAYING;
202         InitGame();
203         redraw = TRUE;
204       }
205       else if (y==9)
206       {
207         game_status = SETUP;
208         DrawSetupScreen();
209         redraw = TRUE;
210       }
211       else if (y==10)
212       {
213         if (AreYouSure("Do you really want to quit ?",AYS_ASK|AYS_STAY_CLOSED))
214           game_status = EXITGAME;
215       }
216     }
217   }
218   BackToFront();
219
220   out:
221
222   if (game_status==MAINMENU)
223     DoAnimation();
224 }
225
226 #define MAX_HELPSCREEN_ELS      10
227 #define HA_NEXT                 -999
228 #define HA_END                  -1000
229
230 static int helpscreen_state;
231 static int helpscreen_step[MAX_HELPSCREEN_ELS];
232 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
233 static int helpscreen_delay[MAX_HELPSCREEN_ELS];
234 static int helpscreen_action[] =
235 {
236   GFX_ERDREICH,1,100,                                           HA_NEXT,
237   GFX_LEERRAUM,1,100,                                           HA_NEXT,
238   GFX_MORAST_LEER,1,100,                                        HA_NEXT,
239   GFX_BETON,1,100,                                              HA_NEXT,
240   GFX_MAUERWERK,1,100,                                          HA_NEXT,
241   GFX_FELSBODEN,1,100,                                          HA_NEXT,
242   GFX_EDELSTEIN,2,5,                                            HA_NEXT,
243   GFX_DIAMANT,2,5,                                              HA_NEXT,
244   GFX_FELSBROCKEN,4,5,                                          HA_NEXT,
245   GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10,         HA_NEXT,
246   GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10,  HA_NEXT,
247   GFX_ERZ_1,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10,        HA_NEXT,
248   GFX_ERZ_2,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10,          HA_NEXT,
249   GFX_GEBLUBBER,4,4,                                            HA_NEXT,
250   GFX_SCHLUESSEL1,4,33,                                         HA_NEXT,
251   GFX_PFORTE1,4,33,                                             HA_NEXT,
252   GFX_PFORTE1X,4,33,                                            HA_NEXT,
253   GFX_DYNAMIT_AUS,1,100,                                        HA_NEXT,
254   GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10,        HA_NEXT,
255   GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
256   GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
257   GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
258   GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3,      HA_NEXT,
259   GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
260   GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
261   GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
262   GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1,         HA_NEXT,
263   GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
264   GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
265   GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
266   GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3,         HA_NEXT,
267   GFX_MAMPFER+0,4,0, GFX_MAMPFER+3,1,0, GFX_MAMPFER+2,1,0,
268   GFX_MAMPFER+1,1,0,                                            HA_NEXT,
269   GFX_ZOMBIE+0,4,0, GFX_ZOMBIE+3,1,0, GFX_ZOMBIE+2,1,0,
270   GFX_ZOMBIE+1,1,0,                                             HA_NEXT,
271   GFX_ABLENK,4,1,                                               HA_NEXT,
272   GFX_AMOEBE_LEBT,4,40,                                         HA_NEXT,
273   GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50,                   HA_NEXT,
274   GFX_SIEB_LEER,4,2,                                            HA_NEXT,
275   HA_END
276 };
277 static char *helpscreen_eltext[][2] =
278 {
279   "Normal sand:", "You can dig through it",
280   "Empty field:", "You can walk through it",
281   "Quicksand: You cannot pass it,", "but rocks can fall though it",
282   "Massive Wall:", "Nothing can go through it",
283   "Normal Wall: You can't go through", "it, but you can bomb it away",
284   "Old Wall: Like normal wall, but", "some things can fall down from it",
285   "Emerald: You must collect enough of", "them to finish a level",
286   "Diamond: Counts as 3 emeralds;", "Can be destroyed by rocks",
287   "Rock: Smashes several things;", "Can be moved by the player",
288   "Bomb: You can move it, but be", "careful when dropping it",
289   "Nut: Throw a rock on it to open it;", "Each nut contains an emerald",
290   "Wall with an Emerald inside:", "Bomb the wall away to get it",
291   "Wall with a Diamond inside:", "Bomb the wall away to get it",
292   "Acid: Destroys everything that", "falls or walks into it",
293   "Key: Opens the door that has the", "same color (red/yellow/green/blue)",
294   "Door: Can be opened by the key", "with the same color",
295   "Door: You have to find out the", "right color of the key for it",
296   "Dynamite: Collect it and use it to", "destroy walls or kill enemies",
297   "Dynamite: This one explodes after", "a few seconds",
298   "Spaceship: Moves at the left side", "of walls; don't touch it!",
299   "Bug: Moves at the right side of", "walls; don't touch it!",
300   "Pacman: Eats the amoeba and you,", "if you're not careful",
301   "Cruncher: Eats diamonds and you,", "if you're not careful",
302   "Robot: Tries to kill the player", "",
303   "Magic Wheel: Touch it to get rid of", "the robots for some seconds",
304   "Living Amoeba: Grows through empty", "fields, sand and quicksand",
305   "Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships",
306   "Magic Wall: Changes rocks, emeralds", "and diamonds when they pass it",
307 };
308 static int num_helpscreen_els = sizeof(helpscreen_eltext)/(2*sizeof(char *));
309
310 static char *helpscreen_music[][3] =
311 {
312   "Alchemy",                    "Ian Boddy",            "Drive",
313   "The Chase",                  "Propaganda",           "A Secret Wish",
314   "Network 23",                 "Tangerine Dream",      "Exit",
315   "Czardasz",                   "Robert Pieculewicz",   "Czardasz",
316   "21st Century Common Man",    "Tangerine Dream",      "Tyger",
317   "Voyager",                    "The Alan Parsons Project","Pyramid",
318   "Twilight Painter",           "Tangerine Dream",      "Heartbreakers"
319 };
320 static int helpscreen_musicpos;
321
322 void DrawHelpScreenElAction(int start)
323 {
324   int i = 0, j = 0;
325   int frame, delay, graphic;
326   int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
327
328   while(helpscreen_action[j] != HA_END)
329   {
330     if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
331       break;
332     else if (i<start || helpscreen_delay[i-start])
333     {
334       if (i>=start && helpscreen_delay[i-start])
335         helpscreen_delay[i-start]--;
336
337       while(helpscreen_action[j] != HA_NEXT)
338         j++;
339       j++;
340       i++;
341       continue;
342     }
343
344     j += 3*helpscreen_step[i-start];
345     graphic = helpscreen_action[j++];
346
347     if (helpscreen_frame[i-start])
348     {
349       frame = helpscreen_action[j++] - helpscreen_frame[i-start];
350       helpscreen_frame[i-start]--;
351     }
352     else
353     {
354       frame = 0;
355       helpscreen_frame[i-start] = helpscreen_action[j++]-1;
356     }
357
358     delay = helpscreen_action[j++];
359     helpscreen_delay[i-start] = delay;
360
361     if (helpscreen_action[j] == HA_NEXT)
362     {
363       if (!helpscreen_frame[i-start])
364         helpscreen_step[i-start] = 0;
365     }
366     else
367     {
368       if (!helpscreen_frame[i-start])
369         helpscreen_step[i-start]++;
370       while(helpscreen_action[j] != HA_NEXT)
371         j++;
372     }
373     j++;
374
375     DrawGraphicExtHiRes(drawto,gc,xstart,ystart+(i-start)*ystep,
376                         graphic+frame);
377     i++;
378   }
379
380   redraw_tiles += 28;
381   for(i=2;i<16;i++)
382     redraw[0][i] = redraw[1][i] = TRUE;
383   redraw_mask |= REDRAW_TILES;
384 }
385
386 void DrawHelpScreenElText(int start)
387 {
388   int i;
389   int xstart = SX+56, ystart = SY+65+2*32, ystep = TILEY+4;
390   char text[FULL_SXSIZE/FONT2_XSIZE+10];
391
392   ClearWindow();
393   DrawText(SX+16, SY+8,  "ROCKS'N'DIAMONDS",FS_BIG,FC_YELLOW);
394   DrawText(SX+25+16, SY+46, "Copyright ^1995 by Holger Schemel",
395            FS_SMALL,FC_RED);
396
397   sprintf(text,"The game elements:");
398   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+100,
399            text,FS_SMALL,FC_GREEN);
400
401   for(i=start;i<start+MAX_HELPSCREEN_ELS && i<num_helpscreen_els;i++)
402   {
403     DrawText(xstart,ystart+(i-start)*ystep+(*helpscreen_eltext[i][1] ? 0 : 8),
404              helpscreen_eltext[i][0],FS_SMALL,FC_YELLOW);
405     DrawText(xstart,ystart+(i-start)*ystep+16,
406              helpscreen_eltext[i][1],FS_SMALL,FC_YELLOW);
407   }
408
409   sprintf(text,"Press any key or button for next page");
410   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+SYSIZE-20,
411            text,FS_SMALL,FC_BLUE);
412 }
413
414 void DrawHelpScreenMusicText(int num)
415 {
416   int ystart = 150, ystep = 30;
417   char text[FULL_SXSIZE/FONT2_XSIZE+10];
418
419   FadeSounds();
420   ClearWindow();
421   DrawText(SX+16, SY+8,  "ROCKS'N'DIAMONDS",FS_BIG,FC_YELLOW);
422   DrawText(SX+25+16, SY+46, "Copyright ^1995 by Holger Schemel",
423            FS_SMALL,FC_RED);
424
425   sprintf(text,"The game background music loops:");
426   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+100,
427            text,FS_SMALL,FC_GREEN);
428
429   sprintf(text,"Excerpt from");
430   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+0*ystep,
431            text,FS_SMALL,FC_YELLOW);
432   sprintf(text,"%c%s%c",'\"',helpscreen_music[num][0],'\"');
433   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+1*ystep,
434            text,FS_SMALL,FC_RED);
435   sprintf(text,"by");
436   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+2*ystep,
437            text,FS_SMALL,FC_YELLOW);
438   sprintf(text,"%s",helpscreen_music[num][1]);
439   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+3*ystep,
440            text,FS_SMALL,FC_RED);
441   sprintf(text,"from the album");
442   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep,
443            text,FS_SMALL,FC_YELLOW);
444   sprintf(text,"%c%s%c",'\"',helpscreen_music[num][2],'\"');
445   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+5*ystep,
446            text,FS_SMALL,FC_RED);
447
448   sprintf(text,"Press any key or button for next page");
449   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+SYSIZE-20,
450            text,FS_SMALL,FC_BLUE);
451
452   PlaySoundLoop(background_loop[num]);
453 }
454
455 void DrawHelpScreenRegistrationText()
456 {
457   int ystart = 150, ystep = 30;
458   char text[FULL_SXSIZE/FONT2_XSIZE+10];
459
460   FadeSounds();
461   ClearWindow();
462   DrawText(SX+16, SY+8,  "ROCKS'N'DIAMONDS",FS_BIG,FC_YELLOW);
463   DrawText(SX+25+16, SY+46, "Copyright ^1995 by Holger Schemel",
464            FS_SMALL,FC_RED);
465
466   sprintf(text,"Registration information:");
467   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+100,
468            text,FS_SMALL,FC_GREEN);
469
470   sprintf(text,"Unregistered version");
471   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep,
472            text,FS_SMALL,FC_YELLOW);
473
474   sprintf(text,"Press any key or button for main menu");
475   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+SYSIZE-20,
476            text,FS_SMALL,FC_BLUE);
477 }
478
479 void DrawHelpScreen()
480 {
481   int i;
482
483   CloseDoor(DOOR_CLOSE_2);
484
485   for(i=0;i<MAX_HELPSCREEN_ELS;i++)
486     helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
487   helpscreen_musicpos = 0;
488   helpscreen_state = 0;
489   DrawHelpScreenElText(0);
490   DrawHelpScreenElAction(0);
491
492   FadeToFront();
493   InitAnimation();
494   PlaySoundLoop(SND_RHYTHMLOOP);
495 }
496
497 void HandleHelpScreen(int button)
498 {
499   static int hs_delay = 0;
500   int num_helpscreen_els_pages =
501     (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
502   int button_released = !button;
503   int i;
504
505   if (button_released)
506   {
507     if (helpscreen_state<num_helpscreen_els_pages-1)
508     {
509       for(i=0;i<MAX_HELPSCREEN_ELS;i++)
510         helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
511       helpscreen_state++;
512       DrawHelpScreenElText(helpscreen_state*MAX_HELPSCREEN_ELS);
513       DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
514     }
515     else if (helpscreen_state<num_helpscreen_els_pages+num_bg_loops-1)
516     {
517       helpscreen_state++;
518       DrawHelpScreenMusicText(helpscreen_state-num_helpscreen_els_pages);
519     }
520     else if (helpscreen_state==num_helpscreen_els_pages+num_bg_loops-1)
521     {
522       helpscreen_state++;
523       DrawHelpScreenRegistrationText();
524     }
525     else
526     {
527       FadeSounds();
528       DrawMainMenu();
529       game_status = MAINMENU;
530     }
531   }
532   else
533   {
534     if (DelayReached(&hs_delay,3))
535     {
536       if (helpscreen_state<num_helpscreen_els_pages)
537         DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
538     }
539     DoAnimation();
540   }
541
542   BackToFront();
543 }
544
545 void CheckCheat()
546 {
547   int old_handicap = player.handicap;
548
549   if (!strcmp(player.alias_name,"Artsoft"))
550     player.handicap = MAX(0,leveldir[leveldir_nr].num_ready-1);
551
552   if (player.handicap != old_handicap)
553   {
554     SavePlayerInfo(PLAYER_LEVEL);
555     level_nr = player.handicap;
556   }
557 }
558
559 void HandleTypeName(int newxpos, KeySym key)
560 {
561   static int xpos = 0, ypos = 2;
562   unsigned char ascii;
563
564   if (newxpos)
565   {
566     xpos = newxpos;
567     DrawText(SX+6*32,SY+ypos*32,player.alias_name,FS_BIG,FC_YELLOW);
568     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
569     return;
570   }
571
572   if ((key>=XK_A && key<=XK_Z) || (key>=XK_a && key<=XK_z && 
573       xpos<MAX_NAMELEN-1))
574   {
575     if (key>=XK_A && key<=XK_Z)
576       ascii = 'A'+(char)(key-XK_A);
577     if (key>=XK_a && key<=XK_z)
578       ascii = 'a'+(char)(key-XK_a);
579     player.alias_name[xpos] = ascii;
580     player.alias_name[xpos+1] = 0;
581     xpos++;
582     DrawTextExt(drawto,gc,SX+6*32,SY+ypos*32,
583                 player.alias_name,FS_BIG,FC_YELLOW);
584     DrawTextExt(window,gc,SX+6*32,SY+ypos*32,
585                 player.alias_name,FS_BIG,FC_YELLOW);
586     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
587   }
588   else if (key==XK_Delete && xpos>0)
589   {
590     player.alias_name[xpos] = 0;
591     xpos--;
592     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
593     DrawGraphic(xpos+7,ypos,GFX_LEERRAUM);
594   }
595   else if (key==XK_Return && xpos>0)
596   {
597     DrawText(SX+6*32,SY+ypos*32,player.alias_name,FS_BIG,FC_RED);
598     DrawGraphic(xpos+6,ypos,GFX_LEERRAUM);
599     SavePlayerInfo(PLAYER_SETUP);
600     CheckCheat();
601
602     game_status = MAINMENU;
603     DrawMainMenu();
604   }
605   BackToFront();
606 }
607
608 void DrawChooseLevel()
609 {
610   int i;
611
612   ClearWindow();
613   DrawText(SX,SY,"Level Directories",FS_BIG,FC_GREEN);
614   for(i=0;i<num_leveldirs;i++)
615   {
616     DrawText(SX+32,SY+(i+2)*32,leveldir[i].name,FS_BIG,FC_YELLOW);
617     DrawGraphic(0,i+2,GFX_KUGEL_BLAU);
618   }
619
620   FadeToFront();
621   InitAnimation();
622   HandleChooseLevel(0,0,0,0,MB_MENU_MARK);
623 }
624
625 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
626 {
627   static int choice = 3;
628   static int redraw = TRUE;
629   int x = (mx+32-SX)/32, y = (my+32-SY)/32;
630
631   if (redraw)
632   {
633     DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
634     redraw = FALSE;
635   }
636
637   if (dx || dy)
638   {
639     if (dy)
640     {
641       x = 1;
642       y = choice+dy;
643     }
644     else
645       x = y = 0;
646
647     if (y<3)
648       y = 3;
649     else if (y>num_leveldirs+2)
650       y = num_leveldirs+2;
651   }
652
653   if (!mx && !my && !dx && !dy)
654   {
655     x = 1;
656     y = choice;
657   }
658
659   if (x==1 && y>=3 && y<=num_leveldirs+2)
660   {
661     if (button)
662     {
663       if (y!=choice)
664       {
665         DrawGraphic(0,y-1,GFX_KUGEL_ROT);
666         DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
667       }
668       choice = y;
669     }
670     else
671     {
672       player.leveldir_nr = leveldir_nr = y-3;
673       LoadPlayerInfo(PLAYER_LEVEL);
674       SavePlayerInfo(PLAYER_SETUP);
675       CheckCheat();
676
677       game_status = MAINMENU;
678       DrawMainMenu();
679       redraw = TRUE;
680     }
681   }
682   BackToFront();
683
684   if (game_status==CHOOSELEVEL)
685     DoAnimation();
686 }
687
688 void DrawHallOfFame(int pos)
689 {
690   int y;
691   char txt[40];
692
693   CloseDoor(DOOR_CLOSE_2);
694
695   if (pos<0) 
696     LoadScore(level_nr);
697   ClearWindow();
698   DrawText(SX+64,SY+10,"Hall Of Fame",FS_BIG,FC_YELLOW);
699   sprintf(txt,"HighScores of Level %d",level_nr);
700   DrawText(SX+256-strlen(txt)*7,SY+48,txt,FS_SMALL,FC_RED);
701   for(y=0;y<MAX_SCORE_ENTRIES;y++)
702   {
703     DrawText(SX,SY+64+y*32,".................",FS_BIG,
704              (y==pos ? FC_RED : FC_GREEN));
705     DrawText(SX,SY+64+y*32,highscore[y].Name,FS_BIG,
706              (y==pos ? FC_RED : FC_GREEN));
707     DrawText(SX+12*32,SY+64+y*32,
708              int2str(highscore[y].Score,5),FS_BIG,
709              (y==pos ? FC_RED : FC_GREEN));
710   }
711
712   FadeToFront();
713   InitAnimation();
714   PlaySound(SND_HALLOFFAME);
715 }
716
717 void HandleHallOfFame(int button)
718 {
719   int button_released = !button;
720
721   if (button_released)
722   {
723     FadeSound(SND_HALLOFFAME);
724     game_status = MAINMENU;
725     DrawMainMenu();
726     BackToFront();
727   }
728   else
729     DoAnimation();
730 }
731
732 void DrawSetupScreen()
733 {
734   int i;
735
736   CloseDoor(DOOR_CLOSE_2);
737
738   ClearWindow();
739   DrawText(SX+16, SY+16,  "SETUP",FS_BIG,FC_YELLOW);
740   DrawText(SX+32, SY+2*32,"Sound:",FS_BIG,FC_GREEN);
741   DrawText(SX+32, SY+3*32,"Sound loops:",FS_BIG,FC_GREEN);
742   DrawText(SX+32, SY+4*32,"Game music:",FS_BIG,FC_GREEN);
743   DrawText(SX+32, SY+5*32,"Toons:",FS_BIG,FC_GREEN);
744   DrawText(SX+32, SY+6*32,"Buffered gfx:",FS_BIG,FC_GREEN);
745   DrawText(SX+32, SY+7*32,"Fading:",FS_BIG,FC_GREEN);
746   DrawText(SX+32, SY+8*32,"Auto-Record:",FS_BIG,FC_GREEN);
747   DrawText(SX+32, SY+9*32,"Joystick:",FS_BIG,FC_GREEN);
748   DrawText(SX+32, SY+10*32,"Cal. Joystick",FS_BIG,FC_GREEN);
749   DrawText(SX+32, SY+12*32,"Exit",FS_BIG,FC_GREEN);
750   DrawText(SX+32, SY+13*32,"Save and exit",FS_BIG,FC_GREEN);
751
752   if (SETUP_SOUND_ON(player.setup))
753     DrawText(SX+14*32, SY+2*32,"on",FS_BIG,FC_YELLOW);
754   else
755     DrawText(SX+14*32, SY+2*32,"off",FS_BIG,FC_BLUE);
756
757   if (SETUP_SOUND_LOOPS_ON(player.setup))
758     DrawText(SX+14*32, SY+3*32,"on",FS_BIG,FC_YELLOW);
759   else
760     DrawText(SX+14*32, SY+3*32,"off",FS_BIG,FC_BLUE);
761
762   if (SETUP_SOUND_MUSIC_ON(player.setup))
763     DrawText(SX+14*32, SY+4*32,"on",FS_BIG,FC_YELLOW);
764   else
765     DrawText(SX+14*32, SY+4*32,"off",FS_BIG,FC_BLUE);
766
767   if (SETUP_TOONS_ON(player.setup))
768     DrawText(SX+14*32, SY+5*32,"on",FS_BIG,FC_YELLOW);
769   else
770     DrawText(SX+14*32, SY+5*32,"off",FS_BIG,FC_BLUE);
771
772   if (!SETUP_DIRECT_DRAW_ON(player.setup))
773     DrawText(SX+14*32, SY+6*32,"on",FS_BIG,FC_YELLOW);
774   else
775     DrawText(SX+14*32, SY+6*32,"off",FS_BIG,FC_BLUE);
776
777   if (SETUP_FADING_ON(player.setup))
778     DrawText(SX+14*32, SY+7*32,"on",FS_BIG,FC_YELLOW);
779   else
780     DrawText(SX+14*32, SY+7*32,"off",FS_BIG,FC_BLUE);
781
782   if (SETUP_RECORD_EACH_GAME_ON(player.setup))
783     DrawText(SX+14*32, SY+8*32,"on",FS_BIG,FC_YELLOW);
784   else
785     DrawText(SX+14*32, SY+8*32,"off",FS_BIG,FC_BLUE);
786
787   if (SETUP_2ND_JOYSTICK_ON(player.setup))
788     DrawText(SX+14*32, SY+9*32,"2nd",FS_BIG,FC_YELLOW);
789   else
790     DrawText(SX+14*32, SY+9*32,"1st",FS_BIG,FC_YELLOW);
791
792   for(i=2;i<14;i++)
793     if (i!=11)
794       DrawGraphic(0,i,GFX_KUGEL_BLAU);
795
796   FadeToFront();
797   InitAnimation();
798   HandleSetupScreen(0,0,0,0,MB_MENU_MARK);
799 }
800
801 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
802 {
803   static int choice = 3;
804   static int redraw = TRUE;
805   int x = (mx+32-SX)/32, y = (my+32-SY)/32;
806
807   if (redraw)
808   {
809     DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
810     redraw = FALSE;
811   }
812
813   if (dx || dy)
814   {
815     if (dy)
816     {
817       x = 1;
818       y = choice+dy;
819     }
820     else
821       x = y = 0;
822
823     if (y==12)
824       y = (dy>0 ? 13 : 11);
825
826     if (y<3)
827       y = 3;
828     else if (y>14)
829       y = 14;
830   }
831
832   if (!mx && !my && !dx && !dy)
833   {
834     x = 1;
835     y = choice;
836   }
837
838   if (x==1 && y>=3 && y<=14 && y!=12)
839   {
840     if (button)
841     {
842       if (y!=choice)
843       {
844         DrawGraphic(0,y-1,GFX_KUGEL_ROT);
845         DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
846       }
847       choice = y;
848     }
849     else
850     {
851       int yy = y-1;
852
853       if (y==3 && sound_status==SOUND_AVAILABLE)
854       {
855         if (SETUP_SOUND_ON(player.setup))
856           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
857         else
858           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
859         player.setup ^= SETUP_SOUND;
860       }
861       else if (y==4 && sound_loops_allowed)
862       {
863         if (SETUP_SOUND_LOOPS_ON(player.setup))
864           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
865         else
866           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
867         player.setup ^= SETUP_SOUND_LOOPS;
868       }
869       else if (y==5 && sound_loops_allowed)
870       {
871         if (SETUP_SOUND_MUSIC_ON(player.setup))
872           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
873         else
874           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
875         player.setup ^= SETUP_SOUND_MUSIC;
876       }
877       else if (y==6)
878       {
879         if (SETUP_TOONS_ON(player.setup))
880           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
881         else
882           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
883         player.setup ^= SETUP_TOONS;
884       }
885       else if (y==7)
886       {
887         if (!SETUP_DIRECT_DRAW_ON(player.setup))
888           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
889         else
890           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
891         player.setup ^= SETUP_DIRECT_DRAW;
892       }
893       else if (y==8)
894       {
895         if (SETUP_FADING_ON(player.setup))
896           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
897         else
898           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
899         player.setup ^= SETUP_FADING;
900       }
901       else if (y==9)
902       {
903         if (SETUP_RECORD_EACH_GAME_ON(player.setup))
904           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
905         else
906           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
907         player.setup ^= SETUP_RECORD_EACH_GAME;
908       }
909       else if (y==10)
910       {
911         if (SETUP_2ND_JOYSTICK_ON(player.setup))
912           DrawText(SX+14*32, SY+yy*32,"1st",FS_BIG,FC_YELLOW);
913         else
914           DrawText(SX+14*32, SY+yy*32,"2nd",FS_BIG,FC_YELLOW);
915         player.setup ^= SETUP_2ND_JOYSTICK;
916       }
917       else if (y==11)
918       {
919         CalibrateJoystick();
920         redraw = TRUE;
921       }
922       else if (y==13 || y==14)
923       {
924         if (y==14)
925         {
926           SavePlayerInfo(PLAYER_SETUP);
927           SaveJoystickData();
928         }
929
930         game_status = MAINMENU;
931         DrawMainMenu();
932         redraw = TRUE;
933       }
934     }
935   }
936   BackToFront();
937
938   if (game_status==SETUP)
939     DoAnimation();
940 }
941
942 void HandleVideoButtons(int mx, int my, int button)
943 {
944   if (game_status!=MAINMENU && game_status!=PLAYING)
945     return;
946
947   switch(CheckVideoButtons(mx,my,button))
948   {
949     case BUTTON_VIDEO_EJECT:
950       TapeStop();
951       if (!TAPE_IS_EMPTY(tape))
952         SaveLevelTape(tape.level_nr);
953       else
954         AreYouSure("Tape is empty !",AYS_CONFIRM);
955       DrawCompleteVideoDisplay();
956       break;
957     case BUTTON_VIDEO_STOP:
958       TapeStop();
959       break;
960     case BUTTON_VIDEO_PAUSE:
961       TapeTogglePause();
962       break;
963     case BUTTON_VIDEO_REC:
964       if (tape.pausing)
965         TapeTogglePause();
966       else if (game_status==MAINMENU)
967         TapeInitRecording();
968       break;
969     case BUTTON_VIDEO_PLAY:
970       if (tape.pausing)
971         TapeTogglePause();
972       else if (game_status==MAINMENU)
973         TapeInitPlaying();
974       break;
975     default:
976       break;
977   }
978 }
979
980 void HandleSoundButtons(int mx, int my, int button)
981 {
982   if (game_status!=PLAYING)
983     return;
984
985   switch(CheckSoundButtons(mx,my,button))
986   {
987     case BUTTON_SOUND_MUSIC:
988       if (sound_music_on)
989       { 
990         sound_music_on = FALSE;
991         player.setup &= ~SETUP_SOUND_MUSIC;
992         FadeSound(background_loop[level_nr % num_bg_loops]);
993         DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF);
994       }
995       else if (sound_loops_allowed)
996       { 
997         sound_music_on = TRUE;
998         player.setup |= SETUP_SOUND_MUSIC;
999         PlaySoundLoop(background_loop[level_nr % num_bg_loops]);
1000         DrawSoundDisplay(BUTTON_SOUND_MUSIC_ON);
1001       }
1002       else
1003         DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF);
1004       break;
1005     case BUTTON_SOUND_LOOPS:
1006       if (sound_loops_on)
1007       { 
1008         sound_loops_on = FALSE;
1009         player.setup &= ~SETUP_SOUND_LOOPS;
1010         DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF);
1011       }
1012       else if (sound_loops_allowed)
1013       { 
1014         sound_loops_on = TRUE;
1015         player.setup |= SETUP_SOUND_LOOPS;
1016         DrawSoundDisplay(BUTTON_SOUND_LOOPS_ON);
1017       }
1018       else
1019         DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF);
1020       break;
1021     case BUTTON_SOUND_SOUND:
1022       if (sound_on)
1023       { 
1024         sound_on = FALSE;
1025         player.setup &= ~SETUP_SOUND;
1026         DrawSoundDisplay(BUTTON_SOUND_SOUND_OFF);
1027       }
1028       else if (sound_status==SOUND_AVAILABLE)
1029       { 
1030         sound_on = TRUE;
1031         player.setup |= SETUP_SOUND;
1032         DrawSoundDisplay(BUTTON_SOUND_SOUND_ON);
1033       }
1034       else
1035         DrawSoundDisplay(BUTTON_SOUND_SOUND_OFF);
1036       break;
1037     default:
1038       break;
1039   }
1040 }
1041
1042 void HandleGameButtons(int mx, int my, int button)
1043 {
1044   if (game_status!=PLAYING)
1045     return;
1046
1047   switch(CheckGameButtons(mx,my,button))
1048   {
1049     case BUTTON_GAME_STOP:
1050       if (AreYouSure("Do you really want to quit the game ?",
1051                       AYS_ASK | AYS_STAY_CLOSED))
1052       { 
1053         game_status = MAINMENU;
1054         DrawMainMenu();
1055       }
1056       else
1057         OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
1058       break;
1059     case BUTTON_GAME_PAUSE:
1060       if (tape.pausing)
1061       {
1062         tape.pausing = FALSE;
1063         DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
1064       }
1065       else
1066       {
1067         tape.pausing = TRUE;
1068         DrawVideoDisplay(VIDEO_STATE_PAUSE_ON,0);
1069       }
1070       break;
1071     case BUTTON_GAME_PLAY:
1072       if (tape.pausing)
1073       {
1074         tape.pausing = FALSE;
1075         DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
1076       }
1077       break;
1078     default:
1079       break;
1080   }
1081 }
1082
1083 int CheckVideoButtons(int mx, int my, int button)
1084 {
1085   int return_code = 0;
1086   static int choice = -1;
1087   static BOOL pressed = FALSE;
1088   static int video_button[5] =
1089   {
1090     VIDEO_PRESS_EJECT_ON,
1091     VIDEO_PRESS_STOP_ON,
1092     VIDEO_PRESS_PAUSE_ON,
1093     VIDEO_PRESS_REC_ON,
1094     VIDEO_PRESS_PLAY_ON
1095   };
1096
1097   if (button)
1098   {
1099     if (!motion_status)         /* Maustaste neu gedrückt */
1100     {
1101       if (ON_VIDEO_BUTTON(mx,my))
1102       {
1103         choice = VIDEO_BUTTON(mx);
1104         pressed = TRUE;
1105         DrawVideoDisplay(video_button[choice],0);
1106       }
1107     }
1108     else                        /* Mausbewegung bei gedrückter Maustaste */
1109     {
1110       if ((!ON_VIDEO_BUTTON(mx,my) || VIDEO_BUTTON(mx)!=choice) &&
1111           choice>=0 && pressed)
1112       {
1113         pressed = FALSE;
1114         DrawVideoDisplay(video_button[choice]<<1,0);
1115       }
1116       else if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && !pressed)
1117       {
1118         pressed = TRUE;
1119         DrawVideoDisplay(video_button[choice],0);
1120       }
1121     }
1122   }
1123   else                          /* Maustaste wieder losgelassen */
1124   {
1125     if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && pressed)
1126     {
1127       DrawVideoDisplay(video_button[choice]<<1,0);
1128       return_code = choice+1;
1129       choice = -1;
1130       pressed = FALSE;
1131     }
1132     else
1133     {
1134       choice = -1;
1135       pressed = FALSE;
1136     }
1137   }
1138
1139   BackToFront();
1140   return(return_code);
1141 }
1142
1143 int CheckSoundButtons(int mx, int my, int button)
1144 {
1145   int return_code = 0;
1146   static int choice = -1;
1147   static BOOL pressed = FALSE;
1148   int sound_state[3];
1149
1150   sound_state[0] = BUTTON_SOUND_MUSIC | (BUTTON_ON * sound_music_on);
1151   sound_state[1] = BUTTON_SOUND_LOOPS | (BUTTON_ON * sound_loops_on);
1152   sound_state[2] = BUTTON_SOUND_SOUND | (BUTTON_ON * sound_on);
1153
1154   if (button)
1155   {
1156     if (!motion_status)         /* Maustaste neu gedrückt */
1157     {
1158       if (ON_SOUND_BUTTON(mx,my))
1159       {
1160         choice = SOUND_BUTTON(mx);
1161         pressed = TRUE;
1162         DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED);
1163       }
1164     }
1165     else                        /* Mausbewegung bei gedrückter Maustaste */
1166     {
1167       if ((!ON_SOUND_BUTTON(mx,my) || SOUND_BUTTON(mx)!=choice) &&
1168           choice>=0 && pressed)
1169       {
1170         pressed = FALSE;
1171         DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED);
1172       }
1173       else if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && !pressed)
1174       {
1175         pressed = TRUE;
1176         DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED);
1177       }
1178     }
1179   }
1180   else                          /* Maustaste wieder losgelassen */
1181   {
1182     if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && pressed)
1183     {
1184       DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED);
1185       return_code = 1<<choice;
1186       choice = -1;
1187       pressed = FALSE;
1188     }
1189     else
1190     {
1191       choice = -1;
1192       pressed = FALSE;
1193     }
1194   }
1195
1196   BackToFront();
1197   return(return_code);
1198 }
1199
1200 int CheckGameButtons(int mx, int my, int button)
1201 {
1202   int return_code = 0;
1203   static int choice = -1;
1204   static BOOL pressed = FALSE;
1205   int game_state[3] =
1206   {
1207     BUTTON_GAME_STOP,
1208     BUTTON_GAME_PAUSE,
1209     BUTTON_GAME_PLAY
1210   };
1211
1212   if (button)
1213   {
1214     if (!motion_status)         /* Maustaste neu gedrückt */
1215     {
1216       if (ON_GAME_BUTTON(mx,my))
1217       {
1218         choice = GAME_BUTTON(mx);
1219         pressed = TRUE;
1220         DrawGameButton(game_state[choice] | BUTTON_PRESSED);
1221       }
1222     }
1223     else                        /* Mausbewegung bei gedrückter Maustaste */
1224     {
1225       if ((!ON_GAME_BUTTON(mx,my) || GAME_BUTTON(mx)!=choice) &&
1226           choice>=0 && pressed)
1227       {
1228         pressed = FALSE;
1229         DrawGameButton(game_state[choice] | BUTTON_RELEASED);
1230       }
1231       else if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && !pressed)
1232       {
1233         pressed = TRUE;
1234         DrawGameButton(game_state[choice] | BUTTON_PRESSED);
1235       }
1236     }
1237   }
1238   else                          /* Maustaste wieder losgelassen */
1239   {
1240     if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && pressed)
1241     {
1242       DrawGameButton(game_state[choice] | BUTTON_RELEASED);
1243       return_code = 1<<choice;
1244       choice = -1;
1245       pressed = FALSE;
1246     }
1247     else
1248     {
1249       choice = -1;
1250       pressed = FALSE;
1251     }
1252   }
1253
1254   BackToFront();
1255   return(return_code);
1256 }
1257
1258 int CheckChooseButtons(int mx, int my, int button)
1259 {
1260   int return_code = 0;
1261   static int choice = -1;
1262   static BOOL pressed = FALSE;
1263   static int choose_button[5] =
1264   {
1265     BUTTON_OK,
1266     BUTTON_NO
1267   };
1268
1269   if (button)
1270   {
1271     if (!motion_status)         /* Maustaste neu gedrückt */
1272     {
1273       if (ON_CHOOSE_BUTTON(mx,my))
1274       {
1275         choice = CHOOSE_BUTTON(mx);
1276         pressed = TRUE;
1277         DrawChooseButton(choose_button[choice] | BUTTON_PRESSED);
1278       }
1279     }
1280     else                        /* Mausbewegung bei gedrückter Maustaste */
1281     {
1282       if ((!ON_CHOOSE_BUTTON(mx,my) || CHOOSE_BUTTON(mx)!=choice) &&
1283           choice>=0 && pressed)
1284       {
1285         pressed = FALSE;
1286         DrawChooseButton(choose_button[choice] | BUTTON_RELEASED);
1287       }
1288       else if (ON_CHOOSE_BUTTON(mx,my) &&CHOOSE_BUTTON(mx)==choice && !pressed)
1289       {
1290         pressed = TRUE;
1291         DrawChooseButton(choose_button[choice] | BUTTON_PRESSED);
1292       }
1293     }
1294   }
1295   else                          /* Maustaste wieder losgelassen */
1296   {
1297     if (ON_CHOOSE_BUTTON(mx,my) && CHOOSE_BUTTON(mx)==choice && pressed)
1298     {
1299       DrawChooseButton(choose_button[choice] | BUTTON_RELEASED);
1300       return_code = choice+1;
1301       choice = -1;
1302       pressed = FALSE;
1303     }
1304     else
1305     {
1306       choice = -1;
1307       pressed = FALSE;
1308     }
1309   }
1310
1311   BackToFront();
1312   return(return_code);
1313 }
1314
1315 int CheckConfirmButton(int mx, int my, int button)
1316 {
1317   int return_code = 0;
1318   static int choice = -1;
1319   static BOOL pressed = FALSE;
1320
1321   if (button)
1322   {
1323     if (!motion_status)         /* Maustaste neu gedrückt */
1324     {
1325       if (ON_CONFIRM_BUTTON(mx,my))
1326       {
1327         choice = 0;
1328         pressed = TRUE;
1329         DrawConfirmButton(BUTTON_PRESSED);
1330       }
1331     }
1332     else                        /* Mausbewegung bei gedrückter Maustaste */
1333     {
1334       if (!ON_CONFIRM_BUTTON(mx,my) && choice>=0 && pressed)
1335       {
1336         pressed = FALSE;
1337         DrawConfirmButton(BUTTON_RELEASED);
1338       }
1339       else if (ON_CONFIRM_BUTTON(mx,my) && !pressed)
1340       {
1341         pressed = TRUE;
1342         DrawConfirmButton(BUTTON_PRESSED);
1343       }
1344     }
1345   }
1346   else                          /* Maustaste wieder losgelassen */
1347   {
1348     if (ON_CONFIRM_BUTTON(mx,my) && pressed)
1349     {
1350       DrawConfirmButton(BUTTON_RELEASED);
1351       return_code = BUTTON_CONFIRM;
1352       choice = -1;
1353       pressed = FALSE;
1354     }
1355     else
1356     {
1357       choice = -1;
1358       pressed = FALSE;
1359     }
1360   }
1361
1362   BackToFront();
1363   return(return_code);
1364 }
1365
1366 void DrawCompleteVideoDisplay()
1367 {
1368   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
1369             DOOR_GFX_PAGEX3,DOOR_GFX_PAGEY2, VXSIZE,VYSIZE, VX,VY);
1370   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
1371             DOOR_GFX_PAGEX4+VIDEO_CONTROL_XPOS,
1372             DOOR_GFX_PAGEY2+VIDEO_CONTROL_YPOS,
1373             VIDEO_CONTROL_XSIZE,VIDEO_CONTROL_YSIZE,
1374             VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS);
1375
1376   DrawVideoDisplay(VIDEO_ALL_OFF,0);
1377   if (tape.date && tape.length)
1378   {
1379     DrawVideoDisplay(VIDEO_STATE_DATE_ON,tape.date);
1380     DrawVideoDisplay(VIDEO_STATE_TIME_ON,0);
1381   }
1382
1383   XCopyArea(display,drawto,pix[PIX_DB_DOOR],gc,
1384             VX,VY, VXSIZE,VYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2);
1385 }