forked from scp-fs2open/fs2open.github.com
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui.cpp
More file actions
3995 lines (3283 loc) · 103 KB
/
Copy pathui.cpp
File metadata and controls
3995 lines (3283 loc) · 103 KB
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
//
//
#include "ui.h"
#include "freespace.h"
#include "globalincs/alphacolors.h"
#include "cmdline/cmdline.h"
#include "cutscene/cutscenes.h"
#include "gamesnd/eventmusic.h"
#include "gamesequence/gamesequence.h"
#include "io/key.h"
#include "menuui/barracks.h"
#include "menuui/credits.h"
#include "menuui/mainhallmenu.h"
#include "menuui/optionsmenu.h"
#include "menuui/playermenu.h"
#include "menuui/readyroom.h"
#include "mission/missionmessage.h"
#include "mission/missionbriefcommon.h"
#include "mission/missionparse.h"
#include "missionui/fictionviewer.h"
#include "missionui/missionbrief.h"
#include "mission/missioncampaign.h"
#include "missionui/missionscreencommon.h"
#include "missionui/missiondebrief.h"
#include "mission/missiongoals.h"
#include "mission/missioncampaign.h"
#include "mission/missionhotkey.h"
#include "missionui/chatbox.h"
#include "missionui/redalert.h"
#include "missionui/missionpause.h"
#include "mod_table/mod_table.h"
#include "network/chat_api.h"
#include "network/multi.h"
#include "network/multiui.h"
#include "network/multi_endgame.h"
#include "network/multiteamselect.h"
#include "network/multi_pause.h"
#include "network/multi_pxo.h"
#include "network/multimsgs.h"
#include "network/multi_ingame.h"
#include "pilotfile/pilotfile.h"
#include "playerman/managepilot.h"
#include "radar/radarsetup.h"
#include "ship/ship.h"
#include "weapon/weapon.h"
#include "scpui/SoundPlugin.h"
#include "scpui/rocket_ui.h"
#include "scripting/api/objs/briefing.h"
#include "scripting/api/objs/cmd_brief.h"
#include "scripting/api/objs/color.h"
#include "scripting/api/objs/control_config.h"
#include "scripting/api/objs/debriefing.h"
#include "scripting/api/objs/enums.h"
#include "scripting/api/objs/fictionviewer.h"
#include "scripting/api/objs/gamehelp.h"
#include "scripting/api/objs/goal.h"
#include "scripting/api/objs/hudconfig.h"
#include "scripting/api/objs/loop_brief.h"
#include "scripting/api/objs/medals.h"
#include "scripting/api/objs/missionhotkey.h"
#include "scripting/api/objs/missionlog.h"
#include "scripting/api/objs/multi_objects.h"
#include "scripting/api/objs/player.h"
#include "scripting/api/objs/rank.h"
#include "scripting/api/objs/redalert.h"
#include "scripting/api/objs/shipwepselect.h"
#include "scripting/api/objs/techroom.h"
#include "scripting/api/objs/texture.h"
#include "scripting/api/objs/vecmath.h"
#include "scripting/lua/LuaTable.h"
#include "sound/audiostr.h"
#include "stats/medals.h"
#include "stats/stats.h"
// Our Assert conflicts with the definitions inside libRocket
#pragma push_macro("Assert")
#undef Assert
#include <Rocket/Core/Lua/LuaType.h>
#pragma pop_macro("Assert")
namespace scripting {
namespace api {
//*************************Global UI stuff*************************
ADE_LIB(l_UserInterface, "UserInterface", "ui", "Functions for managing the \"SCPUI\" user interface system.");
ADE_FUNC(setOffset, l_UserInterface, "number x, number y",
"Sets the offset from the top left corner at which <b>all</b> rocket contexts will be rendered", "boolean",
"true if the operation was successful, false otherwise")
{
float x;
float y;
if (!ade_get_args(L, "ff", &x, &y)) {
return ADE_RETURN_FALSE;
}
scpui::setOffset(x, y);
return ADE_RETURN_TRUE;
}
ADE_FUNC(enableInput,
l_UserInterface,
"any context /* A libRocket Context value */",
"Enables input for the specified libRocket context",
"boolean",
"true if successful")
{
using namespace Rocket::Core;
// Check parameter number
if (!ade_get_args(L, "*")) {
return ADE_RETURN_FALSE;
}
auto ctx = Lua::LuaType<Context>::check(L, 1);
if (ctx == nullptr) {
LuaError(L, "Parameter 1 is not a valid context handle!");
return ADE_RETURN_FALSE;
}
scpui::enableInput(ctx);
game_flush();
Main_hall_poll_key = false;
return ADE_RETURN_TRUE;
}
ADE_FUNC(disableInput, l_UserInterface, nullptr, "Disables UI input", nullptr, "nothing")
{
SCP_UNUSED(L);
scpui::disableInput();
game_flush();
Main_hall_poll_key = true;
return ADE_RETURN_NIL;
}
ADE_VIRTVAR(ColorTags,
l_UserInterface,
nullptr,
"The available tagged colors",
"{ string => color ... }",
"A mapping from tag string to color value")
{
using namespace luacpp;
LuaTable mapping = LuaTable::create(L);
for (const auto& tagged : Tagged_Colors) {
SCP_string tag;
tag.resize(1, tagged.first);
mapping.addValue(tag, l_Color.Set(*tagged.second));
}
return ade_set_args(L, "t", mapping);
}
ADE_FUNC(DefaultTextColorTag,
l_UserInterface,
"number UiScreen",
"Gets the default color tag string for the specified state. 1 for Briefing, 2 for CBriefing, 3 for Debriefing, "
"4 for Fiction Viewer, 5 for Red Alert, 6 for Loop Briefing, 7 for Recommendation text. Defaults to 1. Index into ColorTags.",
"string",
"The default color tag")
{
int UiScreen;
if (!ade_get_args(L, "i", &UiScreen)) {
UiScreen = 1;
}
SCP_string tagStr;
char defaultColor = default_briefing_color;
switch (UiScreen) {
case 1:
defaultColor = default_briefing_color;
break;
case 2:
defaultColor = default_command_briefing_color;
break;
case 3:
defaultColor = default_debriefing_color;
break;
case 4:
defaultColor = default_fiction_viewer_color;
break;
case 5:
defaultColor = default_redalert_briefing_color;
break;
case 6:
defaultColor = default_loop_briefing_color;
break;
case 7:
defaultColor = default_recommendation_color;
break;
}
if (defaultColor == '\0' || !brief_verify_color_tag(defaultColor)) {
defaultColor = Color_Tags[0];
}
tagStr.resize(1, defaultColor);
return ade_set_args(L, "s", tagStr);
}
ADE_FUNC(playElementSound,
l_UserInterface,
"any element /* A libRocket element */, string event, string state = \"\"",
"Plays an element specific sound with an optional state for differentiating different UI states.",
"boolean",
"true if a sound was played, false otherwise")
{
using namespace Rocket::Core;
const char* event;
const char* state = "";
if (!ade_get_args(L, "*s|s", &event, &state)) {
return ADE_RETURN_FALSE;
}
auto el = Lua::LuaType<Element>::check(L, 1);
if (el == nullptr) {
return ADE_RETURN_FALSE;
}
return ade_set_args(L, "b", scpui::SoundPlugin::instance()->PlayElementSound(el, event, state));
}
ADE_FUNC(maybePlayCutscene, l_UserInterface, "enumeration MovieType /* MOVIE_* */, boolean RestartMusic, number ScoreIndex", "Plays a cutscene, if one exists, for the appropriate state transition. If RestartMusic is true, then the music score at ScoreIndex will be started after the cutscene plays.", nullptr, "Returns nothing")
{
enum_h movie_type;
bool restart_music = false;
int score_index = 0;
if (!ade_get_args(L, "obi", l_Enum.Get(&movie_type), &restart_music, &score_index))
return ADE_RETURN_NIL;
if (!movie_type.isValid() || movie_type.index < LE_MOVIE_PRE_FICTION || movie_type.index > LE_MOVIE_END_CAMPAIGN)
{
Warning(LOCATION, "Invalid movie type index %d", movie_type.index);
return ADE_RETURN_NIL;
}
common_maybe_play_cutscene(movie_type.index - LE_MOVIE_PRE_FICTION, restart_music, score_index);
return ADE_RETURN_NIL;
}
ADE_FUNC(playCutscene, l_UserInterface, "string Filename, boolean RestartMusic, number ScoreIndex", "Plays a cutscene. If RestartMusic is true, then the music score at ScoreIndex will be started after the cutscene plays.", nullptr, "Returns nothing")
{
const char* filename;
bool restart_music = false;
int score_index = 0;
if (!ade_get_args(L, "sbi", &filename, &restart_music, &score_index))
return ADE_RETURN_NIL;
common_play_cutscene(filename, restart_music, score_index);
return ADE_RETURN_NIL;
}
ADE_FUNC(isCutscenePlaying, l_UserInterface, nullptr, "Checks if a cutscene is playing.", "boolean", "Returns true if cutscene is playing, false otherwise")
{
return ade_set_args(L, "b", Movie_active);
}
ADE_FUNC(launchURL, l_UserInterface, "string url", "Launches the given URL in a web browser", nullptr, nullptr)
{
const char* url;
if (!ade_get_args(L, "s", &url))
return ADE_RETURN_NIL;
multi_pxo_url(url);
return ADE_RETURN_NIL;
}
ADE_FUNC(linkTexture, l_UserInterface, "texture texture", "Links a texture directly to librocket.", "string", "The url string for librocket, or an empty string if invalid.")
{
texture_h* tex;
if (!ade_get_args(L, "o", l_Texture.GetPtr(&tex)))
return ade_set_error(L, "s", "");
if(tex == nullptr || !tex->isValid())
return ade_set_error(L, "s", "");
return ade_set_args(L, "s", "data:image/bmpman," + std::to_string(tex->handle));
}
//**********SUBLIBRARY: UserInterface/PilotSelect
ADE_LIB_DERIV(l_UserInterface_PilotSelect, "PilotSelect", nullptr,
"API for accessing values specific to the Pilot Select UI.",
l_UserInterface);
ADE_VIRTVAR_DEPRECATED(MAX_PILOTS, l_UserInterface_PilotSelect, nullptr, "Gets the maximum number of possible pilots.", "number",
"The maximum number of pilots",
gameversion::version(25, 0, 0, 0),
"This variable has moved to the GlobalVariabls library.")
{
return ade_set_args(L, "i", MAX_PILOTS);
}
ADE_VIRTVAR(WarningCount, l_UserInterface_PilotSelect, nullptr, "The amount of warnings caused by the mod while loading.", "number",
"The maximum number of pilots")
{
return ade_set_args(L, "i", Global_warning_count);
}
ADE_VIRTVAR(ErrorCount, l_UserInterface_PilotSelect, nullptr, "The amount of errors caused by the mod while loading.", "number",
"The maximum number of pilots")
{
return ade_set_args(L, "i", Global_error_count);
}
ADE_FUNC(enumeratePilots, l_UserInterface_PilotSelect, nullptr,
"Lists all pilots available for the pilot selection<br>", "table",
"A table containing the pilots (without a file extension) or nil on error")
{
using namespace luacpp;
auto table = LuaTable::create(L);
auto pilots = player_select_enumerate_pilots();
for (size_t i = 0; i < pilots.size(); ++i) {
table.addValue(i + 1, pilots[i]);
}
return ade_set_args(L, "t", &table);
}
ADE_FUNC(getLastPilot, l_UserInterface_PilotSelect, nullptr,
"Reads the last active pilot from the config file and returns some information about it. callsign is the name "
"of the player and is_multi indicates whether the pilot was last active as a multiplayer pilot.",
"string", "The pilot name or nil if there was no last pilot")
{
using namespace luacpp;
auto callsign = player_get_last_player();
if (callsign.empty()) {
return ADE_RETURN_NIL;
}
return ade_set_args(L, "s", callsign.c_str());
}
ADE_FUNC(checkPilotLanguage, l_UserInterface_PilotSelect, "string callsign",
"Checks if the pilot with the specified callsign has the right language.", "boolean",
"true if pilot is valid, false otherwise")
{
const char* callsign;
if (!ade_get_args(L, "s", &callsign)) {
return ADE_RETURN_FALSE;
}
return ade_set_args(L, "b", valid_pilot(callsign, true));
}
ADE_FUNC(selectPilot, l_UserInterface_PilotSelect, "string callsign, boolean is_multi",
"Selects the pilot with the specified callsign and advances the game to the main menu.", nullptr, "nothing")
{
const char* callsign;
bool is_multi;
if (!ade_get_args(L, "sb", &callsign, &is_multi)) {
return ADE_RETURN_NIL;
}
player_finish_select(callsign, is_multi);
return ADE_RETURN_NIL;
}
ADE_FUNC(deletePilot, l_UserInterface_PilotSelect, "string callsign",
"Deletes the pilot with the specified callsign. This is not reversible!", "boolean",
"true on success, false otherwise")
{
const char* callsign;
if (!ade_get_args(L, "s", &callsign)) {
return ADE_RETURN_NIL;
}
return ade_set_args(L, "b", delete_pilot_file(callsign));
}
ADE_FUNC(
createPilot, l_UserInterface_PilotSelect, "string callsign, boolean is_multi, [string copy_from]",
"Creates a new pilot in either single or multiplayer mode and optionally copies settings from an existing pilot.",
"boolean", "true on success, false otherwise")
{
const char* callsign;
bool is_multi;
const char* copy_from = nullptr;
if (!ade_get_args(L, "sb|s", &callsign, &is_multi, ©_from)) {
return ADE_RETURN_NIL;
}
return ade_set_args(L, "b", player_create_new_pilot(callsign, is_multi, copy_from));
}
ADE_FUNC(unloadPilot,
l_UserInterface_PilotSelect,
nullptr,
"Unloads a player file & associated campaign file. Can not be used outside of pilot select!",
"boolean",
"Returns true if successful, false otherwise")
{
if (gameseq_get_state() == GS_STATE_INITIAL_PLAYER_SELECT) {
Player = nullptr;
Campaign.filename[0] = '\0';
return ADE_RETURN_TRUE;
}
return ADE_RETURN_FALSE;
}
ADE_FUNC(isAutoselect, l_UserInterface_PilotSelect, nullptr,
"Determines if the pilot selection screen should automatically select the default user.", "boolean",
"true if autoselect is enabled, false otherwise")
{
return ade_set_args(L, "b", Cmdline_benchmark_mode || Cmdline_pilot);
}
ADE_VIRTVAR(CmdlinePilot, l_UserInterface_PilotSelect, nullptr,
"The pilot chosen from commandline, if any.", "string",
"The name if specified, nil otherwise")
{
if (Cmdline_pilot)
return ade_set_args(L, "s", Cmdline_pilot);
else
return ADE_RETURN_NIL;
}
//**********SUBLIBRARY: UserInterface/MainHall
ADE_LIB_DERIV(l_UserInterface_MainHall, "MainHall", nullptr,
"API for accessing values specific to the Main Hall UI.",
l_UserInterface);
ADE_FUNC(startAmbientSound, l_UserInterface_MainHall, nullptr, "Starts the ambient mainhall sound.", nullptr, "nothing")
{
SCP_UNUSED(L);
main_hall_start_ambient();
return ADE_RETURN_NIL;
}
ADE_FUNC(stopAmbientSound, l_UserInterface_MainHall, nullptr, "Stops the ambient mainhall sound.", nullptr, "nothing")
{
SCP_UNUSED(L);
main_hall_stop_ambient();
return ADE_RETURN_NIL;
}
ADE_FUNC(startMusic, l_UserInterface_MainHall, nullptr, "Starts the mainhall music.", nullptr, "nothing")
{
SCP_UNUSED(L);
main_hall_start_music();
return ADE_RETURN_NIL;
}
ADE_FUNC(stopMusic, l_UserInterface_MainHall, "boolean Fade=false", "Stops the mainhall music. True to fade, false to stop immediately.", nullptr, "nothing")
{
bool fade = false;
if (!ade_get_args(L, "|b", &fade))
return ADE_RETURN_NIL;
main_hall_stop_music(fade);
return ADE_RETURN_NIL;
}
ADE_FUNC(toggleHelp,
l_UserInterface_MainHall,
"boolean",
"Sets the mainhall F1 help overlay to display. True to display, false to hide",
nullptr,
"nothing")
{
bool toggle;
if (!ade_get_args(L, "b", &toggle))
return ADE_RETURN_NIL;
main_hall_toggle_help(toggle);
return ADE_RETURN_NIL;
}
ADE_FUNC(setMainhall, l_UserInterface_MainHall, "string mainhall, boolean enforce", "The name of the mainhall to try to set. Will immediately change if the player is currently in the mainhall menu. "
"Use enforce to set this as the mainhall on next mainhall load if setting from outside the mainhall menu. NOTE: If enforce is true then the player will always return back to this mainhall forever. "
"Call this with a blank string and enforce false to unset enforce without changing the current mainhall that is loaded.", nullptr, "nothing")
{
const char* name = nullptr;
bool enforce = false;
if (!ade_get_args(L, "s|b", &name, &enforce)) {
return ADE_RETURN_NIL;
}
if (enforce) {
Enforced_main_hall = name;
} else {
Enforced_main_hall.clear();
}
if (gameseq_get_state() == GS_STATE_MAIN_MENU) {
if (name[0] != '\0') {
main_hall_close();
main_hall_init(name);
}
}
return ADE_RETURN_NIL;
}
//**********SUBLIBRARY: UserInterface/Barracks
ADE_LIB_DERIV(l_UserInterface_Barracks, "Barracks", nullptr,
"API for accessing values specific to the Barracks UI.",
l_UserInterface);
ADE_FUNC(listPilotImages, l_UserInterface_Barracks, nullptr, "Lists the names of the available pilot images.",
"table", "The list of pilot filenames or nil on error")
{
pilot_load_pic_list();
using namespace luacpp;
LuaTable out = LuaTable::create(L);
for (auto i = 0; i < Num_pilot_images; ++i) {
out.addValue(i + 1, Pilot_image_names[i]);
}
return ade_set_args(L, "t", &out);
}
ADE_FUNC(listSquadImages, l_UserInterface_Barracks, nullptr, "Lists the names of the available squad images.",
"table", "The list of squad filenames or nil on error")
{
pilot_load_squad_pic_list();
using namespace luacpp;
LuaTable out = LuaTable::create(L);
for (auto i = 0; i < Num_pilot_squad_images; ++i) {
out.addValue(i + 1, Pilot_squad_image_names[i]);
}
return ade_set_args(L, "t", &out);
}
ADE_FUNC(acceptPilot, l_UserInterface_Barracks, "player selection, [boolean changeState]", "Accept the given player as the current player. Set second argument to false to prevent returning to the mainhall",
"boolean", "true on success, false otherwise")
{
player_h* plh;
bool changeState = true;
if (!ade_get_args(L, "o|b", l_Player.GetPtr(&plh), &changeState)) {
return ADE_RETURN_FALSE;
}
barracks_accept_pilot(plh->get(), changeState);
return ADE_RETURN_TRUE;
}
//**********SUBLIBRARY: UserInterface/OptionsMenu
// This needs a slightly different name since there is already a type called "Options"
ADE_LIB_DERIV(l_UserInterface_Options,
"OptionsMenu",
nullptr,
"API for accessing values specific to the Options UI.",
l_UserInterface);
ADE_FUNC(playVoiceClip,
l_UserInterface_Options,
nullptr,
"Plays the example voice clip used for checking the voice volume",
"boolean",
"true on success, false otherwise")
{
options_play_voice_clip();
return ADE_RETURN_TRUE;
}
ADE_FUNC(savePlayerData,
l_UserInterface_Options,
nullptr,
"Saves all player data. This includes the player file and campaign file.",
nullptr,
nullptr)
{
SCP_UNUSED(L);
Pilot.save_player();
Pilot.save_savefile();
return ADE_RETURN_NIL;
}
//**********SUBLIBRARY: UserInterface/CampaignMenu
ADE_LIB_DERIV(l_UserInterface_Campaign,
"CampaignMenu",
nullptr,
"API for accessing data related to the Campaign UI.",
l_UserInterface);
ADE_FUNC(loadCampaignList,
l_UserInterface_Campaign,
nullptr,
"Loads the list of available campaigns",
"boolean",
// ade_type_info({ade_type_array("string"), ade_type_array("string")}),
"false if something failed while loading the list, true otherwise")
{
return ade_set_args(L, "b", !campaign_build_campaign_list());
}
ADE_FUNC(getCampaignList,
l_UserInterface_Campaign,
nullptr,
"Get the campaign name and description lists",
"table, table, table",
"Three tables with the names, file names, and descriptions of the campaigns")
{
luacpp::LuaTable nameTable = luacpp::LuaTable::create(L);
luacpp::LuaTable fileNameTable = luacpp::LuaTable::create(L);
luacpp::LuaTable descriptionTable = luacpp::LuaTable::create(L);
for (int i = 0; i < Num_campaigns; ++i) {
nameTable.addValue(i + 1, Campaign_names[i]);
fileNameTable.addValue(i + 1, Campaign_file_names[i]);
auto description = Campaign_descs[i];
descriptionTable.addValue(i + 1, description ? description : "");
}
// We actually do not need this anymore now so free it immediately
mission_campaign_free_list();
return ade_set_args(L, "ttt", nameTable, fileNameTable, descriptionTable);
}
ADE_FUNC(selectCampaign,
l_UserInterface_Campaign,
"string campaign_file",
"Selects the specified campaign file name",
"boolean",
"true if successful, false otherwise")
{
const char* filename = nullptr;
if (!ade_get_args(L, "s", &filename)) {
return ADE_RETURN_FALSE;
}
campaign_select_campaign(filename);
Pilot.save_player();
return ADE_RETURN_TRUE;
}
ADE_FUNC(resetCampaign,
l_UserInterface_Campaign,
"string campaign_file",
"Resets the campaign with the specified file name",
"boolean",
"true if successful, false otherwise")
{
const char* filename = nullptr;
if (!ade_get_args(L, "s", &filename)) {
return ADE_RETURN_FALSE;
}
campaign_reset(filename);
return ADE_RETURN_TRUE;
}
//**********SUBLIBRARY: UserInterface/Briefing
ADE_LIB_DERIV(l_UserInterface_Brief,
"Briefing",
nullptr,
"API for accessing data related to the Briefing UI.",
l_UserInterface);
ADE_FUNC(getBriefingMusicName,
l_UserInterface_Brief,
nullptr,
"Gets the file name of the music file to play for the briefing.",
"string",
"The file name or empty if no music")
{
return ade_set_args(L, "s", common_music_get_filename(SCORE_BRIEFING));
}
ADE_FUNC(runBriefingStageHook,
l_UserInterface_Brief,
"number oldStage, number newStage",
"Run $On Briefing Stage: hooks.",
nullptr,
nullptr)
{
int oldStage = -1, newStage = -1;
if (ade_get_args(L, "ii", &oldStage, &newStage) == 2) {
// Subtract 1 to convert from Lua conventions to C conventions
common_fire_stage_script_hook(oldStage - 1, newStage - 1);
} else {
LuaError(L, "Bad arguments given to ui.runBriefingStageHook!");
}
return ADE_RETURN_NIL;
}
ADE_FUNC(initBriefing,
l_UserInterface_Brief,
nullptr,
"Initializes the briefing and prepares the map for drawing. Also handles various non-UI housekeeping tasks "
"and compacts the stages to remove those that should not be shown.",
nullptr,
nullptr)
{
SCP_UNUSED(L);
brief_init(true);
return ADE_RETURN_NIL;
}
ADE_FUNC(closeBriefing,
l_UserInterface_Brief,
nullptr,
"Closes the briefing and pauses the map. Required after using the briefing API!",
nullptr,
nullptr)
{
SCP_UNUSED(L);
brief_close(true);
return ADE_RETURN_NIL;
}
ADE_FUNC(getBriefing,
l_UserInterface_Brief,
nullptr,
"Get the briefing",
"briefing",
"The briefing data")
{
// get a pointer to the appropriate briefing structure
if (MULTI_TEAM) {
return ade_set_args(L, "o", l_Brief.Set(Net_player->p_info.team));
} else {
return ade_set_args(L, "o", l_Brief.Set(0));
}
}
ADE_FUNC(exitLoop,
l_UserInterface_Brief,
nullptr,
"Skips the current mission, exits the campaign loop, and loads the next non-loop mission in a campaign. Returns to the main hall if the player is not in a campaign.",
nullptr,
nullptr)
{
SCP_UNUSED(L);
if (!(Game_mode & GM_CAMPAIGN_MODE)) {
gameseq_post_event(GS_EVENT_MAIN_MENU);
}
mission_campaign_exit_loop();
return ADE_RETURN_NIL;
}
ADE_FUNC(skipMission,
l_UserInterface_Brief,
nullptr,
"Skips the current mission, and loads the next mission in a campaign. Returns to the main hall if the player is not in a campaign.",
nullptr,
nullptr)
{
SCP_UNUSED(L);
if (!(Game_mode & GM_CAMPAIGN_MODE)) {
gameseq_post_event(GS_EVENT_MAIN_MENU);
}
mission_campaign_skip_to_next();
return ADE_RETURN_NIL;
}
ADE_FUNC(skipTraining,
l_UserInterface_Brief,
nullptr,
"Skips the current training mission, and loads the next mission in a campaign. Returns to the main hall if the player is not in a campaign.",
nullptr,
nullptr)
{
SCP_UNUSED(L);
if (!(Game_mode & GM_CAMPAIGN_MODE)) {
gameseq_post_event(GS_EVENT_MAIN_MENU);
}
// tricky part. Need to move to the next mission in the campaign.
mission_goal_mark_objectives_complete();
mission_goal_fail_incomplete();
mission_campaign_store_goals_and_events_and_variables(false);
mission_campaign_eval_next_mission();
mission_campaign_mission_over();
if (Campaign.next_mission == -1 || (The_mission.flags[Mission::Mission_Flags::End_to_mainhall])) {
gameseq_post_event(GS_EVENT_MAIN_MENU);
} else {
gameseq_post_event(GS_EVENT_START_GAME);
}
return ADE_RETURN_NIL;
}
ADE_FUNC(commitToMission,
l_UserInterface_Brief,
nullptr,
"Commits to the current mission with current loadout data, and starts the mission.",
"enumeration",
"A COMMIT_* enumeration indicating any errors")
{
commit_pressed_status rc;
if (Game_mode & GM_MULTIPLAYER) {
rc = multi_ts_commit_pressed();
} else {
rc = commit_pressed();
}
lua_enum eh_idx = ENUM_INVALID;
switch (rc) {
case commit_pressed_status::GENERAL_FAIL:
eh_idx = LE_COMMIT_FAIL;
break;
case commit_pressed_status::PLAYER_NO_WEAPONS:
eh_idx = LE_COMMIT_PLAYER_NO_WEAPONS;
break;
case commit_pressed_status::NO_REQUIRED_WEAPON:
eh_idx = LE_COMMIT_NO_REQUIRED_WEAPON;
break;
case commit_pressed_status::NO_REQUIRED_WEAPON_MULTIPLE:
eh_idx = LE_COMMIT_NO_REQUIRED_WEAPON_MULTIPLE;
break;
case commit_pressed_status::BANK_GAP_ERROR:
eh_idx = LE_COMMIT_BANK_GAP_ERROR;
break;
case commit_pressed_status::PLAYER_NO_SLOT:
eh_idx = LE_COMMIT_PLAYER_NO_SLOT;
break;
case commit_pressed_status::MULTI_PLAYERS_NO_SHIPS:
eh_idx = LE_COMMIT_MULTI_PLAYERS_NO_SHIPS;
break;
case commit_pressed_status::MULTI_NOT_ALL_ASSIGNED:
eh_idx = LE_COMMIT_MULTI_NOT_ALL_ASSIGNED;
break;
case commit_pressed_status::MULTI_NO_PRIMARY:
eh_idx = LE_COMMIT_MULTI_NO_PRIMARY;
break;
case commit_pressed_status::MULTI_NO_SECONDARY:
eh_idx = LE_COMMIT_MULTI_NO_SECONDARY;
break;
case commit_pressed_status::SUCCESS:
default:
eh_idx = LE_COMMIT_SUCCESS;
break;
}
return ade_set_args(L, "o", l_Enum.Set(enum_h(eh_idx)));
}
ADE_FUNC(renderBriefingModel,
l_UserInterface_Brief,
"string PofName, number CloseupZoom, vector CloseupPos, number X1, number Y1, number X2, number Y2, [number RotationPercent =0, number PitchPercent =0, "
"number "
"BankPercent=40, number Zoom=1.3, boolean Lighting=true, boolean Jumpnode=false]",
"Draws a pof. True for regular lighting, false for flat lighting.",
"boolean",
"Whether pof was rendered")
{
int x1, y1, x2, y2;
angles rot_angles = {0.0f, 0.0f, 40.0f};
const char* pof;
float closeup_zoom;
vec3d closeup_pos;
float zoom = 1.3f;
bool lighting = true;
bool jumpNode = false;
if (!ade_get_args(L,
"sfoiiii|ffffbb",
&pof,
&closeup_zoom,
l_Vector.Get(&closeup_pos),
&x1,
&y1,
&x2,
&y2,
&rot_angles.h,
&rot_angles.p,
&rot_angles.b,
&zoom,
&lighting,
&jumpNode))
return ade_set_error(L, "b", false);
if (x2 < x1 || y2 < y1)
return ade_set_args(L, "b", false);
CLAMP(rot_angles.p, 0.0f, 100.0f);
CLAMP(rot_angles.b, 0.0f, 100.0f);
CLAMP(rot_angles.h, 0.0f, 100.0f);
// Handle angles
matrix orient = vmd_identity_matrix;
angles view_angles = {-0.6f, 0.0f, 0.0f};
vm_angles_2_matrix(&orient, &view_angles);
rot_angles.p = (rot_angles.p * 0.01f) * PI2;
rot_angles.b = (rot_angles.b * 0.01f) * PI2;
rot_angles.h = (rot_angles.h * 0.01f) * PI2;
vm_rotate_matrix_by_angles(&orient, &rot_angles);
tech_render_type thisType = TECH_POF;
if (jumpNode) {
thisType = TECH_JUMP_NODE;
}
return ade_set_args(L, "b", render_tech_model(thisType, x1, y1, x2, y2, zoom, lighting, -1, &orient, pof, closeup_zoom, &closeup_pos));
}
ADE_FUNC(drawBriefingMap,
l_UserInterface_Brief,
"number x, number y, [number width = 888, number height = 371]",
"Draws the briefing map for the current mission at the specified coordinates. Note that the "
"width and height must be a specific aspect ratio to match retail. If changed then some icons "
"may be clipped from view unexpectedly. Must be called On Frame.",
nullptr,
nullptr)
{
int x1;
int y1;
int x2 = 888;
int y2 = 371;
if (!ade_get_args(L, "ii|ii", &x1, &y1, &x2, &y2)) {
LuaError(L, "X and Y coordinates not provided!");
return ADE_RETURN_NIL;
}
// Saving retail coords here for posterity
// GR_640 - 19, 147, 555, 232
// GR_1024 - 30, 235, 888, 371
bscreen.map_x1 = x1;
bscreen.map_x2 = x1 + x2;
bscreen.map_y1 = y1;
bscreen.map_y2 = y1 + y2;
bscreen.resize = GR_RESIZE_NONE;
brief_do_frame(flRealframetime, true);
return ADE_RETURN_NIL;
}
ADE_FUNC(checkStageIcons,
l_UserInterface_Brief,
"number xPos, number yPos",
"Sends the mouse position to the brief map rendering functions to properly highlight icons.",
"string, number, vector, string, number",
"If an icon is highlighted then this will return the ship name for ships or the pof to render for asteroid, jumpnode, or unknown icons. "
"also returns the closeup zoom, the closeup position, the closeup label, and the icon id. Otherwise it returns nil")
{
int x;
int y;
if (!ade_get_args(L, "ii", &x, &y)) {
LuaError(L, "X and Y coordinates not provided!");
return ADE_RETURN_NIL;
}
brief_check_for_anim(true, x, y);
if (Closeup_icon == nullptr) {
return ADE_RETURN_NIL;
} else {
return ade_set_args(L, "sfosi", Closeup_type_name, Closeup_zoom, l_Vector.Set(Closeup_cam_pos), Closeup_icon->closeup_label, Closeup_icon->id);
}
}
ADE_FUNC(callNextMapStage,
l_UserInterface_Brief,
nullptr,
"Sends the briefing map to the next stage.",