The Battle for Wesnoth  1.19.0-dev
unit_preview_pane.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
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 
20 
22 #include "gui/widgets/button.hpp"
23 #include "gui/widgets/drawing.hpp"
24 #include "gui/widgets/image.hpp"
25 #include "gui/widgets/label.hpp"
28 
29 #include "font/text_formatting.hpp"
30 #include "formatter.hpp"
31 #include "formula/string_utils.hpp"
32 #include "language.hpp"
33 #include "preferences/game.hpp"
34 #include "gettext.hpp"
35 #include "help/help.hpp"
36 #include "help/help_impl.hpp"
37 #include "play_controller.hpp"
38 #include "resources.hpp"
39 #include "team.hpp"
40 #include "terrain/movement.hpp"
41 #include "terrain/type_data.hpp"
42 #include "units/types.hpp"
43 #include "units/helper.hpp"
44 #include "units/unit.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_()
68 {
69 }
70 
72 {
73  // Icons
74  icon_type_ = find_widget<drawing>(this, "type_image", false, false);
75  icon_race_ = find_widget<image>(this, "type_race", false, false);
76  icon_alignment_ = find_widget<image>(this, "type_alignment", false, false);
77 
78  // Labels
79  label_name_ = find_widget<label>(this, "type_name", false, false);
80  label_level_ = find_widget<label>(this, "type_level", false, false);
81  label_race_ = find_widget<label>(this, "type_race_label", false, false);
82  label_details_ = find_widget<styled_widget>(this, "type_details_minimal", false, false);
83 
84  tree_details_ = find_widget<tree_view>(this, "type_details", false, false);
85 
86  // Profile button
87  button_profile_ = find_widget<button>(this, "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 = find_widget<styled_widget>(&child_node, "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) {
126  line << "<span color='" << unit_helper::resistance_color(res_def) << "'>\t" << utils::signed_percent(res_def) << "</span>";
127  } else {
128  line << "<span color='" << unit_helper::resistance_color(res_att) << "'>\t" << utils::signed_percent(res_att) << "</span>" << "/"
129  << "<span color='" << unit_helper::resistance_color(res_def) << "'>" << utils::signed_percent(res_def) << "</span>";
130  att_def_diff = true;
131  }
132 
133  resistances_table.push_back(line.str());
134  }
135 
136  tooltip << "<big>" << _("Resistances: ") << "</big>";
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, std::function<int (t_translation::terrain_code)> get)
149 {
150  std::set<terrain_movement> terrain_moves;
151  std::ostringstream tooltip;
152  tooltip << "<big>" << _("Movement Costs:") << "</big>";
153 
154  std::shared_ptr<terrain_type_data> tdata = help::load_terrain_types_data();
155 
156  if(!tdata) {
157  return "";
158  }
159 
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  // passing true to select the less saturated red-to-green scale
180  std::string color = game_config::red_to_green(movement_red_to_green, true).to_hex_string();
181 
182  tooltip << "<span color='" << color << "'>";
183 
184  // A 5 MP margin; if the movement costs go above the unit's max moves + 5, we replace it with dashes.
185  if(cannot_move && (tm.moves > total_movement + 5)) {
187  } else if (cannot_move) {
188  tooltip << "(" << tm.moves << ")";
189  } else {
190  tooltip << tm.moves;
191  }
192  if(tm.moves != 0) {
193  const int movement_hexes_per_turn = total_movement / tm.moves;
194  tooltip << " ";
195  for(int i = 0; i < movement_hexes_per_turn; ++i) {
196  // Unicode horizontal black hexagon and Unicode zero width space (to allow a line break)
197  tooltip << "\u2b23\u200b";
198  }
199  }
200 
201  tooltip << "</span>";
202  }
203 
204  return tooltip.str();
205 }
206 
207 /*
208  * Both unit and unit_type use the same format (vector of attack_types) for their
209  * attack data, meaning we can keep this as a helper function.
210  */
211 template<typename T>
213 {
214  if(attacks.empty()) {
215  return;
216  }
217 
218  auto& header_node = add_name_tree_node(
219  parent_node,
220  "header",
221  "<b>" + _("Attacks") + "</b>"
222  );
223 
224  for(const auto& a : attacks) {
225  const std::string range_png = std::string("icons/profiles/") + a.range() + "_attack.png~SCALE_INTO(16,16)";
226  const std::string type_png = std::string("icons/profiles/") + a.type() + ".png~SCALE_INTO(16,16)";
227  const bool range_png_exists = ::image::locator(range_png).file_exists();
228  const bool type_png_exists = ::image::locator(type_png).file_exists();
229 
230  const t_string& range = string_table["range_" + a.range()];
231  const t_string& type = string_table["type_" + a.type()];
232 
233  const std::string label = (formatter()
235  << a.damage() << font::weapon_numbers_sep << a.num_attacks()
236  << " " << a.name() << "</span>").str();
237 
238  auto& subsection = header_node.add_child(
239  "item_image",
240  {
241  { "image_range", { { "label", range_png } } },
242  { "image_type", { { "label", type_png } } },
243  { "name", { { "label", label }, { "use_markup", "true" } } },
244  }
245  );
246 
247  find_widget<styled_widget>(&subsection, "image_range", true).set_tooltip(range);
248  find_widget<styled_widget>(&subsection, "image_type", true).set_tooltip(type);
249 
250  if(!range_png_exists || !type_png_exists) {
252  subsection,
253  "item",
254  (formatter()
256  << range << font::weapon_details_sep
257  << type << "</span>"
258  ).str()
259  );
260  }
261 
262  for(const auto& pair : a.special_tooltips()) {
264  subsection,
265  "item",
266  (formatter() << font::span_color(font::weapon_details_color) << pair.first << "</span>").str(),
267  (formatter() << "<span size='x-large'>" << pair.first << "</span>" << "\n" << pair.second).str()
268  );
269  }
270  }
271 }
272 
274 {
275  // Sets the current type id for the profile button callback to use
277 
278  if(icon_type_) {
279  std::string mods;
280 
282  mods = "~RC(" + type.flag_rgb() + ">" +
284  + ")";
285  }
286 
287  mods += image_mods_;
288 
289  icon_type_->set_label((type.icon().empty() ? type.image() : type.icon()) + mods);
290  }
291 
292  if(label_name_) {
293  label_name_->set_label("<big>" + type.type_name() + "</big>");
295  }
296 
297  if(label_level_) {
298  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
299 
300  label_level_->set_label("<b>" + l_str + "</b>");
303  }
304 
305  if(label_race_) {
306  label_race_ ->set_label(type.race()->name(type.genders().front()));
307  }
308 
309  if(icon_race_) {
310  icon_race_->set_label(type.race()->get_icon_path_stem() + "_30.png");
311  }
312 
313  if(icon_alignment_) {
314  const std::string& alignment_name = unit_alignments::get_string(type.alignment());
315 
316  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
318  type.alignment(),
319  type.genders().front()));
320  }
321 
322  if(label_details_) {
323  std::stringstream str;
324 
325  str << "<span size='large'> </span>" << "\n";
326 
327  str << font::span_color(font::unit_type_color) << type.type_name() << "</span>" << "\n";
328 
329  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
330  str << l_str << "\n";
331 
332  str << unit_alignments::get_string(type.alignment()) << "\n";
333 
334  str << "\n"; // Leave a blank line where traits would be
335 
336  str << _("HP: ") << type.hitpoints() << "\n";
337 
338  str << _("XP: ") << type.experience_needed(true);
339 
340  label_details_->set_label(str.str());
342  }
343 
344  if(tree_details_) {
345 
346  tree_details_->clear();
347  tree_details_->add_node("hp_xp_mp", {
348  { "hp",{
349  { "label", (formatter() << "<small>" << font::span_color(unit::hp_color_max()) << "<b>" << _("HP: ") << "</b>" << type.hitpoints() << "</span>" << " | </small>").str() },
350  { "use_markup", "true" },
351  { "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); }) }
352  } },
353  { "xp",{
354  { "label", (formatter() << "<small>" << font::span_color(unit::xp_color(100, type.can_advance(), true)) << "<b>" << _("XP: ") << "</b>" << type.experience_needed() << "</span>" << " | </small>").str() },
355  { "use_markup", "true" },
356  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
357  } },
358  { "mp",{
359  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << type.movement() << "</small>").str() },
360  { "use_markup", "true" },
361  { "tooltip", get_mp_tooltip(type.movement(), [&type](t_translation::terrain_code terrain) { return type.movement_type().movement_cost(terrain); }) }
362  } },
363  });
364 
365  // Print trait details
366  {
367  tree_view_node* header_node = nullptr;
368 
369  for(const auto& tr : type.possible_traits()) {
370  t_string name = tr[type.genders().front() == unit_race::FEMALE ? "female_name" : "male_name"];
371  if(tr["availability"] != "musthave" || name.empty()) {
372  continue;
373  }
374 
375  if(header_node == nullptr) {
376  header_node = &add_name_tree_node(
378  "header",
379  "<b>" + _("Traits") + "</b>"
380  );
381  }
382 
384  *header_node,
385  "item",
386  name
387  );
388  }
389  }
390 
391  // Print ability details
392  if(!type.abilities_metadata().empty()) {
393 
394  auto& header_node = add_name_tree_node(
396  "header",
397  "<b>" + _("Abilities") + "</b>"
398  );
399 
400  for(const auto& ab : type.abilities_metadata()) {
401  if(!ab.name.empty()) {
403  header_node,
404  "item",
405  ab.name,
406  (formatter() << "<span size='x-large'>" << ab.name << "</span>\n" << ab.description).str()
407  );
408  }
409  }
410  }
411 
413  }
414 }
415 
417 {
418  // Sets the current type id for the profile button callback to use
419  current_type_ = u.type();
420 
421  if(icon_type_) {
422  std::string mods = u.image_mods();
423 
424  if(u.can_recruit()) {
425  mods += "~BLIT(" + unit::leader_crown() + ")";
426  }
427 
428  for(const std::string& overlay : u.overlays()) {
429  mods += "~BLIT(" + overlay + ")";
430  }
431 
432  mods += image_mods_;
433 
434  icon_type_->set_label(u.absolute_image() + mods);
435  }
436 
437  if(label_name_) {
438  std::string name;
439  if(!u.name().empty()) {
440  name = "<span size='large'>" + u.name() + "</span>" + "\n" + "<small>" + font::span_color(font::unit_type_color) + u.type_name() + "</span></small>";
441  } else {
442  name = "<span size='large'>" + u.type_name() + "</span>\n";
443  }
444 
445  label_name_->set_label(name);
447  }
448 
449  if(label_level_) {
450  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
451 
452  label_level_->set_label("<b>" + l_str + "</b>");
455  }
456 
457  if(label_race_) {
458  label_race_->set_label(u.race()->name(u.gender()));
459  }
460 
461  if(icon_race_) {
462  icon_race_->set_label(u.race()->get_icon_path_stem() + "_30.png");
463  }
464 
465  if(icon_alignment_) {
466  const std::string& alignment_name = unit_alignments::get_string(u.alignment());
467 
468  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
470  u.alignment(),
471  u.gender()));
472  }
473 
474  if(label_details_) {
475  std::stringstream str;
476 
477  const std::string name = "<span size='large'>" + (!u.name().empty() ? u.name() : " ") + "</span>";
478  str << name << "\n";
479 
480  str << font::span_color(font::unit_type_color) << u.type_name() << "</span>" << "\n";
481 
482  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
483  str << l_str << "\n";
484 
485  str << unit_type::alignment_description(u.alignment(), u.gender()) << "\n";
486 
487  str << utils::join(u.trait_names(), ", ") << "\n";
488 
489  str << font::span_color(u.hp_color())
490  << _("HP: ") << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << "\n";
491 
492  str << font::span_color(u.xp_color()) << _("XP: ");
493  if(u.can_advance()) {
494  str << u.experience() << "/" << u.max_experience();
495  } else {
496  str << font::unicode_en_dash;
497  }
498  str << "</span>";
499 
500  label_details_->set_label(str.str());
502  }
503 
504  if(tree_details_) {
505  tree_details_->clear();
506  const std::string unit_xp = u.can_advance() ? (formatter() << u.experience() << "/" << u.max_experience()).str() : font::unicode_en_dash;
507  tree_details_->add_node("hp_xp_mp", {
508  { "hp",{
509  { "label", (formatter() << "<small>" << font::span_color(u.hp_color()) << "<b>" << _("HP: ") << "</b>" << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << " | </small>").str() },
510  { "use_markup", "true" },
511  { "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()); }) }
512  } },
513  { "xp",{
514  { "label", (formatter() << "<small>" << font::span_color(u.xp_color()) << "<b>" << _("XP: ") << "</b>" << unit_xp << "</span>" << " | </small>").str() },
515  { "use_markup", "true" },
516  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
517  } },
518  { "mp",{
519  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << u.movement_left() << "/" << u.total_movement() << "</small>").str() },
520  { "use_markup", "true" },
521  { "tooltip", get_mp_tooltip(u.total_movement(), [&u](t_translation::terrain_code terrain) { return u.movement_cost(terrain); }) }
522  } },
523  });
524 
525  if(!u.trait_names().empty()) {
526  auto& header_node = add_name_tree_node(
528  "header",
529  "<b>" + _("Traits") + "</b>"
530  );
531 
532  assert(u.trait_names().size() == u.trait_descriptions().size());
533  for (std::size_t i = 0; i < u.trait_names().size(); ++i) {
535  header_node,
536  "item",
537  u.trait_names()[i],
538  u.trait_descriptions()[i]
539  );
540  }
541  }
542 
543  if(!u.get_ability_list().empty()) {
544  auto& header_node = add_name_tree_node(
546  "header",
547  "<b>" + _("Abilities") + "</b>"
548  );
549 
550  for(const auto& ab : u.ability_tooltips()) {
552  header_node,
553  "item",
554  std::get<2>(ab),
555  std::get<3>(ab)
556  );
557  }
558  }
560  }
561 }
562 
564 {
565  if(get_window() && current_type_) {
567  }
568 }
569 
570 void unit_preview_pane::set_image_mods(const std::string& mods)
571 {
572  image_mods_ = mods;
573 }
574 
575 void unit_preview_pane::set_active(const bool /*active*/)
576 {
577  /* DO NOTHING */
578 }
579 
581 {
582  return true;
583 }
584 
586 {
587  return ENABLED;
588 }
589 
590 void unit_preview_pane::set_self_active(const bool /*active*/)
591 {
592  /* DO NOTHING */
593 }
594 
595 // }---------- DEFINITION ---------{
596 
599 {
600  DBG_GUI_P << "Parsing unit preview pane " << id;
601 
602  load_resolutions<resolution>(cfg);
603 }
604 
606  : resolution_definition(cfg), grid()
607 {
608  state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", missing_mandatory_wml_tag("unit_preview_pane_definition][resolution", "background")));
609  state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", missing_mandatory_wml_tag("unit_preview_pane_definition][resolution", "foreground")));
610 
611  auto child = VALIDATE_WML_CHILD(cfg, "grid", missing_mandatory_wml_tag("unit_preview_pane_definition][resolution", "grid"));
612  grid = std::make_shared<builder_grid>(child);
613 }
614 
615 // }---------- BUILDER -----------{
616 
617 namespace implementation
618 {
619 
620 builder_unit_preview_pane::builder_unit_preview_pane(const config& cfg)
621  : builder_styled_widget(cfg)
622  , image_mods_(cfg["image_mods"])
623 {
624 }
625 
626 std::unique_ptr<widget> builder_unit_preview_pane::build() const
627 {
628  auto widget = std::make_unique<unit_preview_pane>(*this);
629 
630  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
631  << "' with definition '" << definition << "'.";
632 
633  const auto conf = widget->cast_config_to<unit_preview_pane_definition>();
634  assert(conf);
635 
636  widget->init_grid(*conf->grid);
637  widget->finalize_setup();
638  widget->set_image_mods(image_mods_);
639 
640  return widget;
641 }
642 
643 } // namespace implementation
644 
645 // }------------ END --------------
646 
647 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
std::ostringstream wrapper.
Definition: formatter.hpp:40
A generic container base class.
Class to show the tips.
Definition: tooltip.cpp:56
Base container class.
Definition: grid.hpp:32
A label displays text that can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
void set_tooltip(const t_string &tooltip)
virtual void set_label(const t_string &text)
virtual void set_use_markup(bool use_markup)
tree_view_node & add_child(const std::string &id, const widget_data &data, const int index=-1)
Constructs a new child node.
tree_view_node & get_root_node()
Definition: tree_view.hpp:74
tree_view_node & add_node(const std::string &id, const widget_data &data, const int index=-1)
Definition: tree_view.cpp:56
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.
virtual void set_active(const bool active) override
See styled_widget::set_active.
styled_widget * label_details_
void set_displayed_unit(const unit &u)
Displays the stats of a specific unit.
virtual bool get_active() const override
See styled_widget::get_active.
void print_attack_details(T attacks, tree_view_node &parent_node)
void set_image_mods(const std::string &mods)
Sets the facing of the unit image.
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
void set_displayed_type(const unit_type &type)
Displays the stats of a specified unit type.
virtual unsigned get_state() const override
See styled_widget::get_state.
utils::optional_reference< const unit_type > current_type_
void finalize_setup()
Initializes the internal sub-widget pointers.
Base class for all widgets.
Definition: widget.hpp:53
window * get_window()
Get the parent window.
Definition: widget.cpp:117
Generic locator abstracting the location of an image.
Definition: picture.hpp:63
bool file_exists() const
Tests whether the file the locator points at exists.
Definition: picture.cpp:563
bool empty() const
Definition: tstring.hpp:186
static std::string get_side_color_id(unsigned side)
Definition: team.cpp:971
std::string get_icon_path_stem() const
Gets this race's icon path without state/size suffix and extension.
Definition: race.cpp:166
const t_string & name(GENDER gender=MALE) const
Definition: race.hpp:37
@ FEMALE
Definition: race.hpp:27
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:838
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:1058
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
std::size_t i
Definition: function.cpp:968
static std::string _(const char *str)
Definition: gettext.hpp:93
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:324
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:505
unit_alignments::type alignment() const
The alignment of this unit.
Definition: unit.hpp:475
int level() const
The current level of this unit.
Definition: unit.hpp:559
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:499
const unit_race * race() const
Gets this unit's race.
Definition: unit.hpp:493
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:523
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
Definition: unit.hpp:612
int max_experience() const
The max number of experience points this unit can have.
Definition: unit.hpp:529
unit_race::GENDER gender() const
The gender of this unit.
Definition: unit.hpp:465
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:927
utils::string_map_res get_base_resistances() const
Gets resistances without any abilities applied.
Definition: unit.hpp:1049
color_t xp_color() const
Color for this unit's XP.
Definition: unit.cpp:1160
color_t hp_color() const
Color for this unit's current hitpoints.
Definition: unit.cpp:1106
static color_t hp_color_max()
Definition: unit.cpp:1116
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
Definition: unit.cpp:2730
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
Definition: unit.hpp:1607
std::string absolute_image() const
The name of the file to game_display (used in menus).
Definition: unit.cpp:2549
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1282
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1266
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
Definition: unit.hpp:1093
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
Definition: unit.hpp:1083
#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:211
symbol_table string_table
Definition: language.cpp:64
CURSOR_TYPE get()
Definition: cursor.cpp:216
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
Definition: draw.cpp:180
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
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
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:177
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, 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:1695
void show_unit_description(const unit &u)
Definition: help.cpp:71
Contains the implementation details for lexical_cast and shouldn't be used directly.
logger & info()
Definition: log.cpp:314
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:918
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:54
std::string resistance_color(const int resistance)
Maps resistance <= -60 (resistance value <= -60%) to intense red.
Definition: helper.cpp:48
std::size_t size(const std::string &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.
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
static config unit_xp(const unit *u)
Definition: reports.cpp:526
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
Definition: color.cpp:78
std::string definition
Parameters for the styled_widget.
virtual std::unique_ptr< widget > build() const override
Base class of a resolution, contains the common keys for a resolution.
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:571
std::string missing_mandatory_wml_tag(const std::string &section, const std::string &tag)
Returns a standard message for a missing wml child (tag).
#define VALIDATE_WML_CHILD(cfg, key, message)
#define a