Skip to content

Commit

Permalink
show trait and ability tooltips in recall dialog
Browse files Browse the repository at this point in the history
This still needs to be done for the recruit dialog, doing that might also
reduce code duplication.

This also contains multiple other fixes to treeviews.
  • Loading branch information
gfgtdf committed Aug 13, 2016
1 parent 2ea30d5 commit 6f179bf
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 21 deletions.
76 changes: 68 additions & 8 deletions data/gui/widget/unit_preview_pane.cfg
Expand Up @@ -118,16 +118,76 @@
horizontal_grow = "true"
border = "top"
border_size = 5

{GUI_FORCE_WIDGET_MINIMUM_SIZE 225 300 (
[scroll_label]
id = "type_details"
definition = "default_small"
vertical_scrollbar_mode = "auto"
wrap = "true"
[/scroll_label]
[grid]
[row]
grow_factor = 0
[column]
horizontal_alignment = "left"
vertical_alignment = "top"
[scroll_label]
id = "type_details"
definition = "default_small"
wrap = "true"
vertical_scrollbar_mode = "never"
[/scroll_label]
[/column]
[/row]
[row]
grow_factor = 1
vertical_grow = "true"
horizontal_grow = "true"
[column]
vertical_grow = "true"
horizontal_grow = "true"
[tree_view]
id = "tree_details"
indention_step_size = 8
[node]
id = "header"
unfolded = true
[node_definition]
[row]
[column]
[spacer]
height = 9
[/spacer]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "left"
vertical_alignment = "top"
[label]
definition = "default_small"
id = "name"
[/label]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "item"
unfolded = true
[node_definition]
[row]
[column]
horizontal_alignment = "left"
vertical_alignment = "top"
[label]
wrap = "true"
definition = "default_small"
id = "name"
[/label]
[/column]
[/row]
[/node_definition]
[/node]
[/tree_view]
[/column]
[/row]
[/grid]
)}

[/column]

