16 #define GETTEXT_DOMAIN "wesnoth-lib"
39 #include <boost/dynamic_bitset.hpp>
62 = find_widget<toggle_button>(&
window,
"male_toggle",
false);
64 = find_widget<toggle_button>(&
window,
"female_toggle",
false);
78 listbox& list = find_widget<listbox>(&
window,
"unit_type_list",
false);
81 = find_widget<text_box>(&
window,
"filter_box",
false,
true);
103 column[
"label"] =
units_.back()->race()->plural_name();
104 row_data.emplace(
"race", column);
106 column[
"label"] =
units_.back()->type_name();
107 if(
units_.back()->type_name().str() !=
units_.back()->id()) {
108 column[
"label"] +=
" (" +
units_.back()->id() +
")";
110 row_data.emplace(
"unit_type", column);
121 ERR_GUI_G <<
"no unit types found for unit create dialog; not good"
136 listbox& list = find_widget<listbox>(&
window,
"unit_type_list",
false);
145 if(selected_row < 0) {
147 }
else if(
static_cast<std::size_t
>(selected_row) >=
units_.size()) {
149 ERR_GUI_G <<
"unit create dialog has more list items than known unit "
161 const int selected_row
162 = find_widget<listbox>(
this,
"unit_type_list",
false).get_selected_row();
164 if(selected_row == -1) {
176 find_widget<unit_preview_pane>(
this,
"unit_details",
false).set_displayed_type(*ut);
181 const int selected_row
182 = find_widget<listbox>(
this,
"unit_type_list",
false).get_selected_row();
184 if(selected_row == -1) {
191 return units_[selected_row]->has_gender_variation(
gender);
194 menu_button& var_box = find_widget<menu_button>(
this,
"variation_box",
false);
195 std::vector<config> var_box_values;
196 var_box_values.emplace_back(
"label",
_(
"unit_variation^Default Variation"),
"variation_id",
"");
198 const auto& ut = *
units_[selected_row];
199 const auto& uvars = ut.variation_types();
203 unsigned n = 0, selection = 0;
205 for(
const auto& pair : uvars) {
208 const std::string& uv_id = pair.first;
211 std::string uv_label;
215 uv_label = uv.
type_name() +
" (" + uv_id +
")";
220 var_box_values.emplace_back(
"label", uv_label,
"variation_id", uv_id);
233 var_box.
set_values(var_box_values, selection);
238 listbox& list = find_widget<listbox>(
this,
"unit_type_list",
false);
240 const std::vector<std::string> words =
utils::split(text,
' ');
246 boost::dynamic_bitset<> show_items;
255 = find_widget<label>(*it,
"unit_type",
false);
257 = find_widget<label>(*it,
"race",
false);
260 const std::string& unit_type_id =
units_[
i] ?
units_[
i]->id() :
"";
263 for(
const auto & word : words)
275 show_items[
i] = found;
291 menu_button& var_box = find_widget<menu_button>(
this,
"variation_box",
false);
Abstract base class for all modal dialogs.
int get_retval() const
Returns the cached window exit code.
This shows the debug-mode dialog to create new units on the map.
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
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()
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
void filter_text_changed(const std::string &text)
void update_displayed_type()
void gender_toggle_callback(const unit_race::GENDER val)
std::vector< const unit_type * > units_
Iterator for the child items.
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.
A label displays text that can be wrapped but no scrollbars are provided.
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.
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 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.
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
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)
This file contains the settings handling of the widget library.
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