15 #define GETTEXT_DOMAIN "wesnoth-editor" 43 auto pos = items.erase(items.begin() +
i);
45 std::vector<config> groups;
46 const std::vector<item_group>& item_groups = get_groups();
48 for (std::size_t mci = 0; mci < item_groups.size(); ++mci) {
49 std::string groupname = item_groups[mci].name;
50 if (groupname.empty()) {
51 groupname =
_(
"(Unknown Group)");
53 std::string img = item_groups[mci].icon +
"_30";
54 if (mci == active_group_index()) {
55 std::string pressed_img = img +
"-pressed.png";
59 img +=
".png~CS(70,70,0)";
71 items.insert(pos, groups.begin(), groups.end());
77 int decrement = item_width_;
78 if (items_start_ + num_visible_items() == num_items() && num_items() % item_width_ != 0) {
79 decrement = num_items() % item_width_;
81 if(items_start_ >= decrement) {
82 items_start_ -= decrement;
92 return (items_start_ != 0);
98 return (items_start_ + nitems_ + item_width_ <= num_items());
104 bool end_reached = (!(items_start_ + nitems_ + item_width_ <= num_items()));
105 bool scrolled =
false;
109 items_start_ += item_width_;
112 else if (items_start_ + nitems_ + (num_items() % item_width_) <= num_items()) {
113 items_start_ += num_items() % item_width_;
128 if (group.id ==
id) {
130 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
131 if (palette_menu_button) {
133 palette_menu_button->set_tooltip_string(group.name);
134 palette_menu_button->set_overlay(group.icon);
142 if(active_group().empty()) {
143 ERR_ED <<
"No items found in group with the id: '" <<
id <<
"'." << std::endl;
150 assert(groups_.size() >
index);
151 set_group(groups_[index].
id);
157 assert(!active_group_.empty());
159 for (std::size_t
i = 0 ;
i < groups_.size();
i++) {
160 if (groups_[
i].
id == active_group_)
164 return static_cast<std::size_t
>(-1);
170 palette_x_ = target.x;
171 palette_y_ = target.y;
172 const int space_for_items = target.h;
173 const int items_fitting = (space_for_items / item_space_) * item_width_;
174 nitems_ = std::min(items_fitting, nmax_items_);
175 if (num_visible_items() != nitems_) {
178 set_location(target);
180 gui_.video().clear_help_string(help_handle_);
181 help_handle_ = gui_.video().set_help_string(get_help_string());
187 if (selected_fg_item_ != item_id) {
188 selected_fg_item_ = item_id;
191 gui_.video().clear_help_string(help_handle_);
192 help_handle_ = gui_.video().set_help_string(get_help_string());
198 if (selected_bg_item_ != item_id) {
199 selected_bg_item_ = item_id;
202 gui_.video().clear_help_string(help_handle_);
203 help_handle_ = gui_.video().set_help_string(get_help_string());
209 std::swap(selected_fg_item_, selected_bg_item_);
210 select_fg_item(selected_fg_item_);
211 select_bg_item(selected_bg_item_);
218 return group_map_[active_group_].size();
224 return selected_fg_item_ == id;
230 return selected_bg_item_ == id;
236 toolkit_.set_mouseover_overlay(gui_);
238 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
239 if (palette_menu_button) {
242 std::string& icon = groups_[active_group_index()].icon;
244 palette_menu_button->set_tooltip_string(name);
245 palette_menu_button->set_overlay(icon);
248 unsigned int y = palette_y_;
249 unsigned int x = palette_x_;
250 int starting = items_start_;
251 int ending = std::min<int>(starting + nitems_, num_items());
253 std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button(
"upscroll-button-editor");
255 upscroll_button->enable(starting != 0);
256 std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button(
"downscroll-button-editor");
257 if (downscroll_button)
258 downscroll_button->enable(ending != num_items());
261 int counter = starting;
262 for (
int i = 0,
size = num_visible_items();
i <
size ; ++
i) {
270 if (
i >= ending)
continue;
272 const std::string item_id = active_group()[counter];
277 std::stringstream tooltip_text;
278 draw_item((*item).second, item_image, tooltip_text);
280 bool is_core = non_core_items_.find(
get_id((*item).second)) == non_core_items_.end();
284 <<
_(
"(non-core)") <<
"\n" 285 <<
_(
"Will not work in game without extra care.")
289 const int counter_from_zero = counter - starting;
291 dstrect.x = x + (counter_from_zero % item_width_) * item_space_;
293 dstrect.w = item_size_ + 2;
294 dstrect.h = item_size_ + 2;
312 if (is_selected_bg_item(
get_id(item->second))
313 && is_selected_fg_item(
get_id(item->second))) {
315 }
else if (is_selected_bg_item(
get_id(item->second))) {
317 }
else if (is_selected_fg_item(
get_id(item->second))) {
328 if (counter_from_zero % item_width_ == item_width_ - 1)
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.
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...
const std::vector< std::string > items
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.
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.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
int num_items() override
Return the number of items in the palette.
virtual bool can_scroll_down() override
Manage the empty-palette in the editor.
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
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.
virtual void draw_contents() override
void adjust_size(const SDL_Rect &target) override
Update the size of this widget.
std::string::const_iterator iterator
HOTKEY_COMMAND get_id(const std::string &command)
returns get_hotkey_command(command).id
std::pair< std::string, unsigned > item