#include #include #include #include #include #include #include #include #include #include #include #include "activity_tracker.h" #include "avatar.h" #include "bodypart.h" #include "calendar.h" #include "cata_catch.h" #include "cata_scope_helpers.h" #include "cata_utility.h" #include "character_attire.h" #include "coordinates.h" #include "display.h" #include "effect.h" #include "game.h" #include "game_constants.h" #include "item.h" #include "magic.h" #include "map.h" #include "map_helpers.h" #include "map_helpers_tests.h" #include "mission.h" #include "monster.h" #include "options_helpers.h" #include "overmap.h" #include "overmap_ui.h" #include "overmapbuffer.h" #include "pimpl.h" #include "player_helpers.h" #include "point.h" #include "string_formatter.h" #include "translation.h" #include "type_id.h" #include "units.h" #include "weather.h" #include "weather_type.h" #include "widget.h" // Needed for screen scraping #if defined(TILES) #include #include "cursesdef.h" #include "cursesport.h" #endif static const efftype_id effect_bandaged( "bandaged" ); static const efftype_id effect_bite( "bite" ); static const efftype_id effect_bleed( "bleed" ); static const efftype_id effect_disinfected( "disinfected" ); static const efftype_id effect_hunger_blank( "hunger_blank" ); static const efftype_id effect_hunger_engorged( "hunger_engorged" ); static const efftype_id effect_hunger_famished( "hunger_famished" ); static const efftype_id effect_hunger_full( "hunger_full" ); static const efftype_id effect_hunger_hungry( "hunger_hungry" ); static const efftype_id effect_hunger_near_starving( "hunger_near_starving" ); static const efftype_id effect_hunger_satisfied( "hunger_satisfied" ); static const efftype_id effect_hunger_starving( "hunger_starving" ); static const efftype_id effect_hunger_very_hungry( "hunger_very_hungry" ); static const efftype_id effect_infected( "infected" ); static const flag_id json_flag_SPLINT( "SPLINT" ); const static flag_id json_flag_W_DISABLED_WHEN_EMPTY( "W_DISABLED_WHEN_EMPTY" ); static const itype_id itype_arm_splint( "arm_splint" ); static const itype_id itype_blindfold( "blindfold" ); static const itype_id itype_ear_plugs( "ear_plugs" ); static const itype_id itype_rad_badge( "rad_badge" ); static const itype_id itype_sneakers( "sneakers" ); static const itype_id itype_swim_fins( "swim_fins" ); static const itype_id itype_test_hazmat_suit( "test_hazmat_suit" ); static const itype_id itype_test_socks( "test_socks" ); static const itype_id itype_test_zentai( "test_zentai" ); static const morale_type morale_food_good( "morale_food_good" ); static const morale_type morale_killed_innocent( "morale_killed_innocent" ); static const move_mode_id move_mode_crouch( "crouch" ); static const move_mode_id move_mode_prone( "prone" ); static const move_mode_id move_mode_run( "run" ); static const move_mode_id move_mode_walk( "walk" ); static const trait_id trait_GOODHEARING( "GOODHEARING" ); static const trait_id trait_NIGHTVISION( "NIGHTVISION" ); static const trait_id trait_NIGHTVISION2( "NIGHTVISION2" ); static const trait_id trait_NIGHTVISION3( "NIGHTVISION3" ); static const weather_type_id weather_clear( "clear" ); static const weather_type_id weather_cloudy( "cloudy" ); static const weather_type_id weather_drizzle( "drizzle" ); static const weather_type_id weather_fog( "fog" ); static const weather_type_id weather_lightning( "lightning" ); static const weather_type_id weather_portal_storm( "portal_storm" ); static const weather_type_id weather_snowing( "snowing" ); static const weather_type_id weather_sunny( "sunny" ); // test widgets defined in data/json/sidebar.json and data/mods/TEST_DATA/widgets.json static const widget_id widget_test_2_column_layout( "test_2_column_layout" ); static const widget_id widget_test_3_column_layout( "test_3_column_layout" ); static const widget_id widget_test_4_column_layout( "test_4_column_layout" ); static const widget_id widget_test_activity_clauses( "test_activity_clauses" ); static const widget_id widget_test_body_temp_clause( "test_body_temp_clause" ); static const widget_id widget_test_body_temp_delta_sym( "test_body_temp_delta_sym" ); static const widget_id widget_test_body_temp_delta_text( "test_body_temp_delta_text" ); static const widget_id widget_test_bp_wetness_head_num( "test_bp_wetness_head_num" ); static const widget_id widget_test_bp_wetness_torso_num( "test_bp_wetness_torso_num" ); static const widget_id widget_test_bucket_graph( "test_bucket_graph" ); static const widget_id widget_test_clause_legend( "test_clause_legend" ); static const widget_id widget_test_clause_number( "test_clause_number" ); static const widget_id widget_test_clause_sym( "test_clause_sym" ); static const widget_id widget_test_clause_text( "test_clause_text" ); static const widget_id widget_test_color_graph_10k_widget( "test_color_graph_10k_widget" ); static const widget_id widget_test_color_graph_widget( "test_color_graph_widget" ); static const widget_id widget_test_color_number_widget( "test_color_number_widget" ); static const widget_id widget_test_compass_N( "test_compass_N" ); static const widget_id widget_test_compass_N_nodir_nowidth( "test_compass_N_nodir_nowidth" ); static const widget_id widget_test_compass_N_nowidth( "test_compass_N_nowidth" ); static const widget_id widget_test_compass_legend_1( "test_compass_legend_1" ); static const widget_id widget_test_compass_legend_3( "test_compass_legend_3" ); static const widget_id widget_test_compass_legend_5( "test_compass_legend_5" ); static const widget_id widget_test_custom_var_dynamic_range( "test_custom_var_dynamic_range" ); static const widget_id widget_test_custom_var_static_range( "test_custom_var_static_range" ); static const widget_id widget_test_dex_color_num( "test_dex_color_num" ); static const widget_id widget_test_disabled_when_empty( "test_disabled_when_empty" ); static const widget_id widget_test_focus_num( "test_focus_num" ); static const widget_id widget_test_health_clause( "test_health_clause" ); static const widget_id widget_test_health_color_num( "test_health_color_num" ); static const widget_id widget_test_hp_head_graph( "test_hp_head_graph" ); static const widget_id widget_test_hp_head_num( "test_hp_head_num" ); static const widget_id widget_test_hunger_clause( "test_hunger_clause" ); static const widget_id widget_test_int_color_num( "test_int_color_num" ); static const widget_id widget_test_layout_cols_in_cols( "test_layout_cols_in_cols" ); static const widget_id widget_test_layout_nopad( "test_layout_nopad" ); static const widget_id widget_test_layout_nopad_noflag( "test_layout_nopad_noflag" ); static const widget_id widget_test_layout_rows_in_columns( "test_layout_rows_in_columns" ); static const widget_id widget_test_lighting_clause( "test_lighting_clause" ); static const widget_id widget_test_mana_num( "test_mana_num" ); static const widget_id widget_test_moon_phase_clause( "test_moon_phase_clause" ); static const widget_id widget_test_morale_num( "test_morale_num" ); static const widget_id widget_test_move_cost_num( "test_move_cost_num" ); static const widget_id widget_test_move_count_mode_text( "test_move_count_mode_text" ); static const widget_id widget_test_move_mode_letter( "test_move_mode_letter" ); static const widget_id widget_test_move_mode_text( "test_move_mode_text" ); static const widget_id widget_test_move_num( "test_move_num" ); static const widget_id widget_test_overmap_3x3_text( "test_overmap_3x3_text" ); static const widget_id widget_test_per_color_num( "test_per_color_num" ); static const widget_id widget_test_pool_graph( "test_pool_graph" ); static const widget_id widget_test_rad_badge_text( "test_rad_badge_text" ); static const widget_id widget_test_sleepiness_clause( "test_sleepiness_clause" ); static const widget_id widget_test_speed_num( "test_speed_num" ); static const widget_id widget_test_stamina_graph( "test_stamina_graph" ); static const widget_id widget_test_stamina_num( "test_stamina_num" ); static const widget_id widget_test_stat_panel( "test_stat_panel" ); static const widget_id widget_test_status_left_arm_text( "test_status_left_arm_text" ); static const widget_id widget_test_status_legend_text( "test_status_legend_text" ); static const widget_id widget_test_status_sym_left_arm_text( "test_status_sym_left_arm_text" ); static const widget_id widget_test_status_sym_torso_text( "test_status_sym_torso_text" ); static const widget_id widget_test_status_torso_text( "test_status_torso_text" ); static const widget_id widget_test_str_color_num( "test_str_color_num" ); static const widget_id widget_test_sundial_text( "test_sundial_text" ); static const widget_id widget_test_text_widget( "test_text_widget" ); static const widget_id widget_test_thirst_clause( "test_thirst_clause" ); static const widget_id widget_test_torso_armor_outer_text( "test_torso_armor_outer_text" ); static const widget_id widget_test_weariness_num( "test_weariness_num" ); static const widget_id widget_test_weather_text( "test_weather_text" ); static const widget_id widget_test_weather_text_height5( "test_weather_text_height5" ); static const widget_id widget_test_weight_clauses_fun( "test_weight_clauses_fun" ); static const widget_id widget_test_weight_clauses_normal( "test_weight_clauses_normal" ); // dseguin 2022 - Ugly hack to scrape content from the window object. // Scrapes the window w at origin, reading the number of cols and rows. #if defined(TILES) static std::vector scrape_win_at( catacurses::window &w, const point &origin, int cols, int rows ) { std::vector lines; cata_cursesport::WINDOW *win = static_cast( w.get() ); for( int i = origin.y; i < rows && static_cast( i ) < win->line.size(); i++ ) { lines.emplace_back( ); for( int j = origin.x; j < cols && static_cast( j ) < win->line[i].chars.size(); j++ ) { lines[i] += win->line[i].chars[j].ch; } } // For curses builds, this would need something like this instead (including "curses.h"): // ::WINDOW *win = static_cast<::WINDOW *>( w.get() ); // // int max_y = catacurses::getmaxy( w ); // for( int i = origin.y; i < rows && i < max_y; i++ ) { // wchar_t *buf = static_cast( ::malloc( sizeof( *buf ) * ( cols + 1 ) ) ); // ::mvwinnwstr( win, i, origin.x, buf, cols ); // std::wstring line( buf, static_cast( cols ), std::allocator() ); // lines.emplace_back( std::string( line.begin(), line.end() ) ); // ::free( buf ); // } return lines; } #endif TEST_CASE( "widget_value_strings", "[widget][value][string]" ) { SECTION( "numeric values" ) { widget focus = widget_test_focus_num.obj(); REQUIRE( focus._style == "number" ); CHECK( focus.value_string( 0 ) == "0" ); CHECK( focus.value_string( 50 ) == "50" ); CHECK( focus.value_string( 100 ) == "100" ); } SECTION( "graph values with bucket fill" ) { widget head = widget_test_hp_head_graph.obj(); head._var_min = 0; head._var_max = 10; REQUIRE( head._style == "graph" ); REQUIRE( head._fill == "bucket" ); // Buckets of width 5 with 2 nonzero symbols can show 10 values REQUIRE( head._width == 5 ); // Uses comma instead of period to avoid clang-tidy complaining about ellipses REQUIRE( head._symbols == ",\\|" ); // Each integer step cycles the graph symbol by one CHECK( head.value_string( 0 ) == ",,,,," ); CHECK( head.value_string( 1 ) == "\\,,,," ); CHECK( head.value_string( 2 ) == "|,,,," ); CHECK( head.value_string( 3 ) == "|\\,,," ); CHECK( head.value_string( 4 ) == "||,,," ); CHECK( head.value_string( 5 ) == "||\\,," ); CHECK( head.value_string( 6 ) == "|||,," ); CHECK( head.value_string( 7 ) == "|||\\," ); CHECK( head.value_string( 8 ) == "||||," ); CHECK( head.value_string( 9 ) == "||||\\" ); CHECK( head.value_string( 10 ) == "|||||" ); // Above max displayable value, show max CHECK( head.value_string( 11 ) == "|||||" ); CHECK( head.value_string( 12 ) == "|||||" ); // Below minimum, show min CHECK( head.value_string( -1 ) == ",,,,," ); CHECK( head.value_string( -2 ) == ",,,,," ); } SECTION( "graph values with pool fill" ) { widget stamina = widget_test_stamina_graph.obj(); stamina._var_min = 0; stamina._var_max = 20; REQUIRE( stamina._style == "graph" ); REQUIRE( stamina._fill == "pool" ); // Pool of width 20 with 2 nonzero symbols can show 20 values REQUIRE( stamina._width == 10 ); REQUIRE( stamina._symbols == "-=#" ); // Each integer step increases the graph symbol by one CHECK( stamina.value_string( 0 ) == "----------" ); CHECK( stamina.value_string( 1 ) == "=---------" ); CHECK( stamina.value_string( 2 ) == "==--------" ); CHECK( stamina.value_string( 3 ) == "===-------" ); CHECK( stamina.value_string( 4 ) == "====------" ); CHECK( stamina.value_string( 6 ) == "======----" ); CHECK( stamina.value_string( 8 ) == "========--" ); CHECK( stamina.value_string( 10 ) == "==========" ); CHECK( stamina.value_string( 12 ) == "##========" ); CHECK( stamina.value_string( 14 ) == "####======" ); CHECK( stamina.value_string( 16 ) == "######====" ); CHECK( stamina.value_string( 18 ) == "########==" ); CHECK( stamina.value_string( 20 ) == "##########" ); // Above max displayable value, show max CHECK( stamina.value_string( 21 ) == "##########" ); CHECK( stamina.value_string( 22 ) == "##########" ); // Below minimum, show min CHECK( stamina.value_string( -1 ) == "----------" ); CHECK( stamina.value_string( -2 ) == "----------" ); } } TEST_CASE( "text_widgets", "[widget][text]" ) { SECTION( "words Zero-Ten for values 0-10" ) { widget words = widget_test_text_widget.obj(); words._var_min = 0; words._var_max = 10; REQUIRE( words._style == "text" ); CHECK( words.text( false, 0 ) == "Zero" ); } } TEST_CASE( "number_widgets_with_color", "[widget][number][color]" ) { SECTION( "numbers 0-2 with 3 colors" ) { widget colornum = widget_test_color_number_widget.obj(); colornum._var_min = 0; colornum._var_max = 2; REQUIRE( colornum._style == "number" ); REQUIRE( colornum._colors.size() == 3 ); CHECK( colornum.color_value_string( 0 ) == "0" ); CHECK( colornum.color_value_string( 1 ) == "1" ); CHECK( colornum.color_value_string( 2 ) == "2" ); // Beyond var_max, stays at max color CHECK( colornum.color_value_string( 3 ) == "3" ); } } TEST_CASE( "graph_widgets", "[widget][graph]" ) { SECTION( "graph widgets" ) { SECTION( "bucket fill with 12 states" ) { widget wid = widget_test_bucket_graph.obj(); wid._var_min = 0; wid._var_max = 12; REQUIRE( wid._style == "graph" ); REQUIRE( wid._fill == "bucket" ); CHECK( wid.graph( 0 ) == "0000" ); CHECK( wid.graph( 1 ) == "1000" ); CHECK( wid.graph( 2 ) == "2000" ); CHECK( wid.graph( 3 ) == "3000" ); CHECK( wid.graph( 4 ) == "3100" ); CHECK( wid.graph( 5 ) == "3200" ); CHECK( wid.graph( 6 ) == "3300" ); CHECK( wid.graph( 7 ) == "3310" ); CHECK( wid.graph( 8 ) == "3320" ); CHECK( wid.graph( 9 ) == "3330" ); CHECK( wid.graph( 10 ) == "3331" ); CHECK( wid.graph( 11 ) == "3332" ); CHECK( wid.graph( 12 ) == "3333" ); } SECTION( "pool fill with 12 states" ) { widget wid = widget_test_pool_graph.obj(); wid._var_min = 0; wid._var_max = 12; REQUIRE( wid._style == "graph" ); REQUIRE( wid._fill == "pool" ); CHECK( wid.graph( 0 ) == "0000" ); CHECK( wid.graph( 1 ) == "1000" ); CHECK( wid.graph( 2 ) == "1100" ); CHECK( wid.graph( 3 ) == "1110" ); CHECK( wid.graph( 4 ) == "1111" ); CHECK( wid.graph( 5 ) == "2111" ); CHECK( wid.graph( 6 ) == "2211" ); CHECK( wid.graph( 7 ) == "2221" ); CHECK( wid.graph( 8 ) == "2222" ); CHECK( wid.graph( 9 ) == "3222" ); CHECK( wid.graph( 10 ) == "3322" ); CHECK( wid.graph( 11 ) == "3332" ); CHECK( wid.graph( 12 ) == "3333" ); } } SECTION( "graph hit points with 10 states" ) { widget wid = widget_test_hp_head_graph.obj(); wid._var_min = 0; wid._var_max = 10; REQUIRE( wid._fill == "bucket" ); CHECK( wid._label.translated() == "HEAD" ); CHECK( wid.graph( 0 ) == ",,,,," ); CHECK( wid.graph( 1 ) == "\\,,,," ); CHECK( wid.graph( 2 ) == "|,,,," ); CHECK( wid.graph( 3 ) == "|\\,,," ); CHECK( wid.graph( 4 ) == "||,,," ); CHECK( wid.graph( 5 ) == "||\\,," ); CHECK( wid.graph( 6 ) == "|||,," ); CHECK( wid.graph( 7 ) == "|||\\," ); CHECK( wid.graph( 8 ) == "||||," ); CHECK( wid.graph( 9 ) == "||||\\" ); CHECK( wid.graph( 10 ) == "|||||" ); } } TEST_CASE( "graph_widgets_with_color", "[widget][graph][color]" ) { SECTION( "graph widget with 4 colors and 10 states" ) { widget colornum = widget_test_color_graph_widget.obj(); colornum._var_min = 0; colornum._var_max = 10; REQUIRE( colornum._style == "graph" ); REQUIRE( colornum._colors.size() == 4 ); // with +0.5: 2r, 3y, 4lg, 2g CHECK( colornum.color_value_string( 0 ) == "-----" ); CHECK( colornum.color_value_string( 1 ) == "=----" ); CHECK( colornum.color_value_string( 2 ) == "#----" ); CHECK( colornum.color_value_string( 3 ) == "#=---" ); CHECK( colornum.color_value_string( 4 ) == "##---" ); CHECK( colornum.color_value_string( 5 ) == "##=--" ); CHECK( colornum.color_value_string( 6 ) == "###--" ); CHECK( colornum.color_value_string( 7 ) == "###=-" ); CHECK( colornum.color_value_string( 8 ) == "####-" ); CHECK( colornum.color_value_string( 9 ) == "####=" ); CHECK( colornum.color_value_string( 10 ) == "#####" ); // Beyond var_max, stays at max color CHECK( colornum.color_value_string( 11 ) == "#####" ); } SECTION( "graph showing variable range 0-10000 with 5 colors and 20 states" ) { // Long / large var graph widget graph10k = widget_test_color_graph_10k_widget.obj(); graph10k._var_min = 0; graph10k._var_max = 10000; // 2 nonzero symbols x 10 width == 20 possible graph states REQUIRE( graph10k._style == "graph" ); REQUIRE( graph10k._symbols == "-=#" ); REQUIRE( graph10k._width == 10 ); // 10000 values / 20 states == 500 values for each state int tick = 500; // 20 states / 5 colors == 4 states in each color REQUIRE( graph10k._colors.size() == 5 ); // At each tick, the graph should be in a new state CHECK( graph10k.color_value_string( 0 * tick ) == "----------" ); CHECK( graph10k.color_value_string( 1 * tick ) == "=---------" ); CHECK( graph10k.color_value_string( 2 * tick ) == "==--------" ); CHECK( graph10k.color_value_string( 3 * tick ) == "===-------" ); CHECK( graph10k.color_value_string( 4 * tick ) == "====------" ); CHECK( graph10k.color_value_string( 5 * tick ) == "=====-----" ); CHECK( graph10k.color_value_string( 6 * tick ) == "======----" ); CHECK( graph10k.color_value_string( 7 * tick ) == "=======---" ); CHECK( graph10k.color_value_string( 8 * tick ) == "========--" ); CHECK( graph10k.color_value_string( 9 * tick ) == "=========-" ); CHECK( graph10k.color_value_string( 10 * tick ) == "==========" ); CHECK( graph10k.color_value_string( 11 * tick ) == "#=========" ); CHECK( graph10k.color_value_string( 12 * tick ) == "##========" ); CHECK( graph10k.color_value_string( 13 * tick ) == "###=======" ); CHECK( graph10k.color_value_string( 14 * tick ) == "####======" ); CHECK( graph10k.color_value_string( 15 * tick ) == "#####=====" ); CHECK( graph10k.color_value_string( 16 * tick ) == "######====" ); CHECK( graph10k.color_value_string( 17 * tick ) == "#######===" ); CHECK( graph10k.color_value_string( 18 * tick ) == "########==" ); CHECK( graph10k.color_value_string( 19 * tick ) == "#########=" ); CHECK( graph10k.color_value_string( 20 * tick ) == "##########" ); } } TEST_CASE( "widgets_showing_avatar_stats_with_color_for_normal_value", "[widget][stats][color]" ) { widget str_w = widget_test_str_color_num.obj(); widget dex_w = widget_test_dex_color_num.obj(); widget int_w = widget_test_int_color_num.obj(); widget per_w = widget_test_per_color_num.obj(); avatar &ava = get_avatar(); clear_avatar(); SECTION( "base stats str / dex / int / per" ) { ava.set_str_base( 8 ); ava.set_dex_base( 8 ); ava.set_int_base( 8 ); ava.set_per_base( 8 ); CHECK( str_w.layout( ava ) == "STR: 8" ); CHECK( dex_w.layout( ava ) == "DEX: 8" ); CHECK( int_w.layout( ava ) == "INT: 8" ); CHECK( per_w.layout( ava ) == "PER: 8" ); } SECTION( "stats above or below their normal level" ) { // Normal base STR is 8, always shown in white ava.set_str_base( 8 ); CHECK( str_w.layout( ava ) == "STR: 8" ); // Reduced STR, due to pain or something ava.set_str_bonus( -1 ); CHECK( str_w.layout( ava ) == "STR: 7" ); ava.set_str_bonus( -2 ); CHECK( str_w.layout( ava ) == "STR: 6" ); ava.set_str_bonus( -3 ); CHECK( str_w.layout( ava ) == "STR: 5" ); // Increased STR, due to magic or something ava.set_str_bonus( 1 ); CHECK( str_w.layout( ava ) == "STR: 9" ); ava.set_str_bonus( 2 ); CHECK( str_w.layout( ava ) == "STR: 10" ); ava.set_str_bonus( 3 ); CHECK( str_w.layout( ava ) == "STR: 11" ); // STR mod has no effect on other stats CHECK( dex_w.layout( ava ) == "DEX: 8" ); CHECK( int_w.layout( ava ) == "INT: 8" ); CHECK( per_w.layout( ava ) == "PER: 8" ); } } TEST_CASE( "widget_showing_character_sleepiness_status", "[widget]" ) { widget sleepiness_w = widget_test_sleepiness_clause.obj(); avatar &ava = get_avatar(); clear_avatar(); ava.set_sleepiness( 0 ); CHECK( sleepiness_w.layout( ava ) == "Rest: " ); ava.set_sleepiness( 192 ); CHECK( sleepiness_w.layout( ava ) == "Rest: Tired" ); ava.set_sleepiness( 384 ); CHECK( sleepiness_w.layout( ava ) == "Rest: Dead Tired" ); ava.set_sleepiness( 576 ); CHECK( sleepiness_w.layout( ava ) == "Rest: Exhausted" ); } TEST_CASE( "widgets_showing_avatar_health_with_color_for_normal_value", "[widget][health][color]" ) { widget health_w = widget_test_health_color_num.obj(); widget health_clause_w = widget_test_health_clause.obj(); avatar &ava = get_avatar(); clear_avatar(); ava.set_lifestyle( -200 ); CHECK( health_w.layout( ava ) == "Health: -200" ); CHECK( health_clause_w.layout( ava ) == "Health: Horrible" ); ava.set_lifestyle( -99 ); CHECK( health_w.layout( ava ) == "Health: -99" ); CHECK( health_clause_w.layout( ava ) == "Health: Very bad" ); ava.set_lifestyle( -49 ); CHECK( health_w.layout( ava ) == "Health: -49" ); CHECK( health_clause_w.layout( ava ) == "Health: Bad" ); ava.set_lifestyle( 0 ); CHECK( health_w.layout( ava ) == "Health: 0" ); CHECK( health_clause_w.layout( ava ) == "Health: OK" ); ava.set_lifestyle( 49 ); CHECK( health_w.layout( ava ) == "Health: 49" ); CHECK( health_clause_w.layout( ava ) == "Health: Good" ); ava.set_lifestyle( 99 ); CHECK( health_w.layout( ava ) == "Health: 99" ); CHECK( health_clause_w.layout( ava ) == "Health: Very good" ); ava.set_lifestyle( 200 ); CHECK( health_w.layout( ava ) == "Health: 200" ); CHECK( health_clause_w.layout( ava ) == "Health: Excellent" ); } TEST_CASE( "widgets_showing_body_temperature_and_delta", "[widget]" ) { widget w_temp = widget_test_body_temp_clause.obj(); widget w_dtxt = widget_test_body_temp_delta_text.obj(); widget w_dsym = widget_test_body_temp_delta_sym.obj(); avatar &ava = get_avatar(); clear_avatar(); ava.set_all_parts_temp_cur( 27.99_C ); ava.set_all_parts_temp_conv( 37_C ); CHECK( w_temp.layout( ava ) == "Heat: Freezing!" ); CHECK( w_dtxt.layout( ava ) == "Temp change: (Rising!!)" ); CHECK( w_dsym.layout( ava ) == "Temp change: ↑↑↑" ); ava.set_all_parts_temp_cur( 30.99_C ); ava.set_all_parts_temp_conv( 37_C ); CHECK( w_temp.layout( ava ) == "Heat: Very cold!" ); CHECK( w_dtxt.layout( ava ) == "Temp change: (Rising!)" ); CHECK( w_dsym.layout( ava ) == "Temp change: ↑↑" ); ava.set_all_parts_temp_cur( 33.99_C ); ava.set_all_parts_temp_conv( 37_C ); CHECK( w_temp.layout( ava ) == "Heat: Chilly" ); CHECK( w_dtxt.layout( ava ) == "Temp change: (Rising)" ); CHECK( w_dsym.layout( ava ) == "Temp change: ↑" ); ava.set_all_parts_temp_cur( 37_C ); ava.set_all_parts_temp_conv( 37_C ); CHECK( w_temp.layout( ava ) == "Heat: Comfortable" ); CHECK( w_dtxt.layout( ava ) == "Temp change: " ); CHECK( w_dsym.layout( ava ) == "Temp change: -" ); ava.set_all_parts_temp_cur( 40.01_C ); ava.set_all_parts_temp_conv( 37_C ); CHECK( w_temp.layout( ava ) == "Heat: warm" ); CHECK( w_dtxt.layout( ava ) == "Temp change: (Falling)" ); CHECK( w_dsym.layout( ava ) == "Temp change: ↓" ); ava.set_all_parts_temp_cur( 43.01_C ); ava.set_all_parts_temp_conv( 37_C ); CHECK( w_temp.layout( ava ) == "Heat: Very hot!" ); CHECK( w_dtxt.layout( ava ) == "Temp change: (Falling!)" ); CHECK( w_dsym.layout( ava ) == "Temp change: ↓↓" ); ava.set_all_parts_temp_cur( 46.01_C ); ava.set_all_parts_temp_conv( 37_C ); CHECK( w_temp.layout( ava ) == "Heat: Scorching!" ); CHECK( w_dtxt.layout( ava ) == "Temp change: (Falling!!)" ); CHECK( w_dsym.layout( ava ) == "Temp change: ↓↓↓" ); } TEST_CASE( "widgets_showing_avatar_stamina", "[widget][avatar][stamina]" ) { avatar &ava = get_avatar(); clear_avatar(); // Calculate 25%, 50%, 75%, and 100% of maximum stamina const int stamina_max = ava.get_stamina_max(); const int stamina_25 = std::ceil( 0.25 * stamina_max ); const int stamina_50 = std::ceil( 0.5 * stamina_max ); const int stamina_75 = std::ceil( 0.75 * stamina_max ); // Test widgets showing stamina as a number, and as a 10-character graph widget stamina_num_w = widget_test_stamina_num.obj(); widget stamina_graph_w = widget_test_stamina_graph.obj(); // Ensure graph is configured as expected REQUIRE( stamina_graph_w._fill == "pool" ); REQUIRE( stamina_graph_w._symbols == "-=#" ); REQUIRE( stamina_graph_w._width == 10 ); ava.set_stamina( 0 ); CHECK( stamina_num_w.layout( ava ) == "STAMINA: 0" ); CHECK( stamina_graph_w.layout( ava ) == "STAMINA: ----------" ); ava.set_stamina( stamina_25 ); CHECK( stamina_num_w.layout( ava ) == string_format( "STAMINA: %d", stamina_25 ) ); CHECK( stamina_graph_w.layout( ava ) == "STAMINA: =====-----" ); ava.set_stamina( stamina_50 ); CHECK( stamina_num_w.layout( ava ) == string_format( "STAMINA: %d", stamina_50 ) ); CHECK( stamina_graph_w.layout( ava ) == "STAMINA: ==========" ); ava.set_stamina( stamina_75 ); CHECK( stamina_num_w.layout( ava ) == string_format( "STAMINA: %d", stamina_75 ) ); CHECK( stamina_graph_w.layout( ava ) == "STAMINA: #####=====" ); ava.set_stamina( stamina_max ); CHECK( stamina_num_w.layout( ava ) == string_format( "STAMINA: %d", stamina_max ) ); CHECK( stamina_graph_w.layout( ava ) == "STAMINA: ##########" ); } // Set the avatar's stored kcals to reach a given BMI value static void set_avatar_bmi( avatar &ava, float bmi ) { // BMI is split into muscle, fat and other. Other is always 12 and muscle is 1:1 strength stat. // It is normal to have 5 BMIs of fat (this is bordering Normal and Overweight - BMI 25 for an 8 str character) // Normal BMI is now irrelevant for almost everything, as "fat bmis" are what determine your obesity. // Your natural strength trends down to 0 as you starve (below 2 fat BMIs - emaciated/skeletal) meaning you die at BMI 12. // (see char_biometrics_test.cpp for more BMI details) ava.set_stored_kcal( ava.get_healthy_kcal() * ( bmi / 5 ) ); } TEST_CASE( "widgets_showing_avatar_weight", "[widget][weight]" ) { avatar &ava = get_avatar(); clear_avatar(); // Classic weight widget, modeled after the one shown in-game widget weight_clause_w = widget_test_weight_clauses_normal.obj(); set_avatar_bmi( ava, 0.5 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Skeletal" ); set_avatar_bmi( ava, 1.0 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Skeletal" ); set_avatar_bmi( ava, 1.1 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Emaciated" ); set_avatar_bmi( ava, 2.0 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Emaciated" ); set_avatar_bmi( ava, 2.1 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Underweight" ); set_avatar_bmi( ava, 2.9 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Underweight" ); set_avatar_bmi( ava, 3.1 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Normal" ); set_avatar_bmi( ava, 5.0 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Normal" ); set_avatar_bmi( ava, 5.1 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Overweight" ); set_avatar_bmi( ava, 10.0 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Overweight" ); set_avatar_bmi( ava, 10.1 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Obese" ); set_avatar_bmi( ava, 15.0 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Obese" ); set_avatar_bmi( ava, 15.1 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Very Obese" ); set_avatar_bmi( ava, 20.0 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Very Obese" ); set_avatar_bmi( ava, 20.1 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Morbidly Obese" ); set_avatar_bmi( ava, 25.0 ); CHECK( weight_clause_w.layout( ava ) == "Weight: Morbidly Obese" ); // "Fun" version with customized thresholds, text, and color widget weight_clause_fun_w = widget_test_weight_clauses_fun.obj(); set_avatar_bmi( ava, 2.0 ); CHECK( weight_clause_fun_w.layout( ava ) == "Thiccness: Skin and Bones" ); set_avatar_bmi( ava, 3.6 ); CHECK( weight_clause_fun_w.layout( ava ) == "Thiccness: Boring" ); set_avatar_bmi( ava, 10.0 ); CHECK( weight_clause_fun_w.layout( ava ) == "Thiccness: Boring" ); set_avatar_bmi( ava, 20.1 ); CHECK( weight_clause_fun_w.layout( ava ) == "Thiccness: C H O N K" ); } TEST_CASE( "widgets_showing_avatar_attributes", "[widget][avatar]" ) { avatar &ava = get_avatar(); clear_avatar(); SECTION( "speed pool" ) { widget speed_w = widget_test_speed_num.obj(); ava.set_speed_base( 90 ); CHECK( speed_w.layout( ava ) == "SPEED: 90" ); ava.set_speed_base( 240 ); CHECK( speed_w.layout( ava ) == "SPEED: 240" ); } SECTION( "focus pool" ) { widget focus_w = widget_test_focus_num.obj(); ava.set_focus( 75 ); CHECK( focus_w.layout( ava ) == "FOCUS: 75" ); ava.set_focus( 120 ); CHECK( focus_w.layout( ava ) == "FOCUS: 120" ); } SECTION( "mana pool" ) { widget mana_w = widget_test_mana_num.obj(); ava.magic->set_mana( 150 ); CHECK( mana_w.layout( ava ) == "MANA: 150" ); ava.magic->set_mana( 450 ); CHECK( mana_w.layout( ava ) == "MANA: 450" ); } SECTION( "morale" ) { widget morale_w = widget_test_morale_num.obj(); ava.clear_morale(); CHECK( morale_w.layout( ava ) == "MORALE: 0" ); ava.add_morale( morale_food_good, 20 ); CHECK( morale_w.layout( ava ) == "MORALE: 20" ); ava.clear_morale(); ava.add_morale( morale_killed_innocent, -100 ); CHECK( morale_w.layout( ava ) == "MORALE: -100" ); } SECTION( "hit points" ) { bodypart_id head( "head" ); widget head_num_w = widget_test_hp_head_num.obj(); widget head_graph_w = widget_test_hp_head_graph.obj(); REQUIRE( ava.get_part_hp_max( head ) == 55 ); REQUIRE( ava.get_part_hp_cur( head ) == 55 ); ava.set_part_hp_cur( head, 54 ); CHECK( head_num_w.layout( ava ) == "HEAD: 54" ); CHECK( head_graph_w.layout( ava ) == "HEAD: ||||\\" ); ava.set_part_hp_cur( head, 27 ); CHECK( head_num_w.layout( ava ) == "HEAD: 27" ); CHECK( head_graph_w.layout( ava ) == "HEAD: ||,,," ); ava.set_part_hp_cur( head, 11 ); CHECK( head_num_w.layout( ava ) == "HEAD: 11" ); CHECK( head_graph_w.layout( ava ) == "HEAD: |,,,," ); ava.set_part_hp_cur( head, 0 ); CHECK( head_num_w.layout( ava ) == "HEAD: 0" ); // NOLINTNEXTLINE(cata-text-style): suppress "unnecessary space" warning before commas CHECK( head_graph_w.layout( ava ) == "HEAD: ,,,,," ); } SECTION( "weariness" ) { widget weariness_w = widget_test_weariness_num.obj(); CHECK( weariness_w.layout( ava ) == "WEARINESS: 0" ); // TODO: Check weariness set to other levels } SECTION( "wetness" ) { widget head_wetness_w = widget_test_bp_wetness_head_num.obj(); widget torso_wetness_w = widget_test_bp_wetness_torso_num.obj(); CHECK( head_wetness_w.layout( ava ) == "HEAD WET: 0" ); CHECK( torso_wetness_w.layout( ava ) == "TORSO WET: 0" ); ava.drench( 100, { body_part_head, body_part_torso }, false ); CHECK( head_wetness_w.layout( ava ) == "HEAD WET: 200" ); CHECK( torso_wetness_w.layout( ava ) == "TORSO WET: 200" ); } } TEST_CASE( "widgets_showing_activity_level", "[widget][activity]" ) { avatar &ava = get_avatar(); clear_avatar(); widget activity_w = widget_test_activity_clauses.obj(); ava.reset_activity_level(); activity_tracker &tracker = ava.activity_history; tracker.new_turn(); tracker.log_activity( NO_EXERCISE ); CHECK( activity_w.layout( ava ) == "Activity: None" ); tracker.new_turn(); tracker.log_activity( LIGHT_EXERCISE ); CHECK( activity_w.layout( ava ) == "Activity: Light" ); tracker.new_turn(); tracker.log_activity( MODERATE_EXERCISE ); CHECK( activity_w.layout( ava ) == "Activity: Moderate" ); tracker.new_turn(); tracker.log_activity( BRISK_EXERCISE ); CHECK( activity_w.layout( ava ) == "Activity: Brisk" ); tracker.new_turn(); tracker.log_activity( ACTIVE_EXERCISE ); CHECK( activity_w.layout( ava ) == "Activity: Active" ); tracker.new_turn(); tracker.log_activity( EXTRA_EXERCISE ); CHECK( activity_w.layout( ava ) == "Activity: Extreme" ); } TEST_CASE( "widgets_showing_move_counter_and_mode", "[widget][move_mode]" ) { avatar &ava = get_avatar(); clear_avatar(); SECTION( "move counter" ) { widget move_w = widget_test_move_num.obj(); ava.movecounter = 80; CHECK( move_w.layout( ava ) == "MOVE: 80" ); ava.movecounter = 150; CHECK( move_w.layout( ava ) == "MOVE: 150" ); } SECTION( "move counter and mode letter" ) { widget move_count_mode_w = widget_test_move_count_mode_text.obj(); ava.movecounter = 90; ava.set_movement_mode( move_mode_walk ); CHECK( move_count_mode_w.layout( ava ) == "MOVE/MODE: 90(W)" ); ava.set_movement_mode( move_mode_run ); CHECK( move_count_mode_w.layout( ava ) == "MOVE/MODE: 90(R)" ); ava.set_movement_mode( move_mode_crouch ); CHECK( move_count_mode_w.layout( ava ) == "MOVE/MODE: 90(C)" ); ava.set_movement_mode( move_mode_prone ); CHECK( move_count_mode_w.layout( ava ) == "MOVE/MODE: 90(P)" ); } SECTION( "movement mode text and letter" ) { widget mode_letter_w = widget_test_move_mode_letter.obj(); widget mode_text_w = widget_test_move_mode_text.obj(); ava.set_movement_mode( move_mode_walk ); CHECK( mode_letter_w.layout( ava ) == "MODE: W" ); CHECK( mode_text_w.layout( ava ) == "MODE: walking" ); ava.set_movement_mode( move_mode_run ); CHECK( mode_letter_w.layout( ava ) == "MODE: R" ); CHECK( mode_text_w.layout( ava ) == "MODE: running" ); ava.set_movement_mode( move_mode_crouch ); CHECK( mode_letter_w.layout( ava ) == "MODE: C" ); CHECK( mode_text_w.layout( ava ) == "MODE: crouching" ); ava.set_movement_mode( move_mode_prone ); CHECK( mode_letter_w.layout( ava ) == "MODE: P" ); CHECK( mode_text_w.layout( ava ) == "MODE: prone" ); } } TEST_CASE( "thirst_and_hunger_widgets", "[widget]" ) { widget wt = widget_test_thirst_clause.obj(); widget wh = widget_test_hunger_clause.obj(); avatar &ava = get_avatar(); clear_avatar(); ava.clear_effects(); ava.add_effect( effect_hunger_famished, 1_minutes ); ava.set_thirst( -61 ); CHECK( wt.layout( ava ) == "THIRST: Turgid" ); CHECK( wh.layout( ava ) == "HUNGER: Famished" ); ava.clear_effects(); ava.add_effect( effect_hunger_starving, 1_minutes ); ava.set_thirst( -21 ); CHECK( wt.layout( ava ) == "THIRST: Hydrated" ); CHECK( wh.layout( ava ) == "HUNGER: Starving!" ); ava.clear_effects(); ava.add_effect( effect_hunger_near_starving, 1_minutes ); ava.set_thirst( -1 ); CHECK( wt.layout( ava ) == "THIRST: Slaked" ); CHECK( wh.layout( ava ) == "HUNGER: Near starving" ); ava.clear_effects(); ava.add_effect( effect_hunger_very_hungry, 1_minutes ); ava.set_thirst( 0 ); CHECK( wt.layout( ava ) == "THIRST: " ); CHECK( wh.layout( ava ) == "HUNGER: Very hungry" ); ava.clear_effects(); ava.add_effect( effect_hunger_hungry, 1_minutes ); ava.set_thirst( 41 ); CHECK( wt.layout( ava ) == "THIRST: Thirsty" ); CHECK( wh.layout( ava ) == "HUNGER: Hungry" ); ava.clear_effects(); ava.add_effect( effect_hunger_blank, 1_minutes ); ava.set_thirst( 81 ); CHECK( wt.layout( ava ) == "THIRST: Very thirsty" ); CHECK( wh.layout( ava ) == "HUNGER: " ); ava.clear_effects(); ava.add_effect( effect_hunger_satisfied, 1_minutes ); ava.set_thirst( 241 ); CHECK( wt.layout( ava ) == "THIRST: Dehydrated" ); CHECK( wh.layout( ava ) == "HUNGER: Satisfied" ); ava.clear_effects(); ava.add_effect( effect_hunger_full, 1_minutes ); ava.set_thirst( 521 ); CHECK( wt.layout( ava ) == "THIRST: Parched" ); CHECK( wh.layout( ava ) == "HUNGER: Full" ); ava.clear_effects(); ava.add_effect( effect_hunger_engorged, 1_minutes ); CHECK( wt.layout( ava ) == "THIRST: Parched" ); CHECK( wh.layout( ava ) == "HUNGER: Engorged" ); } TEST_CASE( "widgets_showing_movement_cost", "[widget][move_cost]" ) { clear_map(); widget cost_num_w = widget_test_move_cost_num.obj(); avatar &ava = get_avatar(); clear_avatar(); SECTION( "without shoes" ) { REQUIRE_FALSE( ava.is_wearing_shoes() ); // Having no shoes adds +8 per foot to base run cost REQUIRE( ava.run_cost( 100 ) == 116 ); CHECK( cost_num_w.layout( ava ) == "MOVE COST: 116" ); } SECTION( "wearing sneakers" ) { // Sneakers eliminate the no-shoes penalty ava.wear_item( item( itype_sneakers ) ); REQUIRE( ava.is_wearing_shoes() ); REQUIRE( ava.run_cost( 100 ) == 100 ); CHECK( cost_num_w.layout( ava ) == "MOVE COST: 100" ); } SECTION( "wearing swim fins" ) { // Swim fins multiply cost by 1.5 ava.wear_item( item( itype_swim_fins ) ); REQUIRE( ava.is_wearing_shoes() ); REQUIRE( ava.run_cost( 100 ) == 167 ); CHECK( cost_num_w.layout( ava ) == "MOVE COST: 167" ); } } TEST_CASE( "widgets_showing_Sun_and_Moon_position", "[widget]" ) { widget sundial_w = widget_test_sundial_text.obj(); avatar &ava = get_avatar(); clear_map_without_vision(); clear_avatar(); SECTION( "variable widths " ) { scoped_weather_override forcast( weather_clear ); sundial_w._width = 20; set_time( calendar::turn_zero ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); sundial_w._width = 15; CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); sundial_w._width = 9; CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); } SECTION( "time of day" ) { scoped_weather_override forcast( weather_clear ); sundial_w._width = 20; set_time( calendar::turn_zero + 2_hours ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); set_time( calendar::turn_zero + 5_hours ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); set_time( calendar::turn_zero + 5_hours + 10_minutes ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); set_time( calendar::turn_zero + 5_hours + 20_minutes ); // Sky begins to brighten, but no sun CHECK( sundial_w.layout( ava ) == "SKY: [ " " ○ ]" ); set_time( calendar::turn_zero + 5_hours + 45_minutes ); // Rising sun is a red underscore CHECK( sundial_w.layout( ava ) == "SKY: [ _" " ○ ]" ); set_time( calendar::turn_zero + 6_hours ); // Sun has risen and has brightened the whole sky CHECK( sundial_w.layout( ava ) == "SKY: [ ☼" " ○ ]" ); set_time( calendar::turn_zero + 8_hours ); CHECK( sundial_w.layout( ava ) == "SKY: [ ☼" " ○ ]" ); set_time( calendar::turn_zero + 12_hours + 5_minutes ); CHECK( sundial_w.layout( ava ) == "SKY: [ ☼" " ○]" ); set_time( calendar::turn_zero + 12_hours + 10_minutes ); // moon wrapped around the display CHECK( sundial_w.layout( ava ) == "SKY: [○ ☼" " ]" ); set_time( calendar::turn_zero + 58_days + 12_hours ); // White sun when illumination is max CHECK( sundial_w.layout( ava ) == "SKY: [○ ☼ ]" ); set_time( calendar::turn_zero + 16_hours ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ☼" " ]" ); set_time( calendar::turn_zero + 18_hours + 15_minutes ); // sun is still up CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ☼" " ]" ); set_time( calendar::turn_zero + 18_hours + 30_minutes ); // sun is setting and some light is gone CHECK( sundial_w.layout( ava ) == "SKY: [ ○ " "_ ]" ); set_time( calendar::turn_zero + 18_hours + 45_minutes ); // sun is down but still providing light CHECK( sundial_w.layout( ava ) == "SKY: [ ○ " " ]" ); set_time( calendar::turn_zero + 20_hours ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); set_time( calendar::turn_zero + 22_hours ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); set_time( calendar::turn_zero + 24_hours ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); set_time( calendar::turn_zero ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); } SECTION( "phases of the moon" ) { scoped_weather_override forcast( weather_clear ); sundial_w._width = 20; set_time( calendar::turn_zero ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); set_time( calendar::turn_zero + 4_days ); CHECK( sundial_w.layout( ava ) == "SKY: [ ☽ ]" ); set_time( calendar::turn_zero + 8_days ); CHECK( sundial_w.layout( ava ) == "SKY: [ ◑ ]" ); set_time( calendar::turn_zero + 12_days ); CHECK( sundial_w.layout( ava ) == "SKY: [ ◕ " " ]" ); set_time( calendar::turn_zero + 16_days ); CHECK( sundial_w.layout( ava ) == "SKY: [ ● " " ]" ); set_time( calendar::turn_zero + 20_days ); // Waxing and waning gibbous share a symbol, sadly CHECK( sundial_w.layout( ava ) == "SKY: [ ◕ " " ]" ); set_time( calendar::turn_zero + 23_days ); CHECK( sundial_w.layout( ava ) == "SKY: [ ◐ ]" ); set_time( calendar::turn_zero + 27_days ); CHECK( sundial_w.layout( ava ) == "SKY: [ ☾ ]" ); set_time( calendar::turn_zero + 28_days ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ]" ); } SECTION( "weather" ) { sundial_w._width = 20; set_time( calendar::turn_zero + 18_hours + 15_minutes ); // sun is still up SECTION( "sunny" ) { scoped_weather_override forecast( weather_sunny ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ☼" " ]" ); } SECTION( "cloudy" ) { scoped_weather_override forecast( weather_cloudy ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ⛅" " ]" ); } SECTION( "drizzle" ) { scoped_weather_override forecast( weather_drizzle ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ☂" " ]" ); } SECTION( "snowing" ) { scoped_weather_override forecast( weather_snowing ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ☃" " ]" ); } SECTION( "lightning" ) { scoped_weather_override forecast( weather_lightning ); CHECK( sundial_w.layout( ava ) == "SKY: [%%%%%%% " "⛈ ]" ); } SECTION( "fog" ) { scoped_weather_override forecast( weather_fog ); CHECK( sundial_w.layout( ava ) == "SKY: [~~~~~ " "⛆ ]" ); } SECTION( "portal_storm" ) { scoped_weather_override forecast( weather_portal_storm ); CHECK( sundial_w.layout( ava ) == "SKY: [ ○ ✺" " ]" ); } } SECTION( "night vision" ) { scoped_weather_override forcast( weather_clear ); sundial_w._width = 20; set_time( calendar::turn_zero + 8_days ); CHECK( sundial_w.layout( ava ) == "SKY: [ ◑ ]" ); ava.set_mutation( trait_NIGHTVISION ); CHECK( sundial_w.layout( ava ) == "SKY: [ ◑" " ]" ); ava.set_mutation( trait_NIGHTVISION2 ); CHECK( sundial_w.layout( ava ) == "SKY: [ ◑" " ]" ); ava.set_mutation( trait_NIGHTVISION3 ); CHECK( sundial_w.layout( ava ) == "SKY: [ ◑ " " ]" ); clear_avatar(); } SECTION( "not outside" ) { sundial_w._width = 20; set_time( calendar::turn_zero ); clear_map_and_put_player_underground(); CHECK( sundial_w.layout( ava ) == "SKY: [??????????????????]" ); clear_avatar(); } } // Bodypart status strings are pulled from a std::map, which is // not guaranteed to be sorted in a deterministic way. // Just check if the layout string contains the specified status conditions. static void check_bp_has_status( const std::string_view layout, const std::vector &stat_str ) { for( const std::string &stat : stat_str ) { CHECK( layout.find( stat ) != std::string::npos ); } } TEST_CASE( "widget_showing_body_part_status_text", "[widget][bp_status]" ) { avatar &ava = get_avatar(); clear_avatar(); bodypart_id arm( "arm_l" ); bodypart_id torso( "torso" ); widget arm_status_w = widget_test_status_left_arm_text.obj(); widget torso_status_w = widget_test_status_torso_text.obj(); // No ailments CHECK( arm_status_w.layout( ava ) == "LEFT ARM STATUS: --" ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); // Add various ailments and/or treatments to the left arm, and ensure status is displayed // correctly, while torso status display is unaffected WHEN( "bitten" ) { ava.add_effect( effect_bite, 1_minutes, arm ); CHECK( arm_status_w.layout( ava ) == "LEFT ARM STATUS: bitten" ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "bleeding" ) { // low-intensity ava.add_effect( effect_bleed, 1_minutes, arm ); ava.get_effect( effect_bleed, arm ).set_intensity( 5 ); CHECK( arm_status_w.layout( ava ) == "LEFT ARM STATUS: bleeding" ); // medium-intensity ava.get_effect( effect_bleed, arm ).set_intensity( 15 ); CHECK( arm_status_w.layout( ava ) == "LEFT ARM STATUS: bleeding" ); // high-intensity ava.get_effect( effect_bleed, arm ).set_intensity( 25 ); CHECK( arm_status_w.layout( ava ) == "LEFT ARM STATUS: bleeding" ); // torso still fine CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "bandaged" ) { ava.add_effect( effect_bandaged, 1_minutes, arm ); CHECK( arm_status_w.layout( ava ) == "LEFT ARM STATUS: bandaged" ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "broken" ) { ava.set_part_hp_cur( arm, 0 ); REQUIRE( ava.is_limb_broken( arm ) ); CHECK( arm_status_w.layout( ava ) == "LEFT ARM STATUS: broken" ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "broken and splinted" ) { ava.set_part_hp_cur( arm, 0 ); ava.wear_item( item( itype_arm_splint ) ); REQUIRE( ava.is_limb_broken( arm ) ); REQUIRE( ava.worn_with_flag( json_flag_SPLINT, arm ) ); check_bp_has_status( arm_status_w.layout( ava ), { "LEFT ARM STATUS:", "broken", "splinted" } ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "infected" ) { ava.add_effect( effect_infected, 1_minutes, arm ); CHECK( arm_status_w.layout( ava ) == "LEFT ARM STATUS: infected" ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "disinfected" ) { ava.add_effect( effect_disinfected, 1_minutes, arm ); CHECK( arm_status_w.layout( ava ) == "LEFT ARM STATUS: disinfected" ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "bitten and bleeding" ) { ava.add_effect( effect_bite, 1_minutes, arm ); ava.add_effect( effect_bleed, 1_minutes, arm ); check_bp_has_status( arm_status_w.layout( ava ), { "LEFT ARM STATUS:", "bitten", "bleeding" } ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "bitten and infected" ) { ava.add_effect( effect_bite, 1_minutes, arm ); ava.add_effect( effect_infected, 1_minutes, arm ); check_bp_has_status( arm_status_w.layout( ava ), { "LEFT ARM STATUS:", "bitten", "infected" } ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "bleeding and infected" ) { ava.add_effect( effect_bleed, 1_minutes, arm ); ava.add_effect( effect_infected, 1_minutes, arm ); check_bp_has_status( arm_status_w.layout( ava ), { "LEFT ARM STATUS:", "bleeding", "infected" } ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } WHEN( "bitten, bleeding, and infected" ) { ava.add_effect( effect_bite, 1_minutes, arm ); ava.add_effect( effect_bleed, 1_minutes, arm ); ava.add_effect( effect_infected, 1_minutes, arm ); check_bp_has_status( arm_status_w.layout( ava ), { "LEFT ARM STATUS:", "bitten", "bleeding", "infected" } ); CHECK( torso_status_w.layout( ava ) == "TORSO STATUS: --" ); } } TEST_CASE( "compact_bodypart_status_widgets_+_legend", "[widget][bp_status]" ) { const int sidebar_width = 36; avatar &ava = get_avatar(); clear_avatar(); bodypart_id arm( "arm_l" ); bodypart_id torso( "torso" ); widget bp_legend = widget_test_status_legend_text.obj(); widget arm_stat = widget_test_status_sym_left_arm_text.obj(); widget torso_stat = widget_test_status_sym_torso_text.obj(); CHECK( arm_stat.layout( ava, sidebar_width ) == "L ARM: " ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); CHECK( bp_legend.layout( ava, sidebar_width ).empty() ); WHEN( "bitten" ) { ava.add_effect( effect_bite, 1_minutes, arm ); CHECK( arm_stat.layout( ava, sidebar_width ) == "L ARM: B " ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); CHECK( bp_legend.layout( ava, sidebar_width ) == "B bitten " ); } WHEN( "bleeding" ) { // low-intensity ava.add_effect( effect_bleed, 1_minutes, arm ); ava.get_effect( effect_bleed, arm ).set_intensity( 5 ); CHECK( arm_stat.layout( ava, sidebar_width ) == "L ARM: b " ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); CHECK( bp_legend.layout( ava, sidebar_width ) == "b bleeding " ); // medium-intensity ava.get_effect( effect_bleed, arm ).set_intensity( 15 ); CHECK( arm_stat.layout( ava, sidebar_width ) == "L ARM: b " ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); CHECK( bp_legend.layout( ava, sidebar_width ) == "b bleeding " ); // high-intensity ava.get_effect( effect_bleed, arm ).set_intensity( 25 ); CHECK( arm_stat.layout( ava, sidebar_width ) == "L ARM: b " ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); CHECK( bp_legend.layout( ava, sidebar_width ) == "b bleeding " ); } WHEN( "bandaged" ) { ava.add_effect( effect_bandaged, 1_minutes, arm ); CHECK( arm_stat.layout( ava, sidebar_width ) == "L ARM: + " ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); CHECK( bp_legend.layout( ava, sidebar_width ) == "+ bandaged " ); } WHEN( "broken" ) { ava.set_part_hp_cur( arm, 0 ); REQUIRE( ava.is_limb_broken( arm ) ); CHECK( arm_stat.layout( ava, sidebar_width ) == "L ARM: % " ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); CHECK( bp_legend.layout( ava, sidebar_width ) == "% broken " ); } WHEN( "broken and splinted" ) { ava.set_part_hp_cur( arm, 0 ); ava.wear_item( item( itype_arm_splint ) ); REQUIRE( ava.is_limb_broken( arm ) ); REQUIRE( ava.worn_with_flag( json_flag_SPLINT, arm ) ); check_bp_has_status( arm_stat.layout( ava, sidebar_width ), { "L ARM:", "%", "=" } ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); check_bp_has_status( bp_legend.layout( ava, sidebar_width ), { "% broken", "= splinted" } ); } WHEN( "infected" ) { ava.add_effect( effect_infected, 1_minutes, arm ); CHECK( arm_stat.layout( ava, sidebar_width ) == "L ARM: I " ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); CHECK( bp_legend.layout( ava, sidebar_width ) == "I infected " ); } WHEN( "disinfected" ) { ava.add_effect( effect_disinfected, 1_minutes, arm ); CHECK( arm_stat.layout( ava, sidebar_width ) == "L ARM: $ " ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); CHECK( bp_legend.layout( ava, sidebar_width ) == "$ disinfected " ); } WHEN( "bitten and bleeding" ) { ava.add_effect( effect_bite, 1_minutes, arm ); ava.add_effect( effect_bleed, 1_minutes, arm ); check_bp_has_status( arm_stat.layout( ava, sidebar_width ), { "L ARM:", "B", "b" } ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); check_bp_has_status( bp_legend.layout( ava, sidebar_width ), { "B bitten", "b bleeding" } ); } WHEN( "bitten and infected" ) { ava.add_effect( effect_bite, 1_minutes, arm ); ava.add_effect( effect_infected, 1_minutes, arm ); check_bp_has_status( arm_stat.layout( ava, sidebar_width ), { "L ARM:", "B", "I" } ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); check_bp_has_status( bp_legend.layout( ava, sidebar_width ), { "B bitten", "I infected" } ); } WHEN( "bleeding and infected" ) { ava.add_effect( effect_bleed, 1_minutes, arm ); ava.add_effect( effect_infected, 1_minutes, arm ); check_bp_has_status( arm_stat.layout( ava, sidebar_width ), { "L ARM:", "I", "b" } ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); check_bp_has_status( bp_legend.layout( ava, sidebar_width ), { "I infected", "b bleeding" } ); } WHEN( "bitten, bleeding, and infected" ) { ava.add_effect( effect_bite, 1_minutes, arm ); ava.add_effect( effect_bleed, 1_minutes, arm ); ava.add_effect( effect_infected, 1_minutes, arm ); check_bp_has_status( arm_stat.layout( ava, sidebar_width ), { "L ARM:", "B", "I", "b" } ); CHECK( torso_stat.layout( ava, sidebar_width ) == "TORSO: " ); check_bp_has_status( bp_legend.layout( ava, sidebar_width ), { "B bitten", "I infected", "b bleeding" } ); } } TEST_CASE( "outer_armor_widget", "[widget][armor]" ) { widget torso_armor_w = widget_test_torso_armor_outer_text.obj(); avatar &ava = get_avatar(); clear_avatar(); // Empty when no armor is worn CHECK( torso_armor_w.layout( ava ) == "Torso Armor: -" ); // Wearing something covering torso ava.worn.wear_item( ava, item( itype_test_zentai ), false, false ); CHECK( torso_armor_w.layout( ava ) == "Torso Armor: ++\u00A0test zentai (poor fit)" ); // Wearing socks doesn't affect the torso ava.worn.wear_item( ava, item( itype_test_socks ), false, false ); CHECK( torso_armor_w.layout( ava ) == "Torso Armor: ++\u00A0test zentai (poor fit)" ); // Wearing something else on the torso ava.worn.wear_item( ava, item( itype_test_hazmat_suit ), false, false ); CHECK( torso_armor_w.layout( ava ) == "Torso Armor: ++\u00A0TEST hazmat suit (poor fit)" ); } TEST_CASE( "radiation_badge_widget", "[widget][radiation]" ) { widget rads_w = widget_test_rad_badge_text.obj(); avatar &ava = get_avatar(); clear_avatar(); // No indicator when character has no radiation badge CHECK( rads_w.layout( ava ) == "RADIATION: Unknown" ); // Acquire and wear a radiation badge item rad_badge( itype_rad_badge ); auto rad_badge_iter = *ava.worn.wear_item( ava, rad_badge, false, false ); item *rad_badge_worn = & *rad_badge_iter; // Color indicator is shown when character has radiation badge rad_badge_worn->irradiation = 0; CHECK( rads_w.layout( ava ) == "RADIATION: green " ); // Any positive value turns it blue rad_badge_worn->irradiation = 1; CHECK( rads_w.layout( ava ) == "RADIATION: blue " ); rad_badge_worn->irradiation = 29; CHECK( rads_w.layout( ava ) == "RADIATION: blue " ); rad_badge_worn->irradiation = 31; CHECK( rads_w.layout( ava ) == "RADIATION: yellow " ); rad_badge_worn->irradiation = 61; CHECK( rads_w.layout( ava ) == "RADIATION: orange " ); rad_badge_worn->irradiation = 121; CHECK( rads_w.layout( ava ) == "RADIATION: red " ); rad_badge_worn->irradiation = 241; CHECK( rads_w.layout( ava ) == "RADIATION: black " ); } TEST_CASE( "moon_and_lighting_widgets", "[widget]" ) { // The CI tests have inconsistent lighting values for the same // time/day/weather/sun azimuth/etc, so just validate extreme lighting // conditions to check that the lighting widget updates properly. widget w_light = widget_test_lighting_clause.obj(); widget w_moon = widget_test_moon_phase_clause.obj(); avatar &ava = get_avatar(); clear_avatar(); clear_map_without_vision(); set_time( calendar::turn_zero ); CHECK( w_light.layout( ava ) == "LIGHTING: very dark" ); CHECK( w_moon.layout( ava ) == "MOON: New moon" ); set_time( calendar::turn_zero + 3_days ); CHECK( w_moon.layout( ava ) == "MOON: Waxing crescent" ); set_time( calendar::turn_zero + 7_days ); CHECK( w_moon.layout( ava ) == "MOON: Half moon" ); set_time( calendar::turn_zero + 10_days ); CHECK( w_moon.layout( ava ) == "MOON: Waxing gibbous" ); set_time( calendar::turn_zero + 15_days ); CHECK( w_moon.layout( ava ) == "MOON: Full moon" ); set_time( calendar::turn_zero + 18_days ); CHECK( w_moon.layout( ava ) == "MOON: Waning gibbous" ); set_time( calendar::turn_zero + 21_days ); CHECK( w_moon.layout( ava ) == "MOON: Half moon" ); set_time( calendar::turn_zero + 24_days ); CHECK( w_moon.layout( ava ) == "MOON: Waning crescent" ); set_time( calendar::turn_zero + 28_days ); CHECK( w_moon.layout( ava ) == "MOON: New moon" ); set_time( calendar::turn + 12_hours ); CHECK( w_light.layout( ava ) == "LIGHTING: bright" ); } TEST_CASE( "compass_widget", "[widget][compass]" ) { const map &here = get_map(); const int sidebar_width = 36; widget c5s_N = widget_test_compass_N.obj(); widget c5s_N_nowidth = widget_test_compass_N_nowidth.obj(); widget c5s_N_nodir_nowidth = widget_test_compass_N_nodir_nowidth.obj(); widget c5s_legend1 = widget_test_compass_legend_1.obj(); widget c5s_legend3 = widget_test_compass_legend_3.obj(); widget c5s_legend5 = widget_test_compass_legend_5.obj(); avatar &ava = get_avatar(); clear_avatar(); const tripoint_bub_ms northeast = ava.pos_bub() + tripoint( 10, -10, 0 ); const tripoint_bub_ms north = ava.pos_bub() + tripoint( 0, -15, 0 ); SECTION( "No monsters" ) { clear_map_without_vision(); set_time( calendar::turn_zero + 12_hours ); g->mon_info_update(); CHECK( c5s_N.layout( ava, sidebar_width ) == "N: " ); CHECK( c5s_N_nowidth.layout( ava, sidebar_width ) == "N: " ); CHECK( c5s_N_nodir_nowidth.layout( ava, sidebar_width ) == "N: " ); CHECK( c5s_legend1.layout( ava, sidebar_width ).empty() ); CHECK( c5s_legend3.layout( ava, sidebar_width ).empty() ); CHECK( c5s_legend5.layout( ava, sidebar_width ).empty() ); } SECTION( "1 monster NE" ) { clear_map_without_vision(); set_time( calendar::turn_zero + 12_hours ); monster &mon1 = spawn_test_monster( "mon_test_CBM", northeast ); g->mon_info_update(); REQUIRE( ava.sees( here, mon1 ) ); REQUIRE( ava.get_mon_visible().unique_mons[static_cast( cardinal_direction::NORTHEAST )].size() == 1 ); CHECK( c5s_N.layout( ava, sidebar_width ) == "N: " ); CHECK( c5s_N_nowidth.layout( ava, sidebar_width ) == "N: " ); CHECK( c5s_N_nodir_nowidth.layout( ava, sidebar_width ) == "N: " ); CHECK( c5s_legend1.layout( ava, sidebar_width + 3 ) == "B monster producing CBMs when dissected" ); CHECK( c5s_legend3.layout( ava, sidebar_width ) == "B monster producing CBMs when disse…" ); CHECK( c5s_legend5.layout( ava, sidebar_width ) == "B monster producing CBMs when disse…" ); } SECTION( "1 monster N" ) { clear_map_without_vision(); set_time( calendar::turn_zero + 12_hours ); monster &mon1 = spawn_test_monster( "mon_test_CBM", north ); g->mon_info_update(); REQUIRE( ava.sees( here, mon1 ) ); REQUIRE( ava.get_mon_visible().unique_mons[static_cast( cardinal_direction::NORTH )].size() == 1 ); CHECK( c5s_N.layout( ava, sidebar_width ) == "N: B " ); CHECK( c5s_N_nowidth.layout( ava, sidebar_width ) == "N: + " ); CHECK( c5s_N_nodir_nowidth.layout( ava, sidebar_width ) == "N: " ); CHECK( c5s_legend1.layout( ava, sidebar_width + 3 ) == "B monster producing CBMs when dissected" ); CHECK( c5s_legend3.layout( ava, sidebar_width ) == "B monster producing CBMs when disse…" ); CHECK( c5s_legend5.layout( ava, sidebar_width ) == "B monster producing CBMs when disse…" ); } SECTION( "3 same monsters N" ) { clear_map_without_vision(); set_time( calendar::turn_zero + 12_hours ); monster &mon1 = spawn_test_monster( "mon_test_CBM", north ); //NOLINTNEXTLINE(cata-use-named-point-constants) monster &mon2 = spawn_test_monster( "mon_test_CBM", north + tripoint( 0, -1, 0 ) ); monster &mon3 = spawn_test_monster( "mon_test_CBM", north + tripoint( 0, -2, 0 ) ); g->mon_info_update(); REQUIRE( ava.sees( here, mon1 ) ); REQUIRE( ava.sees( here, mon2 ) ); REQUIRE( ava.sees( here, mon3 ) ); REQUIRE( ava.get_mon_visible().unique_mons[static_cast( cardinal_direction::NORTH )].size() == 1 ); CHECK( c5s_N.layout( ava, sidebar_width ) == "N: B " ); CHECK( c5s_N_nowidth.layout( ava, sidebar_width ) == "N: + " ); CHECK( c5s_N_nodir_nowidth.layout( ava, sidebar_width ) == "N: " ); CHECK( c5s_legend1.layout( ava, sidebar_width + 5 ) == "B 3 monster producing CBMs when dissected" ); CHECK( c5s_legend3.layout( ava, sidebar_width ) == "B 3 monster producing CBMs when dis…" ); CHECK( c5s_legend5.layout( ava, sidebar_width ) == "B 3 monster producing CBMs when dis…" ); } SECTION( "3 different monsters N" ) { clear_map_without_vision(); set_time( calendar::turn_zero + 12_hours ); monster &mon1 = spawn_test_monster( "mon_test_CBM", north ); //NOLINTNEXTLINE(cata-use-named-point-constants) monster &mon2 = spawn_test_monster( "mon_test_bovine", north + tripoint( 0, -1, 0 ) ); monster &mon3 = spawn_test_monster( "mon_test_shearable", north + tripoint( 0, -2, 0 ) ); g->mon_info_update(); REQUIRE( ava.sees( here, mon1 ) ); REQUIRE( ava.sees( here, mon2 ) ); REQUIRE( ava.sees( here, mon3 ) ); REQUIRE( ava.get_mon_visible().unique_mons[static_cast( cardinal_direction::NORTH )].size() == 3 ); CHECK( c5s_N.layout( ava, sidebar_width ) == "N: BB" "S " ); CHECK( c5s_N_nowidth.layout( ava, sidebar_width ) == "N: + " ); CHECK( c5s_N_nodir_nowidth.layout( ava, sidebar_width ) == "N: " ); CHECK( c5s_legend1.layout( ava, sidebar_width ) == "S shearable monster " ); CHECK( c5s_legend3.layout( ava, sidebar_width ) == "S shearable monster \n" "B monster producing cattle samples when dissected\n" "B monster producing CBMs when dissected" ); CHECK( c5s_legend5.layout( ava, sidebar_width ) == "S shearable monster \n" "B monster producing cattle samples when dissected\n" "B monster producing CBMs when dissected" ); } } // Widgets with "layout" style can combine other widgets in columns or rows. // // Using "arrange": "columns", width is divided as equally as possible among widgets. // With C columns, (C-1)*2 characters are allotted for space between columns (__): // // C=2: FIRST__SECOND // C=3: FIRST__SECOND__THIRD // C=4: FIRST__SECOND__THIRD__FOURTH // // So total width available to each column is: // // (W - (C-1)*2) / C // // At 24 width, 2 columns, each column gets (24 - (2-1)*2) / 2 == 11 characters. // At 36 width, 2 columns, each column gets (36 - (2-1)*2) / 2 == 17 characters. // At 36 width, 3 columns, each column gets (36 - (3-1)*2) / 3 == 10 characters. // // This test case calls layout() at different widths for 2-, 3-, and 4-column layouts, // to verify and demonstrate how the space is distributed among widgets in columns. // TEST_CASE( "layout_widgets_in_columns", "[widget][layout][columns]" ) { widget stat_w = widget_test_stat_panel.obj(); widget two_w = widget_test_2_column_layout.obj(); widget three_w = widget_test_3_column_layout.obj(); widget four_w = widget_test_4_column_layout.obj(); avatar &ava = get_avatar(); clear_avatar(); ava.set_str_base( 8 ); ava.set_dex_base( 8 ); ava.set_int_base( 8 ); ava.set_per_base( 8 ); ava.movecounter = 50; ava.set_focus( 120 ); ava.set_speed_base( 100 ); ava.magic->set_mana( 1000 ); // Two columns // string ruler: 123456789012345678901234567890123456 CHECK( two_w.layout( ava, 24 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 25 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 26 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 27 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 28 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 29 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 30 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 31 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 32 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 33 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 34 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 35 ) == "MOVE: 50 SPEED: 100 " ); CHECK( two_w.layout( ava, 36 ) == "MOVE: 50 SPEED: 100 " ); // string ruler: 123456789012345678901234567890123456 // Three columns // string ruler: 1234567890123456789012345678901234567890 CHECK( three_w.layout( ava, 36 ) == "MOVE: 50 SPEED: 100 FOCUS: 120" ); CHECK( three_w.layout( ava, 37 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); CHECK( three_w.layout( ava, 38 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); CHECK( three_w.layout( ava, 39 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); CHECK( three_w.layout( ava, 40 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); CHECK( three_w.layout( ava, 41 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); CHECK( three_w.layout( ava, 42 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); CHECK( three_w.layout( ava, 43 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); CHECK( three_w.layout( ava, 44 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); CHECK( three_w.layout( ava, 45 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); CHECK( three_w.layout( ava, 46 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 " ); // string ruler: 1234567890123456789012345678901234567890123456 // Four columns // string ruler: 123456789012345678901234567890123456789012 CHECK( stat_w.layout( ava, 32 ) == "STR: 8 DEX: 8 INT: 8 PER: 8" ); CHECK( stat_w.layout( ava, 33 ) == "STR: 8 DEX: 8 INT: 8 PER: 8" ); CHECK( stat_w.layout( ava, 34 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 35 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 36 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 37 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 38 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 39 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 40 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 41 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 42 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 43 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 44 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 45 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( stat_w.layout( ava, 46 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); // string ruler: 1234567890123456789012345678901234567890123456 // Column alignment // Layout keeps labels vertically aligned for layouts with the same number of widgets // string ruler: 123456789012345678901234567890123456789012345678 CHECK( stat_w.layout( ava, 48 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( four_w.layout( ava, 48 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 MANA: 1000" ); // string ruler: 1234567890123456789012345678901234567890123456789012 CHECK( stat_w.layout( ava, 52 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( four_w.layout( ava, 52 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 MANA: 1000 " ); // string ruler: 12345678901234567890123456789012345678901234567890123456 CHECK( stat_w.layout( ava, 56 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( four_w.layout( ava, 56 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 MANA: 1000 " ); // string ruler: 123456789012345678901234567890123456789012345678901234567890 CHECK( stat_w.layout( ava, 60 ) == "STR: 8 DEX: 8 INT: 8 PER: 8 " ); CHECK( four_w.layout( ava, 60 ) == "MOVE: 50 SPEED: 100 FOCUS: 120 MANA: 1000 " ); } TEST_CASE( "widgets_showing_weather_conditions", "[widget][weather]" ) { map &here = get_map(); widget weather_w = widget_test_weather_text.obj(); avatar &ava = get_avatar(); clear_avatar(); SECTION( "weather conditions" ) { SECTION( "sunny" ) { scoped_weather_override forecast( weather_sunny ); REQUIRE( get_weather().weather_id->name.translated() == "Sunny" ); CHECK( weather_w.layout( ava ) == "Weather: Sunny" ); } SECTION( "cloudy" ) { scoped_weather_override forecast( weather_cloudy ); CHECK( weather_w.layout( ava ) == "Weather: Cloudy" ); } SECTION( "drizzle" ) { scoped_weather_override forecast( weather_drizzle ); CHECK( weather_w.layout( ava ) == "Weather: Drizzle" ); } SECTION( "snowing" ) { scoped_weather_override forecast( weather_snowing ); CHECK( weather_w.layout( ava ) == "Weather: Snowing" ); } SECTION( "portal storm" ) { scoped_weather_override forecast( weather_portal_storm ); CHECK( weather_w.layout( ava ) == "Weather: Portal Storm" ); } SECTION( "cannot see weather when underground" ) { ava.setpos( here, tripoint_bub_ms::zero + tripoint::below ); CHECK( weather_w.layout( ava ) == "Weather: Underground" ); } } } // Fill a 3x3 overmap area around the avatar with a given overmap terrain static void fill_overmap_area( const avatar &ava, const oter_id &oter ) { const tripoint_abs_omt &ava_pos = ava.pos_abs_omt(); for( int x = -1; x <= 1; ++x ) { for( int y = -1; y <= 1; ++y ) { const tripoint offset( x, y, 0 ); overmap_buffer.ter_set( ava_pos + offset, oter ); overmap_buffer.set_seen( ava_pos + offset, om_vision_level::full ); } } // Terrain changed, so the overmap widget cache is stale. display::invalidate_overmap_cache(); } TEST_CASE( "multi-line_overmap_text_widget", "[widget][overmap]" ) { widget overmap_w = widget_test_overmap_3x3_text.obj(); avatar &ava = get_avatar(); mission msn; // Use mission target to invalidate the om cache msn.set_target( ava.pos_abs_omt() + tripoint( 5, 0, 0 ) ); clear_avatar(); clear_map_without_vision(); ava.on_mission_assignment( msn ); // Mission marker is a red asterisk when it's along the border const std::string red_star = "*"; SECTION( "field" ) { const std::string brown_dot = "."; const std::string h_brown_dot = "."; fill_overmap_area( ava, oter_id( "field" ) ); // Mission marker to the north of avatar position (y - 2) msn.set_target( ava.pos_abs_omt() + tripoint( 0, -2, 0 ) ); // (red star in top center of the map) const std::vector field_3x3 = { brown_dot, red_star, brown_dot, "\n", brown_dot, h_brown_dot, brown_dot, "\n", brown_dot, brown_dot, brown_dot }; CHECK( overmap_w.layout( ava ) == string_join( field_3x3, "" ) ); } SECTION( "forest" ) { const std::string green_F = "F"; const std::string h_green_F = "F"; fill_overmap_area( ava, oter_id( "forest" ) ); // Mission marker to the east of avatar position (x + 2) msn.set_target( ava.pos_abs_omt() + tripoint( 2, 0, 0 ) ); // (red star on the right edge of the map) const std::vector forest_3x3 = { green_F, green_F, green_F, "\n", green_F, h_green_F, red_star, "\n", green_F, green_F, green_F }; CHECK( overmap_w.layout( ava ) == string_join( forest_3x3, "" ) ); } SECTION( "swamp" ) { const std::string cyan_F = "F"; const std::string h_cyan_F = "F"; fill_overmap_area( ava, oter_id( "forest_water" ) ); // Mission marker southwest of avatar position (x-2, y+2) msn.set_target( ava.pos_abs_omt() + tripoint( -2, 2, 0 ) ); // (red star on lower left corner of map) const std::vector swamp_3x3 = { cyan_F, cyan_F, cyan_F, "\n", cyan_F, h_cyan_F, cyan_F, "\n", red_star, cyan_F, cyan_F }; CHECK( overmap_w.layout( ava ) == string_join( swamp_3x3, "" ) ); } // TODO: Horde indicators } TEST_CASE( "Custom_widget_height_and_multiline_formatting", "[widget]" ) { widget height1 = widget_test_weather_text.obj(); widget height5 = widget_test_weather_text_height5.obj(); avatar &ava = get_avatar(); clear_avatar(); scoped_weather_override forcast( weather_sunny ); SECTION( "Height field does not impact text content" ) { std::string layout1 = height1.layout( ava ); std::string layout5 = height5.layout( ava ); CHECK( height1._height == 1 ); CHECK( height5._height == 5 ); CHECK( layout1 == "Weather: Sunny" ); CHECK( layout5 == "Weather: Sunny" ); } #if (defined(TILES)) SECTION( "Multiline drawing splits newlines correctly" ) { const int cols = 32; const int rows = 5; catacurses::window w = catacurses::newwin( rows, cols, point::zero ); werase( w ); SECTION( "Single-line layout" ) { std::string layout1 = "abcd efgh ijkl mnop qrst"; CHECK( widget::custom_draw_multiline( layout1, w, 1, 30, 0 ) == 1 ); std::vector lines = scrape_win_at( w, point::zero, cols, rows ); CHECK( lines[0] == " abcd efgh ijkl mnop qrst " ); CHECK( lines[1] == " " ); CHECK( lines[2] == " " ); CHECK( lines[3] == " " ); CHECK( lines[4] == " " ); } werase( w ); SECTION( "Single-line layout" ) { std::string layout5 = "abcd\nefgh\nijkl\nmnop\nqrst"; CHECK( widget::custom_draw_multiline( layout5, w, 1, 30, 0 ) == 5 ); std::vector lines = scrape_win_at( w, point::zero, cols, rows ); CHECK( lines[0] == " abcd " ); CHECK( lines[1] == " efgh " ); CHECK( lines[2] == " ijkl " ); CHECK( lines[3] == " mnop " ); CHECK( lines[4] == " qrst " ); } } #endif } static int get_height_from_widget_factory( const widget_id &id ) { for( const widget &w : widget::get_all() ) { if( w.getId() == id ) { return w._height; } } return -1; } // Use the compass legend as a proof-of-concept TEST_CASE( "Dynamic_height_for_multiline_widgets", "[widget]" ) { const map &here = get_map(); const int sidebar_width = 36; widget c5s_legend3 = widget_test_compass_legend_3.obj(); avatar &ava = get_avatar(); clear_avatar(); const tripoint_bub_ms north = ava.pos_bub() + tripoint( 0, -15, 0 ); SECTION( "No monsters (0 lines, bumped to 1 line when drawing)" ) { clear_map_without_vision(); set_time( calendar::turn_zero + 12_hours ); g->mon_info_update(); CHECK( c5s_legend3.layout( ava, sidebar_width ).empty() ); CHECK( get_height_from_widget_factory( c5s_legend3.getId() ) == 0 ); } SECTION( "1 monster N (1 line)" ) { clear_map_without_vision(); set_time( calendar::turn_zero + 12_hours ); monster &mon1 = spawn_test_monster( "mon_test_CBM", north ); g->mon_info_update(); REQUIRE( ava.sees( here, mon1 ) ); REQUIRE( ava.get_mon_visible().unique_mons[static_cast( cardinal_direction::NORTH )].size() == 1 ); CHECK( c5s_legend3.layout( ava, sidebar_width ) == "B monster producing CBMs when disse…" ); CHECK( get_height_from_widget_factory( c5s_legend3.getId() ) == 1 ); } SECTION( "2 different monsters N (2 lines)" ) { clear_map_without_vision(); set_time( calendar::turn_zero + 12_hours ); monster &mon1 = spawn_test_monster( "mon_test_CBM", north ); //NOLINTNEXTLINE(cata-use-named-point-constants) monster &mon2 = spawn_test_monster( "mon_test_bovine", north + tripoint( 0, -1, 0 ) ); g->mon_info_update(); REQUIRE( ava.sees( here, mon1 ) ); REQUIRE( ava.sees( here, mon2 ) ); REQUIRE( ava.get_mon_visible().unique_mons[static_cast( cardinal_direction::NORTH )].size() == 2 ); CHECK( c5s_legend3.layout( ava, sidebar_width ) == "B monster producing cattle samples when dissected\n" "B monster producing CBMs when dissected" ); CHECK( get_height_from_widget_factory( c5s_legend3.getId() ) == 2 ); } SECTION( "3 different monsters N (3 lines)" ) { clear_map_without_vision(); set_time( calendar::turn_zero + 12_hours ); monster &mon1 = spawn_test_monster( "mon_test_CBM", north ); //NOLINTNEXTLINE(cata-use-named-point-constants) monster &mon2 = spawn_test_monster( "mon_test_bovine", north + tripoint( 0, -1, 0 ) ); monster &mon3 = spawn_test_monster( "mon_test_shearable", north + tripoint( 0, -2, 0 ) ); g->mon_info_update(); REQUIRE( ava.sees( here, mon1 ) ); REQUIRE( ava.sees( here, mon2 ) ); REQUIRE( ava.sees( here, mon3 ) ); REQUIRE( ava.get_mon_visible().unique_mons[static_cast( cardinal_direction::NORTH )].size() == 3 ); CHECK( c5s_legend3.layout( ava, sidebar_width ) == "S shearable monster \n" "B monster producing cattle samples when dissected\n" "B monster producing CBMs when dissected" ); CHECK( get_height_from_widget_factory( c5s_legend3.getId() ) == 3 ); } } /** * Alignments * ---------- * * Label left, text right (default): * ------------------------------------ * LEFT ARM STATUS: disinfected * TORSO STATUS: bitten * L ARM: $ * TORSO: B * * Label left, text left: * ------------------------------------ * LEFT ARM STATUS: disinfected * TORSO STATUS: bitten * L ARM: $ * TORSO: B * * Label right, text left: * ------------------------------------ * LEFT ARM STATUS: disinfected * TORSO STATUS: bitten * L ARM: $ * TORSO: B * * Label right, text right: * ------------------------------------ * LEFT ARM STATUS: disinfected * TORSO STATUS: bitten * L ARM: $ * TORSO: B * * Label center, text left: * ------------------------------------ * LEFT ARM STATUS: disinfected * TORSO STATUS: bitten * L ARM: $ * TORSO: B * * Label center, text right: * ------------------------------------ * LEFT ARM STATUS: disinfected * TORSO STATUS: bitten * L ARM: $ * TORSO: B * * Label center, text center: * ------------------------------------ * LEFT ARM STATUS: disinfected * TORSO STATUS: bitten * L ARM: $ * TORSO: B * * Label left, text center: * ------------------------------------ * LEFT ARM STATUS: disinfected * TORSO STATUS: bitten * L ARM: $ * TORSO: B * * Label right, text center: * ------------------------------------ * LEFT ARM STATUS: disinfected * TORSO STATUS: bitten * L ARM: $ * TORSO: B */ TEST_CASE( "Widget_alignment", "[widget]" ) { const int sidebar_width = 36; const int row_label_width = 15; avatar &ava = get_avatar(); clear_avatar(); bodypart_id arm( "arm_l" ); bodypart_id torso( "torso" ); widget arm_stat_sc = widget_test_status_left_arm_text.obj(); widget torso_stat_sc = widget_test_status_torso_text.obj(); widget arm_stat_mc = widget_test_status_sym_left_arm_text.obj(); widget torso_stat_mc = widget_test_status_sym_torso_text.obj(); ava.add_effect( effect_bite, 1_minutes, torso ); ava.add_effect( effect_disinfected, 1_minutes, arm ); SECTION( "Label left, text right (default)" ) { arm_stat_sc._label_align = widget_alignment::LEFT; arm_stat_mc._label_align = widget_alignment::LEFT; torso_stat_sc._label_align = widget_alignment::LEFT; torso_stat_mc._label_align = widget_alignment::LEFT; arm_stat_sc._text_align = widget_alignment::RIGHT; arm_stat_mc._text_align = widget_alignment::RIGHT; torso_stat_sc._text_align = widget_alignment::RIGHT; torso_stat_mc._text_align = widget_alignment::RIGHT; CHECK( arm_stat_sc.layout( ava, sidebar_width, row_label_width ) == "LEFT ARM STATUS: disinfected" ); CHECK( torso_stat_sc.layout( ava, sidebar_width, row_label_width ) == "TORSO STATUS: bitten" ); CHECK( arm_stat_mc.layout( ava, sidebar_width, row_label_width ) == "L ARM: $" ); CHECK( torso_stat_mc.layout( ava, sidebar_width, row_label_width ) == "TORSO: B" ); } SECTION( "Label left, text left" ) { arm_stat_sc._label_align = widget_alignment::LEFT; arm_stat_mc._label_align = widget_alignment::LEFT; torso_stat_sc._label_align = widget_alignment::LEFT; torso_stat_mc._label_align = widget_alignment::LEFT; arm_stat_sc._text_align = widget_alignment::LEFT; arm_stat_mc._text_align = widget_alignment::LEFT; torso_stat_sc._text_align = widget_alignment::LEFT; torso_stat_mc._text_align = widget_alignment::LEFT; CHECK( arm_stat_sc.layout( ava, sidebar_width, row_label_width ) == "LEFT ARM STATUS: disinfected " ); CHECK( torso_stat_sc.layout( ava, sidebar_width, row_label_width ) == "TORSO STATUS: bitten " ); CHECK( arm_stat_mc.layout( ava, sidebar_width, row_label_width ) == "L ARM: $ " ); CHECK( torso_stat_mc.layout( ava, sidebar_width, row_label_width ) == "TORSO: B " ); } SECTION( "Label right, text left" ) { arm_stat_sc._label_align = widget_alignment::RIGHT; arm_stat_mc._label_align = widget_alignment::RIGHT; torso_stat_sc._label_align = widget_alignment::RIGHT; torso_stat_mc._label_align = widget_alignment::RIGHT; arm_stat_sc._text_align = widget_alignment::LEFT; arm_stat_mc._text_align = widget_alignment::LEFT; torso_stat_sc._text_align = widget_alignment::LEFT; torso_stat_mc._text_align = widget_alignment::LEFT; CHECK( arm_stat_sc.layout( ava, sidebar_width, row_label_width ) == "LEFT ARM STATUS: disinfected " ); CHECK( torso_stat_sc.layout( ava, sidebar_width, row_label_width ) == " TORSO STATUS: bitten " ); CHECK( arm_stat_mc.layout( ava, sidebar_width, row_label_width ) == " L ARM: $ " ); CHECK( torso_stat_mc.layout( ava, sidebar_width, row_label_width ) == " TORSO: B " ); } SECTION( "Label right, text right" ) { arm_stat_sc._label_align = widget_alignment::RIGHT; arm_stat_mc._label_align = widget_alignment::RIGHT; torso_stat_sc._label_align = widget_alignment::RIGHT; torso_stat_mc._label_align = widget_alignment::RIGHT; arm_stat_sc._text_align = widget_alignment::RIGHT; arm_stat_mc._text_align = widget_alignment::RIGHT; torso_stat_sc._text_align = widget_alignment::RIGHT; torso_stat_mc._text_align = widget_alignment::RIGHT; CHECK( arm_stat_sc.layout( ava, sidebar_width, row_label_width ) == " LEFT ARM STATUS: disinfected" ); CHECK( torso_stat_sc.layout( ava, sidebar_width, row_label_width ) == " TORSO STATUS: bitten" ); CHECK( arm_stat_mc.layout( ava, sidebar_width, row_label_width ) == " L ARM: $" ); CHECK( torso_stat_mc.layout( ava, sidebar_width, row_label_width ) == " TORSO: B" ); } SECTION( "Label center, text left" ) { arm_stat_sc._label_align = widget_alignment::CENTER; arm_stat_mc._label_align = widget_alignment::CENTER; torso_stat_sc._label_align = widget_alignment::CENTER; torso_stat_mc._label_align = widget_alignment::CENTER; arm_stat_sc._text_align = widget_alignment::LEFT; arm_stat_mc._text_align = widget_alignment::LEFT; torso_stat_sc._text_align = widget_alignment::LEFT; torso_stat_mc._text_align = widget_alignment::LEFT; CHECK( arm_stat_sc.layout( ava, sidebar_width, row_label_width ) == "LEFT ARM STATUS: disinfected " ); CHECK( torso_stat_sc.layout( ava, sidebar_width, row_label_width ) == " TORSO STATUS: bitten " ); CHECK( arm_stat_mc.layout( ava, sidebar_width, row_label_width ) == " L ARM: $ " ); CHECK( torso_stat_mc.layout( ava, sidebar_width, row_label_width ) == " TORSO: B " ); } SECTION( "Label center, text right" ) { arm_stat_sc._label_align = widget_alignment::CENTER; arm_stat_mc._label_align = widget_alignment::CENTER; torso_stat_sc._label_align = widget_alignment::CENTER; torso_stat_mc._label_align = widget_alignment::CENTER; arm_stat_sc._text_align = widget_alignment::RIGHT; arm_stat_mc._text_align = widget_alignment::RIGHT; torso_stat_sc._text_align = widget_alignment::RIGHT; torso_stat_mc._text_align = widget_alignment::RIGHT; CHECK( arm_stat_sc.layout( ava, sidebar_width, row_label_width ) == "LEFT ARM STATUS: disinfected" ); CHECK( torso_stat_sc.layout( ava, sidebar_width, row_label_width ) == " TORSO STATUS: bitten" ); CHECK( arm_stat_mc.layout( ava, sidebar_width, row_label_width ) == " L ARM: $" ); CHECK( torso_stat_mc.layout( ava, sidebar_width, row_label_width ) == " TORSO: B" ); } SECTION( "Label center, text center" ) { arm_stat_sc._label_align = widget_alignment::CENTER; arm_stat_mc._label_align = widget_alignment::CENTER; torso_stat_sc._label_align = widget_alignment::CENTER; torso_stat_mc._label_align = widget_alignment::CENTER; arm_stat_sc._text_align = widget_alignment::CENTER; arm_stat_mc._text_align = widget_alignment::CENTER; torso_stat_sc._text_align = widget_alignment::CENTER; torso_stat_mc._text_align = widget_alignment::CENTER; CHECK( arm_stat_sc.layout( ava, sidebar_width, row_label_width ) == "LEFT ARM STATUS: disinfected " ); CHECK( torso_stat_sc.layout( ava, sidebar_width, row_label_width ) == " TORSO STATUS: bitten " ); CHECK( arm_stat_mc.layout( ava, sidebar_width, row_label_width ) == " L ARM: $ " ); CHECK( torso_stat_mc.layout( ava, sidebar_width, row_label_width ) == " TORSO: B " ); } SECTION( "Label left, text center" ) { arm_stat_sc._label_align = widget_alignment::LEFT; arm_stat_mc._label_align = widget_alignment::LEFT; torso_stat_sc._label_align = widget_alignment::LEFT; torso_stat_mc._label_align = widget_alignment::LEFT; arm_stat_sc._text_align = widget_alignment::CENTER; arm_stat_mc._text_align = widget_alignment::CENTER; torso_stat_sc._text_align = widget_alignment::CENTER; torso_stat_mc._text_align = widget_alignment::CENTER; CHECK( arm_stat_sc.layout( ava, sidebar_width, row_label_width ) == "LEFT ARM STATUS: disinfected " ); CHECK( torso_stat_sc.layout( ava, sidebar_width, row_label_width ) == "TORSO STATUS: bitten " ); CHECK( arm_stat_mc.layout( ava, sidebar_width, row_label_width ) == "L ARM: $ " ); CHECK( torso_stat_mc.layout( ava, sidebar_width, row_label_width ) == "TORSO: B " ); } SECTION( "Label right, text center" ) { arm_stat_sc._label_align = widget_alignment::RIGHT; arm_stat_mc._label_align = widget_alignment::RIGHT; torso_stat_sc._label_align = widget_alignment::RIGHT; torso_stat_mc._label_align = widget_alignment::RIGHT; arm_stat_sc._text_align = widget_alignment::CENTER; arm_stat_mc._text_align = widget_alignment::CENTER; torso_stat_sc._text_align = widget_alignment::CENTER; torso_stat_mc._text_align = widget_alignment::CENTER; CHECK( arm_stat_sc.layout( ava, sidebar_width, row_label_width ) == "LEFT ARM STATUS: disinfected " ); CHECK( torso_stat_sc.layout( ava, sidebar_width, row_label_width ) == " TORSO STATUS: bitten " ); CHECK( arm_stat_mc.layout( ava, sidebar_width, row_label_width ) == " L ARM: $ " ); CHECK( torso_stat_mc.layout( ava, sidebar_width, row_label_width ) == " TORSO: B " ); } SECTION( "Multiline text" ) { widget bp_legend = widget_test_status_legend_text.obj(); const std::string line1 = "B bitten I infected % broken"; const std::string line2 = "= splinted + bandaged"; const std::string line3 = "$ disinfected b bleeding"; ava.add_effect( effect_infected, 1_minutes, torso ); ava.add_effect( effect_bleed, 1_minutes, torso ); ava.get_effect( effect_bleed, torso ).set_intensity( 5 ); ava.set_part_hp_cur( arm, 0 ); ava.wear_item( item( itype_arm_splint ) ); ava.add_effect( effect_bandaged, 1_minutes, arm ); bp_legend._label_align = widget_alignment::LEFT; bp_legend._text_align = widget_alignment::RIGHT; CHECK( bp_legend.layout( ava, sidebar_width ) == " " + line1 + "\n" + " " + line2 + " \n" + " " + line3 ); bp_legend._label_align = widget_alignment::RIGHT; bp_legend._text_align = widget_alignment::RIGHT; CHECK( bp_legend.layout( ava, sidebar_width ) == " " + line1 + "\n" + " " + line2 + " \n" + " " + line3 ); bp_legend._label_align = widget_alignment::CENTER; bp_legend._text_align = widget_alignment::RIGHT; CHECK( bp_legend.layout( ava, sidebar_width ) == " " + line1 + "\n" + " " + line2 + " \n" + " " + line3 ); bp_legend._label_align = widget_alignment::LEFT; bp_legend._text_align = widget_alignment::LEFT; CHECK( bp_legend.layout( ava, sidebar_width ) == line1 + " \n" + line2 + " \n" + line3 + " " ); bp_legend._label_align = widget_alignment::RIGHT; bp_legend._text_align = widget_alignment::LEFT; CHECK( bp_legend.layout( ava, sidebar_width ) == line1 + " \n" + line2 + " \n" + line3 + " " ); bp_legend._label_align = widget_alignment::CENTER; bp_legend._text_align = widget_alignment::LEFT; CHECK( bp_legend.layout( ava, sidebar_width ) == line1 + " \n" + line2 + " \n" + line3 + " " ); bp_legend._label_align = widget_alignment::LEFT; bp_legend._text_align = widget_alignment::CENTER; CHECK( bp_legend.layout( ava, sidebar_width ) == " " + line1 + " \n" + " " + line2 + " \n" + " " + line3 + " " ); bp_legend._label_align = widget_alignment::RIGHT; bp_legend._text_align = widget_alignment::CENTER; CHECK( bp_legend.layout( ava, sidebar_width ) == " " + line1 + " \n" + " " + line2 + " \n" + " " + line3 + " " ); bp_legend._label_align = widget_alignment::CENTER; bp_legend._text_align = widget_alignment::CENTER; CHECK( bp_legend.layout( ava, sidebar_width ) == " " + line1 + " \n" + " " + line2 + " \n" + " " + line3 + " " ); } } TEST_CASE( "Clause_conditions_-_pure_JSON_widgets", "[widget][clause][condition]" ) { const int sidebar_width = 20; const time_point midnight = calendar::turn_zero + 0_hours; const time_point midday = calendar::turn_zero + 12_hours; const item blindfold( itype_blindfold ); const item earplugs( itype_ear_plugs ); widget w_num = widget_test_clause_number.obj(); widget w_txt = widget_test_clause_text.obj(); widget w_sym = widget_test_clause_sym.obj(); widget w_lgd = widget_test_clause_legend.obj(); avatar &ava = get_avatar(); clear_avatar(); set_time( midnight ); REQUIRE( !ava.has_trait( trait_GOODHEARING ) ); REQUIRE( !ava.has_trait( trait_NIGHTVISION ) ); REQUIRE( !is_day( calendar::turn ) ); REQUIRE( !ava.is_deaf() ); REQUIRE( !ava.is_blind() ); SECTION( "Default values" ) { CHECK( w_num.layout( ava ) == "Num Values: 1" ); CHECK( w_txt.layout( ava ) == "Text Values: None" ); CHECK( w_sym.layout( ava ) == "Symbol Values: ." ); CHECK( w_lgd.layout( ava, sidebar_width ) == ". None " ); } SECTION( "GOODHEARING" ) { ava.toggle_trait( trait_GOODHEARING ); CHECK( w_num.layout( ava ) == "Num Values: 10" ); CHECK( w_txt.layout( ava ) == "Text Values: good hearing" ); CHECK( w_sym.layout( ava ) == "Symbol Values: +" ); CHECK( w_lgd.layout( ava, sidebar_width ) == "+ good hearing " ); } SECTION( "Daylight" ) { set_time( midday ); CHECK( w_num.layout( ava ) == "Num Values: 0" ); CHECK( w_txt.layout( ava ) == "Text Values: daylight" ); CHECK( w_sym.layout( ava ) == "Symbol Values: =" ); CHECK( w_lgd.layout( ava, sidebar_width ) == "= daylight " ); } SECTION( "Daylight / Blind" ) { set_time( midday ); ava.wear_item( blindfold, false ); CHECK( w_num.layout( ava ) == "Num Values: -20, 0" ); CHECK( w_txt.layout( ava ) == "Text Values: blind, daylight" ); CHECK( w_sym.layout( ava ) == "Symbol Values: <=" ); CHECK( w_lgd.layout( ava, sidebar_width ) == "< blind = daylight " ); } SECTION( "Daylight / Blind / Deaf / GOODHEARING / NIGHTVISION" ) { set_time( midday ); ava.wear_item( blindfold, false ); ava.wear_item( earplugs, false ); ava.toggle_trait( trait_GOODHEARING ); ava.toggle_trait( trait_NIGHTVISION ); CHECK( w_num.layout( ava ) == "Num Values: -20, -10, 0, 10, 20" ); CHECK( w_txt.layout( ava ) == "Text Values: blind, deaf, daylight, good hearing, good vision" ); CHECK( w_sym.layout( ava ) == "Symbol Values: <-=+>" ); CHECK( w_lgd.layout( ava, sidebar_width ) == "< blind - deaf \n= daylight \n+ good hearing \n> good vision " ); } } TEST_CASE( "widget_disabled_when_empty", "[widget]" ) { item blindfold( itype_blindfold ); avatar &ava = get_avatar(); clear_avatar(); widget wgt = widget_test_disabled_when_empty.obj(); REQUIRE( wgt.has_flag( json_flag_W_DISABLED_WHEN_EMPTY ) ); SECTION( "test layout results" ) { // Show widget text when character is not blind REQUIRE( !ava.is_blind() ); CHECK( wgt.layout( ava ) == "NOT EMPTY: Text exists" ); // Hide the widget when character is blind. // The empty string indicates to the calling function // that the widget should not be rendered // (combined with the W_DISABLED_WHEN_EMPTY flag). ava.wear_item( blindfold ); REQUIRE( ava.is_blind() ); CHECK( wgt.layout( ava ).empty() ); } #if (defined(TILES)) SECTION( "test widget rendering when disabled" ) { const int cols = 32; const int rows = 5; catacurses::window w = catacurses::newwin( rows, cols, point::zero ); werase( w ); SECTION( "Not empty" ) { // Show widget text when character is not blind REQUIRE( !ava.is_blind() ); CHECK( widget::custom_draw_multiline( wgt.layout( ava ), w, 1, 30, 0 ) == 1 ); std::vector lines = scrape_win_at( w, point::zero, cols, rows ); CHECK( lines[0] == " NOT EMPTY: Text exists " ); CHECK( lines[1] == " " ); CHECK( lines[2] == " " ); CHECK( lines[3] == " " ); CHECK( lines[4] == " " ); } werase( w ); SECTION( "Empty" ) { // Hide the widget when character is blind. ava.wear_item( blindfold ); REQUIRE( ava.is_blind() ); // Shouldn't be called (height should be decremented), but check it just in case CHECK( widget::custom_draw_multiline( wgt.layout( ava ), w, 1, 30, 0 ) == 1 ); std::vector lines = scrape_win_at( w, point::zero, cols, rows ); CHECK( lines[0] == " " ); CHECK( lines[1] == " " ); CHECK( lines[2] == " " ); CHECK( lines[3] == " " ); CHECK( lines[4] == " " ); } } #endif } TEST_CASE( "widget_rows_in_columns", "[widget]" ) { avatar &ava = get_avatar(); clear_avatar(); clear_map_without_vision(); // Setup overmap fill_overmap_area( ava, oter_id( "field" ) ); ava.reset_all_missions(); ava.set_focus( 100 ); ava.movecounter = 0; REQUIRE( ava.movecounter == 0 ); REQUIRE( ava.get_focus() == 100 ); REQUIRE( ava.get_speed() == 100 ); SECTION( "3 columns, multiline/rows/rows" ) { const std::string brown_dot = "."; const std::string h_brown_dot = "."; const std::string expected = string_join( std::vector { brown_dot, brown_dot, brown_dot, " MOVE: 0 STR: 8 \n", brown_dot, h_brown_dot, brown_dot, " SPEED: 100 DEX: 8 \n", brown_dot, brown_dot, brown_dot, " FOCUS: 100 INT: 8 \n", " MANA: 1000 PER: 8 " }, "" ); widget wgt = widget_test_layout_rows_in_columns.obj(); widget::finalize_inherited_fields_recursive( wgt.getId(), wgt._separator, wgt._padding ); widget::finalize_label_width_recursive( wgt.getId() ); CHECK( wgt.layout( ava, 34 ) == expected ); } SECTION( "3 columns nested in 2 columns, rows/columns, multiline/rows/rows" ) { const std::string brown_dot = "."; const std::string h_brown_dot = "."; const std::string expected = string_join( std::vector { string_join( std::vector { "CLAUSE: Zero ", brown_dot, brown_dot, brown_dot, " MOVE: 0 STR: 8 \n" }, "" ), string_join( std::vector { "POOL: 0000 ", brown_dot, h_brown_dot, brown_dot, " SPEED: 100 DEX: 8 \n" }, "" ), string_join( std::vector { "NUM: 0 ", brown_dot, brown_dot, brown_dot, " FOCUS: 100 INT: 8 \n" }, "" ), " MANA: 1000 PER: 8 " }, "" ); widget wgt = widget_test_layout_cols_in_cols.obj(); widget::finalize_inherited_fields_recursive( wgt.getId(), wgt._separator, wgt._padding ); widget::finalize_label_width_recursive( wgt.getId() ); CHECK( wgt.layout( ava, 68 ) == expected ); } } static void test_widget_flag_nopad( const bodypart_id &bid, int bleed_int, avatar &ava, const widget_id &wgt, bool skip_pad ) { const int width = 36; const int max_hp = ava.get_part_hp_max( bid ); widget w = wgt.obj(); std::string bleed_txt; if( bleed_int <= 0 ) { bleed_txt.clear(); } else if( bleed_int < 11 ) { bleed_txt = "│"; } else if( bleed_int < 21 ) { bleed_txt = "║"; } else { bleed_txt = "║"; } std::string broken_txt = "‖"; GIVEN( "left arm HP full" ) { REQUIRE( ava.get_part_hp_cur( bid ) == max_hp ); REQUIRE( !ava.is_limb_broken( bid ) ); if( skip_pad ) { const std::string txt = "LA : " + bleed_txt + broken_txt + "█████"; CHECK( w.layout( ava, width, 0, skip_pad ) == txt + txt + txt ); } else { CHECK( w.layout( ava, width, 0, skip_pad ) == "LA… " + broken_txt + " █… " "LA… " + broken_txt + " █… " "L… " + broken_txt + " █…" ); } } GIVEN( "left arm HP 3/4" ) { ava.set_part_hp_cur( bid, ( max_hp * 3 ) / 4 ); REQUIRE( ava.get_part_hp_cur( bid ) == ( max_hp * 3 ) / 4 ); REQUIRE( !ava.is_limb_broken( bid ) ); if( skip_pad ) { const std::string txt = "LA : " + bleed_txt + broken_txt + "███▋ "; CHECK( w.layout( ava, width, 0, skip_pad ) == txt + txt + txt ); } else { CHECK( w.layout( ava, width, 0, skip_pad ) == "LA… " + broken_txt + " █… " "LA… " + broken_txt + " █… " "L… " + broken_txt + " █…" ); } } GIVEN( "left arm HP 1/2" ) { ava.set_part_hp_cur( bid, max_hp / 2 ); REQUIRE( ava.get_part_hp_cur( bid ) == max_hp / 2 ); REQUIRE( !ava.is_limb_broken( bid ) ); if( skip_pad ) { const std::string txt = "LA : " + bleed_txt + broken_txt + "██▍ "; CHECK( w.layout( ava, width, 0, skip_pad ) == txt + txt + txt ); } else { CHECK( w.layout( ava, width, 0, skip_pad ) == "LA… " + broken_txt + " █… " "LA… " + broken_txt + " █… " "L… " + broken_txt + " █…" ); } } GIVEN( "left arm HP 1/4" ) { ava.set_part_hp_cur( bid, max_hp / 4 ); REQUIRE( ava.get_part_hp_cur( bid ) == max_hp / 4 ); REQUIRE( !ava.is_limb_broken( bid ) ); if( skip_pad ) { const std::string txt = "LA : " + bleed_txt + broken_txt + "█▎ "; CHECK( w.layout( ava, width, 0, skip_pad ) == txt + txt + txt ); } else { CHECK( w.layout( ava, width, 0, skip_pad ) == "LA… " + broken_txt + " █… " "LA… " + broken_txt + " █… " "L… " + broken_txt + " █…" ); } } GIVEN( "left arm HP 0" ) { broken_txt = "ℵ"; ava.set_part_hp_cur( bid, 0 ); REQUIRE( ava.get_part_hp_cur( bid ) == 0 ); REQUIRE( ava.is_limb_broken( bid ) ); if( skip_pad ) { const std::string txt = "LA : " + bleed_txt + broken_txt + " "; CHECK( w.layout( ava, width, 0, skip_pad ) == txt + txt + txt ); } else { CHECK( w.layout( ava, width, 0, skip_pad ) == "LA… " + broken_txt + " … " "LA… " + broken_txt + " … " "L… " + broken_txt + " …" ); } } } TEST_CASE( "W_NO_PADDING_widget_flag", "[widget]" ) { avatar &ava = get_avatar(); clear_avatar(); clear_map_without_vision(); ava.reset_all_missions(); ava.set_focus( 100 ); ava.movecounter = 0; // workaround for mbstowcs to process multibyte utf-8 chars std::locale const &oldloc = std::locale(); on_out_of_scope reset_loc( [&oldloc]() { std::locale::global( oldloc ); } ); char *result = setlocale( LC_ALL, "" ); REQUIRE( result ); SECTION( "without flag" ) { const widget_id &wgt = widget_test_layout_nopad_noflag; widget::finalize_inherited_fields_recursive( wgt, wgt->_separator, wgt->_padding ); widget::finalize_label_width_recursive( wgt ); REQUIRE( !wgt->has_flag( "W_NO_PADDING" ) ); GIVEN( "left arm bleed intensity = 0" ) { REQUIRE( !ava.has_effect( effect_bleed, body_part_arm_l ) ); test_widget_flag_nopad( body_part_arm_l, 0, ava, wgt, false ); } GIVEN( "left arm bleed intensity = 1" ) { ava.add_effect( effect_bleed, 10_turns, body_part_arm_l ); ava.get_effect( effect_bleed, body_part_arm_l ).set_intensity( 1 ); REQUIRE( ava.has_effect( effect_bleed, body_part_arm_l ) ); REQUIRE( ava.get_effect_int( effect_bleed, body_part_arm_l ) == 1 ); test_widget_flag_nopad( body_part_arm_l, 1, ava, wgt, false ); } GIVEN( "left arm bleed intensity = 11" ) { ava.add_effect( effect_bleed, 10_turns, body_part_arm_l ); ava.get_effect( effect_bleed, body_part_arm_l ).set_intensity( 11 ); REQUIRE( ava.has_effect( effect_bleed, body_part_arm_l ) ); REQUIRE( ava.get_effect_int( effect_bleed, body_part_arm_l ) == 11 ); test_widget_flag_nopad( body_part_arm_l, 11, ava, wgt, false ); } GIVEN( "left arm bleed intensity = 21" ) { ava.add_effect( effect_bleed, 10_turns, body_part_arm_l ); ava.get_effect( effect_bleed, body_part_arm_l ).set_intensity( 21 ); REQUIRE( ava.has_effect( effect_bleed, body_part_arm_l ) ); REQUIRE( ava.get_effect_int( effect_bleed, body_part_arm_l ) == 21 ); test_widget_flag_nopad( body_part_arm_l, 21, ava, wgt, false ); } } SECTION( "with flag" ) { const widget_id &wgt = widget_test_layout_nopad; REQUIRE( wgt->has_flag( "W_NO_PADDING" ) ); GIVEN( "left arm bleed intensity = 0" ) { REQUIRE( !ava.has_effect( effect_bleed, body_part_arm_l ) ); test_widget_flag_nopad( body_part_arm_l, 0, ava, wgt, true ); } GIVEN( "left arm bleed intensity = 1" ) { ava.add_effect( effect_bleed, 10_turns, body_part_arm_l ); ava.get_effect( effect_bleed, body_part_arm_l ).set_intensity( 1 ); REQUIRE( ava.has_effect( effect_bleed, body_part_arm_l ) ); REQUIRE( ava.get_effect_int( effect_bleed, body_part_arm_l ) == 1 ); test_widget_flag_nopad( body_part_arm_l, 1, ava, wgt, true ); } GIVEN( "left arm bleed intensity = 11" ) { ava.add_effect( effect_bleed, 10_turns, body_part_arm_l ); ava.get_effect( effect_bleed, body_part_arm_l ).set_intensity( 11 ); REQUIRE( ava.has_effect( effect_bleed, body_part_arm_l ) ); REQUIRE( ava.get_effect_int( effect_bleed, body_part_arm_l ) == 11 ); test_widget_flag_nopad( body_part_arm_l, 11, ava, wgt, true ); } GIVEN( "left arm bleed intensity = 21" ) { ava.add_effect( effect_bleed, 10_turns, body_part_arm_l ); ava.get_effect( effect_bleed, body_part_arm_l ).set_intensity( 21 ); REQUIRE( ava.has_effect( effect_bleed, body_part_arm_l ) ); REQUIRE( ava.get_effect_int( effect_bleed, body_part_arm_l ) == 21 ); test_widget_flag_nopad( body_part_arm_l, 21, ava, wgt, true ); } } } TEST_CASE( "widgets_using_custom_vars", "[widget]" ) { avatar &ava = get_avatar(); clear_avatar(); SECTION( "static range" ) { widget static_range_w = widget_test_custom_var_static_range.obj(); ava.set_focus( 75 ); CHECK( static_range_w.layout( ava ) == "FOCUS: 75" ); ava.set_focus( 120 ); CHECK( static_range_w.layout( ava ) == "FOCUS: 120" ); } SECTION( "dynamic range" ) { widget dynamic_range_w = widget_test_custom_var_dynamic_range.obj(); ava.set_str_base( 8 ); GIVEN( "value within normal range" ) { ava.set_str_bonus( 0 ); CHECK( dynamic_range_w.layout( ava ) == "STR: 8" ); } GIVEN( "value below normal range" ) { ava.set_str_bonus( -1 ); CHECK( dynamic_range_w.layout( ava ) == "STR: 7" ); ava.set_str_bonus( -2 ); CHECK( dynamic_range_w.layout( ava ) == "STR: 6" ); ava.set_str_bonus( -3 ); CHECK( dynamic_range_w.layout( ava ) == "STR: 5" ); } GIVEN( "value above normal range" ) { ava.set_str_bonus( 1 ); CHECK( dynamic_range_w.layout( ava ) == "STR: 9" ); ava.set_str_bonus( 2 ); CHECK( dynamic_range_w.layout( ava ) == "STR: 10" ); ava.set_str_bonus( 3 ); CHECK( dynamic_range_w.layout( ava ) == "STR: 11" ); } } }