16 #define GETTEXT_DOMAIN "wesnoth-lib"
55 = find_widget<toggle_button>(
"male_toggle");
57 = find_widget<toggle_button>(
"female_toggle");
67 menu_button& var_box = find_widget<menu_button>(
"variation_box");
71 listbox& list = find_widget<listbox>(
"unit_type_list");
74 = find_widget<text_box>(
"filter_box",
false,
true);
96 column[
"label"] =
units_.back()->race()->plural_name();
97 row_data.emplace(
"race", column);
99 column[
"label"] =
units_.back()->type_name();
100 if(
units_.back()->type_name().str() !=
units_.back()->id()) {
101 column[
"label"] +=
" (" +
units_.back()->id() +
")";
103 row_data.emplace(
"unit_type", column);
114 ERR_GUI_G <<
"no unit types found for unit create dialog; not good"
129 listbox& list = find_widget<listbox>(
"unit_type_list");
138 if(selected_row < 0) {
140 }
else if(
static_cast<std::size_t
>(selected_row) >=
units_.size()) {
142 ERR_GUI_G <<
"unit create dialog has more list items than known unit "
154 const int selected_row
155 = find_widget<listbox>(
"unit_type_list").get_selected_row();
157 if(selected_row == -1) {
169 find_widget<unit_preview_pane>(
"unit_details").set_displayed_type(*ut);
174 const int selected_row
175 = find_widget<listbox>(
"unit_type_list").get_selected_row();
177 if(selected_row == -1) {
184 return units_[selected_row]->has_gender_variation(
gender);
187 menu_button& var_box = find_widget<menu_button>(
"variation_box");
188 std::vector<config> var_box_values;
189 var_box_values.emplace_back(
"label",
_(
"unit_variation^Default Variation"),
"variation_id",
"");
191 const auto& ut = *
units_[selected_row];
192 const auto& uvars = ut.variation_types();
196 unsigned n = 0, selection = 0;
198 for(
const auto& pair : uvars) {
201 const std::string& uv_id = pair.first;
204 std::string uv_label;
208 uv_label = uv.
type_name() +
" (" + uv_id +
")";
213 var_box_values.emplace_back(
"label", uv_label,
"variation_id", uv_id);
226 var_box.
set_values(var_box_values, selection);
231 listbox& list = find_widget<listbox>(
"unit_type_list");
233 const std::vector<std::string> words =
utils::split(text,
' ');
239 boost::dynamic_bitset<> show_items;
251 const std::string& unit_type_id =
units_[
i] ?
units_[
i]->id() :
"";
254 for(
const auto & word : words)
266 show_items[
i] = found;
282 menu_button& var_box = find_widget<menu_button>(
"variation_box");
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.
unit_race::GENDER gender_
group< unit_race::GENDER > gender_toggle
unit_race::GENDER gender()
Gender choice from the user.
std::vector< std::string > last_words_
void list_item_clicked()
Callbacks.
void variation_menu_callback()
void filter_text_changed(const std::string &text)
virtual void post_show() override
Actions to be taken after the window has been shown.
void update_displayed_type()
void gender_toggle_callback(const unit_race::GENDER val)
std::vector< const unit_type * > units_
void add_member(selectable_item *w, const T &value)
Adds a widget/value pair to the group map.
void set_member_states(const T &value)
Sets the toggle values for all widgets besides the one associated with the specified value to false.
void set_callback_on_value_change(std::function< void(widget &, const T)> func)
Sets a common callback function for all members.
void set_members_enabled(std::function< bool(const T &)> predicate)
Wrapper for enabling or disabling member widgets.
bool select_last_row(const bool select=true)
Does exactly as advertised: selects the list's last row.
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.
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.
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.
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.
const std::string & str() const
void build_unit_type(const unit_type &ut, unit_type::BUILD_STATUS status) const
Makes sure the provided unit_type is built to the specified level.
const unit_type_map & types() const
A single unit type that the player may recruit.
const unit_type & get_variation(const std::string &id) const
const t_string & variation_name() const
const t_string & type_name() const
The name of the unit in the current language setting.
static std::string _(const char *str)
Define the common log macros for the gui toolkit.
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.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
@ OK
Dialog was closed with the OK button.
bool ci_search(const std::string &s1, const std::string &s2)
std::vector< std::string > split(const config_attribute_value &val)
static map_location::direction n
unit_type_data unit_types
static unit_race::GENDER last_gender
static std::string last_chosen_type_id
static std::string last_variation