@@ -1709,6 +1709,8 @@ void hud_config_color_load(const char *name)
17091709 HUD_config.set_gauge_color (gauge.first , clr);
17101710 }
17111711
1712+ SCP_vector<std::pair<SCP_string, color>> gauge_color_list;
1713+
17121714 // Now read in the color values for the gauges
17131715 int version = 1 ;
17141716 if (optional_string (" +VERSION 2" )) {
@@ -1732,19 +1734,46 @@ void hud_config_color_load(const char *name)
17321734 case 1 : {
17331735 SCP_string gauge = gauge_map.get_string_id_from_hcf_id (str);
17341736 if (!gauge.empty ()) {
1735- HUD_config. set_gauge_color (gauge, clr);
1737+ gauge_color_list. emplace_back (gauge, clr);
17361738 }
17371739 break ;
17381740 }
17391741 case 2 : {
1740- HUD_config. set_gauge_color (str, clr);
1742+ gauge_color_list. emplace_back (str, clr);
17411743 break ;
17421744 }
17431745 default : {
17441746 throw parse::ParseException (" Unknown HUD config version: " + std::to_string (version));
17451747 }
17461748 }
17471749 }
1750+
1751+ auto is_builtin = [](auto const & p) {
1752+ return p.first .rfind (" Builtin::" , 0 ) == 0 ;
1753+ };
1754+
1755+ // Move all builtin:: items to the front, keeping original order
1756+ std::stable_partition (gauge_color_list.begin (), gauge_color_list.end (), is_builtin);
1757+
1758+ // Add the colors to the HUD_config
1759+ for (const auto & gauge_color : gauge_color_list) {
1760+ HUD_config.set_gauge_color (gauge_color.first , gauge_color.second );
1761+
1762+ // If this is a builtin gauge, we also need to set the color for all other gauges of the same type
1763+ // Builtin gauges are handled first so that any defintions for custom gauges will override the builtin ones later
1764+ if (is_builtin (gauge_color)) {
1765+ int type = gauge_map.get_numeric_id_from_string_id (gauge_color.first );
1766+
1767+ for (const auto & this_gauge : HC_gauge_map) {
1768+ if (this_gauge.first == gauge_color.first ) {
1769+ continue ;
1770+ }
1771+ if (this_gauge.second ->getConfigType () == type) {
1772+ HUD_config.set_gauge_color (this_gauge.first , gauge_color.second );
1773+ }
1774+ }
1775+ }
1776+ }
17481777 }
17491778 catch (const parse::ParseException& e)
17501779 {
0 commit comments