tunit_attack: major progress on GUI2 attack dialog

This commit is contained in:
Charles Dang 2016-01-11 00:19:40 +11:00
parent f716d6e99d
commit 2c487ffd48
3 changed files with 315 additions and 46 deletions

View file

@ -9,8 +9,12 @@
linked_group = "unit"
[row]
grow_factor = 1
[column]
horizontal_alignment = "center"
vertical_alignment = "center"
border = "all"
border_size = 5
@ -22,15 +26,66 @@
[column]
grow_factor = 1
horizontal_grow = "true"
horizontal_alignment = "right"
border = "all"
border_size = 5
[grid]
[label]
id = "attacker_name"
definition = "alignment"
[/label]
[row]
grow_factor = 1
[column]
horizontal_alignment = "right"
border = "all"
border_size = 5
[label]
id = "attacker_stats"
definition = "alignment"
text_alignment = "right"
[/label]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "right"
vertical_alignment = "top"
border = "all"
border_size = 5
[image]
id = "a_alignment"
[/image]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "center"
vertical_alignment = "bottom"
border = "all"
border_size = 5
[button]
id = "attacker_profile"
definition = "default"
label = _ "Profile"
[/button]
[/column]
[/row]
[/grid]
[/column]
@ -45,24 +100,77 @@
linked_group = "unit"
[row]
grow_factor = 1
[column]
grow_factor = 1
horizontal_grow = "true"
horizontal_alignment = "left"
border = "all"
border_size = 5
[grid]
[label]
id = "defender_name"
definition = "alignment"
[row]
grow_factor = 1
text_alignment = "right"
[/label]
[column]
horizontal_alignment = "left"
border = "all"
border_size = 5
[label]
id = "defender_stats"
definition = "alignment"
text_alignment = "left"
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
horizontal_alignment = "left"
vertical_alignment = "top"
border = "all"
border_size = 5
[image]
id = "d_alignment"
[/image]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "center"
vertical_alignment = "bottom"
border = "all"
border_size = 5
[button]
id = "defender_profile"
definition = "default"
label = _ "Profile"
[/button]
[/column]
[/row]
[/grid]
[/column]
[column]
horizontal_alignment = "center"
vertical_alignment = "center"
border = "all"
border_size = 5
@ -83,10 +191,12 @@
[row]
[column]
horizontal_grow = "true"
{_GUI_BIG_ATTACKER_PANEL}
[/column]
[column]
horizontal_grow = "true"
{_GUI_BIG_DEFENDER_PANEL}
[/column]
@ -124,9 +234,10 @@
[grid]
[row]
grow_factor = 1
[column]
grow_factor = 1
grow_factor = 0
horizontal_alignment = "left"
border = "all"
@ -141,8 +252,8 @@
[column]
grow_factor = 1
horizontal_grow = "true"
vertical_alignment = "top"
horizontal_alignment = "left"
vertical_alignment = "center"
border = "all"
border_size = 5
@ -165,14 +276,17 @@
[label]
id = "range"
definition = "alignment"
text_alignment = "center"
[/label]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
vertical_alignment = "top"
horizontal_alignment = "right"
vertical_alignment = "center"
border = "all"
border_size = 5
@ -182,14 +296,14 @@
definition = "alignment"
linked_group = "weapon"
text_alignment = "left"
text_alignment = "right"
[/label]
[/column]
[column]
grow_factor = 1
horizontal_alignment = right
grow_factor = 0
horizontal_alignment = "right"
border = "all"
border_size = 5
@ -234,24 +348,58 @@
horizontal_alignment = "right"
[button]
id = "ok"
id = "damage_calculation"
definition = "default"
label = _ "Attack"
label = _ "Damage Calculation"
[/button]
[/column]
[/row]
[row]
[column]
border = "all"
border_size = 5
grow_factor = 1
horizontal_alignment = "right"
[button]
id = "cancel"
definition = "default"
[grid]
label = _ "Cancel"
[/button]
[row]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "ok"
definition = "default"
label = _ "Attack"
[/button]
[/column]
[column]
border = "all"
border_size = 5
[button]
id = "cancel"
definition = "default"
label = _ "Cancel"
[/button]
[/column]
[/row]
[/grid]
[/column]
@ -277,6 +425,11 @@
fixed_width = "true"
[/linked_group]
[linked_group]
id = "unit_image"
fixed_height = "true"
[/linked_group]
# All weapons share the same size, regardless whether attacker or
# defender.
[linked_group]
@ -305,7 +458,7 @@
[label]
definition = "title"
label = _ "Attack enemy"
label = _ "Attack Enemy"
[/label]
[/column]
@ -321,6 +474,23 @@
[/row]
[row]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
label = _ "Choose weapon:"
[/label]
[/column]
[/row]
[row]
[column]

