File: menu.c

package info (click to toggle)
freedroid 1.2.3.apk-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,276 kB
  • sloc: ansic: 12,743; objc: 185; makefile: 156; sh: 17; lisp: 6
file content (1507 lines) | stat: -rw-r--r-- 43,296 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
/*
 *
 *   Copyright (c) 2016  Reinhard Prix
 *   Copyright (c) 1994, 2002, 2003  Johannes Prix
 *   Copyright (c) 1994, 2002, 2003  Reinhard Prix
 *
 *
 *  This file is part of Freedroid
 *
 *  Freedroid is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Freedroid is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Freedroid; see the file COPYING. If not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 */

/*----------------------------------------------------------------------
 *
 * Desc: all menu functions and their subfunctions for Freedroid
 *
 *----------------------------------------------------------------------*/

#define _menu_c

// ----- includes --------------------
#include "system.h"

#include "defs.h"
#include "struct.h"
#include "global.h"
#include "proto.h"
#include "map.h"

// ----- global variables --------------------
extern int key_cmds[CMD_LAST][3];
extern char *cmd_strings[CMD_LAST];
extern char *keystr[INPUT_LAST];


SDL_Surface *Menu_Background = NULL;
int fheight;  // font height of Menu-font

// ----- Macros --------------------
// ----- local types ----------
typedef struct MenuEntry_s
{
  const char *name;			/**< menu entry string */
  const char *(*handler)(MenuAction_t action);	/**< handler & info function for this menu entry (none if NULL) */
  const struct MenuEntry_s *submenu; 	/**< enter this submenu (if non-NULL) */
} MenuEntry_t;


// ----- local prototypes ----------
void Key_Config_Menu (void);
void Display_Key_Config (int selx, int sely);
void ShowCredits (void);

void ShowMenu ( const MenuEntry_t *menu );

const char *handle_StrictlyClassic ( MenuAction_t action );
const char *handle_WindowType ( MenuAction_t action );
const char *handle_Theme ( MenuAction_t action );
const char *handle_DroidTalk ( MenuAction_t action );
const char *handle_AllMapVisible ( MenuAction_t action );
const char *handle_ShowDecals ( MenuAction_t action );
const char *handle_TransferIsActivate ( MenuAction_t action );
const char *handle_FireIsTransfer ( MenuAction_t action );
const char *handle_EmptyLevelSpeedup ( MenuAction_t action );

const char *handle_MusicVolume ( MenuAction_t action );
const char *handle_SoundVolume ( MenuAction_t action );
const char *handle_Fullscreen ( MenuAction_t action );

const char *handle_ShowPosition ( MenuAction_t action );
const char *handle_ShowFramerate ( MenuAction_t action );
const char *handle_ShowEnergy ( MenuAction_t action );
const char *handle_ShowDeathCount ( MenuAction_t action );

const char *handle_OpenLevelEditor ( MenuAction_t action );
const char *handle_Highscores ( MenuAction_t action );
const char *handle_Credits ( MenuAction_t action );
const char *handle_ConfigureKeys ( MenuAction_t action );
const char *handle_QuitGame ( MenuAction_t action );

const char *handle_LE_Exit ( MenuAction_t action );
const char *handle_LE_LevelNumber ( MenuAction_t action );
const char *handle_LE_Color ( MenuAction_t action );
const char *handle_LE_SizeX ( MenuAction_t action );
const char *handle_LE_SizeY ( MenuAction_t action );
const char *handle_LE_Name ( MenuAction_t action );
const char *handle_LE_Music ( MenuAction_t action );
const char *handle_LE_Comment ( MenuAction_t action );
const char *handle_LE_SaveShip ( MenuAction_t action );

void setTheme ( int theme_index );
const char *isToggleOn ( int toggle );
void flipToggle ( int *toggle );
void menuChangeFloat ( MenuAction_t action, float *val, float step, float min_val, float max_val );
void menuChangeInt ( MenuAction_t action, int *val, int step, int min_val, int max_val );

// ----- define menus ----------
MenuEntry_t LegacyMenu[] =
  {
    { "Back",			NULL,			NULL },
    { "Set Strictly Classic",	handle_StrictlyClassic,	NULL },
    { "Combat Window: ", 	handle_WindowType, 	NULL },
    { "Graphics Theme: ", 	handle_Theme,		NULL },
    { "Droid Talk: ", 		handle_DroidTalk,	NULL },
    { "Show Decals: ", 		handle_ShowDecals,	NULL },
    { "All Map Visible: ", 	handle_AllMapVisible,	NULL },
#ifndef ANDROID
    { "Transfer = Activate: ", 	handle_TransferIsActivate, NULL },
    { "Hold Fire to Transfer: ",handle_FireIsTransfer,	NULL },
#endif
    { "Empty Level Speedup: ",  handle_EmptyLevelSpeedup, NULL },
    { NULL,			NULL, 			NULL }
  };

MenuEntry_t GraphicsSoundMenu[] =
  {
    { "Back", 			NULL,			NULL },
    { "Music Volume: ", 	handle_MusicVolume,	NULL },
    { "Sound Volume: ", 	handle_SoundVolume,	NULL },
    { "Fullscreen Mode: ", 	handle_Fullscreen,	NULL },
    { NULL,			NULL, 			NULL }
  };

MenuEntry_t HUDMenu[] =
{
  { "Back", 			NULL,			NULL },
  { "Show Position: ", 		handle_ShowPosition,	NULL },
  { "Show Framerate: ",		handle_ShowFramerate,	NULL },
  { "Show Energy: ",		handle_ShowEnergy,	NULL },
//  { "Show DeathCount: ",	handle_ShowDeathCount,	NULL },
  { NULL,			NULL, 			NULL }
};

MenuEntry_t LevelEditorMenu[] =
{
  { "Exit Level Editor", 	handle_LE_Exit,         NULL },
  { "Current Level: ", 		handle_LE_LevelNumber,	NULL },
  { "Level Color: ",		handle_LE_Color,	NULL },
  { "Levelsize X: ",		handle_LE_SizeX,	NULL },
  { "Levelsize Y: ",		handle_LE_SizeY,	NULL },
  { "Level Name: ", 		handle_LE_Name,		NULL },
  //{ "Background Music: ",	handle_LE_Music,	NULL },
  //{ "Level Comment: ",	handle_LE_Comment,	NULL },
  { "Save ship: ",              handle_LE_SaveShip,	NULL },
  { NULL,			NULL, 			NULL }
};

