Skip to content

Commit

Permalink
Made Attack dialog use a unit_preview_pane widget
Browse files Browse the repository at this point in the history
This also adds the necessary changes to said widget to allow single-unit stats display.
It still needs to be expanded somewhat. Right now it contains the minimum required for
the attack dialog.
  • Loading branch information
Vultraz committed Jul 31, 2016
1 parent 4889fd7 commit 639548a
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 105 deletions.
5 changes: 5 additions & 0 deletions data/gui/schema.cfg
Expand Up @@ -1930,6 +1930,11 @@
max="1"
super="gui/window/resolution/grid"
[/tag]
[key]
name="image_facing"
type="string"
default="right"
[/key]
[/tag]
[tag]
name="vertical_scrollbar"
Expand Down
160 changes: 160 additions & 0 deletions data/gui/widget/unit_preview_pane.cfg
Expand Up @@ -254,6 +254,150 @@
[/grid]
#enddef

#define _GUI_UNIT_PREVIEW_PANE_UNIT_MINIMAL_LEFT
[grid]

[row]
grow_factor = 1

[column]
horizontal_alignment = "center"
vertical_alignment = "center"

border = "all"
border_size = 5

[image]
id = "type_image"
[/image]

[/column]

[column]
grow_factor = 1
horizontal_alignment = "right"

[grid]

[row]
grow_factor = 1

[column]
horizontal_alignment = "right"

border = "all"
border_size = 5

[label]
id = "type_details"
definition = "default"

text_alignment = "right"
[/label]

[/column]

[/row]

[row]

[column]
horizontal_alignment = "right"
border = "all"
border_size = 5

[button]
id = "type_profile"
definition = "default"

label = _ "Profile"
[/button]

[/column]

[/row]

[/grid]

[/column]

[/row]

[/grid]
#enddef

#define _GUI_UNIT_PREVIEW_PANE_UNIT_MINIMAL_RIGHT
[grid]

[row]
grow_factor = 1

[column]
grow_factor = 1
horizontal_alignment = "left"

[grid]

[row]
grow_factor = 1

[column]
horizontal_alignment = "left"

border = "all"
border_size = 5

[label]
id = "type_details"
definition = "default"

text_alignment = "left"
[/label]

[/column]

[/row]

[row]
grow_factor = 1

[column]
horizontal_alignment = "left"
border = "all"
border_size = 5

[button]
id = "type_profile"
definition = "default"

label = _ "Profile"
[/button]

[/column]

[/row]

[/grid]

[/column]

[column]
horizontal_alignment = "center"
vertical_alignment = "center"
border = "all"
border_size = 5

[image]
id = "type_image"
[/image]

[/column]

[/row]

[/grid]
#enddef

#define _GUI_RESOLUTION DEFINITION_GRID
[resolution]

Expand Down Expand Up @@ -301,6 +445,22 @@
{_GUI_RESOLUTION ({_GUI_UNIT_PREVIEW_PANE_MINIMAL})}
[/unit_preview_pane_definition]

[unit_preview_pane_definition]
id = "unit_minimal_left"
description = "A more text-based unit preview pane, used in the attack dialog with the sprite to the left."

{_GUI_RESOLUTION ({_GUI_UNIT_PREVIEW_PANE_UNIT_MINIMAL_LEFT})}
[/unit_preview_pane_definition]

[unit_preview_pane_definition]
id = "unit_minimal_right"
description = "A more text-based unit preview pane, used in the attack dialog with the sprite to the right."

{_GUI_RESOLUTION ({_GUI_UNIT_PREVIEW_PANE_UNIT_MINIMAL_RIGHT})}
[/unit_preview_pane_definition]

#undef _GUI_UNIT_PREVIEW_PANE_FULL
#undef _GUI_UNIT_PREVIEW_PANE_MINIMAL
#undef _GUI_UNIT_PREVIEW_PANE_UNIT_MINIMAL_LEFT
#undef _GUI_UNIT_PREVIEW_PANE_UNIT_MINIMAL_RIGHT
#undef _GUI_RESOLUTION
17 changes: 15 additions & 2 deletions data/gui/window/unit_attack.cfg
Expand Up @@ -159,15 +159,28 @@
[column]
grow_factor = 1
horizontal_grow = "true"
{_GUI_BIG_ATTACKER_PANEL}
border = "all"
border_size = 5

