diff --git a/code/hud/hudconfig.cpp b/code/hud/hudconfig.cpp index e1855e614d1..32fd548cf51 100644 --- a/code/hud/hudconfig.cpp +++ b/code/hud/hudconfig.cpp @@ -1709,6 +1709,8 @@ void hud_config_color_load(const char *name) HUD_config.set_gauge_color(gauge.first, clr); } + SCP_vector> 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) { diff --git a/code/hud/hudconfig.h b/code/hud/hudconfig.h index e6cf7796ef3..56b80a5333d 100644 --- a/code/hud/hudconfig.h +++ b/code/hud/hudconfig.h @@ -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; } diff --git a/code/pilotfile/plr_hudprefs.cpp b/code/pilotfile/plr_hudprefs.cpp index edc51da6f81..a4c45a6f7c4 100644 --- a/code/pilotfile/plr_hudprefs.cpp +++ b/code/pilotfile/plr_hudprefs.cpp @@ -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); }