Skip to content

Commit dbe0af1

Browse files
authored
Allow Custom Gauges to fully use parent type colors (#6799)
* Allow Custom Gauges to fully use parent type colors #6670 allowed for custom coloring of HUD gauges, so this PR follows that up with fixing a few edge cases where mods with custom gauges that are linked to parent gauge types accurately reflect the color of their parent gauge type in both the new saved HUD file and the in-mission HUD. This ability to link color to parent gauges for custom gauges the player cannot edit is what the behavior has always been, so this PR does not change any expected behavior it simply ensures that the new HUD updates and various combinations of table entries for `Config` are all robustly accounted for. For example, in FotG we have multiple non-configurable custom gauges all tied to the center reticle, so if the player changes the color of the center reticle all the custom gauges set to that type also automatically change color. Tested and works as expected. * appease clang * one more clang * clang needs to calm down * instruct clang to be calm * fix comment typo
1 parent f95ae0b commit dbe0af1

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

code/hud/hudconfig.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ extern SCP_vector<SCP_string> observer_visible_gauges;
147147
extern const int HC_gauge_config_coords[GR_NUM_RESOLUTIONS][4];
148148
extern int HC_resize_mode;
149149

150+
/*!
151+
* @brief get the gauge pointer for the given gauge index
152+
*/
153+
HudGauge* hud_config_get_gauge_pointer(const SCP_string& gauge_id);
154+
150155
/**
151156
* @brief Contains core HUD configuration data
152157
* @note Is not default init'd. Assumes new player, PLR, or CSG reads will correctly set data.
@@ -176,17 +181,18 @@ typedef struct HUD_CONFIG_TYPE {
176181
gauge_colors[gauge_id] = col;
177182
}
178183

179-
// Get the gauge color, the color based on it's type, or white if the gauge is not found
180-
color get_gauge_color(const SCP_string& gauge_id) const
184+
// Get the gauge color, the color based on its type, or white if the gauge is not found
185+
color get_gauge_color(const SCP_string& gauge_id, bool check_exact_match = true) const
181186
{
182187
auto it = gauge_colors.find(gauge_id);
183188

184189
// Got a match? Return it
185-
if (it != gauge_colors.end()) {
190+
// but only if we are using the exact match
191+
if (check_exact_match && it != gauge_colors.end()) {
186192
return it->second;
187193
}
188194

189-
// No match.. try using the gauge type
195+
// No match yet.. try using the gauge type
190196
auto type_it = gauge_types.find(gauge_id);
191197
if (type_it != gauge_types.end()) {
192198
const HC_gauge_mappings& gauge_map = HC_gauge_mappings::get_instance();
@@ -228,6 +234,13 @@ typedef struct HUD_CONFIG_TYPE {
228234
auto it = popup_flags_map.find(gauge_id);
229235
return (it != popup_flags_map.end()) ? it->second : false; // Default to not a popup
230236
}
237+
238+
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
239+
bool is_gauge_shown_in_config(const SCP_string& gauge_id) const
240+
{
241+
HudGauge* gauge = hud_config_get_gauge_pointer(gauge_id);
242+
return gauge && gauge->getVisibleInConfig();
243+
}
231244
} HUD_CONFIG_TYPE;
232245

233246
extern HUD_CONFIG_TYPE HUD_config;
@@ -321,11 +334,6 @@ extern SCP_map<SCP_string, SCP_vector<SCP_string>> HC_hud_primary_weapons;
321334
extern SCP_map<SCP_string, SCP_vector<SCP_string>> HC_hud_secondary_weapons;
322335

323336

324-
/*!
325-
* @brief get the gauge pointer for the given gauge index
326-
*/
327-
HudGauge* hud_config_get_gauge_pointer(const SCP_string& gauge_id);
328-
329337
/*!
330338
* @brief init hud config screen, setting up the hud preview display
331339
*

code/pilotfile/plr_hudprefs.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ void hud_config_save_player_prefs(const char* callsign)
4242
// Get current state
4343
bool is_visible = HUD_config.is_gauge_visible(gauge_id);
4444
bool is_popup = HUD_config.is_gauge_popup(gauge_id);
45-
color clr = pair.second;
45+
46+
// Get color to save. If gauge is hidden in configure screen, then player cannot set it,
47+
// so look up the parent gauge type and save/set it. --wookeejedi
48+
color clr;
49+
if (HUD_config.is_gauge_shown_in_config(gauge_id)) {
50+
clr = pair.second;
51+
} else {
52+
clr = HUD_config.get_gauge_color(gauge_id, false);
53+
HUD_config.set_gauge_color(gauge_id, clr);
54+
}
4655

4756
// +Gauge: <id>
4857
sprintf(format_buffer, "+Gauge: %s\n", gauge_id.c_str());

0 commit comments

Comments
 (0)