15 #define GETTEXT_DOMAIN "wesnoth-lib"
47 #include <boost/dynamic_bitset.hpp>
50 #define LOG_DP LOG_STREAM(info, log_display)
63 , recall_list_(recall_list)
76 LOG_DP <<
"size: " << units.size();
79 for(
const auto& u_ptr : units) {
80 LOG_DP <<
"\tunit[" << (idx++) <<
"]: " << u_ptr->id() <<
" name = '" << u_ptr->name() <<
"'";
86 static const inline std::string
maybe_inactive(
const std::string& str,
bool active)
96 std::string lvl = std::to_string(
level);
105 }
else if(
level < 1) {
107 }
else if(
level == 1) {
109 }
else if(
level == 2) {
110 return "<b>" + lvl +
"</b>";
112 return"<b><span color='#ffffff'>" + lvl +
"</span></b>";
118 std::stringstream str;
120 if(unit_recall_cost < 0) {
121 unit_recall_cost = team_recall_cost;
124 if(unit_recall_cost > team_recall_cost) {
125 str <<
"<span color='#ff0000'>" << unit_recall_cost <<
"</span>";
126 }
else if(unit_recall_cost == team_recall_cost) {
127 str << unit_recall_cost;
128 }
else if(unit_recall_cost < team_recall_cost) {
129 str <<
"<span color='#00ff00'>" << unit_recall_cost <<
"</span>";
143 int controlled_recruiters = 0;
146 ++controlled_recruiters;
150 std::stringstream
msg;
151 if(controlled_recruiters >= 2) {
154 msg <<
" (" << leader->name();
msg <<
")";
163 label& title = find_widget<label>(&
window,
"title",
true);
167 = find_widget<text_box>(&
window,
"filter_box",
false,
true);
172 listbox& list = find_widget<listbox>(&
window,
"recall_list",
false);
182 find_widget<button>(&
window,
"rename",
false),
186 find_widget<button>(&
window,
"dismiss",
false),
190 find_widget<button>(&
window,
"show_help",
false),
203 wb_gold = whiteb->get_spent_gold_for(
team_.
side());
217 mods +=
"~BLIT(" +
overlay +
")";
225 column[
"tooltip"] =
_(
"This unit cannot be recalled because you will not have enough gold at this point in your plan.");
227 column[
"tooltip"] =
_(
"This unit cannot be recalled because you do not have enough gold.");
230 column[
"use_markup"] =
"true";
233 row_data.emplace(
"unit_image", column);
236 row_data.emplace(
"unit_type", column);
244 row_data.emplace(
"unit_recall_cost", column);
248 row_data.emplace(
"unit_name", column);
251 row_data.emplace(
"unit_level", column);
253 std::stringstream exp_str;
261 row_data.emplace(
"unit_experience", column);
272 filter_text +=
" " + std::string(
"vvv");
277 traits += (traits.empty() ?
"" :
"\n") + trait;
278 filter_text +=
" " + trait;
284 row_data.emplace(
"unit_traits", column);
322 std::string name = selected_unit.
name();
323 const std::string dialog_title(
_(
"Rename Unit"));
324 const std::string dialog_label(
_(
"Name:"));
326 if(gui2::dialogs::edit_text::execute(dialog_title, dialog_label, name)) {
327 selected_unit.
rename(name);
329 find_widget<label>(list.
get_row_grid(
index),
"unit_name",
false).set_label(name);
332 std::ostringstream filter_text;
333 filter_text << selected_unit.
type_name() <<
" " << name <<
" " << std::to_string(selected_unit.
level());
334 for(
const std::string& trait : selected_unit.
trait_names()) {
335 filter_text <<
" " << trait;
360 ?
_(
"Do you really want to dismiss him?")
361 :
_(
"Do you really want to dismiss her?"));
363 }
else if(u.
level() > 1) {
365 ?
_(
"Do you really want to dismiss him?")
366 :
_(
"Do you really want to dismiss her?"));
370 ?
_(
"Do you really want to dismiss him?")
371 :
_(
"Do you really want to dismiss her?"));
392 LOG_DP <<
"Dismissing a unit, side = " << u.
side() <<
", id = '" << u.
id() <<
"'";
393 LOG_DP <<
"That side's recall list:";
398 assert(dismissed_unit);
416 const int selected_row
417 = find_widget<listbox>(
get_window(),
"recall_list",
false).get_selected_row();
419 if(selected_row == -1) {
425 find_widget<unit_preview_pane>(
get_window(),
"unit_details",
false)
426 .set_displayed_unit(selected_unit);
433 listbox& list = find_widget<listbox>(&
window,
"recall_list",
false);
445 const std::vector<std::string> words =
utils::split(text,
' ');
451 boost::dynamic_bitset<> show_items;
458 for(
const auto & word : words) {
467 show_items[
i] = found;
475 find_widget<button>(
get_window(),
"rename",
false).set_active(any_shown);
476 find_widget<button>(
get_window(),
"dismiss",
false).set_active(any_shown);
virtual const unit_map & units() const override
Main class to show messages to the user.
@ yes_no_buttons
Shows a yes and no button.
Abstract base class for all modal dialogs.
int get_retval() const
Returns the cached window exit code.
window * get_window()
Returns a pointer to the dialog's window.
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
std::vector< std::string > filter_options_
void list_item_clicked()
Callbacks.
void filter_text_changed(const std::string &text)
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
std::vector< unit_const_ptr > & recall_list_
std::vector< std::string > last_words_
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
t_string get_image() const
Wrapper for label.
void set_image(const t_string &label)
Wrapper for set_label.
A label displays text that can be wrapped but no scrollbars are provided.
void set_row_shown(const unsigned row, const bool shown)
Makes a row visible or invisible.
void set_active_sorting_option(const order_pair &sort_by, const bool select_first=false)
Sorts the listbox by a pre-set sorting option.
std::pair< int, sort_order::type > order_pair
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
void register_translatable_sorting_option(const int col, translatable_sorter_func_t f)
Registers a special sorting function specifically for translatable values.
bool any_rows_shown() const
void register_sorting_option(const int col, const Func &f)
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
void clear()
Removes all the rows in the listbox, clearing it.
int get_selected_row() const
Returns the first selected row.
unsigned get_item_count() const
Returns the number of items in the listbox.
const order_pair get_active_sorting_option()
void set_text_changed_callback(std::function< void(text_box_base *textbox, const std::string text)> cb)
Set the text_changed callback.
Class for a single line text area.
base class of top level items, the only item which needs to store the final canvases to draw on.
void set_retval(const int retval, const bool close_window=true)
Sets there return value of the window.
void keyboard_capture(widget *widget)
void invalidate_layout()
Updates the size of the window.
void add_to_keyboard_chain(widget *widget)
Adds the widget to the keyboard chain.
unit_ptr find_if_matches_id(const std::string &unit_id)
Find a unit by id.
static config get_disband(const std::string &unit_id)
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)
const std::string & str() const
This class stores all the data for a single 'side' (in game nomenclature).
bool is_local_human() const
recall_list_manager & recall_list()
const std::set< std::string > & recruits() const
Container associating units to locations.
unit_iterator find_leader(int side)
This class represents a single unit of a specific type.
static const std::string & leader_crown()
The path to the leader crown overlay.
static std::string _(const char *str)
int level() const
The current level of this unit.
const t_string & type_name() const
Gets the translatable name of this unit's type.
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 rename(const std::string &name)
Attempts to rename this unit's translatable display name, taking the 'unrenamable' flag into account.
int experience() const
The current number of experience points this unit has.
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
const std::string & id() const
Gets this unit's id.
int side() const
The side this unit belongs to.
unsigned int experience_to_advance() const
The number of experience points this unit needs to level up, or 0 if current XP > max XP.
int max_experience() const
The max number of experience points this unit can have.
unit_race::GENDER gender() const
The gender of this unit.
const t_string & name() const
Gets this unit's translatable display name.
bool can_advance() const
Checks whether this unit has any options to advance to.
color_t xp_color() const
Color for this unit's XP.
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
std::string absolute_image() const
The name of the file to game_display (used in menus).
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
bool loyal() const
Gets whether this unit is loyal - ie, it costs no upkeep.
Define the common log macros for the gui toolkit.
#define log_scope2(domain, description)
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
const std::string unicode_en_dash
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
static std::string get_title_suffix(int side_num)
static listbox::order_pair sort_default
static const std::string maybe_inactive(const std::string &str, bool active)
static std::string format_level_string(const int level)
static void dump_recall_list_to_console(const T &units)
static const color_t inactive_row_color(0x96, 0x96, 0x96)
static listbox::order_pair sort_last
static std::string format_cost_string(int unit_recall_cost, const int team_recall_cost)
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
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.
@ OK
Dialog was closed with the OK button.
@ CANCEL
Dialog was closed with the CANCEL button.
void show_help(const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
Functions to load and save images from/to disk.
play_controller * controller
bool ci_search(const std::string &s1, const std::string &s2)
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.
std::vector< std::string > split(const config_attribute_value &val)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::shared_ptr< const unit > unit_const_ptr
std::shared_ptr< unit > unit_ptr
This file contains the settings handling of the widget library.
The basic class for representing 8-bit RGB or RGBA colour values.
Applies the planned unit map for the duration of the struct's life.
static lg::log_domain log_display("display")