[unit_preview_pane]
id = "attacker_pane"
definition = "unit_minimal_left"
[/unit_preview_pane]
[/column]

{GUI_VERTICAL_SPACER_LINE}

[column]
grow_factor = 1
horizontal_grow = "true"
{_GUI_BIG_DEFENDER_PANEL}
border = "all"
border_size = 5

[unit_preview_pane]
id = "defender_pane"
definition = "unit_minimal_right"
image_facing = "left"
[/unit_preview_pane]
[/column]

[/row]
Expand Down
94 changes: 6 additions & 88 deletions src/gui/dialogs/unit_attack.cpp
Expand Up @@ -28,6 +28,7 @@
#include "gui/widgets/listbox.hpp"
#endif
#include "gui/widgets/settings.hpp"
#include "gui/widgets/unit_preview_pane.hpp"
#include "gui/widgets/window.hpp"
#include "game_config.hpp"
#include "gettext.hpp"
Expand Down Expand Up @@ -94,82 +95,6 @@ set_label(twindow& window, const std::string& id, const std::string& label)
}
}

static std::string format_stats(const unit& u)
{
const std::string name = "<span size='large'>" + (!u.name().empty() ? u.name() : " ") + "</span>";
std::string traits;

for(const std::string& trait : u.trait_names()) {
traits += (traits.empty() ? "" : ", ") + trait;
}

if (traits.empty()) {
traits = " ";
}

std::stringstream str;

str << name << "\n";

str << "<small>";

str << "<span color='#f5e6c1'>" << u.type_name() << "</span>" << "\n";

str << "Lvl " << u.level() << "\n";

str << u.alignment() << "\n";

str << traits << "\n";

str << font::span_color(u.hp_color())
<< _("HP: ") << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << "\n";
str << font::span_color(u.xp_color())
<< _("XP: ") << u.experience() << "/" << u.max_experience() << "</span>";

str << "</small>";

return str.str();
}

static std::string get_image_mods(const unit& u)
{
std::string res
= "~RC(" + u.team_color() + ">" + team::get_side_color_index(u.side()) + ")";

if (u.can_recruit()) {
res += "~BLIT(" + unit::leader_crown() + ")";
}

for(const std::string& overlay : u.overlays()) {
res += "~BLIT(" + overlay + ")";
}

return res;
}

static void set_attacker_info(twindow& window, const unit& u)
{
set_label<timage>(window, "attacker_image", u.absolute_image() + get_image_mods(u));

tcontrol& attacker_name =
find_widget<tcontrol>(&window, "attacker_stats", false);

attacker_name.set_use_markup(true);
attacker_name.set_label(format_stats(u));
}

static void set_defender_info(twindow& window, const unit& u)
{
// Ensure the defender image is always facing left
set_label<timage>(window, "defender_image", u.absolute_image() + "~FL(horiz)" + get_image_mods(u));

tcontrol& defender_name =
find_widget<tcontrol>(&window, "defender_stats", false);

defender_name.set_use_markup(true);
defender_name.set_label(format_stats(u));
}

static void set_weapon_info(twindow& window,
const std::vector<battle_context>& weapons,
const int best_weapon)
Expand Down Expand Up @@ -265,22 +190,15 @@ void tunit_attack::damage_calc_callback(twindow& window)

void tunit_attack::pre_show(twindow& window)
{
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "attacker_profile", false),
std::bind(&tunit_attack::profile_button_callback, this, std::ref(window),
(*attacker_itor_).type_id()));

connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "defender_profile", false),
std::bind(&tunit_attack::profile_button_callback, this, std::ref(window),
(*defender_itor_).type_id()));

connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "damage_calculation", false),
std::bind(&tunit_attack::damage_calc_callback, this, std::ref(window)));

set_attacker_info(window, *attacker_itor_);
set_defender_info(window, *defender_itor_);
find_widget<tunit_preview_pane>(&window, "attacker_pane", false)
.set_displayed_unit(&(*attacker_itor_));

find_widget<tunit_preview_pane>(&window, "defender_pane", false)
.set_displayed_unit(&(*defender_itor_));

selected_weapon_ = -1;
set_weapon_info(window, weapons_, best_weapon_);
Expand Down

0 comments on commit 639548a

Please sign in to comment.