16 #define GETTEXT_DOMAIN "wesnoth-help"
41 #define WRN_HP LOG_STREAM(warn, log_help)
42 #define DBG_HP LOG_STREAM(debug, log_help)
63 std::string lang_policy = (best ?
_(
"Best of") :
_(
"Worst of"));
64 std::string color_policy = (best ?
"green":
"red");
66 return "<format>color='" + color_policy +
"' text='" + lang_policy +
"'</format>";
69 typedef t_translation::ter_list::const_iterator
ter_iter;
74 if (
start == end)
return "";
77 std::optional<ter_iter> last_change_pos;
79 bool best = begin_best;
89 if (!last_change_pos) {
90 std::vector<std::string>
names;
97 if (
names.empty())
return "";
101 if (!first_level) ss <<
"( ";
104 for (std::size_t
i = 1;
i <
names.size();
i++) {
105 ss <<
", " <<
names.at(
i);
108 if (!first_level) ss <<
" )";
110 std::vector<std::string>
names;
111 for (
ter_iter i = *last_change_pos+1;
i != end; ++
i) {
122 if (!first_level) ss <<
"( ";
125 for (
const std::string &
s :
names) {
128 if (!first_level) ss <<
" )";
134 std::stringstream ss;
137 ss <<
"<img>src='images/buttons/icon-base-32.png~RC(magenta>" <<
type_.
id()
138 <<
")~BLIT("<<
"terrain/" <<
type_.
icon_image() <<
"_30.png)" <<
"'</img> ";
151 WRN_HP <<
"When building terrain help topics, we couldn't acquire any terrain types data";
157 std::vector<std::string> special_notes;
160 special_notes.push_back(
_(
"Villages allow any unit stationed therein to heal, or to be cured of poison."));
165 auto message =
VNGETTEXT(
"This terrain allows units to be cured of poison, or to heal a single hitpoint.",
166 "This terrain allows units to heal $amount hitpoints, or to be cured of poison, as if stationed in a village.",
168 special_notes.push_back(std::move(message));
172 special_notes.push_back(
_(
"This terrain is a castle — units can be recruited onto it from a connected keep."));
176 special_notes.push_back(
_(
"This terrain is a keep — a leader can recruit from this hex onto connected castle hexes."));
179 special_notes.push_back(
_(
"This unusual keep allows a leader to recruit while standing on it, but does not allow a leader on a connected keep to recruit onto this hex."));
182 if(!special_notes.empty()) {
183 ss <<
"\n" <<
_(
"Special Notes:") <<
'\n';
184 for(
const auto& note : special_notes) {
192 ss <<
"\n" <<
_(
"Base Terrain: ");
196 const terrain_type& base = tdata->get_terrain_info(underlying_terrain);
212 ss <<
"\n" <<
_(
"Movement properties: ");
216 ss <<
"\n" <<
_(
"Defense properties: ");
223 ss <<
"ID: " <<
type_.
id() <<
"\n";
228 ss <<
"Keep: " << (
type_.
is_keep() ?
"Yes" :
"No") <<
"\n";
235 ss <<
"Terrain string: " <<
type_.
number() <<
"\n";
245 ss <<
"\nEditor Image: Empty\n";
251 ss <<
"\nDebug Mvt Description String:";
257 ss <<
"\nDebug Def Description String:";
279 for(
i++;
i < l.size();
i++) {
288 std::stringstream ss;
289 std::string clear_stringstream;
299 ss <<
"<img>src='" << male_type.
image();
300 ss <<
"~RC(" << male_type.
flag_rgb() <<
">red)";
301 if (
screen_width >= 1200) ss <<
"~SCALE_SHARP(200%,200%)";
302 ss <<
"' box='no'</img> ";
304 if (female_type.
image() != male_type.
image()) {
305 ss <<
"<img>src='" << female_type.
image();
306 ss <<
"~RC(" << female_type.
flag_rgb() <<
">red)";
307 if (
screen_width >= 1200) ss <<
"~SCALE_SHARP(200%,200%)";
308 ss <<
"' box='no'</img> ";
311 const std::string &male_portrait = male_type.
small_profile().empty() ?
313 const std::string &female_portrait = female_type.
small_profile().empty() ?
316 const bool has_male_portrait = !male_portrait.empty() && male_portrait != male_type.
image() && male_portrait !=
"unit_image";
317 const bool has_female_portrait = !female_portrait.empty() && female_portrait != male_portrait && female_portrait != female_type.
image() && female_portrait !=
"unit_image";
319 int sz = (has_male_portrait && has_female_portrait ? 300 : 400);
321 sz = (has_male_portrait && has_female_portrait ? 200 : 300);
331 if (has_male_portrait) {
332 ss <<
"<img>src='" << male_portrait <<
"~FL(horiz)~SCALE_INTO(" << sz <<
',' << sz <<
")' box='no' align='right' float='yes'</img> ";
336 if (has_female_portrait) {
337 ss <<
"<img>src='" << female_portrait <<
"~FL(horiz)~SCALE_INTO(" << sz <<
',' << sz <<
")' box='no' align='right' float='yes'</img> ";
344 const bool first_reverse_value =
true;
345 bool reverse = first_reverse_value;
348 std::vector<std::string> adv_units =
352 for (
const std::string &adv : adv_units) {
360 ss <<
_(
"Advances from: ");
362 ss <<
_(
"Advances to: ");
369 std::string lang_unit =
type->type_name();
372 const std::string section_prefix =
type->show_variations_in_help() ?
".." :
"";
385 }
while(reverse != first_reverse_value);
396 ss <<
_(
"Base units: ");
406 for (
const std::string &var_id : parent->
variations()) {
409 if(
type.hide_help()) {
414 ss <<
_(
"Variations: ");
422 std::string var_name =
type.variation_name();
437 if (race_name.empty()) {
438 race_name =
_ (
"race^Miscellaneous");
441 ss <<
make_link(race_name,
"..race_" + race_id);
447 std::vector<trait_data> must_have_traits;
448 std::vector<trait_data> random_traits;
449 int must_have_nameless_traits = 0;
451 for(
const config& trait : traits) {
452 const std::string& male_name = trait[
"male_name"].str();
453 const std::string& female_name = trait[
"female_name"].str();
454 std::string trait_name;
456 trait_name = male_name;
458 trait_name = female_name;
459 else if (! trait[
"name"].str().empty())
460 trait_name = trait[
"name"].str();
465 if (lang_trait_name.empty() && trait[
"availability"].str() ==
"musthave") {
466 ++must_have_nameless_traits;
469 const std::string ref_id =
"traits_"+trait[
"id"].str();
470 ((trait[
"availability"].str() ==
"musthave") ? must_have_traits : random_traits).emplace_back(lang_trait_name, ref_id);
473 bool line1 = !must_have_traits.empty();
474 bool line2 = !random_traits.empty() &&
type_.
num_traits() > must_have_traits.size();
477 std::string traits_label =
_(
"Traits");
480 std::stringstream must_have_count;
481 must_have_count <<
" (" << must_have_traits.size() <<
") : ";
482 std::stringstream random_count;
483 random_count <<
" (" << (
type_.
num_traits() - must_have_traits.size() - must_have_nameless_traits) <<
") : ";
489 ss << must_have_count.str();
491 ss <<
"\n" <<
jump(second_line_whitespace) << random_count.str();
500 ss <<
_(
"Traits") <<
" (" << (
type_.
num_traits() - must_have_nameless_traits) <<
") : ";
510 ss <<
_(
"Abilities: ");
515 const std::string ref_id =
ability_prefix + iter->id + iter->name.base_str();
517 if(iter->name.empty()) {
536 ss <<
_(
"Ability Upgrades: ");
541 const std::string ref_id =
ability_prefix + iter->id + iter->name.base_str();
543 if(iter->name.empty()) {
601 ss <<
"\n\n" << detailed_description;
603 ss <<
"\n\n" <<
_(
"Special Notes:") <<
'\n';
604 for(
const auto& note : notes) {
610 const auto padding = 4;
615 ss <<
"\n\n<header>text='" <<
escape(
_(
"unit help^Attacks"))
619 std::vector<item> first_row;
621 first_row.push_back(
item(
"", 0));
627 table.push_back(first_row);
630 std::string lang_weapon = attack.name();
631 std::string lang_type =
string_table[
"type_" + attack.type()];
632 std::vector<item> row;
633 std::stringstream attack_ss;
636 attack_ss <<
"<img>src='" << attack.icon() <<
"'</img>";
637 row.emplace_back(attack_ss.str(),
image_width(attack.icon()));
638 attack_ss.str(clear_stringstream);
645 <<
" " << attack.accuracy_parry_description();
647 attack_ss.str(clear_stringstream);
650 const std::string range_icon =
"icons/profiles/" + attack.range() +
"_attack.png~SCALE_INTO(16,16)";
651 if (attack.min_range() > 1 || attack.max_range() > 1) {
652 attack_ss << attack.min_range() <<
"-" << attack.max_range() <<
' ';
656 attack_ss.str(clear_stringstream);
659 const std::string type_icon =
"icons/profiles/" + attack.type() +
".png~SCALE_INTO(16,16)";
664 std::vector<std::pair<t_string, t_string>> specials = attack.special_tooltips();
665 if (!specials.empty()) {
666 std::string lang_special =
"";
667 const std::size_t specials_size = specials.size();
668 for (std::size_t
i = 0;
i != specials_size; ++
i) {
669 const std::string ref_id = std::string(
"weaponspecial_")
670 + specials[
i].first.base_str();
671 lang_special = (specials[
i].first);
672 attack_ss <<
make_link(lang_special, ref_id);
673 if (
i+1 != specials_size) {
679 table.push_back(row);
688 for (
const config &
t : traits) {
689 if (
t[
"availability"].str() ==
"musthave") {
690 for (
const config & effect :
t.child_range(
"effect")) {
691 if (!effect.has_child(
"filter")
693 movement_type.
merge(effect, effect[
"replace"].to_bool());
701 ss <<
"\n\n<header>text='" <<
escape(
_(
"Resistances"))
704 std::vector<item> first_res_row;
707 resistance_table.push_back(first_res_row);
709 for(std::pair<std::string, std::string> dam_it : dam_tab) {
710 std::vector<item> row;
711 int resistance = 100;
713 resistance -= std::stoi(dam_it.second);
714 }
catch(std::invalid_argument&) {}
715 std::string resist = std::to_string(resistance) +
'%';
716 const std::size_t pos = resist.find(
'-');
717 if (pos != std::string::npos) {
721 const std::string lang_type =
string_table[
"type_" + dam_it.first];
722 const std::string type_icon =
"icons/profiles/" + dam_it.first +
".png~SCALE_INTO(16,16)";
724 std::stringstream str;
725 str <<
"<format>color=\"" << color <<
"\" text='"<< resist <<
"'</format>";
726 const std::string markup = str.str();
727 str.str(clear_stringstream);
730 resistance_table.push_back(row);
736 ss <<
"\n\n<header>text='" <<
escape(
_(
"Terrain Modifiers"))
738 std::vector<item> first_row;
745 if (has_terrain_defense_caps) {
758 table.push_back(first_row);
760 std::set<terrain_movement_info> terrain_moves;
769 if (cannot_move &&
info.hide_if_impassable()) {
773 if (
info.is_indivisible() &&
info.is_nonnull()) {
785 terrain_moves.insert(movement_info);
791 std::vector<item> row;
793 bool high_res =
false;
794 const std::string tc_base = high_res ?
"images/buttons/icon-base-32.png" :
"images/buttons/icon-base-16.png";
795 const std::string terrain_image =
"icons/terrain/terrain_type_" + m.id + (high_res ?
"_30.png" :
".png");
797 const std::string final_image = tc_base +
"~RC(magenta>" + m.id +
")~BLIT(" + terrain_image +
")";
799 row.emplace_back(
"<img>src='" + final_image +
"'</img> " +
807 std::stringstream str;
808 std::stringstream str_unformatted;
809 str <<
"<format>color='" << color <<
"' text='"<< m.defense <<
"%'</format>";
810 str_unformatted << m.defense <<
"%";
814 str.str(clear_stringstream);
815 str_unformatted.str(clear_stringstream);
817 double movement_red_to_green = 100.0 - 25.0 * m.movement_cost;
821 str <<
"<format>color='" << movement_color <<
"' text='";
824 if(cannot_move && (m.movement_cost >
type_.
movement() + 5)) {
826 }
else if(cannot_move) {
827 str_unformatted <<
"(" << m.movement_cost <<
")";
829 str_unformatted << m.movement_cost;
831 if(m.movement_cost != 0) {
832 const int movement_hexes_per_turn =
type_.
movement() / m.movement_cost;
833 str_unformatted <<
" ";
834 for(
int i = 0;
i < movement_hexes_per_turn; ++
i) {
836 str_unformatted <<
"\u2b23\u200b";
839 str << str_unformatted.str() <<
"'</format>";
843 if (has_terrain_defense_caps) {
844 str.str(clear_stringstream);
845 str_unformatted.str(clear_stringstream);
847 str <<
"<format>color='"<< color <<
"' text='" << m.defense <<
"%'</format>";
848 str_unformatted << m.defense <<
"%";
858 str.str(clear_stringstream);
859 str_unformatted.str(clear_stringstream);
860 const bool cannot_view = m.vision_cost >
type_.
vision();
861 double vision_red_to_green = 100.0 - 25.0 * m.vision_cost;
865 str <<
"<format>color='" << vision_color <<
"' text='";
868 if(cannot_view && (m.vision_cost >
type_.
vision() + 5)) {
870 }
else if(cannot_view) {
871 str_unformatted <<
"(" << m.vision_cost <<
")";
873 str_unformatted << m.vision_cost;
875 if(m.vision_cost != 0) {
876 const int vision_hexes_per_turn =
type_.
vision() / m.vision_cost;
877 str_unformatted <<
" ";
878 for(
int i = 0;
i < vision_hexes_per_turn; ++
i) {
880 str_unformatted <<
"\u2b23\u200b";
883 str << str_unformatted.str() <<
"'</format>";
889 str.str(clear_stringstream);
890 str_unformatted.str(clear_stringstream);
891 const bool cannot_jam = m.jamming_cost >
type_.
jamming();
892 double jamming_red_to_green = 100.0 - 25.0 * m.jamming_cost;
896 str <<
"<format>color='" << jamming_color <<
"' text='";
899 if (cannot_jam && m.jamming_cost >
type_.
jamming() + 5) {
901 }
else if(cannot_jam) {
902 str_unformatted <<
"(" << m.jamming_cost <<
")";
904 str_unformatted << m.jamming_cost;
906 if(m.jamming_cost != 0) {
907 const int jamming_hexes_per_turn =
type_.
jamming() / m.jamming_cost;
908 str_unformatted <<
" ";
909 for(
int i = 0;
i < jamming_hexes_per_turn; ++
i) {
911 str_unformatted <<
"\u2b23\u200b";
914 str << str_unformatted.str() <<
"'</format>";
918 table.push_back(row);
923 WRN_HP <<
"When building unit help topics, the display object was null and we couldn't get the terrain info we need.";
std::vector< std::string > names
A config object defines a single node in a WML file, with access to child nodes.
boost::iterator_range< const_child_iterator > const_child_itors
const terrain_type & type_
virtual std::string operator()() const
virtual std::string operator()() const
void push_header(std::vector< help::item > &row, const std::string &name) const
const std::string variation_
bool capped(const t_translation::terrain_code &terrain) const
Returns whether there is a defense cap associated to this terrain.
The basic "size" of the unit - flying, small land, large land, etc.
static const std::set< std::string > effects
The set of applicable effects for movement types.
void merge(const config &new_cfg, bool overwrite=true)
Merges the given config over the existing data, the config should have zero or more children named "m...
bool has_vision_data() const
Returns whether or not there are any vision-specific costs.
bool has_jamming_data() const
Returns whether or not there are any jamming-specific costs.
bool has_terrain_defense_caps(const std::set< t_translation::terrain_code > &ts) const
Returns whether or not there are any terrain caps with respect to a set of terrains.
int defense_modifier(const t_translation::terrain_code &terrain) const
Returns the defensive value of the indicated terrain.
int jamming_cost(const t_translation::terrain_code &terrain, bool slowed=false) const
Returns the cost to "jam" through the indicated terrain.
int vision_cost(const t_translation::terrain_code &terrain, bool slowed=false) const
Returns the cost to see through the indicated terrain.
int movement_cost(const t_translation::terrain_code &terrain, bool slowed=false) const
Returns the cost to move through the indicated terrain.
utils::string_map_res damage_table() const
Returns a map from attack types to resistances.
terrain_defense & get_defense()
const std::string & str() const
const std::string & editor_group() const
const std::string & icon_image() const
const t_string & income_description() const
bool is_combined() const
True for instances created by the terrain_code(base, overlay) constructor.
const std::string & editor_image() const
bool is_nonnull() const
True if this object represents some sentinel values.
const std::string & id() const
const t_string & help_topic_text() const
const t_translation::ter_list & def_type() const
const t_translation::ter_list & mvt_type() const
The underlying type of the terrain.
int light_bonus(int base) const
Returns the light (lawful) bonus for this terrain when the time of day gives a base bonus.
const t_translation::ter_list & union_type() const
static bool is_indivisible(t_translation::terrain_code id, const t_translation::ter_list &underlying)
Returns true if a terrain has no underlying types other than itself, in respect of either union,...
const t_string & editor_name() const
int gives_healing() const
bool hide_in_editor() const
t_translation::terrain_code number() const
const t_string & plural_name() const
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
void build_unit_type(const unit_type &ut, unit_type::BUILD_STATUS status) const
Makes sure the provided unit_type is built to the specified level.
A single unit type that the player may recruit.
const std::vector< std::string > advances_from() const
A vector of unit_type ids that can advance to this unit_type.
std::string race_id() const
Returns the ID of this type's race without the need to build the type.
static std::string alignment_description(unit_alignments::type align, unit_race::GENDER gender=unit_race::MALE)
Implementation detail of unit_type::alignment_description.
const std::string & image() const
const std::string & id() const
The id for this unit_type.
const std::vector< ability_metadata > & adv_abilities_metadata() const
Some extra abilities that may be gained through AMLA advancements.
const movetype & movement_type() const
bool show_variations_in_help() const
Whether the unit type has at least one help-visible variation.
const unit_race * race() const
Never returns nullptr, but may point to the null race.
const unit_type & get_variation(const std::string &id) const
const_attack_itors attacks() const
const std::vector< std::string > & advances_to() const
A vector of unit_type ids that this unit_type can advance to.
bool has_gender_variation(const unit_race::GENDER gender) const
t_string unit_description() const
const std::vector< unit_race::GENDER > & genders() const
The returned vector will not be empty, provided this has been built to the HELP_INDEXED status.
std::vector< std::string > variations() const
const std::string & flag_rgb() const
std::vector< t_string > special_notes() const
Returns all notes that should be displayed in the help page for this type, including those found in a...
config::const_child_itors modification_advancements() const
Returns two iterators pointing to a range of AMLA configs.
const unit_type & get_gender_unit_type(std::string gender) const
Returns a gendered variant of this unit_type.
int experience_needed(bool with_acceleration=true) const
const std::string & big_profile() const
const t_string & type_name() const
The name of the unit in the current language setting.
config::const_child_itors possible_traits() const
unit_alignments::type alignment() const
const std::string & small_profile() const
const std::vector< ability_metadata > & abilities_metadata() const
const config & get_cfg() const
unsigned int num_traits() const
static std::string _(const char *str)
static lg::log_domain log_help("help")
symbol_table string_table
Standard logging facilities (interface).
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
int pango_line_width(const std::string &line, int font_size, font::pango_text::FONT_STYLE font_style=font::pango_text::STYLE_NORMAL)
Determine the width of a line of text given a certain font size.
const std::string unicode_bullet
const std::string unicode_figure_dash
const std::string weapon_numbers_sep
const std::string unicode_minus
color_t red_to_green(double val, bool for_text)
Return a color corresponding to the value val red for val=0.0 to green for val=100....
unsigned screen_width
The screen resolution and pixel pitch should be available for all widgets since their drawing method ...
std::string bold(const std::string &s)
std::string make_link(const std::string &text, const std::string &dst)
std::string escape(const std::string &s)
Prepend all chars with meaning inside attributes with a backslash.
static std::string print_behavior_description(ter_iter start, ter_iter end, const std::shared_ptr< terrain_type_data > &tdata, bool first_level=true, bool begin_best=true)
t_translation::ter_list::const_iterator ter_iter
const std::string unit_prefix
unsigned image_width(const std::string &filename)
const std::string variation_prefix
UNIT_DESCRIPTION_TYPE description_type(const unit_type &type)
Return the type of description that should be shown for a unit of the given kind.
const std::string ability_prefix
std::vector< std::vector< help::item > > table_spec
void push_tab_pair(std::vector< help::item > &v, const std::string &s, const std::optional< std::string > &image, unsigned padding)
std::pair< std::string, unsigned > item
std::pair< std::string, std::string > trait_data
const int normal_font_size
std::string generate_table(const table_spec &tab, const unsigned int spacing)
const std::string terrain_prefix
const std::string unknown_unit_topic
std::shared_ptr< terrain_type_data > load_terrain_types_data()
Load the appropriate terrain types data to use.
static std::string best_str(bool best)
std::string jump(const unsigned amount)
static void print_trait_list(std::stringstream &ss, const std::vector< trait_data > &l)
std::set< t_translation::terrain_code > & encountered_terrains()
const terrain_code VOID_TERRAIN
VOID_TERRAIN is used for shrouded hexes.
bool terrain_matches(const terrain_code &src, const terrain_code &dest)
Tests whether a specific terrain matches an expression, for matching rules see above.
std::vector< terrain_code > ter_list
const ter_match ALL_OFF_MAP
const terrain_code FOGGED
static std::string gettext(const char *str)
int icompare(const std::string &s1, const std::string &s2)
Case-insensitive lexicographical comparison.
std::string resistance_color(const int resistance)
Maps resistance <= -60 (resistance value <= -60%) to intense red.
std::map< std::string, t_string, res_compare > string_map_res
std::map< std::string, t_string > string_map
std::vector< std::string > split(const config_attribute_value &val)
point game_canvas_size()
The size of the game canvas, in drawing coordinates / game pixels.
int get_pixel_scale()
Get the current active pixel scale multiplier.
Transitional API for porting SDL_ttf-based code to Pango.
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
bool operator<(const terrain_movement_info &other) const
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
static map_location::DIRECTION s
unit_type_data unit_types