15 #define GETTEXT_DOMAIN "wesnoth-lib"
40 , recruit_map_(recruit_map)
44 for(
const auto& pair : recruit_map) {
45 recruit_list_.push_back(pair.first);
48 std::sort(recruit_list_.begin(), recruit_list_.end(), [](
const unit_type* t1,
const unit_type* t2) {
49 return t1->type_name().str() < t2->type_name().str();
64 listbox& list = find_widget<listbox>(
"recruit_list");
66 const std::vector<std::string> words =
utils::split(text,
' ');
72 boost::dynamic_bitset<> show_items;
81 auto default_gender = !
type->genders().empty()
83 const auto* race =
type->race();
87 auto criteria = std::make_tuple(
90 std::to_string(
type->level()),
92 (race ? race->name(default_gender) :
""),
93 (race ? race->plural_name() :
"")
97 for(
const auto & word : words)
101 std::apply([&](
auto&&... criterion) {
111 show_items[
i] = found;
120 text_box* filter = find_widget<text_box>(
"filter_box",
false,
true);
124 listbox& list = find_widget<listbox>(
"recruit_list");
132 find_widget<button>(
"show_help"),
141 std::string image_string = recruit->image() +
"~RC(" + recruit->flag_rgb() +
">"
144 const bool is_recruitable = error.
empty();
146 const std::string cost_string = std::to_string(recruit->cost());
148 column[
"use_markup"] =
"true";
151 column[
"tooltip"] = error;
154 column[
"label"] = image_string + (is_recruitable ?
"" :
"~GS()");
155 row_data.emplace(
"unit_image", column);
158 row_data.emplace(
"unit_type", column);
161 row_data.emplace(
"unit_cost", column);
164 if(!is_recruitable) {
176 const int selected_row
177 = find_widget<listbox>(
"recruit_list").get_selected_row();
179 if(selected_row == -1) {
183 find_widget<unit_preview_pane>(
"recruit_details")
Abstract base class for all modal dialogs.
int get_retval() const
Returns the cached window exit code.
virtual void pre_show() override
Actions to be taken before showing the window.
virtual void post_show() override
Actions to be taken after the window has been shown.
std::map< const unit_type *, t_string > & recruit_map_
void filter_text_changed(const std::string &text)
std::vector< std::string > last_words_
std::vector< const unit_type * > recruit_list_
A vector of unit types in the order listed in the UI.
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.
void set_row_shown(const unsigned row, const bool shown)
Makes a row visible or invisible.
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.
unsigned get_item_count() const
Returns the number of items in the listbox.
void set_text_changed_callback(std::function< void(text_box_base *textbox, const std::string text)> cb)
Set the text_changed callback.
A widget that allows the user to input text in single line.
void keyboard_capture(widget *widget)
void add_to_keyboard_chain(widget *widget)
Adds the widget to the keyboard chain.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
This class stores all the data for a single 'side' (in game nomenclature).
const std::string & color() const
A single unit type that the player may recruit.
static std::string alignment_description(unit_alignments::type align, unit_race::GENDER gender=unit_race::MALE)
Implementation detail of unit_type::alignment_description.
static std::string gray_if_unrecruitable(const std::string &text, const bool is_recruitable)
static const color_t inactive_row_color(0x96, 0x96, 0x96)
REGISTER_DIALOG(editor_edit_unit)
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
@ OK
Dialog was closed with the OK 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 span_color(const color_t &color, Args &&... data)
bool ci_search(const std::string &s1, const std::string &s2)
std::vector< std::string > split(const config_attribute_value &val)
The basic class for representing 8-bit RGB or RGBA colour values.