GUI2: implemented a Unit Preview Pane widget
This commit is contained in:
parent
c7de7ce9d4
commit
29e19cd854
11 changed files with 702 additions and 0 deletions
175
data/gui/default/widget/unit_preview_pane.cfg
Normal file
175
data/gui/default/widget/unit_preview_pane.cfg
Normal file
|
@ -0,0 +1,175 @@
|
|||
#textdomain wesnoth-lib
|
||||
|
||||
#define _GUI_UNIT_PREVIEW_PANE_FULL
|
||||
[grid]
|
||||
vertical_grow = "true"
|
||||
horizontal_grow = "true"
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
[column]
|
||||
border = "bottom"
|
||||
border_size = 5
|
||||
vertical_grow = "true"
|
||||
horizontal_grow = "true"
|
||||
|
||||
[label]
|
||||
id = "type_name"
|
||||
wrap = "true"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
border = "bottom"
|
||||
border_size = 5
|
||||
horizontal_alignment = "center"
|
||||
vertical_alignment = "center"
|
||||
|
||||
[image]
|
||||
id = "type_image"
|
||||
definition = "default"
|
||||
[/image]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
border = "bottom"
|
||||
border_size = 5
|
||||
horizontal_alignment = "center"
|
||||
|
||||
[button]
|
||||
id = "type_profile"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Profile"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
border = "right,bottom"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
id = "type_level"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "right,bottom"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[image]
|
||||
id = "type_race"
|
||||
[/image]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "bottom"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[image]
|
||||
id = "type_alignment"
|
||||
[/image]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
vertical_grow = "true"
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
id = "type_details"
|
||||
definition = "default_small"
|
||||
wrap = "true"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
#enddef
|
||||
|
||||
#define _GUI_RESOLUTION DEFINITION_GRID
|
||||
[resolution]
|
||||
|
||||
min_width = 0
|
||||
min_height = 0
|
||||
|
||||
default_width = 0
|
||||
default_height = 0
|
||||
|
||||
max_width = 0
|
||||
max_height = 0
|
||||
|
||||
[background]
|
||||
|
||||
[draw]
|
||||
|
||||
[/draw]
|
||||
|
||||
[/background]
|
||||
|
||||
[foreground]
|
||||
|
||||
[draw]
|
||||
|
||||
[/draw]
|
||||
|
||||
[/foreground]
|
||||
|
||||
{DEFINITION_GRID}
|
||||
|
||||
[/resolution]
|
||||
#enddef
|
||||
|
||||
[unit_preview_pane_definition]
|
||||
id = "default"
|
||||
description = "A fully detailed preview area for unit stats."
|
||||
|
||||
{_GUI_RESOLUTION ({_GUI_UNIT_PREVIEW_PANE_FULL})}
|
||||
[/unit_preview_pane_definition]
|
||||
|
||||
#undef _GUI_UNIT_PREVIEW_PANE_FULL
|
||||
#undef _GUI_RESOLUTION
|
|
@ -533,6 +533,8 @@
|
|||
<Unit filename="../../src/gui/auxiliary/widget_definition/toggle_panel.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/widget_definition/tree_view.cpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/widget_definition/tree_view.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/widget_definition/unit_preview_pane.cpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/widget_definition/unit_preview_pane.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/widget_definition/vertical_scrollbar.cpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/widget_definition/vertical_scrollbar.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/widget_definition/window.cpp" />
|
||||
|
@ -595,6 +597,8 @@
|
|||
<Unit filename="../../src/gui/auxiliary/window_builder/toggle_panel.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/window_builder/tree_view.cpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/window_builder/tree_view.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/window_builder/unit_preview_pane.cpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/window_builder/unit_preview_pane.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/window_builder/vertical_scrollbar.cpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/window_builder/vertical_scrollbar.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/window_builder/viewport.cpp" />
|
||||
|
@ -819,6 +823,8 @@
|
|||
<Unit filename="../../src/gui/widgets/tree_view.hpp" />
|
||||
<Unit filename="../../src/gui/widgets/tree_view_node.cpp" />
|
||||
<Unit filename="../../src/gui/widgets/tree_view_node.hpp" />
|
||||
<Unit filename="../../src/gui/widgets/unit_preview_pane.cpp" />
|
||||
<Unit filename="../../src/gui/widgets/unit_preview_pane.hpp" />
|
||||
<Unit filename="../../src/gui/widgets/vertical_scrollbar.cpp" />
|
||||
<Unit filename="../../src/gui/widgets/vertical_scrollbar.hpp" />
|
||||
<Unit filename="../../src/gui/widgets/viewport.cpp" />
|
||||
|
|
|
@ -604,6 +604,7 @@ set(wesnoth-gui_widget_SRC
|
|||
gui/widgets/toggle_panel.cpp
|
||||
gui/widgets/tree_view.cpp
|
||||
gui/widgets/tree_view_node.cpp
|
||||
gui/widgets/unit_preview_pane.cpp
|
||||
gui/widgets/vertical_scrollbar.cpp
|
||||
gui/widgets/viewport.cpp
|
||||
gui/widgets/widget.cpp
|
||||
|
@ -637,6 +638,7 @@ set(wesnoth-gui_widget_SRC
|
|||
gui/auxiliary/window_builder/toggle_button.cpp
|
||||
gui/auxiliary/window_builder/toggle_panel.cpp
|
||||
gui/auxiliary/window_builder/tree_view.cpp
|
||||
gui/auxiliary/window_builder/unit_preview_pane.cpp
|
||||
gui/auxiliary/window_builder/vertical_scrollbar.cpp
|
||||
gui/auxiliary/window_builder/viewport.cpp
|
||||
)
|
||||
|
@ -685,6 +687,7 @@ set(wesnoth-gui_widget_definition_SRC
|
|||
gui/auxiliary/widget_definition/toggle_button.cpp
|
||||
gui/auxiliary/widget_definition/toggle_panel.cpp
|
||||
gui/auxiliary/widget_definition/tree_view.cpp
|
||||
gui/auxiliary/widget_definition/unit_preview_pane.cpp
|
||||
gui/auxiliary/widget_definition/vertical_scrollbar.cpp
|
||||
gui/auxiliary/widget_definition/window.cpp
|
||||
)
|
||||
|
|
|
@ -367,6 +367,7 @@ wesnoth_sources = Split("""
|
|||
gui/auxiliary/widget_definition/toggle_button.cpp
|
||||
gui/auxiliary/widget_definition/toggle_panel.cpp
|
||||
gui/auxiliary/widget_definition/tree_view.cpp
|
||||
gui/auxiliary/widget_definition/unit_preview_pane.cpp
|
||||
gui/auxiliary/widget_definition/vertical_scrollbar.cpp
|
||||
gui/auxiliary/widget_definition/window.cpp
|
||||
gui/auxiliary/window_builder.cpp
|
||||
|
@ -398,6 +399,7 @@ wesnoth_sources = Split("""
|
|||
gui/auxiliary/window_builder/toggle_button.cpp
|
||||
gui/auxiliary/window_builder/toggle_panel.cpp
|
||||
gui/auxiliary/window_builder/tree_view.cpp
|
||||
gui/auxiliary/window_builder/unit_preview_pane.cpp
|
||||
gui/auxiliary/window_builder/vertical_scrollbar.cpp
|
||||
gui/auxiliary/window_builder/viewport.cpp
|
||||
gui/dialogs/addon/description.cpp
|
||||
|
@ -504,6 +506,7 @@ wesnoth_sources = Split("""
|
|||
gui/widgets/toggle_panel.cpp
|
||||
gui/widgets/tree_view.cpp
|
||||
gui/widgets/tree_view_node.cpp
|
||||
gui/widgets/unit_preview_pane.cpp
|
||||
gui/widgets/vertical_scrollbar.cpp
|
||||
gui/widgets/viewport.cpp
|
||||
gui/widgets/widget.cpp
|
||||
|
|
45
src/gui/auxiliary/widget_definition/unit_preview_pane.cpp
Normal file
45
src/gui/auxiliary/widget_definition/unit_preview_pane.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
Copyright (C) 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/auxiliary/widget_definition/unit_preview_pane.hpp"
|
||||
|
||||
#include "gettext.hpp"
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tunit_preview_pane_definition::tunit_preview_pane_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
{
|
||||
DBG_GUI_P << "Parsing unit preview pane " << id << '\n';
|
||||
|
||||
load_resolutions<tresolution>(cfg);
|
||||
}
|
||||
|
||||
tunit_preview_pane_definition::tresolution::tresolution(const config& cfg)
|
||||
: tresolution_definition_(cfg), grid()
|
||||
{
|
||||
state.push_back(tstate_definition(cfg.child("background")));
|
||||
state.push_back(tstate_definition(cfg.child("foreground")));
|
||||
|
||||
const config& child = cfg.child("grid");
|
||||
VALIDATE(child, _("No grid defined."));
|
||||
|
||||
grid = new tbuilder_grid(child);
|
||||
}
|
||||
|
||||
}
|
38
src/gui/auxiliary/widget_definition/unit_preview_pane.hpp
Normal file
38
src/gui/auxiliary/widget_definition/unit_preview_pane.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
Copyright (C) 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GUI_AUXILIARY_WIDGET_DEFINITION_UNIT_PREVIEW_PANE_HPP_INCLUDED
|
||||
#define GUI_AUXILIARY_WIDGET_DEFINITION_UNIT_PREVIEW_PANE_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tunit_preview_pane_definition : public tcontrol_definition
|
||||
{
|
||||
|
||||
explicit tunit_preview_pane_definition(const config& cfg);
|
||||
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
tbuilder_grid_ptr grid;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
|
@ -39,6 +39,7 @@
|
|||
#include "gui/auxiliary/window_builder/pane.hpp"
|
||||
#include "gui/auxiliary/window_builder/password_box.hpp"
|
||||
#include "gui/auxiliary/window_builder/viewport.hpp"
|
||||
#include "gui/auxiliary/window_builder/unit_preview_pane.hpp"
|
||||
#endif
|
||||
#include "gui/auxiliary/window_builder/instance.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
|
@ -227,6 +228,7 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
TRY(combobox);
|
||||
TRY(drawing);
|
||||
TRY(password_box);
|
||||
TRY(unit_preview_pane);
|
||||
#undef TRY
|
||||
#endif
|
||||
|
||||
|
|
58
src/gui/auxiliary/window_builder/unit_preview_pane.cpp
Normal file
58
src/gui/auxiliary/window_builder/unit_preview_pane.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright (C) 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/auxiliary/window_builder/unit_preview_pane.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/auxiliary/widget_definition/unit_preview_pane.hpp"
|
||||
#include "gui/auxiliary/window_builder/helper.hpp"
|
||||
#include "gui/widgets/unit_preview_pane.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
tbuilder_unit_preview_pane::tbuilder_unit_preview_pane(const config& cfg)
|
||||
: tbuilder_control(cfg)
|
||||
{
|
||||
}
|
||||
|
||||
twidget* tbuilder_unit_preview_pane::build() const
|
||||
{
|
||||
tunit_preview_pane* widget = new tunit_preview_pane();
|
||||
|
||||
init_control(widget);
|
||||
|
||||
DBG_GUI_G << "Window builder: placed unit preview pane '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
boost::intrusive_ptr<const tunit_preview_pane_definition::tresolution> conf
|
||||
= boost::dynamic_pointer_cast<
|
||||
const tunit_preview_pane_definition::tresolution>(widget->config());
|
||||
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
widget->finalize_setup();
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
38
src/gui/auxiliary/window_builder/unit_preview_pane.hpp
Normal file
38
src/gui/auxiliary/window_builder/unit_preview_pane.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
Copyright (C) 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GUI_AUXILIARY_WINDOW_BUILDER_UNIT_PREVIEW_PANE_HPP_INCLUDED
|
||||
#define GUI_AUXILIARY_WINDOW_BUILDER_UNIT_PREVIEW_PANE_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/window_builder/control.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
struct tbuilder_unit_preview_pane : public tbuilder_control
|
||||
{
|
||||
explicit tbuilder_unit_preview_pane(const config& cfg);
|
||||
|
||||
using tbuilder_control::build;
|
||||
|
||||
twidget* build() const;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
232
src/gui/widgets/unit_preview_pane.cpp
Normal file
232
src/gui/widgets/unit_preview_pane.cpp
Normal file
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
Copyright (C) 2016 The Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/widgets/unit_preview_pane.hpp"
|
||||
|
||||
#include "gui/auxiliary/find_widget.tpp"
|
||||
#include "gui/auxiliary/widget_definition/unit_preview_pane.hpp"
|
||||
#include "gui/auxiliary/window_builder/unit_preview_pane.hpp"
|
||||
|
||||
#include "gui/widgets/detail/register.tpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/image.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
||||
#include "formula_string_utils.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "help/help.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
#include "play_controller.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "team.hpp"
|
||||
|
||||
#include "utils/foreach.tpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
REGISTER_WIDGET(unit_preview_pane)
|
||||
|
||||
void tunit_preview_pane::finalize_setup()
|
||||
{
|
||||
// Icons
|
||||
icon_type_ = find_widget<timage>(this, "type_image" , false, false);
|
||||
icon_race_ = find_widget<timage>(this, "type_race" , false, false);
|
||||
icon_alignment_ = find_widget<timage>(this, "type_alignment", false, false);
|
||||
|
||||
// Labels
|
||||
label_name_ = find_widget<tlabel>(this, "type_name" , false, false);
|
||||
label_level_ = find_widget<tlabel>(this, "type_level" , false, false);
|
||||
label_details_ = find_widget<tlabel>(this, "type_details", false, false);
|
||||
|
||||
// Profile button
|
||||
button_profile_ = find_widget<tbutton>(this, "type_profile", false, false);
|
||||
|
||||
if(button_profile_) {
|
||||
connect_signal_mouse_left_click(*button_profile_,
|
||||
boost::bind(&tunit_preview_pane::profile_button_callback, this));
|
||||
}
|
||||
}
|
||||
|
||||
void tunit_preview_pane::set_displayed_type(const unit_type* type)
|
||||
{
|
||||
// Sets the current type id for the profile button callback to use
|
||||
current_type_ = type->id();
|
||||
|
||||
if(icon_type_) {
|
||||
std::string tc;
|
||||
|
||||
if(resources::controller) {
|
||||
tc = "~RC(" + type->flag_rgb() + ">" +
|
||||
team::get_side_color_index(resources::controller->current_side())
|
||||
+ ")";
|
||||
}
|
||||
|
||||
icon_type_->set_label((type->icon().empty() ? type->image() : type->icon()) + tc);
|
||||
}
|
||||
|
||||
if(label_name_) {
|
||||
label_name_->set_label("<big>" + type->type_name() + "</big>");
|
||||
label_name_->set_use_markup(true);
|
||||
}
|
||||
|
||||
if(label_level_) {
|
||||
utils::string_map symbols;
|
||||
symbols["lvl"] = lexical_cast<std::string>(type->level());
|
||||
|
||||
std::string l_str = vgettext("Lvl $lvl", symbols);
|
||||
|
||||
label_level_->set_label("<b>" + l_str + "</b>");
|
||||
label_level_->set_use_markup(true);
|
||||
}
|
||||
|
||||
if(icon_race_) {
|
||||
icon_race_->set_label("icons/unit-groups/race_" + type->race_id() + "_30.png");
|
||||
icon_race_->set_tooltip(type->race()->name(type->genders().front()));
|
||||
}
|
||||
|
||||
if(icon_alignment_) {
|
||||
const std::string& alignment_name = type->alignment().to_string();
|
||||
|
||||
icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
|
||||
icon_alignment_->set_tooltip(unit_type::alignment_description(
|
||||
type->alignment(),
|
||||
type->genders().front()));
|
||||
}
|
||||
|
||||
if(label_details_) {
|
||||
std::stringstream str;
|
||||
str << "<b>" << _("HP: ") << "</b>"
|
||||
<< "<span color='#21e100'>" << type->hitpoints() << "</span> ";
|
||||
|
||||
str << "<b>" << _("XP: ") << "</b>"
|
||||
<< "<span color='#00a0e1'>" << type->experience_needed() << "</span> ";
|
||||
|
||||
str << "<b>" << _("MP: ") << "</b>"
|
||||
<< type->movement() << "\n";
|
||||
|
||||
str << " \n";
|
||||
|
||||
// Print trait details
|
||||
bool has_traits = false;
|
||||
std::stringstream t_str;
|
||||
|
||||
FOREACH(const AUTO& tr, type->possible_traits())
|
||||
{
|
||||
if(tr["availability"] != "musthave") continue;
|
||||
|
||||
const std::string gender_string =
|
||||
type->genders().front() == unit_race::FEMALE ? "female_name" : "male_name";
|
||||
|
||||
t_string name = tr[gender_string];
|
||||
if(name.empty()) {
|
||||
name = tr["name"];
|
||||
}
|
||||
|
||||
if(!name.empty()) {
|
||||
t_str << " " << name << "\n";
|
||||
}
|
||||
|
||||
has_traits = true;
|
||||
}
|
||||
|
||||
if(has_traits) {
|
||||
str << "<b>" << _("Traits") << "</b>" << "\n";
|
||||
str << t_str.str();
|
||||
str << " \n";
|
||||
}
|
||||
|
||||
// Print ability details
|
||||
if(!type->abilities().empty()) {
|
||||
str << "<b>" << _("Abilities") << "</b>" << "\n";
|
||||
|
||||
FOREACH(const AUTO& ab, type->abilities())
|
||||
{
|
||||
str << " " << ab << "\n";
|
||||
}
|
||||
|
||||
str << " \n";
|
||||
}
|
||||
|
||||
// Print attack details
|
||||
if(!type->attacks().empty()) {
|
||||
str << "<b>" << _("Attacks") << "</b>" << "\n";
|
||||
|
||||
FOREACH(const AUTO& a, type->attacks())
|
||||
{
|
||||
str << "<span color='#f5e6c1'>" << a.damage()
|
||||
<< font::weapon_numbers_sep << a.num_attacks() << " " << a.name() << "</span>" << "\n";
|
||||
|
||||
str << "<span color='#a69275'>" << " " << a.range()
|
||||
<< font::weapon_details_sep << a.type() << "</span>" << "\n";
|
||||
|
||||
const std::string special = a.weapon_specials();
|
||||
if (!special.empty()) {
|
||||
str << "<span color='#a69275'>" << " " << special << "</span>" << "\n";
|
||||
}
|
||||
|
||||
const std::string accuracy_parry = a.accuracy_parry_description();
|
||||
if(!accuracy_parry.empty()) {
|
||||
str << "<span color='#a69275'>" << " " << accuracy_parry << "</span>" << "\n";
|
||||
}
|
||||
|
||||
str << " \n";
|
||||
}
|
||||
}
|
||||
|
||||
label_details_->set_label(str.str());
|
||||
label_details_->set_use_markup(true);
|
||||
}
|
||||
}
|
||||
|
||||
void tunit_preview_pane::profile_button_callback()
|
||||
{
|
||||
if(get_window()) {
|
||||
help::show_unit_help((*get_window()).video(), current_type_);
|
||||
}
|
||||
}
|
||||
|
||||
void tunit_preview_pane::set_active(const bool /*active*/)
|
||||
{
|
||||
/* DO NOTHING */
|
||||
}
|
||||
|
||||
bool tunit_preview_pane::get_active() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned tunit_preview_pane::get_state() const
|
||||
{
|
||||
return ENABLED;
|
||||
}
|
||||
|
||||
const std::string& tunit_preview_pane::get_control_type() const
|
||||
{
|
||||
static const std::string type = "unit_preview_pane";
|
||||
return type;
|
||||
}
|
||||
|
||||
void tunit_preview_pane::set_self_active(const bool /*active*/)
|
||||
{
|
||||
/* DO NOTHING */
|
||||
}
|
||||
|
||||
} // namespace gui2
|
102
src/gui/widgets/unit_preview_pane.hpp
Normal file
102
src/gui/widgets/unit_preview_pane.hpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
Copyright (C) 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GUI_WIDGETS_UNIT_PREVIEW_PANE_HPP_INCLUDED
|
||||
#define GUI_WIDGETS_UNIT_PREVIEW_PANE_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/widget_definition/unit_preview_pane.hpp"
|
||||
#include "gui/widgets/container.hpp"
|
||||
#include "unit_types.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class tbutton;
|
||||
class timage;
|
||||
class tlabel;
|
||||
|
||||
namespace implementation
|
||||
{
|
||||
struct tbuilder_unit_preview_pane;
|
||||
}
|
||||
|
||||
class tunit_preview_pane : public tcontainer_
|
||||
{
|
||||
friend struct implementation::tbuilder_unit_preview_pane;
|
||||
|
||||
public:
|
||||
tunit_preview_pane()
|
||||
: tcontainer_(1)
|
||||
, current_type_("")
|
||||
, icon_type_()
|
||||
, icon_race_()
|
||||
, icon_alignment_()
|
||||
, label_name_()
|
||||
, label_level_()
|
||||
, label_details_()
|
||||
, button_profile_()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the interneral sub-widget pointers.
|
||||
* Should be called when building the window, so the pointers
|
||||
* are initilized when set_displayed_type() is called.
|
||||
*/
|
||||
void finalize_setup();
|
||||
|
||||
/** Displays the stats of a specified unit type */
|
||||
void set_displayed_type(const unit_type* type);
|
||||
|
||||
/** Callback for the profile button */
|
||||
void profile_button_callback();
|
||||
|
||||
/** See @ref tcontrol::set_active. */
|
||||
virtual void set_active(const bool active) OVERRIDE;
|
||||
|
||||
/** See @ref tcontrol::get_active. */
|
||||
virtual bool get_active() const OVERRIDE;
|
||||
|
||||
/** See @ref tcontrol::get_state. */
|
||||
virtual unsigned get_state() const OVERRIDE;
|
||||
|
||||
private:
|
||||
std::string current_type_;
|
||||
|
||||
timage* icon_type_;
|
||||
timage* icon_race_;
|
||||
timage* icon_alignment_;
|
||||
|
||||
tlabel* label_name_;
|
||||
tlabel* label_level_;
|
||||
tlabel* label_details_;
|
||||
|
||||
tbutton* button_profile_;
|
||||
|
||||
enum tstate {
|
||||
ENABLED
|
||||
};
|
||||
|
||||
/** See @ref tcontrol::get_control_type. */
|
||||
virtual const std::string& get_control_type() const OVERRIDE;
|
||||
|
||||
/** See @ref tcontainer_::set_self_active. */
|
||||
virtual void set_self_active(const bool active) OVERRIDE;
|
||||
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue