Пример #1
0
void theme::modify(const config &cfg)
{
	std::map<std::string,std::string> title_stash;
	std::vector<theme::menu>::iterator m;
	for (m = menus_.begin(); m != menus_.end(); ++m) {
		if (!m->title().empty() && !m->get_id().empty())
			title_stash[m->get_id()] = m->title();
	}

	std::vector<theme::action>::iterator a;
	for (a = actions_.begin(); a != actions_.end(); ++a) {
		if (!a->title().empty() && !a->get_id().empty())
			title_stash[a->get_id()] = a->title();
	}

	// Change existing theme objects.
	for(const config &c : cfg.child_range("change"))
	{
		std::string id = c["id"];
		std::string ref_id = c["ref"];
		theme::object &element = find_element(id);
		if (element.get_id() == id)
			set_object_location(element, c["rect"], ref_id);
	}

	// Add new theme objects.
	for(const config &c : cfg.child_range("add")) {
		add_object(c);
	}

	// Remove existent theme objects.
	for(const config &c : cfg.child_range("remove")) {
		remove_object(c["id"]);
	}

	for (m = menus_.begin(); m != menus_.end(); ++m) {
		if (title_stash.find(m->get_id()) != title_stash.end())
			m->set_title(title_stash[m->get_id()]);
	}
	for (a = actions_.begin(); a != actions_.end(); ++a) {
		if (title_stash.find(a->get_id()) != title_stash.end())
			a->set_title(title_stash[a->get_id()]);
	}
}
Пример #2
0
void theme::modify(const config* cfg){
	std::map<std::string,std::string> title_stash;
	std::vector<theme::menu>::iterator m;
	for (m = menus_.begin(); m != menus_.end(); ++m) {
		if (!m->title().empty() && !m->get_id().empty())
			title_stash[m->get_id()] = m->title();
	}

	{
		// changes to existing theme objects
		const config::child_list& c = cfg->get_children("change");
		for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) {
			std::string id = (**j)["id"];
			std::string ref_id = (**j)["ref"];
			theme::object& element = find_element(id);
			if (element.get_id() == id){
				set_object_location(element, (**j)["rect"], ref_id);
			}
		}
	}
	// adding new theme objects
	{
		const config::child_list& c = cfg->get_children("add");
		for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) {
			add_object(**j);
		}
	}
	// removing existent theme objects
	{
		const config::child_list& c = cfg->get_children("remove");
		for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) {
			remove_object((**j)["id"]);
		}
	}
	for (m = menus_.begin(); m != menus_.end(); ++m) {
		if (title_stash.find(m->get_id()) != title_stash.end())
			m->set_title(title_stash[m->get_id()]);
	}
}
Пример #3
0
void theme::add_object(const config& cfg)
{
	if(const config& c = cfg.child("main_map")) {
		main_map_ = object(c);
	}

	if(const config& c = cfg.child("mini_map")) {
		mini_map_ = object(c);
	}

	if(const config& c = cfg.child("palette")) {
		palette_ = object(c);
	}

	if(const config& status_cfg = cfg.child("status")) {
		for(const config::any_child& i : status_cfg.all_children_range()) {
			status_.emplace(i.key, status_item(i.cfg));
		}
		if(const config& unit_image_cfg = status_cfg.child("unit_image")) {
			unit_image_ = object(unit_image_cfg);
		} else {
			unit_image_ = object();
		}
	}

	for(const config& p : cfg.child_range("panel")) {
		panel new_panel(p);
		set_object_location(new_panel, p["rect"], p["ref"]);
		panels_.push_back(new_panel);
	}

	for(const config& lb : cfg.child_range("label")) {
		label new_label(lb);
		set_object_location(new_label, lb["rect"], lb["ref"]);
		labels_.push_back(new_label);
	}

	for(const config& m : cfg.child_range("menu")) {
		menu new_menu(m);
		DBG_DP << "adding menu: " << (new_menu.is_context() ? "is context" : "not context") << "\n";
		if(new_menu.is_context())
			context_ = new_menu;
		else {
			set_object_location(new_menu, m["rect"], m["ref"]);
			menus_.push_back(new_menu);
		}

		DBG_DP << "done adding menu...\n";
	}

	for(const config& a : cfg.child_range("action")) {
		action new_action(a);
		DBG_DP << "adding action: " << (new_action.is_context() ? "is context" : "not context") << "\n";
		if(new_action.is_context())
			action_context_ = new_action;
		else {
			set_object_location(new_action, a["rect"], a["ref"]);
			actions_.push_back(new_action);
		}

		DBG_DP << "done adding action...\n";
	}

	for(const config& s : cfg.child_range("slider")) {
		slider new_slider(s);
		DBG_DP << "adding slider\n";
		set_object_location(new_slider, s["rect"], s["ref"]);
		sliders_.push_back(new_slider);

		DBG_DP << "done adding slider...\n";
	}

	if(const config& c = cfg.child("main_map_border")) {
		border_ = border_t(c);
	}
}
Пример #4
0
void theme::add_object(const config& cfg){

	const config* const main_map_cfg = cfg.child("main_map");
	if(main_map_cfg != NULL) {
		main_map_ = object(*main_map_cfg);
	}

	const config* const mini_map_cfg = cfg.child("mini_map");
	if(mini_map_cfg != NULL) {
		mini_map_ = object(*mini_map_cfg);
	}

	const config* const status_cfg = cfg.child("status");
	if(status_cfg != NULL) {
		for(config::child_map::const_iterator i = status_cfg->all_children().begin(); i != status_cfg->all_children().end(); ++i) {
			for(config::child_list::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
				status_.insert(std::pair<std::string,status_item>(i->first,status_item(**j)));
			}
		}
		const config* const unit_image_cfg = status_cfg->child("unit_image");
		if (unit_image_cfg != NULL) {
			unit_image_ = object(*unit_image_cfg);
		} else {
			unit_image_ = object();
		}
	}

	const config::child_list& panel_list = cfg.get_children("panel");
	for(config::child_list::const_iterator p = panel_list.begin(); p != panel_list.end(); ++p) {
		panel new_panel(**p);
		set_object_location(new_panel, (**p)["rect"], (**p)["ref"]);
		panels_.push_back(new_panel);
	}

	const config::child_list& label_list = cfg.get_children("label");
	for(config::child_list::const_iterator lb = label_list.begin(); lb != label_list.end(); ++lb) {
		label new_label(**lb);
		set_object_location(new_label, (**lb)["rect"], (**lb)["ref"]);
		labels_.push_back(new_label);
	}

	const config::child_list& menu_list = cfg.get_children("menu");
	for(config::child_list::const_iterator m = menu_list.begin(); m != menu_list.end(); ++m) {
		menu new_menu(**m);
		DBG_DP << "adding menu: " << (new_menu.is_context() ? "is context" : "not context") << "\n";
		if(new_menu.is_context())
			context_ = new_menu;
		else{
			set_object_location(new_menu, (**m)["rect"], (**m)["ref"]);
			menus_.push_back(new_menu);
		}

		DBG_DP << "done adding menu...\n";
	}

	const config* const border_cfg = cfg.child("main_map_border");
	if (border_cfg != NULL) {
		border_ = tborder(*border_cfg);
	} else {
		border_ = tborder();
	}
}