Skip to content

Commit 25dbfc6

Browse files
authored
Misc hud config fixes (#6727)
* Fix crash when clicking inside the hud area but not on a gauge * add dogfight_variant weapon flag for sorting purposes * fix weapon display for default hud and skip dogfight weapons on auto-select * cleanup the mouse check function
1 parent 66d9335 commit 25dbfc6

File tree

4 files changed

+92
-55
lines changed

4 files changed

+92
-55
lines changed

code/hud/hudconfig.cpp

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -847,23 +847,7 @@ void hud_config_check_regions_by_mouse(int mx, int my)
847847
*/
848848
void hud_config_check_regions(int mx, int my)
849849
{
850-
if (hud_config_check_mouse_in_hud_area(mx, my)) {
851-
HC_gauge_hot = "-2";
852-
}
853-
854-
if (HC_gauge_hot == "-2" && mouse_down(MOUSE_LEFT_BUTTON)) {
855-
HC_gauge_selected.clear();
856-
HC_color_sliders[HCS_RED].hide();
857-
HC_color_sliders[HCS_GREEN].hide();
858-
HC_color_sliders[HCS_BLUE].hide();
859-
HC_color_sliders[HCS_ALPHA].hide();
860-
861-
HC_color_sliders[HCS_RED].disable();
862-
HC_color_sliders[HCS_GREEN].disable();
863-
HC_color_sliders[HCS_BLUE].disable();
864-
HC_color_sliders[HCS_ALPHA].disable();
865-
}
866-
850+
// If we click on one of the new arrows then try to select a new HUD
867851
if (HC_arrow_hot >= 0 && mouse_down(MOUSE_LEFT_BUTTON)) {
868852
gamesnd_play_iface(InterfaceSounds::USER_SELECT);
869853
if (HC_arrow_hot == 0) {
@@ -875,51 +859,65 @@ void hud_config_check_regions(int mx, int my)
875859
return;
876860
}
877861

878-
hud_config_check_regions_by_mouse(mx, my);
862+
// If we're not in the HUD area then nothing else applies here
863+
if (!hud_config_check_mouse_in_hud_area(mx, my)) {
864+
mouse_flush();
865+
return;
866+
}
879867

880-
if (!HC_gauge_hot.empty() && mouse_down(MOUSE_LEFT_BUTTON)) {
881-
gamesnd_play_iface(InterfaceSounds::USER_SELECT);
882-
HC_gauge_selected = HC_gauge_hot;
868+
// Sets HC_gauge_hot to a gauge name if we're hovering over one of them
869+
hud_config_check_regions_by_mouse(mx, my);
883870

884-
// turn off select all
885-
hud_config_select_all_toggle(false);
871+
// If we click inside the HUD area then reset the UI
872+
if (mouse_down(MOUSE_LEFT_BUTTON)) {
873+
HC_gauge_selected.clear();
874+
HC_color_sliders[HCS_RED].hide();
875+
HC_color_sliders[HCS_GREEN].hide();
876+
HC_color_sliders[HCS_BLUE].hide();
877+
HC_color_sliders[HCS_ALPHA].hide();
886878

887-
const auto gauge = hud_config_get_gauge_pointer(HC_gauge_selected);
879+
HC_color_sliders[HCS_RED].disable();
880+
HC_color_sliders[HCS_GREEN].disable();
881+
HC_color_sliders[HCS_BLUE].disable();
882+
HC_color_sliders[HCS_ALPHA].disable();
888883

889-
// maybe setup rgb sliders
890-
if (gauge != nullptr && gauge->getConfigUseIffColor()) {
891-
HC_color_sliders[HCS_RED].hide();
892-
HC_color_sliders[HCS_GREEN].hide();
893-
HC_color_sliders[HCS_BLUE].hide();
894-
HC_color_sliders[HCS_ALPHA].hide();
895-
896-
HC_color_sliders[HCS_RED].disable();
897-
HC_color_sliders[HCS_GREEN].disable();
898-
HC_color_sliders[HCS_BLUE].disable();
899-
HC_color_sliders[HCS_ALPHA].disable();
900-
} else {
901-
HC_color_sliders[HCS_RED].enable();
902-
HC_color_sliders[HCS_GREEN].enable();
903-
HC_color_sliders[HCS_BLUE].enable();
904-
HC_color_sliders[HCS_ALPHA].enable();
884+
// Turn off select all
885+
hud_config_select_all_toggle(false);
905886

906-
HC_color_sliders[HCS_RED].unhide();
907-
HC_color_sliders[HCS_GREEN].unhide();
908-
HC_color_sliders[HCS_BLUE].unhide();
909-
HC_color_sliders[HCS_ALPHA].unhide();
887+
// See if we have a gauge that we were hovering over when we clicked
888+
const auto gauge = hud_config_get_gauge_pointer(HC_gauge_hot);
910889

911-
color clr = HUD_config.get_gauge_color(HC_gauge_selected);
890+
// If we clicked on a gauge then set the UI up for managing that gauge
891+
if (gauge) {
892+
gamesnd_play_iface(InterfaceSounds::USER_SELECT);
893+
HC_gauge_selected = HC_gauge_hot;
894+
895+
// Setup rgb sliders if the gauge doesn't use IFF colors
896+
if (!gauge->getConfigUseIffColor()) {
897+
HC_color_sliders[HCS_RED].enable();
898+
HC_color_sliders[HCS_GREEN].enable();
899+
HC_color_sliders[HCS_BLUE].enable();
900+
HC_color_sliders[HCS_ALPHA].enable();
901+
902+
HC_color_sliders[HCS_RED].unhide();
903+
HC_color_sliders[HCS_GREEN].unhide();
904+
HC_color_sliders[HCS_BLUE].unhide();
905+
HC_color_sliders[HCS_ALPHA].unhide();
906+
907+
color clr = HUD_config.get_gauge_color(HC_gauge_selected);
908+
909+
HC_color_sliders[HCS_RED].force_currentItem(HCS_CONV(clr.red));
910+
HC_color_sliders[HCS_GREEN].force_currentItem(HCS_CONV(clr.green));
911+
HC_color_sliders[HCS_BLUE].force_currentItem(HCS_CONV(clr.blue));
912+
HC_color_sliders[HCS_ALPHA].force_currentItem(HCS_CONV(clr.alpha));
913+
}
912914

913-
HC_color_sliders[HCS_RED].force_currentItem(HCS_CONV(clr.red));
914-
HC_color_sliders[HCS_GREEN].force_currentItem(HCS_CONV(clr.green));
915-
HC_color_sliders[HCS_BLUE].force_currentItem(HCS_CONV(clr.blue));
916-
HC_color_sliders[HCS_ALPHA].force_currentItem(HCS_CONV(clr.alpha));
915+
// recalc alpha slider
916+
hud_config_recalc_alpha_slider();
917917
}
918-
919-
// recalc alpha slider
920-
hud_config_recalc_alpha_slider();
921-
mouse_flush();
922918
}
919+
920+
mouse_flush();
923921
}
924922

925923
// set the display flags for a HUD gauge

code/hud/hudtarget.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6519,10 +6519,15 @@ void HudGaugeWeapons::render(float /*frametime*/, bool config)
65196519

65206520
if (auto it_spec = weapon_map.find(hud); it_spec != weapon_map.end()) {
65216521
return it_spec->second;
6522-
} else if (auto it_def = weapon_map.find("default"); it_def != weapon_map.end()) {
6523-
return it_def->second;
65246522
}
65256523
}
6524+
6525+
// Nothing found, try default
6526+
if (auto it_def = weapon_map.find("default"); it_def != weapon_map.end()) {
6527+
return it_def->second;
6528+
}
6529+
6530+
// No specialized settings, return null and pick some weapons later
65266531
return std::nullopt;
65276532
};
65286533

@@ -6606,6 +6611,12 @@ void HudGaugeWeapons::render(float /*frametime*/, bool config)
66066611
int match_count = 0;
66076612
for (weapon_info& wep : Weapon_info) {
66086613
if (wep.subtype == WP_LASER && wep.wi_flags[Weapon::Info_Flags::Player_allowed]) {
6614+
6615+
// Skip the retail dogfight weapons
6616+
if (wep.wi_flags[Weapon::Info_Flags::Dogfight_weapon]) {
6617+
continue;
6618+
}
6619+
66096620
if (match_count == i) {
66106621
wip = &wep;
66116622
weapon_name = wip->get_display_name();
@@ -6694,6 +6705,12 @@ void HudGaugeWeapons::render(float /*frametime*/, bool config)
66946705
int match_count = 0;
66956706
for (weapon_info& wep : Weapon_info) {
66966707
if (wep.subtype == WP_MISSILE && wep.wi_flags[Weapon::Info_Flags::Player_allowed]) {
6708+
6709+
// Skip the retail dogfight weapons
6710+
if (wep.wi_flags[Weapon::Info_Flags::Dogfight_weapon]) {
6711+
continue;
6712+
}
6713+
66976714
if (match_count == i) {
66986715
wip = &wep;
66996716
break;

code/weapon/weapon_flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ namespace Weapon {
9696
Detonate_on_expiration, // Secondary weapons always detonate when their lifetime runs out, but now primary weapons can too
9797
Ignores_countermeasures, // The weapon will never be affected by countermeasures
9898
Freespace_1_missile_behavior, // Bundles several observed behaviors missiles had in the freespace 1 release
99+
Dogfight_weapon, // Dogfight weapons are intended as balanced variants for multiplayer. This flag can be used to filter them out when necessary.
99100

100101
NUM_VALUES
101102
};

code/weapon/weapons.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ special_flag_def_list_new<Weapon::Info_Flags, weapon_info*, flagset<Weapon::Info
258258
flags.remove(Weapon::Info_Flags::Freespace_1_missile_behavior);
259259
}
260260
}}, //special case
261+
{"dogfight variant", Weapon::Info_Flags::Dogfight_weapon, true},
261262
};
262263

263264
const size_t num_weapon_info_flags = sizeof(Weapon_Info_Flags) / sizeof(special_flag_def_list_new<Weapon::Info_Flags, weapon_info*, flagset<Weapon::Info_Flags>&>);
@@ -2069,6 +2070,26 @@ int parse_weapon(int subtype, bool replace, const char *filename)
20692070

20702071
parse_wi_flags(wip);
20712072

2073+
// List of retail dogfight weapons to enforce dogfight flag on
2074+
static const SCP_unordered_set<SCP_string> retailDogfightWeapons = {
2075+
"Subach HL-D",
2076+
"Mekhu HL-7D",
2077+
"MorningStar D",
2078+
"Prometheus D",
2079+
"Maxim D",
2080+
"UD-D Kayser",
2081+
"Rockeye D",
2082+
"Tempest D",
2083+
"Hornet D",
2084+
"Tornado D",
2085+
"Harpoon D"
2086+
};
2087+
2088+
// If we're a retail dogfight weapon then mark it
2089+
if (retailDogfightWeapons.contains(wip->name)) {
2090+
wip->wi_flags.set(Weapon::Info_Flags::Dogfight_weapon);
2091+
}
2092+
20722093
// be friendly; make sure ballistic flags are synchronized - Goober5000
20732094
// primary
20742095
if (subtype == WP_LASER)

0 commit comments

Comments
 (0)