Port the unit_list dialog to the editor.

This commit is contained in:
fendrin 2013-05-15 05:58:57 +02:00
parent 6d36595f6b
commit 01167bcc07
7 changed files with 149 additions and 131 deletions

View file

@ -65,7 +65,7 @@
#image=lite_small
#image=lite
font_size=9
items=statustable,editor-map-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,preferences,editor-settings,help,editor-close-map,quit-editor,editor-quit-to-desktop
items=statustable,unitlist,editor-map-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,preferences,editor-settings,help,editor-close-map,quit-editor,editor-quit-to-desktop
ref=top-panel
rect="=+1,=+1,+100,+20"
#rect="=+3,=+1,+55,=-4"

View file

@ -315,6 +315,137 @@ bool animate_unit_advancement(const map_location &loc, size_t choice, const bool
return true;
}
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
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);
std::vector<std::string> items;
items.push_back(heading);
std::vector<map_location> locations_list;
std::vector<unit> units_list;
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);
}
{
dialogs::units_list_preview_pane unit_preview(units_list);
unit_preview.set_selection(selected);
gui::dialog umenu(gui, _("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.select_hex(loc);
}
}
void show_objectives(const config &level, const std::string &objectives)
{
static const std::string no_objectives(_("No objectives available"));
@ -935,8 +1066,8 @@ unit_preview_pane::details::details() :
}
unit_preview_pane::unit_preview_pane(const gui::filter_textbox *filter, TYPE type, bool on_left_side) :
gui::preview_pane(resources::screen->video()), index_(0),
details_button_(resources::screen->video(), _("Profile"),
gui::preview_pane(display::get_singleton()->video()), index_(0),
details_button_(display::get_singleton()->video(), _("Profile"),
gui::button::TYPE_PRESS,"lite_small", gui::button::MINIMUM_SPACE),
filter_(filter), weapons_(type == SHOW_ALL), left_(on_left_side)
{
@ -1301,9 +1432,9 @@ void show_unit_description(const unit_type &t)
}
if (use_variation)
help::show_variation_help(*resources::screen, t.id(), var, hide_help);
help::show_variation_help(*display::get_singleton(), t.id(), var, hide_help);
else
help::show_unit_help(*resources::screen, t.id(), hide_help);
help::show_unit_help(*display::get_singleton(), t.id(), hide_help);
}
static network::connection network_data_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num, network::statistics (*get_stats)(network::connection handle))

View file

@ -60,6 +60,8 @@ bool animate_unit_advancement(const map_location &loc, size_t choice, const bool
void show_objectives(const config &level, const std::string &objectives);
void show_unit_list(display& gui);
/**
* Allow user to select the game they want to load. Returns the name of the
* save they want to load. Stores whether the user wants to show a replay of

View file

@ -277,6 +277,8 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case HOTKEY_QUIT_GAME:
return true; //general hotkeys we can always do
case hotkey::HOTKEY_UNIT_LIST:
return context_manager_->get_map_context().get_units().size() != 0;
case HOTKEY_STATUS_TABLE:
case HOTKEY_EDITOR_SWITCH_TIME:
@ -917,6 +919,11 @@ void editor_controller::rename_unit()
}
}
void editor_controller::unit_list()
{
dialogs::show_unit_list(*gui_);
}
void editor_controller::cut_selection()
{
copy_selection();

View file

@ -134,6 +134,8 @@ class editor_controller : public controller_base,
void change_unit_id();
void rename_unit();
void unit_list();
/** Copy the selection on the current map to the clipboard */
void copy_selection();

View file

@ -105,7 +105,7 @@ const hotkey_command hotkey_list_[] = {
{ hotkey::HOTKEY_CHANGE_SIDE, "changeside", N_("Change Side (Debug!)"), false, hotkey::SCOPE_GAME, NULL },
{ hotkey::HOTKEY_PREFERENCES, "preferences", N_("Preferences"), false, hotkey::SCOPE_GENERAL, NULL },
{ hotkey::HOTKEY_OBJECTIVES, "objectives", N_("Scenario Objectives"), false, hotkey::SCOPE_GAME, NULL },
{ hotkey::HOTKEY_UNIT_LIST, "unitlist", N_("Unit List"), false, hotkey::SCOPE_GAME, NULL },
{ hotkey::HOTKEY_UNIT_LIST, "unitlist", N_("Unit List"), false, hotkey::SCOPE_GENERAL, NULL },
{ hotkey::HOTKEY_STATISTICS, "statistics", N_("Statistics"), false, hotkey::SCOPE_GAME, NULL },
{ hotkey::HOTKEY_STOP_NETWORK, "stopnetwork", N_("Pause Network Game"), false, hotkey::SCOPE_GAME, NULL },
{ hotkey::HOTKEY_START_NETWORK, "startnetwork", N_("Continue Network Game"), false, hotkey::SCOPE_GAME, NULL },

View file

@ -146,131 +146,7 @@ void menu_handler::show_statistics(int side_num)
void menu_handler::unit_list()
{
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
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);
std::vector<std::string> items;
items.push_back(heading);
std::vector<map_location> locations_list;
std::vector<unit> units_list;
int selected = 0;
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);
}
{
dialogs::units_list_preview_pane unit_preview(units_list);
unit_preview.set_selection(selected);
gui::dialog umenu(*gui_, _("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_->select_hex(loc);
}
dialogs::show_unit_list(*gui_);
}
namespace {