Fix two HUD Config preset issues (#6830)

* always use exact match

* custom gauges should use the type for colors with old preset files
This commit is contained in:
Mike Nelson authored and GitHub committed 2025-07-24 16:51:45 -04:00
1 parent 487cac6456
commit 021eb8e49a
3 files changed
+34 -6

No files matched your search

+31 -2
View File
@@ -1709,6 +1709,8 @@ void hud_config_color_load(const char *name)
HUD_config.set_gauge_color(gauge.first, clr);
}
SCP_vector<std::pair<SCP_string, color>> gauge_color_list;
// Now read in the color values for the gauges
int version = 1;
if (optional_string("+VERSION 2")) {
@@ -1732,12 +1734,12 @@ void hud_config_color_load(const char *name)
case 1: {
SCP_string gauge = gauge_map.get_string_id_from_hcf_id(str);
if (!gauge.empty()) {
HUD_config.set_gauge_color(gauge, clr);
gauge_color_list.emplace_back(gauge, clr);
}
break;
}
case 2: {
HUD_config.set_gauge_color(str, clr);
gauge_color_list.emplace_back(str, clr);
break;
}
default: {
@@ -1745,6 +1747,33 @@ void hud_config_color_load(const char *name)
}
}
}
auto is_builtin = [](auto const& p) {
return p.first.rfind("Builtin::", 0) == 0;
};
// Move all builtin:: items to the front, keeping original order
std::stable_partition(gauge_color_list.begin(), gauge_color_list.end(), is_builtin);
// Add the colors to the HUD_config
for (const auto& gauge_color : gauge_color_list) {
HUD_config.set_gauge_color(gauge_color.first, gauge_color.second);
// If this is a builtin gauge, we also need to set the color for all other gauges of the same type
// Builtin gauges are handled first so that any defintions for custom gauges will override the builtin ones later
if (is_builtin(gauge_color)) {
int type = gauge_map.get_numeric_id_from_string_id(gauge_color.first);
for (const auto& this_gauge : HC_gauge_map) {
if (this_gauge.first == gauge_color.first) {
continue;
}
if (this_gauge.second->getConfigType() == type) {
HUD_config.set_gauge_color(this_gauge.first, gauge_color.second);
}
}
}
}
}
catch (const parse::ParseException& e)
{
+2 -3
View File
@@ -182,13 +182,12 @@ typedef struct HUD_CONFIG_TYPE {
}
// Get the gauge color, the color based on its type, or white if the gauge is not found
color get_gauge_color(const SCP_string& gauge_id, bool check_exact_match = true) const
color get_gauge_color(const SCP_string& gauge_id) const
{
auto it = gauge_colors.find(gauge_id);
// Got a match? Return it
// but only if we are using the exact match
if (check_exact_match && it != gauge_colors.end()) {
if (it != gauge_colors.end()) {
return it->second;
}
+1 -1
View File
@@ -49,7 +49,7 @@ void hud_config_save_player_prefs(const char* callsign)
if (HUD_config.is_gauge_shown_in_config(gauge_id)) {
clr = pair.second;
} else {
clr = HUD_config.get_gauge_color(gauge_id, false);
clr = HUD_config.get_gauge_color(gauge_id);
HUD_config.set_gauge_color(gauge_id, clr);
}