private void updateMaterial(object sender) { this.stockpile.color = this.SelectionColorWidget.SelectedColor; if (materialIntInfo == null) { materialIntInfo = typeof(Zone).GetField("materialInt", BindingFlags.NonPublic | BindingFlags.Instance); } materialIntInfo.SetValue(this.stockpile, null); MapDrawer mapDrawer = Find.CurrentMap.mapDrawer; foreach (IntVec3 cell in this.stockpile.cells) { mapDrawer.SectionAt(cell).RegenerateLayers(MapMeshFlag.Zone); } }
protected override void LoadFields(StreamReader reader) { Dictionary <string, string> fields = new Dictionary <string, string>(); while (!reader.EndOfStream) { if (TryReadField(reader, out Pair <string, string> pair)) { fields.Add(pair.First, pair.Second); } } bool changed = false; foreach (var pair in fields) { string key = pair.Key; string value = pair.Value; switch (key) { case BREAK: return; case "color": string[] color = value.Split(','); Stockpile.color = new Color( float.Parse(color[0]), float.Parse(color[1]), float.Parse(color[2]), float.Parse(color[3])); FieldInfo materialIntInfo = typeof(Zone).GetField("materialInt", BindingFlags.NonPublic | BindingFlags.Instance); materialIntInfo.SetValue(Stockpile, null); MapDrawer mapDrawer = Find.CurrentMap.mapDrawer; foreach (IntVec3 cell in Stockpile.cells) { mapDrawer.SectionAt(cell).RegenerateLayers(MapMeshFlag.Zone); } break; case "priority": Stockpile.settings.Priority = (StoragePriority)Enum.Parse(typeof(StoragePriority), value, true); changed = true; break; case "allowedDefs": Reflection.AllowedDefs.Clear(); if (value != null) { HashSet <string> expected = new HashSet <string>(value.Split('/')); IEnumerable <ThingDef> all = Reflection.AllStorableThingDefs; var expectedContained = from thing in all where expected.Contains(thing.defName) select thing; Reflection.AllowedDefs.AddRange(expectedContained.ToList()); } changed = true; break; case "allowedHitPointsPercents": if (!string.IsNullOrEmpty(value) && value.IndexOf(':') != -1) { string[] values = value.Split(':'); float min = float.Parse(values[0]); float max = float.Parse(values[1]); Stockpile.settings.filter.AllowedHitPointsPercents = new FloatRange(min, max); changed = true; } break; case "allowedQualities": if (!string.IsNullOrEmpty(value) && value.IndexOf(':') != -1) { string[] values = value.Split(':'); Stockpile.settings.filter.AllowedQualityLevels = new QualityRange( (QualityCategory)Enum.Parse(typeof(QualityCategory), values[0], true), (QualityCategory)Enum.Parse(typeof(QualityCategory), values[1], true)); changed = true; } break; case "disallowedSpecialFilters": Reflection.DisallowedSpecialFilters.Clear(); if (!string.IsNullOrEmpty(value)) { HashSet <string> expected = new HashSet <string>(value.Split('/')); List <SpecialThingFilterDef> l = new List <SpecialThingFilterDef>(); foreach (SpecialThingFilterDef def in DefDatabase <SpecialThingFilterDef> .AllDefs) { if (def != null && def.configurable && expected.Contains(def.defName)) { l.Add(def); } } Reflection.DisallowedSpecialFilters = l; } changed = true; break; } } if (changed) { Reflection.SettingsChangedCallback(); } }