16 #define GETTEXT_DOMAIN "wesnoth-editor"
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) {
126 palette_menu_button->set_tooltip_string(group.name);
127 palette_menu_button->set_overlay(group.icon);
135 if(active_group().empty()) {
136 ERR_ED <<
"No items found in group with the id: '" <<
id <<
"'.";
143 assert(groups_.size() >
index);
144 set_group(groups_[
index].
id);
150 assert(!active_group_.empty());
152 for (std::size_t
i = 0 ;
i < groups_.size();
i++) {
153 if (groups_[
i].
id == active_group_)
157 return static_cast<std::size_t
>(-1);
165 const int items_fitting =
static_cast<int>((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 +
static_cast<int>(
i % columns_) * item_space_;
188 dstrect.y = target.y +
static_cast<int>(
i / columns_) * item_space_;
189 buttons_[
i].set_location(dstrect);
192 set_location(target);
194 gui_.set_help_string(get_help_string());
200 if (selected_fg_item_ != item_id) {
201 selected_fg_item_ = item_id;
204 gui_.set_help_string(get_help_string());
210 if (selected_bg_item_ != item_id) {
211 selected_bg_item_ = item_id;
214 gui_.set_help_string(get_help_string());
220 std::swap(selected_fg_item_, selected_bg_item_);
221 select_fg_item(selected_fg_item_);
222 select_bg_item(selected_bg_item_);
229 return group_map_[active_group_].size();
236 widget::hide(hidden);
239 gui_.set_help_string(get_help_string());
241 gui_.clear_help_string();
253 return selected_fg_item_ ==
id;
259 return selected_bg_item_ ==
id;
269 toolkit_.set_mouseover_overlay(gui_);
271 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
272 if(palette_menu_button) {
273 t_string& name = groups_[active_group_index()].name;
274 std::string& icon = groups_[active_group_index()].icon;
276 palette_menu_button->set_tooltip_string(name);
277 palette_menu_button->set_overlay(icon);
282 std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button(
"upscroll-button-editor");
284 upscroll_button->enable(can_scroll_up());
285 std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button(
"downscroll-button-editor");
286 if(downscroll_button)
287 downscroll_button->enable(can_scroll_down());
289 for(std::size_t
i = 0;
i < buttons_.size(); ++
i) {
290 const auto item_index = items_start_ +
i;
296 if(item_index >= num_items()) {
300 const std::string item_id = active_group()[item_index];
304 texture item_base, item_overlay;
305 std::stringstream tooltip_text;
306 setup_item((*item).second, item_base, item_overlay, tooltip_text);
308 bool is_core = non_core_items_.find(get_id((*item).second)) == non_core_items_.end();
312 <<
_(
"(non-core)") <<
"\n"
313 <<
_(
"Will not work in game without extra care.")
332 if (is_selected_bg_item(get_id(
item->second))
333 && is_selected_fg_item(get_id(
item->second))) {
335 }
else if (is_selected_bg_item(get_id(
item->second))) {
337 }
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()
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.
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...
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
static void setup_item(const std::string &item, window &window)
std::pair< std::string, unsigned > item
const std::vector< std::string > items
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.