void editor_palette<Item>::expand_palette_groups_menu(std::vector<config>& items, int i) { auto pos = items.erase(items.begin() + i); std::vector<config> groups; const std::vector<item_group>& item_groups = get_groups(); for (std::size_t mci = 0; mci < item_groups.size(); ++mci) { std::string groupname = item_groups[mci].name; if (groupname.empty()) { groupname = _("(Unknown Group)"); } std::string img = item_groups[mci].icon + "_30"; if (mci == active_group_index()) { std::string pressed_img = img + "-pressed.png"; if(!filesystem::get_binary_file_location("images", pressed_img).empty()) { img = pressed_img; } else { img += ".png~CS(70,70,0)"; } } else { img += ".png"; } groups.emplace_back( "label", groupname, "icon", img ); } items.insert(pos, groups.begin(), groups.end()); }
void prev_group() { set_group( (active_group_index() -1) % (groups_.size()) ); };
void next_group() { set_group( (active_group_index() +1) % (groups_.size()) ); };
void editor_palette<Item>::draw_contents() { toolkit_.set_mouseover_overlay(gui_); std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button("menu-editor-terrain"); if (palette_menu_button) { t_string& name = groups_[active_group_index()].name; std::string& icon = groups_[active_group_index()].icon; palette_menu_button->set_tooltip_string(name); palette_menu_button->set_overlay(icon); } unsigned int y = palette_y_; unsigned int x = palette_x_; int starting = items_start_; int ending = std::min<int>(starting + nitems_, num_items()); std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button("upscroll-button-editor"); if (upscroll_button) upscroll_button->enable(starting != 0); std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button("downscroll-button-editor"); if (downscroll_button) downscroll_button->enable(ending != num_items()); int counter = starting; for (int i = 0, size = num_visible_items(); i < size ; ++i) { //TODO check if the conditions still hold for the counter variable //for (unsigned int counter = starting; counter < ending; counter++) gui::tristate_button& tile = buttons_[i]; tile.hide(true); if (i >= ending) continue; const std::string item_id = active_group()[counter]; //typedef std::map<std::string, Item> item_map_wurscht; typename item_map::iterator item = item_map_.find(item_id); surface item_image(nullptr); std::stringstream tooltip_text; draw_item((*item).second, item_image, tooltip_text); bool is_core = non_core_items_.find(get_id((*item).second)) == non_core_items_.end(); if (!is_core) { tooltip_text << " " << font::span_color(font::BAD_COLOR) << _("(non-core)") << "\n" << _("Will not work in game without extra care.") << "</span>"; } const int counter_from_zero = counter - starting; SDL_Rect dstrect; dstrect.x = x + (counter_from_zero % item_width_) * item_space_; dstrect.y = y; dstrect.w = item_size_ + 2; dstrect.h = item_size_ + 2; tile.set_location(dstrect); tile.set_tooltip_string(tooltip_text.str()); tile.set_item_image(item_image); tile.set_item_id(item_id); // if (get_id((*item).second) == selected_bg_item_ // && get_id((*item).second) == selected_fg_item_) { // tile.set_pressed(gui::tristate_button::BOTH); // } else if (get_id((*item).second) == selected_bg_item_) { // tile.set_pressed(gui::tristate_button::RIGHT); // } else if (get_id((*item).second) == selected_fg_item_) { // tile.set_pressed(gui::tristate_button::LEFT); // } else { // tile.set_pressed(gui::tristate_button::NONE); // } if (is_selected_bg_item(get_id(item->second)) && is_selected_fg_item(get_id(item->second))) { tile.set_pressed(gui::tristate_button::BOTH); } else if (is_selected_bg_item(get_id(item->second))) { tile.set_pressed(gui::tristate_button::RIGHT); } else if (is_selected_fg_item(get_id(item->second))) { tile.set_pressed(gui::tristate_button::LEFT); } else { tile.set_pressed(gui::tristate_button::NONE); } tile.set_dirty(true); tile.hide(false); tile.draw(); // Adjust location if (counter_from_zero % item_width_ == item_width_ - 1) y += item_space_; ++counter; } }