The Battle for Wesnoth  1.15.12+dev
unit_preview_pane.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 The Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #define GETTEXT_DOMAIN "wesnoth-lib"
15 
17 
19 
21 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/image.hpp"
23 #include "gui/widgets/label.hpp"
24 #include "gui/widgets/settings.hpp"
25 #include "gui/widgets/window.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/attack_type.hpp"
43 #include "units/types.hpp"
44 #include "units/helper.hpp"
45 #include "units/unit.hpp"
46 
47 #include <functional>
48 
49 namespace gui2
50 {
51 
52 // ------------ WIDGET -----------{
53 
54 REGISTER_WIDGET(unit_preview_pane)
55 
56 unit_preview_pane::unit_preview_pane(const implementation::builder_unit_preview_pane& builder)
57  : container_base(builder, type())
58  , current_type_()
59  , icon_type_(nullptr)
60  , icon_race_(nullptr)
61  , icon_alignment_(nullptr)
62  , label_name_(nullptr)
63  , label_level_(nullptr)
64  , label_race_(nullptr)
65  , label_details_(nullptr)
66  , tree_details_(nullptr)
67  , button_profile_(nullptr)
68  , image_mods_()
69 {
70 }
71 
73 {
74  // Icons
75  icon_type_ = find_widget<image>(this, "type_image", false, false);
76  icon_race_ = find_widget<image>(this, "type_race", false, false);
77  icon_alignment_ = find_widget<image>(this, "type_alignment", false, false);
78 
79  // Labels
80  label_name_ = find_widget<label>(this, "type_name", false, false);
81  label_level_ = find_widget<label>(this, "type_level", false, false);
82  label_race_ = find_widget<label>(this, "type_race_label", false, false);
83  label_details_ = find_widget<styled_widget>(this, "type_details_minimal", false, false);
84 
85  tree_details_ = find_widget<tree_view>(this, "type_details", false, false);
86 
87  // Profile button
88  button_profile_ = find_widget<button>(this, "type_profile", false, false);
89 
90  if(button_profile_) {
91  connect_signal_mouse_left_click(*button_profile_,
93  }
94 }
95 
96 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 = "")
97 {
98  /* Note: We have to pass data instead of just doing 'child_label.set_label(label)' below
99  * because the tree_view_node::add_child needs to have the correct size of the
100  * node child widgets for its internal size calculations.
101  * Same is true for 'use_markup'
102  */
103  auto& child_node = header_node.add_child(type, { { "name",{ { "label", label },{ "use_markup", "true" } } } });
104  auto& child_label = find_widget<styled_widget>(&child_node, "name", true);
105 
106  child_label.set_tooltip(tooltip);
107  return child_node;
108 }
109 
110 static inline std::string get_hp_tooltip(const utils::string_map& res, const std::function<int (const std::string&, bool)>& get)
111 {
112  std::ostringstream tooltip;
113 
114  std::set<std::string> resistances_table;
115 
116  bool att_def_diff = false;
117  for(const utils::string_map::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.insert(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;
177 
178  std::string color;
179  if(cannot_move) {
180  // cannot move in this terrain
181  color = "red";
182  } else if(tm.moves > 1) {
183  color = "yellow";
184  } else {
185  color = "white";
186  }
187 
188  tooltip << "<span color='" << color << "'>";
189 
190  // A 5 MP margin; if the movement costs go above the unit's max moves + 5, we replace it with dashes.
191  if(cannot_move && (tm.moves > total_movement + 5)) {
192  tooltip << font::unicode_figure_dash;
193  } else {
194  tooltip << tm.moves;
195  }
196 
197  tooltip << "</span>";
198  }
199 
200  return tooltip.str();
201 }
202 
203 /*
204  * Both unit and unit_type use the same format (vector of attack_types) for their
205  * attack data, meaning we can keep this as a helper function.
206  */
207 template<typename T>
209 {
210  if(attacks.empty()) {
211  return;
212  }
213 
214  auto& header_node = add_name_tree_node(
215  parent_node,
216  "header",
217  "<b>" + _("Attacks") + "</b>"
218  );
219 
220  for(const auto& a : attacks) {
221  const std::string range_png = std::string("icons/profiles/") + a.range() + "_attack.png~SCALE_INTO_SHARP(16,16)";
222  const std::string type_png = std::string("icons/profiles/") + a.type() + ".png~SCALE_INTO_SHARP(16,16)";
223  const bool range_png_exists = ::image::locator(range_png).file_exists();
224  const bool type_png_exists = ::image::locator(type_png).file_exists();
225 
226  const t_string& range = string_table["range_" + a.range()];
227  const t_string& type = string_table["type_" + a.type()];
228 
229  const std::string label = (formatter()
231  << a.damage() << font::weapon_numbers_sep << a.num_attacks()
232  << " " << a.name() << "</span>").str();
233 
234  auto& subsection = header_node.add_child(
235  "item_image",
236  {
237  { "image_range", { { "label", range_png } } },
238  { "image_type", { { "label", type_png } } },
239  { "name", { { "label", label }, { "use_markup", "true" } } },
240  }
241  );
242 
243  find_widget<styled_widget>(&subsection, "image_range", true).set_tooltip(range);
244  find_widget<styled_widget>(&subsection, "image_type", true).set_tooltip(type);
245 
246  if(!range_png_exists || !type_png_exists) {
248  subsection,
249  "item",
250  (formatter()
252  << range << font::weapon_details_sep
253  << type << "</span>"
254  ).str()
255  );
256  }
257 
258  for(const auto& pair : a.special_tooltips()) {
260  subsection,
261  "item",
262  (formatter() << font::span_color(font::weapon_details_color) << pair.first << "</span>").str(),
263  (formatter() << "<span size='x-large'>" << pair.first << "</span>" << "\n" << pair.second).str()
264  );
265  }
266  }
267 }
268 
270 {
271  // Sets the current type id for the profile button callback to use
273 
274  if(icon_type_) {
275  std::string mods;
276 
278  mods = "~RC(" + type.flag_rgb() + ">" +
280  + ")";
281  }
282 
283  mods += "~XBRZ(2)~SCALE_INTO_SHARP(144,144)" + image_mods_;
284 
285  icon_type_->set_label((type.icon().empty() ? type.image() : type.icon()) + mods);
286  }
287 
288  if(label_name_) {
289  label_name_->set_label("<big>" + type.type_name() + "</big>");
291  }
292 
293  if(label_level_) {
294  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
295 
296  label_level_->set_label("<b>" + l_str + "</b>");
299  }
300 
301  if(label_race_) {
302  label_race_ ->set_label(type.race()->name(type.genders().front()));
303  }
304 
305  if(icon_race_) {
306  icon_race_->set_label(type.race()->get_icon_path_stem() + "_30.png");
307  }
308 
309  if(icon_alignment_) {
310  const std::string& alignment_name = type.alignment().to_string();
311 
312  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
314  type.alignment(),
315  type.genders().front()));
316  }
317 
318  if(label_details_) {
319  std::stringstream str;
320 
321  str << "<span size='large'> </span>" << "\n";
322 
323  str << font::span_color(font::unit_type_color) << type.type_name() << "</span>" << "\n";
324 
325  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
326  str << l_str << "\n";
327 
328  str << type.alignment() << "\n";
329 
330  str << "\n"; // Leave a blank line where traits would be
331 
332  str << _("HP: ") << type.hitpoints() << "\n";
333 
334  str << _("XP: ") << type.experience_needed(true);
335 
336  label_details_->set_label(str.str());
338  }
339 
340  if(tree_details_) {
341 
342  tree_details_->clear();
343  tree_details_->add_node("hp_xp_mp", {
344  { "hp",{
345  { "label", (formatter() << "<small>" << font::span_color(unit::hp_color_max()) << "<b>" << _("HP: ") << "</b>" << type.hitpoints() << "</span>" << " | </small>").str() },
346  { "use_markup", "true" },
347  { "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); }) }
348  } },
349  { "xp",{
350  { "label", (formatter() << "<small>" << font::span_color(unit::xp_color(100, type.can_advance(), true)) << "<b>" << _("XP: ") << "</b>" << type.experience_needed() << "</span>" << " | </small>").str() },
351  { "use_markup", "true" },
352  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
353  } },
354  { "mp",{
355  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << type.movement() << "</small>").str() },
356  { "use_markup", "true" },
357  { "tooltip", get_mp_tooltip(type.movement(), [&type](t_translation::terrain_code terrain) { return type.movement_type().movement_cost(terrain); }) }
358  } },
359  });
360 
361  // Print trait details
362  {
363  tree_view_node* header_node = nullptr;
364 
365  for(const auto& tr : type.possible_traits()) {
366  t_string name = tr[type.genders().front() == unit_race::FEMALE ? "female_name" : "male_name"];
367  if(tr["availability"] != "musthave" || name.empty()) {
368  continue;
369  }
370 
371  if(header_node == nullptr) {
372  header_node = &add_name_tree_node(
374  "header",
375  "<b>" + _("Traits") + "</b>"
376  );
377  }
378 
380  *header_node,
381  "item",
382  name
383  );
384  }
385  }
386 
387  // Print ability details
388  if(!type.abilities_metadata().empty()) {
389 
390  auto& header_node = add_name_tree_node(
392  "header",
393  "<b>" + _("Abilities") + "</b>"
394  );
395 
396  for(const auto& ab : type.abilities_metadata()) {
397  if(!ab.name.empty()) {
399  header_node,
400  "item",
401  ab.name,
402  (formatter() << "<span size='x-large'>" << ab.name << "</span>\n" << ab.description).str()
403  );
404  }
405  }
406  }
407 
409  }
410 }
411 
413 {
414  // Sets the current type id for the profile button callback to use
415  current_type_ = u.type();
416 
417  if(icon_type_) {
418  std::string mods = u.image_mods();
419 
420  if(u.can_recruit()) {
421  mods += "~BLIT(" + unit::leader_crown() + ")";
422  }
423 
424  for(const std::string& overlay : u.overlays()) {
425  mods += "~BLIT(" + overlay + ")";
426  }
427 
428  mods += "~XBRZ(2)~SCALE_INTO_SHARP(144,144)" + image_mods_;
429 
430  icon_type_->set_label(u.absolute_image() + mods);
431  }
432 
433  if(label_name_) {
434  std::string name;
435  if(!u.name().empty()) {
436  name = "<span size='large'>" + u.name() + "</span>" + "\n" + "<small>" + font::span_color(font::unit_type_color) + u.type_name() + "</span></small>";
437  } else {
438  name = "<span size='large'>" + u.type_name() + "</span>\n";
439  }
440 
441  label_name_->set_label(name);
443  }
444 
445  if(label_level_) {
446  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
447 
448  label_level_->set_label("<b>" + l_str + "</b>");
451  }
452 
453  if(label_race_) {
454  label_race_->set_label(u.race()->name(u.gender()));
455  }
456 
457  if(icon_race_) {
458  icon_race_->set_label(u.race()->get_icon_path_stem() + "_30.png");
459  }
460 
461  if(icon_alignment_) {
462  const std::string& alignment_name = u.alignment().to_string();
463 
464  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
466  u.alignment(),
467  u.gender()));
468  }
469 
470  if(label_details_) {
471  std::stringstream str;
472 
473  const std::string name = "<span size='large'>" + (!u.name().empty() ? u.name() : " ") + "</span>";
474  str << name << "\n";
475 
476  str << font::span_color(font::unit_type_color) << u.type_name() << "</span>" << "\n";
477 
478  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
479  str << l_str << "\n";
480 
481  str << unit_type::alignment_description(u.alignment(), u.gender()) << "\n";
482 
483  str << utils::join(u.trait_names(), ", ") << "\n";
484 
485  str << font::span_color(u.hp_color())
486  << _("HP: ") << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << "\n";
487 
488  str << font::span_color(u.xp_color()) << _("XP: ");
489  if(u.can_advance()) {
490  str << u.experience() << "/" << u.max_experience();
491  } else {
492  str << font::unicode_en_dash;
493  }
494  str << "</span>";
495 
496  label_details_->set_label(str.str());
498  }
499 
500  if(tree_details_) {
501  tree_details_->clear();
502  const std::string unit_xp = u.can_advance() ? (formatter() << u.experience() << "/" << u.max_experience()).str() : font::unicode_en_dash;
503  tree_details_->add_node("hp_xp_mp", {
504  { "hp",{
505  { "label", (formatter() << "<small>" << font::span_color(u.hp_color()) << "<b>" << _("HP: ") << "</b>" << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << " | </small>").str() },
506  { "use_markup", "true" },
507  { "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()); }) }
508  } },
509  { "xp",{
510  { "label", (formatter() << "<small>" << font::span_color(u.xp_color()) << "<b>" << _("XP: ") << "</b>" << unit_xp << "</span>" << " | </small>").str() },
511  { "use_markup", "true" },
512  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
513  } },
514  { "mp",{
515  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << u.movement_left() << "/" << u.total_movement() << "</small>").str() },
516  { "use_markup", "true" },
517  { "tooltip", get_mp_tooltip(u.total_movement(), [&u](t_translation::terrain_code terrain) { return u.movement_cost(terrain); }) }
518  } },
519  });
520 
521  if(!u.trait_names().empty()) {
522  auto& header_node = add_name_tree_node(
524  "header",
525  "<b>" + _("Traits") + "</b>"
526  );
527 
528  assert(u.trait_names().size() == u.trait_descriptions().size());
529  for (std::size_t i = 0; i < u.trait_names().size(); ++i) {
531  header_node,
532  "item",
533  u.trait_names()[i],
534  u.trait_descriptions()[i]
535  );
536  }
537  }
538 
539  if(!u.get_ability_list().empty()) {
540  auto& header_node = add_name_tree_node(
542  "header",
543  "<b>" + _("Abilities") + "</b>"
544  );
545 
546  for(const auto& ab : u.ability_tooltips()) {
548  header_node,
549  "item",
550  std::get<2>(ab),
551  std::get<3>(ab)
552  );
553  }
554  }
556  }
557 }
558 
560 {
561  if(get_window() && current_type_) {
563  }
564 }
565 
566 void unit_preview_pane::set_image_mods(const std::string& mods)
567 {
568  image_mods_ = mods;
569 }
570 
571 void unit_preview_pane::set_active(const bool /*active*/)
572 {
573  /* DO NOTHING */
574 }
575 
577 {
578  return true;
579 }
580 
582 {
583  return ENABLED;
584 }
585 
586 void unit_preview_pane::set_self_active(const bool /*active*/)
587 {
588  /* DO NOTHING */
589 }
590 
591 // }---------- DEFINITION ---------{
592 
595 {
596  DBG_GUI_P << "Parsing unit preview pane " << id << '\n';
597 
598  load_resolutions<resolution>(cfg);
599 }
600 
602  : resolution_definition(cfg), grid()
603 {
604  state.emplace_back(cfg.child("background"));
605  state.emplace_back(cfg.child("foreground"));
606 
607  const config& child = cfg.child("grid");
608  VALIDATE(child, _("No grid defined."));
609 
610  grid = std::make_shared<builder_grid>(child);
611 }
612 
613 // }---------- BUILDER -----------{
614 
615 namespace implementation
616 {
617 
618 builder_unit_preview_pane::builder_unit_preview_pane(const config& cfg)
619  : builder_styled_widget(cfg)
620  , image_mods_(cfg["image_mods"])
621 {
622 }
623 
625 {
627 
628  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
629  << "' with definition '" << definition << "'.\n";
630 
631  const auto conf = widget->cast_config_to<unit_preview_pane_definition>();
632  assert(conf);
633 
634  widget->init_grid(*conf->grid);
635  widget->finalize_setup();
636  widget->set_image_mods(image_mods_);
637 
638  return widget;
639 }
640 
641 } // namespace implementation
642 
643 // }------------ END --------------
644 
645 } // namespace gui2
play_controller * controller
Definition: resources.cpp:21
Base class of a resolution, contains the common keys for a resolution.
#define DBG_GUI_P
Definition: log.hpp:65
static config unit_xp(const unit *u)
Definition: reports.cpp:509
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:414
void set_displayed_type(const unit_type &type)
Displays the stats of a specified unit type.
std::vector< state_definition > state
static int get_acceleration()
Definition: types.cpp:541
resistances & get_resistances()
Definition: movetype.hpp:267
std::map< std::string, t_string > string_map
utils::optional_reference< const unit_type > current_type_
const std::string weapon_details_sep
Definition: constants.cpp:49
This class represents a single unit of a specific type.
Definition: unit.hpp:120
int movement_cost(const t_translation::terrain_code &terrain) const
Get the unit&#39;s movement cost on a particular terrain.
Definition: unit.hpp:1431
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
bool terrain_matches(const terrain_code &src, const terrain_code &dest)
Tests whether a specific terrain matches an expression, for matching rules see above.
unit_race::GENDER gender() const
The gender of this unit.
Definition: unit.hpp:458
logger & info()
Definition: log.cpp:88
#define a
int hitpoints() const
The current number of hitpoints this unit has.
Definition: unit.hpp:492
tree_view_node & get_root_node()
Definition: tree_view.hpp:73
const std::string & flag_rgb() const
Definition: types.cpp:689
This file contains the window object, this object is a top level container which has the event manage...
Base class for all widgets.
Definition: widget.hpp:49
std::string dgettext(const char *domain, const char *msgid)
Definition: gettext.cpp:391
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
int experience_needed(bool with_acceleration=true) const
Definition: types.cpp:546
static bool is_indivisible(t_translation::terrain_code id, const t_translation::ter_list &underlying)
Returns true if a terrain has no underlying types other than itself, in respect of either union...
Definition: terrain.hpp:99
int resistance_against(const std::string &damage_name, bool attacker) const
Gets resistance while considering custom WML abilities.
Definition: types.cpp:742
std::string absolute_image() const
The name of the file to game_display (used in menus).
Definition: unit.cpp:2357
styled_widget * label_details_
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
void profile_button_callback()
Callback for the profile button.
static std::string _(const char *str)
Definition: gettext.hpp:92
utils::string_map get_base_resistances() const
Gets resistances without any abilities applied.
Definition: unit.hpp:1040
std::vector< std::tuple< std::string, t_string, t_string, t_string > > ability_tooltips() const
Gets the names and descriptions of this unit&#39;s abilities.
Definition: abilities.cpp:322
A single unit type that the player may recruit.
Definition: types.hpp:44
const color_t unit_type_color
bool is_nonnull() const
True if this object represents some sentinel values.
Definition: terrain.hpp:128
const t_string & name(GENDER gender=MALE) const
Definition: race.hpp:36
const terrain_code VOID_TERRAIN
VOID_TERRAIN is used for shrouded hexes.
Generic file dialog.
Definition: field-fwd.hpp:22
const unit_type & type() const
This unit&#39;s type, accounting for gender and variation.
Definition: unit.hpp:345
color_t hp_color() const
Color for this unit&#39;s current hitpoints.
Definition: unit.cpp:1045
virtual void set_label(const t_string &label)
void set_displayed_unit(const unit &u)
Displays the stats of a specific unit.
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
Base container class.
Definition: grid.hpp:30
std::string definition
Parameters for the styled_widget.
static const std::string & leader_crown()
The path to the leader crown overlay.
Definition: unit.cpp:997
const std::vector< unit_race::GENDER > & genders() const
The returned vector will not be empty, provided this has been built to the HELP_INDEXED status...
Definition: types.hpp:244
void set_tooltip(const t_string &tooltip)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
const movetype & movement_type() const
Definition: types.hpp:182
This file contains the settings handling of the widget library.
std::shared_ptr< terrain_type_data > load_terrain_types_data()
Load the appropriate terrain types data to use.
Definition: help_impl.cpp:1622
const terrain_code FOGGED
std::ostringstream wrapper.
Definition: formatter.hpp:38
const t_string & type_name() const
The name of the unit in the current language setting.
Definition: types.hpp:140
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:171
color_t xp_color() const
Color for this unit&#39;s XP.
Definition: unit.cpp:1099
void init_grid(const builder_grid &grid_builder)
Initializes and builds the grid.
const t_string & name() const
Gets this unit&#39;s translatable display name.
Definition: unit.hpp:393
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
virtual unsigned get_state() const override
See styled_widget::get_state.
virtual void set_active(const bool active) override
See styled_widget::set_active.
static tree_view_node & add_name_tree_node(tree_view_node &header_node, const std::string &type, const t_string &label, const t_string &tooltip="")
int max_experience() const
The max number of experience points this unit can have.
Definition: unit.hpp:522
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:929
const std::vector< ability_metadata > & abilities_metadata() const
Definition: types.hpp:212
int level() const
The current level of this unit.
Definition: unit.hpp:552
virtual void set_use_markup(bool use_markup)
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
Definition: unit.hpp:1074
const std::vector< std::string > & overlays() const
Get the unit&#39;s overlay images.
Definition: unit.hpp:1590
const t_string & type_name() const
Gets the translatable name of this unit&#39;s type.
Definition: unit.hpp:359
static color_t hp_color_max()
Definition: unit.cpp:1055
const std::string unicode_figure_dash
Definition: constants.cpp:44
void show_unit_description(const unit &u)
Definition: help.cpp:57
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
Generic locator abstracting the location of an image.
Definition: picture.hpp:59
static std::string get_side_color_id(unsigned side)
Definition: team.cpp:959
const color_t weapon_details_color
std::size_t i
Definition: function.cpp:940
const std::string unicode_en_dash
Definition: constants.cpp:42
int max_hitpoints() const
The max number of hitpoints this unit can have.
Definition: unit.hpp:498
std::shared_ptr< const typename T::resolution > cast_config_to() const
Casts the current resolution definition config to the respective type of a derived widget...
std::string resistance_color(const int resistance)
Definition: helper.cpp:42
window * get_window()
Get the parent window.
Definition: widget.cpp:116
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
Definition: unit.hpp:605
std::string signed_percent(int val)
Convert into a percentage (using the Unicode "−" and +0% convention.
attack_itors attacks()
Gets an iterator over this unit&#39;s attacks.
Definition: unit.hpp:918
const std::string & icon() const
Definition: types.hpp:171
int level() const
Definition: types.hpp:158
const unit_race * race() const
Gets this unit&#39;s race.
Definition: unit.hpp:486
const std::string unicode_bullet
Definition: constants.cpp:46
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
void finalize_setup()
Initializes the internal sub-widget pointers.
int hitpoints() const
Definition: types.hpp:155
A generic container base class.
int movement() const
Definition: types.hpp:160
int movement_cost(const t_translation::terrain_code &terrain, bool slowed=false) const
Returns the cost to move through the indicated terrain.
Definition: movetype.hpp:281
const t_string & name() const
Definition: terrain.hpp:47
config::const_child_itors possible_traits() const
Definition: types.hpp:226
const std::string & image() const
Definition: types.hpp:170
bool empty() const
Definition: tstring.hpp:186
const ter_match ALL_OFF_MAP
const std::string weapon_numbers_sep
Definition: constants.cpp:48
const t_string & tooltip() const
int experience() const
The current number of experience points this unit has.
Definition: unit.hpp:516
UNIT_ALIGNMENT alignment() const
The alignment of this unit.
Definition: unit.hpp:468
utils::string_map damage_table() const
Returns a map from attack types to resistances.
Definition: movetype.cpp:727
const map_location & get_location() const
The current map location this unit is at.
Definition: unit.hpp:1348
symbol_table string_table
Definition: language.cpp:64
const unit_race * race() const
Never returns nullptr, but may point to the null race.
Definition: types.hpp:272
bool can_advance() const
Checks whether this unit has any options to advance to.
Definition: unit.hpp:262
void set_image_mods(const std::string &mods)
Sets the facing of the unit image.
Class to show the tips.
Definition: tooltip.cpp:56
static std::string get_hp_tooltip(const utils::string_map &res, const std::function< int(const std::string &, bool)> &get)
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1257
void print_attack_details(T attacks, tree_view_node &parent_node)
std::string get_icon_path_stem() const
Gets this race&#39;s icon path without state/size suffix and extension.
Definition: race.cpp:152
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:56
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
Definition: abilities.cpp:238
const_attack_itors attacks() const
Definition: types.cpp:512
int resistance_against(const std::string &damage_name, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
The unit&#39;s resistance against a given damage type.
Definition: unit.cpp:1611
bool can_advance() const
Definition: types.hpp:217
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
static std::string alignment_description(ALIGNMENT align, unit_race::GENDER gender=unit_race::MALE)
tree_view_node & add_child(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
Constructs a new child node.
ALIGNMENT alignment() const
Definition: types.hpp:188
#define DBG_GUI_G
Definition: log.hpp:40
bool file_exists() const
Tests whether the file the locator points at exists.
Definition: picture.cpp:658
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1273
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
Definition: unit.cpp:2536
static std::string get_mp_tooltip(int total_movement, std::function< int(t_translation::terrain_code)> get)
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
tree_view_node & add_node(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
Definition: tree_view.cpp:56
virtual bool get_active() const override
See styled_widget::get_active.
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
Definition: unit.hpp:1084