Completed and activated the GUI2 Unit List dialog
This commit is contained in:
parent
5b3c786e8b
commit
cfd205e3a4
4 changed files with 106 additions and 159 deletions
|
@ -3,6 +3,61 @@
|
|||
### Definition of the window to create units in debug mode.
|
||||
###
|
||||
|
||||
#define _GUI_STATUS_BOX
|
||||
[grid]
|
||||
linked_group = "status"
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
horizontal_grow = "true"
|
||||
|
||||
[image]
|
||||
id = "unit_status_slowed"
|
||||
definition = "default"
|
||||
label = "misc/slowed.png"
|
||||
[/image]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
horizontal_grow = "true"
|
||||
|
||||
[image]
|
||||
id = "unit_status_poisoned"
|
||||
definition = "default"
|
||||
label = "misc/poisoned.png"
|
||||
[/image]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
horizontal_grow = "true"
|
||||
|
||||
[image]
|
||||
id = "unit_status_invisible"
|
||||
definition = "default"
|
||||
label = "misc/invisible.png"
|
||||
[/image]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
horizontal_grow = "true"
|
||||
|
||||
[image]
|
||||
id = "unit_status_petrified"
|
||||
definition = "default"
|
||||
label = "misc/petrified.png"
|
||||
[/image]
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
#enddef
|
||||
|
||||
#define _GUI_UNIT_LIST
|
||||
[listbox]
|
||||
id = "units_list"
|
||||
|
@ -56,11 +111,10 @@
|
|||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
border = "left,right"
|
||||
border = "top,bottom"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "sort_3"
|
||||
definition = "gold_small"
|
||||
linked_group = "status"
|
||||
|
||||
|
@ -74,6 +128,7 @@
|
|||
|
||||
# No border by design
|
||||
[toggle_button]
|
||||
id = "sort_3"
|
||||
definition = "listbox_header"
|
||||
linked_group = "hp"
|
||||
|
||||
|
@ -164,49 +219,46 @@
|
|||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
border = "all"
|
||||
border_size = 5
|
||||
[label]
|
||||
id = "unit_moves"
|
||||
definition = "default"
|
||||
definition = "default_small"
|
||||
linked_group = "moves"
|
||||
[/label]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
border = "all"
|
||||
border_size = 5
|
||||
[image]
|
||||
id = "unit_status"
|
||||
definition = "default"
|
||||
linked_group = "status"
|
||||
[/image]
|
||||
|
||||
{_GUI_STATUS_BOX}
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
border = "all"
|
||||
border_size = 5
|
||||
[label]
|
||||
id = "unit_hp"
|
||||
definition = "default"
|
||||
definition = "default_small"
|
||||
linked_group = "hp"
|
||||
[/label]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
border = "all"
|
||||
border_size = 5
|
||||
[label]
|
||||
id = "unit_level"
|
||||
definition = "default"
|
||||
definition = "default_small"
|
||||
linked_group = "level"
|
||||
[/label]
|
||||
[/column]
|
||||
|
@ -409,3 +461,4 @@
|
|||
[/window]
|
||||
|
||||
#undef _GUI_UNIT_LIST
|
||||
#undef _GUI_STATUS_BOX
|
||||
|
|
128
src/dialogs.cpp
128
src/dialogs.cpp
|
@ -27,6 +27,7 @@
|
|||
#include "game_preferences.hpp"
|
||||
#include "gui/dialogs/game_delete.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
#include "gui/dialogs/unit_list.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "help/help.hpp"
|
||||
|
@ -206,131 +207,14 @@ bool animate_unit_advancement(const map_location &loc, size_t choice, const bool
|
|||
|
||||
void show_unit_list(display& gui)
|
||||
{
|
||||
const std::string heading = std::string(1,HEADING_PREFIX) +
|
||||
_("Type") + COLUMN_SEPARATOR + // 0
|
||||
_("Name") + COLUMN_SEPARATOR + // 1
|
||||
_("Moves") + COLUMN_SEPARATOR + // 2
|
||||
_("Status") + COLUMN_SEPARATOR + // 3
|
||||
_("HP") + COLUMN_SEPARATOR + // 4
|
||||
_("Level^Lvl.") + COLUMN_SEPARATOR + // 5
|
||||
_("XP") + COLUMN_SEPARATOR + // 6
|
||||
_("unit list^Traits"); // 7
|
||||
gui2::tunit_list dlg(gui);
|
||||
|
||||
gui::menu::basic_sorter sorter;
|
||||
sorter.set_alpha_sort(0).set_alpha_sort(1).set_numeric_sort(2);
|
||||
sorter.set_alpha_sort(3).set_numeric_sort(4).set_level_sort(5, 6);
|
||||
sorter.set_xp_sort(6).set_alpha_sort(7);
|
||||
dlg.show(gui.video());
|
||||
|
||||
std::vector<std::string> items;
|
||||
items.push_back(heading);
|
||||
if(dlg.get_retval() == gui2::twindow::OK) {
|
||||
const map_location& loc = dlg.get_location_to_scroll_to();
|
||||
|
||||
std::vector<map_location> locations_list;
|
||||
std::shared_ptr<std::vector<unit_const_ptr> > units_list = std::make_shared<std::vector<unit_const_ptr> >();
|
||||
|
||||
int selected = 0;
|
||||
|
||||
const unit_map& units = gui.get_units();
|
||||
|
||||
for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
|
||||
if (i->side() != gui.viewing_side())
|
||||
continue;
|
||||
|
||||
std::stringstream row;
|
||||
// If a unit is already selected on the map, we do the same in the unit list dialog
|
||||
if (gui.selected_hex() == i->get_location()) {
|
||||
row << DEFAULT_ITEM;
|
||||
selected = units_list->size();
|
||||
}
|
||||
// If unit is leader, show name in special color, e.g. gold/silver
|
||||
/** @todo TODO: hero just has overlay "misc/hero-icon.png" - needs an ability to query */
|
||||
|
||||
if (i->can_recruit() ) {
|
||||
row << "<205,173,0>"; // gold3
|
||||
}
|
||||
row << i->type_name() << COLUMN_SEPARATOR;
|
||||
if (i->can_recruit() ) {
|
||||
row << "<205,173,0>"; // gold3
|
||||
}
|
||||
row << i->name() << COLUMN_SEPARATOR;
|
||||
|
||||
// display move left (0=red, moved=yellow, not moved=green)
|
||||
if (i->movement_left() == 0) {
|
||||
row << font::RED_TEXT;
|
||||
} else if (i->movement_left() < i->total_movement() ) {
|
||||
row << "<255,255,0>";
|
||||
} else {
|
||||
row << font::GREEN_TEXT;
|
||||
}
|
||||
row << i->movement_left() << '/' << i->total_movement() << COLUMN_SEPARATOR;
|
||||
|
||||
// show icons if unit is slowed, poisoned, petrified, invisible:
|
||||
if(i->get_state(unit::STATE_PETRIFIED))
|
||||
row << IMAGE_PREFIX << "misc/petrified.png" << IMG_TEXT_SEPARATOR;
|
||||
if(i->get_state(unit::STATE_POISONED))
|
||||
row << IMAGE_PREFIX << "misc/poisoned.png" << IMG_TEXT_SEPARATOR;
|
||||
if(i->get_state(unit::STATE_SLOWED))
|
||||
row << IMAGE_PREFIX << "misc/slowed.png" << IMG_TEXT_SEPARATOR;
|
||||
if(i->invisible(i->get_location(),false))
|
||||
row << IMAGE_PREFIX << "misc/invisible.png";
|
||||
row << COLUMN_SEPARATOR;
|
||||
|
||||
// Display HP
|
||||
// see also unit_preview_pane in dialogs.cpp
|
||||
row << font::color2markup(i->hp_color());
|
||||
row << i->hitpoints() << '/' << i->max_hitpoints() << COLUMN_SEPARATOR;
|
||||
|
||||
// Show units of level (0=gray, 1 normal, 2 bold, 2+ bold&wbright)
|
||||
int level = i->level();
|
||||
if(level < 1) {
|
||||
row << "<150,150,150>";
|
||||
} else if(level == 1) {
|
||||
row << font::NORMAL_TEXT;
|
||||
} else if(level == 2) {
|
||||
row << font::BOLD_TEXT;
|
||||
} else if(level > 2 ) {
|
||||
row << font::BOLD_TEXT << "<255,255,255>";
|
||||
}
|
||||
row << level << COLUMN_SEPARATOR;
|
||||
|
||||
// Display XP
|
||||
row << font::color2markup(i->xp_color());
|
||||
row << i->experience() << "/";
|
||||
if (i->can_advance()) {
|
||||
row << i->max_experience();
|
||||
} else {
|
||||
row << "-";
|
||||
}
|
||||
row << COLUMN_SEPARATOR;
|
||||
|
||||
// TODO: show 'loyal' in green / xxx in red // how to handle translations ??
|
||||
row << utils::join(i->trait_names(), ", ");
|
||||
items.push_back(row.str());
|
||||
|
||||
locations_list.push_back(i->get_location());
|
||||
units_list->push_back(i.get_shared_ptr());
|
||||
}
|
||||
|
||||
{
|
||||
dialogs::units_list_preview_pane unit_preview(units_list);
|
||||
unit_preview.set_selection(selected);
|
||||
|
||||
gui::dialog umenu(gui.video(), _("Unit List"), "", gui::NULL_DIALOG);
|
||||
umenu.set_menu(items, &sorter);
|
||||
umenu.add_pane(&unit_preview);
|
||||
//sort by type name
|
||||
umenu.get_menu().sort_by(0);
|
||||
|
||||
umenu.add_button(new gui::standard_dialog_button(gui.video(), _("Scroll To"), 0, false),
|
||||
gui::dialog::BUTTON_STANDARD);
|
||||
umenu.add_button(new gui::standard_dialog_button(gui.video(), _("Close"), 1, true),
|
||||
gui::dialog::BUTTON_STANDARD);
|
||||
umenu.set_basic_behavior(gui::OK_CANCEL);
|
||||
selected = umenu.show();
|
||||
} // this will kill the dialog before scrolling
|
||||
|
||||
if(selected >= 0 && selected < int(locations_list.size())) {
|
||||
const map_location& loc = locations_list[selected];
|
||||
gui.scroll_to_tile(loc,game_display::WARP);
|
||||
gui.scroll_to_tile(loc, game_display::WARP);
|
||||
gui.select_hex(loc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,10 +60,6 @@ tunit_list::tunit_list(const display& gui)
|
|||
|
||||
unit_list_->push_back(i.get_shared_ptr());
|
||||
}
|
||||
|
||||
//for(const unit_map& u : gui.get_units()) {
|
||||
// unit_list_->push_back(u.get_shared_ptr());
|
||||
//}
|
||||
}
|
||||
|
||||
static std::string format_level_string(const int level)
|
||||
|
@ -127,16 +123,6 @@ void tunit_list::pre_show(twindow& window)
|
|||
std::map<std::string, string_map> row_data;
|
||||
string_map column;
|
||||
|
||||
std::string mods = unit->image_mods();
|
||||
|
||||
if(unit->can_recruit()) {
|
||||
mods += "~BLIT(" + unit::leader_crown() + ")";
|
||||
}
|
||||
|
||||
for(const std::string& overlay : unit->overlays()) {
|
||||
mods += "~BLIT(" + overlay + ")";
|
||||
}
|
||||
|
||||
column["use_markup"] = "true";
|
||||
|
||||
column["label"] = format_if_leader(unit, unit->type_name());
|
||||
|
@ -169,14 +155,36 @@ void tunit_list::pre_show(twindow& window)
|
|||
row_data.insert(std::make_pair("unit_traits", column));
|
||||
|
||||
list.add_row(row_data);
|
||||
|
||||
// NOTE: this needs to be done *after* the row is added
|
||||
tgrid* row_grid = list.get_row_grid(list.get_item_count() - 1);
|
||||
|
||||
// TODO: show custom statuses
|
||||
if(!unit->get_state(unit::STATE_PETRIFIED)) {
|
||||
find_widget<timage>(row_grid, "unit_status_slowed", false).set_visible(twidget::tvisible::invisible);
|
||||
}
|
||||
|
||||
if(!unit->get_state(unit::STATE_POISONED)) {
|
||||
find_widget<timage>(row_grid, "unit_status_poisoned", false).set_visible(twidget::tvisible::invisible);
|
||||
}
|
||||
|
||||
if(!unit->get_state(unit::STATE_SLOWED)) {
|
||||
find_widget<timage>(row_grid, "unit_status_invisible", false).set_visible(twidget::tvisible::invisible);
|
||||
}
|
||||
|
||||
if(!unit->invisible(unit->get_location(), false)) {
|
||||
find_widget<timage>(row_grid, "unit_status_petrified", false).set_visible(twidget::tvisible::invisible);
|
||||
}
|
||||
}
|
||||
|
||||
list.register_sorting_option(0, [this](const int i) { return (*unit_list_)[i]->type_name().str(); });
|
||||
list.register_sorting_option(1, [this](const int i) { return (*unit_list_)[i]->name().str(); });
|
||||
list.register_sorting_option(2, [this](const int i) { return (*unit_list_)[i]->level(); });
|
||||
list.register_sorting_option(3, [this](const int i) { return (*unit_list_)[i]->experience(); });
|
||||
list.register_sorting_option(4, [this](const int i) {
|
||||
return (*unit_list_)[i]->trait_names().empty() ? (*unit_list_)[i]->trait_names().front().str() : ""; });
|
||||
list.register_sorting_option(2, [this](const int i) { return (*unit_list_)[i]->movement_left(); });
|
||||
list.register_sorting_option(3, [this](const int i) { return (*unit_list_)[i]->hitpoints(); });
|
||||
list.register_sorting_option(4, [this](const int i) { return (*unit_list_)[i]->level(); });
|
||||
list.register_sorting_option(5, [this](const int i) { return (*unit_list_)[i]->experience(); });
|
||||
list.register_sorting_option(6, [this](const int i) {
|
||||
return !(*unit_list_)[i]->trait_names().empty() ? (*unit_list_)[i]->trait_names().front().str() : ""; });
|
||||
|
||||
list_item_clicked(window);
|
||||
}
|
||||
|
@ -197,8 +205,9 @@ void tunit_list::list_item_clicked(twindow& window)
|
|||
void tunit_list::post_show(twindow& window)
|
||||
{
|
||||
if(get_retval() == twindow::OK) {
|
||||
selected_index_ = find_widget<tlistbox>(&window, "units_list", false)
|
||||
.get_selected_row();
|
||||
const int selected_row = find_widget<tlistbox>(&window, "units_list", false).get_selected_row();
|
||||
|
||||
location_of_selected_unit_ = unit_list_->at(selected_row).get()->get_location();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define GUI_DIALOGS_UNIT_LIST_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "map/location.hpp"
|
||||
#include "units/ptr.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
@ -35,15 +36,15 @@ class tunit_list : public tdialog
|
|||
public:
|
||||
explicit tunit_list(const display& gui);
|
||||
|
||||
int get_selected_index() const
|
||||
map_location get_location_to_scroll_to() const
|
||||
{
|
||||
return selected_index_;
|
||||
return location_of_selected_unit_;
|
||||
}
|
||||
|
||||
private:
|
||||
unit_ptr_vector unit_list_;
|
||||
|
||||
int selected_index_;
|
||||
map_location location_of_selected_unit_;
|
||||
|
||||
/** Callbacks */
|
||||
void list_item_clicked(twindow& window);
|
||||
|
|
Loading…
Add table
Reference in a new issue