Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description widgets for pain, thirst, fatigue, weight, hunger and more #50945

Merged
merged 9 commits into from
Aug 28, 2021
76 changes: 76 additions & 0 deletions data/json/ui/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,82 @@
"arrange": "columns",
"widgets": [ "int_num", "per_num" ]
},
{
"id": "pain_desc",
"type": "widget",
"label": "Pain",
"style": "text",
"var": "pain_text",
"//": "Uses display::pain_text_color"
},
{
"id": "thirst_desc",
"type": "widget",
"label": "Thirst",
"style": "text",
"var": "thirst_text",
"//": "Uses display::thirst_text_color"
},
{
"id": "fatigue_desc",
"type": "widget",
"label": "Rest",
"style": "text",
"var": "fatigue_text",
"//": "Uses display::fatigue_text_color"
},
{
"id": "weight_desc",
"type": "widget",
"label": "Weight",
"style": "text",
"var": "weight_text",
"//": "Uses display::weight_text_color"
},
{
"id": "hunger_desc",
"type": "widget",
"label": "Hunger",
"style": "text",
"var": "hunger_text",
"//": "Uses display::hunger_text_color"
},
{
"id": "weariness_desc",
"type": "widget",
"label": "Weariness",
"style": "text",
"var": "weariness_text",
"//": "Uses display::weariness_text_color"
},
{
"id": "wielding_desc",
"type": "widget",
"label": "Wield",
"style": "text",
"var": "wielding_text"
},
{
"id": "style_desc",
"type": "widget",
"label": "Style",
"style": "text",
"var": "style_text"
},
{
"id": "date_desc",
"type": "widget",
"label": "Date",
"style": "text",
"var": "date_text"
},
{
"id": "place_desc",
"type": "widget",
"label": "Place",
"style": "text",
"var": "place_text"
},
{
"id": "root_layout_wide",
"type": "widget",
Expand Down
6 changes: 3 additions & 3 deletions data/mods/TEST_DATA/widgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@
"widgets": [ "test_str_num", "test_dex_num", "test_int_num", "test_per_num" ]
},
{
"id": "test_phrase_widget",
"id": "test_text_widget",
"type": "widget",
"label": "PHRASE",
"style": "phrase",
"style": "text",
"strings": [ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" ]
},
{
"id": "test_layout_list",
"type": "widget",
"style": "layout",
"widgets": [ "test_phrase_widget", "test_pool_graph", "test_number_widget" ]
"widgets": [ "test_text_widget", "test_pool_graph", "test_number_widget" ]
}
]
16 changes: 15 additions & 1 deletion doc/SIDEBAR_MOD.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,24 @@ Widgets have the following "style" options:

- `number`: Display value as a plain integer number
- `graph`: Show a bar graph of the value with colored text characters
- `text`: Show text from a `*_text` variable
- `layout`: Special style; this widget will be a layout container for other widgets

Non-layout widgets must define a "var" field, with the name of a predefined widget variable.


## Widget variables

The "var" field of a widget tells what variable data gives the widget its value. Valid var names
The "var" field of a widget tells what variable data gives the widget its value. Valid var names
are given by the `widget_var` enum defined in `widget.h`. In the widget's `show` method, these var
enums determine which avatar method(s) to get their values from.

Below are a few examples of vars and what they mean. See the `widget_var` list in `widget.h` for the
definitive list of vars.

Many vars are numeric in nature. These may use style "number" or style "graph".
Some examples:

- `bp_hp`: hit points of given "bodypart", like "arm_l" or "torso", scale of 0-max HP
- `bp_encumb`: encumbrance given "bodypart", scale of 0-??
- `bp_warmth`: warmth of given "bodypart", scale of 0-10000
Expand All @@ -69,6 +73,16 @@ definitive list of vars.
- `fatigue`: 0-1000, greater is more fatigued/tired
- `move`, `pain`, `speed`, `mana`: other numeric avatar attributes

Some vars refer to text descriptors. These must use style "text". Examples:

