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
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
|
/*
* PARSEC - Main Menu Module
*
* $Author: uberlinuxguy $ - $Date: 2004/09/26 03:43:37 $
*
* Orginally written by:
* Copyright (c) Markus Hadwiger <msh@parsec.org> 1998-2000
* Copyright (c) Andreas Varga <sid@parsec.org> 1999-2000
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// C library
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// compilation flags/debug support
#include "config.h"
#include "debug.h"
// general definitions
#include "general.h"
#include "objstruc.h"
// global externals
#include "globals.h"
// subsystem headers
#include "aud_defs.h"
#include "inp_defs.h"
#include "net_defs.h"
#include "sys_defs.h"
// mathematics header
#include "utl_math.h"
// local module header
#include "m_main.h"
// proprietary module headers
#include "con_aux.h"
#include "con_ext.h"
#include "e_demo.h"
#include "e_draw.h"
#include "e_supp.h"
#include "g_supp.h"
#include "h_drwhud.h"
#include "h_strmap.h"
#include "h_text.h"
#include "m_button.h"
#include "m_list.h"
#include "m_logo.h"
#include "m_status.h"
#include "m_option.h"
#include "m_viewer.h"
#include "net_conn.h"
#include "net_csdf.h"
#include "obj_creg.h"
// flags
#define PLAY_DEMO_BEHIND_MENU
// generic string paste area --------------------------------------------------
//
#define PASTE_STR_LEN 2047
static char paste_str[ PASTE_STR_LEN + 1 ];
// demo playback behind menu --------------------------------------------------
//
#define DEMO_FILE "menudemo"
static int demo_play_possible = TRUE;
// sintab for sliding ---------------------------------------------------------
//
#define SINTAB_SIZE 16
PUBLIC int m_sintab[ SINTAB_SIZE ];
PUBLIC int m_sintab_size = SINTAB_SIZE;
PUBLIC int m_sintab_ampl = 320;
// visibility flags for all parts of the menu ---------------------------------
//
static int itemvis_buttons = TRUE;
static int itemvis_logo = TRUE;
static int itemvis_listwindow = TRUE;
static int itemvis_optionsmenu = FALSE;
static int itemvis_viewer = FALSE;
static int itemvis_gamestatus = FALSE;
PUBLIC int itemvis_loading = FALSE;
// transition flags -----------------------------------------------------------
//
enum {
MENUTRANS_NONE = 0,
MENUTRANS_TO_SUBMENU = 1,
MENUTRANS_FROM_SUBMENU = 2,
MENUTRANS_TO_GAMESTATUS = 3,
MENUTRANS_FROM_GAMESTATUS = 4,
MENUTRANS_TO_VIEWER = 5,
MENUTRANS_FROM_VIEWER = 6,
MENUTRANS_OPTIONS_TO_LIST = 7,
MENUTRANS_LIST_TO_OPTIONS = 8,
MENUTRANS_SHIP_TO_OBJECTS = 9,
MENUTRANS_OBJECTS_TO_SHIP = 10
};
static int menu_state_transition = MENUTRANS_NONE;
// ----------------------------------------------------------------------------
//
static int prev_GameTime = 0;
// used when kill limit has been reached --------------------------------------
//
PUBLIC int disable_join_game = 0;
// mouse vars -----------------------------------------------------------------
//
static int old_mouse_x = -1;
static int old_mouse_y = -1;
static int cur_mouse_x;
static int cur_mouse_y;
int old_mouse_button_state = MOUSE_BUTTON_RELEASED;
int cur_mouse_button_state;
// current mouse position state -----------------------------------------------
//
static int mouse_position_state = MOUSE_OVER_NOTHING;
// perform options menu exit --------------------------------------------------
//
void ExitOptionsMenu()
{
//NOTE:
// called by M_OPTION::ExecOptionSelectExit() when
// the user wants to exit the options menu.
// disable options menu
menu_state_transition = MENUTRANS_OPTIONS_TO_LIST;
FadeInButtons();
}
// return whether status window is active -------------------------------------
//
int FloatingMenuStatusWindowActive()
{
//NOTE:
// this is needed by AUD_BackGroundPlayer_Maintain() to determine
// whether the background player should be turned off automatically.
if ( itemvis_gamestatus ) {
return TRUE;
}
// avoid sequencing problems within the same frame
return ( menu_state_transition == MENUTRANS_TO_GAMESTATUS );
}
// ----------------------------------------------------------------------------
//
static int scv_sound_played = FALSE;
static int opt_sound_played = FALSE;
extern int cur_scv_mode;
extern int cur_scv_ship;
extern int scv_object_selindx;
extern int scv_ring_spinning;
// check whether game status window should be activated -----------------------
//
PRIVATE
int CheckGameStatusWindowEnabling()
{
if ( !AUX_ENABLE_GAME_STATUS_WINDOW )
return FALSE;
if ( itemvis_gamestatus )
return FALSE;
if ( menu_state_transition != MENUTRANS_NONE )
return FALSE;
//FIXME:
/* if ( NumRemPlayers <= 1 )
return FALSE;//FIXME:*/
// if ( !GAME_OVER() )
// return FALSE;
MoveOutButtons();
MoveOutListWindow();
menu_state_transition = MENUTRANS_TO_GAMESTATUS;
return TRUE;
}
// activate the floating menu -------------------------------------------------
//
void ActivateFloatingMenu( int statuswin )
{
ASSERT( InFloatingMenu );
AUD_StopOnBoardComputer();
if ( statuswin ) {
// state switch to enable game status window
if ( CheckGameStatusWindowEnabling() ) {
return;
}
} else if ( itemvis_gamestatus ) {
// fade out status window if already visible
menu_state_transition = MENUTRANS_FROM_GAMESTATUS;
}
AUDs_OpenMenuSound();
MoveOutFloatingMenu();
SlideInFloatingMenu();
}
// set slide targets for menu items to in -------------------------------------
//
void SlideInFloatingMenu()
{
if ( !InFloatingMenu )
return;
SlideInButtons();
SlideInLogo();
SlideInListWindow();
SlideInOptions();
FadeInStatusWindow();
FadeInBackground();
SlideInShip();
SlideInRing();
}
// set slide targets for menu items to out ------------------------------------
//
void SlideOutFloatingMenu()
{
if ( !InFloatingMenu )
return;
SlideOutButtons();
SlideOutLogo();
SlideOutListWindow();
SlideOutOptions();
FadeOutStatusWindow();
FadeOutBackground();
SlideOutShip();
SlideOutRing();
}
// move in all floating menu items --------------------------------------------
//
void MoveInFloatingMenu()
{
MoveInButtons();
MoveInLogo();
MoveInListWindow();
MoveInOptions();
}
// move out all floating menu items -------------------------------------------
//
void MoveOutFloatingMenu()
{
MoveOutButtons();
MoveOutLogo();
MoveOutListWindow();
MoveOutOptions();
}
// make floating menu items invisible, prepare for sliding in -----------------
//
void HideFloatingMenu()
{
MoveOutFloatingMenu();
SlideInFloatingMenu();
}
// called during transition from menu to spacecraft viewer --------------------
//
PRIVATE
void MaintainTransitionToViewer()
{
SlideOutButtons();
SlideOutLogo();
SlideOutListWindow();
SlideOutOptions();
// play "spacecraft viewer in" sample
if ( !scv_sound_played ) {
scv_sound_played = TRUE;
AUD_SpaceCraftViewerIn();
}
if ( SlideFinishedButtons() ) {
FadeInBackground();
SlideInShip();
SlideInRing();
itemvis_buttons = FALSE;
itemvis_logo = FALSE;
itemvis_listwindow = FALSE;
itemvis_viewer = TRUE;
cur_scv_mode = SCVMODE_SPACECRAFT;
cur_scv_ship = ObjClassShipIndex[ LocalShipClass ];
ASSERT( cur_scv_ship != SHIPINDEX_NO_SHIP );
scv_sound_played = FALSE;
menu_state_transition = MENUTRANS_NONE;
}
}
// called during transition from spacecraft viewer to menu --------------------
//
PRIVATE
void MaintainTransitionFromViewer()
{
FadeOutBackground();
SlideOutShip();
SlideOutRing();
// play "spacecraft viewer out" sample
if ( !scv_sound_played ) {
scv_sound_played = TRUE;
AUD_SpaceCraftViewerOut();
}
if ( FadeFinishedBackground() ) {
itemvis_buttons = TRUE;
itemvis_logo = TRUE;
itemvis_listwindow = TRUE;
itemvis_viewer = FALSE;
SlideInButtons();
SlideInLogo();
SlideInListWindow();
SlideInOptions();
if ( SlideFinishedButtons() ) {
scv_sound_played = FALSE;
menu_state_transition = MENUTRANS_NONE;
}
}
}
// called during transition from player list to options menu ------------------
//
PRIVATE
void MaintainTransitionListToOptions()
{
InitOptionsSubsystemInfo();
if ( !opt_sound_played ) {
opt_sound_played = TRUE;
AUD_SlideIn( 0 );
}
SlideOutListWindow();
if ( SlideFinishedListWindow() ) {
itemvis_listwindow = FALSE;
itemvis_optionsmenu = TRUE;
SlideInOptions();
opt_sound_played = FALSE;
menu_state_transition = MENUTRANS_NONE;
}
}
// called during transition from options menu to player list ------------------
//
PRIVATE
void MaintainTransitionOptionsToList()
{
if ( !opt_sound_played ) {
AUD_SlideOut( 0 );
opt_sound_played = TRUE;
}
SlideOutOptions();
if ( SlideFinishedOptions() ) {
itemvis_listwindow = TRUE;
itemvis_optionsmenu = FALSE;
SlideInListWindow();
opt_sound_played = FALSE;
menu_state_transition = MENUTRANS_NONE;
}
}
// called during transition from ship to objects in spacecraft viewer ---------
//
PRIVATE
void MaintainTransitionShipToObjects()
{
SlideOutShip();
if ( SlideFinishedShip() ) {
scv_object_selindx = 0;
cur_scv_mode = SCVMODE_OBJECTSRING;
SlideInRing();
menu_state_transition = MENUTRANS_NONE;
}
}
// called during transition from objects to ship in spacecraft viewer ---------
//
PRIVATE
void MaintainTransitionObjectsToShip()
{
SlideOutRing();
if ( SlideFinishedRing() ) {
cur_scv_mode = SCVMODE_SPACECRAFT;
SlideInShip();
menu_state_transition = MENUTRANS_NONE;
}
}
// called during transition to submenu ----------------------------------------
//
PRIVATE
void MaintainTransitionToSubMenu()
{
FadeOutButtons( BUTTON_ALPHA_LOW );
if ( FadeFinishedButtons() ) {
MenuButtonsEnterSubmenu();
FadeInButtons();
menu_state_transition = MENUTRANS_NONE;
}
}
// called during transition from submenu --------------------------------------
//
PRIVATE
void MaintainTransitionFromSubMenu()
{
FadeOutButtons( BUTTON_ALPHA_LOW );
if ( FadeFinishedButtons() ) {
MenuButtonsLeaveSubmenu();
FadeInButtons();
menu_state_transition = MENUTRANS_NONE;
}
}
// called during transition to game status window -----------------------------
//
PRIVATE
void MaintainTransitionToGameStatus()
{
if ( !itemvis_gamestatus ) {
SlideOutButtons();
SlideOutListWindow();
if ( SlideFinishedButtons() ) {
itemvis_buttons = FALSE;
itemvis_listwindow = FALSE;
itemvis_gamestatus = TRUE;
} else {
ASSERT( itemvis_buttons );
ASSERT( itemvis_listwindow );
}
} else {
ASSERT( !itemvis_buttons );
ASSERT( !itemvis_listwindow );
FadeInStatusWindow();
if ( FadeFinishedStatusWindow() ) {
menu_state_transition = MENUTRANS_NONE;
}
}
}
// called during transition from game status window ---------------------------
//
PRIVATE
void MaintainTransitionFromGameStatus()
{
if ( itemvis_gamestatus ) {
FadeOutStatusWindow();
if ( FadeFinishedStatusWindow() ) {
itemvis_buttons = TRUE;
itemvis_listwindow = TRUE;
itemvis_gamestatus = FALSE;
} else {
ASSERT( !itemvis_buttons );
ASSERT( !itemvis_listwindow );
}
} else {
ASSERT( itemvis_buttons );
ASSERT( itemvis_listwindow );
SlideInButtons();
SlideInListWindow();
if ( SlideFinishedButtons() ) {
menu_state_transition = MENUTRANS_NONE;
AUDs_OpenMenuSound();
}
}
}
// check whether game status window should be deactivated ---------------------
//
PRIVATE
void CheckGameStatusWindowDisabling()
{
if ( ( prev_GameTime >= 0 ) && ( CurGameTime >= 0 ) ) {
// game is still running, change nothing
prev_GameTime = CurGameTime;
} else if ( ( prev_GameTime < 0 ) && ( CurGameTime >= 0 ) ) {
// game has been started...
menu_state_transition = MENUTRANS_FROM_GAMESTATUS;
prev_GameTime = CurGameTime;
} else {
prev_GameTime = CurGameTime;
}
}
// check whether demo should/can be started behind the menu -------------------
//
PRIVATE
void CheckMenuDemoReplay()
{
#ifdef PLAY_DEMO_BEHIND_MENU
if ( AUX_DISABLE_DEMO_REPLAY_IN_MENU )
return;
if ( demo_play_possible ) {
if ( !DEMO_ReplayActive() && !NetConnected ) {
demo_play_possible = DEMO_PlayBehindMenu( DEMO_FILE );
AUX_STOP_DEMO_REPLAY_ON_CONNECT = 1;
}
}
#endif
}
// restore menu state if it got stuck -----------------------------------------
//
void EnsureStateConsistency()
{
//NOTE:
// the following state must be detected as an invalid menu
// condition:
// itemvis_buttons = 0
// itemvis_logo = 1
// itemvis_listwindow = 0
// itemvis_optionsmenu = 0
// itemvis_viewer = 0
// itemvis_gamestatus = 0
// itemvis_loading = 0
if ( !itemvis_logo )
return;
if ( itemvis_buttons )
return;
if ( itemvis_listwindow )
return;
if ( itemvis_optionsmenu )
return;
if ( itemvis_viewer )
return;
if ( itemvis_gamestatus )
return;
if ( itemvis_loading )
return;
// we simply restore the buttons
// and the listwindow
itemvis_buttons = TRUE;
itemvis_listwindow = TRUE;
MoveInButtons();
MoveInListWindow();
}
// call corresponding maintenance function if transition in progress ----------
//
PRIVATE
void MaintainMenuStateTransitions()
{
// maintain state transitions
switch ( menu_state_transition ) {
case MENUTRANS_NONE:
EnsureStateConsistency();
break;
// menu -> submenu
case MENUTRANS_TO_SUBMENU:
MaintainTransitionToSubMenu();
break;
// submenu -> menu
case MENUTRANS_FROM_SUBMENU:
MaintainTransitionFromSubMenu();
break;
// menu/game -> game status
case MENUTRANS_TO_GAMESTATUS:
MaintainTransitionToGameStatus();
break;
// game status -> menu
case MENUTRANS_FROM_GAMESTATUS:
MaintainTransitionFromGameStatus();
break;
// menu -> spacecraft viewer
case MENUTRANS_TO_VIEWER:
MaintainTransitionToViewer();
break;
// spacecraft viewer -> menu
case MENUTRANS_FROM_VIEWER:
MaintainTransitionFromViewer();
break;
// player list -> options menu
case MENUTRANS_LIST_TO_OPTIONS:
MaintainTransitionListToOptions();
break;
// options menu -> player list
case MENUTRANS_OPTIONS_TO_LIST:
MaintainTransitionOptionsToList();
break;
// ships -> objects in spacecraft viewer
case MENUTRANS_SHIP_TO_OBJECTS:
MaintainTransitionShipToObjects();
break;
// objects -> ships in spacecraft viewer
case MENUTRANS_OBJECTS_TO_SHIP:
MaintainTransitionObjectsToShip();
break;
}
}
// currently selected sample quality is defined in an audio module ------------
//
static int prev_sample_quality = -1;
// ----------------------------------------------------------------------------
//
PRIVATE
void HandleMenuLoading()
{
if ( prev_sample_quality == -1 ) {
prev_sample_quality = aud_sample_quality;
}
if ( itemvis_loading ) {
// draw loading bitmap
DrawMenuLoading();
// disable loading bitmap now, which triggers the loading and
// ensures that the bitmap is removed as soon as loading has
// finished
itemvis_loading = FALSE;
prev_sample_quality = aud_sample_quality;
extern int cur_sfxquality;
if ( cur_sfxquality == 0 ) {
aud_sample_quality = 44100;
} else if ( cur_sfxquality == 1 ) {
aud_sample_quality = 22050;
} else {
aud_sample_quality = 11025;
}
} else if ( aud_sample_quality != prev_sample_quality ) {
const char * soundfile = "_sound";
ExecExternalFile( (char *) soundfile );
prev_sample_quality = aud_sample_quality;
}
}
// draw all visible menu items ------------------------------------------------
//
PRIVATE
void DrawMenuItems()
{
// draw the menu buttons
if ( itemvis_buttons ) {
DrawMenuButtons();
}
// draw the rotating logo
if ( itemvis_logo ) {
DrawMenuLogo();
}
// draw the currently active list window
if ( itemvis_listwindow ) {
DrawMenuListWindow();
}
// draw the options menu
if ( itemvis_optionsmenu ) {
DrawOptionsMenuWindow();
}
// draw the blinking connect indicator
if ( NetConnected && !itemvis_viewer ) {
DrawMenuConnected();
}
// draw the game status window
if ( itemvis_gamestatus ) {
DrawStatusWindow();
}
// draw the spacecraft viewer
if ( itemvis_viewer ) {
DrawSpacecraftViewer();
}
}
// draw floating menu (overlay menu in entry mode) ----------------------------
//
void DrawFloatingMenu()
{
ASSERT( InFloatingMenu );
/*
// automatic disabling of game status window
if ( itemvis_gamestatus ) {
CheckGameStatusWindowDisabling();
}
*/
// init vidmode state variables for options menu
InitOptionsWindow();
// play demo in the background if enabled
CheckMenuDemoReplay();
// maintain state transitions
MaintainMenuStateTransitions();
// draw all visible menu items
DrawMenuItems();
// handle automatic reloads in menu
HandleMenuLoading();
}
// notify menu code of successful network connect -----------------------------
//
void MenuNotifyConnect()
{
/* //TODO:
// make server list current
listwin_mode = LISTWIN_SERVERLIST;
*/
// make player list current
listwin_mode = LISTWIN_PLAYERLIST;
// toggle buttons
MenuButtonsToggleConnect();
}
// notify menu code of successful network disconnect --------------------------
//
void MenuNotifyDisconnect()
{
// make server list current
listwin_mode = LISTWIN_SERVERLIST;
// toggle buttons
MenuButtonsToggleDisconnect();
}
// enter game mode ("join game") ----------------------------------------------
//
void MENU_FloatingMenuEnterGame()
{
HideFloatingMenu();
HideStatusWindow();
// close menu sound
AUDs_CloseMenuSound();
// play sample for booting the on-board computer
AUD_BootOnBoardComputer();
#ifdef PLAY_DEMO_BEHIND_MENU
// stop the demo playback
if ( DEMO_BinaryReplayActive() ) {
DEMO_BinaryStopReplay();
}
AUX_STOP_DEMO_REPLAY_ON_CONNECT = 0;
#endif
// init ship stuff
ASSERT( LocalShipClass < MAX_DISTINCT_OBJCLASSES );
ASSERT( ObjClassShipIndex[ LocalShipClass ] < NumShipClasses );
InitLocalShipStatus( LocalShipClass );
InitHudDisplay();
InitFloatingMyShip();
// enter network game if possible
if ( NetConnected ) {
InitJoinPosition();
NETs_Join();
}
EntryMode = FALSE;
InFloatingMenu = FALSE;
ExitGameLoop = 0;
}
// determine whether joining is possible in the game status window ------------
//
INLINE
int GameStatusJoinAllowed()
{
if ( GAME_RUNNING() )
return TRUE;
if ( GAME_NO_SERVER() )
return TRUE;
if ( !NetConnected )
return TRUE;
if ( NumRemPlayers <= 1 )
return TRUE;
return FALSE;
}
// join game from game status window ------------------------------------------
//
PRIVATE
void GameStatusEnterGame()
{
if ( AUX_DISABLE_JOIN_GAME_BUTTON || disable_join_game )
return;
if ( !GameStatusJoinAllowed() )
return;
itemvis_gamestatus = FALSE;
MENU_FloatingMenuEnterGame();
}
// exit game status window ----------------------------------------------------
//
PRIVATE
void GameStatusKeyEscape()
{
menu_state_transition = MENUTRANS_FROM_GAMESTATUS;
}
// the escape key quits submenus, or selects quit in the toplevel menu --------
//
void ExecMenuEscape()
{
if ( MenuButtonsEscape() ) {
// play sound to denote quit selection
AUD_Select1();
} else {
// in submenus, <ESC> goes back to the previous menu
menu_state_transition = MENUTRANS_FROM_SUBMENU;
}
}
// main menu item selected: game submenu --------------------------------------
//
INLINE
void MenuItemSelectGame()
{
menu_state_transition = MENUTRANS_TO_SUBMENU;
}
// main menu item selected: server submenu ------------------------------------
//
INLINE
void MenuItemSelectServer()
{
//if ( AUX_DISABLE_SERVER_MENU_BUTTON )
// return;
// make server list current if suitable
if ( listwin_mode != LISTWIN_PLAYERLIST ) {
listwin_mode = LISTWIN_SERVERLIST;
}
menu_state_transition = MENUTRANS_TO_SUBMENU;
}
// main menu item selected: config submenu ------------------------------------
//
INLINE
void MenuItemSelectConfig()
{
menu_state_transition = MENUTRANS_TO_SUBMENU;
}
// main menu item selected: quit game -----------------------------------------
//
INLINE
void MenuItemSelectQuit()
{
if ( AUX_DISABLE_QUIT_BUTTON )
return;
ExitGameLoop = 1;
}
// game menu item selected: connect -------------------------------------------
//
INLINE
void MenuItemSelectConnect()
{
// connect and notify menu
if(NET_ProtocolGMSV()) {
if ( NET_CommandConnect( "servers.openparsec.com" ) ) {
MenuNotifyConnect();
}
} else {
if ( NET_CommandConnect( "peers" ) ) {
MenuNotifyConnect();
}
}
}
// game menu item selected: join game -----------------------------------------
//
PRIVATE
void MenuItemSelectJoinGame()
{
if ( AUX_DISABLE_JOIN_GAME_BUTTON || disable_join_game )
return;
MENU_FloatingMenuEnterGame();
}
// game menu item selected: starmap -------------------------------------------
//
INLINE
void MenuItemSelectStarmap()
{
MAP_ActivateStarmap();
}
// game menu item selected: play demo -----------------------------------------
//
INLINE
void MenuItemSelectPlayDemo()
{
if ( listwin_active || itemvis_gamestatus )
return;
// make demo list current
listwin_mode = LISTWIN_DEMOLIST;
// activate demo list if not already active
listwin_active = TRUE;
// make sure the button does at least something for mouse users
if ( mouse_position_state != MOUSE_OVER_NOTHING ) {
DemoListMouseSet();
}
}
// game menu item selected: disconnect ----------------------------------------
//
INLINE
void MenuItemSelectDisconnect()
{
if ( AUX_DISABLE_DISCONNECT_BUTTON )
return;
// disconnect and notify menu
if ( NET_CommandDisconnect() ) {
MenuNotifyDisconnect();
}
}
// server menu item selected: create server -----------------------------------
//
INLINE
void MenuItemSelectCreate()
{
//TODO:
}
// server menu item selected: game mod ----------------------------------------
//
INLINE
void MenuItemSelectGameMod()
{
// menu_state_transition = MENUTRANS_LIST_TO_GAMEMODS;
}
// server menu item selected: server settings ---------------------------------
//
INLINE
void MenuItemSelectSettings()
{
if ( AUX_DISABLE_SERVER_SETTINGS_BUTTON )
return;
// menu_state_transition = MENUTRANS_LIST_TO_SETTINGS;
}
// conf menu item selected: spacecraft viewer ---------------------------------
//
INLINE
void MenuItemSelectSpacecraft()
{
extern int scv_ring_objects[];
// init all objects for the ring
for ( int oid = 0; oid < NUM_SCV_OBJECTS; oid++ ) {
dword classid = ExtraClasses[ scv_ring_objects[ oid ] ];
if ( classid == CLASS_ID_INVALID ) {
continue;
}
MakeIdMatrx( ObjClasses[ classid ]->ObjPosition );
}
menu_state_transition = MENUTRANS_TO_VIEWER;
}
// conf menu item selected: controls dialog -----------------------------------
//
INLINE
void MenuItemSelectControls()
{
// menu_state_transition = MENUTRANS_LIST_TO_CONTROLS;
}
// conf menu item selected: show options menu ---------------------------------
//
INLINE
void MenuItemSelectOptions()
{
menu_state_transition = MENUTRANS_LIST_TO_OPTIONS;
FadeOutButtons( BUTTON_ALPHA_MID );
OptionsListSelectDefault();
}
// submenu item selected: back to previous menu -------------------------------
//
INLINE
void MenuItemSelectBack()
{
menu_state_transition = MENUTRANS_FROM_SUBMENU;
}
// select item of main menu ---------------------------------------------------
//
PRIVATE
void ExecMenuitemSelection( int menuitem )
{
// invoke corresponding function
switch ( menuitem ) {
// game submenu
case M_GAME:
MenuItemSelectGame();
break;
// server submenu
case M_SERVER:
MenuItemSelectServer();
break;
// config submenu
case M_CONFIG:
MenuItemSelectConfig();
break;
// quit
case M_QUIT:
MenuItemSelectQuit();
break;
// connect
case M_CONNECT:
MenuItemSelectConnect();
break;
// join game
case M_JOIN_GAME:
MenuItemSelectJoinGame();
break;
// starmap
case M_STARMAP:
MenuItemSelectStarmap();
break;
// play demo
case M_PLAY_DEMO:
MenuItemSelectPlayDemo();
break;
// disconnect
case M_DISCONNECT:
MenuItemSelectDisconnect();
break;
// create server
case M_CREATE:
MenuItemSelectCreate();
break;
// game mod
case M_GAME_MOD:
MenuItemSelectGameMod();
break;
// server settings
case M_SETTINGS:
MenuItemSelectSettings();
break;
// spacecraft
case M_SPACECRAFT:
MenuItemSelectSpacecraft();
break;
// controls
case M_CONTROLS:
MenuItemSelectControls();
break;
// options
case M_OPTIONS:
MenuItemSelectOptions();
break;
// back
case M_BACK:
MenuItemSelectBack();
break;
}
}
// select (and play) demo from demo list --------------------------------------
//
PRIVATE
void ExecDemoListSelection( int selindx )
{
// check for "free flight mode" demo
if ( selindx == -1 ) {
MenuItemSelectJoinGame();
} else if ( !NetConnected ) {
// close menu sound
AUDs_CloseMenuSound();
if ( DEMO_BinaryReplayActive() ) {
DEMO_BinaryStopReplay();
}
DEMO_PlayFromMenu( registered_demo_names[ selindx ] );
AUX_STOP_DEMO_REPLAY_ON_CONNECT = 1;
}
listwin_active = FALSE;
}
// select item from list ------------------------------------------------------
//
PRIVATE
void ExecListSelection()
{
switch ( listwin_mode ) {
case LISTWIN_DEMOLIST:
ExecDemoListSelection( DemoListSelection() );
break;
case LISTWIN_PLAYERLIST:
// ExecPlayerListSelection( selindx );
break;
case LISTWIN_SERVERLIST:
// ExecServerListSelection( selindx );
break;
}
}
// move cursor up in list window ----------------------------------------------
//
PRIVATE
void ListCursorUp()
{
switch ( listwin_mode ) {
case LISTWIN_DEMOLIST:
DemoListCursorUp();
break;
case LISTWIN_PLAYERLIST:
// PlayerListCursorUp();
break;
case LISTWIN_SERVERLIST:
// ServerListCursorUp( selindx );
break;
}
}
// move cursor down in list window --------------------------------------------
//
PRIVATE
void ListCursorDown()
{
switch ( listwin_mode ) {
case LISTWIN_DEMOLIST:
DemoListCursorDown();
break;
case LISTWIN_PLAYERLIST:
// PlayerListCursorDown();
break;
case LISTWIN_SERVERLIST:
// ServerListCursorDown( selindx );
break;
}
}
// action for <ENTER> pressed in spacecraft viewer ----------------------------
//
PRIVATE
void SpacecraftViewerKeyEnter()
{
switch ( cur_scv_mode ) {
case SCVMODE_SPACECRAFT:
ASSERT( cur_scv_ship < NumShipClasses );
LocalShipClass = ShipClasses[ cur_scv_ship ];
menu_state_transition = MENUTRANS_FROM_VIEWER;
break;
case SCVMODE_OBJECTSRING:
menu_state_transition = MENUTRANS_OBJECTS_TO_SHIP;
break;
default:
ASSERT( 0 );
break;
}
}
// action for <ESC> pressed in spacecraft viewer ------------------------------
//
PRIVATE
void SpacecraftViewerKeyEscape()
{
// exit spacecraft viewer
menu_state_transition = MENUTRANS_FROM_VIEWER;
}
// action for <CURSOR-UP> pressed in spacecraft viewer ------------------------
//
PRIVATE
void SpacecraftViewerKeyCursorUp()
{
switch ( cur_scv_mode ) {
case SCVMODE_SPACECRAFT:
menu_state_transition = MENUTRANS_SHIP_TO_OBJECTS;
AUD_Select1();
break;
case SCVMODE_OBJECTSRING:
menu_state_transition = MENUTRANS_OBJECTS_TO_SHIP;
AUD_Select1();
break;
default:
ASSERT( 0 );
break;
}
}
// action for <CURSOR-DOWN> pressed in spacecraft viewer ----------------------
//
PRIVATE
void SpacecraftViewerKeyCursorDown()
{
switch ( cur_scv_mode ) {
case SCVMODE_SPACECRAFT:
menu_state_transition = MENUTRANS_SHIP_TO_OBJECTS;
AUD_Select1();
break;
case SCVMODE_OBJECTSRING:
menu_state_transition = MENUTRANS_OBJECTS_TO_SHIP;
AUD_Select1();
break;
default:
ASSERT( 0 );
break;
}
}
// action for <CURSOR-LEFT> pressed in spacecraft viewer ----------------------
//
PRIVATE
void SpacecraftViewerKeyCursorLeft()
{
switch ( cur_scv_mode ) {
case SCVMODE_SPACECRAFT:
if ( --cur_scv_ship < 0 ) {
cur_scv_ship = NumShipClasses - 1;
}
AUD_Select2();
break;
case SCVMODE_OBJECTSRING:
scv_ring_spinning = 1;
AUD_Select2();
break;
default:
ASSERT( 0 );
break;
}
}
// action for <CURSOR-RIGHT> pressed in spacecraft viewer ---------------------
//
PRIVATE
void SpacecraftViewerKeyCursorRight()
{
switch ( cur_scv_mode ) {
case SCVMODE_SPACECRAFT:
if ( ++cur_scv_ship >= NumShipClasses ) {
cur_scv_ship = 0;
}
AUD_Select2();
break;
case SCVMODE_OBJECTSRING:
scv_ring_spinning = -1;
AUD_Select2();
break;
default:
ASSERT( 0 );
break;
}
}
// action for <ENTER> pressed in menu -----------------------------------------
//
PRIVATE
void FloatingMenuKeyEnter()
{
if ( itemvis_optionsmenu ) {
ExecOptionSelection( OptionsListSelection() );
} else if ( itemvis_viewer ) {
SpacecraftViewerKeyEnter();
} else if ( itemvis_gamestatus ) {
GameStatusEnterGame();
} else if ( listwin_active ) {
ExecListSelection();
} else {
ExecMenuitemSelection( MenuButtonsSelection() );
}
}
// action for <ESC> pressed in menu -------------------------------------------
//
PRIVATE
void FloatingMenuKeyEscape()
{
// key checking only if no transition in progress
if ( menu_state_transition != MENUTRANS_NONE )
return;
if ( itemvis_gamestatus ) {
GameStatusKeyEscape();
} else if ( itemvis_viewer ) {
SpacecraftViewerKeyEscape();
} else if ( itemvis_optionsmenu ){
// exit options menu
ExecOptionSelection( EXIT_OPT );
} else if ( listwin_active ) {
// move cursor from list window to buttons
listwin_active = FALSE;
} else {
ExecMenuEscape();
}
}
// action for <CURSOR-UP> pressed in menu -------------------------------------
//
PRIVATE
void FloatingMenuKeyCursorUp()
{
if ( itemvis_optionsmenu ) {
OptionsListCursorUp();
} else if ( itemvis_viewer ) {
SpacecraftViewerKeyCursorUp();
} else if ( listwin_active ) {
ListCursorUp();
} else {
MenuButtonsCursorUp();
}
}
// action for <CURSOR-DOWN> pressed in menu -----------------------------------
//
PRIVATE
void FloatingMenuKeyCursorDown()
{
if ( itemvis_optionsmenu ) {
OptionsListCursorDown();
} else if ( itemvis_viewer ) {
SpacecraftViewerKeyCursorDown();
} else if ( listwin_active ) {
ListCursorDown();
} else {
MenuButtonsCursorDown();
}
}
// action for <CURSOR-LEFT> pressed in menu -----------------------------------
//
PRIVATE
void FloatingMenuKeyCursorLeft()
{
if ( itemvis_viewer ) {
SpacecraftViewerKeyCursorLeft();
}
}
// action for <CURSOR-RIGHT> pressed in menu ----------------------------------
//
PRIVATE
void FloatingMenuKeyCursorRight()
{
if ( itemvis_viewer ) {
SpacecraftViewerKeyCursorRight();
}
}
// ensure mouse is properly turned off ----------------------------------------
//
INLINE
void FloatingMenuMouseOff()
{
// ensure it will be detected as
// moved when turned on again
old_mouse_x = -1;
old_mouse_y = -1;
// kill dangling button presses
cur_mouse_button_state = MOUSE_BUTTON_RELEASED;
}
// handle mouse actions for floating menu -------------------------------------
//
PRIVATE
void FloatingMenuMouseGetState()
{
// avoid dangling position state
mouse_position_state = MOUSE_OVER_NOTHING;
// retrieve mouse state
mousestate_s mousestate;
int mouseavailable = INPs_MouseGetState( &mousestate );
// make sure mouse is there
if ( !mouseavailable ) {
FloatingMenuMouseOff();
return;
}
cur_mouse_x = (int) ( mousestate.xpos * Screen_Width );
cur_mouse_y = (int) ( mousestate.ypos * Screen_Height );
cur_mouse_button_state = mousestate.buttons[ MOUSE_BUTTON_LEFT ];
// if button released check only if mouse has been moved since last frame
if ( cur_mouse_button_state == MOUSE_BUTTON_RELEASED ) {
if ( ( cur_mouse_x == old_mouse_x ) && ( cur_mouse_y == old_mouse_y ) ) {
return;
}
}
old_mouse_x = cur_mouse_x;
old_mouse_y = cur_mouse_y;
// area checking only if no transition in progress
if ( menu_state_transition != MENUTRANS_NONE )
return;
// check if mouse is over any clickable area
if ( itemvis_optionsmenu ) {
mouse_position_state = MouseOverOption( cur_mouse_x, cur_mouse_y );
} else if ( itemvis_viewer ) {
mouse_position_state = MouseOverViewerItem( cur_mouse_x, cur_mouse_y );
} else {
if ( itemvis_listwindow ) {
mouse_position_state = MouseOverListItem( cur_mouse_x, cur_mouse_y );
if ( mouse_position_state != MOUSE_OVER_NOTHING ) {
listwin_active = TRUE;
}
}
if ( mouse_position_state == MOUSE_OVER_NOTHING ) {
mouse_position_state = MouseOverMenuButton( cur_mouse_x, cur_mouse_y );
if ( mouse_position_state != MOUSE_OVER_NOTHING ) {
listwin_active = FALSE;
}
}
}
}
// must be called before using key via mouse simulation functions -------------
//
INLINE
void FloatingMenuMouseBegin()
{
if ( AUX_ENABLE_MOUSE_FOR_MENU_SCREENS ) {
FloatingMenuMouseGetState();
} else {
FloatingMenuMouseOff();
}
}
// must be called after using key via mouse simulation functions --------------
//
INLINE
void FloatingMenuMouseEnd()
{
// remember state for edge detection
old_mouse_button_state = cur_mouse_button_state;
}
// determine whether enter simulated with mouse button ------------------------
//
INLINE
int FloatingMenuMousePressedEnter()
{
int mousepressed =
( ( cur_mouse_button_state != old_mouse_button_state ) &&
( cur_mouse_button_state == MOUSE_BUTTON_PRESSED ) &&
( mouse_position_state & MOUSE_OVER_ENTER_SIMUL ) );
return mousepressed;
}
// determine whether cursor up simulated with mouse button --------------------
//
INLINE
int FloatingMenuMousePressedCursorUp()
{
int mousepressed =
( ( cur_mouse_button_state != old_mouse_button_state ) &&
( cur_mouse_button_state == MOUSE_BUTTON_PRESSED ) &&
( mouse_position_state & MOUSE_OVER_CURUP_SIMUL ) );
return mousepressed;
}
// determine whether cursor down simulated with mouse button ------------------
//
INLINE
int FloatingMenuMousePressedCursorDown()
{
int mousepressed =
( ( cur_mouse_button_state != old_mouse_button_state ) &&
( cur_mouse_button_state == MOUSE_BUTTON_PRESSED ) &&
( mouse_position_state & MOUSE_OVER_CURDN_SIMUL ) );
return mousepressed;
}
// determine whether cursor left simulated with mouse button ------------------
//
INLINE
int FloatingMenuMousePressedCursorLeft()
{
int mousepressed =
( ( cur_mouse_button_state != old_mouse_button_state ) &&
( cur_mouse_button_state == MOUSE_BUTTON_PRESSED ) &&
( mouse_position_state & MOUSE_OVER_CURLF_SIMUL ) );
return mousepressed;
}
// determine whether cursor right simulated with mouse button -----------------
//
INLINE
int FloatingMenuMousePressedCursorRight()
{
int mousepressed =
( ( cur_mouse_button_state != old_mouse_button_state ) &&
( cur_mouse_button_state == MOUSE_BUTTON_PRESSED ) &&
( mouse_position_state & MOUSE_OVER_CURRT_SIMUL ) );
return mousepressed;
}
// for sticky rotation of objects ring ----------------------------------------
//
PUBLIC int rotkey_active_left = FALSE;
PUBLIC int rotkey_active_right = FALSE;
// check if enter key is pressed (or simulated) -------------------------------
//
INLINE
int FloatingMenuKeyPressedEnter()
{
int keypressed = SELECT_KEYS_PRESSED();
if ( keypressed ) {
SELECT_KEYS_RESET();
}
return ( keypressed || FloatingMenuMousePressedEnter() );
}
// check if cursor up is pressed (or simulated) -------------------------------
//
INLINE
int FloatingMenuKeyPressedCursorUp()
{
int keypressed = DepressedKeys->key_CursorUp;
// if ( keypressed ) {
DepressedKeys->key_CursorUp = 0;
// }
return ( keypressed || FloatingMenuMousePressedCursorUp() );
}
// check if cursor down is pressed (or simulated) -----------------------------
//
INLINE
int FloatingMenuKeyPressedCursorDown()
{
int keypressed = DepressedKeys->key_CursorDown;
// if ( keypressed ) {
DepressedKeys->key_CursorDown = 0;
// }
return ( keypressed || FloatingMenuMousePressedCursorDown() );
}
// check if cursor left is pressed (or simulated) -----------------------------
//
INLINE
int FloatingMenuKeyPressedCursorLeft()
{
int keypressed = ( DepressedKeys->key_CursorLeft && !rotkey_active_left );
if ( keypressed ) {
// DepressedKeys->key_CursorLeft = 0;
rotkey_active_left = TRUE;
}
return ( keypressed || FloatingMenuMousePressedCursorLeft() );
}
// check if cursor right is pressed (or simulated) ----------------------------
//
INLINE
int FloatingMenuKeyPressedCursorRight()
{
int keypressed = ( DepressedKeys->key_CursorRight && !rotkey_active_right );
if ( keypressed ) {
// DepressedKeys->key_CursorRight = 0;
rotkey_active_right = TRUE;
}
return ( keypressed || FloatingMenuMousePressedCursorRight() );
}
// handle standard keys in floating menu --------------------------------------
//
PRIVATE
void FloatingMenuKeyStandard()
{
// standard key checking only if no transition in progress
if ( menu_state_transition != MENUTRANS_NONE )
return;
if ( FloatingMenuKeyPressedEnter() ) {
FloatingMenuKeyEnter();
} else if ( FloatingMenuKeyPressedCursorUp() ) {
FloatingMenuKeyCursorUp();
} else if ( FloatingMenuKeyPressedCursorDown() ) {
FloatingMenuKeyCursorDown();
} else if ( FloatingMenuKeyPressedCursorLeft() ) {
FloatingMenuKeyCursorLeft();
} else if ( FloatingMenuKeyPressedCursorRight() ) {
FloatingMenuKeyCursorRight();
}
}
// handle keyboard input for menu ---------------------------------------------
//
void FloatingMenuKeyHandler()
{
ASSERT( FloatingMenu );
ASSERT( InFloatingMenu );
//NOTE:
// this function is called each frame by the
// gameloop via G_MAIN::Gm_FloatingMenuSpecifics().
// allow mouse for keyboard simulation
FloatingMenuMouseBegin();
if ( ExitGameLoop && ExitGameLoop != 3 ) {
//NOTE:
// we intercept the game loop exit caused by pressing escape
// because we never exit the game loop immediately when the
// floating menu is active. it will only be exited when the
// user actually presses enter on the quit button.
ExitGameLoop = 0;
FloatingMenuKeyEscape();
} else {
FloatingMenuKeyStandard();
}
// reset sticky object rotation if necessary
if ( !DepressedKeys->key_CursorLeft ) {
rotkey_active_left = FALSE;
}
if ( !DepressedKeys->key_CursorRight ) {
rotkey_active_right = FALSE;
}
FloatingMenuMouseEnd();
}
// module registration function -----------------------------------------------
//
REGISTER_MODULE( M_MAIN )
{
// precalculate a quarter of a sine wave ampl*[1.0,0.0] for all sliding
hprec_t anorm = ( m_sintab_size - 1 ) * 2;
for ( int tid = 0; tid < m_sintab_size; tid++ ) {
hprec_t angle = HPREC_PI * tid;
m_sintab[ tid ] = (int)(m_sintab_ampl * sin( angle / anorm ));
m_sintab[ tid ] = m_sintab_ampl - m_sintab[ tid ];
}
}
|