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 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 "language.hpp"
33 #include "preferences/game.hpp"
34 #include "gettext.hpp"
35 #include "help/help.hpp"
36 #include "help/utils.hpp"
37 #include "play_controller.hpp"
38 #include "resources.hpp"
39 #include "team.hpp"
40 #include "units/attack_type.hpp"
41 #include "units/types.hpp"
42 #include "units/helper.hpp"
43 #include "units/unit.hpp"
44 
45 #include "utils/functional.hpp"
46 
47 namespace gui2
48 {
49 
50 // ------------ WIDGET -----------{
51 
52 REGISTER_WIDGET(unit_preview_pane)
53 
54 unit_preview_pane::unit_preview_pane(const implementation::builder_unit_preview_pane& builder)
55  : container_base(builder, get_control_type())
56  , current_type_()
57  , icon_type_(nullptr)
58  , icon_race_(nullptr)
59  , icon_alignment_(nullptr)
60  , label_name_(nullptr)
61  , label_level_(nullptr)
62  , label_race_(nullptr)
63  , label_details_(nullptr)
64  , tree_details_(nullptr)
65  , button_profile_(nullptr)
66  , image_mods_()
67 {
68 }
69 
71 {
72  // Icons
73  icon_type_ = find_widget<image>(this, "type_image", false, false);
74  icon_race_ = find_widget<image>(this, "type_race", false, false);
75  icon_alignment_ = find_widget<image>(this, "type_alignment", false, false);
76 
77  // Labels
78  label_name_ = find_widget<label>(this, "type_name", false, false);
79  label_level_ = find_widget<label>(this, "type_level", false, false);
80  label_race_ = find_widget<label>(this, "type_race_label", false, false);
81  label_details_ = find_widget<styled_widget>(this, "type_details_minimal", false, false);
82 
83  tree_details_ = find_widget<tree_view>(this, "type_details", false, false);
84 
85  // Profile button
86  button_profile_ = find_widget<button>(this, "type_profile", false, false);
87 
88  if(button_profile_) {
89  connect_signal_mouse_left_click(*button_profile_,
91  }
92 }
93 
94 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 = "")
95 {
96  /* Note: We have to pass data instead of just doing 'child_label.set_label(label)' below
97  * because the tree_view_node::add_child needs to have the correct size of the
98  * node child widgets for its internal size calculations.
99  * Same is true for 'use_markup'
100  */
101  auto& child_node = header_node.add_child(type, { { "name",{ { "label", label },{ "use_markup", "true" } } } });
102  auto& child_label = find_widget<styled_widget>(&child_node, "name", true);
103 
104  child_label.set_tooltip(tooltip);
105  return child_node;
106 }
107 
108 static inline std::string get_hp_tooltip(const utils::string_map& res, const std::function<int (const std::string&, bool)>& get)
109 {
110  std::ostringstream tooltip;
111 
112  std::set<std::string> resistances_table;
113 
114  bool att_def_diff = false;
115  for(const utils::string_map::value_type &resist : res) {
116  std::ostringstream line;
117  line << translation::dgettext("wesnoth", resist.first.c_str()) << ": ";
118 
119  // Some units have different resistances when attacking or defending.
120  const int res_att = 100 - get(resist.first, true);
121  const int res_def = 100 - get(resist.first, false);
122 
123  if(res_att == res_def) {
124  line << "<span color='" << unit_helper::resistance_color(res_def) << "'>\t" << utils::signed_percent(res_def) << "</span>";
125  } else {
126  line << "<span color='" << unit_helper::resistance_color(res_att) << "'>\t" << utils::signed_percent(res_att) << "</span>" << "/"
127  << "<span color='" << unit_helper::resistance_color(res_def) << "'>" << utils::signed_percent(res_def) << "</span>";
128  att_def_diff = true;
129  }
130 
131  resistances_table.insert(line.str());
132  }
133 
134  tooltip << "<big>" << _("Resistances: ") << "</big>";
135  if(att_def_diff) {
136  tooltip << _("(Att / Def)");
137  }
138 
139  for(const std::string &line : resistances_table) {
140  tooltip << '\n' << font::unicode_bullet << " " << line;
141  }
142 
143  return tooltip.str();
144 }
145 
146 static inline std::string get_mp_tooltip(int total_movement, std::function<int (t_translation::terrain_code)> get)
147 {
148  std::ostringstream tooltip;
149  tooltip << "<big>" << _("Movement Costs:") << "</big>";
150 
152 
153  if(!tdata) {
154  return "";
155  }
156 
159  continue;
160  }
161 
162  const terrain_type& info = tdata->get_terrain_info(terrain);
163  if(info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) {
164  const std::string& name = info.name();
165  const int moves = get(terrain);
166 
167  tooltip << '\n' << font::unicode_bullet << " " << name << ": ";
168 
169  // movement - range: 1 .. 5, movetype::UNREACHABLE=impassable
170  const bool cannot_move = moves > total_movement;
171 
172  std::string color;
173  if(cannot_move) {
174  // cannot move in this terrain
175  color = "red";
176  } else if(moves > 1) {
177  color = "yellow";
178  } else {
179  color = "white";
180  }
181 
182  tooltip << "\t<span color='" << color << "'>";
183 
184  // A 5 MP margin; if the movement costs go above the unit's max moves + 5, we replace it with dashes.
185  if(cannot_move && (moves > total_movement + 5)) {
186  tooltip << font::unicode_figure_dash;
187  } else {
188  tooltip << moves;
189  }
190 
191  tooltip << "</span>";
192  }
193  }
194 
195  return tooltip.str();
196 }
197 
198 /*
199  * Both unit and unit_type use the same format (vector of attack_types) for their
200  * attack data, meaning we can keep this as a helper function.
201  */
202 template<typename T>
204 {
205  if(attacks.empty()) {
206  return;
207  }
208 
209  auto& header_node = add_name_tree_node(
210  parent_node,
211  "header",
212  "<b>" + _("Attacks") + "</b>"
213  );
214 
215  for(const auto& a : attacks) {
216 
217  auto& subsection = add_name_tree_node(
218  header_node,
219  "item",
220  (formatter() << font::span_color(font::unit_type_color) << a.damage() << font::weapon_numbers_sep << a.num_attacks() << " " << a.name() << "</span>").str()
221  );
222 
224  subsection,
225  "item",
226  (formatter() << font::span_color(font::weapon_details_color) << string_table["range_" + a.range()] << font::weapon_details_sep << string_table["type_" + a.type()] << "</span>").str()
227  );
228 
229  for(const auto& pair : a.special_tooltips()) {
231  subsection,
232  "item",
233  (formatter() << font::span_color(font::weapon_details_color) << pair.first << "</span>").str(),
234  (formatter() << "<span size='x-large'>" << pair.first << "</span>" << "\n" << pair.second).str()
235  );
236  }
237  }
238 }
239 
241 {
242  // Sets the current type id for the profile button callback to use
243  current_type_ = type.id();
244 
245  if(icon_type_) {
246  std::string mods;
247 
249  mods = "~RC(" + type.flag_rgb() + ">" +
251  + ")";
252  }
253 
254  mods += "~XBRZ(2)~SCALE_INTO_SHARP(144,144)" + image_mods_;
255 
256  icon_type_->set_label((type.icon().empty() ? type.image() : type.icon()) + mods);
257  }
258 
259  if(label_name_) {
260  label_name_->set_label("<big>" + type.type_name() + "</big>");
262  }
263 
264  if(label_level_) {
265  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
266 
267  label_level_->set_label("<b>" + l_str + "</b>");
269  }
270 
271  if(label_race_) {
272  label_race_ ->set_label(type.race()->name(type.genders().front()));
273  }
274 
275  if(icon_race_) {
276  icon_race_->set_label(type.race()->get_icon_path_stem() + "_30.png");
277  }
278 
279  if(icon_alignment_) {
280  const std::string& alignment_name = type.alignment().to_string();
281 
282  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
284  type.alignment(),
285  type.genders().front()));
286  }
287 
288  if(label_details_) {
289  std::stringstream str;
290 
291  str << "<span size='large'> </span>" << "\n";
292 
293  str << font::span_color(font::unit_type_color) << type.type_name() << "</span>" << "\n";
294 
295  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
296  str << l_str << "\n";
297 
298  str << type.alignment() << "\n";
299 
300  str << "\n"; // Leave a blank line where traits would be
301 
302  str << _("HP: ") << type.hitpoints() << "\n";
303 
304  str << _("XP: ") << type.experience_needed(true);
305 
306  label_details_->set_label(str.str());
308  }
309 
310  if(tree_details_) {
311 
312  tree_details_->clear();
313  tree_details_->add_node("hp_xp_mp", {
314  { "hp",{
315  { "label", (formatter() << "<small>" << "<span color='#21e100'>" << "<b>" << _("HP: ") << "</b>" << type.hitpoints() << "</span>" << " | </small>").str() },
316  { "use_markup", "true" },
317  { "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); }) }
318  } },
319  { "xp",{
320  { "label", (formatter() << "<small>" << "<span color='#00a0e1'>" << "<b>" << _("XP: ") << "</b>" << type.experience_needed() << "</span>" << " | </small>").str() },
321  { "use_markup", "true" },
322  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
323  } },
324  { "mp",{
325  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << type.movement() << "</small>").str() },
326  { "use_markup", "true" },
327  { "tooltip", get_mp_tooltip(type.movement(), [&type](t_translation::terrain_code terrain) { return type.movement_type().movement_cost(terrain); }) }
328  } },
329  });
330 
331  // Print trait details
332  {
333  tree_view_node* header_node = nullptr;
334 
335  for(const auto& tr : type.possible_traits()) {
336  t_string name = tr[type.genders().front() == unit_race::FEMALE ? "female_name" : "male_name"];
337  if(tr["availability"] != "musthave" || name.empty()) {
338  continue;
339  }
340 
341  if(header_node == nullptr) {
342  header_node = &add_name_tree_node(
344  "header",
345  "<b>" + _("Traits") + "</b>"
346  );
347  }
348 
350  *header_node,
351  "item",
352  name
353  );
354  }
355  }
356 
357  // Print ability details
358  if(!type.abilities_metadata().empty()) {
359 
360  auto& header_node = add_name_tree_node(
362  "header",
363  "<b>" + _("Abilities") + "</b>"
364  );
365 
366  for(const auto& ab : type.abilities_metadata()) {
367  if(!ab.name.empty()) {
369  header_node,
370  "item",
371  ab.name,
372  (formatter() << "<span size='x-large'>" << ab.name << "</span>\n" << ab.description).str()
373  );
374  }
375  }
376  }
377 
379  }
380 }
381 
383 {
384  // Sets the current type id for the profile button callback to use
385  current_type_ = u.type_id();
386 
387  if(icon_type_) {
388  std::string mods = u.image_mods();
389 
390  if(u.can_recruit()) {
391  mods += "~BLIT(" + unit::leader_crown() + ")";
392  }
393 
394  for(const std::string& overlay : u.overlays()) {
395  mods += "~BLIT(" + overlay + ")";
396  }
397 
398  mods += "~XBRZ(2)~SCALE_INTO_SHARP(144,144)" + image_mods_;
399 
400  icon_type_->set_label(u.absolute_image() + mods);
401  }
402 
403  if(label_name_) {
404  std::string name;
405  if(!u.name().empty()) {
406  name = "<span size='large'>" + u.name() + "</span>" + "\n" + "<small>" + font::span_color(font::unit_type_color) + u.type_name() + "</span></small>";
407  } else {
408  name = "<span size='large'>" + u.type_name() + "</span>\n";
409  }
410 
411  label_name_->set_label(name);
413  }
414 
415  if(label_level_) {
416  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
417 
418  label_level_->set_label("<b>" + l_str + "</b>");
420  }
421 
422  if(label_race_) {
423  label_race_->set_label(u.race()->name(u.gender()));
424  }
425 
426  if(icon_race_) {
427  icon_race_->set_label("icons/unit-groups/race_" + u.race()->id() + "_30.png");
428  }
429 
430  if(icon_alignment_) {
431  const std::string& alignment_name = u.alignment().to_string();
432 
433  icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
435  u.alignment(),
436  u.gender()));
437  }
438 
439  if(label_details_) {
440  std::stringstream str;
441 
442  const std::string name = "<span size='large'>" + (!u.name().empty() ? u.name() : " ") + "</span>";
443  str << name << "\n";
444 
445  str << font::span_color(font::unit_type_color) << u.type_name() << "</span>" << "\n";
446 
447  std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
448  str << l_str << "\n";
449 
450  str << unit_type::alignment_description(u.alignment(), u.gender()) << "\n";
451 
452  str << utils::join(u.trait_names(), ", ") << "\n";
453 
454  str << font::span_color(u.hp_color())
455  << _("HP: ") << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << "\n";
456 
457  str << font::span_color(u.xp_color())
458  << _("XP: ") << u.experience() << "/" << u.max_experience() << "</span>";
459 
460  label_details_->set_label(str.str());
462  }
463 
464  if(tree_details_) {
465  tree_details_->clear();
466  tree_details_->add_node("hp_xp_mp", {
467  { "hp",{
468  { "label", (formatter() << "<small>" << font::span_color(u.hp_color()) << "<b>" << _("HP: ") << "</b>" << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << " | </small>").str() },
469  { "use_markup", "true" },
470  { "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()); }) }
471  } },
472  { "xp",{
473  { "label", (formatter() << "<small>" << font::span_color(u.xp_color()) << "<b>" << _("XP: ") << "</b>" << u.experience() << "/" << u.max_experience() << "</span>" << " | </small>").str() },
474  { "use_markup", "true" },
475  { "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
476  } },
477  { "mp",{
478  { "label", (formatter() << "<small>" << "<b>" << _("MP: ") << "</b>" << u.movement_left() << "/" << u.total_movement() << "</small>").str() },
479  { "use_markup", "true" },
480  { "tooltip", get_mp_tooltip(u.total_movement(), [&u](t_translation::terrain_code terrain) { return u.movement_cost(terrain); }) }
481  } },
482  });
483 
484  if(!u.trait_names().empty()) {
485  auto& header_node = add_name_tree_node(
487  "header",
488  "<b>" + _("Traits") + "</b>"
489  );
490 
491  assert(u.trait_names().size() == u.trait_descriptions().size());
492  for (std::size_t i = 0; i < u.trait_names().size(); ++i) {
494  header_node,
495  "item",
496  u.trait_names()[i],
497  u.trait_descriptions()[i]
498  );
499  }
500  }
501 
502  if(!u.get_ability_list().empty()) {
503  auto& header_node = add_name_tree_node(
505  "header",
506  "<b>" + _("Abilities") + "</b>"
507  );
508 
509  for(const auto& ab : u.ability_tooltips()) {
511  header_node,
512  "item",
513  std::get<2>(ab),
514  std::get<3>(ab)
515  );
516  }
517  }
519  }
520 }
521 
523 {
524  if(get_window()) {
525  const unit_type* ut = unit_types.find(current_type_);
526  if(ut != nullptr) {
528  }
529  }
530 }
531 
532 void unit_preview_pane::set_image_mods(const std::string& mods)
533 {
534  image_mods_ = mods;
535 }
536 
537 void unit_preview_pane::set_active(const bool /*active*/)
538 {
539  /* DO NOTHING */
540 }
541 
543 {
544  return true;
545 }
546 
548 {
549  return ENABLED;
550 }
551 
552 void unit_preview_pane::set_self_active(const bool /*active*/)
553 {
554  /* DO NOTHING */
555 }
556 
557 // }---------- DEFINITION ---------{
558 
561 {
562  DBG_GUI_P << "Parsing unit preview pane " << id << '\n';
563 
564  load_resolutions<resolution>(cfg);
565 }
566 
568  : resolution_definition(cfg), grid()
569 {
570  state.emplace_back(cfg.child("background"));
571  state.emplace_back(cfg.child("foreground"));
572 
573  const config& child = cfg.child("grid");
574  VALIDATE(child, _("No grid defined."));
575 
576  grid = std::make_shared<builder_grid>(child);
577 }
578 
579 // }---------- BUILDER -----------{
580 
581 namespace implementation
582 {
583 
584 builder_unit_preview_pane::builder_unit_preview_pane(const config& cfg)
585  : builder_styled_widget(cfg)
586  , image_mods_(cfg["image_mods"])
587 {
588 }
589 
591 {
593 
594  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
595  << "' with definition '" << definition << "'.\n";
596 
597  const auto conf = widget->cast_config_to<unit_preview_pane_definition>();
598  assert(conf);
599 
600  widget->init_grid(conf->grid);
601  widget->finalize_setup();
602  widget->set_image_mods(image_mods_);
603 
604  return widget;
605 }
606 
607 } // namespace implementation
608 
609 // }------------ END --------------
610 
611 } // 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
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:45
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:1257
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
const std::string & id() const
Definition: race.hpp:34
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:381
logger & info()
Definition: log.cpp:90
#define a
int hitpoints() const
The current number of hitpoints this unit has.
Definition: unit.hpp:414
tree_view_node & get_root_node()
Definition: tree_view.hpp:52
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:49
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:2305
const std::string & type_id() const
The id of this unit&#39;s type.
Definition: unit.hpp:288
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:917
unit_type::ALIGNMENT alignment() const
The alignment of this unit.
Definition: unit.hpp:391
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:1094
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
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:1046
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.
This file contains the settings handling of the widget library.
const movetype & movement_type() const
Definition: types.hpp:174
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:164
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
Definition: unit.hpp:961
color_t xp_color() const
Color for this unit&#39;s XP.
Definition: unit.cpp:1104
const t_string & name() const
Gets this unit&#39;s translatable display name.
Definition: unit.hpp:328
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:438
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:945
const std::vector< ability_metadata > & abilities_metadata() const
Definition: types.hpp:209
int level() const
The current level of this unit.
Definition: unit.hpp:462
const std::string & id() const
The id for this unit_type.
Definition: types.hpp:139
virtual void set_use_markup(bool use_markup)
ter_data_cache load_terrain_types_data()
Load the appropriate terrain types data to use.
Definition: utils.cpp:99
const std::vector< std::string > & overlays() const
Get the unit&#39;s overlay images.
Definition: unit.hpp:1416
const t_string & type_name() const
Gets the translatable name of this unit&#39;s type.
Definition: unit.hpp:294
const std::string unicode_figure_dash
Definition: constants.cpp:40
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:46
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
static std::string get_side_color_id(unsigned side)
Definition: team.cpp:950
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
Definition: unit.hpp:951
const color_t weapon_details_color
std::size_t i
Definition: function.cpp:933
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:276
int max_hitpoints() const
The max number of hitpoints this unit can have.
Definition: unit.hpp:420
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:113
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:502
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:806
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:408
const std::string unicode_bullet
Definition: constants.cpp:42
#define VGETTEXT(msgid,...)
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:44
const t_string & tooltip() const
int experience() const
The current number of experience points this unit has.
Definition: unit.hpp:432
utils::string_map damage_table() const
Returns a map from attack types to resistances.
Definition: movetype.cpp:625
const map_location & get_location() const
The current map location this unit is at.
Definition: unit.hpp:1174
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
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)
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1090
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:160
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
Definition: abilities.cpp:232
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:1604
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
static std::string alignment_description(ALIGNMENT align, unit_race::GENDER gender=unit_race::MALE)
#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:1100
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
Definition: unit.cpp:2488
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:62
virtual bool get_active() const override
See styled_widget::get_active.
std::shared_ptr< terrain_type_data > ter_data_cache