16 #define GETTEXT_DOMAIN "wesnoth-editor"
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);
167 const int items_fitting =
static_cast<int>((target.h / item_space_) * columns_);
176 if(items_fitting > 0) {
177 const auto buttons_needed =
static_cast<std::size_t
>(items_fitting);
178 if(buttons_.size() != buttons_needed) {
186 dstrect.w = item_size_ + 2;
187 dstrect.h = item_size_ + 2;
188 for(std::size_t
i = 0;
i < buttons_.size(); ++
i) {
189 dstrect.x = target.x +
static_cast<int>(
i % columns_) * item_space_;
190 dstrect.y = target.y +
static_cast<int>(
i / columns_) * item_space_;
191 buttons_[
i].set_location(dstrect);
194 set_location(target);
196 gui_.set_help_string(get_help_string());
202 if (selected_fg_item_ != item_id) {
203 selected_fg_item_ = item_id;
206 gui_.set_help_string(get_help_string());
212 if (selected_bg_item_ != item_id) {
213 selected_bg_item_ = item_id;
216 gui_.set_help_string(get_help_string());
222 std::swap(selected_fg_item_, selected_bg_item_);
223 select_fg_item(selected_fg_item_);
224 select_bg_item(selected_bg_item_);
231 return group_map_[active_group_].size();
238 widget::hide(hidden);
241 gui_.set_help_string(get_help_string());
243 gui_.clear_help_string();
255 return selected_fg_item_ ==
id;
261 return selected_bg_item_ ==
id;
271 toolkit_.set_mouseover_overlay(gui_);
273 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
274 if(palette_menu_button) {
275 t_string& name = groups_[active_group_index()].name;
276 std::string& icon = groups_[active_group_index()].icon;
278 palette_menu_button->set_tooltip_string(name);
279 palette_menu_button->set_overlay(icon);
284 std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button(
"upscroll-button-editor");
286 upscroll_button->enable(can_scroll_up());
287 std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button(
"downscroll-button-editor");
288 if(downscroll_button)
289 downscroll_button->enable(can_scroll_down());
291 for(std::size_t
i = 0;
i < buttons_.size(); ++
i) {
292 const auto item_index = items_start_ +
i;
298 if(item_index >= num_items()) {
302 const std::string item_id = active_group()[item_index];
306 texture item_base, item_overlay;
307 std::stringstream tooltip_text;
308 setup_item((*item).second, item_base, item_overlay, tooltip_text);
310 bool is_core = non_core_items_.find(get_id((*item).second)) == non_core_items_.end();
314 <<
_(
"(non-core)") <<
"\n"
315 <<
_(
"Will not work in game without extra care.")
334 if (is_selected_bg_item(get_id(
item->second))
335 && is_selected_fg_item(get_id(
item->second))) {
337 }
else if (is_selected_bg_item(get_id(
item->second))) {
339 }
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.