Skip to content

Commit 021eb8e

Browse files
authored
Fix two HUD Config preset issues (#6830)
* always use exact match * custom gauges should use the type for colors with old preset files
1 parent 487cac6 commit 021eb8e

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

code/hud/hudconfig.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

code/hud/hudconfig.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,12 @@ typedef struct HUD_CONFIG_TYPE {
182182
}
183183

184184
// 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
185+
color get_gauge_color(const SCP_string& gauge_id) const
186186
{
187187
auto it = gauge_colors.find(gauge_id);
188188

189189
// Got a match? Return it
190-
// but only if we are using the exact match
191-
if (check_exact_match && it != gauge_colors.end()) {
190+
if (it != gauge_colors.end()) {
192191
return it->second;
193192
}
194193

code/pilotfile/plr_hudprefs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void hud_config_save_player_prefs(const char* callsign)
4949
if (HUD_config.is_gauge_shown_in_config(gauge_id)) {
5050
clr = pair.second;
5151
} else {
52-
clr = HUD_config.get_gauge_color(gauge_id, false);
52+
clr = HUD_config.get_gauge_color(gauge_id);
5353
HUD_config.set_gauge_color(gauge_id, clr);
5454
}
5555

0 commit comments

Comments
 (0)