From 905884cd7078f1c4b633932cd341287e8ea67209 Mon Sep 17 00:00:00 2001 From: AudBobb Date: Sun, 20 Oct 2024 20:41:54 -0500 Subject: [PATCH 1/9] Add two new widgets to display weight with the format "##.#/##.# kg" and "##.#/##.# lb", and add the widgets to the legacy labels sidebar --- data/json/ui/sidebar-legacy-labels.json | 50 +++++++++++++++++- src/display.cpp | 68 +++++++++++++++++++++++++ src/display.h | 5 ++ src/widget.cpp | 12 +++++ src/widget.h | 2 + 5 files changed, 136 insertions(+), 1 deletion(-) diff --git a/data/json/ui/sidebar-legacy-labels.json b/data/json/ui/sidebar-legacy-labels.json index 3ff4b4bbb256e..81fa87c9e104d 100644 --- a/data/json/ui/sidebar-legacy-labels.json +++ b/data/json/ui/sidebar-legacy-labels.json @@ -169,10 +169,56 @@ "id": "ll_place_layout", "type": "widget", "style": "layout", - "label": { "ctxt": "UI sidebar", "str": "Place" }, + "label": { + "ctxt": "UI sidebar", + "str": "Place" + }, "arrange": "minimum_columns", "widgets": [ "ll_place_info", "ll_place_overmap" ] }, + { + "id": "ll_carry_weight_label", + "width": 8, + "style": "symbol", + "text_align": "left", + "colors": [ "c_dark_gray" ], + "string": "Weight :", + "type": "widget" + }, + { + "id": "ll_carry_weight_kgs", + "width": 12, + "style": "text", + "text_align": "left", + "var": "carry_weight_kgs", + "type": "widget" + }, + { + "id": "ll_weight_carried_kgs", + "width": 13, + "style": "layout", + "label": "Weight Carried (kg)", + "arrange": "minimum_columns", + "widgets": [ "ll_carry_weight_label", "ll_carry_weight_kgs" ], + "type": "widget" + }, + { + "id": "ll_carry_weight_lbs", + "width": 12, + "style": "text", + "text_align": "left", + "var": "carry_weight_lbs", + "type": "widget" + }, + { + "id": "ll_weight_carried_lbs", + "width": 13, + "style": "layout", + "label": "Weight Carried (lb)", + "arrange": "minimum_columns", + "widgets": [ "ll_carry_weight_label", "ll_carry_weight_lbs" ], + "type": "widget" + }, { "id": "legacy_labels_sidebar", "type": "widget", @@ -194,6 +240,8 @@ "weapon_style_layout", "vehicle_acf_label_layout", "compass_all_danger_layout", + "ll_weight_carried_kgs", + "ll_weight_carried_lbs", "rad_badge_desc", "sundial_label_layout" ] diff --git a/src/display.cpp b/src/display.cpp index 9850ee064dd43..ced666162fa40 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1012,6 +1012,74 @@ std::pair display::carry_weight_text_color( const avatar return std::make_pair( weight_text, weight_color ); } +// Weight carried, formatted as "current/max" in kg +std::pair display::carry_weight_kgs_color(const avatar& ava) +{ + float carry_wt = ( ava.weight_carried().value() / 1000000.0f ); + float max_wt = ( ava.weight_capacity().value() / 1000000.0f ); + + // Create a string showing "current_weight / max_weight" + //std::string weight_text = string_format("%d", carry_wt); + std::string weight_text = string_format("%.1f/%.1f kg", carry_wt, max_wt); + + // Set the color based on carry weight + nc_color weight_color = c_green; // Default color + + if (max_wt > 0) { + if (carry_wt > max_wt) { + weight_color = c_red; // Exceeds capacity + } + else if (carry_wt > 0.75 * max_wt) { + weight_color = c_light_red; // Approaching capacity (75%) + } + else if (carry_wt > 0.5 * max_wt) { + weight_color = c_yellow; // At half capacity (50%) + } + else if (carry_wt > 0.25 * max_wt) { + weight_color = c_light_green; // Below half capacity (25%) + } + else { + weight_color = c_green; // Light load + } + } + + return std::make_pair(weight_text, weight_color); +} + +// Weight carried, formatted as "current/max" in lbs +std::pair display::carry_weight_lbs_color(const avatar& ava) +{ + float carry_wt = (ava.weight_carried().value() / 453592.37f); + float max_wt = (ava.weight_capacity().value() / 453592.37f); + + // Create a string showing "current_weight / max_weight" + //std::string weight_text = string_format("%d", carry_wt); + std::string weight_text = string_format("%.1f/%.1f lb", carry_wt, max_wt); + + // Set the color based on carry weight + nc_color weight_color = c_green; // Default color + + if (max_wt > 0) { + if (carry_wt > max_wt) { + weight_color = c_red; // Exceeds capacity + } + else if (carry_wt > 0.75 * max_wt) { + weight_color = c_light_red; // Approaching capacity (75%) + } + else if (carry_wt > 0.5 * max_wt) { + weight_color = c_yellow; // At half capacity (50%) + } + else if (carry_wt > 0.25 * max_wt) { + weight_color = c_light_green; // Below half capacity (25%) + } + else { + weight_color = c_green; // Light load + } + } + + return std::make_pair(weight_text, weight_color); +} + std::pair display::overmap_note_symbol_color( const std::string_view note_text ) { diff --git a/src/display.h b/src/display.h index 1dec42a2c6b13..b2aa708de5015 100644 --- a/src/display.h +++ b/src/display.h @@ -181,6 +181,11 @@ nc_color limb_color( const Character &u, const bodypart_id &bp, bool bleed, bool // Color for displaying the given encumbrance level nc_color encumb_color( int level ); +// Weight carried, formatted as "current/max" in kg +std::pair carry_weight_kgs_color(const avatar& ava); +// Weight carried, formatted as "current/max" in lb +std::pair carry_weight_lbs_color(const avatar& ava); + // Colorized symbol for the overmap tile at the given location std::pair overmap_tile_symbol_color( const avatar &u, const tripoint_abs_omt &omt, bool edge_tile, bool &found_mi ); diff --git a/src/widget.cpp b/src/widget.cpp index faa69108b1929..55a63e5b24606 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -144,6 +144,10 @@ std::string enum_to_string( widget_var data ) return "bp_armor_outer_text"; case widget_var::carry_weight_text: return "carry_weight_text"; + case widget_var::carry_weight_kgs: + return "carry_weight_kgs"; + case widget_var::carry_weight_lbs: + return "carry_weight_lbs"; case widget_var::date_text: return "date_text"; case widget_var::env_temp_text: @@ -1037,6 +1041,8 @@ bool widget::uses_text_function() const case widget_var::body_graph_wet: case widget_var::bp_armor_outer_text: case widget_var::carry_weight_text: + case widget_var::carry_weight_kgs: + case widget_var::carry_weight_lbs: case widget_var::compass_text: case widget_var::compass_legend_text: case widget_var::date_text: @@ -1140,6 +1146,12 @@ std::string widget::color_text_function_string( const avatar &ava, unsigned int case widget_var::carry_weight_text: desc = display::carry_weight_text_color( ava ); break; + case widget_var::carry_weight_kgs: + desc = display::carry_weight_kgs_color( ava ); + break; + case widget_var::carry_weight_lbs: + desc = display::carry_weight_lbs_color(ava); + break; case widget_var::date_text: desc.first = display::date_string(); break; diff --git a/src/widget.h b/src/widget.h index ed1b072366e1f..ce436c08325f1 100644 --- a/src/widget.h +++ b/src/widget.h @@ -54,6 +54,8 @@ enum class widget_var : int { body_graph_wet, // Body graph showing color-coded body part wetness bp_armor_outer_text, // Outermost armor on body part, with color/damage bars carry_weight_text, // Weight carried, relative to capacity, in % + carry_weight_kgs, // Weight carried, formatted as "current/max" in kgs + carry_weight_lbs, // Weight carried, formatted as "current/max" in lbs compass_text, // Compass / visible threats by cardinal direction compass_legend_text, // Names of visible creatures that appear on the compass date_text, // Current date, in terms of day within season From ebd314a51608d9695e6caf6fb3a9c9aa27b0e5ec Mon Sep 17 00:00:00 2001 From: Zhan Avesna <97810032+AudBobb@users.noreply.github.com> Date: Sun, 20 Oct 2024 21:54:09 -0500 Subject: [PATCH 2/9] Apply suggestions from code review I don't format goodly Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- data/json/ui/sidebar-legacy-labels.json | 5 +-- src/display.cpp | 48 +++++++++++-------------- src/display.h | 4 +-- src/widget.cpp | 2 +- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/data/json/ui/sidebar-legacy-labels.json b/data/json/ui/sidebar-legacy-labels.json index 81fa87c9e104d..4053fcabcbaa9 100644 --- a/data/json/ui/sidebar-legacy-labels.json +++ b/data/json/ui/sidebar-legacy-labels.json @@ -169,10 +169,7 @@ "id": "ll_place_layout", "type": "widget", "style": "layout", - "label": { - "ctxt": "UI sidebar", - "str": "Place" - }, + "label": { "ctxt": "UI sidebar", "str": "Place" }, "arrange": "minimum_columns", "widgets": [ "ll_place_info", "ll_place_overmap" ] }, diff --git a/src/display.cpp b/src/display.cpp index ced666162fa40..86b9f159282e5 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1013,71 +1013,63 @@ std::pair display::carry_weight_text_color( const avatar } // Weight carried, formatted as "current/max" in kg -std::pair display::carry_weight_kgs_color(const avatar& ava) +std::pair display::carry_weight_kgs_color( const avatar &ava ) { float carry_wt = ( ava.weight_carried().value() / 1000000.0f ); float max_wt = ( ava.weight_capacity().value() / 1000000.0f ); // Create a string showing "current_weight / max_weight" //std::string weight_text = string_format("%d", carry_wt); - std::string weight_text = string_format("%.1f/%.1f kg", carry_wt, max_wt); + std::string weight_text = string_format( "%.1f/%.1f kg", carry_wt, max_wt ); // Set the color based on carry weight nc_color weight_color = c_green; // Default color - if (max_wt > 0) { - if (carry_wt > max_wt) { + if( max_wt > 0 ) { + if( carry_wt > max_wt ) { weight_color = c_red; // Exceeds capacity - } - else if (carry_wt > 0.75 * max_wt) { + } else if( carry_wt > 0.75 * max_wt ) { weight_color = c_light_red; // Approaching capacity (75%) - } - else if (carry_wt > 0.5 * max_wt) { + } else if( carry_wt > 0.5 * max_wt ) { weight_color = c_yellow; // At half capacity (50%) - } - else if (carry_wt > 0.25 * max_wt) { + } else if( carry_wt > 0.25 * max_wt ) { weight_color = c_light_green; // Below half capacity (25%) - } - else { + } else { weight_color = c_green; // Light load } } - return std::make_pair(weight_text, weight_color); + return std::make_pair( weight_text, weight_color ); } // Weight carried, formatted as "current/max" in lbs -std::pair display::carry_weight_lbs_color(const avatar& ava) +std::pair display::carry_weight_lbs_color( const avatar &ava ) { - float carry_wt = (ava.weight_carried().value() / 453592.37f); - float max_wt = (ava.weight_capacity().value() / 453592.37f); + float carry_wt = ( ava.weight_carried().value() / 453592.37f ); + float max_wt = ( ava.weight_capacity().value() / 453592.37f ); // Create a string showing "current_weight / max_weight" //std::string weight_text = string_format("%d", carry_wt); - std::string weight_text = string_format("%.1f/%.1f lb", carry_wt, max_wt); + std::string weight_text = string_format( "%.1f/%.1f lb", carry_wt, max_wt ); // Set the color based on carry weight nc_color weight_color = c_green; // Default color - if (max_wt > 0) { - if (carry_wt > max_wt) { + if( max_wt > 0 ) { + if( carry_wt > max_wt ) { weight_color = c_red; // Exceeds capacity - } - else if (carry_wt > 0.75 * max_wt) { + } else if( carry_wt > 0.75 * max_wt ) { weight_color = c_light_red; // Approaching capacity (75%) - } - else if (carry_wt > 0.5 * max_wt) { + } else if( carry_wt > 0.5 * max_wt ) { weight_color = c_yellow; // At half capacity (50%) - } - else if (carry_wt > 0.25 * max_wt) { + } else if( carry_wt > 0.25 * max_wt ) { weight_color = c_light_green; // Below half capacity (25%) - } - else { + } else { weight_color = c_green; // Light load } } - return std::make_pair(weight_text, weight_color); + return std::make_pair( weight_text, weight_color ); } std::pair display::overmap_note_symbol_color( const std::string_view diff --git a/src/display.h b/src/display.h index b2aa708de5015..b1091db8e4184 100644 --- a/src/display.h +++ b/src/display.h @@ -182,9 +182,9 @@ nc_color limb_color( const Character &u, const bodypart_id &bp, bool bleed, bool nc_color encumb_color( int level ); // Weight carried, formatted as "current/max" in kg -std::pair carry_weight_kgs_color(const avatar& ava); +std::pair carry_weight_kgs_color( const avatar &ava ); // Weight carried, formatted as "current/max" in lb -std::pair carry_weight_lbs_color(const avatar& ava); +std::pair carry_weight_lbs_color( const avatar &ava ); // Colorized symbol for the overmap tile at the given location std::pair overmap_tile_symbol_color( const avatar &u, diff --git a/src/widget.cpp b/src/widget.cpp index 55a63e5b24606..73cf8c357307f 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1150,7 +1150,7 @@ std::string widget::color_text_function_string( const avatar &ava, unsigned int desc = display::carry_weight_kgs_color( ava ); break; case widget_var::carry_weight_lbs: - desc = display::carry_weight_lbs_color(ava); + desc = display::carry_weight_lbs_color( ava ); break; case widget_var::date_text: desc.first = display::date_string(); From 21a47e6293f5f16a7ce903b7251fbb5aeafc182c Mon Sep 17 00:00:00 2001 From: AudBobb Date: Mon, 21 Oct 2024 15:37:30 -0500 Subject: [PATCH 3/9] Remove imperial version of the feature, and modify the metric version to read users mass setting and adjust the display accordingly --- data/json/ui/sidebar-legacy-labels.json | 28 +++------------- src/display.cpp | 43 ++++++------------------- src/display.h | 6 ++-- src/widget.cpp | 15 +++------ src/widget.h | 3 +- 5 files changed, 22 insertions(+), 73 deletions(-) diff --git a/data/json/ui/sidebar-legacy-labels.json b/data/json/ui/sidebar-legacy-labels.json index 4053fcabcbaa9..1632e18e8e996 100644 --- a/data/json/ui/sidebar-legacy-labels.json +++ b/data/json/ui/sidebar-legacy-labels.json @@ -183,37 +183,20 @@ "type": "widget" }, { - "id": "ll_carry_weight_kgs", + "id": "ll_carry_weight_value", "width": 12, "style": "text", "text_align": "left", - "var": "carry_weight_kgs", + "var": "carry_weight_value", "type": "widget" }, { - "id": "ll_weight_carried_kgs", + "id": "ll_weight_carried_value", "width": 13, "style": "layout", "label": "Weight Carried (kg)", "arrange": "minimum_columns", - "widgets": [ "ll_carry_weight_label", "ll_carry_weight_kgs" ], - "type": "widget" - }, - { - "id": "ll_carry_weight_lbs", - "width": 12, - "style": "text", - "text_align": "left", - "var": "carry_weight_lbs", - "type": "widget" - }, - { - "id": "ll_weight_carried_lbs", - "width": 13, - "style": "layout", - "label": "Weight Carried (lb)", - "arrange": "minimum_columns", - "widgets": [ "ll_carry_weight_label", "ll_carry_weight_lbs" ], + "widgets": [ "ll_carry_weight_label", "ll_carry_weight_value" ], "type": "widget" }, { @@ -237,8 +220,7 @@ "weapon_style_layout", "vehicle_acf_label_layout", "compass_all_danger_layout", - "ll_weight_carried_kgs", - "ll_weight_carried_lbs", + "ll_weight_carried_value", "rad_badge_desc", "sundial_label_layout" ] diff --git a/src/display.cpp b/src/display.cpp index 86b9f159282e5..fc44beb36b279 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1013,44 +1013,19 @@ std::pair display::carry_weight_text_color( const avatar } // Weight carried, formatted as "current/max" in kg -std::pair display::carry_weight_kgs_color( const avatar &ava ) +std::pair display::carry_weight_value_color( const avatar &ava ) { - float carry_wt = ( ava.weight_carried().value() / 1000000.0f ); - float max_wt = ( ava.weight_capacity().value() / 1000000.0f ); - - // Create a string showing "current_weight / max_weight" - //std::string weight_text = string_format("%d", carry_wt); - std::string weight_text = string_format( "%.1f/%.1f kg", carry_wt, max_wt ); - - // Set the color based on carry weight - nc_color weight_color = c_green; // Default color - - if( max_wt > 0 ) { - if( carry_wt > max_wt ) { - weight_color = c_red; // Exceeds capacity - } else if( carry_wt > 0.75 * max_wt ) { - weight_color = c_light_red; // Approaching capacity (75%) - } else if( carry_wt > 0.5 * max_wt ) { - weight_color = c_yellow; // At half capacity (50%) - } else if( carry_wt > 0.25 * max_wt ) { - weight_color = c_light_green; // Below half capacity (25%) - } else { - weight_color = c_green; // Light load - } + float divisor = 1000000.0f; + std::string unit = "kg"; + if (get_option("USE_METRIC_WEIGHTS") == "lbs") { + divisor = 453592.37f; + unit = "lb"; } - - return std::make_pair( weight_text, weight_color ); -} - -// Weight carried, formatted as "current/max" in lbs -std::pair display::carry_weight_lbs_color( const avatar &ava ) -{ - float carry_wt = ( ava.weight_carried().value() / 453592.37f ); - float max_wt = ( ava.weight_capacity().value() / 453592.37f ); + float carry_wt = ( ava.weight_carried().value() / divisor ); + float max_wt = ( ava.weight_capacity().value() / divisor ); // Create a string showing "current_weight / max_weight" - //std::string weight_text = string_format("%d", carry_wt); - std::string weight_text = string_format( "%.1f/%.1f lb", carry_wt, max_wt ); + std::string weight_text = string_format( "%.1f/%.1f" + unit, carry_wt, max_wt); // Set the color based on carry weight nc_color weight_color = c_green; // Default color diff --git a/src/display.h b/src/display.h index b1091db8e4184..dec8b7c3acd06 100644 --- a/src/display.h +++ b/src/display.h @@ -181,10 +181,8 @@ nc_color limb_color( const Character &u, const bodypart_id &bp, bool bleed, bool // Color for displaying the given encumbrance level nc_color encumb_color( int level ); -// Weight carried, formatted as "current/max" in kg -std::pair carry_weight_kgs_color( const avatar &ava ); -// Weight carried, formatted as "current/max" in lb -std::pair carry_weight_lbs_color( const avatar &ava ); +// Weight carried, formatted as "current/max" +std::pair carry_weight_value_color( const avatar &ava ); // Colorized symbol for the overmap tile at the given location std::pair overmap_tile_symbol_color( const avatar &u, diff --git a/src/widget.cpp b/src/widget.cpp index 73cf8c357307f..28dd0cf28acde 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -144,10 +144,8 @@ std::string enum_to_string( widget_var data ) return "bp_armor_outer_text"; case widget_var::carry_weight_text: return "carry_weight_text"; - case widget_var::carry_weight_kgs: - return "carry_weight_kgs"; - case widget_var::carry_weight_lbs: - return "carry_weight_lbs"; + case widget_var::carry_weight_value: + return "carry_weight_value"; case widget_var::date_text: return "date_text"; case widget_var::env_temp_text: @@ -1041,8 +1039,7 @@ bool widget::uses_text_function() const case widget_var::body_graph_wet: case widget_var::bp_armor_outer_text: case widget_var::carry_weight_text: - case widget_var::carry_weight_kgs: - case widget_var::carry_weight_lbs: + case widget_var::carry_weight_value: case widget_var::compass_text: case widget_var::compass_legend_text: case widget_var::date_text: @@ -1146,11 +1143,9 @@ std::string widget::color_text_function_string( const avatar &ava, unsigned int case widget_var::carry_weight_text: desc = display::carry_weight_text_color( ava ); break; - case widget_var::carry_weight_kgs: - desc = display::carry_weight_kgs_color( ava ); + case widget_var::carry_weight_value: + desc = display::carry_weight_value_color( ava ); break; - case widget_var::carry_weight_lbs: - desc = display::carry_weight_lbs_color( ava ); break; case widget_var::date_text: desc.first = display::date_string(); diff --git a/src/widget.h b/src/widget.h index ce436c08325f1..39672c2c3b3c9 100644 --- a/src/widget.h +++ b/src/widget.h @@ -54,8 +54,7 @@ enum class widget_var : int { body_graph_wet, // Body graph showing color-coded body part wetness bp_armor_outer_text, // Outermost armor on body part, with color/damage bars carry_weight_text, // Weight carried, relative to capacity, in % - carry_weight_kgs, // Weight carried, formatted as "current/max" in kgs - carry_weight_lbs, // Weight carried, formatted as "current/max" in lbs + carry_weight_value, // Weight carried, formatted as "current/max" compass_text, // Compass / visible threats by cardinal direction compass_legend_text, // Names of visible creatures that appear on the compass date_text, // Current date, in terms of day within season From 95b8bbc7a9f09848feca098dfd4e0b09b6ae28fe Mon Sep 17 00:00:00 2001 From: Zhan Avesna <97810032+AudBobb@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:57:07 -0500 Subject: [PATCH 4/9] Apply suggestions from code review Formatting Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/display.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index fc44beb36b279..e56447ab9bbdc 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1017,7 +1017,7 @@ std::pair display::carry_weight_value_color( const avatar { float divisor = 1000000.0f; std::string unit = "kg"; - if (get_option("USE_METRIC_WEIGHTS") == "lbs") { + if( get_option( "USE_METRIC_WEIGHTS" ) == "lbs" ) { divisor = 453592.37f; unit = "lb"; } @@ -1025,7 +1025,7 @@ std::pair display::carry_weight_value_color( const avatar float max_wt = ( ava.weight_capacity().value() / divisor ); // Create a string showing "current_weight / max_weight" - std::string weight_text = string_format( "%.1f/%.1f" + unit, carry_wt, max_wt); + std::string weight_text = string_format( "%.1f/%.1f" + unit, carry_wt, max_wt ); // Set the color based on carry weight nc_color weight_color = c_green; // Default color From 3c1bfbe052ec90dff59e675551383f8069b42e50 Mon Sep 17 00:00:00 2001 From: AudBobb Date: Mon, 21 Oct 2024 16:25:58 -0500 Subject: [PATCH 5/9] Updated per IdleSol suggestion --- src/display.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index fc44beb36b279..40d0628f77164 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1016,16 +1016,16 @@ std::pair display::carry_weight_text_color( const avatar std::pair display::carry_weight_value_color( const avatar &ava ) { float divisor = 1000000.0f; - std::string unit = "kg"; + std::string unit = "kgs"; if (get_option("USE_METRIC_WEIGHTS") == "lbs") { divisor = 453592.37f; - unit = "lb"; + unit = "lbs"; } float carry_wt = ( ava.weight_carried().value() / divisor ); float max_wt = ( ava.weight_capacity().value() / divisor ); // Create a string showing "current_weight / max_weight" - std::string weight_text = string_format( "%.1f/%.1f" + unit, carry_wt, max_wt); + std::string weight_text = string_format( "%.1f/%.1f " + unit, carry_wt, max_wt); // Set the color based on carry weight nc_color weight_color = c_green; // Default color From c3eaf446110f75d67244f2eb244cb418fef094dc Mon Sep 17 00:00:00 2001 From: AudBobb Date: Mon, 21 Oct 2024 16:34:52 -0500 Subject: [PATCH 6/9] I think I forgot to pull before pushing and I don't understand git so I think it ate this space in the merge :( --- src/display.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/display.cpp b/src/display.cpp index 226d4c34a5f21..ab658d6ed5717 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1025,7 +1025,7 @@ std::pair display::carry_weight_value_color( const avatar float max_wt = ( ava.weight_capacity().value() / divisor ); // Create a string showing "current_weight / max_weight" - std::string weight_text = string_format( "%.1f/%.1f" + unit, carry_wt, max_wt ); + std::string weight_text = string_format( "%.1f/%.1f " + unit, carry_wt, max_wt ); // Set the color based on carry weight nc_color weight_color = c_green; // Default color From 90fbf3b4fc9440c4df1eb778d23caa6e344151b0 Mon Sep 17 00:00:00 2001 From: AudBobb Date: Mon, 21 Oct 2024 16:45:50 -0500 Subject: [PATCH 7/9] I'll get it right one day --- src/display.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/display.cpp b/src/display.cpp index ab658d6ed5717..62fc31048a968 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1016,7 +1016,7 @@ std::pair display::carry_weight_text_color( const avatar std::pair display::carry_weight_value_color( const avatar &ava ) { float divisor = 1000000.0f; - std::string unit = "kgs"; + std::string unit = "kg"; if( get_option( "USE_METRIC_WEIGHTS" ) == "lbs" ) { divisor = 453592.37f; unit = "lbs"; From 6efe9227cc761f478c44c4b2cf16fc63b17dbd13 Mon Sep 17 00:00:00 2001 From: AudBobb Date: Fri, 25 Oct 2024 14:04:20 -0500 Subject: [PATCH 8/9] Update to use functions I didn't know existed, removing a few lines of code. --- data/json/ui/sidebar-legacy-labels.json | 2 +- src/display.cpp | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/data/json/ui/sidebar-legacy-labels.json b/data/json/ui/sidebar-legacy-labels.json index 1632e18e8e996..4a81b0a0ec619 100644 --- a/data/json/ui/sidebar-legacy-labels.json +++ b/data/json/ui/sidebar-legacy-labels.json @@ -194,7 +194,7 @@ "id": "ll_weight_carried_value", "width": 13, "style": "layout", - "label": "Weight Carried (kg)", + "label": "Weight Carried", "arrange": "minimum_columns", "widgets": [ "ll_carry_weight_label", "ll_carry_weight_value" ], "type": "widget" diff --git a/src/display.cpp b/src/display.cpp index 8ca4e485eea7f..9d4f90e1968dd 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1015,17 +1015,11 @@ std::pair display::carry_weight_text_color( const avatar // Weight carried, formatted as "current/max" in kg std::pair display::carry_weight_value_color( const avatar &ava ) { - float divisor = 1000000.0f; - std::string unit = "kg"; - if( get_option( "USE_METRIC_WEIGHTS" ) == "lbs" ) { - divisor = 453592.37f; - unit = "lbs"; - } - float carry_wt = ( ava.weight_carried().value() / divisor ); - float max_wt = ( ava.weight_capacity().value() / divisor ); + float carry_wt = ( convert_weight( ava.weight_carried() ) ); + float max_wt = ( convert_weight( ava.weight_capacity() ) ); // Create a string showing "current_weight / max_weight" - std::string weight_text = string_format( "%.1f/%.1f " + unit, carry_wt, max_wt ); + std::string weight_text = string_format( "%.1f/%.1f %s", carry_wt, max_wt, weight_units()); // Set the color based on carry weight nc_color weight_color = c_green; // Default color From 6e7d3c4d556cdab1d680fc892edfbe5810e2b9ad Mon Sep 17 00:00:00 2001 From: Zhan Avesna <97810032+AudBobb@users.noreply.github.com> Date: Fri, 25 Oct 2024 14:34:54 -0500 Subject: [PATCH 9/9] Update src/display.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/display.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/display.cpp b/src/display.cpp index 9d4f90e1968dd..ec0713da1d9d3 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1019,7 +1019,7 @@ std::pair display::carry_weight_value_color( const avatar float max_wt = ( convert_weight( ava.weight_capacity() ) ); // Create a string showing "current_weight / max_weight" - std::string weight_text = string_format( "%.1f/%.1f %s", carry_wt, max_wt, weight_units()); + std::string weight_text = string_format( "%.1f/%.1f %s", carry_wt, max_wt, weight_units() ); // Set the color based on carry weight nc_color weight_color = c_green; // Default color