void editor_palette<Item>::swap()
{
	std::swap(selected_fg_item_, selected_bg_item_);
	select_fg_item(selected_fg_item_);
	select_bg_item(selected_bg_item_);
	set_dirty();
}
Esempio n. 2
0
void item_palette::setup(const config& cfg)
{

	for (const config& group : cfg.child_range("item_group")) {

		groups_.push_back(item_group(group));

		for (const config& item : group.child_range("item")) {

			item_map_.insert(std::pair<std::string, overlay>(item["id"], overlay(item)));
			group_map_[group["id"]].push_back(item["id"]);
			if (!group["core"].to_bool(false))
				non_core_items_.insert(item["id"]);
		}
		nmax_items_ = std::max(nmax_items_, group_map_[group["id"]].size());
	}

	select_fg_item("anvil");
	select_bg_item("altar");

	// Set the default group
	set_group("items");

	if(active_group().empty()) {
		ERR_ED << "No items found." << std::endl;
	}
}
Esempio n. 3
0
void unit_palette::setup(const config& /*cfg*/)
{
    for (const unit_type_data::unit_type_map::value_type &i : unit_types.types())
    {
        if (i.second.do_not_list())
            continue;
        item_map_.insert(std::pair<std::string, unit_type>(i.second.id(), i.second));
        group_map_[i.second.race_id()].push_back(i.second.id());
        nmax_items_ = std::max<int>(nmax_items_, group_map_[i.second.race_id()].size());
        //TODO
        bool core = true;
        if (core) {
            // Add the unit to the default group
            group_map_["all"].push_back(i.second.id());
            nmax_items_ = std::max<int>(nmax_items_, group_map_["all"].size());
        } else {
            non_core_items_.insert(i.second.id());
        }
    }

    for (const race_map::value_type &i : unit_types.races())
    {
        if (group_map_[i.second.id()].empty())
            continue;
        config cfg;
        cfg["id"] = i.second.id();
        cfg["name"] = i.second.plural_name();
        cfg["icon"] = "icons/unit-groups/race_" + i.second.id();
        cfg["core"] = "yes";
        groups_.push_back(item_group(cfg));
    }

    //TODO
    //move "invalid" items to the end
    //std::stable_partition(items.begin(), items.end(), is_valid_terrain);

    select_fg_item(item_map_.begin()->second.id());
    select_bg_item(item_map_.begin()->second.id());

    // Set the default group
    set_group(groups_[0].id);

    if(active_group().empty()) {
        ERR_ED << "No items found." << std::endl;
    }
}
Esempio n. 4
0
void terrain_palette::setup(const config& cfg)
{
	// Get the available terrains temporary in items
	t_translation::t_list items = map().get_terrain_list();

	//move "invalid" items to the end
	std::stable_partition(items.begin(), items.end(), is_valid_terrain);

	// Get the available groups and add them to the structure
	std::set<std::string> group_names;
	for (const config &group : cfg.child_range("editor_group"))
	{
		if (group_names.find(group["id"]) == group_names.end()) {

			config group_cfg;
			group_cfg["id"] = group["id"];
			group_cfg["name"] = group["name"];

			group_cfg["icon"] = "icons/terrain/terrain_" + group["icon"].str();
			group_cfg["core"] = group["core"];
			groups_.push_back(item_group(group_cfg));

			group_names.insert(groups_.back().id);
		}
	}

	std::map<std::string, item_group*> id_to_group;
	for (item_group& group : groups_) {
		id_to_group.insert(std::make_pair(group.id, &group));
	}

	// add the groups for all terrains to the map
	for (const t_translation::t_terrain& t : items) {

		const terrain_type& t_info = map().get_terrain_info(t);
		DBG_ED << "Palette: processing terrain " << t_info.name()
			<< "(editor name: '" << t_info.editor_name() << "') "
			<< "(" << t_info.number() << ")"
			<< ": " << t_info.editor_group() << "\n";

		// don't display terrains that were automatically created from base+overlay
		if (t_info.is_combined()) continue;
		// nor display terrains that have hide_in_editor=true
		if (t_info.hide_in_editor()) continue;

		// add the terrain to the requested groups
		const std::vector<std::string>& keys = utils::split(t_info.editor_group());
		bool core = false;

		item_map_[get_id(t)] = t;

		for (const std::string& k : keys) {
			group_map_[k].push_back(get_id(t));
			nmax_items_ = std::max<int>(nmax_items_, group_map_[k].size());
			std::map<std::string, item_group*>::iterator i = id_to_group.find(k);
			if (i != id_to_group.end()) {
				if (i->second->core) {
					core = true;
				}
			}
		}

		// A terrain is considered core iff it appears in at least
		// one core terrain group
		if (core) {
		// Add the terrain to the default group
			group_map_["all"].push_back(get_id(t));
		nmax_items_ = std::max<int>(nmax_items_, group_map_["all"].size());
		} else {
			non_core_items_.insert(get_id(t));
		}

	}

	// Set the default terrain
	select_fg_item("regular_mountains");
	select_bg_item("grassland");

	// Set the default group
	set_group("all");

	if(active_group().empty()) {
		ERR_ED << "No items found." << std::endl;
	}
}