15 #define GETTEXT_DOMAIN "wesnoth-lib"
46 #define LOG_DP LOG_STREAM(info, log_display)
51 static std::pair
sort_default{ std::string{
"sort_2"}, sort_order::type::descending };
58 , recall_list_(recall_list)
71 LOG_DP <<
"size: " << units.size();
74 for(
const auto& u_ptr : units) {
75 LOG_DP <<
"\tunit[" << (idx++) <<
"]: " << u_ptr->id() <<
" name = '" << u_ptr->name() <<
"'";
81 static const inline std::string
maybe_inactive(
const std::string& str,
bool active)
95 }
else if(
level < 1) {
97 }
else if(
level == 1) {
98 return std::to_string(
level);
99 }
else if(
level == 2) {
108 std::stringstream str;
110 if(unit_recall_cost < 0) {
111 unit_recall_cost = team_recall_cost;
114 if(unit_recall_cost > team_recall_cost) {
116 }
else if(unit_recall_cost == team_recall_cost) {
117 str << unit_recall_cost;
118 }
else if(unit_recall_cost < team_recall_cost) {
133 int controlled_recruiters = 0;
136 ++controlled_recruiters;
140 std::stringstream
msg;
141 if(controlled_recruiters >= 2) {
144 msg <<
" (" << leader->name();
msg <<
")";
153 label& title = find_widget<label>(
"title",
true);
157 = find_widget<text_box>(
"filter_box",
false,
true);
161 listbox& list = find_widget<listbox>(
"recall_list");
171 find_widget<button>(
"rename"),
175 find_widget<button>(
"dismiss"),
179 find_widget<button>(
"show_help"),
192 wb_gold = whiteb->get_spent_gold_for(
team_.
side());
206 mods +=
"~BLIT(" +
overlay +
")";
214 column[
"tooltip"] =
_(
"This unit cannot be recalled because you will not have enough gold at this point in your plan.");
216 column[
"tooltip"] =
_(
"This unit cannot be recalled because you do not have enough gold.");
219 column[
"use_markup"] =
"true";
222 row_data.emplace(
"unit_image", column);
225 row_data.emplace(
"unit_type", column);
233 row_data.emplace(
"unit_recall_cost", column);
237 row_data.emplace(
"unit_name", column);
240 row_data.emplace(
"unit_level", column);
242 std::stringstream exp_str;
250 row_data.emplace(
"unit_experience", column);
256 if(
const auto* race =
unit->
race()) {
257 filter_text +=
" " + race->name(
unit->
gender()) +
" " + race->plural_name();
265 filter_text +=
" " + std::string(
"vvv");
270 traits += (traits.empty() ?
"" :
"\n") + trait;
271 filter_text +=
" " + trait;
277 row_data.emplace(
"unit_traits", column);
289 [
this](
const std::size_t
i) {
return recall_list_[
i]->type_name(); },
291 [
this](
const std::size_t
i) {
295 [
this](
const std::size_t
i) {
return recall_list_[
i]->experience(); },
296 [
this](
const std::size_t
i) {
309 listbox& list = find_widget<listbox>(
"recall_list");
318 std::string name = selected_unit.
name();
319 const std::string dialog_title(
_(
"Rename Unit"));
320 const std::string dialog_label(
_(
"Name:"));
322 if(gui2::dialogs::edit_text::execute(dialog_title, dialog_label, name)) {
323 selected_unit.
rename(name);
328 std::ostringstream filter_text;
329 filter_text << selected_unit.
type_name() <<
" " << name <<
" " << std::to_string(selected_unit.
level());
330 for(
const std::string& trait : selected_unit.
trait_names()) {
331 filter_text <<
" " << trait;
344 listbox& list = find_widget<listbox>(
"recall_list");
356 ?
_(
"Do you really want to dismiss him?")
357 :
_(
"Do you really want to dismiss her?"));
359 }
else if(u.
level() > 1) {
361 ?
_(
"Do you really want to dismiss him?")
362 :
_(
"Do you really want to dismiss her?"));
366 ?
_(
"Do you really want to dismiss him?")
367 :
_(
"Do you really want to dismiss her?"));
388 LOG_DP <<
"Dismissing a unit, side = " << u.
side() <<
", id = '" << u.
id() <<
"'";
389 LOG_DP <<
"That side's recall list:";
394 assert(dismissed_unit);
412 const int selected_row
413 = find_widget<listbox>(
"recall_list").get_selected_row();
415 if(selected_row == -1) {
421 find_widget<unit_preview_pane>(
"unit_details")
422 .set_display_data(selected_unit);
424 find_widget<button>(
"rename").set_active(!selected_unit.
unrenamable());
429 listbox& list = find_widget<listbox>(
"recall_list");
444 const std::size_t shown = find_widget<listbox>(
"recall_list")
450 find_widget<button>(
"rename").set_active(shown > 0);
451 find_widget<button>(
"dismiss").set_active(shown > 0);
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.
std::vector< std::string > filter_options_
virtual void pre_show() override
Actions to be taken before showing the window.
void list_item_clicked()
Callbacks.
void filter_text_changed(const std::string &text)
std::vector< unit_const_ptr > & recall_list_
virtual void post_show() override
Actions to be taken after the window has been shown.
widget * find(const std::string_view 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.
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 set_active_sorter(std::string_view id, sort_order::type order, bool select_first=false)
Sorts the listbox by a pre-set sorting option.
void set_sorters(Args &&... functors)
Registers sorting controls using magic index IDs.
std::pair< widget *, sort_order::type > get_active_sorter() const
Returns a widget pointer to the active sorter, along with its corresponding order.
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.
A widget that allows the user to input text in single line.
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, action_spectator &spectator=get_default_spectator())
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)
static std::string alignment_description(unit_alignments::type align, unit_race::GENDER gender=unit_race::MALE)
Implementation detail of unit_type::alignment_description.
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)
unit_alignments::type alignment() const
The alignment of this unit.
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.
const unit_race * race() const
Gets this unit's race.
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 log_scope2(domain, description)
const std::string unicode_en_dash
static std::string get_title_suffix(int side_num)
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 utils::optional< decltype(sort_default)> sort_last
REGISTER_DIALOG(editor_edit_unit)
static std::string format_cost_string(int unit_recall_cost, const int team_recall_cost)
static std::pair sort_default
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)
Open the help browser, show topic with id show_topic.
Functions to load and save images from/to disk.
std::string bold(Args &&... data)
std::string span_color(const color_t &color, Args &&... data)
play_controller * controller
auto make_ci_matcher(std::string_view filter_text)
Returns a function which performs locale-aware case-insensitive search.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
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
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")