15 #define GETTEXT_DOMAIN "wesnoth-lib" 47 #include <boost/dynamic_bitset.hpp> 50 #define LOG_DP LOG_STREAM(info, log_display) 62 : recall_list_(recall_list)
75 LOG_DP <<
"size: " << units.size() <<
"\n";
78 for(
const auto& u_ptr : units) {
79 LOG_DP <<
"\tunit[" << (idx++) <<
"]: " << u_ptr->id() <<
" name = '" << u_ptr->name() <<
"'\n";
85 static const inline std::string
maybe_inactive(
const std::string& str,
bool active)
95 std::string lvl = std::to_string(level);
104 }
else if(level < 1) {
106 }
else if(level == 1) {
108 }
else if(level == 2) {
109 return "<b>" + lvl +
"</b>";
111 return"<b><span color='#ffffff'>" + lvl +
"</span></b>";
117 std::stringstream str;
119 if(unit_recall_cost < 0) {
120 unit_recall_cost = team_recall_cost;
123 if(unit_recall_cost > team_recall_cost) {
124 str <<
"<span color='#ff0000'>" << unit_recall_cost <<
"</span>";
125 }
else if(unit_recall_cost == team_recall_cost) {
126 str << unit_recall_cost;
127 }
else if(unit_recall_cost < team_recall_cost) {
128 str <<
"<span color='#00ff00'>" << unit_recall_cost <<
"</span>";
142 int controlled_recruiters = 0;
145 ++controlled_recruiters;
149 std::stringstream
msg;
150 if(controlled_recruiters >= 2) {
153 msg <<
" (" << leader->name(); msg <<
")";
162 label& title = find_widget<label>(&window,
"title",
true);
166 = find_widget<text_box>(&window,
"filter_box",
false,
true);
171 listbox& list = find_widget<listbox>(&window,
"recall_list",
false);
177 window.keyboard_capture(filter);
178 window.add_to_keyboard_chain(&list);
181 find_widget<button>(&window,
"rename",
false),
185 find_widget<button>(&window,
"dismiss",
false),
189 find_widget<button>(&window,
"show_help",
false),
193 std::map<std::string, string_map> row_data;
202 wb_gold = whiteb->get_spent_gold_for(
team_.
side());
209 const bool recallable = (recall_cost <=
team_.
gold() - wb_gold);
216 mods +=
"~BLIT(" +
overlay +
")";
224 column[
"tooltip"] =
_(
"This unit cannot be recalled because you will not have enough gold at this point in your plan.");
226 column[
"tooltip"] =
_(
"This unit cannot be recalled because you do not have enough gold.");
229 column[
"use_markup"] =
"true";
232 row_data.emplace(
"unit_image", column);
235 row_data.emplace(
"unit_type", column);
243 row_data.emplace(
"unit_recall_cost", column);
247 row_data.emplace(
"unit_name", column);
250 row_data.emplace(
"unit_level", column);
252 std::stringstream exp_str;
260 row_data.emplace(
"unit_experience", column);
271 filter_text +=
" " + std::string(
"vvv");
276 traits += (traits.empty() ?
"" :
"\n") + trait;
277 filter_text +=
" " + trait;
283 row_data.emplace(
"unit_traits", column);
288 image *gold_icon =
dynamic_cast<image*
>(grid.
find(
"gold_icon",
false));
297 const unit& u = *recall_list_[
i];
302 return !recall_list_[
i]->trait_names().empty() ? recall_list_[
i]->trait_names().front().str() :
"";
321 std::string name = selected_unit.
name();
322 const std::string dialog_title(
_(
"Rename Unit"));
323 const std::string dialog_label(
_(
"Name:"));
325 if(gui2::dialogs::edit_text::execute(dialog_title, dialog_label, name)) {
326 selected_unit.
rename(name);
328 find_widget<label>(list.
get_row_grid(index),
"unit_name",
false).set_label(name);
331 std::ostringstream filter_text;
332 filter_text << selected_unit.
type_name() <<
" " << name <<
" " << std::to_string(selected_unit.
level());
333 for(
const std::string& trait : selected_unit.
trait_names()) {
334 filter_text <<
" " << trait;
359 ?
_(
"Do you really want to dismiss him?")
360 :
_(
"Do you really want to dismiss her?"));
362 }
else if(u.
level() > 1) {
363 message <<
_(
"This unit is an experienced one, having advanced levels.") <<
" " << (u.
gender() ==
unit_race::MALE 364 ?
_(
"Do you really want to dismiss him?")
365 :
_(
"Do you really want to dismiss her?"));
369 ?
_(
"Do you really want to dismiss him?")
370 :
_(
"Do you really want to dismiss her?"));
373 if(!message.str().empty()) {
391 LOG_DP <<
"Dismissing a unit, side = " << u.
side() <<
", id = '" << u.
id() <<
"'\n";
392 LOG_DP <<
"That side's recall list:\n";
397 assert(dismissed_unit);
415 const int selected_row
416 = find_widget<listbox>(
get_window(),
"recall_list",
false).get_selected_row();
418 if(selected_row == -1) {
424 find_widget<unit_preview_pane>(
get_window(),
"unit_details",
false)
425 .set_displayed_unit(selected_unit);
432 listbox& list = find_widget<listbox>(&window,
"recall_list",
false);
444 const std::vector<std::string> words =
utils::split(text,
' ');
450 boost::dynamic_bitset<> show_items;
457 for(
const auto & word : words) {
466 show_items[
i] = found;
474 find_widget<button>(
get_window(),
"rename",
false).set_active(any_shown);
475 find_widget<button>(
get_window(),
"dismiss",
false).set_active(any_shown);
const order_pair get_active_sorting_option()
Define the common log macros for the gui toolkit.
static const std::string maybe_inactive(const std::string &str, bool active)
play_controller * controller
Dialog was closed with the CANCEL button.
void set_active_sorting_option(const order_pair &sort_by, const bool select_first=false)
Sorts the listbox by a pre-set sorting option.
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
void set_text_changed_callback(std::function< void(text_box_base *textbox, const std::string text)> cb)
Set the text_changed callback.
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
void show_help(const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
virtual const unit_map & units() const override
This class represents a single unit of a specific type.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
unit_iterator find_leader(int side)
Main class to show messages to the user.
unit_race::GENDER gender() const
The gender of this unit.
static const color_t inactive_row_color(0x96, 0x96, 0x96)
void rename(const std::string &name)
Attempts to rename this unit's translatable display name, taking the 'unrenamable' flag into account...
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
std::pair< int, sort_order::type > order_pair
t_string get_image() const
Wrapper for label.
std::vector< unit_const_ptr > & recall_list_
static listbox::order_pair sort_default
void register_translatable_sorting_option(const int col, translatable_sorter_func_t f)
Registers a special sorting function specifically for translatable values.
std::string absolute_image() const
The name of the file to game_display (used in menus).
window * get_window() const
Returns a pointer to the dialog's window.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
A label displays a text, the text can be wrapped but no scrollbars are provided.
int get_selected_row() const
Returns the first selected row.
static std::string _(const char *str)
std::shared_ptr< unit > unit_ptr
static lg::log_domain log_display("display")
Class for a single line text area.
static listbox::order_pair sort_last
unsigned int experience_to_advance() const
The number of experience points this unit needs to level up, or 0 if current XP > max XP...
std::shared_ptr< const unit > unit_const_ptr
static std::string format_level_string(const int level)
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
void filter_text_changed(const std::string &text)
This class stores all the data for a single 'side' (in game nomenclature).
static const std::string & leader_crown()
The path to the leader crown overlay.
const std::string & id() const
Gets this unit's id.
unit_ptr find_if_matches_id(const std::string &unit_id)
Find a unit by id.
std::vector< std::string > filter_options_
This file contains the settings handling of the widget library.
Applies the planned unit map for the duration of the struct's life.
void clear()
Removes all the rows in the listbox, clearing it.
color_t xp_color() const
Color for this unit's XP.
const t_string & name() const
Gets this unit's translatable display name.
int max_experience() const
The max number of experience points this unit can have.
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
unsigned get_item_count() const
Returns the number of items in the listbox.
Shows a yes and no button.
int level() const
The current level of this unit.
#define log_scope2(domain, description)
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
bool any_rows_shown() const
const t_string & type_name() const
Gets the translatable name of this unit's type.
static std::string format_cost_string(int unit_recall_cost, const int team_recall_cost)
bool loyal() const
Gets whether this unit is loyal - ie, it costs no upkeep.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
bool ci_search(const std::string &s1, const std::string &s2)
void list_item_clicked()
Callbacks.
const std::string unicode_en_dash
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
grid & add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
static std::string get_title_suffix(int side_num)
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
static void dump_recall_list_to_console(const T &units)
std::vector< std::string > last_words_
static config get_disband(const std::string &unit_id)
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
void set_image(const t_string &label)
Wrapper for set_label.
static bool run_and_throw(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
int get_retval() const
Returns the cached window exit code.
bool is_local_human() const
int experience() const
The current number of experience points this unit has.
std::vector< std::string > split(const config_attribute_value &val)
Functions to load and save images from/to disk.
bool can_advance() const
Checks whether this unit has any options to advance to.
recall_list_manager & recall_list()
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
Container associating units to locations.
void invalidate_layout()
Updates the size of the window.
int side() const
The side this unit belongs to.
Dialog was closed with the OK button.
void register_sorting_option(const int col, const Func &f)
const std::string & str() const
void set_retval(int retval)
Convenience wrapper to set the window's exit code.
base class of top level items, the only item which needs to store the final canvases to draw on...
bool unrenamable() const
Whether this unit can be renamed.
int recall_cost() const
How much gold it costs to recall this unit, or -1 if the side's default recall cost is used...
void set_row_shown(const unsigned row, const bool shown)
Makes a row visible or invisible.
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
const std::set< std::string > & recruits() const