15 #define GETTEXT_DOMAIN "wesnoth-lib"
59 , icon_alignment_(
nullptr)
60 , label_name_(
nullptr)
61 , label_level_(
nullptr)
62 , label_race_(
nullptr)
63 , label_details_(
nullptr)
64 , tree_details_(
nullptr)
65 , button_profile_(
nullptr)
66 , image_mods_(builder.image_mods)
73 icon_type_ = find_widget<drawing>(
"type_image",
false,
false);
74 icon_race_ = find_widget<image>(
"type_race",
false,
false);
78 label_name_ = find_widget<label>(
"type_name",
false,
false);
79 label_level_ = find_widget<label>(
"type_level",
false,
false);
80 label_race_ = find_widget<label>(
"type_race_label",
false,
false);
81 label_details_ = find_widget<styled_widget>(
"type_details_minimal",
false,
false);
83 tree_details_ = find_widget<tree_view>(
"type_details",
false,
false);
101 auto& child_node = header_node.
add_child(
type, { {
"name",{ {
"label",
label },{
"use_markup",
"true" } } } });
113 std::vector<std::string> resistances_table;
115 bool att_def_diff =
false;
116 for(
const utils::string_map_res::value_type &resist : res) {
117 std::ostringstream
line;
121 const int res_att = 100 -
get(resist.first,
true);
122 const int res_def = 100 -
get(resist.first,
false);
124 if(res_att == res_def) {
132 resistances_table.push_back(
line.str());
140 for(
const std::string &
line : resistances_table) {
149 std::set<terrain_movement> terrain_moves;
165 if(
info.is_indivisible() &&
info.is_nonnull()) {
166 terrain_moves.emplace(
info.name(),
get(terrain));
175 const bool cannot_move = tm.moves > total_movement;
176 double movement_red_to_green = 100.0 - 25.0 * tm.moves;
178 std::stringstream move_ss;
180 if(cannot_move && (tm.moves > total_movement + 5)) {
182 }
else if (cannot_move) {
183 move_ss <<
"(" << tm.moves <<
")";
188 const int movement_hexes_per_turn = total_movement / tm.moves;
190 for(
int i = 0;
i < movement_hexes_per_turn; ++
i) {
192 move_ss <<
"\u2b23\u200b";
210 const int attacks_left,
211 const int max_attacks,
214 if(attacks.empty()) {
220 if(max_attacks > 1) {
223 {{
"left", std::to_string(attacks_left)},
224 {
"max", std::to_string(max_attacks)}}),
225 _(
"This unit can attack multiple times per turn."));
228 for(
const auto& a : attacks) {
229 const std::string range_png = std::string(
"icons/profiles/") + a.range() +
"_attack.png~SCALE_INTO(16,16)";
230 const std::string type_png = std::string(
"icons/profiles/") + a.type() +
".png~SCALE_INTO(16,16)";
240 auto& subsection = header_node.add_child(
243 {
"image_range", { {
"label", range_png } } },
244 {
"image_type", { {
"label", type_png } } },
245 {
"name", { {
"label", dmg_label }, {
"use_markup",
"true" } } },
252 if(!range_png_exists || !type_png_exists) {
260 const std::string acc_parry_str = a.accuracy_parry_description();
261 if(!acc_parry_str.empty()) {
266 a.accuracy_parry_tooltip()
270 if(max_attacks > 1) {
280 { {
"num", std::to_string(a.attacks_used())} }))
284 for(
const auto& pair : a.special_tooltips()) {
298 current_type_ =
type;
304 mods =
"~RC(" +
type.flag_rgb() +
">" +
311 icon_type_->set_label((
type.icon().empty() ?
type.image() :
type.icon()) + mods);
316 label_name_->set_use_markup(
true);
320 std::string l_str =
VGETTEXT(
"Lvl $lvl", {{
"lvl", std::to_string(
type.level())}});
324 label_level_->set_use_markup(
true);
328 label_race_ ->set_label(
type.race()->name(
type.genders().front()));
332 icon_race_->set_label(
type.race()->get_icon_path_stem() +
"_30.png");
335 if(icon_alignment_) {
338 icon_alignment_->set_label(
"icons/alignments/alignment_" + alignment_name +
"_30.png");
341 type.genders().front()));
345 std::stringstream str;
351 std::string l_str =
VGETTEXT(
"Lvl $lvl", {{
"lvl", std::to_string(
type.level())}});
352 str << l_str <<
"\n";
358 str <<
_(
"HP: ") <<
type.hitpoints() <<
"\n";
360 str <<
_(
"XP: ") <<
type.experience_needed(
true);
362 label_details_->set_label(str.str());
363 label_details_->set_use_markup(
true);
368 tree_details_->clear();
369 tree_details_->add_node(
"hp_xp_mp", {
372 {
"use_markup",
"true" },
373 {
"tooltip",
get_hp_tooltip(
type.movement_type().get_resistances().damage_table(), [&
type](
const std::string& dt,
bool is_attacker) { return type.resistance_against(dt, is_attacker); }) }
377 {
"use_markup",
"true" },
382 {
"use_markup",
"true" },
391 for(
const auto& tr :
type.possible_traits()) {
393 if(tr[
"availability"] !=
"musthave" || name.
empty()) {
397 if(header_node ==
nullptr) {
406 if(!
type.abilities_metadata().empty()) {
410 for(
const auto& ab :
type.abilities_metadata()) {
411 if(!ab.name.empty()) {
422 print_attack_details(
type.attacks(),
type.max_attacks(),
type.max_attacks(), tree_details_->get_root_node());
426 void unit_preview_pane::set_display_data(
const unit& u)
429 current_type_ = u.
type();
439 mods +=
"~BLIT(" +
overlay +
")";
455 label_name_->set_label(name);
456 label_name_->set_use_markup(
true);
460 std::string l_str =
VGETTEXT(
"Lvl $lvl", {{
"lvl", std::to_string(u.
level())}});
464 label_level_->set_use_markup(
true);
475 if(icon_alignment_) {
478 icon_alignment_->set_label(
"icons/alignments/alignment_" + alignment_name +
"_30.png");
485 std::stringstream str;
492 std::string l_str =
VGETTEXT(
"Lvl $lvl", {{
"lvl", std::to_string(u.
level())}});
493 str << l_str <<
"\n";
507 label_details_->set_label(str.str());
508 label_details_->set_use_markup(
true);
512 tree_details_->clear();
514 tree_details_->add_node(
"hp_xp_mp", {
517 {
"use_markup",
"true" },
518 {
"tooltip",
get_hp_tooltip(u.
get_base_resistances(), [&u](
const std::string& dt,
bool is_attacker) { return u.resistance_against(dt, is_attacker, u.get_location()); }) }
522 {
"use_markup",
"true" },
527 {
"use_markup",
"true" },
562 void unit_preview_pane::profile_button_callback()
569 void unit_preview_pane::set_image_mods(
const std::string& mods)
574 void unit_preview_pane::set_active(
const bool )
579 bool unit_preview_pane::get_active()
const
584 unsigned unit_preview_pane::get_state()
const
589 void unit_preview_pane::set_self_active(
const bool )
596 unit_preview_pane_definition::unit_preview_pane_definition(
const config&
cfg)
601 load_resolutions<resolution>(
cfg);
611 grid = std::make_shared<builder_grid>(child);
619 builder_unit_preview_pane::builder_unit_preview_pane(
const config&
cfg)
621 , image_mods(
cfg[
"image_mods"])
627 auto widget = std::make_unique<unit_preview_pane>(*
this);
629 DBG_GUI_G <<
"Window builder: placed unit preview pane '" <<
id
630 <<
"' with definition '" <<
definition <<
"'.";
635 widget->init_grid(*conf->grid);
A config object defines a single node in a WML file, with access to child nodes.
A generic container base class.
tree_view_node & add_child(const std::string &id, const widget_data &data, const int index=-1)
Constructs a new child node.
void profile_button_callback()
Callback for the profile button.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
styled_widget * label_details_
void print_attack_details(T attacks, const int attacks_left, const int max_attacks, tree_view_node &parent_node)
tree_view * tree_details_
void finalize_setup()
Initializes the internal sub-widget pointers.
static std::string get_side_color_id(unsigned side)
std::string get_icon_path_stem() const
Gets this race's icon path without state/size suffix and extension.
const t_string & name(GENDER gender=MALE) const
A single unit type that the player may recruit.
static std::string alignment_description(unit_alignments::type align, unit_race::GENDER gender=unit_race::MALE)
Implementation detail of unit_type::alignment_description.
This class represents a single unit of a specific type.
static const std::string & leader_crown()
The path to the leader crown overlay.
static std::string _(const char *str)
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.
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
int max_hitpoints() const
The max number of hitpoints this unit can have.
unit_alignments::type alignment() const
The alignment of this unit.
int level() const
The current level of this unit.
const t_string & type_name() const
Gets the translatable name of this unit's type.
int hitpoints() const
The current number of hitpoints this unit has.
const unit_race * race() const
Gets this unit's race.
const unit_type & type() const
This unit's type, accounting for gender and variation.
int experience() const
The current number of experience points this unit has.
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
int max_experience() const
The max number of experience points this unit can have.
unit_race::GENDER gender() const
The gender of this unit.
const t_string & name() const
Gets this unit's translatable display name.
bool can_advance() const
Checks whether this unit has any options to advance to.
attack_itors attacks()
Gets an iterator over this unit's attacks.
utils::string_map_res get_base_resistances() const
Gets resistances without any abilities applied.
int attacks_left() const
Gets the remaining number of attacks this unit can perform this turn.
color_t xp_color() const
Color for this unit's XP.
color_t hp_color() const
Color for this unit's current hitpoints.
static color_t hp_color_max()
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
std::string absolute_image() const
The name of the file to game_display (used in menus).
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
int total_movement() const
The maximum moves this unit has.
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
std::string tooltip
Shown when hovering over an entry in the filter's drop-down list.
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
const std::string weapon_details_sep
const color_t unit_type_color
const std::string unicode_bullet
const color_t weapon_details_color
const std::string unicode_en_dash
const std::string unicode_figure_dash
const std::string weapon_numbers_sep
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....
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
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="")
static std::string get_mp_tooltip(int total_movement, const std::function< int(t_translation::terrain_code)> &get)
static std::string get_hp_tooltip(const utils::string_map_res &res, const std::function< int(const std::string &, bool)> &get)
std::shared_ptr< terrain_type_data > load_terrain_types_data()
Load the appropriate terrain types data to use.
void show_unit_description(const unit &u)
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::string bold(Args &&... data)
Applies bold Pango markup to the input.
std::string span_color(const color_t &color, Args &&... data)
Applies Pango markup to the input specifying its display color.
std::string tag(std::string_view tag, Args &&... data)
Wraps the given data in the specified tag.
std::string span_size(std::string_view size, Args &&... data)
Applies Pango markup to the input specifying its display size.
play_controller * controller
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.
const ter_match ALL_OFF_MAP
const terrain_code FOGGED
std::string dgettext(const char *domain, const char *msgid)
static std::string unit_level_tooltip(const int level, const std::vector< std::string > &adv_to_types, const std::vector< config > &adv_to_mods)
std::string resistance_color(const int resistance)
Maps resistance <= -60 (resistance value <= -60%) to intense red.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
std::map< std::string, t_string, res_compare > string_map_res
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::string signed_percent(int val)
Convert into a percentage (using the Unicode "−" and +0% convention.
SDL_Window * get_window()
static config unit_xp(const unit *u)
virtual std::unique_ptr< widget > build() const override
std::vector< state_definition > state
resolution(const config &cfg)
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
static int get_acceleration()
std::string missing_mandatory_wml_tag(const std::string §ion, const std::string &tag)
Returns a standard message for a missing wml child (tag).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WML_CHILD(cfg, key, message)