16 #define GETTEXT_DOMAIN "wesnoth-editor"
42 const std::vector<item_group>& item_groups = get_groups();
44 for (std::size_t mci = 0; mci < item_groups.size(); ++mci) {
45 std::string groupname = item_groups[mci].name;
46 if (groupname.empty()) {
47 groupname =
_(
"(Unknown Group)");
49 std::string
img = item_groups[mci].icon +
"_30";
50 if (mci == active_group_index()) {
51 std::string pressed_img =
img +
"-pressed.png";
55 img +=
".png~CS(70,70,0)";
61 items.emplace_back(
"label", groupname,
"icon",
img);
68 bool scrolled =
false;
71 if(items_start_ < columns_) {
74 items_start_ -= columns_;
85 return (items_start_ != 0);
91 return (items_start_ + buttons_.size() < num_items());
97 bool scrolled =
false;
98 if(can_scroll_down()) {
99 items_start_ += columns_;
113 if (group.id ==
id) {
115 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
116 if (palette_menu_button) {
117 palette_menu_button->set_tooltip_string(group.name);
118 palette_menu_button->set_overlay(group.icon);
126 if(active_group().empty()) {
127 ERR_ED <<
"No items found in group with the id: '" <<
id <<
"'.";
141 assert(!active_group_.empty());
143 for (std::size_t
i = 0 ;
i < groups_.size();
i++) {
144 if (groups_[
i].
id == active_group_)
148 return static_cast<std::size_t
>(-1);
156 const int items_fitting =
static_cast<int>((target.h / item_space_) * columns_);
165 if(items_fitting > 0) {
166 const auto buttons_needed =
static_cast<std::size_t
>(items_fitting);
167 if(buttons_.size() != buttons_needed) {
175 dstrect.w = item_size_ + 2;
176 dstrect.h = item_size_ + 2;
177 for(std::size_t
i = 0;
i < buttons_.size(); ++
i) {
178 dstrect.x = target.x +
static_cast<int>(
i % columns_) * item_space_;
179 dstrect.y = target.y +
static_cast<int>(
i / columns_) * item_space_;
180 buttons_[
i].set_location(dstrect);
183 set_location(target);
185 gui_.set_help_string(get_help_string());
191 if (selected_fg_item_ != item_id) {
192 selected_fg_item_ = item_id;
195 gui_.set_help_string(get_help_string());
201 if (selected_bg_item_ != item_id) {
202 selected_bg_item_ = item_id;
205 gui_.set_help_string(get_help_string());
211 std::swap(selected_fg_item_, selected_bg_item_);
212 select_fg_item(selected_fg_item_);
213 select_bg_item(selected_bg_item_);
220 return group_map_[active_group_].size();
230 gui_.set_help_string(get_help_string());
232 gui_.clear_help_string();
244 return selected_fg_item_ ==
id;
250 return selected_bg_item_ ==
id;
260 toolkit_.set_mouseover_overlay(gui_);
262 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
263 if(palette_menu_button) {
264 t_string& name = groups_[active_group_index()].name;
265 std::string& icon = groups_[active_group_index()].icon;
267 palette_menu_button->set_tooltip_string(name);
268 palette_menu_button->set_overlay(icon);
273 std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button(
"upscroll-button-editor");
275 upscroll_button->enable(can_scroll_up());
276 std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button(
"downscroll-button-editor");
277 if(downscroll_button)
278 downscroll_button->enable(can_scroll_down());
280 for(std::size_t
i = 0;
i < buttons_.size(); ++
i) {
281 const auto item_index = items_start_ +
i;
287 if(item_index >= num_items()) {
291 const std::string item_id = active_group()[item_index];
294 texture item_base, item_overlay;
295 std::stringstream tooltip_text;
296 setup_item((*item).second, item_base, item_overlay, tooltip_text);
297 bool is_core = non_core_items_.find(get_id((*item).second)) == non_core_items_.end();
300 <<
_(
"(non-core)") <<
"\n"
301 <<
_(
"Will not work in game without extra care.");
310 if (is_selected_bg_item(get_id(item->second))
311 && is_selected_fg_item(get_id(item->second))) {
313 }
else if (is_selected_bg_item(get_id(item->second))) {
315 }
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) 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.
void hide()
Hides the fps report popup.
std::string img(const std::string &src, const std::string &align, bool floating)
Generates a Help markup tag corresponding to an image.
std::string span_color(const color_t &color, Args &&... data)
Applies Pango markup to the input specifying its display color.
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.
std::string::const_iterator iterator
Stores the info about the groups in a nice format.