void update_file_view(w32 entry) { if (entry!=0xFFFFFFFF) { i4_str d; entry&=~DIRFLAG; d=((i4_text_item_class *)dirpick->get_item(entry))->get_text(); //Make it root-relative (not valid on windows, but will be ignored) cur_dir.insert(cur_dir.end(),'/'); cur_dir.insert(cur_dir.end(),d); simplify_dir(cur_dir); } i4_directory_struct files; i4_get_directory(cur_dir,files,i4_F,0); if (files.tfiles>0) { qsort(files.files,files.tfiles,4,(compare_type)filename_sorter); } i4_array<i4_window_class *> items(200,250); sel_elem=0; w32 i,j; for (i=0; i<files.tfiles; i++) { if (matches_filter(*files.files[i],file_mask)) { j=items.size(); items.add(new i4_text_item_class(*files.files[i], style, style->color_hint, style->font_hint->small_font, new i4_event_reaction_class(this,j))); } } //must not sort this list here, sine the reaction id's wouldn't //match afterwards. //items.sort(filename_sorter); filepick->update(items.size(),items.size() ? &items[0] : 0); filepick->request_redraw(i4_T); items.clear(); for (i=0; i<files.tdirs; i++) { items.add(new i4_text_item_class(*files.dirs[i], style, style->color_hint, style->font_hint->small_font, new i4_event_reaction_class(this,i|DIRFLAG))); } //items.sort(filename_sorter); add_drives_to_list(items); dirpick->update(items.size(),items.size() ? &items[0] : 0); dirpick->request_redraw(i4_T); text_win->set_text(new i4_str(cur_dir)); text_win->resize_to_fit_text(); text_win->request_redraw(); }
/** * Modifies *this using the specifications in @a cfg, but only if *this matches * @a cfg viewed as a filter. * * If *description is provided, it will be set to a (translated) description * of the modification(s) applied (currently only changes to the number of * strikes, damage, accuracy, and parry are included in this description). * * @returns whether or not @c this matched the @a cfg as a filter. */ bool attack_type::apply_modification(const config& cfg,std::string* description) { if( !matches_filter(cfg) ) return false; const std::string& set_name = cfg["set_name"]; const t_string& set_desc = cfg["set_description"]; const std::string& set_type = cfg["set_type"]; const std::string& set_icon = cfg["set_icon"]; const std::string& del_specials = cfg["remove_specials"]; const config &set_specials = cfg.child("set_specials"); const std::string& increase_damage = cfg["increase_damage"]; const std::string& increase_attacks = cfg["increase_attacks"]; const std::string& set_attack_weight = cfg["attack_weight"]; const std::string& set_defense_weight = cfg["defense_weight"]; const std::string& increase_accuracy = cfg["increase_accuracy"]; const std::string& increase_parry = cfg["increase_parry"]; std::stringstream desc; if(set_name.empty() == false) { id_ = set_name; cfg_["name"] = id_; } if(set_desc.empty() == false) { description_ = set_desc; cfg_["description"] = description_; } if(set_type.empty() == false) { type_ = set_type; cfg_["type"] = type_; } if(set_icon.empty() == false) { icon_ = set_icon; cfg_["icon"] = icon_; } if(del_specials.empty() == false) { const std::vector<std::string>& dsl = utils::split(del_specials); if (config &specials = cfg_.child("specials")) { config new_specials; BOOST_FOREACH(const config::any_child &vp, specials.all_children_range()) { std::vector<std::string>::const_iterator found_id = std::find(dsl.begin(), dsl.end(), vp.cfg["id"].str()); if (found_id == dsl.end()) { new_specials.add_child(vp.key, vp.cfg); } } cfg_.clear_children("specials"); cfg_.add_child("specials",new_specials); } }
/** * Returns whether or not *this matches the given @a filter. */ bool attack_type::matches_filter(const config& filter) const { // Handle the basic filter. bool matches = matches_simple_filter(*this, filter); // Handle [and], [or], and [not] with in-order precedence BOOST_FOREACH( const config::any_child &condition, filter.all_children_range() ) { // Handle [and] if ( condition.key == "and" ) matches = matches && matches_filter(condition.cfg); // Handle [or] else if ( condition.key == "or" ) matches = matches || matches_filter(condition.cfg); // Handle [not] else if ( condition.key == "not" ) matches = matches && !matches_filter(condition.cfg); } return matches; }
bool OfflinePacketFilter::matches_filter(PDU& pdu) const { PDU::serialization_type buffer = pdu.serialize(); return matches_filter(&buffer[0], static_cast<uint32_t>(buffer.size())); }
//don't use references here, as local stays in memory while caller will not. i4_get_save_load_dialog(const i4_const_str _title_name, const i4_const_str _start_dir, const i4_const_str _file_mask, const i4_const_str _mask_name, i4_graphical_style_class * style, w32 ok_id, w32 cancel_id, i4_event_handler_class * tell_who, w32 _flags) : i4_color_window_class(0,0, style->color_hint->neutral(), style), style(style), ok_id(ok_id), cancel_id(cancel_id), tell_who(tell_who), title_name(_title_name), start_dir(_start_dir), file_mask(_file_mask), mask_name(_mask_name), cur_dir(_start_dir), flags(_flags) { mp_window=0; text_input_win=0; if (cur_dir.length()==0 || cur_dir[0]!='/') { //if it's not already an absolute path... cur_dir.insert(cur_dir.begin(),"./"); } simplify_dir(cur_dir); i4_directory_struct files; i4_get_directory(cur_dir,files,i4_F,0); if (files.tfiles>0) { qsort(files.files,files.tfiles,4,(compare_type)filename_sorter); } i4_array<i4_window_class *> items(200,250); w32 i,j; for (i=0; i<files.tfiles; i++) { if (matches_filter(*files.files[i],file_mask)) { //this is required because i grows much faster than j and //therefore the wrong entry would get the message. j=items.size(); items.add(new i4_text_item_class(*files.files[i], style, style->color_hint, style->font_hint->small_font, new i4_event_reaction_class(this,j))); } } //items.sort(filename_sorter); //be aware that the list might be empty. Must not //calculate &items[0] for an empty list. filepick=new i4_list_pick_cpitems(200,250, items.size(),items.size() ? &items[0] : 0, i4_list_pick::LB_SCROLLSELF, 0); items.clear(); for (i=0; i<files.tdirs; i++) { items.add(new i4_text_item_class(*files.dirs[i], style, style->color_hint, style->font_hint->small_font, new i4_event_reaction_class(this,i|DIRFLAG))); } //items.sort(filename_sorter); add_drives_to_list(items); //This list is actually never empty (windows systems have //at least one disk), but for safety.. dirpick=new i4_list_pick_cpitems(200,250, items.size(),items.size() ? &items[0] : 0, i4_list_pick::LB_SCROLLSELF, 0); //i4_parent_window_class *p=new i4_browse_window_class(style, // new i4_text_window_class(start_dir,style), // pick,i4_T,i4_T); w32 l=0,t=0,r=0,b=0; style->get_in_deco_size(l,t,r,b); deco1=new i4_deco_window_class(200,250, i4_T,style); deco2=new i4_deco_window_class(200,250, i4_T,style); deco1->add_child(l,t,dirpick); deco2->add_child(l,t,filepick); add_child(0,0,deco1); add_child(deco1->width(),0,deco2); sel_elem=0; i4_window_class * ok, * cancel; if (style->icon_hint->ok_icon && style->icon_hint->cancel_icon) { ok=new i4_image_window_class(style->icon_hint->ok_icon); cancel=new i4_image_window_class(style->icon_hint->cancel_icon); } else { ok=new i4_text_window_class(i4gets("ok"), style); cancel=new i4_text_window_class(i4gets("cancel"), style); } resize_to_fit_children(); int x=0,maxh=filepick->height(); i4_button_class * okb=new i4_button_class(0, ok, style, new i4_event_reaction_class(this, OK)); i4_button_class * cancelb=new i4_button_class(0, cancel, style, new i4_event_reaction_class(this, CANCEL)); x=width()/2-okb->width()/2-cancelb->width()/2; if (x<0) { x=0; } if (flags&SAVE) { text_win=new i4_text_window_class(cur_dir,style); add_child(5,maxh+4,text_win); maxh=maxh+4+text_win->height(); text_input_win=new i4_text_input_class(style,"", width()-4,MAX_PATH); add_child(5,maxh+4,text_input_win); maxh=maxh+4+text_input_win->height(); } else { text_win=new i4_text_window_class(cur_dir,style); add_child(5,maxh+4,text_win); maxh=maxh+4+text_win->height(); text_input_win=0; } listbox=new i4_list_box_class(width()-4, style,i4_current_app->get_window_manager(), new i4_event_reaction_class(this,LISTBOX)); i4_str filter; filter=mask_name; filter+=i4_str(" ("); filter+=file_mask; filter+=i4_str(")"); listbox->add_item(new i4_text_item_class(filter,style)); listbox->set_current_item(0); filter=i4_str("All files (*.*)"); listbox->add_item(new i4_text_item_class(filter,style)); add_child(2,maxh+2,listbox); maxh=maxh+4+listbox->height(); add_child(x, maxh+1, okb); add_child(x+okb->width(), maxh+1, cancelb); resize_to_fit_children(); }
/// Determine if *this matches @a filter at its current location. /// (Only use for units currently on the map; otherwise use the overload /// that takes a location, possibly with a null location.) bool matches_filter(const vconfig& filter, bool use_flat_tod=false) const { return matches_filter(filter, get_location(), use_flat_tod); }
/** * Trimmed down version of apply_modification(), with no modifications actually * made. This can be used to get a description of the modification(s) specified * by @a cfg (if *this matches cfg as a filter). * * If *description is provided, it will be set to a (translated) description * of the modification(s) applied (currently only changes to the number of * strikes, damage, accuracy, and parry are included in this description). * * @returns whether or not @c this matched the @a cfg as a filter. */ bool attack_type::describe_modification(const config& cfg,std::string* description) { if( !matches_filter(cfg) ) return false; // Did the caller want the description? if(description != nullptr) { const std::string& increase_damage = cfg["increase_damage"]; const std::string& set_damage = cfg["set_damage"]; const std::string& increase_attacks = cfg["increase_attacks"]; const std::string& set_attacks = cfg["set_attacks"]; const std::string& increase_accuracy = cfg["increase_accuracy"]; const std::string& set_accuracy = cfg["set_accuracy"]; const std::string& increase_parry = cfg["increase_parry"]; const std::string& set_parry = cfg["set_parry"]; const std::string& increase_movement = cfg["increase_movement_used"]; const std::string& set_movement = cfg["set_movement_used"]; std::stringstream desc; if(increase_damage.empty() == false) { add_and(desc); int inc_damage = lexical_cast<int>(increase_damage); desc << utils::print_modifier(increase_damage) << " " << _n("damage","damage", inc_damage); } if(set_damage.empty() == false) { add_and(desc); int damage = lexical_cast<int>(increase_damage); desc << set_damage << " " << _n("damage","damage", damage); } if(increase_attacks.empty() == false) { add_and(desc); int inc_attacks = lexical_cast<int>(increase_attacks); desc << utils::print_modifier(increase_attacks) << " " << _n("strike", "strikes", inc_attacks); } if(set_attacks.empty() == false) { int num_attacks = lexical_cast<int>(set_attacks); add_and(desc); desc << set_attacks << " " << _n("strike", "strikes", num_attacks); } if(set_accuracy.empty() == false) { int accuracy = lexical_cast<int>(set_accuracy); add_and(desc); // xgettext:no-c-format desc << accuracy << " " << _("% accuracy"); } if(increase_accuracy.empty() == false) { add_and(desc); int inc_acc = lexical_cast<int>(increase_accuracy); // Help xgettext with a directive to recognize the string as a non C printf-like string // xgettext:no-c-format desc << utils::signed_value(inc_acc) << _("% accuracy"); } if(set_parry.empty() == false) { int parry = lexical_cast<int>(set_parry); add_and(desc); desc << parry << _(" parry"); } if(increase_parry.empty() == false) { add_and(desc); int inc_parry = lexical_cast<int>(increase_parry); // xgettext:no-c-format desc << utils::signed_value(inc_parry) << _("% parry"); } if(set_movement.empty() == false) { int movement_used = lexical_cast<int>(set_movement); add_and(desc); desc << movement_used << " " << _n("movement point","movement points",movement_used); } if(increase_movement.empty() == false) { add_and(desc); int inc_move = lexical_cast<int>(increase_movement); desc << increase_movement << " " << _n("movement point","movement points",inc_move); } *description = desc.str(); } return true; }
/** * Modifies *this using the specifications in @a cfg, but only if *this matches * @a cfg viewed as a filter. * * @returns whether or not @c this matched the @a cfg as a filter. */ bool attack_type::apply_modification(const config& cfg) { if( !matches_filter(cfg) ) return false; const std::string& set_name = cfg["set_name"]; const t_string& set_desc = cfg["set_description"]; const std::string& set_type = cfg["set_type"]; const std::string& set_icon = cfg["set_icon"]; const std::string& del_specials = cfg["remove_specials"]; const config &set_specials = cfg.child("set_specials"); const std::string& increase_damage = cfg["increase_damage"]; const std::string& set_damage = cfg["set_damage"]; const std::string& increase_attacks = cfg["increase_attacks"]; const std::string& set_attacks = cfg["set_attacks"]; const std::string& set_attack_weight = cfg["attack_weight"]; const std::string& set_defense_weight = cfg["defense_weight"]; const std::string& increase_accuracy = cfg["increase_accuracy"]; const std::string& set_accuracy = cfg["set_accuracy"]; const std::string& increase_parry = cfg["increase_parry"]; const std::string& set_parry = cfg["set_parry"]; const std::string& increase_movement = cfg["increase_movement_used"]; const std::string& set_movement = cfg["set_movement_used"]; // NB: If you add something here that requires a description, // it needs to be added to describe_modification as well. if(set_name.empty() == false) { id_ = set_name; } if(set_desc.empty() == false) { description_ = set_desc; } if(set_type.empty() == false) { type_ = set_type; } if(set_icon.empty() == false) { icon_ = set_icon; } if(del_specials.empty() == false) { const std::vector<std::string>& dsl = utils::split(del_specials); config new_specials; for (const config::any_child &vp : specials_.all_children_range()) { std::vector<std::string>::const_iterator found_id = std::find(dsl.begin(), dsl.end(), vp.cfg["id"].str()); if (found_id == dsl.end()) { new_specials.add_child(vp.key, vp.cfg); } } specials_ = new_specials; } if (set_specials) { const std::string &mode = set_specials["mode"]; if (mode != "append") { specials_.clear(); } for (const config::any_child &value : set_specials.all_children_range()) { specials_.add_child(value.key, value.cfg); } } if(set_damage.empty() == false) { damage_ = lexical_cast<int>(set_damage); if (damage_ < 0) { damage_ = 0; } } if(increase_damage.empty() == false) { damage_ = utils::apply_modifier(damage_, increase_damage, 0); if (damage_ < 0) { damage_ = 0; } } if(set_attacks.empty() == false) { num_attacks_ = lexical_cast<int>(set_attacks); if (num_attacks_ < 0) { num_attacks_ = 0; } } if(increase_attacks.empty() == false) { num_attacks_ = utils::apply_modifier(num_attacks_, increase_attacks, 1); } if(set_accuracy.empty() == false) { accuracy_ = lexical_cast<int>(set_accuracy); } if(increase_accuracy.empty() == false) { accuracy_ = utils::apply_modifier(accuracy_, increase_accuracy, 1); } if(set_parry.empty() == false) { parry_ = lexical_cast<int>(set_parry); } if(increase_parry.empty() == false) { parry_ = utils::apply_modifier(parry_, increase_parry, 1); } if(set_movement.empty() == false) { movement_used_ = lexical_cast<int>(set_movement); } if(increase_movement.empty() == false) { movement_used_ = utils::apply_modifier(movement_used_, increase_movement, 1); } if(set_attack_weight.empty() == false) { attack_weight_ = lexical_cast_default<double>(set_attack_weight,1.0); } if(set_defense_weight.empty() == false) { defense_weight_ = lexical_cast_default<double>(set_defense_weight,1.0); } return true; }