void set_about(const config& cfg){ config::child_list about = cfg.get_children("about"); for(config::child_list::const_iterator A = about.begin(); A != about.end(); A++) { config AA = (**A); about_list.add_child("about",AA); if(!AA["images"].empty()){ if(images_default.empty()){ images_default=AA["images"]; }else{ images_default+=","+AA["images"]; } } } config::child_list campaigns = cfg.get_children("campaign"); for(config::child_list::const_iterator C = campaigns.begin(); C != campaigns.end(); C++) { config::child_list about = (**C).get_children("about"); if(about.size()){ config temp; std::string text; std::string title; std::string campaign=(**C)["id"]; title=(**C)["name"]; temp["title"]=title; temp["id"]=(**C)["id"]; for(config::child_list::const_iterator A = about.begin(); A != about.end(); A++) { config AA = (**A); std::string subtitle=AA["title"]; if(subtitle.size()){ if (subtitle[0] == '_') subtitle = gettext(subtitle.substr(1,subtitle.size()-1).c_str()); text += "+" + subtitle + "\n"; } std::vector<std::string> lines=utils::split(AA["text"],'\n'); for(std::vector<std::string>::iterator line=lines.begin(); line != lines.end(); line++){ text+=" "+(*line)+"\n"; } config::child_list entries = AA.get_children("entry"); config::child_list::const_iterator entry; for(entry = entries.begin(); entry != entries.end(); entry++) { text+=" "+(**entry)["name"]+"\n"; } if(!AA["images"].empty()){ if(images[campaign].empty()){ images[campaign]=AA["images"]; }else{ images[campaign]+=","+AA["images"]; } } } temp["text"]=text; about_list.add_child("about",temp); } } }
bool check_names_legal(const config& dir) { const config::child_list& files = dir.get_children("file"); for(config::child_list::const_iterator i = files.begin(); i != files.end(); ++i) { if (!addon_name_legal((**i)["name"])) return false; } const config::child_list& dirs = dir.get_children("dir"); { for(config::child_list::const_iterator i = dirs.begin(); i != dirs.end(); ++i) { if (!addon_name_legal((**i)["name"])) return false; if (!check_names_legal(**i)) return false; } } return true; }
/** * Given a vector of strings, and a config representing an [about] section, * add all the credits lines from the about section to the list of strings. */ static void add_lines(std::vector<std::string> &res, config const &c) { std::string title=c["title"]; if(title.size()) { title = "+" + title; res.push_back(title); } std::vector<std::string> lines = utils::split(c["text"], '\n'); for(std::vector<std::string>::iterator line = lines.begin(); line != lines.end(); line++) { if((*line)[0] == '+' && (*line).size()>1){ *line = "+ " + line->substr(1, line->size() - 1); } else { *line = "- " + *line; } if(line->size()) { if ((*line)[0] == '_') *line = gettext(line->substr(1,line->size()-1).c_str()); res.push_back(*line); } } config::child_list entries = c.get_children("entry"); config::child_list::const_iterator entry; for(entry = entries.begin(); entry != entries.end(); entry++) { res.push_back("- "+(**entry)["name"]); } }
std::vector<config *> find_scripts(const config &cfg, std::string extension) { std::vector<config *> python_scripts; const config::child_list& dirs = cfg.get_children("dir"); config::child_list::const_iterator i; for(i = dirs.begin(); i != dirs.end(); ++i) { const config::child_list& files = (**i).get_children("file"); config::child_list::const_iterator j; for(j = files.begin(); j != files.end(); ++j) { //std::string filename = (**j)["name"].str(); std::string filename = (**j)["name"]; if (filename.length() > extension.length()) { if (filename.substr(filename.length() - extension.length()) == extension) { python_scripts.push_back(*j); } } } // Recursively look for files in sub directories. std::vector<config *> childs = find_scripts(**i, extension); python_scripts.insert(python_scripts.end(), childs.begin(), childs.end()); } return python_scripts; }
static void unarchive_dir(const std::string& path, const config& cfg) { std::string dir; if (cfg["name"].empty()) dir = path; else dir = path + '/' + cfg["name"]; make_directory(dir); const config::child_list& dirs = cfg.get_children("dir"); for(config::child_list::const_iterator i = dirs.begin(); i != dirs.end(); ++i) { unarchive_dir(dir,**i); } const config::child_list& files = cfg.get_children("file"); for(config::child_list::const_iterator j = files.begin(); j != files.end(); ++j) { unarchive_file(dir,**j); } }
cutter::surface_map cutter::cut_surface(surface surf, const config& conf) { surface_map res; const config::child_list& config_parts = conf.get_children("part"); config::child_list::const_iterator itor; for(itor = config_parts.begin(); itor != config_parts.end(); ++itor) { add_sub_image(surf, res, *itor); } return res; }
void cutter::load_masks(const config& conf) { const config::child_list& masks = conf.get_children("mask"); for(config::child_list::const_iterator itor = masks.begin(); itor != masks.end(); ++itor) { const std::string name = (**itor)["name"]; const std::string image = get_mask_dir() + "/" + (**itor)["image"]; if(verbose_) { std::cerr << "Adding mask " << name << "\n"; } if(image.empty()) throw exploder_failure("Missing image for mask " + name); const exploder_point shift((**itor)["shift"]); const exploder_rect cut((**itor)["cut"]); if(masks_.find(name) != masks_.end() && masks_[name].filename != image) { throw exploder_failure("Mask " + name + " correspond to two different files: " + name + " and " + masks_.find(name)->second.filename); } if(masks_.find(name) == masks_.end()) { mask& cur_mask = masks_[name]; cur_mask.name = name; cur_mask.shift = shift; cur_mask.cut = cut; cur_mask.filename = image; surface tmp(IMG_Load(image.c_str())); if(tmp == NULL) throw exploder_failure("Unable to load mask image " + image); cur_mask.image = surface(make_neutral_surface(tmp)); } if(masks_[name].image == NULL) throw exploder_failure("Unable to load mask image " + image); } }
tbuilder_grid::tbuilder_grid(const config& cfg) : tbuilder_widget(cfg), id(cfg["id"]), rows(0), cols(0), row_grow_factor(), col_grow_factor(), flags(), border_size(), widgets() { /*WIKI * @page = GUIToolkitWML * @order = 2_cell * * = Cell = * * Every grid cell has some cell configuration values and one widget in the grid * cell. Here we describe the what is available more information about the usage * can be found here [[GUILayout]]. * * == Row values == * * For every row the following variables are available: * * @start_table = config * grow_factor (unsigned = 0) The grow factor for a row. * @end_table * * == Cell values == * * For every column the following variables are available: * @start_table = config * grow_factor (unsigned = 0) The grow factor for a column, this value * is only read for the first row. * * border_size (unsigned = 0) The border size for this grid cell. * border (border = "") Where to place the border in this grid * cell. * * vertical_alignment (v_align = "") * The vertical alignment of the widget in * the grid cell. (This value is ignored if * vertical_grow is true.) * horizontal_alignment (h_align = "") * The horizontal alignment of the widget in * the grid cell.(This value is ignored if * horizontal_grow is true.) * * vertical_grow (bool = false) Does the widget grow in vertical * direction when the grid cell grows in the * vertical directon. This is used if the * grid cell is wider as the best width for * the widget. * horizontal_grow (bool = false) Does the widget grow in horizontal * direction when the grid cell grows in the * horizontal directon. This is used if the * grid cell is higher as the best width for * the widget. * @end_table * */ log_scope2(gui_parse, "Window builder: parsing a grid"); const config::child_list& row_cfgs = cfg.get_children("row"); for(std::vector<config*>::const_iterator row_itor = row_cfgs.begin(); row_itor != row_cfgs.end(); ++row_itor) { unsigned col = 0; row_grow_factor.push_back(lexical_cast_default<unsigned>((**row_itor)["grow_factor"])); const config::child_list& col_cfgs = (**row_itor).get_children("column"); for(std::vector<config*>::const_iterator col_itor = col_cfgs.begin(); col_itor != col_cfgs.end(); ++col_itor) { flags.push_back(read_flags(**col_itor)); border_size.push_back(lexical_cast_default<unsigned>((**col_itor)["border_size"])); if(rows == 0) { col_grow_factor.push_back(lexical_cast_default<unsigned>((**col_itor)["grow_factor"])); } widgets.push_back(create_builder_widget(**col_itor)); ++col; } ++rows; if(row_itor == row_cfgs.begin()) { cols = col; } else { VALIDATE(col, _("A row must have a column.")); VALIDATE(col == cols, _("Number of columns differ.")); } } DBG_G_P << "Window builder: grid has " << rows << " rows and " << cols << " columns.\n"; }
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(); } }
static void expand_partialresolution(config& dst_cfg, const config& top_cfg) { std::vector<config> res_cfgs_; // resolve all the partialresolutions const config::child_list& parts_list = top_cfg.get_children("partialresolution"); for(config::child_list::const_iterator i = parts_list.begin(); i != parts_list.end(); ++i) { // follow the inheritance hierarchy and push all the nodes on the stack std::vector<const config*> parent_stack(1, (*i)); const config* parent; //const t_string* parent_id = &((**i)["inherits"]); t_string parent_id = ((**i)["inherits"]); //const shared_string* parent_id = &((**i)["inherits"]); //while((parent = top_cfg.find_child("resolution", "id", (*parent_id))) == NULL) { while((parent = top_cfg.find_child("resolution", "id", (parent_id))) == NULL) { //parent = top_cfg.find_child("partialresolution", "id", (*parent_id)); parent = top_cfg.find_child("partialresolution", "id", (parent_id)); if(parent == NULL) //throw config::error("[partialresolution] refers to non-existant [resolution] " + (*parent_id)); throw config::error("[partialresolution] refers to non-existant [resolution] " + (parent_id)); parent_stack.push_back(parent); //parent_id = &((*parent)["inherits"]); parent_id = ((*parent)["inherits"]); } // Add the parent resolution and apply all the modifications of its children res_cfgs_.push_back(*parent); while(!parent_stack.empty()) { //override attributes for(string_map::const_iterator j = parent_stack.back()->values.begin(); j != parent_stack.back()->values.end(); ++j) { res_cfgs_.back().values[j->first] = j->second; } { const config::child_list& c = parent_stack.back()->get_children("remove"); for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) { find_ref ((**j)["id"], res_cfgs_.back(), true); } } { const config::child_list& c = parent_stack.back()->get_children("change"); for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) { config& target = find_ref ((**j)["id"], res_cfgs_.back()); for(string_map::iterator k = (**j).values.begin(); k != (**j).values.end(); ++k) { target.values[k->first] = k->second; } } } { // cannot add [status] sub-elements, but who cares const config* c = parent_stack.back()->child("add"); if (c != NULL) { const config::child_map m = c->all_children(); for(config::child_map::const_iterator j = m.begin(); j != m.end(); ++j) { for(config::child_list::const_iterator k = j->second.begin(); k != j->second.end(); ++k) { res_cfgs_.back().add_child(j->first, **k); } } } } parent_stack.pop_back(); } } // Add all the resolutions const config::child_list& res_list = top_cfg.get_children("resolution"); for(config::child_list::const_iterator j = res_list.begin(); j != res_list.end(); ++j) { dst_cfg.add_child("resolution", (**j)); } // Add all the resolved resolutions for(std::vector<config>::const_iterator k = res_cfgs_.begin(); k != res_cfgs_.end(); ++k) { dst_cfg.add_child("resolution", (*k)); } return; }