diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 62d80520121a4..3443dd76c5bc0 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -1283,6 +1283,33 @@ See also VEHICLE_JSON.md "symbol": "[", // The item symbol as it appears on the map. Must be a Unicode string exactly 1 console cell width. "looks_like": "rag", // hint to tilesets if this item has no tile, use the looks_like tile "description": "Socks. Put 'em on your feet.", // Description of the item +"ascii_picture": [ + " ,,,,,,,,,,,,,", + " .;;;;;;;;;;;;;;;;;;;,.", + " .;;;;;;;;;;;;;;;;;;;;;;;;,", + ".;;;;;;;;;;;;;;;;;;;;;;;;;;;;.", + ";;;;;@;;;;;;;;;;;;;;;;;;;;;;;;' .............", + ";;;;@@;;;;;;;;;;;;;;;;;;;;;;;;'.................", + ";;;;@@;;;;;;;;;;;;;;;;;;;;;;;;'...................`", + ";;;;@;;;;;;;;;;;;;;;@;;;;;;;'.....................", + " `;;;;;;;;;;;;;;;;;;;@@;;;;;'..................;....", // Ascii art that will be displayed at the bottom of the item description. Array of string with each element being a line of the picture. Lines longer than 42 characters won't display properly. + " `;;;;;;;;;;;;;;;;@@;;;;'....................;;...", + " `;;;;;;;;;;;;;@;;;;'...;.................;;....", + " `;;;;;;;;;;;;' ...;;...............;.....", + " `;;;;;;' ...;;..................", + " ;; ..;...............", + " ` ............", + " ` ......", + " ` ..", + " ` '", + " ` '", + " ` '", + " ` `", + " ` `,", + " `", + " `", + " `." + ], "phase": "solid", // (Optional, default = "solid") What phase it is "weight": "350 g", // Weight, weight in grams, mg and kg can be used - "50 mg", "5 g" or "5 kg". For stackable items (ammo, comestibles) this is the weight per charge. "volume": "250 ml", // Volume, volume in ml and L can be used - "50 ml" or "2 L". For stackable items (ammo, comestibles) this is the volume of stack_size charges. diff --git a/src/item.cpp b/src/item.cpp index 3db57d5ffc59c..90784a6201ac1 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -3333,6 +3333,11 @@ void item::final_info( std::vector &info, const iteminfo_query *parts, } } } + if( get_option( "ENABLE_ASCII_ART_ITEM" ) ) { + for( const std::string &line : type->ascii_picture ) { + info.push_back( iteminfo( "DESCRIPTION", line ) ); + } + } } std::string item::info( std::vector &info, const iteminfo_query *parts, int batch ) const diff --git a/src/item_factory.cpp b/src/item_factory.cpp index a92ff8edb4b9b..00c0515c8e1e3 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -25,6 +25,7 @@ #include "json.h" #include "material.h" #include "options.h" +#include "output.h" #include "recipe_dictionary.h" #include "requirements.h" #include "string_formatter.h" @@ -64,6 +65,8 @@ static void npc_implied_flags( itype &item_template ); extern const double MAX_RECOIL; +static const int ascii_art_width = 42; + bool item_is_blacklisted( const std::string &id ) { return item_blacklist.count( id ); @@ -414,6 +417,14 @@ void Item_factory::finalize_post( itype &obj ) } } } + + for( std::string &line : obj.ascii_picture ) { + if( utf8_width( remove_color_tags( line ) ) > ascii_art_width ) { + line = trim_by_length( line, ascii_art_width ); + debugmsg( "ascii_picture in %s contains a line too long to be displayed (>%i char).", obj.id, + ascii_art_width ); + } + } } void Item_factory::finalize() @@ -2082,6 +2093,8 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std: assign( jo, "magazine_well", def.magazine_well ); assign( jo, "explode_in_fire", def.explode_in_fire ); assign( jo, "insulation", def.insulation_factor ); + assign( jo, "ascii_picture", def.ascii_picture ); + if( jo.has_member( "thrown_damage" ) ) { def.thrown_damage = load_damage_instance( jo.get_array( "thrown_damage" ) ); diff --git a/src/itype.h b/src/itype.h index d4e641aaa2d8f..ad43e6488c89b 100644 --- a/src/itype.h +++ b/src/itype.h @@ -866,6 +866,7 @@ struct itype { std::string snippet_category; translation description; // Flavor text + std::vector ascii_picture; // The container it comes in cata::optional default_container; diff --git a/src/options.cpp b/src/options.cpp index a18bd1ed94b57..0b91f074e5889 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -1728,6 +1728,12 @@ void options_manager::add_options_graphics() true, COPT_CURSES_HIDE ); + add( "ENABLE_ASCII_ART_ITEM", "graphics", + translate_marker( "Enable ASCII art in item descriptions" ), + translate_marker( "When available item description will show a picture of the item in ascii art." ), + true, COPT_NO_HIDE + ); + add_empty_line(); add( "USE_TILES", "graphics", translate_marker( "Use tiles" ), diff --git a/src/output.cpp b/src/output.cpp index 119920f3840a5..b441a8ca4252b 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -209,6 +209,12 @@ void print_colored_text( const catacurses::window &w, const point &p, nc_color & void trim_and_print( const catacurses::window &w, const point &begin, int width, nc_color base_color, const std::string &text ) +{ + std::string sText = trim_by_length( text, width ); + print_colored_text( w, begin, base_color, base_color, sText ); +} + +std::string trim_by_length( const std::string &text, int width ) { std::string sText; if( utf8_width( remove_color_tags( text ) ) > width ) { @@ -251,8 +257,7 @@ void trim_and_print( const catacurses::window &w, const point &begin, int width, } else { sText = text; } - - print_colored_text( w, begin, base_color, base_color, sText ); + return sText; } int print_scrollable( const catacurses::window &w, int begin_line, const std::string &text, diff --git a/src/output.h b/src/output.h index 34c1ae2ae5805..81d36d6448c9c 100644 --- a/src/output.h +++ b/src/output.h @@ -310,6 +310,7 @@ inline int fold_and_print_from( const catacurses::window &w, const point &begin, */ void trim_and_print( const catacurses::window &w, const point &begin, int width, nc_color base_color, const std::string &text ); +std::string trim_by_length( const std::string &text, int width ); template inline void trim_and_print( const catacurses::window &w, const point &begin, const int width, const nc_color base_color, const char *const mes, Args &&... args )