16 #define GETTEXT_DOMAIN "wesnoth-editor"
42 auto pos = items.erase(items.begin() +
i);
44 std::vector<config> groups;
45 const std::vector<item_group>& item_groups = get_groups();
47 for (std::size_t mci = 0; mci < item_groups.size(); ++mci) {
48 std::string groupname = item_groups[mci].name;
49 if (groupname.empty()) {
50 groupname =
_(
"(Unknown Group)");
52 std::string
img = item_groups[mci].icon +
"_30";
53 if (mci == active_group_index()) {
54 std::string pressed_img =
img +
"-pressed.png";
58 img +=
".png~CS(70,70,0)";
70 items.insert(pos, groups.begin(), groups.end());
76 bool scrolled =
false;
79 if(items_start_ < columns_) {
82 items_start_ -= columns_;
93 return (items_start_ != 0);
99 return (items_start_ + buttons_.size() < num_items());
105 bool scrolled =
false;
106 if(can_scroll_down()) {
107 items_start_ += columns_;
121 if (group.id ==
id) {
123 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
124 if (palette_menu_button) {
125 palette_menu_button->set_tooltip_string(group.name);
126 palette_menu_button->set_overlay(group.icon);
134 if(active_group().empty()) {
135 ERR_ED <<
"No items found in group with the id: '" <<
id <<
"'.";
142 assert(groups_.size() >
index);
143 set_group(groups_[
index].
id);
149 assert(!active_group_.empty());
151 for (std::size_t
i = 0 ;
i < groups_.size();
i++) {
152 if (groups_[
i].
id == active_group_)
156 return static_cast<std::size_t
>(-1);
164 const int items_fitting =
static_cast<int>((target.h / item_space_) * columns_);
173 if(items_fitting > 0) {
174 const auto buttons_needed =
static_cast<std::size_t
>(items_fitting);
175 if(buttons_.size() != buttons_needed) {
183 dstrect.w = item_size_ + 2;
184 dstrect.h = item_size_ + 2;
185 for(std::size_t
i = 0;
i < buttons_.size(); ++
i) {
186 dstrect.x = target.x +
static_cast<int>(
i % columns_) * item_space_;
187 dstrect.y = target.y +
static_cast<int>(
i / columns_) * item_space_;
188 buttons_[
i].set_location(dstrect);
191 set_location(target);
193 gui_.set_help_string(get_help_string());
199 if (selected_fg_item_ != item_id) {
200 selected_fg_item_ = item_id;
203 gui_.set_help_string(get_help_string());
209 if (selected_bg_item_ != item_id) {
210 selected_bg_item_ = item_id;
213 gui_.set_help_string(get_help_string());
219 std::swap(selected_fg_item_, selected_bg_item_);
220 select_fg_item(selected_fg_item_);
221 select_bg_item(selected_bg_item_);
228 return group_map_[active_group_].size();
235 widget::hide(hidden);
238 gui_.set_help_string(get_help_string());
240 gui_.clear_help_string();
252 return selected_fg_item_ ==
id;
258 return selected_bg_item_ ==
id;
268 toolkit_.set_mouseover_overlay(gui_);
270 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
271 if(palette_menu_button) {
272 t_string& name = groups_[active_group_index()].name;
273 std::string& icon = groups_[active_group_index()].icon;
275 palette_menu_button->set_tooltip_string(name);
276 palette_menu_button->set_overlay(icon);
281 std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button(
"upscroll-button-editor");
283 upscroll_button->enable(can_scroll_up());
284 std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button(
"downscroll-button-editor");
285 if(downscroll_button)
286 downscroll_button->enable(can_scroll_down());
288 for(std::size_t
i = 0;
i < buttons_.size(); ++
i) {
289 const auto item_index = items_start_ +
i;
295 if(item_index >= num_items()) {
299 const std::string item_id = active_group()[item_index];
302 texture item_base, item_overlay;
303 std::stringstream tooltip_text;
304 setup_item((*item).second, item_base, item_overlay, tooltip_text);
305 bool is_core = non_core_items_.find(get_id((*item).second)) == non_core_items_.end();
308 <<
_(
"(non-core)") <<
"\n"
309 <<
_(
"Will not work in game without extra care.");
318 if (is_selected_bg_item(get_id(item->second))
319 && is_selected_fg_item(get_id(item->second))) {
321 }
else if (is_selected_bg_item(get_id(item->second))) {
323 }
else if (is_selected_fg_item(get_id(item->second))) {
void adjust_size(const SDL_Rect &target) override
Update the size of this widget.
virtual bool scroll_up() override
Scroll the editor-palette up one step if possible.
virtual void select_bg_item(const std::string &item_id) override
virtual bool is_selected_bg_item(const std::string &id)
std::size_t num_items() override
Return the number of items in the currently-active group.
virtual bool is_selected_fg_item(const std::string &id)
std::size_t active_group_index()
virtual void draw_contents() override
Called by widget::draw()
void swap() override
For tools which support fg and bg items, exchange the two items.
virtual bool scroll_down() override
Scroll the editor-palette down one step if possible.
virtual bool can_scroll_up() override
virtual void select_fg_item(const std::string &item_id) override
Select a foreground item.
virtual void layout() override
Called by draw_manager to validate layout before drawing.
virtual bool can_scroll_down() override
void hide(bool hidden) override
void expand_palette_groups_menu(std::vector< config > &items, int i) override
Menu expanding for palette group list.
void set_group(std::size_t index) override
virtual sdl_handler_vector handler_members() override
Wrapper class to encapsulate creation and management of an SDL_Texture.
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
std::vector< events::sdl_handler * > sdl_handler_vector
Declarations for File-IO.
static std::string _(const char *str)
std::string id
Text to match against addon_info.tags()
Manage the empty-palette in the editor.
utils::optional< std::string > get_binary_file_location(const std::string &type, const std::string &filename)
Returns a complete path to the actual file of a given type, if it exists.
std::string img(const std::string &src, const std::string &align, const bool floating)
std::string span_color(const color_t &color, Args &&... data)
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::string::const_iterator iterator
Stores the info about the groups in a nice format.