The Battle for Wesnoth  1.13.11+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
unit_preview_pane.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 The Battle for Wesnoth Project http://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 "preferences/game.hpp"
33 #include "gettext.hpp"
34 #include "help/help.hpp"
35 #include "help/help_impl.hpp"
36 #include "play_controller.hpp"
37 #include "resources.hpp"
38 #include "team.hpp"
39 #include "units/attack_type.hpp"
40 #include "units/types.hpp"
41 #include "units/helper.hpp"
42 #include "units/unit.hpp"
43 
44 #include "utils/functional.hpp"
45 
46 namespace gui2
47 {
48 
49 // ------------ WIDGET -----------{
50 
51 REGISTER_WIDGET(unit_preview_pane)
52 
53 unit_preview_pane::unit_preview_pane(const implementation::builder_unit_preview_pane& builder)
54  : container_base(builder, get_control_type())
55  , current_type_()
56  , icon_type_(nullptr)
57  , icon_race_(nullptr)
58  , icon_alignment_(nullptr)
59  , label_name_(nullptr)
60  , label_level_(nullptr)
61  , label_race_(nullptr)
62  , label_details_(nullptr)
63  , tree_details_(nullptr)
64  , button_profile_(nullptr)
65  , image_mods_()
66 {
67 }
68 
70 {
71  // Icons
72  icon_type_ = find_widget<image>(this, "type_image", false, false);
73  icon_race_ = find_widget<image>(this, "type_race", false, false);
74  icon_alignment_ = find_widget<image>(this, "type_alignment", false, false);
75 
76  // Labels
77  label_name_ = find_widget<label>(this, "type_name", false, false);
78  label_level_ = find_widget<label>(this, "type_level", false, false);
79  label_race_ = find_widget<label>(this, "type_race_label", false, false);
80  label_details_ = find_widget<styled_widget>(this, "type_details_minimal", false, false);
81 
82  tree_details_ = find_widget<tree_view>(this, "type_details", false, false);
83 
84  // Profile button
85  button_profile_ = find_widget<button>(this, "type_profile", false, false);
86 
87  if(button_profile_) {
88  connect_signal_mouse_left_click(*button_profile_,
90  }
91 }
92 
93 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 = "")
94 {
95  /* Note: We have to pass data instead of just doing 'child_label.set_label(label)' below
96  * because the tree_view_node::add_child needs to have the correct size of the
97  * node child widgets for its internal size calculations.
98  * Same is true for 'use_markup'
99  */
100  auto& child_node = header_node.add_child(type, { { "name",{ { "label", label },{ "use_markup", "true" } } } });
101  auto& child_label = find_widget<styled_widget>(&child_node, "name", true);
102 
103  child_label.set_tooltip(tooltip);
104  return child_node;
105 }
106 
107 static inline std::string get_hp_tooltip(const utils::string_map& res, const std::function<int (const std::string&, bool)>& get)
108 {
109  std::ostringstream tooltip;
110 
111  std::set<std::string> resistances_table;
112 
113  bool att_def_diff = false;
114  for(const utils::string_map::value_type &resist : res) {
115  std::ostringstream line;
116  line << translation::dgettext("wesnoth", resist.first.c_str()) << ": ";
117 
118  // Some units have different resistances when attacking or defending.
119  const int res_att = 100 - get(resist.first, true);
120  const int res_def = 100 - get(resist.first, false);
121 
122  if(res_att == res_def) {
123  line << "<span color='" << unit_helper::resistance_color(res_def) << "'>" << utils::signed_percent(res_def) << "</span>";
124  } else {
125  line << "<span color='" << unit_helper::resistance_color(res_att) << "'>" << utils::signed_percent(res_att) << "</span>" << "/"
126  << "<span color='" << unit_helper::resistance_color(res_def) << "'>" << utils::signed_percent(res_def) << "</span>";
127  att_def_diff = true;
128  }
129 
130  resistances_table.insert(line.str());
131  }
132 
133  tooltip << "<big>" << _("Resistances: ") << "</big>";
134  if(att_def_diff) {
135  tooltip << _("(Att / Def)");
136  }
137 
138  for(const std::string &line : resistances_table) {
139  tooltip << '\n' << font::unicode_bullet << " " << line;
140  }
141 
142  return tooltip.str();
143 }
144 
145 static inline std::string get_mp_tooltip(int total_movement, std::function<int (t_translation::terrain_code)> get)
146 {
147  std::ostringstream tooltip;
148  tooltip << "<big>" << _("Movement Costs:") << "</big>";
149 
151 
152  if(!tdata) {
153  return "";
154  }
155 
158  continue;
159  }
160 
161  const terrain_type& info = tdata->get_terrain_info(terrain);
162  if(info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) {
163  const std::string& name = info.name();
164  const int moves = get(terrain);
165 
166  tooltip << '\n' << font::unicode_bullet << " " << name << ": ";
167 
168  // movement - range: 1 .. 5, movetype::UNREACHABLE=impassable
169  const bool cannot_move = moves > total_movement;
170 
171  std::string color;
172  if(cannot_move) {
173  // cannot move in this terrain
174  color = "red";
175  } else if(moves > 1) {
176  color = "yellow";
177  } else {
178  color = "white";
179  }
180 
181  tooltip << "<span color='" << color << "'>";
182 
183  // A 5 MP margin; if the movement costs go above the unit's max moves + 5, we replace it with dashes.
184  if(cannot_move && (moves > total_movement + 5)) {
185  tooltip << font::unicode_figure_dash;
186  } else {
187  tooltip << moves;
188  }
189 
190  tooltip << "</span>";
191  }
192  }
193 
194  return tooltip.str();
195 }
196 
197 /*
198  * Both unit and unit_type use the same format (vector of attack_types) for their
199  * attack data, meaning we can keep this as a helper function.
200  */
201 template<typename T>
203 {
204  if(attacks.empty()) {
205  return;
206  }
207 
208  auto& header_node = add_name_tree_node(
209  parent_node,
210  "header",
211  "<b>" + _("Attacks") + "</b>"
212  );
213 
214  for(const auto& a : attacks) {
215 
216  auto& subsection = add_name_tree_node(
217  header_node,
218  "item",
219  (formatter() << font::span_color(font::unit_type_color) << a.damage() << font::weapon_numbers_sep << a.num_attacks() << " " << a.name() << "</span>").str()
220  );
221 
223  subsection,
224  "item",
225  (formatter() << font::span_color(font::weapon_details_color) << a.range() << font::weapon_details_sep << a.type() << "</span>").str()
226  );
227 
228  for(const auto& pair : a.special_tooltips()) {
230  subsection,
231  "item",
232  (formatter() << font::span_color(font::weapon_details_color) << pair.first << "</span>").str(),
233  (formatter() << "<span size='x-large'>" << pair.first << "</span>" << "\n" << pair.second).str()
234  );
235  }
236  }
237 }
238 
240 {
241  // Sets the current type id for the profile button callback to use
242  current_type_ = type.id();
243 
244  if(icon_type_) {
245  std::string mods;
246 
248  mods = "~RC(" + type.flag_rgb() + ">" +
250  + ")";
251  }
252 
253  mods += "~SCALE_INTO_SHARP(144,144)" + image_mods_;
254 
255  icon_type_->set_label((type.icon().empty() ? type.image() : type.icon()) + mods);
256  }
257 
258  if(label_name_) {
259  label_name_->set_label("<big>" + type.type_name() + "</big>");
261  }
262 
263  if(label_level_) {
264  std::string l_str = vgettext("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
265 
266  label_level_->set_label("<b>" + l_str + "</b>");
268  }
269 
270  if(label_race_) {
271  label_race_ ->set_label(type.race()->name(type.genders().front()));
272  }
273 
274  if(icon_race_) {
275  icon_race_->set_label(type.race()->get_icon_path_stem() + "_30.png");
276  }
277 
278  if(icon_alignment_) {
279  const std::string& alignment_name = type.alignment().to_string();
280 
281  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
283  type.alignment(),
284  type.genders().front()));
285  }
286 
287  if(label_details_) {
288  std::stringstream str;
289 
290  str << "<span size='large'> </span>" << "\n";
291 
292  str << font::span_color(font::unit_type_color) << type.type_name() << "</span>" << "\n";
293 
294  std::string l_str = vgettext("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
295  str << l_str << "\n";
296 
297  str << type.alignment() << "\n";
298 
299  str << "\n"; // Leave a blank line where traits would be
300 
301  str << _("HP: ") << type.hitpoints() << "\n";
302 
303  str << _("XP: ") << type.experience_needed(true);
304 
305  label_details_->set_label(str.str());
307  }
308 
309  if(tree_details_) {
310 
311  tree_details_->clear();
312  tree_details_->add_node("hp_xp_mp", {
313  { "hp",{
314  { "label", (formatter() << "<small>" << "<span color='#21e100'>" << "<b>" << _("HP: ") << "</b>" << type.hitpoints() << "</span>" << " | </small>").str() },
315  { "use_markup", "true" },
316  { "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); }) }
317  } },
318  { "xp",{
319  { "label", (formatter() << "<small>" << "<span color='#00a0e1'>" << "<b>" << _("XP: ") << "</b>" << type.experience_needed() << "</span>" << " | </small>").str() },
320  { "use_markup", "true" },
321  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
322  } },
323  { "mp",{
324  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << type.movement() << "</small>").str() },
325  { "use_markup", "true" },
326  { "tooltip", get_mp_tooltip(type.movement(), [&type](t_translation::terrain_code terrain) { return type.movement_type().movement_cost(terrain); }) }
327  } },
328  });
329 
330  // Print trait details
331  {
332  tree_view_node* header_node = nullptr;
333 
334  for(const auto& tr : type.possible_traits()) {
335  t_string name = tr[type.genders().front() == unit_race::FEMALE ? "female_name" : "male_name"];
336  if(tr["availability"] != "musthave" || name.empty()) {
337  continue;
338  }
339 
340  if(header_node == nullptr) {
341  header_node = &add_name_tree_node(
343  "header",
344  "<b>" + _("Traits") + "</b>"
345  );
346  }
347 
349  *header_node,
350  "item",
351  name
352  );
353  }
354  }
355 
356  // Print ability details
357  if(!type.abilities_metadata().empty()) {
358 
359  auto& header_node = add_name_tree_node(
361  "header",
362  "<b>" + _("Abilities") + "</b>"
363  );
364 
365  for(const auto& ab : type.abilities_metadata()) {
366  if(!ab.name.empty()) {
368  header_node,
369  "item",
370  ab.name,
371  (formatter() << "<span size='x-large'>" << ab.name << "</span>\n" << ab.description).str()
372  );
373  }
374  }
375  }
376 
378  }
379 }
380 
382 {
383  // Sets the current type id for the profile button callback to use
384  current_type_ = u.type_id();
385 
386  if(icon_type_) {
387  std::string mods = u.image_mods();
388 
389  if(u.can_recruit()) {
390  mods += "~BLIT(" + unit::leader_crown() + ")";
391  }
392 
393  for(const std::string& overlay : u.overlays()) {
394  mods += "~BLIT(" + overlay + ")";
395  }
396 
397  mods += "~SCALE_INTO_SHARP(144,144)" + image_mods_;
398 
399  icon_type_->set_label(u.absolute_image() + mods);
400  }
401 
402  if(label_name_) {
404  if(!u.name().empty()) {
405  name = "<span size='large'>" + u.name() + "</span>" + "\n" + "<small>" + font::span_color(font::unit_type_color) + u.type_name() + "</span></small>";
406  } else {
407  name = "<span size='large'>" + u.type_name() + "</span>\n";
408  }
409 
410  label_name_->set_label(name);
412  }
413 
414  if(label_level_) {
415  std::string l_str = vgettext("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
416 
417  label_level_->set_label("<b>" + l_str + "</b>");
419  }
420 
421  if(label_race_) {
422  label_race_->set_label(u.race()->name(u.gender()));
423  }
424 
425  if(icon_race_) {
426  icon_race_->set_label("icons/unit-groups/race_" + u.race()->id() + "_30.png");
427  }
428 
429  if(icon_alignment_) {
430  const std::string& alignment_name = u.alignment().to_string();
431 
432  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
434  u.alignment(),
435  u.gender()));
436  }
437 
438  if(label_details_) {
439  std::stringstream str;
440 
441  const std::string name = "<span size='large'>" + (!u.name().empty() ? u.name() : " ") + "</span>";
442  str << name << "\n";
443 
444  str << font::span_color(font::unit_type_color) << u.type_name() << "</span>" << "\n";
445 
446  std::string l_str = vgettext("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
447  str << l_str << "\n";
448 
449  str << u.alignment() << "\n";
450 
451  str << utils::join(u.trait_names(), ", ") << "\n";
452 
453  str << font::span_color(u.hp_color())
454  << _("HP: ") << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << "\n";
455 
456  str << font::span_color(u.xp_color())
457  << _("XP: ") << u.experience() << "/" << u.max_experience() << "</span>";
458 
459  label_details_->set_label(str.str());
461  }
462 
463  if(tree_details_) {
464  tree_details_->clear();
465  tree_details_->add_node("hp_xp_mp", {
466  { "hp",{
467  { "label", (formatter() << "<small>" << font::span_color(u.hp_color()) << "<b>" << _("HP: ") << "</b>" << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << " | </small>").str() },
468  { "use_markup", "true" },
469  { "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()); }) }
470  } },
471  { "xp",{
472  { "label", (formatter() << "<small>" << font::span_color(u.xp_color()) << "<b>" << _("XP: ") << "</b>" << u.experience() << "/" << u.max_experience() << "</span>" << " | </small>").str() },
473  { "use_markup", "true" },
474  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
475  } },
476  { "mp",{
477  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << u.movement_left() << "/" << u.total_movement() << "</small>").str() },
478  { "use_markup", "true" },
480  } },
481  });
482 
483  if(!u.trait_names().empty()) {
484  auto& header_node = add_name_tree_node(
486  "header",
487  "<b>" + _("Traits") + "</b>"
488  );
489 
490  assert(u.trait_names().size() == u.trait_descriptions().size());
491  for (size_t i = 0; i < u.trait_names().size(); ++i) {
493  header_node,
494  "item",
495  u.trait_names()[i],
496  u.trait_descriptions()[i]
497  );
498  }
499  }
500 
501  if(!u.get_ability_list().empty()) {
502  auto& header_node = add_name_tree_node(
504  "header",
505  "<b>" + _("Abilities") + "</b>"
506  );
507 
508  for(const auto& ab : u.ability_tooltips()) {
510  header_node,
511  "item",
512  std::get<2>(ab),
513  std::get<3>(ab)
514  );
515  }
516  }
518  }
519 }
520 
522 {
523  if(get_window()) {
524  const unit_type* ut = unit_types.find(current_type_);
525  if(ut != nullptr) {
527  }
528  }
529 }
530 
532 {
533  image_mods_ = mods;
534 }
535 
536 void unit_preview_pane::set_active(const bool /*active*/)
537 {
538  /* DO NOTHING */
539 }
540 
542 {
543  return true;
544 }
545 
547 {
548  return ENABLED;
549 }
550 
551 void unit_preview_pane::set_self_active(const bool /*active*/)
552 {
553  /* DO NOTHING */
554 }
555 
556 // }---------- DEFINITION ---------{
557 
560 {
561  DBG_GUI_P << "Parsing unit preview pane " << id << '\n';
562 
563  load_resolutions<resolution>(cfg);
564 }
565 
567  : resolution_definition(cfg), grid()
568 {
569  state.emplace_back(cfg.child("background"));
570  state.emplace_back(cfg.child("foreground"));
571 
572  const config& child = cfg.child("grid");
573  VALIDATE(child, _("No grid defined."));
574 
575  grid = std::make_shared<builder_grid>(child);
576 }
577 
578 // }---------- BUILDER -----------{
579 
580 namespace implementation
581 {
582 
583 builder_unit_preview_pane::builder_unit_preview_pane(const config& cfg)
584  : builder_styled_widget(cfg)
585  , image_mods_(cfg["image_mods"])
586 {
587 }
588 
590 {
592 
593  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
594  << "' with definition '" << definition << "'.\n";
595 
596  const auto conf = widget->cast_config_to<unit_preview_pane_definition>();
597  assert(conf);
598 
599  widget->init_grid(conf->grid);
600  widget->finalize_setup();
601  widget->set_image_mods(image_mods_);
602 
603  return widget;
604 }
605 
606 } // namespace implementation
607 
608 // }------------ END --------------
609 
610 } // namespace gui2
play_controller * controller
Definition: resources.cpp:21
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
Definition: unit.hpp:928
Base class of a resolution, contains the common keys for a resolution.
#define DBG_GUI_P
Definition: log.hpp:68
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:197
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:419
void set_displayed_type(const unit_type &type)
Displays the stats of a specified unit type.
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1057
std::vector< char_t > string
std::vector< state_definition > state
static int get_acceleration()
Definition: types.cpp:524
const t_translation::ter_list & union_type() const
Definition: terrain.hpp:50
resistances & get_resistances()
Definition: movetype.hpp:183
std::map< std::string, t_string > string_map
const t_string & type_name() const
The name of the unit in the current language setting.
Definition: types.hpp:136
const std::string weapon_details_sep
Definition: constants.cpp:45
This class represents a single unit of a specific type.
Definition: unit.hpp:100
int movement() const
Definition: types.hpp:152
const t_string & name(GENDER gender=MALE) const
Definition: race.hpp:34
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
utils::string_map get_base_resistances() const
Gets resistances without any abilities applied.
Definition: unit.hpp:884
bool terrain_matches(const terrain_code &src, const terrain_code &dest)
Tests whether a specific terrain matches an expression, for matching rules see above.
logger & info()
Definition: log.cpp:91
#define a
tree_view_node & get_root_node()
Definition: tree_view.hpp:52
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1067
const movetype & movement_type() const
Definition: types.hpp:174
const_attack_itors attacks() const
Definition: types.cpp:495
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:48
color_t xp_color() const
Color for this unit's XP.
Definition: unit.cpp:1125
int level() const
The current level of this unit.
Definition: unit.hpp:441
const std::string & id() const
Definition: race.hpp:32
std::string dgettext(const char *domain, const char *msgid)
const t_string & name() const
Definition: terrain.hpp:33
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
unit_type_data unit_types
Definition: types.cpp:1453
const unit_race * race() const
Never returns nullptr, but may point to the null race.
Definition: types.hpp:265
const std::string & image() const
Definition: types.hpp:162
color_t hp_color() const
Color for this unit's current hitpoints.
Definition: unit.cpp:1115
styled_widget * label_details_
Label showing a text.
Definition: label.hpp:32
const std::string & type_id() const
The id of this unit's type.
Definition: unit.hpp:267
void profile_button_callback()
Callback for the profile button.
-file sdl_utils.hpp
int level() const
Definition: types.hpp:150
const std::vector< ability_metadata > & abilities_metadata() const
Definition: types.hpp:209
const std::string & flag_rgb() const
Definition: types.cpp:745
utils::string_map damage_table() const
Returns a map from attack types to resistances.
Definition: movetype.cpp:626
A single unit type that the player may recruit.
Definition: types.hpp:42
const color_t unit_type_color
const unit_race * race() const
Gets this unit's race.
Definition: unit.hpp:387
const terrain_code VOID_TERRAIN
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
Definition: unit.hpp:1383
Generic file dialog.
Definition: field-fwd.hpp:22
virtual void set_label(const t_string &label)
int max_experience() const
The max number of experience points this unit can have.
Definition: unit.hpp:417
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
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
std::string definition
Parameters for the styled_widget.
static const std::string & leader_crown()
The path to the leader crown overlay.
Definition: unit.cpp:1067
int resistance_against(const std::string &damage_name, bool attacker, const map_location &loc) const
The unit's resistance against a given damage type.
Definition: unit.cpp:1625
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
Definition: unit.cpp:2501
void set_tooltip(const t_string &tooltip)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
This file contains the settings handling of the widget library.
const terrain_code FOGGED
const map_location & get_location() const
The current map location this unit is at.
Definition: unit.hpp:1141
std::ostringstream wrapper.
Definition: formatter.hpp:38
int hitpoints() const
The current number of hitpoints this unit has.
Definition: unit.hpp:393
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:218
std::string get_icon_path_stem() const
Gets this race's icon path without state/size suffix and extension.
Definition: race.cpp:150
const t_string & name() const
Gets this unit's translatable display name.
Definition: unit.hpp:307
unit_race::GENDER gender() const
The gender of this unit.
Definition: unit.hpp:360
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
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:239
virtual unsigned get_state() const override
See styled_widget::get_state.
virtual void set_active(const bool active) override
See styled_widget::set_active.
t_translation::terrain_code number() const
Definition: terrain.hpp:44
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_hitpoints() const
The max number of hitpoints this unit can have.
Definition: unit.hpp:399
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:946
virtual void set_use_markup(bool use_markup)
ter_data_cache load_terrain_types_data()
Load the appropriate terrain types data to use.
Definition: help_impl.cpp:1545
const std::string & icon() const
Definition: types.hpp:163
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
Definition: abilities.cpp:220
int experience() const
The current number of experience points this unit has.
Definition: unit.hpp:411
static const ::config * terrain
The terrain used to create the cache.
Definition: minimap.cpp:130
const std::string unicode_figure_dash
Definition: constants.cpp:40
bool is_nonnull() const
Definition: terrain.hpp:52
tree_view_node & add_child(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
Adds a child item to the list of child nodes.
void init_grid(const std::shared_ptr< builder_grid > &grid_builder)
Initializes and builds the grid.
void show_unit_description(const unit &u)
Definition: help.cpp:58
std::vector< std::tuple< std::string, t_string, t_string, t_string > > ability_tooltips(boost::dynamic_bitset<> *active_list=nullptr) const
Gets the names and descriptions of this unit's abilities.
Definition: abilities.cpp:262
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
static std::string get_side_color_id(unsigned side)
Definition: team.cpp:941
const color_t weapon_details_color
const t_string & type_name() const
Gets the translatable name of this unit's type.
Definition: unit.hpp:273
std::string resistance_color(const int resistance)
Definition: helper.cpp:35
config::const_child_itors possible_traits() const
Definition: types.hpp:223
window * get_window()
Get the parent window.
Definition: widget.cpp:114
std::string absolute_image() const
The name of the file to game_display (used in menus).
Definition: unit.cpp:2327
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's attacks.
Definition: unit.hpp:785
size_t i
Definition: function.cpp:933
int movement_cost(const t_translation::terrain_code &terrain) const
Get the unit's movement cost on a particular terrain.
Definition: unit.hpp:1224
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
Definition: unit.hpp:481
const std::string unicode_bullet
Definition: constants.cpp:42
void finalize_setup()
Initializes the internal sub-widget pointers.
A generic container base class.
std::string vgettext(const char *msgid, const utils::string_map &symbols)
int hitpoints() const
Definition: types.hpp:147
int experience_needed(bool with_acceleration=true) const
Definition: types.cpp:529
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...
const ter_match ALL_OFF_MAP
const std::string weapon_numbers_sep
Definition: constants.cpp:44
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
Definition: unit.hpp:918
unit_type::ALIGNMENT alignment() const
The alignment of this unit.
Definition: unit.hpp:370
void set_image_mods(const std::string &mods)
Sets the facing of the unit image.
Class to show the tips.
Definition: tooltip.cpp:71
static std::string get_hp_tooltip(const utils::string_map &res, const std::function< int(const std::string &, bool)> &get)
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
void print_attack_details(T attacks, tree_view_node &parent_node)
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
Definition: types.cpp:1276
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
static std::string alignment_description(ALIGNMENT align, unit_race::GENDER gender=unit_race::MALE)
#define DBG_GUI_G
Definition: log.hpp:40
bool empty() const
Definition: tstring.hpp:182
static std::string get_mp_tooltip(int total_movement, std::function< int(t_translation::terrain_code)> get)
int resistance_against(const std::string &damage_name, bool attacker) const
Gets resistance while considering custom WML abilities.
Definition: types.cpp:844
const std::string & id() const
The id for this unit_type.
Definition: types.hpp:139
Contains the implementation details for lexical_cast and shouldn'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:62
virtual bool get_active() const override
See styled_widget::get_active.
std::shared_ptr< terrain_type_data > ter_data_cache