forked from scp-fs2open/fs2open.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissionweaponchoice.cpp
More file actions
4248 lines (3558 loc) · 116 KB
/
Copy pathmissionweaponchoice.cpp
File metadata and controls
4248 lines (3558 loc) · 116 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
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "anim/animplay.h"
#include "anim/packunpack.h"
#include "cfile/cfile.h"
#include "gamehelp/contexthelp.h"
#include "gamesnd/gamesnd.h"
#include "globalincs/alphacolors.h"
#include "globalincs/utility.h"
#include "graphics/shadows.h"
#include "graphics/matrix.h"
#include "hud/hudbrackets.h"
#include "io/mouse.h"
#include "io/timer.h"
#include "lighting/lighting.h"
#include "lighting/lighting_profiles.h"
#include "localization/localize.h"
#include "menuui/snazzyui.h"
#include "missionui/chatbox.h"
#include "missionui/missionbrief.h"
#include "missionui/missionscreencommon.h"
#include "missionui/missionshipchoice.h"
#include "missionui/missionweaponchoice.h"
#include "model/model.h"
#include "model/modelrender.h"
#include "mod_table/mod_table.h"
#include "network/multi.h"
#include "network/multi_pmsg.h"
#include "network/multimsgs.h"
#include "network/multiteamselect.h"
#include "network/multiui.h"
#include "network/multiutil.h"
#include "parse/parselo.h"
#include "popup/popup.h"
#include "render/3d.h"
#include "render/batching.h"
#include "ship/ship.h"
#include "weapon/weapon.h"
#define IS_BANK_PRIMARY(x) (x < MAX_SHIP_PRIMARY_BANKS)
#define IS_BANK_SECONDARY(x) (x >= MAX_SHIP_PRIMARY_BANKS)
#define IS_LIST_PRIMARY(x) (Weapon_info[x].subtype != WP_MISSILE)
#define IS_LIST_SECONDARY(x) (Weapon_info[x].subtype == WP_MISSILE)
//////////////////////////////////////////////////////////////////
// Game-wide globals
//////////////////////////////////////////////////////////////////
// This game-wide global flag is set to 1 to indicate that the weapon
// select screen has been opened and memory allocated. This flag
// is needed so we can know if weapon_select_close() needs to called if
// restoring a game from the Options screen invoked from weapon select
int Weapon_select_open = 0;
//////////////////////////////////////////////////////////////////
// UI Data
//////////////////////////////////////////////////////////////////
typedef struct wl_bitmap_group
{
int first_frame;
int num_frames;
} wl_bitmap_group;
#define WEAPON_ANIM_LOOP_FRAME 52 // frame (from 0) to loop weapon anim
#define WEAPON_ICON_FRAME_NORMAL 0
#define WEAPON_ICON_FRAME_HOT 1
#define WEAPON_ICON_FRAME_SELECTED 2
#define WEAPON_ICON_FRAME_DISABLED 3
constexpr int NUM_WL_LAYOUTS = 2;
#define MAX_WEAPON_BUTTONS 8
#define MIN_WEAPON_BUTTONS 7
#define NUM_WEAPON_BUTTONS (Uses_apply_all_button ? MAX_WEAPON_BUTTONS : MIN_WEAPON_BUTTONS)
// Weapn loadout specific buttons
#define WL_BUTTON_SCROLL_PRIMARY_UP 0
#define WL_BUTTON_SCROLL_PRIMARY_DOWN 1
#define WL_BUTTON_SCROLL_SECONDARY_UP 2
#define WL_BUTTON_SCROLL_SECONDARY_DOWN 3
#define WL_BUTTON_RESET 4
#define WL_BUTTON_DUMMY 5
#define WL_BUTTON_MULTI_LOCK 6
#define WL_BUTTON_APPLY_ALL 7
// mask regions for icons in the scrollable lists
// NOLINTBEGIN(modernize-macro-to-enum)
#define ICON_PRIMARY_0 28
#define ICON_PRIMARY_1 29
#define ICON_PRIMARY_2 30
#define ICON_PRIMARY_3 31
#define ICON_SECONDARY_0 10
#define ICON_SECONDARY_1 11
#define ICON_SECONDARY_2 12
#define ICON_SECONDARY_3 13
// NOLINTEND(modernize-macro-to-enum)
constexpr int NUM_PRIMARY_MASK_REGIONS = 4;
constexpr int NUM_SECONDARY_MASK_REGIONS = 4;
// mask regions for icons that sit above the ship
// NOLINTBEGIN(modernize-macro-to-enum)
#define ICON_SHIP_PRIMARY_0 32
#define ICON_SHIP_PRIMARY_1 33
#define ICON_SHIP_PRIMARY_2 34
#define ICON_SHIP_SECONDARY_0 35
#define ICON_SHIP_SECONDARY_1 36
#define ICON_SHIP_SECONDARY_2 37
#define ICON_SHIP_SECONDARY_3 38
// NOLINTEND(modernize-macro-to-enum)
extern int anim_timer_start;
int Weapon_select_overlay_id = -1;
// convenient struct for handling all button controls
struct wl_buttons {
const char *filename;
int x, y, xt, yt;
int hotspot;
UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
wl_buttons(const char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
};
static wl_buttons Buttons[GR_NUM_RESOLUTIONS][MAX_WEAPON_BUTTONS] = {
{
wl_buttons("WLB_27", 24, 276, -1, -1, 27), // WL_BUTTON_SCROLL_PRIMARY_UP
wl_buttons("WLB_26", 24, 125, -1, -1, 26), // WL_BUTTON_SCROLL_PRIMARY_DOWN
wl_buttons("WLB_09", 24, 454, -1, -1, 9), // WL_BUTTON_SCROLL_SECONDARY_UP
wl_buttons("WLB_08", 24, 303, -1, -1, 8), // WL_BUTTON_SCROLL_SECONDARY_DOWN
wl_buttons("ssb_39", 571, 347, -1, -1, 39), // WL_BUTTON_RESET
wl_buttons("ssb_39", 0, 0, -1, -1, 99), // WL_BUTTON_DUMMY
wl_buttons("TSB_34", 603, 374, -1, -1, 34), // WL_BUTTON_MULTI_LOCK
wl_buttons("WLB_40", 0, 90, -1, -1, 40) // WL_BUTTON_APPLY_ALL
},
{
wl_buttons("2_WLB_27", 39, 442, -1, -1, 27),
wl_buttons("2_WLB_26", 39, 200, -1, -1, 26),
wl_buttons("2_WLB_09", 39, 727, -1, -1, 9),
wl_buttons("2_WLB_08", 39, 485, -1, -1, 8),
wl_buttons("2_ssb_39", 913, 556, -1, -1, 39),
wl_buttons("2_ssb_39", 0, 0, -1, -1, 99),
wl_buttons("2_TSB_34", 966, 599, -1, -1, 34),
wl_buttons("2_WLB_40", 0, 138, -1, -1, 40)
}
};
static const char *Wl_mask_single[NUM_WL_LAYOUTS][GR_NUM_RESOLUTIONS] = {
{
"weaponloadout-m",
"2_weaponloadout-m"
},
{
"weaponloadout-mb",
"2_weaponloadout-mb"
}
};
static const char *Wl_mask_multi[NUM_WL_LAYOUTS][GR_NUM_RESOLUTIONS] = {
{
"weaponloadoutmulti-m",
"2_weaponloadoutmulti-m"
},
{
"weaponloadoutmulti-mb",
"2_weaponloadoutmulti-mb"
}
};
static const char *Wl_loadout_select_mask[NUM_WL_LAYOUTS][GR_NUM_RESOLUTIONS] = {
{
"weaponloadout-m",
"2_weaponloadout-m"
},
{
"weaponloadout-mb",
"2_weaponloadout-mb"
}
};
static const char *Weapon_select_background_fname[NUM_WL_LAYOUTS][GR_NUM_RESOLUTIONS] = {
{
"WeaponLoadout",
"2_WeaponLoadout"
},
{
"WeaponLoadoutb",
"2_WeaponLoadoutb"
}
};
static const char *Weapon_select_multi_background_fname[NUM_WL_LAYOUTS][GR_NUM_RESOLUTIONS] = {
{
"WeaponLoadoutMulti",
"2_WeaponLoadoutMulti"
},
{
"WeaponLoadoutMultib",
"2_WeaponLoadoutMultib"
}
};
static int Uses_apply_all_button = 0;
int Weapon_select_background_bitmap; // bitmap for weapon select brackground
static MENU_REGION Weapon_select_region[NUM_COMMON_REGIONS + 27]; // see initialization
static int Num_weapon_select_regions;
// Mask bitmap pointer and Mask bitmap_id
static bitmap* WeaponSelectMaskPtr; // bitmap pointer to the weapon select mask bitmap
static ubyte* WeaponSelectMaskData; // pointer to actual bitmap data
static int Weaponselect_mask_w, Weaponselect_mask_h;
static int WeaponSelectMaskBitmap; // bitmap id of the weapon select mask bitmap
static int Weapon_slot_bitmap;
UI_WINDOW Weapon_ui_window;
static int Weapon_button_scrollable[MAX_WEAPON_BUTTONS] = {0, 0, 0, 0, 0, 0, 0, 0};
#define MAX_WEAPON_ICONS_ON_SCREEN 8
// X and Y locations of the weapon icons in the scrollable lists
static int Wl_weapon_icon_coords[GR_NUM_RESOLUTIONS][MAX_WEAPON_ICONS_ON_SCREEN][2] = {
{
{27, 152},
{27, 182},
{27, 212},
{27, 242},
{36, 331},
{36, 361},
{36, 391},
{36, 421}
},
{
{59, 251},
{59, 299},
{59, 347},
{59, 395},
{59, 538},
{59, 586},
{59, 634},
{59, 682}
}
};
static int Wl_bank_coords[GR_NUM_RESOLUTIONS][MAX_SHIP_WEAPONS][2] = {
{
{106,127},
{106,158},
{106,189},
{322,127},
{322,158},
{322,189},
{322,220},
},
{
{170,203},
{170,246},
{170,290},
{552,203},
{552,246},
{552,290},
{552,333},
}
};
static int Wl_bank_count_draw_flags[MAX_SHIP_WEAPONS] = {
0, 0, 0, // primaries -- don't draw counts
1, 1, 1, 1 // secondaries -- do draw counts
};
static int Weapon_anim_class = -1;
static int Last_wl_ship_class;
static int Wl_overhead_coords[GR_NUM_RESOLUTIONS][2] = {
{
// GR_640
91, 117
},
{
// GR_1024
156, 183
}
};
static int Wl_weapon_ani_coords[GR_NUM_RESOLUTIONS][2] = {
{
408, 82 // GR_640
},
{
648, 128 // GR_1024
}
};
static int Wl_weapon_ani_coords_multi[GR_NUM_RESOLUTIONS][2] = {
{
408, 143 // GR_640
},
{
648, 226 // GR_1024
}
};
static int Wl_weapon_desc_coords[GR_NUM_RESOLUTIONS][2] = {
{
508, 283 // GR_640
},
{
813, 453 // GR_1024
}
};
static int Wl_delta_x, Wl_delta_y;
static int Wl_ship_name_coords[GR_NUM_RESOLUTIONS][2] = {
{
85, 106
},
{
136, 170
}
};
///////////////////////////////////////////////////////////////////////
// UI data structs
///////////////////////////////////////////////////////////////////////
typedef struct wl_ship_class_info
{
int overhead_bitmap;
int model_num;
generic_anim animation;
} wl_ship_class_info;
wl_ship_class_info Wl_ships[MAX_SHIP_CLASSES];
struct wl_icon_info
{
int icon_bmaps[NUM_ICON_FRAMES];
int laser_bmap;
int model_index;
bool can_use_for_ship;
TriStateBool can_use_for_bank;
generic_anim animation;
};
wl_icon_info Wl_icons_teams[MAX_TVT_TEAMS][MAX_WEAPON_TYPES];
wl_icon_info *Wl_icons = NULL;
int Plist[MAX_WEAPON_TYPES]; // used to track scrolling of primary icon list
int Plist_start, Plist_size;
int Slist[MAX_WEAPON_TYPES]; // used to track scrolling of primary icon list
int Slist_start, Slist_size;
static int Selected_wl_slot = -1; // Currently selected ship slot
static int Selected_wl_class = -1; // Class of weapon that is selected
static int Hot_wl_slot = -1; // Ship slot that mouse is over (0..MAX_WSS_SLOTS-1)
static int Hot_weapon_icon = -1; // Icon number (0-7) which has mouse over it
static int Hot_weapon_bank = -1; // index (0-7) for weapon slot on ship that has a droppable icon over it
static int Hot_weapon_bank_icon = -1;
static generic_anim Cur_Anim;
static int Wl_mouse_down_on_region = -1;
// weapon desc stuff
#define WEAPON_DESC_WIPE_TIME 1.5f // time in seconds for wipe to occur (over WEAPON_DESC_MAX_LENGTH number of chars)
static int Weapon_desc_wipe_done = 0;
static float Weapon_desc_wipe_time_elapsed = 0.0f;
static char Weapon_desc_lines[WEAPON_DESC_MAX_LINES][WEAPON_DESC_MAX_LENGTH]; // 1st 2 lines are title, rest are desc
// maximum width the weapon title can be -- used in the line breaking
int Weapon_title_max_width[GR_NUM_RESOLUTIONS] = { 200, 320 };
static int Wl_new_weapon_title_coords[GR_NUM_RESOLUTIONS][2] = {
{
408, 75 // GR_640
},
{
648, 118 // GR_1024
}
};
static int Wl_new_weapon_title_coords_multi[GR_NUM_RESOLUTIONS][2] = {
{
408, 136 // GR_640
},
{
648, 216 // GR_1024
}
};
static int Wl_new_weapon_desc_coords[GR_NUM_RESOLUTIONS][2] = {
{
408, 247 // GR_640
},
{
648, 395 // GR_1024
}
};
static int Wl_new_weapon_desc_coords_multi[GR_NUM_RESOLUTIONS][2] = {
{
408, 308 // GR_640
},
{
648, 493 // GR_1024
}
};
// ship select text
#define WEAPON_SELECT_NUM_TEXT 2
UI_XSTR Weapon_select_text[GR_NUM_RESOLUTIONS][WEAPON_SELECT_NUM_TEXT] = {
{ // GR_640
{ "Reset", 1337, 580, 337, UI_XSTR_COLOR_GREEN, -1, &Buttons[0][WL_BUTTON_RESET].button },
{ "Lock", 1270, 602, 364, UI_XSTR_COLOR_GREEN, -1, &Buttons[0][WL_BUTTON_MULTI_LOCK].button }
},
{ // GR_1024
{ "Reset", 1337, 938, 546, UI_XSTR_COLOR_GREEN, -1, &Buttons[1][WL_BUTTON_RESET].button },
{ "Lock", 1270, 964, 584, UI_XSTR_COLOR_GREEN, -1, &Buttons[1][WL_BUTTON_MULTI_LOCK].button }
}
};
///////////////////////////////////////////////////////////////////////
// Carried Icon
///////////////////////////////////////////////////////////////////////
typedef struct carried_icon
{
int weapon_class; // index Wl_icons[] for carried icon (-1 if carried from bank)
int num; // number of units of weapon
int from_bank; // bank index that icon came from (0..2 primary, 3..6 secondary). -1 if from list
int from_slot; // ship slot that weapon is part of
int from_x, from_y;
} carried_icon;
static carried_icon Carried_wl_icon;
// forward declarations
void draw_wl_icons();
void wl_draw_ship_weapons(int index);
void wl_pick_icon_from_list(int index);
void pick_from_ship_slot(int num);
void start_weapon_animation(int weapon_class);
void stop_weapon_animation();
int wl_get_pilot_subsys_index(p_object *pobjp);
void wl_reset_to_defaults();
void wl_set_selected_slot(int slot_num);
void wl_maybe_reset_selected_slot();
void wl_maybe_reset_selected_weapon_class();
void wl_render_icon_count(int num, int x, int y);
void wl_render_weapon_desc();
void wl_apply_current_loadout_to_all_ships_in_current_wing();
// carry icon functions
void wl_reset_carried_icon();
int wl_icon_being_carried();
void wl_set_carried_icon(int from_bank, int from_slot, int weapon_class);
const char *wl_tooltip_handler(const char *str)
{
if (Selected_wl_class < 0)
return NULL;
if (!stricmp(str, "@weapon_desc")) {
const char *str2;
int x, y, w, h;
str2 = coalesce(Weapon_info[Selected_wl_class].desc.get(), "");
gr_get_string_size(&w, &h, str2);
x = Wl_weapon_desc_coords[gr_screen.res][0] - w / 2;
y = Wl_weapon_desc_coords[gr_screen.res][1] - h / 2;
gr_set_color_fast(&Color_black);
gr_rect(x - 5, y - 5, w + 10, h + 10, GR_RESIZE_MENU);
gr_set_color_fast(&Color_bright_white);
gr_string(x, y, str2, GR_RESIZE_MENU);
return NULL;
}
return NULL;
}
/**
* Reset the data inside Carried_wl_icon
*/
void wl_reset_carried_icon()
{
Carried_wl_icon.weapon_class = -1;
Carried_wl_icon.num = 0;
Carried_wl_icon.from_bank = -1;
Carried_wl_icon.from_slot = -1;
}
/**
* Is an icon being carried?
*/
int wl_icon_being_carried()
{
if ( Carried_wl_icon.weapon_class >= 0 ) {
return 1;
}
return 0;
}
/**
* Set carried icon data
*/
void wl_set_carried_icon(int from_bank, int from_slot, int weapon_class)
{
int mx,my;
Carried_wl_icon.from_bank = from_bank;
Carried_wl_icon.from_slot = from_slot;
Carried_wl_icon.weapon_class = weapon_class;
mouse_get_pos_unscaled( &mx, &my );
Carried_wl_icon.from_x=mx;
Carried_wl_icon.from_y=my;
Buttons[gr_screen.res][WL_BUTTON_DUMMY].button.capture_mouse();
}
/**
* Determine if the carried icon has moved
*/
int wl_carried_icon_moved()
{
int mx, my;
mouse_get_pos_unscaled( &mx, &my );
if ( Carried_wl_icon.from_x != mx || Carried_wl_icon.from_y != my) {
return 1;
}
return 0;
}
/**
* @return the index for the pilot subsystem in the parse object
*/
int wl_get_pilot_subsys_index(p_object *pobjp)
{
int pilot_index, start_index, end_index, i;
// see if there is a PILOT subystem
start_index = pobjp->subsys_index;
end_index = start_index + pobjp->subsys_count;
pilot_index = -1;
for ( i = start_index; i < end_index; i++ ) {
if ( !subsystem_stricmp(Subsys_status[i].name, NOX("pilot") ) ) {
pilot_index = i;
break;
}
}
if ( pilot_index == -1 ) {
Error(LOCATION,"Parse object doesn't have a pilot subsystem\n");
return -1;
}
return pilot_index;
}
// ---------------------------------------------------------------------------------
// weapon_button_do()
//
void weapon_button_do(int i)
{
switch ( i ) {
case WL_BUTTON_SCROLL_PRIMARY_UP:
if ( common_scroll_up_pressed(&Plist_start, Plist_size, NUM_PRIMARY_MASK_REGIONS) ) {
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
break;
case WL_BUTTON_SCROLL_PRIMARY_DOWN:
if ( common_scroll_down_pressed(&Plist_start, Plist_size, NUM_PRIMARY_MASK_REGIONS) ) {
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
break;
case WL_BUTTON_SCROLL_SECONDARY_UP:
if ( common_scroll_up_pressed(&Slist_start, Slist_size, NUM_SECONDARY_MASK_REGIONS) ) {
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
break;
case WL_BUTTON_SCROLL_SECONDARY_DOWN:
if ( common_scroll_down_pressed(&Slist_start, Slist_size, NUM_SECONDARY_MASK_REGIONS) ) {
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
break;
case WL_BUTTON_RESET:
wl_reset_to_defaults();
break;
case WL_BUTTON_MULTI_LOCK:
Assert(Game_mode & GM_MULTIPLAYER);
// the "lock" button has been pressed
multi_ts_lock_pressed();
// disable the button if it is now locked
if(multi_ts_is_locked()){
Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.disable();
}
break;
case WL_BUTTON_APPLY_ALL:
wl_apply_current_loadout_to_all_ships_in_current_wing();
break;
default:
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "Button %d is not yet implemented", i);
break;
}
}
/**
* Check if any weapons loadout screen buttons have been pressed, and
* call weapon_button_do() if they have.
*/
void weapon_check_buttons()
{
int i;
wl_buttons *b;
for ( i = 0; i < NUM_WEAPON_BUTTONS; i++ ) {
b = &Buttons[gr_screen.res][i];
if ( b->button.pressed() ) {
weapon_button_do(i);
}
}
}
/**
* Redraw any weapon loadout buttons that are pressed down. This function is needed
* since we sometimes need to draw pressed buttons last to ensure the entire
* button gets drawn (and not overlapped by other buttons)
*/
void wl_redraw_pressed_buttons()
{
int i;
wl_buttons *b;
common_redraw_pressed_buttons();
for ( i = 0; i < NUM_WEAPON_BUTTONS; i++ ) {
b = &Buttons[gr_screen.res][i];
if ( b->button.button_down() ) {
b->button.draw_forced(2);
}
}
}
// ---------------------------------------------------------------------------------
// weapon_buttons_init()
//
void weapon_buttons_init()
{
wl_buttons *b;
int i;
for ( i = 0; i < NUM_WEAPON_BUTTONS; i++ ) {
b = &Buttons[gr_screen.res][i];
b->button.create( &Weapon_ui_window, "", Buttons[gr_screen.res][i].x, Buttons[gr_screen.res][i].y, 60, 30, Weapon_button_scrollable[i]);
// set up callback for when a mouse first goes over a button
b->button.set_highlight_action( common_play_highlight_sound );
b->button.set_bmaps(Buttons[gr_screen.res][i].filename);
b->button.link_hotspot(Buttons[gr_screen.res][i].hotspot);
}
if ( Game_mode & GM_MULTIPLAYER ) {
Buttons[gr_screen.res][WL_BUTTON_RESET].button.hide();
Buttons[gr_screen.res][WL_BUTTON_RESET].button.disable();
// if we're not the host of the game (or a team captain in team vs. team mode), disable the lock button
if(Netgame.type_flags & NG_TYPE_TEAM){
if(!(Net_player->flags & NETINFO_FLAG_TEAM_CAPTAIN)){
Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.disable();
}
} else {
if(!(Net_player->flags & NETINFO_FLAG_GAME_HOST)){
Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.disable();
}
}
} else {
Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.hide();
Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.disable();
}
// add all xstrs
for(i=0; i<WEAPON_SELECT_NUM_TEXT; i++) {
Weapon_ui_window.add_XSTR(&Weapon_select_text[gr_screen.res][i]);
}
Buttons[gr_screen.res][WL_BUTTON_DUMMY].button.hide();
Buttons[gr_screen.res][WL_BUTTON_DUMMY].button.disable();
}
// ---------------------------------------------------------------------------------
// draw_3d_overhead_view()
//
void draw_3d_overhead_view(int model_num,
int ship_class,
float* rotation_buffer,
float frametime,
int weapon_array[MAX_SHIP_WEAPONS],
int selected_weapon_class,
int hovered_weapon_slot,
int x1,
int y1,
int x2,
int y2,
int resize_mode,
int bank1_x,
int bank1_y,
int bank2_x,
int bank2_y,
int bank3_x,
int bank3_y,
int bank4_x,
int bank4_y,
int bank5_x,
int bank5_y,
int bank6_x,
int bank6_y,
int bank7_x,
int bank7_y,
int bank_prim_offset,
int bank_sec_offset,
int bank_y_offset,
overhead_style style,
const SCP_string& tcolor)
{
lighting_profiles::set_non_mission_profile non_mission_lighting_profile;
ship_info* sip = &Ship_info[ship_class];
if (model_num < 0) {
mprintf(("Couldn't load model file '%s' in missionweaponchoice.cpp\n", sip->pof_file));
} else {
matrix object_orient = IDENTITY_MATRIX;
angles rot_angles;
float zoom;
zoom = sip->closeup_zoom * 1.3f;
if (style == OH_TOP_VIEW) {
rot_angles.p = -(PI_2);
rot_angles.b = 0.0f;
rot_angles.h = 0.0f;
vm_angles_2_matrix(&object_orient, &rot_angles);
} else if (style == OH_ROTATING) {
float rev_rate;
rev_rate = REVOLUTION_RATE;
if (sip->is_big_ship()) {
rev_rate *= 1.7f;
}
if (sip->is_huge_ship()) {
rev_rate *= 3.0f;
}
*rotation_buffer += PI2 * frametime / rev_rate;
while (*rotation_buffer > PI2) {
*rotation_buffer -= PI2;
}
rot_angles.p = -0.6f;
rot_angles.b = 0.0f;
rot_angles.h = 0.0f;
vm_angles_2_matrix(&object_orient, &rot_angles);
rot_angles.p = 0.0f;
rot_angles.b = 0.0f;
rot_angles.h = *rotation_buffer;
vm_rotate_matrix_by_angles(&object_orient, &rot_angles);
} else {
Error(LOCATION, "Got call to draw overhead ship with invalid style!");
}
model_render_params render_info;
gr_set_clip(x1, y1, x2, y2, resize_mode);
g3_start_frame(1);
g3_set_view_matrix(&sip->closeup_pos, &vmd_identity_matrix, zoom);
render_info.set_detail_level_lock(0);
// setup lights
common_setup_room_lights();
Glowpoint_use_depth_buffer = false;
model_clear_instance(model_num);
int model_instance = -1;
auto cache_result = model_get_cached_ui_render_instance(model_num, &model_instance);
// Only set up the instance when it was freshly created; the cached instance persists across frames.
if (cache_result == TriStateBool::TRUE_) {
model_set_up_techroom_instance(sip, model_instance);
}
polymodel* pm = model_get(model_num);
if (sip->replacement_textures.size() > 0) {
render_info.set_replacement_textures(model_num, sip->replacement_textures);
}
if (shadow_maybe_start_frame(Shadow_disable_overrides.disable_mission_select_weapons)) {
gr_reset_clip();
shadows_start_render(&vmd_identity_matrix,
&Eye_position,
Proj_fov,
gr_screen.clip_aspect,
-sip->closeup_pos.xyz.z + pm->rad,
-sip->closeup_pos.xyz.z + pm->rad + 200.0f,
-sip->closeup_pos.xyz.z + pm->rad + 2000.0f,
-sip->closeup_pos.xyz.z + pm->rad + 10000.0f);
render_info.set_flags(MR_NO_TEXTURING | MR_NO_LIGHTING | MR_AUTOCENTER);
model_render_immediate(&render_info, model_num, model_instance, &object_orient, &vmd_zero_vector);
shadows_end_render();
gr_set_clip(x1, y1, x2, y2, resize_mode);
}
gr_set_proj_matrix(Proj_fov, gr_screen.clip_aspect, Min_draw_distance, Max_draw_distance);
gr_set_view_matrix(&Eye_position, &vmd_identity_matrix);
render_info.set_flags(MR_AUTOCENTER | MR_NO_FOGGING);
if (sip->uses_team_colors) {
SCP_string tc = tcolor.empty() ? sip->default_team_name : tcolor;
render_info.set_team_color(tc, "none", 0, 0);
}
model_render_immediate(&render_info, model_num, model_instance, &object_orient, &vmd_zero_vector);
Glowpoint_use_depth_buffer = true;
batching_render_all();
shadow_end_frame();
// NOW render the lines for weapons
gr_reset_clip();
vertex draw_point;
vec3d subobj_pos;
int x, y;
int xc, yc;
int num_found = 0;
int bank_coords[MAX_SHIP_WEAPONS][2] = {
{bank1_x, bank1_y},
{bank2_x, bank2_y},
{bank3_x, bank3_y},
{bank4_x, bank4_y},
{bank5_x, bank5_y},
{bank6_x, bank6_y},
{bank7_x, bank7_y},
};
// Render selected primary lines
for (x = 0; x < pm->n_guns; x++) {
if ((weapon_array[x] == selected_weapon_class && hovered_weapon_slot < 0) ||
x == hovered_weapon_slot) {
Assert(num_found < MAX_SHIP_SECONDARY_BANKS);
gr_set_color_fast(&Overhead_line_colors[num_found]);
gr_circle(bank_coords[x][0] + bank_prim_offset, bank_coords[x][1] + bank_y_offset, 5, resize_mode);
for (y = 0; y < pm->gun_banks[x].num_slots; y++) {
// Stuff
if (pm->flags & PM_FLAG_AUTOCEN) {
vm_vec_sub(&subobj_pos, &pm->gun_banks[x].pnt[y], &pm->autocenter);
vm_vec_unrotate(&subobj_pos, &subobj_pos, &object_orient);
} else {
vm_vec_unrotate(&subobj_pos, &pm->gun_banks[x].pnt[y], &object_orient);
}
g3_rotate_vertex(&draw_point, &subobj_pos);
g3_project_vertex(&draw_point);
int resize = resize_mode;
if (resize_mode == GR_RESIZE_MENU) {
resize = GR_RESIZE_MENU_NO_OFFSET;
}
gr_unsize_screen_posf(&draw_point.screen.xyw.x, &draw_point.screen.xyw.y, nullptr, nullptr, resize);
xc = fl2i(draw_point.screen.xyw.x + x1);
yc = fl2i(draw_point.screen.xyw.y + y1);
// get the curve right.
int curve;
if ((xc > bank_coords[x][0] + bank_prim_offset) && (bank_coords[x][1] + bank_y_offset < yc))
curve = 1;
else if ((xc < bank_coords[x][0] + bank_prim_offset) && (bank_coords[x][1] + bank_y_offset < yc))
curve = 0;
else if ((xc > bank_coords[x][0] + bank_prim_offset) && (bank_coords[x][1] + bank_y_offset > yc))
curve = 3;
else
curve = 2;
int lineendx;
int lineendy;
if (curve == 0) {
lineendx = xc + 4;
} else {
lineendx = xc - 4;
}
gr_line(bank_coords[x][0] + bank_prim_offset,
bank_coords[x][1] + bank_y_offset,
lineendx,
bank_coords[x][1] + bank_y_offset,
resize_mode);
if (curve == 0 || curve == 2)
lineendx = xc;
if (curve == 0 || curve == 1) {
lineendy = bank_coords[x][1] + bank_y_offset;
} else {
lineendy = bank_coords[x][1] + (bank_y_offset / 2);
}
gr_curve(lineendx, lineendy, 5, curve, resize_mode);
if (curve == 0 || curve == 1) {
lineendy = bank_coords[x][1] + static_cast<int>(lround(bank_y_offset * 1.5));
} else {
lineendy = bank_coords[x][1] + (bank_y_offset / 2);
}
gr_line(xc, lineendy, xc, yc, resize_mode);
gr_circle(xc, yc, 5, resize_mode);
}
num_found++;
}
}
num_found = 0;
// Render selected secondary lines
for (x = 0; x < pm->n_missiles; x++) {
if ((weapon_array[x + MAX_SHIP_PRIMARY_BANKS] == selected_weapon_class &&
hovered_weapon_slot < 0) ||
x + MAX_SHIP_PRIMARY_BANKS == hovered_weapon_slot) {
Assert(num_found < MAX_SHIP_PRIMARY_BANKS);
gr_set_color_fast(&Overhead_line_colors[num_found]);
gr_circle(bank_coords[x + MAX_SHIP_PRIMARY_BANKS][0] + bank_sec_offset,
bank_coords[x + MAX_SHIP_PRIMARY_BANKS][1] + bank_y_offset,
5,
resize_mode);
for (y = 0; y < pm->missile_banks[x].num_slots; y++) {
if (pm->flags & PM_FLAG_AUTOCEN) {
vm_vec_sub(&subobj_pos, &pm->missile_banks[x].pnt[y], &pm->autocenter);
vm_vec_unrotate(&subobj_pos, &subobj_pos, &object_orient);
} else {
vm_vec_unrotate(&subobj_pos, &pm->missile_banks[x].pnt[y], &object_orient);
}
g3_rotate_vertex(&draw_point, &subobj_pos);
g3_project_vertex(&draw_point);
int resize = resize_mode;
if (resize_mode == GR_RESIZE_MENU) {
resize = GR_RESIZE_MENU_NO_OFFSET;
}
gr_unsize_screen_posf(&draw_point.screen.xyw.x, &draw_point.screen.xyw.y, nullptr, nullptr, resize);
xc = fl2i(draw_point.screen.xyw.x + x1);
yc = fl2i(draw_point.screen.xyw.y + y1);