14 #define GETTEXT_DOMAIN "wesnoth-lib" 61 , icon_alignment_(
nullptr)
62 , label_name_(
nullptr)
63 , label_level_(
nullptr)
64 , label_race_(
nullptr)
65 , label_details_(
nullptr)
66 , tree_details_(
nullptr)
67 , button_profile_(
nullptr)
75 icon_type_ = find_widget<image>(
this,
"type_image",
false,
false);
76 icon_race_ = find_widget<image>(
this,
"type_race",
false,
false);
77 icon_alignment_ = find_widget<image>(
this,
"type_alignment",
false,
false);
80 label_name_ = find_widget<label>(
this,
"type_name",
false,
false);
81 label_level_ = find_widget<label>(
this,
"type_level",
false,
false);
82 label_race_ = find_widget<label>(
this,
"type_race_label",
false,
false);
83 label_details_ = find_widget<styled_widget>(
this,
"type_details_minimal",
false,
false);
85 tree_details_ = find_widget<tree_view>(
this,
"type_details",
false,
false);
88 button_profile_ = find_widget<button>(
this,
"type_profile",
false,
false);
103 auto& child_node = header_node.
add_child(type, { {
"name",{ {
"label", label },{
"use_markup",
"true" } } } });
104 auto& child_label = find_widget<styled_widget>(&child_node,
"name",
true);
106 child_label.set_tooltip(
tooltip);
114 std::set<std::string> resistances_table;
116 bool att_def_diff =
false;
117 for(
const utils::string_map::value_type &resist : res) {
118 std::ostringstream line;
122 const int res_att = 100 -
get(resist.first,
true);
123 const int res_def = 100 -
get(resist.first,
false);
125 if(res_att == res_def) {
133 resistances_table.insert(line.str());
136 tooltip <<
"<big>" <<
_(
"Resistances: ") <<
"</big>";
138 tooltip <<
_(
"(Att / Def)");
141 for(
const std::string &line : resistances_table) {
145 return tooltip.str();
150 std::set<terrain_movement> terrain_moves;
152 tooltip <<
"<big>" <<
_(
"Movement Costs:") <<
"</big>";
167 terrain_moves.emplace(info.
name(),
get(terrain));
176 const bool cannot_move = tm.moves > total_movement;
182 }
else if(tm.moves > 1) {
188 tooltip <<
"<span color='" << color <<
"'>";
191 if(cannot_move && (tm.moves > total_movement + 5)) {
197 tooltip <<
"</span>";
200 return tooltip.str();
210 if(attacks.empty()) {
217 "<b>" +
_(
"Attacks") +
"</b>" 220 for(
const auto&
a : attacks) {
221 const std::string range_png = std::string(
"icons/profiles/") +
a.range() +
"_attack.png~SCALE_INTO_SHARP(16,16)";
222 const std::string type_png = std::string(
"icons/profiles/") +
a.type() +
".png~SCALE_INTO_SHARP(16,16)";
232 <<
" " <<
a.name() <<
"</span>").str();
234 auto& subsection = header_node.add_child(
237 {
"image_range", { {
"label", range_png } } },
238 {
"image_type", { {
"label", type_png } } },
239 {
"name", { {
"label", label }, {
"use_markup",
"true" } } },
243 find_widget<styled_widget>(&subsection,
"image_range",
true).
set_tooltip(range);
244 find_widget<styled_widget>(&subsection,
"image_type",
true).
set_tooltip(type);
246 if(!range_png_exists || !type_png_exists) {
258 for(
const auto& pair :
a.special_tooltips()) {
263 (
formatter() <<
"<span size='x-large'>" << pair.first <<
"</span>" <<
"\n" << pair.second).str()
278 mods =
"~RC(" + type.
flag_rgb() +
">" +
283 mods +=
"~XBRZ(2)~SCALE_INTO_SHARP(144,144)" +
image_mods_;
294 std::string l_str =
VGETTEXT(
"Lvl $lvl", {{
"lvl", std::to_string(type.
level())}});
310 const std::string& alignment_name = type.
alignment().to_string();
319 std::stringstream str;
321 str <<
"<span size='large'> </span>" <<
"\n";
325 std::string l_str =
VGETTEXT(
"Lvl $lvl", {{
"lvl", std::to_string(type.
level())}});
326 str << l_str <<
"\n";
346 {
"use_markup",
"true" },
351 {
"use_markup",
"true" },
355 {
"label", (
formatter() <<
"<small>" <<
"<b>" <<
_(
"MP: ") <<
"</b>" << type.
movement() <<
"</small>").str() },
356 {
"use_markup",
"true" },
367 if(tr[
"availability"] !=
"musthave" || name.
empty()) {
371 if(header_node ==
nullptr) {
375 "<b>" +
_(
"Traits") +
"</b>" 393 "<b>" +
_(
"Abilities") +
"</b>" 397 if(!ab.name.empty()) {
402 (
formatter() <<
"<span size='x-large'>" << ab.name <<
"</span>\n" << ab.description).str()
425 mods +=
"~BLIT(" +
overlay +
")";
428 mods +=
"~XBRZ(2)~SCALE_INTO_SHARP(144,144)" +
image_mods_;
438 name =
"<span size='large'>" + u.
type_name() +
"</span>\n";
446 std::string l_str =
VGETTEXT(
"Lvl $lvl", {{
"lvl", std::to_string(u.
level())}});
462 const std::string& alignment_name = u.
alignment().to_string();
471 std::stringstream str;
473 const std::string
name =
"<span size='large'>" + (!u.
name().
empty() ? u.
name() :
" ") +
"</span>";
478 std::string l_str =
VGETTEXT(
"Lvl $lvl", {{
"lvl", std::to_string(u.
level())}});
479 str << l_str <<
"\n";
506 {
"use_markup",
"true" },
511 {
"use_markup",
"true" },
516 {
"use_markup",
"true" },
525 "<b>" +
_(
"Traits") +
"</b>" 543 "<b>" +
_(
"Abilities") +
"</b>" 596 DBG_GUI_P <<
"Parsing unit preview pane " <<
id <<
'\n';
598 load_resolutions<resolution>(cfg);
610 grid = std::make_shared<builder_grid>(child);
618 builder_unit_preview_pane::builder_unit_preview_pane(
const config& cfg)
620 , image_mods_(cfg[
"image_mods"])
628 DBG_GUI_G <<
"Window builder: placed unit preview pane '" <<
id 629 <<
"' with definition '" <<
definition <<
"'.\n";
const std::string image_mods_
play_controller * controller
Base class of a resolution, contains the common keys for a resolution.
static config unit_xp(const unit *u)
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
void set_displayed_type(const unit_type &type)
Displays the stats of a specified unit type.
std::vector< state_definition > state
static int get_acceleration()
resistances & get_resistances()
std::map< std::string, t_string > string_map
const std::string weapon_details_sep
This class represents a single unit of a specific type.
int movement_cost(const t_translation::terrain_code &terrain) const
Get the unit's movement cost on a particular terrain.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
bool terrain_matches(const terrain_code &src, const terrain_code &dest)
Tests whether a specific terrain matches an expression, for matching rules see above.
unit_race::GENDER gender() const
The gender of this unit.
int hitpoints() const
The current number of hitpoints this unit has.
tree_view_node & get_root_node()
const std::string & flag_rgb() const
std::string dgettext(const char *domain, const char *msgid)
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
int experience_needed(bool with_acceleration=true) 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...
int resistance_against(const std::string &damage_name, bool attacker) const
Gets resistance while considering custom WML abilities.
std::string absolute_image() const
The name of the file to game_display (used in menus).
styled_widget * label_details_
A label displays a text, the text can be wrapped but no scrollbars are provided.
void profile_button_callback()
Callback for the profile button.
static std::string _(const char *str)
utils::string_map get_base_resistances() const
Gets resistances without any abilities applied.
std::vector< std::tuple< std::string, t_string, t_string, t_string > > ability_tooltips() const
Gets the names and descriptions of this unit's abilities.
A single unit type that the player may recruit.
const color_t unit_type_color
bool is_nonnull() const
True if this object represents some sentinel values.
const t_string & name(GENDER gender=MALE) const
const terrain_code VOID_TERRAIN
VOID_TERRAIN is used for shrouded hexes.
const unit_type & type() const
This unit's type, accounting for gender and variation.
color_t hp_color() const
Color for this unit's current hitpoints.
void set_displayed_unit(const unit &u)
Displays the stats of a specific unit.
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
static const std::string & leader_crown()
The path to the leader crown overlay.
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...
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
const movetype & movement_type() const
This file contains the settings handling of the widget library.
std::shared_ptr< terrain_type_data > load_terrain_types_data()
Load the appropriate terrain types data to use.
const terrain_code FOGGED
const t_string & type_name() const
The name of the unit in the current language setting.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
color_t xp_color() const
Color for this unit's XP.
void init_grid(const builder_grid &grid_builder)
Initializes and builds the grid.
const t_string & name() const
Gets this unit's translatable display name.
tree_view * tree_details_
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
virtual unsigned get_state() const override
See styled_widget::get_state.
virtual void set_active(const bool active) override
See styled_widget::set_active.
static tree_view_node & add_name_tree_node(tree_view_node &header_node, const std::string &type, const t_string &label, const t_string &tooltip="")
int max_experience() const
The max number of experience points this unit can have.
std::set< t_translation::terrain_code > & encountered_terrains()
const std::vector< ability_metadata > & abilities_metadata() const
boost::optional< const unit_type & > current_type_
int level() const
The current level of this unit.
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
const t_string & type_name() const
Gets the translatable name of this unit's type.
static color_t hp_color_max()
const std::string unicode_figure_dash
void show_unit_description(const unit &u)
Generic locator abstracting the location of an image.
static std::string get_side_color_id(unsigned side)
const color_t weapon_details_color
const std::string unicode_en_dash
int max_hitpoints() const
The max number of hitpoints this unit can have.
std::string resistance_color(const int resistance)
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
std::string signed_percent(int val)
Convert into a percentage (using the Unicode "−" and +0% convention.
attack_itors attacks()
Gets an iterator over this unit's attacks.
resolution(const config &cfg)
const std::string & icon() const
const unit_race * race() const
Gets this unit's race.
const std::string unicode_bullet
void finalize_setup()
Initializes the internal sub-widget pointers.
A generic container base class.
int movement_cost(const t_translation::terrain_code &terrain, bool slowed=false) const
Returns the cost to move through the indicated terrain.
const t_string & name() const
config::const_child_itors possible_traits() const
const std::string & image() const
virtual widget * build() const override
unit_preview_pane_definition(const config &cfg)
const ter_match ALL_OFF_MAP
const std::string weapon_numbers_sep
int experience() const
The current number of experience points this unit has.
UNIT_ALIGNMENT alignment() const
The alignment of this unit.
utils::string_map damage_table() const
Returns a map from attack types to resistances.
const map_location & get_location() const
The current map location this unit is at.
symbol_table string_table
const unit_race * race() const
Never returns nullptr, but may point to the null race.
bool can_advance() const
Checks whether this unit has any options to advance to.
void set_image_mods(const std::string &mods)
Sets the facing of the unit image.
static std::string get_hp_tooltip(const utils::string_map &res, const std::function< int(const std::string &, bool)> &get)
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
int total_movement() const
The maximum moves this unit has.
void print_attack_details(T attacks, tree_view_node &parent_node)
std::string get_icon_path_stem() const
Gets this race's icon path without state/size suffix and extension.
std::string unit_level_tooltip(const int level, const std::vector< std::string > &adv_to_types, const std::vector< config > &adv_to_mods)
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
const_attack_itors attacks() const
int resistance_against(const std::string &damage_name, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
The unit's resistance against a given damage type.
A config object defines a single node in a WML file, with access to child nodes.
static std::string alignment_description(ALIGNMENT align, unit_race::GENDER gender=unit_race::MALE)
tree_view_node & add_child(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
Constructs a new child node.
ALIGNMENT alignment() const
bool file_exists() const
Tests whether the file the locator points at exists.
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
static std::string get_mp_tooltip(int total_movement, std::function< int(t_translation::terrain_code)> get)
Contains the implementation details for lexical_cast and shouldn't be used directly.
tree_view_node & add_node(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
virtual bool get_active() const override
See styled_widget::get_active.
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.