MenuEntry_t MainMenu[] =
  {
    { "Back to Game", 		NULL, 				NULL },
    { "Graphics & Sound", 	NULL, 				GraphicsSoundMenu },
    { "Legacy Options", 	NULL,				LegacyMenu },
    { "HUD Settings",		NULL, 				HUDMenu },
#ifndef ANDROID
    { "Level Editor",		handle_OpenLevelEditor,		NULL },
#endif
    { "Highscores", 		handle_Highscores, 		NULL },
    { "Credits", 		handle_Credits, 		NULL },
#ifndef ANDROID
    { "Configure Keys", 	handle_ConfigureKeys, 		NULL },
#endif
    { "Quit Game",		handle_QuitGame, 		NULL },
    { NULL,			NULL, 				NULL }
  };


const char *
isToggleOn ( int toggle )
{
  return toggle ? "YES" : "NO";
}
void
flipToggle ( int *toggle )
{
  if (toggle) {
    //MoveLiftSound();
    MenuItemSelectedSound();
    (*toggle) = !(*toggle);
  }
  return;
}

void
setTheme ( int theme_index )
{
  if ( (theme_index < 0) || ( theme_index > AllThemes.num_themes - 1 ) )
    {
      DebugPrintf ( 0, "%s: Coding error: invalid theme index '%s' requested, must be within [0, %d]\n", __func__, theme_index, AllThemes.num_themes - 1 );
      Terminate(ERR);
    }
  AllThemes.cur_tnum = theme_index;
  strcpy ( GameConfig.Theme_Name, AllThemes.theme_name [ AllThemes.cur_tnum ] );
  InitPictures();
  return;
} // setTheme()
void
menuChangeFloat ( MenuAction_t action, float *val, float step, float min_val, float max_val )
{
  if ( (action == ACTION_RIGHT) && ( (*val) < max_val ) )
    {
      MoveLiftSound();
      (*val) += step;
      if ( (*val) > max_val ) (*val) = max_val;
    }
  if ( (action == ACTION_LEFT) && ( (*val) > min_val ) )
    {
      MoveLiftSound();
      (*val) -= step;
      if ( (*val) < min_val ) (*val) = min_val;
    }
  return;
} // menuChangeFloat()
void
menuChangeInt ( MenuAction_t action, int *val, int step, int min_val, int max_val )
{
  float float_val = (float)(*val);
  menuChangeFloat ( action, &float_val, step, min_val, max_val );
  (*val) = (int)round(float_val);
  return;
} // menuChangeInt()


// ========== menu entry handler functions ====================
const char *
handle_StrictlyClassic ( MenuAction_t action )
{
  if ( action == ACTION_CLICK )
    {
      MenuItemSelectedSound();
      GameConfig.Droid_Talk = FALSE;
      GameConfig.ShowDecals = FALSE;
      GameConfig.TakeoverActivates = TRUE;
      GameConfig.FireHoldTakeover = TRUE;
      GameConfig.AllMapVisible = TRUE;
      GameConfig.emptyLevelSpeedup = 1.0;

      // set window type
      GameConfig.FullUserRect = FALSE;
      Copy_Rect (Classic_User_Rect, User_Rect);
      // set theme
      setTheme ( classic_theme_index );
      InitiateMenu (FALSE);
    }

  return NULL;
}

const char *
handle_WindowType ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return GameConfig.FullUserRect ? "Full" : "Classic";
  }

  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) )
    {
      flipToggle ( &GameConfig.FullUserRect );
      if ( GameConfig.FullUserRect )
        Copy_Rect ( Full_User_Rect, User_Rect );
      else
        Copy_Rect ( Classic_User_Rect, User_Rect );

      InitiateMenu (FALSE);
    }
  return NULL;
} // handle_WindowType()

const char *
handle_Theme ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return AllThemes.theme_name [ AllThemes.cur_tnum ];
  }

  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) )
    {
      MoveLiftSound();
      int tnum = AllThemes.cur_tnum;
      if ( (action == ACTION_CLICK) || (action == ACTION_RIGHT) )
        tnum ++;
      else
        tnum --;

      if ( tnum < 0 ) tnum = AllThemes.num_themes - 1;
      if ( tnum > AllThemes.num_themes - 1 ) tnum = 0;

      setTheme ( tnum );
      InitiateMenu (FALSE);
    }

  return NULL;
} // handle_Theme()

const char *
handle_DroidTalk ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.Droid_Talk );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) ) {
    flipToggle ( &GameConfig.Droid_Talk );
  }
  return NULL;
}

const char *
handle_AllMapVisible ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.AllMapVisible );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) )
    {
      flipToggle ( &GameConfig.AllMapVisible );
      InitiateMenu (FALSE);
    }
  return NULL;
}

const char *
handle_ShowDecals ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.ShowDecals );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) )
    {
      flipToggle ( &GameConfig.ShowDecals );
      InitiateMenu (FALSE);
    }
  return NULL;
}

const char *
handle_TransferIsActivate ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.TakeoverActivates );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) ) {
    flipToggle ( &GameConfig.TakeoverActivates );
  }
  return NULL;
}

const char *
handle_FireIsTransfer ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.FireHoldTakeover );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) ) {
    flipToggle ( &GameConfig.FireHoldTakeover );
  }
  return NULL;
}

const char *
handle_EmptyLevelSpeedup ( MenuAction_t action )
{
  static char buf[256];
  if ( action == ACTION_INFO ) {
    sprintf ( buf, "%3.1f" , GameConfig.emptyLevelSpeedup );
    return buf;
  }

  menuChangeFloat ( action, &(GameConfig.emptyLevelSpeedup), 0.1, 0.5, 2.0 );
  return NULL;
}

const char *
handle_MusicVolume ( MenuAction_t action )
{
  static char buf[256];
  if ( action == ACTION_INFO ) {
    sprintf ( buf, "%4.2f" , GameConfig.Current_BG_Music_Volume );
    return buf;
  }

  menuChangeFloat ( action, &(GameConfig.Current_BG_Music_Volume), 0.05, 0, 1 );
  Set_BG_Music_Volume ( GameConfig.Current_BG_Music_Volume );
  return NULL;
}