[/row]
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/scrollbar_container.cpp
Expand Up @@ -711,7 +711,7 @@ bool tscrollbar_container::content_resize_height(const int height_modification,
DBG_GUI_L << LOG_HEADER << " current height " << content_grid_->get_height()
<< " wanted height " << new_height;

assert(new_height > 0);
assert(new_height >= 0);

if(static_cast<unsigned>(new_height) <= content_->get_height()) {
DBG_GUI_L << " height in container, resize allowed.\n";
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/tree_view.cpp
Expand Up @@ -90,7 +90,7 @@ void ttree_view::remove_node(ttree_view_node* node)

void ttree_view::clear()
{
get_root_node().children_.clear();
get_root_node().clear();
}

void
Expand Down
16 changes: 8 additions & 8 deletions src/gui/widgets/tree_view_node.cpp
Expand Up @@ -62,7 +62,9 @@ ttree_view_node::ttree_view_node(

twidget* toggle_widget = grid_.find("tree_view_node_icon", false);
toggle_ = dynamic_cast<tselectable_*>(toggle_widget);

if(node_definition.unfolded) {
unfolded_ = true;
}
if(toggle_) {
toggle_widget->set_visible(twidget::tvisible::hidden);
toggle_widget->connect_signal<event::LEFT_BUTTON_CLICK>(std::bind(
Expand All @@ -73,10 +75,8 @@ ttree_view_node::ttree_view_node(
&ttree_view_node::signal_handler_left_button_click,
this,
_2), event::tdispatcher::back_post_child);

if(node_definition.unfolded) {
if(unfolded_) {
toggle_->set_value(1);
unfolded_ = true;
}
}

Expand Down Expand Up @@ -150,7 +150,7 @@ ttree_view_node& ttree_view_node::add_child(
new ttree_view_node(
id, node_definitions_, this, tree_view(), data));

if(is_folded() || is_root_node()) {
if(is_folded() /*|| is_root_node()*/) {
return *itor;
}

Expand All @@ -169,7 +169,7 @@ ttree_view_node& ttree_view_node::add_child(

// Calculate height modification.
const int height_modification = best_size.y;
assert(height_modification > 0);
assert(height_modification >= 0);

// Request new size.
tree_view().resize_content(width_modification, height_modification, -1, itor->calculate_ypos());
Expand Down Expand Up @@ -224,7 +224,7 @@ bool ttree_view_node::is_folded() const

void ttree_view_node::fold(/*const bool recursive*/)
{
if(is_folded()) {
if(!is_folded()) {
fold_internal();
if(toggle_) {
toggle_->set_value(false);
Expand All @@ -234,7 +234,7 @@ void ttree_view_node::fold(/*const bool recursive*/)

void ttree_view_node::unfold(/*const texpand_mode mode*/)
{
if(!is_folded()) {
if(is_folded()) {
unfold_internal();
if(toggle_) {
toggle_->set_value(true);
Expand Down
115 changes: 112 additions & 3 deletions src/gui/widgets/unit_preview_pane.cpp
Expand Up @@ -23,6 +23,8 @@
#include "gui/widgets/label.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/tree_view.hpp"
#include "gui/widgets/tree_view_node.hpp"

#include "formula/string_utils.hpp"
#include "gettext.hpp"
Expand All @@ -34,6 +36,8 @@
#include "units/attack_type.hpp"
#include "units/types.hpp"
#include "units/unit.hpp"
#include "formatter.hpp"
#include "marked-up_text.hpp"

#include "utils/functional.hpp"

Expand All @@ -57,6 +61,8 @@ void tunit_preview_pane::finalize_setup()
label_details_ = find_widget<tcontrol>(this, "type_details", false, false);
label_details_minimal_ = find_widget<tcontrol>(this, "type_details_minimal", false, false);

tree_details_ = find_widget<ttree_view>(this, "tree_details", false, false);

// Profile button
button_profile_ = find_widget<tbutton>(this, "type_profile", false, false);

Expand Down Expand Up @@ -140,8 +146,7 @@ void tunit_preview_pane::set_displayed_type(const unit_type& type)
type.alignment(),
type.genders().front()));
}

if(label_details_) {
else if(label_details_) {
std::stringstream str;
str << "<small>";

Expand Down Expand Up @@ -202,6 +207,17 @@ void tunit_preview_pane::set_displayed_type(const unit_type& type)
}
}

static inline ttree_view_node& add_name_tree_node(ttree_view_node& header_node, const std::string& type, const t_string& label, const t_string& tooltip = "")
{
//Note: we have to pass data instead of just doing 'child_label.set_label(label)' below
// because the ttree_view_node::add_child need to have teh correct size of the
// node child widgets for its internal size calculations.
auto& child_node = header_node.add_child(type, { {"name", { {"label", label } } } });
auto& child_label = find_widget<tcontrol>(&child_node, "name", true);
child_label.set_tooltip(tooltip);
child_label.set_use_markup(true);
return child_node;
}
void tunit_preview_pane::set_displayed_unit(const unit& u)
{
// Sets the current type id for the profile button callback to use
Expand Down Expand Up @@ -283,7 +299,100 @@ void tunit_preview_pane::set_displayed_unit(const unit& u)
label_details_minimal_->set_use_markup(true);
}

if(label_details_) {
if (tree_details_) {

std::stringstream str;
str << "<small>";

str << font::span_color(u.hp_color())
<< "<b>" << _("HP: ") << "</b>" << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << " | ";

str << font::span_color(u.xp_color())
<< "<b>" << _("XP: ") << "</b>" << u.experience() << "/" << u.max_experience() << "</span>" << " | ";

str << "<b>" << _("MP: ") << "</b>"
<< u.movement_left() << "/" << u.total_movement();

str << "</small>";

tree_details_->clear();

add_name_tree_node(
tree_details_->get_root_node(),
"item",
str.str()
);

if (!u.trait_names().empty()) {
auto& header_node = add_name_tree_node(
tree_details_->get_root_node(),
"header",
"<b>" + _("Traits") + "</b>"
);

assert(u.trait_names().size() == u.trait_descriptions().size());
for (size_t i = 0; i < u.trait_names().size(); ++i) {
add_name_tree_node(
header_node,
"item",
u.trait_names()[i],
u.trait_descriptions()[i]
);
}
}
if (!u.get_ability_list().empty()) {
auto& header_node = add_name_tree_node(
tree_details_->get_root_node(),
"header",
"<b>" + _("Abilities") + "</b>"
);

for (const auto& ab : u.ability_tooltips()) {
add_name_tree_node(
header_node,
"item",
std::get<1>(ab),
std::get<2>(ab)
);
}
}

if (!u.attacks().empty()) {

auto& header_node = add_name_tree_node(
tree_details_->get_root_node(),
"header",
"<b>" + _("Attacks") + "</b>"
);

for (const auto& a : u.attacks()) {

auto& subsection = add_name_tree_node(
header_node,
"item",
(formatter() << "<span color='#f5e6c1'>" << a.damage() << font::weapon_numbers_sep << a.num_attacks() << " " << a.name() << "</span>").str()
);

add_name_tree_node(
subsection,
"item",
(formatter() << "<span color='#a69275'>" << a.range() << font::weapon_details_sep << a.type() << "</span>").str()
);

for (const auto& pair : a.special_tooltips())
{
add_name_tree_node(
subsection,
"item",
(formatter() << font::span_color(font::weapon_details_color) << pair.first << "</span>").str(),
(formatter() << _("Weapon special: ") << "<b>" << pair.first << "</b>" << '\n' << pair.second).str()
);
}
}

}
}
else if(label_details_) {
std::stringstream str;
str << "<small>";

Expand Down
3 changes: 3 additions & 0 deletions src/gui/widgets/unit_preview_pane.hpp
Expand Up @@ -30,6 +30,7 @@ namespace gui2
class tbutton;
class timage;
class tlabel;
class ttree_view;

namespace implementation
{
Expand All @@ -50,6 +51,7 @@ class tunit_preview_pane : public tcontainer_
, label_name_(nullptr)
, label_level_(nullptr)
, label_details_(nullptr)
, tree_details_(nullptr)
, label_details_minimal_(nullptr)
, button_profile_(nullptr)
, image_mods_()
Expand Down Expand Up @@ -97,6 +99,7 @@ class tunit_preview_pane : public tcontainer_

tcontrol* label_details_;
tcontrol* label_details_minimal_;
ttree_view* tree_details_;

tbutton* button_profile_;

Expand Down

0 comments on commit 6f179bf

Please sign in to comment.