The Battle for Wesnoth  1.19.5+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 
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_()
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, 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 {
211  if(attacks.empty()) {
212  return;
213  }
214 
215 
216  auto& header_node = add_name_tree_node(parent_node, "header", markup::bold(_("Attacks")));
217 
218  for(const auto& a : attacks) {
219  const std::string range_png = std::string("icons/profiles/") + a.range() + "_attack.png~SCALE_INTO(16,16)";
220  const std::string type_png = std::string("icons/profiles/") + a.type() + ".png~SCALE_INTO(16,16)";
221  const bool range_png_exists = ::image::exists(range_png);
222  const bool type_png_exists = ::image::exists(type_png);
223 
224  const t_string& range = string_table["range_" + a.range()];
225  const t_string& type = string_table["type_" + a.type()];
226 
227  const std::string label = markup::span_color(
228  font::unit_type_color, a.damage(), font::weapon_numbers_sep, a.num_attacks(), " ", a.name());
229 
230  auto& subsection = header_node.add_child(
231  "item_image",
232  {
233  { "image_range", { { "label", range_png } } },
234  { "image_type", { { "label", type_png } } },
235  { "name", { { "label", label }, { "use_markup", "true" } } },
236  }
237  );
238 
239  subsection.find_widget<styled_widget>("image_range", true).set_tooltip(range);
240  subsection.find_widget<styled_widget>("image_type", true).set_tooltip(type);
241 
242  if(!range_png_exists || !type_png_exists) {
244  subsection,
245  "item",
247  );
248  }
249 
250  for(const auto& pair : a.special_tooltips()) {
252  subsection,
253  "item",
255  markup::span_size("x-large", pair.first) + "\n" + pair.second
256  );
257  }
258  }
259 }
260 
262 {
263  // Sets the current type id for the profile button callback to use
265 
266  if(icon_type_) {
267  std::string mods;
268 
270  mods = "~RC(" + type.flag_rgb() + ">" +
272  + ")";
273  }
274 
275  mods += image_mods_;
276 
277  icon_type_->set_label((type.icon().empty() ? type.image() : type.icon()) + mods);
278  }
279 
280  if(label_name_) {
281  label_name_->set_label(markup::bold(type.type_name()));
283  }
284 
285  if(label_level_) {
286  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
287 
291  }
292 
293  if(label_race_) {
294  label_race_ ->set_label(type.race()->name(type.genders().front()));
295  }
296 
297  if(icon_race_) {
298  icon_race_->set_label(type.race()->get_icon_path_stem() + "_30.png");
299  }
300 
301  if(icon_alignment_) {
302  const std::string& alignment_name = unit_alignments::get_string(type.alignment());
303 
304  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
306  type.alignment(),
307  type.genders().front()));
308  }
309 
310  if(label_details_) {
311  std::stringstream str;
312 
313  str << " \n";
314 
315  str << markup::span_color(font::unit_type_color, type.type_name()) << "\n";
316 
317  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
318  str << l_str << "\n";
319 
320  str << unit_alignments::get_string(type.alignment()) << "\n";
321 
322  str << "\n"; // Leave a blank line where traits would be
323 
324  str << _("HP: ") << type.hitpoints() << "\n";
325 
326  str << _("XP: ") << type.experience_needed(true);
327 
328  label_details_->set_label(str.str());
330  }
331 
332  if(tree_details_) {
333 
334  tree_details_->clear();
335  tree_details_->add_node("hp_xp_mp", {
336  { "hp",{
337  { "label", markup::tag("small", markup::span_color(unit::hp_color_max(), markup::bold(_("HP: ")), type.hitpoints()), " | ") },
338  { "use_markup", "true" },
339  { "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); }) }
340  } },
341  { "xp",{
342  { "label", markup::tag("small", markup::span_color(unit::xp_color(100, type.can_advance(), true), markup::bold(_("XP: ")), type.experience_needed()), " | ") },
343  { "use_markup", "true" },
344  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
345  } },
346  { "mp",{
347  { "label", markup::tag("small", markup::bold(_("MP: ")) + std::to_string(type.movement())) },
348  { "use_markup", "true" },
349  { "tooltip", get_mp_tooltip(type.movement(), [&type](t_translation::terrain_code terrain) { return type.movement_type().movement_cost(terrain); }) }
350  } },
351  });
352 
353  // Print trait details
354  {
355  tree_view_node* header_node = nullptr;
356 
357  for(const auto& tr : type.possible_traits()) {
358  t_string name = tr[type.genders().front() == unit_race::FEMALE ? "female_name" : "male_name"];
359  if(tr["availability"] != "musthave" || name.empty()) {
360  continue;
361  }
362 
363  if(header_node == nullptr) {
364  header_node = &add_name_tree_node(tree_details_->get_root_node(), "header", markup::bold(_("Traits")));
365  }
366 
367  add_name_tree_node(*header_node, "item", name);
368  }
369  }
370 
371  // Print ability details
372  if(!type.abilities_metadata().empty()) {
373 
374  auto& header_node = add_name_tree_node(tree_details_->get_root_node(), "header", markup::bold(_("Abilities")));
375 
376  for(const auto& ab : type.abilities_metadata()) {
377  if(!ab.name.empty()) {
379  header_node,
380  "item",
381  ab.name,
382  markup::span_size("x-large", ab.name) + "\n" + ab.description
383  );
384  }
385  }
386  }
387 
389  }
390 }
391 
393 {
394  // Sets the current type id for the profile button callback to use
395  current_type_ = u.type();
396 
397  if(icon_type_) {
398  std::string mods = u.image_mods();
399 
400  if(u.can_recruit()) {
401  mods += "~BLIT(" + unit::leader_crown() + ")";
402  }
403 
404  for(const std::string& overlay : u.overlays()) {
405  mods += "~BLIT(" + overlay + ")";
406  }
407 
408  mods += image_mods_;
409 
410  icon_type_->set_label(u.absolute_image() + mods);
411  }
412 
413  if(label_name_) {
414  std::string name;
415  if(!u.name().empty()) {
416  name = markup::span_size("large", u.name() + "\n") + markup::tag("small", markup::span_color(font::unit_type_color, u.type_name()));
417  } else {
418  name = markup::span_size("large", u.type_name()) + "\n";
419  }
420 
421  label_name_->set_label(name);
423  }
424 
425  if(label_level_) {
426  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
427 
431  }
432 
433  if(label_race_) {
434  label_race_->set_label(u.race()->name(u.gender()));
435  }
436 
437  if(icon_race_) {
438  icon_race_->set_label(u.race()->get_icon_path_stem() + "_30.png");
439  }
440 
441  if(icon_alignment_) {
442  const std::string& alignment_name = unit_alignments::get_string(u.alignment());
443 
444  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
446  u.alignment(),
447  u.gender()));
448  }
449 
450  if(label_details_) {
451  std::stringstream str;
452 
453  const std::string name = markup::span_size("large", (!u.name().empty() ? u.name() : " "));
454  str << name << "\n";
455 
457 
458  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
459  str << l_str << "\n";
460 
461  str << unit_type::alignment_description(u.alignment(), u.gender()) << "\n";
462 
463  str << utils::join(u.trait_names(), ", ") << "\n";
464 
465  str << markup::span_color(u.hp_color(), _("HP: "), u.hitpoints(), "/", u.max_hitpoints(), "\n");
466 
467  if(u.can_advance()) {
468  str << markup::span_color(u.xp_color(), _("XP: "), u.experience(), "/", u.max_experience());
469  } else {
470  str << markup::span_color(u.xp_color(), _("XP: "), font::unicode_en_dash);
471  }
472 
473  label_details_->set_label(str.str());
475  }
476 
477  if(tree_details_) {
478  tree_details_->clear();
479  const std::string unit_xp = u.can_advance() ? (formatter() << u.experience() << "/" << u.max_experience()).str() : font::unicode_en_dash;
480  tree_details_->add_node("hp_xp_mp", {
481  { "hp",{
482  { "label", markup::tag("small", markup::span_color(u.hp_color(), markup::bold(_("HP: ")), u.hitpoints(), "/", u.max_hitpoints(), " | ")) },
483  { "use_markup", "true" },
484  { "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()); }) }
485  } },
486  { "xp",{
487  { "label", markup::tag("small", markup::span_color(u.xp_color(), markup::bold(_("XP: ")), unit_xp, " | ")) },
488  { "use_markup", "true" },
489  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
490  } },
491  { "mp",{
492  { "label", markup::tag("small", markup::bold(_("MP: ")), u.movement_left(), "/", u.total_movement()) },
493  { "use_markup", "true" },
494  { "tooltip", get_mp_tooltip(u.total_movement(), [&u](t_translation::terrain_code terrain) { return u.movement_cost(terrain); }) }
495  } },
496  });
497 
498  if(!u.trait_names().empty()) {
499  auto& header_node = add_name_tree_node(tree_details_->get_root_node(), "header", markup::bold(_("Traits")));
500 
501  assert(u.trait_names().size() == u.trait_descriptions().size());
502  for (std::size_t i = 0; i < u.trait_names().size(); ++i) {
504  header_node,
505  "item",
506  u.trait_names()[i],
507  u.trait_descriptions()[i]
508  );
509  }
510  }
511 
512  if(!u.get_ability_list().empty()) {
513  auto& header_node = add_name_tree_node(tree_details_->get_root_node(), "header", markup::bold(_("Abilities")));
514 
515  for(const auto& ab : u.ability_tooltips()) {
517  header_node,
518  "item",
519  std::get<2>(ab),
520  std::get<3>(ab)
521  );
522  }
523  }
525  }
526 }
527 
529 {
530  if(get_window() && current_type_) {
532  }
533 }
534 
535 void unit_preview_pane::set_image_mods(const std::string& mods)
536 {
537  image_mods_ = mods;
538 }
539 
540 void unit_preview_pane::set_active(const bool /*active*/)
541 {
542  /* DO NOTHING */
543 }
544 
546 {
547  return true;
548 }
549 
551 {
552  return ENABLED;
553 }
554 
555 void unit_preview_pane::set_self_active(const bool /*active*/)
556 {
557  /* DO NOTHING */
558 }
559 
560 // }---------- DEFINITION ---------{
561 
564 {
565  DBG_GUI_P << "Parsing unit preview pane " << id;
566 
567  load_resolutions<resolution>(cfg);
568 }
569 
571  : resolution_definition(cfg), grid()
572 {
573  state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", missing_mandatory_wml_tag("unit_preview_pane_definition][resolution", "background")));
574  state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", missing_mandatory_wml_tag("unit_preview_pane_definition][resolution", "foreground")));
575 
576  auto child = VALIDATE_WML_CHILD(cfg, "grid", missing_mandatory_wml_tag("unit_preview_pane_definition][resolution", "grid"));
577  grid = std::make_shared<builder_grid>(child);
578 }
579 
580 // }---------- BUILDER -----------{
581 
582 namespace implementation
583 {
584 
585 builder_unit_preview_pane::builder_unit_preview_pane(const config& cfg)
586  : builder_styled_widget(cfg)
587  , image_mods_(cfg["image_mods"])
588 {
589 }
590 
591 std::unique_ptr<widget> builder_unit_preview_pane::build() const
592 {
593  auto widget = std::make_unique<unit_preview_pane>(*this);
594 
595  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
596  << "' with definition '" << definition << "'.";
597 
598  const auto conf = widget->cast_config_to<unit_preview_pane_definition>();
599  assert(conf);
600 
601  widget->init_grid(*conf->grid);
602  widget->finalize_setup();
603  widget->set_image_mods(image_mods_);
604 
605  return widget;
606 }
607 
608 } // namespace implementation
609 
610 // }------------ END --------------
611 
612 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
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)
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.
const tree_view_node & get_root_node() const
Definition: tree_view.hpp:53
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:55
NOT_DANGLING T * find_widget(const std::string &id, const bool must_be_active, const bool must_exist)
Gets a widget with the wanted id.
Definition: widget.hpp:742
window * get_window()
Get the parent window.
Definition: widget.cpp:117
static prefs & get()
bool empty() const
Definition: tstring.hpp:194
static std::string get_side_color_id(unsigned side)
Definition: team.cpp:972
std::string get_icon_path_stem() const
Gets this race's icon path without state/size suffix and extension.
Definition: race.cpp:165
const t_string & name(GENDER gender=MALE) const
Definition: race.hpp:38
@ 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
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:1140
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
std::size_t i
Definition: function.cpp:1028
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:319
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
Definition: abilities.cpp:262
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:933
utils::string_map_res get_base_resistances() const
Gets resistances without any abilities applied.
Definition: unit.hpp:1064
color_t xp_color() const
Color for this unit's XP.
Definition: unit.cpp:1215
color_t hp_color() const
Color for this unit's current hitpoints.
Definition: unit.cpp:1171
static color_t hp_color_max()
Definition: unit.cpp:1181
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
Definition: unit.cpp:2737
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
Definition: unit.hpp:1677
std::string absolute_image() const
The name of the file to game_display (used in menus).
Definition: unit.cpp:2556
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1329
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1313
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
Definition: unit.hpp:1108
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
Definition: unit.hpp:1098
#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:202
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
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:1459
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:818
Contains the implementation details for lexical_cast and shouldn't be used directly.
logger & info()
Definition: log.cpp:319
std::string span_size(const std::string &size, Args &&... data)
Definition: markup.hpp:110
std::string tag(const std::string &tag_name, Args &&... contents)
Definition: markup.hpp:45
std::string bold(Args &&... data)
Definition: markup.hpp:128
std::string span_color(const color_t &color, Args &&... data)
Definition: markup.hpp:68
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:55
std::string resistance_color(const int resistance)
Maps resistance <= -60 (resistance value <= -60%) to intense red.
Definition: helper.cpp:49
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:524
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)