const char *
handle_SoundVolume ( MenuAction_t action )
{
  static char buf[256];
  if ( action == ACTION_INFO ) {
    sprintf ( buf, "%4.2f" , GameConfig.Current_Sound_FX_Volume );
    return buf;
  }

  menuChangeFloat ( action, &(GameConfig.Current_Sound_FX_Volume), 0.05, 0, 1 );
  Set_Sound_FX_Volume( GameConfig.Current_Sound_FX_Volume );
  return NULL;
}

const char *
handle_Fullscreen ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.UseFullscreen );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) ) {
      toggle_fullscreen();
      MenuItemSelectedSound();
  }
  return NULL;
}



const char *
handle_ShowPosition ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.Draw_Position );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) ) {
    flipToggle ( &GameConfig.Draw_Position );
    InitiateMenu (FALSE);
  }
  return NULL;
}
const char *
handle_ShowFramerate ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.Draw_Framerate );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) ) {
    flipToggle ( &GameConfig.Draw_Framerate );
    InitiateMenu (FALSE);
  }
  return NULL;
}
const char *
handle_ShowEnergy ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.Draw_Energy );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) ) {
    flipToggle ( &GameConfig.Draw_Energy );
    InitiateMenu (FALSE);
  }
  return NULL;
}
const char *
handle_ShowDeathCount ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return isToggleOn ( GameConfig.Draw_DeathCount );
  }
  if ( (action == ACTION_CLICK) || (action == ACTION_LEFT) || (action == ACTION_RIGHT) ) {
    flipToggle ( &GameConfig.Draw_DeathCount );
    InitiateMenu (FALSE);
  }
  return NULL;
}

const char *handle_OpenLevelEditor ( MenuAction_t action )
{
  if ( action == ACTION_CLICK ) {
    MenuItemSelectedSound();
    LevelEditor();
  }
  return NULL;
}

const char *handle_LE_Exit ( MenuAction_t action )
{
  if ( action == ACTION_CLICK )
    {
      MenuItemSelectedSound();
      quit_LevelEditor = TRUE;
      quit_Menu = TRUE;
    }
  return NULL;
}

const char *handle_LE_LevelNumber ( MenuAction_t action )
{
  static char buf[256];
  if ( action == ACTION_INFO ) {
    sprintf ( buf, "%d" , CurLevel->levelnum );
    return buf;
  }

  int curlevel = CurLevel->levelnum;
  menuChangeInt ( action, &curlevel, 1, 0, curShip.num_levels -1 );
  Teleport ( curlevel, 3 , 3 );
  Switch_Background_Music_To ( BYCOLOR );
  InitiateMenu(FALSE);

  return NULL;
}

const char *handle_LE_Color ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return ColorNames[CurLevel->color];
  }
  menuChangeInt ( action, &(CurLevel->color), 1, 0, numLevelColors-1 );
  Switch_Background_Music_To ( BYCOLOR );
  InitiateMenu(FALSE);

  return NULL;
}

const char *handle_LE_SizeX ( MenuAction_t action )
{
  static char buf[256];
  if ( action == ACTION_INFO ) {
    sprintf ( buf, "%d" , CurLevel->xlen );
    return buf;
  }

  int oldxlen = CurLevel->xlen;
  menuChangeInt ( action, &(CurLevel->xlen), 1, 0, MAX_MAP_COLS-1 );
  size_t newmem = CurLevel->xlen * sizeof( CurLevel->map[0][0] );
  // adjust memory sizes for new value
  int row;
  for ( row = 0 ; row < CurLevel->ylen ; row++ )
    {
      CurLevel->map[row] = realloc( CurLevel->map[row], newmem );
      if ( CurLevel->map[row] == NULL ) {
        DebugPrintf ( 0, "Failed to re-allocate to %z bytes in map row %d\n", newmem, row );
        Terminate(ERR);
      }
      if ( CurLevel->xlen > oldxlen ) { // fill new map area with VOID
        CurLevel->map[ row ] [ CurLevel->xlen - 1 ] = VOID;
      }
    }
  InitiateMenu(FALSE);
  return NULL;
}

const char *handle_LE_SizeY ( MenuAction_t action )
{
  static char buf[256];
  if ( action == ACTION_INFO ) {
    sprintf ( buf, "%d" , CurLevel->ylen );
    return buf;
  }

  int oldylen = CurLevel->ylen;
  menuChangeInt ( action, &(CurLevel->ylen), 1, 0, MAX_MAP_ROWS-1 );
  if ( oldylen > CurLevel->ylen )
    {
      free ( CurLevel->map[oldylen - 1] );
      CurLevel->map[oldylen - 1] = NULL;
    }
  else if ( oldylen < CurLevel->ylen )
    {
      CurLevel->map[ CurLevel->ylen-1 ] = MyMalloc ( CurLevel->xlen * sizeof( CurLevel->map[0][0] ) );
      memset ( CurLevel->map[ CurLevel->ylen-1 ], VOID, CurLevel->xlen * sizeof( CurLevel->map[0][0] ) );
    }

  InitiateMenu (FALSE);
  return NULL;
}

const char *handle_LE_Name ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return CurLevel->Levelname;
  }

  if ( action == ACTION_CLICK )
    {
      DisplayText ("New level name: ", Menu_Rect.x-2*fheight, Menu_Rect.y - 3*fheight, &Full_User_Rect );
      SDL_Flip( ne_screen );
      free ( CurLevel->Levelname );
      CurLevel->Levelname = GetString(15, 2);
      InitiateMenu (FALSE);
    }

  return NULL;
}

const char *handle_LE_Music ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return CurLevel->Background_Song_Name;
  }

  if ( action == ACTION_CLICK )
    {
      DisplayText ("Music filename: ", Menu_Rect.x - 2*fheight, Menu_Rect.y - 3*fheight, &Full_User_Rect);
      SDL_Flip( ne_screen );
      free ( CurLevel->Background_Song_Name );
      CurLevel->Background_Song_Name = GetString(20, 2);
      Switch_Background_Music_To ( CurLevel->Background_Song_Name );
    }

  return NULL;
}

