16 #define GETTEXT_DOMAIN "wesnoth-editor" 44 auto pos = items.erase(items.begin() +
i);
46 std::vector<config> groups;
47 const std::vector<item_group>& item_groups = get_groups();
49 for (std::size_t mci = 0; mci < item_groups.size(); ++mci) {
50 std::string groupname = item_groups[mci].name;
51 if (groupname.empty()) {
52 groupname =
_(
"(Unknown Group)");
54 std::string img = item_groups[mci].icon +
"_30";
55 if (mci == active_group_index()) {
56 std::string pressed_img = img +
"-pressed.png";
60 img +=
".png~CS(70,70,0)";
72 items.insert(pos, groups.begin(), groups.end());
78 bool scrolled =
false;
81 if(items_start_ < columns_) {
84 items_start_ -= columns_;
95 return (items_start_ != 0);
101 return (items_start_ + buttons_.size() < num_items());
107 bool scrolled =
false;
108 if(can_scroll_down()) {
109 items_start_ += columns_;
123 if (group.id ==
id) {
125 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
126 if (palette_menu_button) {
128 palette_menu_button->set_tooltip_string(group.name);
129 palette_menu_button->set_overlay(group.icon);
137 if(active_group().empty()) {
138 ERR_ED <<
"No items found in group with the id: '" <<
id <<
"'.";
145 assert(groups_.size() >
index);
146 set_group(groups_[index].
id);
152 assert(!active_group_.empty());
154 for (std::size_t
i = 0 ;
i < groups_.size();
i++) {
155 if (groups_[
i].
id == active_group_)
159 return static_cast<std::size_t
>(-1);
165 const int items_fitting = (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 + (
i % columns_) * item_space_;
187 dstrect.y = target.y + (
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];
303 texture item_base, item_overlay;
304 std::stringstream tooltip_text;
305 setup_item((*item).second, item_base, item_overlay, tooltip_text);
307 bool is_core = non_core_items_.find(get_id((*item).second)) == non_core_items_.end();
311 <<
_(
"(non-core)") <<
"\n" 312 <<
_(
"Will not work in game without extra care.")
331 if (is_selected_bg_item(get_id(item->second))
332 && is_selected_fg_item(get_id(item->second))) {
334 }
else if (is_selected_bg_item(get_id(item->second))) {
336 }
else if (is_selected_fg_item(get_id(item->second))) {
std::vector< events::sdl_handler * > sdl_handler_vector
virtual sdl_handler_vector handler_members() override
virtual void select_fg_item(const std::string &item_id) override
Select a foreground item.
Stores the info about the groups in a nice format.
virtual void select_bg_item(const std::string &item_id) override
std::size_t active_group_index()
virtual bool scroll_down() override
Scroll the editor-palette down one step if possible.
void set_group(std::size_t index) override
virtual bool scroll_up() override
Scroll the editor-palette up one step if possible.
const std::vector< std::string > items
virtual bool is_selected_bg_item(const std::string &id)
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 or an empty string if the file isn't prese...
static std::string _(const char *str)
virtual bool can_scroll_up() override
void expand_palette_groups_menu(std::vector< config > &items, int i) override
Menu expanding for palette group list.
Wrapper class to encapsulate creation and management of an SDL_Texture.
virtual bool is_selected_fg_item(const std::string &id)
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
virtual bool can_scroll_down() override
virtual void layout() override
Called by draw_manager to validate layout before drawing.
Manage the empty-palette in the editor.
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
std::string id
Text to match against addon_info.tags()
std::size_t num_items() override
Return the number of items in the currently-active group.
Declarations for File-IO.
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.
static void setup_item(const std::string &item, window &window)
virtual void draw_contents() override
Called by widget::draw()
void adjust_size(const SDL_Rect &target) override
Update the size of this widget.
void hide(bool hidden) override
std::string::const_iterator iterator
std::pair< std::string, unsigned > item