private static void AddFilter(ThingCategoryDef rootCategory, string defName, string description, string label, string saveKey, Type type) { SpecialThingFilterDef existing = DefDatabase <SpecialThingFilterDef> .GetNamedSilentFail(defName); if (existing != null) { Log.Error($"Clashed with an existing filter named '{defName}' from '{existing.fileName}' with description '{existing.description}'"); return; } SpecialThingFilterDef freezeFilter = new SpecialThingFilterDef { allowedByDefault = true, configurable = true, defName = defName, description = description, label = label, generated = true, /// ??? parentCategory = rootCategory, saveKey = saveKey, /// ??? workerClass = type, }; DefDatabase <SpecialThingFilterDef> .Add(freezeFilter); }
public static void SetAllowance(object o, SpecialThingFilterDef def, bool isSpecial, bool isAllow) { avoidInternalLoop = true; if (o is Zone_Stockpile) { (o as Zone_Stockpile).settings.filter.SetAllow(def, isAllow); } if (o is Outfit) { (o as Outfit).filter.SetAllow(def, isAllow); } if (o is FoodRestriction) { (o as FoodRestriction).filter.SetAllow(def, isAllow); } if (o is Bill) { (o as Bill).ingredientFilter.SetAllow(def, isAllow); } // Utilities.RimLog.Message("SetAllowance for " + o + "::" + def + "::" + isAllow); avoidInternalLoop = false; }
static bool ThingFilter_SetAllow(SpecialThingFilterDef sfDef, bool allow) { if (SyncMarkers.DrawnThingFilter == null) { return(true); } return(!AllowSpecial.DoSync(SyncMarkers.DrawnThingFilter, sfDef, allow)); }
public static bool DoSpecialFilter(SpecialThingFilterDef sfDef) { if (!InDoThingFilterConfigWindow || !sfDef.configurable || InViewArea) { return(true); } ThingFilterOptimizerMod.DbgLog("SKIP"); l.EndLine(); return(false); }
public static ThingFilter DefaultFilter_AnimalZone() { ThingFilter filter = new ThingFilter(); filter.SetDisallowAll(); filter.SetAllow(ThingCategoryDefOf.CorpsesAnimal, true); filter.SetAllow(ThingCategoryDefOf.CorpsesInsect, false); filter.SetAllow(SpecialThingFilterDef.Named("AllowRotten"), false); return(filter); }
public void createSpecialThingFilterDef(StuffCategoryDef stuffToFilter /*, ThingCategoryDef parentCategory*/) { List <ThingDef> defs = DefDatabase <ThingDef> .AllDefsListForReading; Boolean skip = false; foreach (ThingDef def in defs) { if (def.stuffProps != null && def.stuffProps.categories.Contains(stuffToFilter)) { // avoid duplicate SpecialThingFilterDefs if (def.stuffProps.categories.Count > 1) { List <SpecialThingFilterDef> sdefs = DefDatabase <SpecialThingFilterDef> .AllDefsListForReading; foreach (SpecialThingFilterDef sdef in sdefs) { if (sdef.defName == "MaterialFilter_allow" + def.defName) { Logger.Message("Skipping duplicate " + def.defName); skip = true; } } } if (!skip) { SpecialThingFilterDef newSpecialFilterDef = new SpecialThingFilterDef { defName = "MaterialFilter_allow" + def.defName, label = def.label, description = "string_allow".Translate() + " " + def.label, //parentCategory = parentCategory, parentCategory = ThingCategoryDefOf.Root, allowedByDefault = true, saveKey = "allow" + def.defName, configurable = true, modContentPack = ModContentPack }; string newWorkerClassName = "SpecialThingFilterWorker_" + def.defName; newSpecialFilterDef.workerClass = generateDynamicClass(newWorkerClassName, def); if (newSpecialFilterDef.parentCategory.childSpecialFilters.NullOrEmpty()) { newSpecialFilterDef.parentCategory.childSpecialFilters = new List <SpecialThingFilterDef>(); } newSpecialFilterDef.parentCategory.childSpecialFilters.Add(newSpecialFilterDef); DefGenerator.AddImpliedDef(newSpecialFilterDef); } } skip = false; } }
public static bool Prefix(ThingFilter __instance, SpecialThingFilterDef sfDef, bool allow) { //Utilities.RimLog.Message("ThingFilterPatch.avoidThingFilterUsage == " + ThingFilterPatch.avoidThingFilterUsage); if (!thingfilter_methods.avoidInternalLoop && !ThingFilterPatch.avoidThingFilterUsage) { thingfilter_methods.SetAllowance(ThingFilterPatch.thingFilterCallerStack.Peek(), def: sfDef, isAllow: allow, isSpecial: false); return(false); } else { return(true); } }
public static ThingFilter DefaultFilter_RottableZone() { var filter = new ThingFilter(); filter.SetDisallowAll(null, DefDatabase <SpecialThingFilterDef> .AllDefs); DefDatabase <ThingDef> .AllDefs .Where(d => d.HasComp(typeof(CompRottable))) .ToList() .ForEach(d => filter.SetAllow(d, true)); filter.SetAllow(SpecialThingFilterDef.Named("AllowRotten"), false); filter.SetAllow(ThingCategoryDefOf.CorpsesHumanlike, false); return(filter); }
private bool Visible_NewTemp(SpecialThingFilterDef filter, TreeNode_ThingCategory node) { if (parentFilter != null && !parentFilter.Allows(filter)) { return(false); } if (hiddenSpecialFilters == null) { CalculateHiddenSpecialFilters(node); } for (var i = 0; i < hiddenSpecialFilters.Count; i++) { if (hiddenSpecialFilters[i] == filter) { return(false); } } return(true); }
//private bool InViewArea => true; #region Drawers private void DoSpecialFilter(SpecialThingFilterDef sfDef, int nestLevel) { if (!sfDef.configurable) { return; } if (InViewArea) { LabelLeft("*" + sfDef.LabelCap, sfDef.description, nestLevel); var flag = filter.Allows(sfDef); var flag2 = flag; Widgets.Checkbox(new Vector2(LabelWidth, curY), ref flag, lineHeight, false, true); if (flag != flag2) { filter.SetAllow(sfDef, flag); } } EndLine(); }
public static ThingFilter DefaultFilter_IndoorZone() { List <ThingDef> database = DefDatabase <ThingDef> .AllDefsListForReading; ThingFilter filter = new ThingFilter(); filter.SetDisallowAll(); for (int t = 0; t < database.Count; t++) { if (database[t].GetStatValueAbstract(StatDefOf.DeteriorationRate) > 0) { filter.SetAllow(database[t], true); } } filter.SetAllow(ThingCategoryDefOf.Corpses, false); filter.SetAllow(SpecialThingFilterDef.Named("AllowRotten"), false); filter.SetAllow(SpecialThingFilterDef.Named("AllowPlantFood"), true); filter.SetAllow(SpecialThingFilterDef.Named("AllowNonDeadmansApparel"), true); filter.SetAllow(SpecialThingFilterDef.Named("AllowSmeltable"), true); filter.SetAllow(SpecialThingFilterDef.Named("AllowNonSmeltableWeapons"), true); return(filter); }
public static void Prefix() { foreach (SpecialThingFilterDef thingFilter in DefDatabase <SpecialThingFilterDef> .AllDefs) { // Cannot delete the builtin as the core game expect them to always exist if (thingFilter.saveKey == "allowRotten") { rottenFilter = thingFilter; } else if (thingFilter.saveKey == "allowFresh") { freshFilter = thingFilter; } } ThingCategoryDef rootCategory = ThingCategoryDefOf.Root; AddFilter(rootCategory, "AllowFrozen", "Things that must be frozen to last indefinitely", "must be frozen & covered", "allowFrozen", typeof(RottableFilter)); AddFilter(rootCategory, "AllowCovered", "Things that must be covered to last indefinitely", "must be convered", "allowCovered", typeof(MustCoverDoesntRot)); AddFilter(rootCategory, "AllowAnywhere", "Things that can be placed anywhere and will last indefinitely or are already ruined (rotten / desicated)", "no storage restrictions", "allowAnywhere", typeof(DoesntRotDoesntNeedCover)); SetHidden(ZoneHelper.Instnace.ModSettings.HideBuiltinFilters); }
public static SpecialThingFilterDef GetFilter(this Need_FoodGroup foodGroupNeed) { if (foodGroupNeed is Need_Vegetables) { return(SpecialThingFilterDef.Named("AllowVegetables")); } if (foodGroupNeed is Need_Fruit) { return(SpecialThingFilterDef.Named("AllowFruit")); } if (foodGroupNeed is Need_Grain) { return(SpecialThingFilterDef.Named("AllowGrain")); } if (foodGroupNeed is Need_Protein) { return(SpecialThingFilterDef.Named("AllowProtein")); } if (foodGroupNeed is Need_Dairy) { return(SpecialThingFilterDef.Named("AllowDairy")); } throw new NotImplementedException(); }
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { SpecialThingFilterDef s = (SpecialThingFilterDef)obj; info.AddValue("specialThingFilterDefName", s.defName); }
/// <summary> /// Reads the XML document and sets the name, description, and filter that will be used when creating this zone. /// </summary> /// <param name="xmlPath">The absolute path of the XML document to read.</param> private void InitFromXml(string xmlPath) { // Load the XML file into an XmlDocument XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(File.ReadAllText(xmlPath)); // Set the label and description this.defaultLabel = xmlDocument.SelectSingleNode("zoneData/defaultLabel").InnerText; this.defaultDesc = xmlDocument.SelectSingleNode("zoneData/defaultDesc").InnerText; // If the description hasn't been set in this file yet, let the user know where the file is so they can edit it if (this.defaultDesc == "") { this.defaultDesc = "To customize this zone, edit the following file: " + xmlPath; } // Set the storage priority string storagePriorityString = xmlDocument.SelectSingleNode("zoneData/settings/priority").InnerText; switch (storagePriorityString.ToLower()) { case "unstored": this.storageSettings.Priority = StoragePriority.Unstored; break; case "low": this.storageSettings.Priority = StoragePriority.Low; break; case "normal": this.storageSettings.Priority = StoragePriority.Normal; break; case "preferred": this.storageSettings.Priority = StoragePriority.Preferred; break; case "important": this.storageSettings.Priority = StoragePriority.Important; break; case "critical": this.storageSettings.Priority = StoragePriority.Critical; break; default: this.storageSettings.Priority = StoragePriority.Normal; break; } // Set the disallowed special filters XmlNodeList disallowedSpecialFilters = xmlDocument.SelectNodes("zoneData/settings/filter/disallowedSpecialFilters/li"); foreach (XmlNode node in disallowedSpecialFilters) { this.storageSettings.filter.SetAllow(SpecialThingFilterDef.Named(node.InnerText), false); } // Set the allowed defs XmlNodeList allowedDefs = xmlDocument.SelectNodes("zoneData/settings/filter/allowedDefs/li"); foreach (XmlNode node in allowedDefs) { this.storageSettings.filter.SetAllow(ThingDef.Named(node.InnerText), true); } // Set the allowed hit points range this.storageSettings.filter.AllowedHitPointsPercents = FloatRange.FromString(xmlDocument.SelectSingleNode("zoneData/settings/filter/allowedHitPointsPercents").InnerText); // Set the allowed quality range this.storageSettings.filter.AllowedQualityLevels = QualityRange.FromString(xmlDocument.SelectSingleNode("zoneData/settings/filter/allowedQualityLevels").InnerText); }
public static void ToggleCountCompletedOnStockpile(ThingFilter __instance, SpecialThingFilterDef sfDef, bool allow) { if (allow == __instance.Allows(sfDef)) { return; } if (null == CountCompletedDefOf.CountCompleted) { return; } if (sfDef != CountCompletedDefOf.CountCompleted) { return; } if (ITab_Storage_FillTab_Patch.lastITab_Storage == null) { Log.Error("What the heck??? CountCompleted was flipped before any ITab_Storage was printed.. gg"); } else { if (Find.VisibleMap == null) { Log.Error("What the flop??? CountCompleted was flipped while there is no map loaded.. gg"); } else { //Zone_Stockpile zone = (Zone_Stockpile)Find.VisibleMap.zoneManager.AllZones.Find(z => z is Zone_Stockpile && ((Zone_Stockpile)z).GetInspectTabs().Contains(ITab_Storage_FillTab_Patch.lastITab_Storage)); //IStoreSettingsParent tmp = (IStoreSettingsParent)getter.Invoke(ITab_Storage_FillTab_Patch.lastITab_Storage, null); Zone_Stockpile zone = (Zone_Stockpile)getter.Invoke(ITab_Storage_FillTab_Patch.lastITab_Storage, null); if (zone == null) { Log.Error("What the truck??? CountCompleted was flipped, but there are no stockpiles that have the ITab_Storage on which FillTab was last called.. gg"); } else { Log.Warning(zone.label); if (allow) { foreach (IntVec3 sq in zone.AllSlotCells()) { foreach (Thing thing in sq.GetThingList(zone.Map)) { zone.Map.GetComponent <UncountCompletedThingTracker>().UpdateCounter(thing.def, -thing.stackCount); } } } else { foreach (IntVec3 sq in zone.AllSlotCells()) { foreach (Thing thing in sq.GetThingList(zone.Map)) { zone.Map.GetComponent <UncountCompletedThingTracker>().UpdateCounter(thing.def, thing.stackCount); } } } } } } }
private bool Visible(SpecialThingFilterDef filter) { return(Visible_NewTemp(filter, new TreeNode_ThingCategory(ThingCategoryDefOf.Root))); }