const char *handle_LE_Comment ( MenuAction_t action )
{
  if ( action == ACTION_INFO ) {
    return CurLevel->Level_Enter_Comment;
  }
  return NULL;
}

const char *handle_LE_SaveShip ( MenuAction_t action )
{
  const char *shipname = "Testship";
  static char fname[255];
  snprintf ( fname, sizeof(fname)-1, "%s%s", shipname, SHIP_EXT );
  if ( action == ACTION_INFO ) {
    return fname;
  }
  if ( action == ACTION_CLICK )
    {
      SaveShip( shipname );
      char output[512];
      snprintf ( output, sizeof(output)-1, "Ship saved as '%s'", fname );
      CenteredPutString (ne_screen, 3*FontHeight(Menu_BFont), output );
      SDL_Flip ( ne_screen );
      wait_for_key_pressed();
      InitiateMenu (FALSE);
    }

  return NULL;
}

const char *handle_Highscores ( MenuAction_t action )
{
  if ( action == ACTION_CLICK ) {
    MenuItemSelectedSound();
    ShowHighscores();
  }
  return NULL;
}
const char *handle_Credits ( MenuAction_t action )
{
  if ( action == ACTION_CLICK ) {
    MenuItemSelectedSound();
    ShowCredits();
  }

  return NULL;

} // handle_Credits()

const char *handle_ConfigureKeys ( MenuAction_t action )
{
  if ( action == ACTION_CLICK ) {
    MenuItemSelectedSound();
    Key_Config_Menu();
  }
  return NULL;
}
const char *handle_QuitGame ( MenuAction_t action )
{
  if ( action != ACTION_CLICK ) {
    return NULL;
  }

  MenuItemSelectedSound();
  InitiateMenu (FALSE);

#ifdef GCW0
  const char *quit_string = "Press A to quit";
#else
  const char *quit_string = "Hit 'y' or press Fire to quit";
#endif
  int text_width = TextWidth ( quit_string );
  int text_x = User_Rect.x + (User_Rect.w - text_width)/2;
  int text_y = User_Rect.y + (User_Rect.h - fheight)/2;
  PutString (ne_screen, text_x, text_y, quit_string);
  SDL_Flip (ne_screen);

#ifdef GCW0
  while ( (!Gcw0AnyButtonPressed()) ) SDL_Delay(1);
  if ( (Gcw0APressed()) ) {
    while ( (!Gcw0AnyButtonPressedR()) ) SDL_Delay(1); // In case FirePressed && !Gcw0APressed() -> would cause a loop otherwise in the menu...
    Terminate (OK);
  }
#else
  wait_for_all_keys_released();
  int key = wait_for_key_pressed();
  if ( (key == 'y') || (key == key_cmds[CMD_FIRE][0]) || (key == key_cmds[CMD_FIRE][1]) || (key == key_cmds[CMD_FIRE][2]) ) {
    Terminate (OK);
  }
#endif

  return NULL;
} // handle_QuitGame()

// ========== Function definitions ==========

// simple wrapper to ShowMenu() to provide the external entry point into the main menu
void showMainMenu (void)
{
  ShowMenu ( MainMenu );
} // showMainMenu()

// simple wrapper to ShowMenu() to provide the external entry point into the Level Editor menu
void
showLevelEditorMenu (void)
{
  quit_LevelEditor = FALSE;
  ShowMenu ( LevelEditorMenu );
}

/*@Function============================================================
@Desc: This function prepares the screen for a menu and
       its submenus.  This means usual content of the screen, i.e. the
       combat screen and top status bar, is "faded out", the rest of
       the screen is cleared.  This function resolves some redundance
       that occured since there are so many submenus needing this.

@Ret: none
* $Function----------------------------------------------------------*/
void
InitiateMenu (bool with_droids)
{
  //--------------------
  // Here comes the standard initializer for all the menus and submenus
  // of the big escape menu.  This prepares the screen, so that we can
  // write on it further down.
  //
  Activate_Conservative_Frame_Computation();

  SDL_SetClipRect( ne_screen, NULL );
  Me.status=MENU;
  ClearGraphMem();
  DisplayBanner (NULL, NULL,  BANNER_NO_SDL_UPDATE | BANNER_FORCE_UPDATE );
  if (with_droids)
    Assemble_Combat_Picture (0);
  else
    Assemble_Combat_Picture (ONLY_SHOW_MAP);

  SDL_SetClipRect( ne_screen, NULL );
  MakeGridOnScreen( NULL );

  if (Menu_Background) SDL_FreeSurface (Menu_Background);
  Menu_Background = SDL_DisplayFormat (ne_screen);  // keep a global copy of background

  SDL_ShowCursor (SDL_DISABLE);  // deactivate mouse-cursor in menus
  SetCurrentFont ( Menu_BFont );
  fheight = FontHeight (GetCurrentFont()) + 2;

  return;

} // void InitiateMenu (bool with_droids)


