Skip to content

Commit

Permalink
Add a new widget to display weight with the format "##.#/##.#[unit]" (#…
Browse files Browse the repository at this point in the history
…77212)

* Add two new widgets to display weight with the format "##.#/##.# kg" and "##.#/##.# lb", and add the widgets to the legacy labels sidebar

* Apply suggestions from code review

I don't format goodly

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Remove imperial version of the feature, and modify the metric version to read users mass setting and adjust the display accordingly

* Apply suggestions from code review

Formatting

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Updated per IdleSol suggestion

* I think I forgot to pull before pushing and I don't understand git so I think it ate this space in the merge :(

* I'll get it right one day

* Update to use functions I didn't know existed, removing a few lines of code.

* Update src/display.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
AudBobb and github-actions[bot] authored Oct 26, 2024
1 parent 2633215 commit 0425f0e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
27 changes: 27 additions & 0 deletions data/json/ui/sidebar-legacy-labels.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,32 @@
"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_value",
"width": 12,
"style": "text",
"text_align": "left",
"var": "carry_weight_value",
"type": "widget"
},
{
"id": "ll_weight_carried_value",
"width": 13,
"style": "layout",
"label": "Weight Carried",
"arrange": "minimum_columns",
"widgets": [ "ll_carry_weight_label", "ll_carry_weight_value" ],
"type": "widget"
},
{
"id": "legacy_labels_sidebar",
"type": "widget",
Expand All @@ -194,6 +220,7 @@
"weapon_style_layout",
"vehicle_acf_label_layout",
"compass_all_danger_layout",
"ll_weight_carried_value",
"rad_badge_desc",
"sundial_label_layout"
]
Expand Down
29 changes: 29 additions & 0 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,35 @@ std::pair<std::string, nc_color> 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<std::string, nc_color> display::carry_weight_value_color( const avatar &ava )
{
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 %s", carry_wt, max_wt, weight_units() );

// 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<std::string, nc_color> display::overmap_note_symbol_color( const std::string_view
note_text )
{
Expand Down
3 changes: 3 additions & 0 deletions src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ 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"
std::pair<std::string, nc_color> carry_weight_value_color( const avatar &ava );

// Colorized symbol for the overmap tile at the given location
std::pair<std::string, nc_color> overmap_tile_symbol_color( const avatar &u,
const tripoint_abs_omt &omt, bool edge_tile, bool &found_mi );
Expand Down
7 changes: 7 additions & 0 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ std::string enum_to_string<widget_var>( widget_var data )
return "bp_armor_outer_text";
case widget_var::carry_weight_text:
return "carry_weight_text";
case widget_var::carry_weight_value:
return "carry_weight_value";
case widget_var::date_text:
return "date_text";
case widget_var::env_temp_text:
Expand Down Expand Up @@ -1046,6 +1048,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_value:
case widget_var::compass_text:
case widget_var::compass_legend_text:
case widget_var::date_text:
Expand Down Expand Up @@ -1149,6 +1152,10 @@ 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_value:
desc = display::carry_weight_value_color( ava );
break;
break;
case widget_var::date_text:
desc.first = display::date_string();
break;
Expand Down
1 change: 1 addition & 0 deletions src/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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_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
Expand Down

0 comments on commit 0425f0e

Please sign in to comment.