- `pain_text`: "Mild pain", "Distracting pain", "Intense pain", etc.
- `hunger_text`: "Engorged", "Full", "Hungry", "Famished", etc.
- `thirst_text`: "Slaked", "Thirsty", "Dehydrated", etc.
- `wielding_text`: Name of current weapon or wielded item
- `style_text`: Name of current martial arts style
- `weight_text`: "Emaciated", "Normal", "Overweight", etc.
- `date_text`: Current day within season, like "Summer, day 15"

For example, a widget to show the current STR stat would define this "var":

```json
Expand Down
35 changes: 17 additions & 18 deletions src/panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,12 @@ static void draw_limb2( avatar &u, const catacurses::window &w )
wnoutrefresh( w );
}

std::pair<std::string, nc_color> display::weariness_text_color( const Character &u )
{
std::pair<translation, nc_color> trans_color = display::weariness_text_color( u.weariness_level() );
return std::make_pair( trans_color.first.translated(), trans_color.second );
}

std::pair<translation, nc_color> display::weariness_text_color( size_t weariness )
{
static const std::array<std::pair<translation, nc_color>, 6> weary_descriptions { {
Expand Down Expand Up @@ -1286,8 +1292,7 @@ static void draw_stats( avatar &u, const catacurses::window &w )
mvwprintz( w, point( stat < 10 ? 30 : 29, 0 ), stat_clr,
stat < 100 ? std::to_string( stat ) : "99+" );

int weariness = u.weariness_level();
std::pair<translation, nc_color> weary = display::weariness_text_color( weariness );
std::pair<std::string, nc_color> weary = display::weariness_text_color( u );
const float activity = u.instantaneous_activity_level();

nc_color act_color;
Expand All @@ -1305,7 +1310,7 @@ static void draw_stats( avatar &u, const catacurses::window &w )
const int act_start = ( getmaxx( w ) / 2 ) - 1;

mvwprintz( w, point_south, c_light_gray, _( weary_label ) );
mvwprintz( w, point( wlabel_len + 1, 1 ), weary.second, weary.first.translated() );
mvwprintz( w, point( wlabel_len + 1, 1 ), weary.second, weary.first );
mvwprintz( w, point( act_start, 1 ), c_light_gray, _( activity_label ) );
mvwprintz( w, point( act_start + alabel_len + 1, 1 ), act_color,
display::activity_level_str( activity ) );
Expand Down Expand Up @@ -1604,8 +1609,7 @@ static void draw_stat_narrow( avatar &u, const catacurses::window &w )
mvwprintz( w, point( 8, 2 ), pwr_pair.first, "%s", pwr_pair.second );
mvwprintz( w, point( 26, 2 ), safe_color(), g->safe_mode ? _( "On" ) : _( "Off" ) );

int weariness = u.weariness_level();
std::pair<translation, nc_color> weary = display::weariness_text_color( weariness );
std::pair<std::string, nc_color> weary = display::weariness_text_color( u );
const float activity = u.instantaneous_activity_level();

nc_color act_color;
Expand All @@ -1623,7 +1627,7 @@ static void draw_stat_narrow( avatar &u, const catacurses::window &w )
const int act_start = ( getmaxx( w ) / 2 ) - 1;

mvwprintz( w, point( 1, 3 ), c_light_gray, _( weary_label ) );
mvwprintz( w, point( wlabel_len + 2, 3 ), weary.second, weary.first.translated() );
mvwprintz( w, point( wlabel_len + 2, 3 ), weary.second, weary.first );
mvwprintz( w, point( act_start, 3 ), c_light_gray, _( activity_label ) );
mvwprintz( w, point( act_start + alabel_len + 1, 3 ), act_color,
display::activity_level_str( activity ) );
Expand Down Expand Up @@ -1655,8 +1659,7 @@ static void draw_stat_wide( avatar &u, const catacurses::window &w )
mvwprintz( w, point( 38, 0 ), pwr_pair.first, "%s", pwr_pair.second );
mvwprintz( w, point( 38, 1 ), safe_color(), g->safe_mode ? _( "On" ) : _( "Off" ) );

int weariness = u.weariness_level();
std::pair<translation, nc_color> weary = display::weariness_text_color( weariness );
std::pair<std::string, nc_color> weary = display::weariness_text_color( u );
const float activity = u.instantaneous_activity_level();

nc_color act_color;
Expand All @@ -1674,7 +1677,7 @@ static void draw_stat_wide( avatar &u, const catacurses::window &w )
const int act_start = ( getmaxx( w ) / 2 ) - 1;

mvwprintz( w, point( 1, 2 ), c_light_gray, _( weary_label ) );
mvwprintz( w, point( wlabel_len + 2, 2 ), weary.second, weary.first.translated() );
mvwprintz( w, point( wlabel_len + 2, 2 ), weary.second, weary.first );
mvwprintz( w, point( act_start, 2 ), c_light_gray, _( activity_label ) );
mvwprintz( w, point( act_start + alabel_len + 1, 2 ), act_color,
display::activity_level_str( activity ) );
Expand Down Expand Up @@ -2349,8 +2352,7 @@ static void draw_weariness( const avatar &u, const catacurses::window &w )
{
werase( w );

int weariness = u.weariness_level();
std::pair<translation, nc_color> weary = display::weariness_text_color( weariness );
std::pair<std::string, nc_color> weary = display::weariness_text_color( u );
const float activity = u.instantaneous_activity_level();

nc_color act_color;
Expand Down Expand Up @@ -2384,8 +2386,7 @@ static void draw_weariness_narrow( const avatar &u, const catacurses::window &w
{
werase( w );

int weariness = u.weariness_level();
std::pair<translation, nc_color> weary = display::weariness_text_color( weariness );
std::pair<std::string, nc_color> weary = display::weariness_text_color( u );
const float activity = u.instantaneous_activity_level();

nc_color act_color;
Expand Down Expand Up @@ -2419,8 +2420,7 @@ static void draw_weariness_wide( const avatar &u, const catacurses::window &w )
{
werase( w );

int weariness = u.weariness_level();
std::pair<translation, nc_color> weary = display::weariness_text_color( weariness );
std::pair<std::string, nc_color> weary = display::weariness_text_color( u );
const float activity = u.instantaneous_activity_level();

nc_color act_color;
Expand Down Expand Up @@ -2454,8 +2454,7 @@ static void draw_weariness_classic( const avatar &u, const catacurses::window &w
{
werase( w );

int weariness = u.weariness_level();
std::pair<translation, nc_color> weary = display::weariness_text_color( weariness );
std::pair<std::string, nc_color> weary = display::weariness_text_color( u );
const float activity = u.instantaneous_activity_level();

nc_color act_color;
Expand All @@ -2474,7 +2473,7 @@ static void draw_weariness_classic( const avatar &u, const catacurses::window &w
const int act_start = std::floor( getmaxx( w ) / 2 );

mvwprintz( w, point_zero, c_light_gray, _( weary_label ) );
mvwprintz( w, point( wlabel_len + 1, 0 ), weary.second, weary.first.translated() );
mvwprintz( w, point( wlabel_len + 1, 0 ), weary.second, weary.first );
mvwprintz( w, point( act_start, 0 ), c_light_gray, _( activity_label ) );
mvwprintz( w, point( act_start + alabel_len + 1, 0 ), act_color,
display::activity_level_str( activity ) );
Expand Down
1 change: 1 addition & 0 deletions src/panels.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ std::string weight_long_description( const Character &u );

// Functions returning (text, color) pairs
std::pair<translation, nc_color> weariness_text_color( size_t weariness );
std::pair<std::string, nc_color> weariness_text_color( const Character &u );
std::pair<std::string, nc_color> thirst_text_color( const Character &u );
std::pair<std::string, nc_color> hunger_text_color( const Character &u );
std::pair<std::string, nc_color> weight_text_color( const Character &u );
Expand Down
Loading