The Battle for Wesnoth  1.19.10+dev
unit_preview_pane.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2025
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 
21 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/drawing.hpp"
23 #include "gui/widgets/image.hpp"
24 #include "gui/widgets/label.hpp"
27 
28 #include "formatter.hpp"
29 #include "formula/string_utils.hpp"
30 #include "language.hpp"
32 #include "gettext.hpp"
33 #include "help/help.hpp"
34 #include "help/help_impl.hpp"
35 #include "play_controller.hpp"
36 #include "resources.hpp"
37 #include "serialization/markup.hpp"
38 #include "team.hpp"
39 #include "terrain/movement.hpp"
40 #include "terrain/type_data.hpp"
41 #include "units/types.hpp"
42 #include "units/helper.hpp"
43 #include "units/unit.hpp"
44 #include "wml_exception.hpp"
45 
46 #include <functional>
47 
48 namespace gui2
49 {
50 
51 // ------------ WIDGET -----------{
52 
53 REGISTER_WIDGET(unit_preview_pane)
54 
55 unit_preview_pane::unit_preview_pane(const implementation::builder_unit_preview_pane& builder)
56  : container_base(builder, type())
57  , current_type_()
58  , icon_type_(nullptr)
59  , icon_race_(nullptr)
60  , icon_alignment_(nullptr)
61  , label_name_(nullptr)
62  , label_level_(nullptr)
63  , label_race_(nullptr)
64  , label_details_(nullptr)
65  , tree_details_(nullptr)
66  , button_profile_(nullptr)
67  , image_mods_(builder.image_mods)
68 {
69 }
70 
72 {
73  // Icons
74  icon_type_ = find_widget<drawing>("type_image", false, false);
75  icon_race_ = find_widget<image>("type_race", false, false);
76  icon_alignment_ = find_widget<image>("type_alignment", false, false);
77 
78  // Labels
79  label_name_ = find_widget<label>("type_name", false, false);
80  label_level_ = find_widget<label>("type_level", false, false);
81  label_race_ = find_widget<label>("type_race_label", false, false);
82  label_details_ = find_widget<styled_widget>("type_details_minimal", false, false);
83 
84  tree_details_ = find_widget<tree_view>("type_details", false, false);
85 
86  // Profile button
87  button_profile_ = find_widget<button>("type_profile", false, false);
88 
89  if(button_profile_) {
92  }
93 }
94 
95 static inline tree_view_node& add_name_tree_node(tree_view_node& header_node, const std::string& type, const t_string& label, const t_string& tooltip = "")
96 {
97  /* Note: We have to pass data instead of just doing 'child_label.set_label(label)' below
98  * because the tree_view_node::add_child needs to have the correct size of the
99  * node child widgets for its internal size calculations.
100  * Same is true for 'use_markup'
101  */
102  auto& child_node = header_node.add_child(type, { { "name",{ { "label", label },{ "use_markup", "true" } } } });
103  auto& child_label = child_node.find_widget<styled_widget>("name", true);
104 
105  child_label.set_tooltip(tooltip);
106  return child_node;
107 }
108 
109 static inline std::string get_hp_tooltip(
110  const utils::string_map_res& res, const std::function<int(const std::string&, bool)>& get)
111 {
112  std::ostringstream tooltip;
113 
114  std::vector<std::string> resistances_table;
115 
116  bool att_def_diff = false;
117  for(const utils::string_map_res::value_type &resist : res) {
118  std::ostringstream line;
119  line << translation::dgettext("wesnoth", resist.first.c_str()) << ": ";
120 
121  // Some units have different resistances when attacking or defending.
122  const int res_att = 100 - get(resist.first, true);
123  const int res_def = 100 - get(resist.first, false);
124 
125  if(res_att == res_def) {
127  } else {
130  att_def_diff = true;
131  }
132 
133  resistances_table.push_back(line.str());
134  }
135 
136  tooltip << markup::tag("big", _("Resistances: "));
137  if(att_def_diff) {
138  tooltip << _("(Att / Def)");
139  }
140 
141  for(const std::string &line : resistances_table) {
142  tooltip << '\n' << font::unicode_bullet << " " << line;
143  }
144 
145  return tooltip.str();
146 }
147 
148 static inline std::string get_mp_tooltip(int total_movement, const std::function<int (t_translation::terrain_code)>& get)
149 {
150  std::set<terrain_movement> terrain_moves;
151  std::ostringstream tooltip;
152  tooltip << markup::tag("big", _("Movement Costs:"));
153 
154  std::shared_ptr<terrain_type_data> tdata = help::load_terrain_types_data();
155 
156  if(!tdata) {
157  return "";
158  }
159 
160  for(t_translation::terrain_code terrain : prefs::get().encountered_terrains()) {
162  continue;
163  }
164 
165  const terrain_type& info = tdata->get_terrain_info(terrain);
166  if(info.is_indivisible() && info.is_nonnull()) {
167  terrain_moves.emplace(info.name(), get(terrain));
168  }
169  }
170 
171  for(const terrain_movement& tm: terrain_moves)
172  {
173  tooltip << '\n' << font::unicode_bullet << " " << tm.name << ": ";
174 
175  // movement - range: 1 .. 5, movetype::UNREACHABLE=impassable
176  const bool cannot_move = tm.moves > total_movement; // cannot move in this terrain
177  double movement_red_to_green = 100.0 - 25.0 * tm.moves;
178 
179  std::stringstream move_ss;
180  // A 5 MP margin; if the movement costs go above the unit's max moves + 5, we replace it with dashes.
181  if(cannot_move && (tm.moves > total_movement + 5)) {
182  move_ss << font::unicode_figure_dash;
183  } else if (cannot_move) {
184  move_ss << "(" << tm.moves << ")";
185  } else {
186  move_ss << tm.moves;
187  }
188  if(tm.moves != 0) {
189  const int movement_hexes_per_turn = total_movement / tm.moves;
190  tooltip << " ";
191  for(int i = 0; i < movement_hexes_per_turn; ++i) {
192  // Unicode horizontal black hexagon and Unicode zero width space (to allow a line break)
193  move_ss << "\u2b23\u200b";
194  }
195  }
196 
197  // passing true to select the less saturated red-to-green scale
198  tooltip << markup::span_color(game_config::red_to_green(movement_red_to_green, true), move_ss.str());
199  }
200 
201  return tooltip.str();
202 }
203 
204 /*
205  * Both unit and unit_type use the same format (vector of attack_types) for their
206  * attack data, meaning we can keep this as a helper function.
207  */
208 template<typename T>
210  T attacks,
211  const int attacks_left,
212  const int max_attacks,
213  tree_view_node& parent_node)
214 {
215  if(attacks.empty()) {
216  return;
217  }
218 
219 
220  auto& header_node = add_name_tree_node(parent_node, "header", markup::bold(_("Attacks")));
221 
222  if (max_attacks > 1) {
223  add_name_tree_node(header_node, "item",
224  VGETTEXT("Remaining: $left/$max",
225  {{"left", std::to_string(attacks_left)},
226  {"max", std::to_string(max_attacks)}}),
227  _("This unit can attack multiple times per turn."));
228  }
229 
230  for(const auto& a : attacks) {
231  const std::string range_png = std::string("icons/profiles/") + a.range() + "_attack.png~SCALE_INTO(16,16)";
232  const std::string type_png = std::string("icons/profiles/") + a.type() + ".png~SCALE_INTO(16,16)";
233  const bool range_png_exists = ::image::exists(range_png);
234  const bool type_png_exists = ::image::exists(type_png);
235 
236  const t_string& range = string_table["range_" + a.range()];
237  const t_string& type = string_table["type_" + a.type()];
238 
239  const std::string label = markup::span_color(
240  font::unit_type_color, a.damage(), font::weapon_numbers_sep, a.num_attacks(), " ", a.name());
241 
242  auto& subsection = header_node.add_child(
243  "item_image",
244  {
245  { "image_range", { { "label", range_png } } },
246  { "image_type", { { "label", type_png } } },
247  { "name", { { "label", label }, { "use_markup", "true" } } },
248  }
249  );
250 
251  subsection.find_widget<styled_widget>("image_range", true).set_tooltip(range);
252  subsection.find_widget<styled_widget>("image_type", true).set_tooltip(type);
253 
254  if(!range_png_exists || !type_png_exists) {
256  subsection,
257  "item",
259  );
260  }
261 
262  if (max_attacks > 1) {
264  subsection,
265  "item",
268  VNGETTEXT(
269  "uses $num attack",
270  "uses $num attacks",
271  a.attacks_used(),
272  { {"num", std::to_string(a.attacks_used())} }))
273  );
274  }
275 
276  for(const auto& pair : a.special_tooltips()) {
278  subsection,
279  "item",
281  markup::span_size("x-large", pair.first) + "\n" + pair.second
282  );
283  }
284  }
285 }
286 
287 void unit_preview_pane::set_display_data(const unit_type& type)
288 {
289  // Sets the current type id for the profile button callback to use
290  current_type_ = type;
291 
292  if(icon_type_) {
293  std::string mods;
294 
296  mods = "~RC(" + type.flag_rgb() + ">" +
298  + ")";
299  }
300 
301  mods += image_mods_;
302 
303  icon_type_->set_label((type.icon().empty() ? type.image() : type.icon()) + mods);
304  }
305 
306  if(label_name_) {
307  label_name_->set_label(markup::bold(type.type_name()));
308  label_name_->set_use_markup(true);
309  }
310 
311  if(label_level_) {
312  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
313 
314  label_level_->set_label(markup::bold(l_str));
315  label_level_->set_tooltip(unit_helper::unit_level_tooltip(type));
316  label_level_->set_use_markup(true);
317  }
318 
319  if(label_race_) {
320  label_race_ ->set_label(type.race()->name(type.genders().front()));
321  }
322 
323  if(icon_race_) {
324  icon_race_->set_label(type.race()->get_icon_path_stem() + "_30.png");
325  }
326 
327  if(icon_alignment_) {
328  const std::string& alignment_name = unit_alignments::get_string(type.alignment());
329 
330  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
331  icon_alignment_->set_tooltip(unit_type::alignment_description(
332  type.alignment(),
333  type.genders().front()));
334  }
335 
336  if(label_details_) {
337  std::stringstream str;
338 
339  str << " \n";
340 
341  str << markup::span_color(font::unit_type_color, type.type_name()) << "\n";
342 
343  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
344  str << l_str << "\n";
345 
346  str << unit_alignments::get_string(type.alignment()) << "\n";
347 
348  str << "\n"; // Leave a blank line where traits would be
349 
350  str << _("HP: ") << type.hitpoints() << "\n";
351 
352  str << _("XP: ") << type.experience_needed(true);
353 
354  label_details_->set_label(str.str());
355  label_details_->set_use_markup(true);
356  }
357 
358  if(tree_details_) {
359 
360  tree_details_->clear();
361  tree_details_->add_node("hp_xp_mp", {
362  { "hp",{
363  { "label", markup::tag("small", markup::span_color(unit::hp_color_max(), markup::bold(_("HP: ")), type.hitpoints()), " | ") },
364  { "use_markup", "true" },
365  { "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); }) }
366  } },
367  { "xp",{
368  { "label", markup::tag("small", markup::span_color(unit::xp_color(100, type.can_advance(), true), markup::bold(_("XP: ")), type.experience_needed()), " | ") },
369  { "use_markup", "true" },
370  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
371  } },
372  { "mp",{
373  { "label", markup::tag("small", markup::bold(_("MP: ")) + std::to_string(type.movement())) },
374  { "use_markup", "true" },
375  { "tooltip", get_mp_tooltip(type.movement(), [&type](t_translation::terrain_code terrain) { return type.movement_type().movement_cost(terrain); }) }
376  } },
377  });
378 
379  // Print trait details
380  {
381  tree_view_node* header_node = nullptr;
382 
383  for(const auto& tr : type.possible_traits()) {
384  t_string name = tr[type.genders().front() == unit_race::FEMALE ? "female_name" : "male_name"];
385  if(tr["availability"] != "musthave" || name.empty()) {
386  continue;
387  }
388 
389  if(header_node == nullptr) {
390  header_node = &add_name_tree_node(tree_details_->get_root_node(), "header", markup::bold(_("Traits")));
391  }
392 
393  add_name_tree_node(*header_node, "item", name);
394  }
395  }
396 
397  // Print ability details
398  if(!type.abilities_metadata().empty()) {
399 
400  auto& header_node = add_name_tree_node(tree_details_->get_root_node(), "header", markup::bold(_("Abilities")));
401 
402  for(const auto& ab : type.abilities_metadata()) {
403  if(!ab.name.empty()) {
405  header_node,
406  "item",
407  ab.name,
408  markup::span_size("x-large", ab.name) + "\n" + ab.description
409  );
410  }
411  }
412  }
413 
414  print_attack_details(type.attacks(), type.max_attacks(), type.max_attacks(), tree_details_->get_root_node());
415  }
416 }
417 
418 void unit_preview_pane::set_display_data(const unit& u)
419 {
420  // Sets the current type id for the profile button callback to use
421  current_type_ = u.type();
422 
423  if(icon_type_) {
424  std::string mods = u.image_mods();
425 
426  if(u.can_recruit()) {
427  mods += "~BLIT(" + unit::leader_crown() + ")";
428  }
429 
430  for(const std::string& overlay : u.overlays()) {
431  mods += "~BLIT(" + overlay + ")";
432  }
433 
434  mods += image_mods_;
435 
436  icon_type_->set_label(u.absolute_image() + mods);
437  }
438 
439  if(label_name_) {
440  std::string name;
441  if(!u.name().empty()) {
442  name = markup::span_size("large", u.name() + "\n") + markup::tag("small", markup::span_color(font::unit_type_color, u.type_name()));
443  } else {
444  name = markup::span_size("large", u.type_name()) + "\n";
445  }
446 
447  label_name_->set_label(name);
448  label_name_->set_use_markup(true);
449  }
450 
451  if(label_level_) {
452  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
453 
454  label_level_->set_label(markup::bold(l_str));
455  label_level_->set_tooltip(unit_helper::unit_level_tooltip(u));
456  label_level_->set_use_markup(true);
457  }
458 
459  if(label_race_) {
460  label_race_->set_label(u.race()->name(u.gender()));
461  }
462 
463  if(icon_race_) {
464  icon_race_->set_label(u.race()->get_icon_path_stem() + "_30.png");
465  }
466 
467  if(icon_alignment_) {
468  const std::string& alignment_name = unit_alignments::get_string(u.alignment());
469 
470  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
471  icon_alignment_->set_tooltip(unit_type::alignment_description(
472  u.alignment(),
473  u.gender()));
474  }
475 
476  if(label_details_) {
477  std::stringstream str;
478 
479  const std::string name = markup::span_size("large", (!u.name().empty() ? u.name() : " "));
480  str << name << "\n";
481 
483 
484  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
485  str << l_str << "\n";
486 
487  str << unit_type::alignment_description(u.alignment(), u.gender()) << "\n";
488 
489  str << utils::join(u.trait_names(), ", ") << "\n";
490 
491  str << markup::span_color(u.hp_color(), _("HP: "), u.hitpoints(), "/", u.max_hitpoints(), "\n");
492 
493  if(u.can_advance()) {
494  str << markup::span_color(u.xp_color(), _("XP: "), u.experience(), "/", u.max_experience());
495  } else {
496  str << markup::span_color(u.xp_color(), _("XP: "), font::unicode_en_dash);
497  }
498 
499  label_details_->set_label(str.str());
500  label_details_->set_use_markup(true);
501  }
502 
503  if(tree_details_) {
504  tree_details_->clear();
505  const std::string unit_xp = u.can_advance() ? (formatter() << u.experience() << "/" << u.max_experience()).str() : font::unicode_en_dash;
506  tree_details_->add_node("hp_xp_mp", {
507  { "hp",{
508  { "label", markup::tag("small", markup::span_color(u.hp_color(), markup::bold(_("HP: ")), u.hitpoints(), "/", u.max_hitpoints(), " | ")) },
509  { "use_markup", "true" },
510  { "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()); }) }
511  } },
512  { "xp",{
513  { "label", markup::tag("small", markup::span_color(u.xp_color(), markup::bold(_("XP: ")), unit_xp, " | ")) },
514  { "use_markup", "true" },
515  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
516  } },
517  { "mp",{
518  { "label", markup::tag("small", markup::bold(_("MP: ")), u.movement_left(), "/", u.total_movement()) },
519  { "use_markup", "true" },
520  { "tooltip", get_mp_tooltip(u.total_movement(), [&u](t_translation::terrain_code terrain) { return u.movement_cost(terrain); }) }
521  } },
522  });
523 
524  if(!u.trait_names().empty()) {
525  auto& header_node = add_name_tree_node(tree_details_->get_root_node(), "header", markup::bold(_("Traits")));
526 
527  assert(u.trait_names().size() == u.trait_descriptions().size());
528  for (std::size_t i = 0; i < u.trait_names().size(); ++i) {
530  header_node,
531  "item",
532  u.trait_names()[i],
533  u.trait_descriptions()[i]
534  );
535  }
536  }
537 
538  if(!u.get_ability_list().empty()) {
539  auto& header_node = add_name_tree_node(tree_details_->get_root_node(), "header", markup::bold(_("Abilities")));
540 
541  for(const auto& ab : u.ability_tooltips()) {
543  header_node,
544  "item",
545  std::get<2>(ab),
546  std::get<3>(ab)
547  );
548  }
549  }
550  print_attack_details(u.attacks(), u.attacks_left(), u.type().max_attacks(), tree_details_->get_root_node());
551  }
552 }
553 
554 void unit_preview_pane::profile_button_callback()
555 {
556  if(get_window() && current_type_) {
557  help::show_unit_description(*current_type_);
558  }
559 }
560 
561 void unit_preview_pane::set_image_mods(const std::string& mods)
562 {
563  image_mods_ = mods;
564 }
565 
566 void unit_preview_pane::set_active(const bool /*active*/)
567 {
568  /* DO NOTHING */
569 }
570 
571 bool unit_preview_pane::get_active() const
572 {
573  return true;
574 }
575 
576 unsigned unit_preview_pane::get_state() const
577 {
578  return ENABLED;
579 }
580 
581 void unit_preview_pane::set_self_active(const bool /*active*/)
582 {
583  /* DO NOTHING */
584 }
585 
586 // }---------- DEFINITION ---------{
587 
588 unit_preview_pane_definition::unit_preview_pane_definition(const config& cfg)
590 {
591  DBG_GUI_P << "Parsing unit preview pane " << id;
592 
593  load_resolutions<resolution>(cfg);
594 }
595 
597  : resolution_definition(cfg), grid()
598 {
599  state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", missing_mandatory_wml_tag("unit_preview_pane_definition][resolution", "background")));
600  state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", missing_mandatory_wml_tag("unit_preview_pane_definition][resolution", "foreground")));
601 
602  auto child = VALIDATE_WML_CHILD(cfg, "grid", missing_mandatory_wml_tag("unit_preview_pane_definition][resolution", "grid"));
603  grid = std::make_shared<builder_grid>(child);
604 }
605 
606 // }---------- BUILDER -----------{
607 
608 namespace implementation
609 {
610 
611 builder_unit_preview_pane::builder_unit_preview_pane(const config& cfg)
612  : builder_styled_widget(cfg)
613  , image_mods(cfg["image_mods"])
614 {
615 }
616 
617 std::unique_ptr<widget> builder_unit_preview_pane::build() const
618 {
619  auto widget = std::make_unique<unit_preview_pane>(*this);
620 
621  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
622  << "' with definition '" << definition << "'.";
623 
624  const auto conf = widget->cast_config_to<unit_preview_pane_definition>();
625  assert(conf);
626 
627  widget->init_grid(*conf->grid);
628  widget->finalize_setup();
629 
630  return widget;
631 }
632 
633 } // namespace implementation
634 
635 // }------------ END --------------
636 
637 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:158
std::ostringstream wrapper.
Definition: formatter.hpp:40
A generic container base class.
At the moment two kinds of tips are known:
Definition: tooltip.cpp:41
Base container class.
Definition: grid.hpp:32
void set_tooltip(const t_string &tooltip)
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)
void finalize_setup()
Initializes the internal sub-widget pointers.
Base class for all widgets.
Definition: widget.hpp:55
T * find_widget(const std::string_view id, const bool must_be_active, const bool must_exist)
Gets a widget with the wanted id.
Definition: widget.hpp:747
static prefs & get()
bool empty() const
Definition: tstring.hpp:195
static std::string get_side_color_id(unsigned side)
Definition: team.cpp:961
std::string get_icon_path_stem() const
Gets this race's icon path without state/size suffix and extension.
Definition: race.cpp:163
const t_string & name(GENDER gender=MALE) const
Definition: race.hpp:37
@ FEMALE
Definition: race.hpp:28
A single unit type that the player may recruit.
Definition: types.hpp:43
static std::string alignment_description(unit_alignments::type align, unit_race::GENDER gender=unit_race::MALE)
Implementation detail of unit_type::alignment_description.
Definition: types.cpp:841
int max_attacks() const
Definition: types.hpp:171
This class represents a single unit of a specific type.
Definition: unit.hpp:133
static const std::string & leader_crown()
The path to the leader crown overlay.
Definition: unit.cpp:1148
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
#define VNGETTEXT(msgid, msgid_plural, count,...)
std::size_t i
Definition: function.cpp:1030
static std::string _(const char *str)
Definition: gettext.hpp:97
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.
Definition: abilities.cpp:322
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
Definition: abilities.cpp:267
int max_hitpoints() const
The max number of hitpoints this unit can have.
Definition: unit.hpp:521
unit_alignments::type alignment() const
The alignment of this unit.
Definition: unit.hpp:491
int level() const
The current level of this unit.
Definition: unit.hpp:575
const t_string & type_name() const
Gets the translatable name of this unit's type.
Definition: unit.hpp:369
int hitpoints() const
The current number of hitpoints this unit has.
Definition: unit.hpp:515
const unit_race * race() const
Gets this unit's race.
Definition: unit.hpp:509
const unit_type & type() const
This unit's type, accounting for gender and variation.
Definition: unit.hpp:355
int experience() const
The current number of experience points this unit has.
Definition: unit.hpp:539
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
Definition: unit.hpp:628
int max_experience() const
The max number of experience points this unit can have.
Definition: unit.hpp:545
unit_race::GENDER gender() const
The gender of this unit.
Definition: unit.hpp:481
const t_string & name() const
Gets this unit's translatable display name.
Definition: unit.hpp:403
bool can_advance() const
Checks whether this unit has any options to advance to.
Definition: unit.hpp:272
attack_itors attacks()
Gets an iterator over this unit's attacks.
Definition: unit.hpp:942
utils::string_map_res get_base_resistances() const
Gets resistances without any abilities applied.
Definition: unit.hpp:1073
int attacks_left() const
Gets the remaining number of attacks this unit can perform this turn.
Definition: unit.hpp:1009
color_t xp_color() const
Color for this unit's XP.
Definition: unit.cpp:1223
color_t hp_color() const
Color for this unit's current hitpoints.
Definition: unit.cpp:1179
static color_t hp_color_max()
Definition: unit.cpp:1189
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
Definition: unit.cpp:2735
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
Definition: unit.hpp:1686
std::string absolute_image() const
The name of the file to game_display (used in menus).
Definition: unit.cpp:2554
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1338
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1322
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
Definition: unit.hpp:1117
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
Definition: unit.hpp:1107
#define DBG_GUI_G
Definition: log.hpp:41
#define DBG_GUI_P
Definition: log.hpp:66
std::string tooltip
Shown when hovering over an entry in the filter's drop-down list.
Definition: manager.cpp:203
auto string_table
Definition: language.hpp:68
CURSOR_TYPE get()
Definition: cursor.cpp:218
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
Definition: draw.cpp:189
const std::string weapon_details_sep
Definition: constants.cpp:50
const color_t unit_type_color
const std::string unicode_bullet
Definition: constants.cpp:47
const color_t weapon_details_color
const std::string unicode_en_dash
Definition: constants.cpp:43
const std::string unicode_figure_dash
Definition: constants.cpp:45
const std::string weapon_numbers_sep
Definition: constants.cpp:49
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.
Definition: dispatcher.cpp:163
Generic file dialog.
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.
Definition: help_impl.cpp:1458
void show_unit_description(const unit &u)
Definition: help.cpp:71
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
Definition: picture.cpp:835
Contains the implementation details for lexical_cast and shouldn't be used directly.
logger & info()
Definition: log.cpp:318
std::string bold(Args &&... data)
Applies bold Pango markup to the input.
Definition: markup.hpp:161
std::string span_color(const color_t &color, Args &&... data)
Applies Pango markup to the input specifying its display color.
Definition: markup.hpp:110
std::string tag(std::string_view tag, Args &&... data)
Wraps the given data in the specified tag.
Definition: markup.hpp:45
std::string span_size(std::string_view size, Args &&... data)
Applies Pango markup to the input specifying its display size.
Definition: markup.hpp:146
play_controller * controller
Definition: resources.cpp:21
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)
Definition: gettext.cpp:425
static std::string unit_level_tooltip(const int level, const std::vector< std::string > &adv_to_types, const std::vector< config > &adv_to_mods)
Definition: helper.cpp:60
std::string resistance_color(const int resistance)
Maps resistance <= -60 (resistance value <= -60%) to intense red.
Definition: helper.cpp:54
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
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()
Definition: video.cpp:668
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
static config unit_xp(const unit *u)
Definition: reports.cpp:526
std::string definition
Parameters for the styled_widget.
virtual std::unique_ptr< widget > build() const override
std::vector< state_definition > state
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
Definition: enum_base.hpp:46
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:49
static int get_acceleration()
Definition: types.cpp:574
std::string missing_mandatory_wml_tag(const std::string &section, 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)