Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions code/hud/hudconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -1732,19 +1734,46 @@ 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: {
throw parse::ParseException("Unknown HUD config version: " + std::to_string(version));
}
}
}

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)
{
Expand Down
5 changes: 2 additions & 3 deletions code/hud/hudconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion code/pilotfile/plr_hudprefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading