@@ -937,31 +937,37 @@ void hud_config_record_color(int in_color)
937937 HUD_color_blue = HC_colors[in_color].b ;
938938}
939939
940- // Set the HUD color
940+ // Set the HUD color to one of the color presets
941941void hud_config_set_color (int in_color)
942942{
943943 hud_config_record_color (in_color);
944944
945945 HUD_init_hud_color_array ();
946946
947- // apply the color to all gauges
948- for (int idx=0 ; idx<NUM_HUD_GAUGES ; idx++){
949- color clr;
950- gr_init_alphacolor (&clr, HC_colors[in_color].r , HC_colors[in_color].g , HC_colors[in_color].b , (HUD_color_alpha+1 )*16 );
951- SCP_string gauge = gauge_map.get_string_id_from_numeric_id (idx);
952- HUD_config.set_gauge_color (gauge, clr);
953- }
947+ color clr;
948+ gr_init_alphacolor (&clr, HC_colors[in_color].r , HC_colors[in_color].g , HC_colors[in_color].b , (HUD_color_alpha+1 )*16 );
949+
950+ // apply the color to all built-in gauges gauges
951+ for (const auto & gauge_pair : HC_gauge_map){
952+ const SCP_string& gauge_id = gauge_pair.first ;
953+ if (!gauge_id.empty ()) {
954+ HUD_config.set_gauge_color (gauge_id, clr);
955+ }
956+ }
954957}
955958
959+ // Set the HUD color when ALL GAUGES is selected in the HUD Config UI
956960void hud_config_stuff_colors (int r, int g, int b)
957961{
958962 color clr;
959963 gr_init_alphacolor (&clr, r, g, b, 255 );
960964
961965 // apply the color to all gauges
962- for (int idx=0 ; idx<NUM_HUD_GAUGES ; idx++){
963- SCP_string gauge = gauge_map.get_string_id_from_numeric_id (idx);
964- HUD_config.set_gauge_color (gauge, clr);
966+ for (const auto & gauge_pair : HC_gauge_map) {
967+ const SCP_string& gauge_id = gauge_pair.first ;
968+ if (!gauge_id.empty ()) {
969+ HUD_config.set_gauge_color (gauge_id, clr);
970+ }
965971 }
966972}
967973
@@ -1338,7 +1344,10 @@ void hud_config_button_enable(int index)
13381344// determine if on/off/popup buttons should be shown
13391345void hud_config_set_button_state ()
13401346{
1341- if (HC_gauge_selected.empty ()) {
1347+ const auto gauge = hud_config_get_gauge_pointer (HC_gauge_selected);
1348+
1349+ // Custom gauges cannot currently be set to popup or toggle visibility
1350+ if (HC_gauge_selected.empty () || gauge->isCustom ()) {
13421351 hud_config_button_disable (HCB_ON );
13431352 hud_config_button_disable (HCB_OFF );
13441353 hud_config_button_disable (HCB_POPUP );
@@ -1349,8 +1358,6 @@ void hud_config_set_button_state()
13491358 hud_config_button_enable (HCB_ON );
13501359 hud_config_button_enable (HCB_OFF );
13511360
1352- const auto gauge = hud_config_get_gauge_pointer (HC_gauge_selected);
1353-
13541361 // popup is maybe available
13551362 if (gauge != nullptr && gauge->getConfigCanPopup ()) {
13561363 hud_config_button_enable (HCB_POPUP );
@@ -1553,8 +1560,6 @@ void hud_config_close(bool API_Access)
15531560// hud_set_default_hud_config() will set the hud configuration to default values
15541561void hud_set_default_hud_config (player * /* p*/ , const SCP_string& filename)
15551562{
1556- int idx;
1557-
15581563 HUD_color_alpha = HUD_COLOR_ALPHA_DEFAULT ;
15591564 HUD_config.main_color = HC_default_color;
15601565 HUD_color_red = HC_colors[HUD_config.main_color ].r ;
@@ -1564,20 +1569,31 @@ void hud_set_default_hud_config(player * /*p*/, const SCP_string& filename)
15641569 color clr;
15651570 gr_init_alphacolor (&clr, HUD_color_red, HUD_color_green, HUD_color_blue, (HUD_color_alpha + 1 ) * 16 );
15661571
1567- for (idx=0 ; idx<NUM_HUD_GAUGES ; idx++){
1568- SCP_string gauge = gauge_map.get_string_id_from_numeric_id (idx);
1569- HUD_config.set_gauge_color (gauge, clr);
1572+ for (const auto & gauge_pair : HC_gauge_map) {
1573+ const SCP_string& gauge_id = gauge_pair.first ;
1574+ if (!gauge_id.empty ()) {
1575+ HUD_config.set_gauge_color (gauge_id, clr);
1576+ }
15701577 }
15711578
15721579 HUD_config.show_flags_map .clear ();
15731580 HUD_config.popup_flags_map .clear ();
15741581
1582+ // Built-in have specific settings
15751583 for (const auto & gauge_id : default_visible_gauges) {
15761584 HUD_config.show_flags_map [gauge_id] = true ;
15771585 }
15781586
1587+ // Custom gauges are always visible by default
1588+ for (const auto & gauge_pair : HC_gauge_map) {
1589+ if (gauge_pair.second ->isCustom ()) {
1590+ const SCP_string& gauge_id = gauge_pair.first ;
1591+ HUD_config.show_flags_map [gauge_id] = true ;
1592+ }
1593+ }
1594+
15791595 HUD_config.rp_dist = RR_INFINITY ;
1580- HUD_config.is_observer = 0 ;
1596+ HUD_config.is_observer = false ;
15811597
15821598 // load up the default colors
15831599 hud_config_color_load (filename.c_str ());
@@ -1801,23 +1817,22 @@ void hud_config_recalc_alpha_slider()
18011817
18021818void hud_config_red_slider ()
18031819{
1804- int idx;
18051820 int pos = HCS_CONV (HC_color_sliders[HCS_RED ].get_currentItem ()) ;
18061821
1807- // select all ?
18081822 if (HC_select_all){
1809- for (idx=0 ; idx<NUM_HUD_GAUGES ; idx++){
1810- SCP_string gauge = gauge_map.get_string_id_from_numeric_id (idx);
1811- gr_init_alphacolor (&HUD_config.gauge_colors [gauge], pos, HUD_config.gauge_colors [gauge].green , HUD_config.gauge_colors [gauge].blue , HUD_config.gauge_colors [gauge].alpha );
1812- }
1823+ for (const auto & gauge_pair : HC_gauge_map){
1824+ const SCP_string& gauge_id = gauge_pair.first ;
1825+ if (!gauge_id.empty ()) {
1826+ gr_init_alphacolor (&HUD_config.gauge_colors [gauge_id], pos, HUD_config.gauge_colors [gauge_id].green , HUD_config.gauge_colors [gauge_id].blue , HUD_config.gauge_colors [gauge_id].alpha );
1827+ }
1828+ }
18131829 }
18141830 // individual gauge
18151831 else {
18161832 if (HC_gauge_selected.empty ()){
18171833 return ;
18181834 }
18191835
1820- // get slider position
18211836 gr_init_alphacolor (&HUD_config.gauge_colors [HC_gauge_selected], pos, HUD_config.gauge_colors [HC_gauge_selected].green , HUD_config.gauge_colors [HC_gauge_selected].blue , HUD_config.gauge_colors [HC_gauge_selected].alpha );
18221837 }
18231838
@@ -1826,23 +1841,22 @@ void hud_config_red_slider()
18261841
18271842void hud_config_green_slider ()
18281843{
1829- int idx;
18301844 int pos = HCS_CONV (HC_color_sliders[HCS_GREEN ].get_currentItem ()) ;
18311845
1832- // select all ?
18331846 if (HC_select_all){
1834- for (idx=0 ; idx<NUM_HUD_GAUGES ; idx++){
1835- SCP_string gauge = gauge_map.get_string_id_from_numeric_id (idx);
1836- gr_init_alphacolor (&HUD_config.gauge_colors [gauge], HUD_config.gauge_colors [gauge].red , pos, HUD_config.gauge_colors [gauge].blue , HUD_config.gauge_colors [gauge].alpha );
1837- }
1847+ for (const auto & gauge_pair : HC_gauge_map){
1848+ const SCP_string& gauge_id = gauge_pair.first ;
1849+ if (!gauge_id.empty ()) {
1850+ gr_init_alphacolor (&HUD_config.gauge_colors [gauge_id], pos, HUD_config.gauge_colors [gauge_id].green , HUD_config.gauge_colors [gauge_id].blue , HUD_config.gauge_colors [gauge_id].alpha );
1851+ }
1852+ }
18381853 }
18391854 // individual gauge
18401855 else {
18411856 if (HC_gauge_selected.empty ()){
18421857 return ;
18431858 }
18441859
1845- // get slider position
18461860 gr_init_alphacolor (&HUD_config.gauge_colors [HC_gauge_selected], HUD_config.gauge_colors [HC_gauge_selected].red , pos, HUD_config.gauge_colors [HC_gauge_selected].blue , HUD_config.gauge_colors [HC_gauge_selected].alpha );
18471861 }
18481862
@@ -1851,23 +1865,22 @@ void hud_config_green_slider()
18511865
18521866void hud_config_blue_slider ()
18531867{
1854- int idx;
18551868 int pos = HCS_CONV (HC_color_sliders[HCS_BLUE ].get_currentItem ());
18561869
1857- // select all ?
18581870 if (HC_select_all){
1859- for (idx=0 ; idx<NUM_HUD_GAUGES ; idx++){
1860- SCP_string gauge = gauge_map.get_string_id_from_numeric_id (idx);
1861- gr_init_alphacolor (&HUD_config.gauge_colors [gauge], HUD_config.gauge_colors [gauge].red , HUD_config.gauge_colors [gauge].green , pos, HUD_config.gauge_colors [gauge].alpha );
1862- }
1871+ for (const auto & gauge_pair : HC_gauge_map){
1872+ const SCP_string& gauge_id = gauge_pair.first ;
1873+ if (!gauge_id.empty ()) {
1874+ gr_init_alphacolor (&HUD_config.gauge_colors [gauge_id], pos, HUD_config.gauge_colors [gauge_id].green , HUD_config.gauge_colors [gauge_id].blue , HUD_config.gauge_colors [gauge_id].alpha );
1875+ }
1876+ }
18631877 }
18641878 // individual gauge
18651879 else {
18661880 if (HC_gauge_selected.empty ()){
18671881 return ;
18681882 }
18691883
1870- // get slider position
18711884 gr_init_alphacolor (&HUD_config.gauge_colors [HC_gauge_selected], HUD_config.gauge_colors [HC_gauge_selected].red , HUD_config.gauge_colors [HC_gauge_selected].green , pos, HUD_config.gauge_colors [HC_gauge_selected].alpha );
18721885 }
18731886
@@ -1991,3 +2004,27 @@ void hud_config_select_all_toggle(bool toggle, bool API_Access)
19912004 HC_select_all = true ;
19922005 }
19932006}
2007+
2008+ SCP_string create_custom_gauge_id (const SCP_string& gauge_name) {
2009+ Assertion (!gauge_name.empty (), " Custom gauge has no name!" );
2010+
2011+ SCP_string id;
2012+ if (Mod_title.empty ()) {
2013+ id = Cmdline_mod;
2014+
2015+ // Basic cleanup attempt
2016+ id = id.substr (0 , id.find_first_of (DIR_SEPARATOR_CHAR ));
2017+ } else {
2018+ id = Mod_title;
2019+ }
2020+
2021+ if (!id.empty ()) {
2022+ std::replace (id.begin (), id.end (), ' ' , ' _' );
2023+ } else {
2024+ id = " Custom" ;
2025+ }
2026+
2027+ id += " ::" + gauge_name;
2028+
2029+ return id;
2030+ }
0 commit comments