// ----------------------------------------------------------------------
// get menu input actions
// NOTE: built-in time delay to ensure spurious key-repetitions
// such as from touchpad 'wheel' or android joystic emulation
// don't create unexpected menu movements:
// ==> ignore all movement commands withing delay_ms milliseconds of each other
MenuAction_t
getMenuAction ( Uint32 wait_repeat_ticks )
{
  MenuAction_t action = ACTION_NONE;

  // 'normal' menu action keys get released
  if ( KeyIsPressedR ( SDLK_BACKSPACE ) ) {
    action = ACTION_DELETE;
  }
  if ( cmd_is_activeR(CMD_BACK) || KeyIsPressedR(SDLK_ESCAPE) ) {
    action = ACTION_BACK;
  }

  if ( FirePressed() || ReturnPressedR() ) {
    action = ACTION_CLICK;
  }

  // ----- up/down motion: allow for key-repeat, but carefully control repeat rate (modelled on takeover game)
  static Uint32 last_movekey_time = 0;

  static int up    = FALSE;
  static int down  = FALSE;
  static int left  = FALSE;
  static int right = FALSE;

  // we register if there have been key-press events in the "waiting period" between move-ticks
  if ( !up && (UpPressed () || KeyIsPressed(SDLK_UP)) )
    {
      up = TRUE;
      last_movekey_time = SDL_GetTicks();
      action |= ACTION_UP;
    }
  if (!down && (DownPressed() || KeyIsPressed(SDLK_DOWN)) )
    {
      down = TRUE;
      last_movekey_time = SDL_GetTicks();
      action |= ACTION_DOWN;
    }
  if ( !left && (LeftPressed() || KeyIsPressed(SDLK_LEFT)) )
    {
      left = TRUE;
      last_movekey_time = SDL_GetTicks();
      action |= ACTION_LEFT;
    }
  if ( !right && (RightPressed() || KeyIsPressed(SDLK_RIGHT)) )
    {
      right = TRUE;
      last_movekey_time = SDL_GetTicks();
      action |= ACTION_RIGHT;
    }

  if (! (UpPressed()   || KeyIsPressed(SDLK_UP)))    { up   = FALSE; }
  if (! (DownPressed() || KeyIsPressed(SDLK_DOWN)))  { down = FALSE; }
  if (! (LeftPressed() || KeyIsPressed(SDLK_LEFT)))  { left = FALSE; }
  if (! (RightPressed()|| KeyIsPressed(SDLK_RIGHT))) { right= FALSE; }

  // check if enough time since we registered last new move-action
  if ( SDL_GetTicks() - last_movekey_time > wait_repeat_ticks )
    {
      if ( up ) {
        action |= ACTION_UP;
      }
      if ( down ) {
        action |= ACTION_DOWN;
      }
      if ( left ) {
        action |= ACTION_LEFT;
      }
      if ( right ) {
        action |= ACTION_RIGHT;
      }
    }
  // special handling of mouse wheel: register every event, no need for key-repeat delays
  if ( WheelUpPressed() ) {
    action |= ACTION_UP_WHEEL;
  }
  if ( WheelDownPressed() ) {
    action |= ACTION_DOWN_WHEEL;
  }

  return action;

} // getMenuAction()


//
// Generic menu handler
//
void
ShowMenu ( const MenuEntry_t MenuEntries[] )
{
  InitiateMenu ( FALSE );
  wait_for_all_keys_released();

  // figure out menu-start point to make it centered
  int num_entries = 0;
  int menu_width = 0;
  int entry_len;
  while ( MenuEntries[num_entries].name != NULL ) {
    entry_len = TextWidth ( MenuEntries[num_entries].name );
    if ( entry_len > menu_width) {
      menu_width = entry_len;
    }
    num_entries ++;
  }
  int menu_height = num_entries * fheight;
  int menu_x = Full_User_Rect.x + (Full_User_Rect.w - menu_width)/2;
  int menu_y = Full_User_Rect.y + (Full_User_Rect.h - menu_height)/2;
  int influ_x = menu_x - Block_Rect.w - fheight;

  int menu_pos = 0;

  MenuAction_t action = ACTION_NONE;
  const Uint32 wait_move_ticks = 100;
  static Uint32 last_move_tick = 0;
  bool finished = FALSE;
  quit_Menu = FALSE;
  bool need_update = TRUE;
  while ( !finished )
    {
      const char* (*handler)( MenuAction_t action ) = MenuEntries[menu_pos].handler;
      const MenuEntry_t *submenu = MenuEntries[menu_pos].submenu;

      if ( need_update )
        {
          SDL_BlitSurface (Menu_Background, NULL, ne_screen, NULL);
          // print menu
          int i;
          for ( i = 0; i < num_entries; i ++ )
            {
              char fullName[256];
              const char *arg = NULL;
              if ( MenuEntries[i].handler ) {
                arg = (*MenuEntries[i].handler)( ACTION_INFO );
              }
              sprintf ( fullName, "%s%s", MenuEntries[i].name, (arg == NULL) ? "" : arg );
              PutString (ne_screen, menu_x, menu_y + i * fheight, fullName );
            }
          PutInfluence (influ_x, menu_y + (menu_pos - 0.5) * fheight);
#ifndef ANDROID
          SDL_Flip( ne_screen );
#endif
          need_update = FALSE;
        }
#ifdef ANDROID
      SDL_Flip( ne_screen );	// for responsive input on Android, we need to run this every cycle
#endif
      action = getMenuAction( 250 );

      bool time_for_move = ( SDL_GetTicks() - last_move_tick > wait_move_ticks );
      switch ( action )
        {
        case ACTION_BACK:
          finished = TRUE;
          wait_for_all_keys_released();
          break;

        case ACTION_CLICK:
          if ( !handler && !submenu ) {
            MenuItemSelectedSound();
            finished = TRUE;
            break;
          }
          if ( handler ) {
            wait_for_all_keys_released();
            (*handler)(action);
          }
          if ( submenu ) {
            MenuItemSelectedSound();
            wait_for_all_keys_released();
            ShowMenu ( submenu );
            InitiateMenu (FALSE);
          }
          need_update = TRUE;
          break;

        case ACTION_RIGHT:
        case ACTION_LEFT:
          if ( !time_for_move ) continue;

          if ( handler ) {
            (*handler)(action);
          }
          last_move_tick = SDL_GetTicks();
          need_update = TRUE;
          break;

        case ACTION_UP:
          if ( !time_for_move ) continue;
          // intentional fall-through
        case ACTION_UP_WHEEL:
          MoveMenuPositionSound();
          if (menu_pos > 0) {
            menu_pos--;
          } else {
            menu_pos = num_entries - 1;
          }
          last_move_tick = SDL_GetTicks();
          need_update = TRUE;
          break;

        case ACTION_DOWN:
          if ( !time_for_move ) continue;
          // intentional fall-through
        case ACTION_DOWN_WHEEL:
          MoveMenuPositionSound();
          if ( menu_pos < num_entries - 1 ) {
            menu_pos++;
          } else {
            menu_pos = 0;
          }
          last_move_tick = SDL_GetTicks();
          need_update = TRUE;
          break;

        default:
          break;
        } // switch(action)

      if ( quit_Menu ) {
        finished = TRUE;
      }

      SDL_Delay(1);	// don't hog CPU
    } // while !finished

  ClearGraphMem();
  SDL_ShowCursor ( SDL_ENABLE );  // reactivate mouse-cursor for game
  // Since we've faded out the whole scren, it can't hurt
  // to have the top status bar redrawn...
  BannerIsDestroyed = TRUE;
  Me.status = MOBILE;

  while ( any_key_is_pressedR() ) // wait for all key/controller-release
    SDL_Delay(1);

  return;

} // ShowMenu()

