tunit_create: added minimal unit preview section and filter box (non-functional)

This commit is contained in:
Charles Dang 2015-10-20 08:44:48 +11:00
parent 701229d69d
commit 21391f9039
3 changed files with 490 additions and 146 deletions

View file

@ -48,145 +48,340 @@
[/label]
[/column]
[/row]
[row]
grow_factor = 0
grow_factor = 1
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[listbox]
id = "unit_type_list"
definition = "default"
[header]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[toggle_button]
id = "sort_0"
definition = "listbox_header"
linked_group = "race"
label = _ "Race"
[/toggle_button]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[toggle_button]
id = "sort_1"
definition = "listbox_header"
linked_group = "unit_type"
label = _ "Type"
[/toggle_button]
[/column]
[/row]
[/header]
[list_definition]
[row]
[column]
vertical_grow = "true"
horizontal_grow = "true"
[toggle_panel]
definition = "default"
return_value_id = "ok"
[grid]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "race"
definition = "default"
linked_group = "race"
[/label]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "unit_type"
definition = "default"
linked_group = "unit_type"
[/label]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_grow = "true"
vertical_grow = "true"
[grid]
[row]
grow_factor=0
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
vertical_alignment = "top"
[grid]
[label]
definition = "default"
label= _ "Gender:"
[/label]
[/column]
[row]
[column]
border = "all"
border_size = 5
vertical_grow = "true"
horizontal_alignment = "left"
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[label]
id = "type_name"
wrap = "true"
[/label]
[toggle_button]
id = "male_toggle"
definition = "default"
label= _ "Male"
[/toggle_button]
[/column]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[/row]
[toggle_button]
id = "female_toggle"
definition = "default"
label= _ "Female"
[/toggle_button]
[row]
grow_factor = 1
[column]
border = "all"
border_size = 5
horizontal_alignment = "center"
vertical_alignment = "center"
[image]
id = "type_image"
definition = "default"
[/image]
[/column]
[/row]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "center"
[button]
id = "type_profile"
definition = "default"
label = _ "Profile"
[/button]
[/column]
[/row]
[row]
[column]
horizontal_grow = "true"
[grid]
[row]
grow_factor = 1
[column]
border = "all"
border_size = 5
vertical_grow = "true"
horizontal_alignment = "left"
[image]
id = "type_race"
[/image]
[/column]
[column]
border = "all"
border_size = 5
vertical_grow = "true"
horizontal_alignment = "center"
[image]
id = "type_alignment"
[/image]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
[column]
border = "all"
border_size = 5
vertical_grow = "true"
horizontal_alignment = "left"
[label]
id = "type_details"
definition = "default_small"
wrap = "true"
[/label]
[/column]
[/row]
[/grid]
[/column]
[column]
[grid]
[row]
[column]
horizontal_alignment = "left"
[grid]
[row]
grow_factor = 1
[column]
border = "all"
border_size = 5
vertical_alignment = "center"
[label]
definition = "default"
label = _ "Filter"
[/label]
[/column]
[column]
border = "all"
border_size = 5
[text_box]
id = "filter_box"
definition = "default"
label = ""
[/text_box]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[listbox]
id = "unit_type_list"
definition = "default"
[header]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[toggle_button]
id = "sort_0"
definition = "listbox_header"
linked_group = "race"
label = _ "Race"
[/toggle_button]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[toggle_button]
id = "sort_1"
definition = "listbox_header"
linked_group = "unit_type"
label = _ "Type"
[/toggle_button]
[/column]
[/row]
[/header]
[list_definition]
[row]
[column]
vertical_grow = "true"
horizontal_grow = "true"
[toggle_panel]
definition = "default"
return_value_id = "ok"
[grid]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "race"
definition = "default"
linked_group = "race"
[/label]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "unit_type"
definition = "default"
linked_group = "unit_type"
[/label]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_grow = "true"
[grid]
[row]
grow_factor=0
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label= _ "Gender:"
[/label]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[toggle_button]
id = "male_toggle"
definition = "radio"
label= _ "Male"
[/toggle_button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[toggle_button]
id = "female_toggle"
definition = "radio"
label= _ "Female"
[/toggle_button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
@ -224,8 +419,11 @@
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View file

@ -25,9 +25,22 @@
#include "gui/widgets/listbox.hpp"
#endif
#include "gui/widgets/settings.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/image.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/grid.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/window.hpp"
#include "display.hpp"
#include "help/help.hpp"
#include "game_config.hpp"
#include "gettext.hpp"
#include "play_controller.hpp"
#include "resources.hpp"
#include "team.hpp"
#include "unit_types.hpp"
#include "utils/foreach.tpp"
#include <boost/bind.hpp>
@ -85,8 +98,10 @@ namespace gui2
REGISTER_DIALOG(unit_create)
tunit_create::tunit_create()
: gender_(last_gender), choice_(last_chosen_type_id), type_info_()
tunit_create::tunit_create(display* disp)
: gender_(last_gender)
, choice_(last_chosen_type_id)
, disp_(disp)
{
}
@ -98,18 +113,37 @@ void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
= find_widget<ttoggle_button>(&window, "female_toggle", false);
tlistbox& list = find_widget<tlistbox>(&window, "unit_type_list", false);
male_toggle.set_callback_state_change(
dialog_callback<tunit_create,
&tunit_create::gender_toggle_callback>);
female_toggle.set_callback_state_change(
dialog_callback<tunit_create,
&tunit_create::gender_toggle_callback>);
update_male_female_toggles(male_toggle, female_toggle, gender_);
list.clear();
/**find_widget<ttext_box>(&window, "filter_box", false, true)
.set_text_changed_callback(
boost::bind(&tunit_create::filter_text_changed, this, _1, _2));**/
#ifdef GUI2_EXPERIMENTAL_LISTBOX
connect_signal_notify_modified(*list,
boost::bind(&tunit_create::list_item_clicked,
*this,
boost::ref(window)));
#else
list.set_callback_value_change(
dialog_callback<tunit_create, &tunit_create::list_item_clicked>);
#endif
// We use this container to "map" unit_type ids to list subscripts
// later, so it ought to be empty before proceeding.
type_info_.clear();
window.keyboard_capture(&list);
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "type_profile", false),
boost::bind(&tunit_create::profile_button_callback,
this,
boost::ref(window)));
male_toggle.set_callback_state_change(
dialog_callback<tunit_create, &tunit_create::gender_toggle_callback>);
female_toggle.set_callback_state_change(
dialog_callback<tunit_create, &tunit_create::gender_toggle_callback>);
update_male_female_toggles(male_toggle, female_toggle, gender_);
list.clear();
FOREACH(const AUTO & i, unit_types.types())
{
@ -119,15 +153,14 @@ void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
// Make sure this unit type is built with the data we need.
unit_types.build_unit_type(i.second, unit_type::HELP_INDEXED);
// Create a race name/type id pair for each unit type
type_info_.push_back(std::make_pair(i.second.race()->plural_name(), i.first));
units_.push_back(&i.second);
std::map<std::string, string_map> row_data;
string_map column;
column["label"] = type_info_.back().first;
column["label"] = units_.back()->race()->plural_name();
row_data.insert(std::make_pair("race", column));
column["label"] = type_info_.back().second;
column["label"] = units_.back()->type_name();
row_data.insert(std::make_pair("unit_type", column));
list.add_row(row_data);
@ -138,7 +171,7 @@ void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
}
}
if(type_info_.empty()) {
if(units_.empty()) {
ERR_GUI_G << "no unit types found for unit create dialog; not good"
<< std::endl;
}
@ -150,26 +183,28 @@ void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
order_funcs[0] = boost::bind(&tunit_create::compare_type, this, _1, _2);
order_funcs[1] = boost::bind(&tunit_create::compare_type_rev, this, _1, _2);
list.set_column_order(1, order_funcs);
list_item_clicked(window);
}
bool tunit_create::compare_type(unsigned i1, unsigned i2) const
{
return type_info_[i1].second < type_info_[i2].second;
return units_[i1]->type_name().str() < units_[i2]->type_name().str();
}
bool tunit_create::compare_race(unsigned i1, unsigned i2) const
{
return type_info_[i1].first < type_info_[i2].first;
return units_[i1]->race()->plural_name().str() < units_[i2]->race()->plural_name().str();
}
bool tunit_create::compare_type_rev(unsigned i1, unsigned i2) const
{
return type_info_[i1].second > type_info_[i2].second;
return units_[i1]->type_name().str() > units_[i2]->type_name().str();
}
bool tunit_create::compare_race_rev(unsigned i1, unsigned i2) const
{
return type_info_[i1].first > type_info_[i2].first;
return units_[i1]->race()->plural_name().str() > units_[i2]->race()->plural_name().str();
}
void tunit_create::post_show(twindow& window)
@ -187,7 +222,7 @@ void tunit_create::post_show(twindow& window)
const int selected_row = list.get_selected_row();
if(selected_row < 0) {
return;
} else if(static_cast<size_t>(selected_row) >= type_info_.size()) {
} else if(static_cast<size_t>(selected_row) >= units_.size()) {
// FIXME: maybe assert?
ERR_GUI_G << "unit create dialog has more list items than known unit "
"types; not good\n";
@ -195,11 +230,110 @@ void tunit_create::post_show(twindow& window)
}
last_chosen_type_id = choice_
= type_info_[static_cast<size_t>(selected_row)].second;
= units_[static_cast<size_t>(selected_row)]->type_name();
last_gender = gender_ = female_toggle.get_value() ? unit_race::FEMALE
: unit_race::MALE;
}
void tunit_create::print_stats(std::stringstream& str, const int row)
{
const unit_type* u = units_[static_cast<size_t>(row)];
str << _("Level ") << u->level() << "\n";
//str << unit_type::alignment_description(
// u->alignment(),
// u->genders().front()) << "\n";
//str << u->race()->name(u->genders().front()) << "\n";
str << "\n";
str << _("HP: ")
<< "<span color='#21e100'>" << u->hitpoints() << "/" << u->hitpoints() << "</span>" << "\n";
str << _("XP: ")
<< "<span color='#00a0e1'>" << u->experience_needed() << u->experience_needed() << "</span>" << "\n";
str << _("MP: ")
<< u->movement() << "/" << u->movement() << "\n";
// FIXME: This probably must be move into a unit_type function
// Also actually needs to be fixed
/**BOOST_FOREACH(const config& tr, u->possible_traits())
{
if (tr["availability"] != "musthave") continue;
const std::string gender_string =
u->genders().front() == unit_race::FEMALE ? "female_name" : "male_name";
t_string name = tr[gender_string];
if (name.empty()) {
name = tr["name"];
}
if (!name.empty()) {
//if (!traits.empty()) {
// str << ", ";
//}
str << name << "\n";
}
}**/
}
void tunit_create::list_item_clicked(twindow& window)
{
const int selected_row
= find_widget<tlistbox>(&window, "unit_type_list", false).get_selected_row();
const unit_type* u = units_[static_cast<size_t>(selected_row)];
std::stringstream str;
print_stats(str, selected_row);
const std::string& tc = "~RC("
+ u->flag_rgb() + ">"
+ team::get_side_color_index(resources::controller->play_controller::current_side()) + ")";
const std::string& alignment_name = unit_type::alignment_description(
u->alignment(),
u->genders().front());
find_widget<timage>(&window, "type_image", false)
.set_label(u->image() + tc);
tlabel& u_name = find_widget<tlabel>(&window, "type_name", false);
u_name.set_label("<big>" + u->type_name() + "</big>");
u_name.set_use_markup(true);
timage& r_icon = find_widget<timage>(&window, "type_race", false);
r_icon.set_label("icons/unit-groups/race_" + u->race_id() + "_30.png");
r_icon.set_tooltip(u->race()->name(u->genders().front()));
timage& a_icon = find_widget<timage>(&window, "type_alignment", false);
a_icon.set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
a_icon.set_tooltip(alignment_name);
tlabel& details = find_widget<tlabel>(&window, "type_details", false);
details.set_label(str.str());
details.set_use_markup(true);
}
/**bool tunit_create::filter_text_changed(ttext_* textbox, const std::string& text)
{
}**/
void tunit_create::profile_button_callback(twindow& window)
{
const int selected_row
= find_widget<tlistbox>(&window, "unit_type_list", false).get_selected_row();
help::show_unit_help(*disp_,
units_[static_cast<size_t>(selected_row)]->type_name(),
units_[static_cast<size_t>(selected_row)]->show_variations_in_help(), false);
}
void tunit_create::gender_toggle_callback(twindow& window)
{
ttoggle_button& male_toggle

View file

@ -17,17 +17,20 @@
#include "gui/dialogs/dialog.hpp"
#include "race.hpp"
#include "unit_types.hpp"
#include <string>
#include <vector>
class display;
namespace gui2
{
class tunit_create : public tdialog
{
public:
tunit_create();
tunit_create(display* disp = NULL);
/** Unit type choice from the user. */
const std::string& choice() const
@ -48,10 +51,13 @@ public:
}
private:
std::vector<const unit_type*> units_;
unit_race::GENDER gender_;
std::string choice_;
std::vector<std::pair<std::string, std::string> > type_info_;
display* disp_;
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
@ -67,6 +73,12 @@ private:
/** Inherited from tdialog. */
void post_show(twindow& window);
void print_stats(std::stringstream& str, const int row);
/** Callbacks */
void list_item_clicked(twindow& window);
//void filter_text_changed(ttext_* textbox, const std::string& text);
void profile_button_callback(twindow& window);
void gender_toggle_callback(twindow& window);
};
}