16 #define GETTEXT_DOMAIN "wesnoth-editor" 45 auto pos = items.erase(items.begin() +
i);
47 std::vector<config> groups;
48 const std::vector<item_group>& item_groups = get_groups();
50 for (std::size_t mci = 0; mci < item_groups.size(); ++mci) {
51 std::string groupname = item_groups[mci].name;
52 if (groupname.empty()) {
53 groupname =
_(
"(Unknown Group)");
55 std::string img = item_groups[mci].icon +
"_30";
56 if (mci == active_group_index()) {
57 std::string pressed_img = img +
"-pressed.png";
61 img +=
".png~CS(70,70,0)";
73 items.insert(pos, groups.begin(), groups.end());
79 bool scrolled =
false;
82 if(items_start_ < columns_) {
85 items_start_ -= columns_;
96 return (items_start_ != 0);
102 return (items_start_ + buttons_.size() < num_items());
108 bool scrolled =
false;
109 if(can_scroll_down()) {
110 items_start_ += columns_;
124 if (group.id ==
id) {
126 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
127 if (palette_menu_button) {
129 palette_menu_button->set_tooltip_string(group.name);
130 palette_menu_button->set_overlay(group.icon);
138 if(active_group().empty()) {
139 ERR_ED <<
"No items found in group with the id: '" <<
id <<
"'.";
146 assert(groups_.size() >
index);
147 set_group(groups_[index].
id);
153 assert(!active_group_.empty());
155 for (std::size_t
i = 0 ;
i < groups_.size();
i++) {
156 if (groups_[
i].
id == active_group_)
160 return static_cast<std::size_t
>(-1);
166 const int items_fitting = (target.h / item_space_) * columns_;
174 if(items_fitting > 0) {
175 const auto buttons_needed =
static_cast<std::size_t
>(items_fitting);
176 if(buttons_.size() != buttons_needed) {
184 dstrect.w = item_size_ + 2;
185 dstrect.h = item_size_ + 2;
186 for(std::size_t
i = 0;
i < buttons_.size(); ++
i) {
187 dstrect.x = target.x + (
i % columns_) * item_space_;
188 dstrect.y = target.y + (
i / columns_) * item_space_;
189 buttons_[
i].set_location(dstrect);
192 set_location(target);
201 if (selected_fg_item_ != item_id) {
202 selected_fg_item_ = item_id;
212 if (selected_bg_item_ != item_id) {
213 selected_bg_item_ = item_id;
223 std::swap(selected_fg_item_, selected_bg_item_);
224 select_fg_item(selected_fg_item_);
225 select_bg_item(selected_bg_item_);
232 return group_map_[active_group_].size();
239 widget::hide(hidden);
256 return selected_fg_item_ ==
id;
262 return selected_bg_item_ ==
id;
272 toolkit_.set_mouseover_overlay(gui_);
274 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
275 if(palette_menu_button) {
276 t_string& name = groups_[active_group_index()].name;
277 std::string& icon = groups_[active_group_index()].icon;
279 palette_menu_button->set_tooltip_string(name);
280 palette_menu_button->set_overlay(icon);
285 std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button(
"upscroll-button-editor");
287 upscroll_button->enable(can_scroll_up());
288 std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button(
"downscroll-button-editor");
289 if(downscroll_button)
290 downscroll_button->enable(can_scroll_down());
292 for(std::size_t
i = 0;
i < buttons_.size(); ++
i) {
293 const auto item_index = items_start_ +
i;
299 if(item_index >= num_items()) {
303 const std::string item_id = active_group()[item_index];
307 texture item_base, item_overlay;
308 std::stringstream tooltip_text;
309 setup_item((*item).second, item_base, item_overlay, tooltip_text);
311 bool is_core = non_core_items_.find(get_id((*item).second)) == non_core_items_.end();
315 <<
_(
"(non-core)") <<
"\n" 316 <<
_(
"Will not work in game without extra care.")
335 if (is_selected_bg_item(get_id(item->second))
336 && is_selected_fg_item(get_id(item->second))) {
338 }
else if (is_selected_bg_item(get_id(item->second))) {
340 }
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 set_help_string(const std::string &str)
Displays a help string with the given text.
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.
void clear_help_string()
Removes the help string.
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