Skip to content

Commit

Permalink
Add widgets for hitpoint numbers and hidden health
Browse files Browse the repository at this point in the history
- Implement new widget_vars `health` and `health_text`
- Add widget JSON for HP numbers, health numbers/text
  • Loading branch information
wapcaplet committed Dec 28, 2021
1 parent 3b4a722 commit 7bc8224
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 4 deletions.
16 changes: 16 additions & 0 deletions data/json/ui/health.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"id": "health_num",
"type": "widget",
"label": "Health",
"var": "health",
"style": "number"
},
{
"id": "health_text",
"type": "widget",
"label": "Health",
"style": "text",
"var": "health_text"
}
]
78 changes: 74 additions & 4 deletions data/json/ui/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"fill": "bucket",
"colors": [ "c_red", "c_light_red", "c_yellow", "c_light_green", "c_green" ]
},
{
"id": "hitpoint_num",
"type": "widget",
"style": "number",
"colors": [ "c_red", "c_light_red", "c_yellow", "c_light_green", "c_green" ]
},
{
"id": "encumbrance_graph",
"type": "widget",
Expand Down Expand Up @@ -88,6 +94,54 @@
"bodypart": "leg_r",
"copy-from": "hitpoint_graph"
},
{
"id": "hp_head_num",
"type": "widget",
"label": "HEAD",
"var": "bp_hp",
"bodypart": "head",
"copy-from": "hitpoint_num"
},
{
"id": "hp_torso_num",
"type": "widget",
"label": "TORSO",
"var": "bp_hp",
"bodypart": "torso",
"copy-from": "hitpoint_num"
},
{
"id": "hp_left_arm_num",
"type": "widget",
"label": "L ARM",
"var": "bp_hp",
"bodypart": "arm_l",
"copy-from": "hitpoint_num"
},
{
"id": "hp_right_arm_num",
"type": "widget",
"label": "R ARM",
"var": "bp_hp",
"bodypart": "arm_r",
"copy-from": "hitpoint_num"
},
{
"id": "hp_left_leg_num",
"type": "widget",
"label": "L LEG",
"var": "bp_hp",
"bodypart": "leg_l",
"copy-from": "hitpoint_num"
},
{
"id": "hp_right_leg_num",
"type": "widget",
"label": "R LEG",
"var": "bp_hp",
"bodypart": "leg_r",
"copy-from": "hitpoint_num"
},
{
"id": "warmth_head_num",
"type": "widget",
Expand Down Expand Up @@ -368,14 +422,14 @@
"style": "number"
},
{
"id": "hitpoints_top_layout",
"id": "hitpoint_graphs_top_layout",
"type": "widget",
"style": "layout",
"arrange": "columns",
"widgets": [ "hp_left_arm_graph", "hp_head_graph", "hp_right_arm_graph" ]
},
{
"id": "hitpoints_bottom_layout",
"id": "hitpoint_graphs_bottom_layout",
"type": "widget",
"style": "layout",
"arrange": "columns",
Expand All @@ -402,6 +456,22 @@
"arrange": "columns",
"widgets": [ "hp_left_leg_graph", "hp_right_leg_graph" ]
},
{
"id": "hitpoint_nums_top_layout",
"type": "widget",
"label": "HP Nums Top",
"style": "layout",
"arrange": "columns",
"widgets": [ "hp_left_arm_num", "hp_head_num", "hp_right_arm_num" ]
},
{
"id": "hitpoint_nums_bottom_layout",
"type": "widget",
"label": "HP Nums Bottom",
"style": "layout",
"arrange": "columns",
"widgets": [ "hp_left_leg_num", "hp_torso_num", "hp_right_leg_num" ]
},
{
"id": "encumbrance_top_layout",
"type": "widget",
Expand Down Expand Up @@ -693,8 +763,8 @@
"style": "layout",
"arrange": "rows",
"widgets": [
"hitpoints_top_layout",
"hitpoints_bottom_layout",
"hitpoint_graphs_top_layout",
"hitpoint_graphs_bottom_layout",
"sound_fatigue_focus_layout",
"stamina_speed_move_layout",
"stats_layout"
Expand Down
31 changes: 31 additions & 0 deletions src/panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,37 @@ std::pair<std::string, nc_color> display::fatigue_text_color( const Character &u
return std::make_pair( _( fatigue_string ), fatigue_color );
}

std::pair<std::string, nc_color> display::health_text_color( const Character &u )
{
std::string h_string;
nc_color h_color = c_light_gray;

int current_health = u.get_healthy();
if( current_health < -100 ) {
h_string = "Horrible";
h_color = c_red;
} else if( current_health < -50 ) {
h_string = "Very bad";
h_color = c_light_red;
} else if( current_health < -10 ) {
h_string = "Bad";
h_color = c_yellow;
} else if( current_health < 10 ) {
h_string = "OK";
h_color = c_light_gray;
} else if( current_health < 50 ) {
h_string = "Good";
h_color = c_white;
} else if( current_health < 100 ) {
h_string = "Very good";
h_color = c_green;
} else {
h_string = "Excellent";
h_color = c_light_green;
}
return std::make_pair( _( h_string ), h_color );
}

std::pair<std::string, nc_color> display::pain_text_color( const Creature &c )
{
float scale = c.get_perceived_pain() / 10.f;
Expand Down
1 change: 1 addition & 0 deletions src/panels.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ 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 );
std::pair<std::string, nc_color> fatigue_text_color( const Character &u );
std::pair<std::string, nc_color> health_text_color( const Character &u );
std::pair<std::string, nc_color> pain_text_color( const Creature &c );
std::pair<std::string, nc_color> pain_text_color( const Character &u );
// Change in character body temperature, as colorized arrows
Expand Down
11 changes: 11 additions & 0 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ std::string enum_to_string<widget_var>( widget_var data )
return "thirst";
case widget_var::fatigue:
return "fatigue";
case widget_var::health:
return "health";
case widget_var::weariness_level:
return "weariness_level";
case widget_var::mana:
Expand Down Expand Up @@ -102,6 +104,8 @@ std::string enum_to_string<widget_var>( widget_var data )
return "env_temp_text";
case widget_var::fatigue_text:
return "fatigue_text";
case widget_var::health_text:
return "health_text";
case widget_var::hunger_text:
return "hunger_text";
case widget_var::lighting_text:
Expand Down Expand Up @@ -261,6 +265,9 @@ int widget::get_var_value( const avatar &ava )
case widget_var::fatigue:
value = ava.get_fatigue();
break;
case widget_var::health:
value = ava.get_healthy();
break;
case widget_var::weariness_level:
value = ava.weariness_level();
break;
Expand Down Expand Up @@ -328,6 +335,7 @@ bool widget::uses_text_function()
case widget_var::date_text:
case widget_var::env_temp_text:
case widget_var::fatigue_text:
case widget_var::health_text:
case widget_var::hunger_text:
case widget_var::lighting_text:
case widget_var::mood_text:
Expand Down Expand Up @@ -372,6 +380,9 @@ std::string widget::color_text_function_string( const avatar &ava )
case widget_var::fatigue_text:
desc = display::fatigue_text_color( ava );
break;
case widget_var::health_text:
desc = display::health_text_color( ava );
break;
case widget_var::hunger_text:
desc = display::hunger_text_color( ava );
break;
Expand Down
2 changes: 2 additions & 0 deletions src/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum class widget_var : int {
speed, // Current speed, integer
stamina, // Current stamina 0-10000, greater being fuller stamina reserves
fatigue, // Current fatigue, integer
health, // Current hidden health value, -200 to +200
mana, // Current available mana, integer
morale_level, // Current morale level, integer (may be negative)
weariness_level, // Current weariness level, integer
Expand All @@ -45,6 +46,7 @@ enum class widget_var : int {
date_text, // Current date, in terms of day within season
env_temp_text, // Environment temperature, if character has thermometer
fatigue_text, // Fagitue description text, color string
health_text, // Hidden health message, color string
hunger_text, // Hunger description text, color string
lighting_text, // Current light level, color string
mood_text, // Mood as a text emote, color string
Expand Down

0 comments on commit 7bc8224

Please sign in to comment.