/*@Function============================================================
@Desc: This function provides the credits screen.  It is a submenu of
       the big MainMenu.  Here you can see who helped developing the
       game, currently jp, rp and bastian.

@Ret:  none
* $Function----------------------------------------------------------*/
void
ShowCredits (void)
{
  int h, em;
  SDL_Rect screen;
  BFont_Info *oldfont;
  int col2 = 2*User_Rect.w/3;

  h = FontHeight(Menu_BFont);
  em = CharWidth (Menu_BFont, 'm');

  Copy_Rect (Screen_Rect, screen);
  SDL_SetClipRect( ne_screen, NULL );
  DisplayImage ( find_file(CREDITS_PIC_FILE, GRAPHICS_DIR, NO_THEME, CRITICAL));
  MakeGridOnScreen (&screen);

  oldfont = GetCurrentFont();
  SetCurrentFont (Font1_BFont);

  printf_SDL (ne_screen, UserCenter_x - 2*em, h, "CREDITS\n");

  printf_SDL (ne_screen, em, -1, "PROGRAMMING:");
  printf_SDL (ne_screen, col2, -1, "Johannes Prix\n");
  printf_SDL (ne_screen, -1, -1, "Reinhard Prix\n");
  printf_SDL (ne_screen, -1, -1, "\n");

  printf_SDL (ne_screen, em, -1, "ARTWORK:");
  printf_SDL (ne_screen, col2, -1, "Bastian Salmela\n");
  printf_SDL (ne_screen, -1, -1, "\n");
  printf_SDL (ne_screen, em, -1, "ADDITIONAL THEMES:\n");
  printf_SDL (ne_screen, 2*em, -1, "Lanzz-theme");
  printf_SDL (ne_screen, col2, -1, "Lanzz\n");
  printf_SDL (ne_screen, 2*em, -1, "Para90-theme");
  printf_SDL (ne_screen, col2, -1, "Andreas Wedemeyer\n");

  printf_SDL (ne_screen, -1, -1, "\n");
  printf_SDL (ne_screen, em, -1, "C64 LEGACY MODS:\n");


  printf_SDL (ne_screen, 2*em, -1, "Green Beret, Sanxion, Uridium2");
  printf_SDL (ne_screen, col2, -1, "#dreamfish/trsi\n");

  printf_SDL (ne_screen, 2*em, -1, "The last V8, Anarchy");
  printf_SDL (ne_screen, col2, -1, "4-mat\n");

  printf_SDL (ne_screen, 2*em, -1, "Tron");
  printf_SDL (ne_screen, col2, -1, "Kollaps\n");


  printf_SDL (ne_screen, 2*em, -1, "Starpaws");
  printf_SDL (ne_screen, col2, -1, "Nashua\n");


  printf_SDL (ne_screen, 2*em, -1, "Commando");
  printf_SDL (ne_screen, col2, -1, "Android");


  SDL_Flip( ne_screen );

  wait_for_key_pressed();

  SetCurrentFont (oldfont);

  return;

} // Show_Credits()

// ======================================================================

// ------------------------------------------------------------
// show/edit keyboard-config
// ------------------------------------------------------------
void
Key_Config_Menu (void)
{
  int LastMenuPos = CMD_LAST;
  int selx = 1, sely = 1;   // currently selected menu-position
  int newkey = -1;
  MenuAction_t action = ACTION_NONE;
  const Uint32 wait_move_ticks = 100;
  static Uint32 last_move_tick = 0;

  bool finished = FALSE;
  while (!finished)
    {
      Display_Key_Config (selx, sely);

      action = getMenuAction( 250 );
      bool time_for_move = (SDL_GetTicks() - last_move_tick > wait_move_ticks);

      switch ( action )
        {
        case ACTION_BACK:
          finished = TRUE;
          wait_for_all_keys_released();
          break;

        case ACTION_CLICK:
          MenuItemSelectedSound();

          // oldkey = key_cmds[sely-1][selx-1];
          key_cmds[sely-1][selx-1] = '_';
          Display_Key_Config (selx, sely);
          newkey = getchar_raw(); // includes joystick input!
          key_cmds[sely-1][selx-1] = newkey;
          wait_for_all_keys_released();
          last_move_tick = SDL_GetTicks();
          break;

        case ACTION_UP:
          if ( !time_for_move ) continue;
          // intentional fall-through
        case ACTION_UP_WHEEL:
          if ( sely > 1 ) sely--;
          else sely = LastMenuPos;
          MoveMenuPositionSound();
          last_move_tick = SDL_GetTicks();
          break;

        case ACTION_DOWN:
          if ( !time_for_move ) continue;
          // intentional fall-through
        case ACTION_DOWN_WHEEL:
          if ( sely < LastMenuPos ) sely++;
          else sely = 1;
          MoveMenuPositionSound();
          last_move_tick = SDL_GetTicks();
          break;

        case ACTION_RIGHT:
          if ( !time_for_move ) continue;

          if ( selx < 3 ) selx++;
          else selx = 1;
          MoveMenuPositionSound();
          last_move_tick = SDL_GetTicks();
          break;

        case ACTION_LEFT:
          if ( !time_for_move ) continue;

          if ( selx > 1 ) selx--;
          else selx = 3;
          MoveMenuPositionSound();
          last_move_tick = SDL_GetTicks();
          break;

        case ACTION_DELETE:
          key_cmds[sely-1][selx-1] = 0;
          MenuItemSelectedSound();
          break;
        default:
          break;
        } // switch(action)

      SDL_Delay(1);
    } // while !finished

  return;

} // Key_Config_Menu()

