16 #define GETTEXT_DOMAIN "wesnoth-lib" 48 const
int best_weapon)
50 , selected_weapon_(-1)
51 , attacker_itor_(attacker_itor)
52 , defender_itor_(defender_itor)
53 , weapons_(
std::move(weapons))
54 , best_weapon_(best_weapon)
60 const std::size_t
index = find_widget<listbox>(
get_window(),
"weapon_list",
false).get_selected_row();
67 find_widget<button>(&window,
"damage_calculation",
false),
70 find_widget<unit_preview_pane>(&
window,
"attacker_pane",
false)
73 find_widget<unit_preview_pane>(&
window,
"defender_pane",
false)
78 listbox& weapon_list = find_widget<listbox>(&
window,
"weapon_list",
false);
79 window.keyboard_capture(&weapon_list);
85 for(
const auto & weapon :
weapons_) {
92 *defender.
weapon : *no_weapon;
97 const std::string attw_name = !attacker_weapon.
name().
empty() ? attacker_weapon.
name() :
" ";
98 const std::string defw_name = !defender_weapon.
name().
empty() ? defender_weapon.
name() :
" ";
100 std::string range = attacker_weapon.
range().empty() ? defender_weapon.
range() : attacker_weapon.
range();
101 if (!range.empty()) {
119 const std::set<std::string> checking_tags_other = {
"disable",
"berserk",
"drains",
"heal_on_hit",
"plague",
"slow",
"petrifies",
"firststrike",
"poison"};
126 std::string defw_specials = defender_attack ? defender_weapon.
weapon_specials() :
"";
127 std::string defw_specials_dmg = defender_attack ? defender_weapon.
weapon_specials_value({
"leadership",
"damage"}) :
"";
128 std::string defw_specials_atk = defender_attack ? defender_weapon.
weapon_specials_value({
"attacks",
"swarm"}) :
"";
129 std::string defw_specials_cth = defender_attack ? defender_weapon.
weapon_specials_value({
"chance_to_hit"}) :
"";
130 std::string defw_specials_others = defender_attack ? defender_weapon.
weapon_specials_value(checking_tags_other) :
"";
132 if(!attw_specials.empty()) {
133 attw_specials =
" " + attw_specials;
135 if(!attw_specials_dmg.empty()) {
136 attw_specials_dmg =
" " + attw_specials_dmg;
138 if(!attw_specials_atk.empty()) {
139 attw_specials_atk =
" " + attw_specials_atk;
141 if(!attw_specials_cth.empty()) {
142 attw_specials_cth =
" " + attw_specials_cth;
144 if(!attw_specials_others.empty()) {
145 attw_specials_others =
"\n" + (
"<b>"+
translation::dsgettext(
"wesnoth",
"Other aspects: ")+
"</b>") +
"\n" + (
"<i>"+attw_specials_others+
"</i>");
147 if(!defw_specials.empty()) {
148 defw_specials =
" " + defw_specials;
150 if(!defw_specials_dmg.empty()) {
151 defw_specials_dmg =
" " + defw_specials_dmg;
153 if(!defw_specials_atk.empty()) {
154 defw_specials_atk =
" " + defw_specials_atk;
156 if(!defw_specials_cth.empty()) {
157 defw_specials_cth =
" " + defw_specials_cth;
159 if(!defw_specials_others.empty()) {
160 defw_specials_others =
"\n" + (
"<b>"+
translation::dsgettext(
"wesnoth",
"Other aspects: ")+
"</b>") +
"\n" + (
"<i>"+defw_specials_others+
"</i>");
163 std::stringstream attacker_stats, defender_stats, attacker_tooltip, defender_tooltip;
166 attacker_stats <<
"<b>" << attw_name <<
"</b>" <<
"\n" 168 << attw_specials <<
"\n" 175 << attw_specials_others;
177 defender_stats <<
"<b>" << defw_name <<
"</b>" <<
"\n" 179 << defw_specials <<
"\n" 186 << defw_specials_others;
191 item[
"use_markup"] =
"true";
193 item[
"label"] = attacker_weapon.
icon();
194 data.emplace(
"attacker_weapon_icon", item);
196 item[
"tooltip"] = attacker_tooltip.str();
197 item[
"label"] = attacker_stats.str();
198 data.emplace(
"attacker_weapon", item);
199 item[
"tooltip"] =
"";
202 data.emplace(
"range", item);
204 item[
"tooltip"] = defender_attack ? defender_tooltip.str() :
"";
205 item[
"label"] = defender_stats.str();
206 data.emplace(
"defender_weapon", item);
208 item[
"tooltip"] =
"";
209 item[
"label"] = defender_weapon.
icon();
210 data.emplace(
"defender_weapon_icon", item);
const_attack_ptr weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
window(const builder_window::window_resolution &definition)
< Needs to be initialized in show.
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
std::string weapon_specials_value(const std::set< std::string > checking_tags) const
int best_weapon_
The best weapon, aka the one high-lighted.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
std::string dsgettext(const char *domainname, const char *msgid)
bool select_row(const unsigned row, const bool select=true)
Selects a row.
std::vector< battle_context > weapons_
List of all battle contexts used for getting the weapons.
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
int damage
Effective damage of the weapon (all factors accounted for).
std::map< std::string, t_string > widget_item
std::string weapon_specials() const
Returns a comma-separated string of active names for the specials of *this.
void damage_calc_callback()
This file contains the settings handling of the widget library.
const t_string & name() const
The basic class for representing 8-bit RGB or RGBA colour values.
Computes the statistics of a battle between an attacker and a defender unit.
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
const std::string & range() const
unsigned get_item_count() const
Returns the number of items in the listbox.
void unit_attack(display *disp, game_board &board, const map_location &a, const map_location &b, int damage, const attack_type &attack, const_attack_ptr secondary_attack, int swing, const std::string &hit_text, int drain_amount, const std::string &att_text, const std::vector< std::string > *extra_hit_sounds, bool attacking)
Make the unit on tile 'a' attack the unit on tile 'b'.
const std::string & icon() const
Structure describing the statistics of a unit involved in the battle.
window * get_window()
Returns a pointer to the dialog's window.
pointer get_shared_ptr() const
This is exactly the same as operator-> but it's slightly more readable, and can replace &*iter syntax...
int selected_weapon_
The index of the selected weapon.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
int get_retval() const
Returns the cached window exit code.
const std::string weapon_numbers_sep
This shows the dialog for attacking units.
symbol_table string_table
const std::string unicode_em_dash
unit_map::iterator attacker_itor_
Iterator pointing to the attacker.
Abstract base class for all modal dialogs.
Container associating units to locations.
color_t red_to_green(double val, bool for_text)
Return a color corresponding to the value val red for val=0.0 to green for val=100.0, passing by yellow.
unsigned int num_blows
Effective number of blows, takes swarm into account.
std::map< std::string, widget_item > widget_data
specials_context_t specials_context(unit_const_ptr self, unit_const_ptr other, const map_location &unit_loc, const map_location &other_loc, bool attacking, const_attack_ptr other_attack) const
Dialog was closed with the OK button.
A config object defines a single node in a WML file, with access to child nodes.
std::shared_ptr< const attack_type > const_attack_ptr
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
base class of top level items, the only item which needs to store the final canvases to draw on...
std::string::const_iterator iterator
std::pair< std::string, unsigned > item
unit_map::iterator defender_itor_
Iterator pointing to the defender.