The Battle for Wesnoth  1.15.0-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 "units/attack_type.hpp"
42 #include "units/types.hpp"
43 #include "units/helper.hpp"
44 #include "units/unit.hpp"
45 
46 #include "utils/functional.hpp"
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<image>(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_) {
90  connect_signal_mouse_left_click(*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(const utils::string_map& res, const std::function<int (const std::string&, bool)>& get)
110 {
111  std::ostringstream tooltip;
112 
113  std::set<std::string> resistances_table;
114 
115  bool att_def_diff = false;
116  for(const utils::string_map::value_type &resist : res) {
117  std::ostringstream line;
118  line << translation::dgettext("wesnoth", resist.first.c_str()) << ": ";
119 
120  // Some units have different resistances when attacking or defending.
121  const int res_att = 100 - get(resist.first, true);
122  const int res_def = 100 - get(resist.first, false);
123 
124  if(res_att == res_def) {
125  line << "<span color='" << unit_helper::resistance_color(res_def) << "'>\t" << utils::signed_percent(res_def) << "</span>";
126  } else {
127  line << "<span color='" << unit_helper::resistance_color(res_att) << "'>\t" << utils::signed_percent(res_att) << "</span>" << "/"
128  << "<span color='" << unit_helper::resistance_color(res_def) << "'>" << utils::signed_percent(res_def) << "</span>";
129  att_def_diff = true;
130  }
131 
132  resistances_table.insert(line.str());
133  }
134 
135  tooltip << "<big>" << _("Resistances: ") << "</big>";
136  if(att_def_diff) {
137  tooltip << _("(Att / Def)");
138  }
139 
140  for(const std::string &line : resistances_table) {
141  tooltip << '\n' << font::unicode_bullet << " " << line;
142  }
143 
144  return tooltip.str();
145 }
146 
147 static inline std::string get_mp_tooltip(int total_movement, std::function<int (t_translation::terrain_code)> get)
148 {
149  std::set<terrain_movement> terrain_moves;
150  std::ostringstream tooltip;
151  tooltip << "<big>" << _("Movement Costs:") << "</big>";
152 
154 
155  if(!tdata) {
156  return "";
157  }
158 
161  continue;
162  }
163 
164  const terrain_type& info = tdata->get_terrain_info(terrain);
165  if(info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) {
166  terrain_moves.emplace(info.name(), get(terrain));
167  }
168  }
169 
170  for(const terrain_movement& tm: terrain_moves)
171  {
172  tooltip << '\n' << font::unicode_bullet << " " << tm.name << ": ";
173 
174  // movement - range: 1 .. 5, movetype::UNREACHABLE=impassable
175  const bool cannot_move = tm.moves > total_movement;
176 
177  std::string color;
178  if(cannot_move) {
179  // cannot move in this terrain
180  color = "red";
181  } else if(tm.moves > 1) {
182  color = "yellow";
183  } else {
184  color = "white";
185  }
186 
187  tooltip << "<span color='" << color << "'>";
188 
189  // A 5 MP margin; if the movement costs go above the unit's max moves + 5, we replace it with dashes.
190  if(cannot_move && (tm.moves > total_movement + 5)) {
191  tooltip << font::unicode_figure_dash;
192  } else {
193  tooltip << tm.moves;
194  }
195 
196  tooltip << "</span>";
197  }
198 
199  return tooltip.str();
200 }
201 
202 /*
203  * Both unit and unit_type use the same format (vector of attack_types) for their
204  * attack data, meaning we can keep this as a helper function.
205  */
206 template<typename T>
208 {
209  if(attacks.empty()) {
210  return;
211  }
212 
213  auto& header_node = add_name_tree_node(
214  parent_node,
215  "header",
216  "<b>" + _("Attacks") + "</b>"
217  );
218 
219  for(const auto& a : attacks) {
220 
221  auto& subsection = add_name_tree_node(
222  header_node,
223  "item",
224  (formatter() << font::span_color(font::unit_type_color) << a.damage() << font::weapon_numbers_sep << a.num_attacks() << " " << a.name() << "</span>").str()
225  );
226 
228  subsection,
229  "item",
230  (formatter() << font::span_color(font::weapon_details_color) << string_table["range_" + a.range()] << font::weapon_details_sep << string_table["type_" + a.type()] << "</span>").str()
231  );
232 
233  for(const auto& pair : a.special_tooltips()) {
235  subsection,
236  "item",
237  (formatter() << font::span_color(font::weapon_details_color) << pair.first << "</span>").str(),
238  (formatter() << "<span size='x-large'>" << pair.first << "</span>" << "\n" << pair.second).str()
239  );
240  }
241  }
242 }
243 
245 {
246  // Sets the current type id for the profile button callback to use
247  current_type_ = type.id();
248 
249  if(icon_type_) {
250  std::string mods;
251 
253  mods = "~RC(" + type.flag_rgb() + ">" +
255  + ")";
256  }
257 
258  mods += "~XBRZ(2)~SCALE_INTO_SHARP(144,144)" + image_mods_;
259 
260  icon_type_->set_label((type.icon().empty() ? type.image() : type.icon()) + mods);
261  }
262 
263  if(label_name_) {
264  label_name_->set_label("<big>" + type.type_name() + "</big>");
266  }
267 
268  if(label_level_) {
269  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
270 
271  label_level_->set_label("<b>" + l_str + "</b>");
273  }
274 
275  if(label_race_) {
276  label_race_ ->set_label(type.race()->name(type.genders().front()));
277  }
278 
279  if(icon_race_) {
280  icon_race_->set_label(type.race()->get_icon_path_stem() + "_30.png");
281  }
282 
283  if(icon_alignment_) {
284  const std::string& alignment_name = type.alignment().to_string();
285 
286  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
288  type.alignment(),
289  type.genders().front()));
290  }
291 
292  if(label_details_) {
293  std::stringstream str;
294 
295  str << "<span size='large'> </span>" << "\n";
296 
297  str << font::span_color(font::unit_type_color) << type.type_name() << "</span>" << "\n";
298 
299  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
300  str << l_str << "\n";
301 
302  str << type.alignment() << "\n";
303 
304  str << "\n"; // Leave a blank line where traits would be
305 
306  str << _("HP: ") << type.hitpoints() << "\n";
307 
308  str << _("XP: ") << type.experience_needed(true);
309 
310  label_details_->set_label(str.str());
312  }
313 
314  if(tree_details_) {
315 
316  tree_details_->clear();
317  tree_details_->add_node("hp_xp_mp", {
318  { "hp",{
319  { "label", (formatter() << "<small>" << "<span color='#21e100'>" << "<b>" << _("HP: ") << "</b>" << type.hitpoints() << "</span>" << " | </small>").str() },
320  { "use_markup", "true" },
321  { "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); }) }
322  } },
323  { "xp",{
324  { "label", (formatter() << "<small>" << "<span color='#00a0e1'>" << "<b>" << _("XP: ") << "</b>" << type.experience_needed() << "</span>" << " | </small>").str() },
325  { "use_markup", "true" },
326  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
327  } },
328  { "mp",{
329  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << type.movement() << "</small>").str() },
330  { "use_markup", "true" },
331  { "tooltip", get_mp_tooltip(type.movement(), [&type](t_translation::terrain_code terrain) { return type.movement_type().movement_cost(terrain); }) }
332  } },
333  });
334 
335  // Print trait details
336  {
337  tree_view_node* header_node = nullptr;
338 
339  for(const auto& tr : type.possible_traits()) {
340  t_string name = tr[type.genders().front() == unit_race::FEMALE ? "female_name" : "male_name"];
341  if(tr["availability"] != "musthave" || name.empty()) {
342  continue;
343  }
344 
345  if(header_node == nullptr) {
346  header_node = &add_name_tree_node(
348  "header",
349  "<b>" + _("Traits") + "</b>"
350  );
351  }
352 
354  *header_node,
355  "item",
356  name
357  );
358  }
359  }
360 
361  // Print ability details
362  if(!type.abilities_metadata().empty()) {
363 
364  auto& header_node = add_name_tree_node(
366  "header",
367  "<b>" + _("Abilities") + "</b>"
368  );
369 
370  for(const auto& ab : type.abilities_metadata()) {
371  if(!ab.name.empty()) {
373  header_node,
374  "item",
375  ab.name,
376  (formatter() << "<span size='x-large'>" << ab.name << "</span>\n" << ab.description).str()
377  );
378  }
379  }
380  }
381 
383  }
384 }
385 
387 {
388  // Sets the current type id for the profile button callback to use
389  current_type_ = u.type_id();
390 
391  if(icon_type_) {
392  std::string mods = u.image_mods();
393 
394  if(u.can_recruit()) {
395  mods += "~BLIT(" + unit::leader_crown() + ")";
396  }
397 
398  for(const std::string& overlay : u.overlays()) {
399  mods += "~BLIT(" + overlay + ")";
400  }
401 
402  mods += "~XBRZ(2)~SCALE_INTO_SHARP(144,144)" + image_mods_;
403 
404  icon_type_->set_label(u.absolute_image() + mods);
405  }
406 
407  if(label_name_) {
408  std::string name;
409  if(!u.name().empty()) {
410  name = "<span size='large'>" + u.name() + "</span>" + "\n" + "<small>" + font::span_color(font::unit_type_color) + u.type_name() + "</span></small>";
411  } else {
412  name = "<span size='large'>" + u.type_name() + "</span>\n";
413  }
414 
415  label_name_->set_label(name);
417  }
418 
419  if(label_level_) {
420  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
421 
422  label_level_->set_label("<b>" + l_str + "</b>");
424  }
425 
426  if(label_race_) {
427  label_race_->set_label(u.race()->name(u.gender()));
428  }
429 
430  if(icon_race_) {
431  icon_race_->set_label(u.race()->get_icon_path_stem() + "_30.png");
432  }
433 
434  if(icon_alignment_) {
435  const std::string& alignment_name = u.alignment().to_string();
436 
437  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
439  u.alignment(),
440  u.gender()));
441  }
442 
443  if(label_details_) {
444  std::stringstream str;
445 
446  const std::string name = "<span size='large'>" + (!u.name().empty() ? u.name() : " ") + "</span>";
447  str << name << "\n";
448 
449  str << font::span_color(font::unit_type_color) << u.type_name() << "</span>" << "\n";
450 
451  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
452  str << l_str << "\n";
453 
454  str << unit_type::alignment_description(u.alignment(), u.gender()) << "\n";
455 
456  str << utils::join(u.trait_names(), ", ") << "\n";
457 
458  str << font::span_color(u.hp_color())
459  << _("HP: ") << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << "\n";
460 
461  str << font::span_color(u.xp_color()) << _("XP: ");
462  if(u.can_advance()) {
463  str << u.experience() << "/" << u.max_experience();
464  } else {
465  str << font::unicode_en_dash;
466  }
467  str << "</span>";
468 
469  label_details_->set_label(str.str());
471  }
472 
473  if(tree_details_) {
474  tree_details_->clear();
475  const std::string unit_xp = u.can_advance() ? (formatter() << u.experience() << "/" << u.max_experience()).str() : font::unicode_en_dash;
476  tree_details_->add_node("hp_xp_mp", {
477  { "hp",{
478  { "label", (formatter() << "<small>" << font::span_color(u.hp_color()) << "<b>" << _("HP: ") << "</b>" << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << " | </small>").str() },
479  { "use_markup", "true" },
480  { "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()); }) }
481  } },
482  { "xp",{
483  { "label", (formatter() << "<small>" << font::span_color(u.xp_color()) << "<b>" << _("XP: ") << "</b>" << unit_xp << "</span>" << " | </small>").str() },
484  { "use_markup", "true" },
485  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
486  } },
487  { "mp",{
488  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << u.movement_left() << "/" << u.total_movement() << "</small>").str() },
489  { "use_markup", "true" },
491  } },
492  });
493 
494  if(!u.trait_names().empty()) {
495  auto& header_node = add_name_tree_node(
497  "header",
498  "<b>" + _("Traits") + "</b>"
499  );
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(
515  "header",
516  "<b>" + _("Abilities") + "</b>"
517  );
518 
519  for(const auto& ab : u.ability_tooltips()) {
521  header_node,
522  "item",
523  std::get<2>(ab),
524  std::get<3>(ab)
525  );
526  }
527  }
529  }
530 }
531 
533 {
534  if(get_window()) {
535  const unit_type* ut = unit_types.find(current_type_);
536  if(ut != nullptr) {
538  }
539  }
540 }
541 
542 void unit_preview_pane::set_image_mods(const std::string& mods)
543 {
544  image_mods_ = mods;
545 }
546 
547 void unit_preview_pane::set_active(const bool /*active*/)
548 {
549  /* DO NOTHING */
550 }
551 
553 {
554  return true;
555 }
556 
558 {
559  return ENABLED;
560 }
561 
562 void unit_preview_pane::set_self_active(const bool /*active*/)
563 {
564  /* DO NOTHING */
565 }
566 
567 // }---------- DEFINITION ---------{
568 
571 {
572  DBG_GUI_P << "Parsing unit preview pane " << id << '\n';
573 
574  load_resolutions<resolution>(cfg);
575 }
576 
578  : resolution_definition(cfg), grid()
579 {
580  state.emplace_back(cfg.child("background"));
581  state.emplace_back(cfg.child("foreground"));
582 
583  const config& child = cfg.child("grid");
584  VALIDATE(child, _("No grid defined."));
585 
586  grid = std::make_shared<builder_grid>(child);
587 }
588 
589 // }---------- BUILDER -----------{
590 
591 namespace implementation
592 {
593 
594 builder_unit_preview_pane::builder_unit_preview_pane(const config& cfg)
595  : builder_styled_widget(cfg)
596  , image_mods_(cfg["image_mods"])
597 {
598 }
599 
601 {
603 
604  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
605  << "' with definition '" << definition << "'.\n";
606 
607  const auto conf = widget->cast_config_to<unit_preview_pane_definition>();
608  assert(conf);
609 
610  widget->init_grid(conf->grid);
611  widget->finalize_setup();
612  widget->set_image_mods(image_mods_);
613 
614  return widget;
615 }
616 
617 } // namespace implementation
618 
619 // }------------ END --------------
620 
621 } // 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:68
static config unit_xp(const unit *u)
Definition: reports.cpp:462
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:423
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:523
resistances & get_resistances()
Definition: movetype.hpp:183
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:1275
std::map< std::string, t_string > string_map
const std::string weapon_details_sep
Definition: constants.cpp:46
This class represents a single unit of a specific type.
Definition: unit.hpp:99
int movement_cost(const t_translation::terrain_code &terrain) const
Get the unit&#39;s movement cost on a particular terrain.
Definition: unit.hpp:1267
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:386
logger & info()
Definition: log.cpp:90
#define a
int hitpoints() const
The current number of hitpoints this unit has.
Definition: unit.hpp:419
tree_view_node & get_root_node()
Definition: tree_view.hpp:53
const std::string & flag_rgb() const
Definition: types.cpp:744
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:47
std::string dgettext(const char *domain, const char *msgid)
Definition: gettext.cpp:393
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:50
int experience_needed(bool with_acceleration=true) const
Definition: types.cpp:528
unit_type_data unit_types
Definition: types.cpp:1452
int resistance_against(const std::string &damage_name, bool attacker) const
Gets resistance while considering custom WML abilities.
Definition: types.cpp:843
std::string absolute_image() const
The name of the file to game_display (used in menus).
Definition: unit.cpp:2286
const std::string & type_id() const
The id of this unit&#39;s type.
Definition: unit.hpp:293
styled_widget * label_details_
Label showing a text.
Definition: label.hpp:32
void profile_button_callback()
Callback for the profile button.
-file sdl_utils.hpp
utils::string_map get_base_resistances() const
Gets resistances without any abilities applied.
Definition: unit.hpp:922
unit_type::ALIGNMENT alignment() const
The alignment of this unit.
Definition: unit.hpp:396
A single unit type that the player may recruit.
Definition: types.hpp:42
const color_t unit_type_color
bool is_nonnull() const
Definition: terrain.hpp:52
const t_string & name(GENDER gender=MALE) const
Definition: race.hpp:36
const terrain_code VOID_TERRAIN
Generic file dialog.
Definition: field-fwd.hpp:22
color_t hp_color() const
Color for this unit&#39;s current hitpoints.
Definition: unit.cpp:1075
virtual void set_label(const t_string &label)
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
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:1027
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
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:174
This file contains the settings handling of the widget library.
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:136
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:217
color_t xp_color() const
Color for this unit&#39;s XP.
Definition: unit.cpp:1085
const t_string & name() const
Gets this unit&#39;s translatable display name.
Definition: unit.hpp:333
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:443
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:944
const std::vector< ability_metadata > & abilities_metadata() const
Definition: types.hpp:209
int level() const
The current level of this unit.
Definition: unit.hpp:467
const std::string & id() const
The id for this unit_type.
Definition: types.hpp:139
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:956
ter_data_cache load_terrain_types_data()
Load the appropriate terrain types data to use.
Definition: help_impl.cpp:1534
const std::vector< std::string > & overlays() const
Get the unit&#39;s overlay images.
Definition: unit.hpp:1426
const t_string & type_name() const
Gets the translatable name of this unit&#39;s type.
Definition: unit.hpp:299
static const ::config * terrain
The terrain used to create the cache.
Definition: minimap.cpp:130
const std::string unicode_figure_dash
Definition: constants.cpp:41
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
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
static std::string get_side_color_id(unsigned side)
Definition: team.cpp:952
const color_t weapon_details_color
std::size_t i
Definition: function.cpp:933
const std::string unicode_en_dash
Definition: constants.cpp:39
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&#39;s abilities.
Definition: abilities.cpp:268
int max_hitpoints() const
The max number of hitpoints this unit can have.
Definition: unit.hpp:425
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:35
window * get_window()
Get the parent window.
Definition: widget.cpp:114
t_translation::terrain_code number() const
Definition: terrain.hpp:44
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
Definition: unit.hpp:507
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:811
const t_translation::ter_list & union_type() const
Definition: terrain.hpp:50
const std::string & icon() const
Definition: types.hpp:163
int level() const
Definition: types.hpp:150
const unit_race * race() const
Gets this unit&#39;s race.
Definition: unit.hpp:413
const std::string unicode_bullet
Definition: constants.cpp:43
#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:147
A generic container base class.
int movement() const
Definition: types.hpp:152
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
const t_string & name() const
Definition: terrain.hpp:33
config::const_child_itors possible_traits() const
Definition: types.hpp:223
const std::string & image() const
Definition: types.hpp:162
bool empty() const
Definition: tstring.hpp:182
const ter_match ALL_OFF_MAP
const std::string weapon_numbers_sep
Definition: constants.cpp:45
const t_string & tooltip() const
int experience() const
The current number of experience points this unit has.
Definition: unit.hpp:437
utils::string_map damage_table() const
Returns a map from attack types to resistances.
Definition: movetype.cpp:626
const map_location & get_location() const
The current map location this unit is at.
Definition: unit.hpp:1184
symbol_table string_table
Definition: language.cpp:63
const unit_race * race() const
Never returns nullptr, but may point to the null race.
Definition: types.hpp:265
bool can_advance() const
Checks whether this unit has any options to advance to.
Definition: unit.hpp:198
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 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:1095
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:150
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
Definition: abilities.cpp:226
const_attack_itors attacks() const
Definition: types.cpp:494
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:1585
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
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.
#define DBG_GUI_G
Definition: log.hpp:40
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1110
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
Definition: unit.cpp:2474
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:61
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:966
std::shared_ptr< terrain_type_data > ter_data_cache