// ------------------------------------------------------------
// subroutine to display the current key-config and highlight
//  current selection
// ------------------------------------------------------------
#define PosFont(x,y) ( (((x)!=selx)||((y)!=sely)) ? Font1_BFont : Font2_BFont )
void
Display_Key_Config (int selx, int sely)
{
  int startx = Full_User_Rect.x + 1.2*Block_Rect.w;
  int starty = Full_User_Rect.y + FontHeight(GetCurrentFont());
  int col1 = startx + 7.5 * CharWidth(GetCurrentFont(), 'O');
  int col2 = col1 + 6.5 * CharWidth(GetCurrentFont(), 'O');
  int col3 = col2 + 6.5 * CharWidth(GetCurrentFont(), 'O');
  int posy = 0;
  int lheight = FontHeight (Font0_BFont) + 2;

  SDL_BlitSurface (Menu_Background, NULL, ne_screen, NULL);

  //      PutInfluence (startx - 1.1*Block_Rect.w, starty + (MenuPosition-1.5)*lheight);
  //PrintStringFont (ne_screen, (sely==1)? Font2_BFont:Font1_BFont, startx, starty+(posy++)*lheight, "Back");
#ifdef GCW0
  PrintStringFont (ne_screen, Font0_BFont, col1, starty, "(RShldr to clear an entry)");
#else
  PrintStringFont (ne_screen, Font0_BFont, col1, starty, "(Backspace to clear an entry)");
#endif
  posy++;
  PrintStringFont (ne_screen, Font0_BFont, startx, starty + (posy)*lheight, "Command");
  PrintStringFont (ne_screen, Font0_BFont, col1,   starty + (posy)*lheight, "Key1");
  PrintStringFont (ne_screen, Font0_BFont, col2,   starty + (posy)*lheight, "Key2");
  PrintStringFont (ne_screen, Font0_BFont, col3,   starty + (posy)*lheight, "Key3");
  posy ++;

  int i;
  for (i=0; i < CMD_LAST; i++)
    {
      PrintStringFont (ne_screen, Font0_BFont,  startx, starty+(posy)*lheight, cmd_strings[i]);
      PrintStringFont (ne_screen, PosFont(1,1+i), col1, starty+(posy)*lheight, keystr[key_cmds[i][0]]);
      PrintStringFont (ne_screen, PosFont(2,1+i), col2, starty+(posy)*lheight, keystr[key_cmds[i][1]]);
      PrintStringFont (ne_screen, PosFont(3,1+i), col3, starty+(posy)*lheight, keystr[key_cmds[i][2]]);
      posy ++;
    }

  SDL_Flip( ne_screen );

  return;
} // Display_Key_Config


// ======================================================================

