15 #define GETTEXT_DOMAIN "wesnoth-editor"
48 for (
unsigned int i = 0;
i < items.size(); ++
i) {
49 if (items[
i] ==
"editor-palette-groups") {
50 items.erase(items.begin() +
i);
52 std::vector<std::string>
groups;
53 const std::vector<item_group>& item_groups = get_groups();
55 for (
size_t mci = 0; mci < item_groups.size(); ++mci) {
57 if (groupname.empty()) {
58 groupname =
_(
"(Unknown Group)");
60 std::stringstream str;
62 if (mci == active_group_index()) {
65 str <<
"_30-pressed.png";
67 str <<
"_30.png~CS(70,70,0)";
74 groups.push_back(str.str());
78 items.insert(items.begin() +
i, groups.begin(), groups.end());
90 int decrement = item_width_;
91 if (items_start_ + num_visible_items() == num_items() && num_items() % item_width_ != 0) {
92 decrement = num_items() % item_width_;
94 if(items_start_ >= decrement) {
95 items_start_ -= decrement;
108 const std::vector<item_group>& item_groups = get_groups();
110 for (
size_t mci = 0; mci < item_groups.size(); ++mci) {
112 if (groupname.empty()) {
113 groupname =
_(
"(Unknown Group)");
116 items.push_back(std::pair<std::string, std::string>( img, groupname));
126 return (items_start_ != 0);
135 return (items_start_ + nitems_ + item_width_ <= num_items());
144 bool end_reached = (!(items_start_ + nitems_ + item_width_ <= num_items()));
145 bool scrolled =
false;
149 items_start_ += item_width_;
152 else if (items_start_ + nitems_ + (num_items() % item_width_) <= num_items()) {
153 items_start_ += num_items() % item_width_;
171 if (
group.id ==
id) {
173 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
174 if (palette_menu_button) {
176 palette_menu_button->set_tooltip_string(
group.name);
177 palette_menu_button->set_overlay(
group.icon);
185 if(active_group().empty()) {
186 ERR_ED <<
"No items found in group with the id: '" <<
id <<
"'." << std::endl;
196 assert(groups_.size() >
index);
197 set_group(groups_[index].
id);
206 assert(!active_group_.empty());
208 for (
size_t i = 0 ;
i < groups_.size();
i++) {
209 if (groups_[
i].
id == active_group_)
213 return static_cast<size_t>(-1);
222 palette_x_ = target.x;
223 palette_y_ = target.y;
224 const int space_for_items = target.h;
225 const int items_fitting = (space_for_items / item_space_) * item_width_;
226 nitems_ = std::min(items_fitting, nmax_items_);
227 if (num_visible_items() != nitems_) {
230 set_location(target);
232 gui_.video().clear_help_string(help_handle_);
233 help_handle_ = gui_.video().set_help_string(get_help_string());
242 if (selected_fg_item_ != item_id) {
243 selected_fg_item_ = item_id;
246 gui_.video().clear_help_string(help_handle_);
247 help_handle_ = gui_.video().set_help_string(get_help_string());
256 if (selected_bg_item_ != item_id) {
257 selected_bg_item_ = item_id;
260 gui_.video().clear_help_string(help_handle_);
261 help_handle_ = gui_.video().set_help_string(get_help_string());
270 std::swap(selected_fg_item_, selected_bg_item_);
271 select_fg_item(selected_fg_item_);
272 select_bg_item(selected_bg_item_);
282 return group_map_[active_group_].size();
291 return selected_fg_item_ ==
id;
300 return selected_bg_item_ ==
id;
309 if (*active_mouse_action_)
310 (*active_mouse_action_)->set_mouse_overlay(gui_);
312 std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button(
"menu-editor-terrain");
313 if (palette_menu_button) {
316 std::string& icon = groups_[active_group_index()].icon;
318 palette_menu_button->set_tooltip_string(name);
319 palette_menu_button->set_overlay(icon);
322 unsigned int y = palette_y_;
323 unsigned int x = palette_x_;
324 int starting = items_start_;
325 int ending = std::min<int>(starting + nitems_, num_items());
327 std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button(
"upscroll-button-editor");
329 upscroll_button->enable(starting != 0);
330 std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button(
"downscroll-button-editor");
331 if (downscroll_button)
332 downscroll_button->enable(ending != num_items());
336 for (
int i = 0,
size = num_visible_items();
i <
size ; ++
i) {
344 if (
i >= ending)
continue;
351 std::stringstream tooltip_text;
352 draw_item((*item).second, item_image, tooltip_text);
354 bool is_core = non_core_items_.find(
get_id((*item).second)) == non_core_items_.end();
358 <<
_(
"(non-core)") <<
"\n"
359 <<
_(
"Will not work in game without extra care.")
363 const int counter_from_zero = counter - starting;
365 dstrect.x = x + (counter_from_zero % item_width_) * item_space_;
367 dstrect.w = item_size_ + 2;
368 dstrect.h = item_size_ + 2;
386 if (is_selected_bg_item(
get_id(item->second))
387 && is_selected_fg_item(
get_id(item->second))) {
389 }
else if (is_selected_bg_item(
get_id(item->second))) {
391 }
else if (is_selected_fg_item(
get_id(item->second))) {
402 if (counter_from_zero % item_width_ == item_width_ - 1)
virtual bool scroll_up()
Scroll the editor-palette up one step if possible.
virtual void select_bg_item(const std::string &item_id)
virtual bool can_scroll_down()
std::vector< events::sdl_handler * > sdl_handler_vector
virtual void select_fg_item(const std::string &item_id)
Select a foreground item.
Stores the info about the groups in a nice format.
size_t active_group_index()
virtual bool can_scroll_up()
GLint GLint GLint GLint GLint GLint y
virtual bool is_selected_bg_item(const std::string &id)
const std::vector< std::string > items
virtual bool scroll_down()
Scroll the editor-palette down one step if possible.
std::string span_color(const SDL_Color &color)
Creates pango markup of a color.
GLdouble GLdouble GLdouble b
static UNUSEDNOWARN std::string _(const char *str)
virtual bool is_selected_fg_item(const std::string &id)
const SDL_Color BAD_COLOR
void draw(surface screen)
Manage the empty-palette in the editor.
int num_items()
Return the number of items in the palette.
void adjust_size(const SDL_Rect &target)
Update the size of this widget.
GLint GLint GLint GLint GLint x
Declarations for File-IO.
GLuint const GLchar * name
void expand_palette_groups_menu(std::vector< std::pair< std::string, std::string > > &items)
Menu expanding for palette group list.
char const COLUMN_SEPARATOR
void swap(game_board &one, game_board &other)
virtual void draw_contents()
virtual sdl_handler_vector handler_members()
void update_rect(const SDL_Rect &)
bool file_exists(const std::string &name)
Returns true if a file or directory with such name already exists.
GLsizei const GLcharARB ** string
HOTKEY_COMMAND get_id(const std::string &command)
returns get_hotkey_command(command).id
void set_group(size_t index)