View file

@ -17,6 +17,8 @@
#include "gui/dialogs/unit_attack.hpp"
#include "gui/auxiliary/find_widget.tpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/image.hpp"
#ifdef GUI2_EXPERIMENTAL_LISTBOX
#include "gui/widgets/list.hpp"
@ -25,15 +27,22 @@
#endif
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "display.hpp"
#include "game_config.hpp"
#include "gettext.hpp"
#include "help/help.hpp"
#include "language.hpp"
#include "marked-up_text.hpp"
#include "play_controller.hpp"
#include "resources.hpp"
#include "team.hpp"
#include "unit.hpp"
#include "unit_types.hpp"
#include "utils/foreach.tpp"
#include <boost/bind.hpp>
namespace gui2
{
@ -69,12 +78,14 @@ REGISTER_DIALOG(unit_attack)
tunit_attack::tunit_attack(const unit_map::iterator& attacker_itor,
const unit_map::iterator& defender_itor,
const std::vector<battle_context>& weapons,
const int best_weapon)
const int best_weapon,
display* disp)
: selected_weapon_(-1)
, attacker_itor_(attacker_itor)
, defender_itor_(defender_itor)
, weapons_(weapons)
, best_weapon_(best_weapon)
, disp_(disp)
{
}
@ -88,7 +99,44 @@ set_label(twindow& window, const std::string& id, const std::string& label)
}
}
static void set_attacker_info(twindow& w, unit& u)
static std::string format_stats(unit& u)
{
const std::string& name = "<span size='large'>" + (!u.name().empty() ? u.name() : " ") + "</span>";
const std::string& traits = !u.get_traits_list().empty() ? u.get_traits_list().front() : " ";
std::stringstream str;
str << name << "\n";
str << "<small>";
str << "<span color='#f5e6c1'>" << u.type_name() << "</span>" << "\n";
str << "Lvl " << u.level() << "\n";
str << traits << "\n";
str << font::span_color(u.hp_color()) << _("HP: ") << u.hitpoints() << "</span>" << "\n";
str << font::span_color(u.xp_color()) << _("XP: ") << u.experience() << "</span>" << "\n";
str << "</small>" << "\n";
return str.str();
}
static void set_alignment_icon(twindow& window, const std::string& widget_id, unit& u)
{
const std::string& alignment_name = unit_type::alignment_description(
u.alignment(),
u.gender());
timage& a_icon = find_widget<timage>(&window, widget_id, false);
a_icon.set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
a_icon.set_tooltip(alignment_name);
}
static void set_attacker_info(twindow& window, unit& u)
{
std::string tc;
@ -98,21 +146,36 @@ static void set_attacker_info(twindow& w, unit& u)
+ ")";
}
set_label<timage>(w, "attacker_portrait", u.absolute_image() + tc);
set_label<timage>(w, "attacker_icon", u.absolute_image() + tc);
set_label<tcontrol>(w, "attacker_name", u.name());
set_label<timage>(window, "attacker_portrait", u.absolute_image() + tc);
set_label<timage>(window, "attacker_icon", u.absolute_image() + tc);
tcontrol& attacker_name =
find_widget<tcontrol>(&window, "attacker_stats", false);
attacker_name.set_use_markup(true);
attacker_name.set_label(format_stats(u));
set_alignment_icon(window, "a_alignment", u);
}
static void set_defender_info(twindow& w, unit& u)
static void set_defender_info(twindow& window, unit& u)
{
const std::string&
tc = "~RC(" + u.team_color() + ">" +
team::get_side_color_index(u.side())
+ ")";
set_label<timage>(w, "defender_portrait", u.absolute_image() + tc);
set_label<timage>(w, "defender_icon", u.absolute_image() + tc);
set_label<tcontrol>(w, "defender_name", u.name());
// Ensure the defender image is always facing left
set_label<timage>(window, "defender_portrait", u.absolute_image() + tc + "~FL(horiz)");
set_label<timage>(window, "defender_icon", u.absolute_image() + tc + "~FL(horiz)");
tcontrol& defender_name =
find_widget<tcontrol>(&window, "defender_stats", false);
defender_name.set_use_markup(true);
defender_name.set_label(format_stats(u));
set_alignment_icon(window, "d_alignment", u);
}
static void set_weapon_info(twindow& window,
@ -149,16 +212,21 @@ static void set_weapon_info(twindow& window,
range = string_table["range_" + range];
}
const std::string& attw_apecials =
!attacker_weapon.weapon_specials().empty() ? " " + attacker_weapon.weapon_specials() : "";
const std::string& defw_specials =
!defender_weapon.weapon_specials().empty() ? " " + defender_weapon.weapon_specials() : "";
std::stringstream attacker_stats, defender_stats;
attacker_stats << "<b>" << attw_name << "</b>" << "\n"
<< attacker_weapon.damage() << font::weapon_numbers_sep << attacker_weapon.num_attacks()
<< " " << attacker_weapon.weapon_specials() << "\n"
<< attw_apecials << "\n"
<< font::span_color(a_cth_color) << attacker.chance_to_hit << "%</span>" << "\n";
defender_stats << "<b>" << defw_name << "</b>" << "\n"
<< defender_weapon.damage() << font::weapon_numbers_sep << defender_weapon.num_attacks()
<< " " << defender_weapon.weapon_specials() << "\n"
<< defw_specials << "\n"
<< font::span_color(d_cth_color) << defender.chance_to_hit << "%</span>" << "\n";
std::map<std::string, string_map> data;
@ -171,7 +239,6 @@ static void set_weapon_info(twindow& window,
item["use_markup"] = "true";
data.insert(std::make_pair("attacker_weapon", item));
//item["label"] = << utils::unicode_em_dash + " " << range << " " + utils::unicode_em_dash;
item["label"] = "<span color='#a69275'>" + utils::unicode_em_dash + " " + range + " " + utils::unicode_em_dash + "</span>";
item["use_markup"] = "true";
data.insert(std::make_pair("range", item));
@ -190,8 +257,34 @@ static void set_weapon_info(twindow& window,
weapon_list.select_row(best_weapon);
}
void tunit_attack::profile_button_callback(const std::string& type)
{
if (!disp_) {
return;
}
help::show_unit_help(*disp_, type);
}
void tunit_attack::pre_show(CVideo& /*video*/, twindow& window)
{
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "attacker_profile", false),
boost::bind(&profile_button_callback, this, (*attacker_itor_).type_id()));
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "defender_profile", false),
boost::bind(&profile_button_callback, this, (*defender_itor_).type_id()));
// TODO: implement
find_widget<tbutton>(&window, "damage_calculation", false).set_active(false);
/**connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "damage_calculation", false),
boost::bind(&tunit_attack::damage_calc_callback,
this,
boost::ref(window)));**/
set_attacker_info(window, *attacker_itor_);
set_defender_info(window, *defender_itor_);

View file

@ -17,6 +17,7 @@
#include "actions/attack.hpp"
#include "gui/dialogs/dialog.hpp"
#include "display.hpp"
#include "unit_map.hpp"
namespace gui2
@ -28,7 +29,8 @@ public:
tunit_attack(const unit_map::iterator& attacker_itor,
const unit_map::iterator& defender_itor,
const std::vector<battle_context>& weapons,
const int best_weapon);
const int best_weapon,
display* disp = NULL);
/***** ***** ***** setters / getters for members ***** ****** *****/
@ -47,6 +49,8 @@ private:
/** Inherited from tdialog. */
void post_show(twindow& window);
void profile_button_callback(const std::string& type);
/** The index of the selected weapon. */
int selected_weapon_;
@ -61,6 +65,8 @@ private:
/** The best weapon, aka the one high-lighted. */
int best_weapon_;
display* disp_;
};
} // namespace gui2