// ----------------------------------------------------------------------
// Cheat menu
// ----------------------------------------------------------------------
void
Cheatmenu (void)
{
  char *input;		/* string input from user */
  int Weiter;
  int LNum, X, Y, num;
  int i, l;
  int x0, y0;
  Waypoint WpList;      /* pointer on current waypoint-list  */
  BFont_Info *font;
  const char *status;

  // Prevent distortion of framerate by the delay coming from
  // the time spend in the menu.
  Activate_Conservative_Frame_Computation();

  font =  Font0_BFont;


  SetCurrentFont (font);  /* not the ideal one, but there's currently */
				/* no other it seems.. */
  x0 = 50;
  y0 = 20;

  Weiter = FALSE;
  while (!Weiter)
    {
      ClearGraphMem ();
      printf_SDL (ne_screen, x0, y0, "Current position: Level=%d, X=%d, Y=%d\n",
		   CurLevel->levelnum, (int)Me.pos.x, (int)Me.pos.y);
      printf_SDL (ne_screen, -1, -1, " a. Armageddon (alle Robots sprengen)\n");
      printf_SDL (ne_screen, -1, -1, " l. robot list of current level\n");
      printf_SDL (ne_screen, -1, -1, " g. complete robot list\n");
      printf_SDL (ne_screen, -1, -1, " d. destroy robots on current level\n");
      printf_SDL (ne_screen, -1, -1, " t. Teleportation\n");
      printf_SDL (ne_screen, -1, -1, " r. change to new robot type\n");
      printf_SDL (ne_screen, -1, -1, " i. Invinciblemode: %s",
		  InvincibleMode ? "ON\n" : "OFF\n");
      printf_SDL (ne_screen, -1, -1, " e. set energy\n");
      printf_SDL (ne_screen, -1, -1, " n. No hidden droids: %s",
		  show_all_droids ? "ON\n" : "OFF\n" );
      printf_SDL (ne_screen, -1, -1, " m. Map of Deck xy\n");
      printf_SDL (ne_screen, -1, -1, " s. Sound: %s",
		  sound_on ? "ON\n" : "OFF\n");
      printf_SDL (ne_screen, -1, -1, " w. Print current waypoints\n");
      printf_SDL (ne_screen, -1, -1, " z. change Zoom factor\n");
      printf_SDL (ne_screen, -1, -1, " f. Freeze on this positon: %s",
		  stop_influencer ? "ON\n" : "OFF\n");
      printf_SDL (ne_screen, -1, -1, " q. RESUME game\n");

      switch (getchar_raw ())
	{
	case 'f':
	  stop_influencer = !stop_influencer;
	  break;

	case 'z':
	  ClearGraphMem();
	  printf_SDL (ne_screen, x0, y0, "Current Zoom factor: %f\n",
		      CurrentCombatScaleFactor);
	  printf_SDL (ne_screen, -1, -1, "New zoom factor: ");
	  input = GetString (40, 2);
	  sscanf (input, "%f", &CurrentCombatScaleFactor);
	  free (input);
	  SetCombatScaleTo (CurrentCombatScaleFactor);
	  break;

	case 'a': /* armageddon */
	  Weiter = 1;
	  Armageddon ();
	  break;

	case 'l': /* robot list of this deck */
	  l = 0; /* line counter for enemy output */
	  for (i = 0; i < NumEnemys; i++)
	    {
	      if (AllEnemys[i].levelnum == CurLevel->levelnum)
		{
		  if (l && !(l%20))
		    {
		      printf_SDL (ne_screen, -1, -1, " --- MORE --- \n");
		      if( getchar_raw () == 'q')
			break;
		    }
		  if (!(l % 20) )
		    {
		      ClearGraphMem ();
		      printf_SDL (ne_screen, x0, y0,
				   " NR.   ID  X    Y   ENERGY   Status\n");
		      printf_SDL (ne_screen, -1, -1,
				  "---------------------------------------------\n");
		    }

		  l ++;
		  if (AllEnemys[i].status == OUT)
		    status = "OUT";
		  else if (AllEnemys[i].status == TERMINATED)
		    status = "DEAD";
		  else
		    status = "ACTIVE";

		  printf_SDL (ne_screen, -1, -1,
			      "%d.   %s   %d   %d   %d    %s.\n", i,
			      Druidmap[AllEnemys[i].type].druidname,
			      (int)AllEnemys[i].pos.x,
			      (int)AllEnemys[i].pos.y,
			      (int)AllEnemys[i].energy,
			      status);
		} /* if (enemy on current level)  */
	    } /* for (i<NumEnemys) */

	  printf_SDL (ne_screen, -1, -1," --- END --- \n");
	  getchar_raw ();
	  break;

	case 'g': /* complete robot list of this ship */
	  for (i = 0; i < NumEnemys ; i++)
	    {
	      if ( AllEnemys[i].type == (-1) ) continue;

	      if (i && !(i%13))
		{
		  printf_SDL (ne_screen, -1, -1, " --- MORE --- ('q' to quit)\n");
		  if (getchar_raw () == 'q')
		    break;
		}
	      if ( !(i % 13) )
		{
		  ClearGraphMem ();
		  printf_SDL (ne_screen, x0, y0, "Nr.  Lev. ID  Energy  Status.\n");
		  printf_SDL (ne_screen, -1, -1, "------------------------------\n");
		}

	      printf_SDL (ne_screen, -1, -1, "%d  %d  %s  %d  %s\n",
			  i, AllEnemys[i].levelnum,
			  Druidmap[AllEnemys[i].type].druidname,
			  (int)AllEnemys[i].energy,
			  InfluenceModeNames[AllEnemys[i].status]);
	    } /* for (i<NumEnemys) */

	  printf_SDL (ne_screen, -1, -1, " --- END ---\n");
	  getchar_raw ();
	  break;


	case 'd': /* destroy all robots on this level, haha */
	  for (i = 0; i < NumEnemys; i++)
	    {
	      if (AllEnemys[i].levelnum == CurLevel->levelnum)
		AllEnemys[i].energy = -100;
	    }
	  printf_SDL (ne_screen, -1, -1, "All robots on this deck killed!\n");
	  getchar_raw ();
	  break;


	case 't': /* Teleportation */
	  ClearGraphMem ();
	  printf_SDL (ne_screen, x0, y0, "Enter Level, X, Y: ");
	  input = GetString (40, 2);
	  sscanf (input, "%d, %d, %d\n", &LNum, &X, &Y);
	  free (input);
	  Teleport (LNum, X, Y);
	  break;

	case 'r': /* change to new robot type */
	  ClearGraphMem ();
	  printf_SDL (ne_screen, x0, y0, "Type number of new robot: ");
	  input = GetString (40, 2);
	  for (i = 0; i < Number_Of_Droid_Types ; i++)
	    if (!strcmp (Druidmap[i].druidname, input))
	      break;

	  if ( i == Number_Of_Droid_Types )
	    {
	      printf_SDL (ne_screen, x0, y0+20,
			  "Unrecognized robot-type: %s", input);
	      getchar_raw ();
	      ClearGraphMem();
	    }
	  else
	    {
	      Me.type = i;
	      Me.energy = Druidmap[Me.type].maxenergy;
	      Me.health = Me.energy;
	      printf_SDL (ne_screen, x0, y0+20, "You are now a %s. Have fun!\n", input);
	      getchar_raw ();
	    }
	  free (input);
	  break;

	case 'i': /* togge Invincible mode */
	  InvincibleMode = !InvincibleMode;
	  break;

	case 'e': /* complete heal */
	  ClearGraphMem();
	  printf_SDL (ne_screen, x0, y0, "Current energy: %f\n", Me.energy);
	  printf_SDL (ne_screen, -1, -1, "Enter your new energy: ");
	  input = GetString (40, 2);
	  sscanf (input, "%d", &num);
	  free (input);
	  Me.energy = (float) num;
	  if (Me.energy > Me.health) Me.health = Me.energy;
	  break;

	case 'n': /* toggle display of all droids */
	  show_all_droids = !show_all_droids;
	  break;

	case 's': /* toggle sound on/off */
	  sound_on = !sound_on;
	  break;

	case 'm': /* Show deck map in Concept view */
	  printf_SDL (ne_screen, -1, -1, "\nLevelnum: ");
	  input = GetString (40, 2);
	  sscanf (input, "%d", &LNum);
	  free (input);
	  ShowDeckMap ();
	  getchar_raw ();
	  break;

	case 'w':  /* print waypoint info of current level */
	  WpList = CurLevel->AllWaypoints;
	  for (i=0; i<CurLevel->num_waypoints; i++)
	    {
	      if (i && !(i%20))
		{
		  printf_SDL (ne_screen, -1, -1, " ---- MORE -----\n");
		  if (getchar_raw () == 'q')
		    break;
		}
	      if ( !(i%20) )
		{
		  ClearGraphMem ();
		  printf_SDL (ne_screen, x0, y0, "Nr.   X   Y      C1  C2  C3  C4\n");
		  printf_SDL (ne_screen, -1, -1, "------------------------------------\n");
		}
	      printf_SDL (ne_screen, -1, -1, "%2d   %2d  %2d      %2d  %2d  %2d  %2d\n",
			  i, WpList[i].x, WpList[i].y,
			  WpList[i].connections[0],
			  WpList[i].connections[1],
			  WpList[i].connections[2],
			  WpList[i].connections[3]);

	    } /* for (all waypoints) */
	  printf_SDL (ne_screen, -1, -1, " --- END ---\n");
	  getchar_raw ();
	  break;

	case ' ':
	case 'q':
	  Weiter = 1;
	  break;
	} /* switch (getchar_raw()) */
    } /* while (!Weiter) */

  ClearGraphMem ();

  update_input (); /* treat all pending keyboard events */

  return;
} /* Cheatmenu() */

void
FreeMenuData ( void )
{
  SDL_FreeSurface (Menu_Background);
  return;
}
#undef _menu_c