private static void CreateHaulModeButton(Bill_Production _this, WidgetRow widgetRow) { var label = ("BillStoreMode_" + _this.storeMode).Translate(); Texture2D tex = null; if (_this.storeMode == BillStoreModeDefOf.BestStockpile) { tex = TexButton.BestStockpile; } else if (_this.storeMode == BillStoreModeDefOf.DropOnFloor) { tex = TexButton.DropOnFloor; } if (widgetRow.ButtonIcon(tex, label)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (BillStoreModeDef current in from bsm in DefDatabase <BillStoreModeDef> .AllDefs orderby bsm.listOrder select bsm) { BillStoreModeDef smLocal = current; list.Add(new FloatMenuOption(("BillStoreMode_" + current).Translate(), delegate { _this.storeMode = smLocal; }, MenuOptionPriority.Default, null, null, 0f, null, null)); } Find.WindowStack.Add(new FloatMenu(list)); } }
public override void ExposeData() { base.ExposeData(); Scribe_Defs.Look(ref storeMode, "storeMode"); Scribe_Values.Look(ref paused, "paused", false, false); if (storeMode == null) { storeMode = BillStoreModeDefOf.BestStockpile; } }
protected override IEnumerable <Toil> MakeNewToils() { Building_ShellfishTrap crabPot = this.job.GetTarget(CrabPotIndex).Thing as Building_ShellfishTrap; Pawn actor = this.pawn; Toil unloadProcess = new Toil() { initAction = () => { storemode = crabPot.StoreMode; }, defaultDuration = BaseUnloadDuration, defaultCompleteMode = ToilCompleteMode.Delay, activeSkill = (() => SkillDefOf.Animals) } .FailOnDespawnedNullOrForbidden(CrabPotIndex) .FailOnBurningImmobile(CrabPotIndex) .FailOnThingHavingDesignation(CrabPotIndex, DesignationDefOf.Uninstall) .FailOnCannotTouch(CrabPotIndex, PathEndMode.Touch) .WithProgressBarToilDelay(CrabPotIndex); Toil unloadPot = new Toil() { initAction = () => { //Log.Message("unloadPot"); AddFinishAction(DropStuff); crabPot.LastOpenTick = Find.TickManager.TicksGame; var items = crabPot.GetDirectlyHeldThings(); //Log.Message("items"); //foreach(var item in items) //{ // Log.Message(item.def.defName + " " + item.stackCount); //} //Log.Message("unloading"); while (!MassUtility.IsOverEncumbered(pawn) && items.Count > 0) { int count = Math.Min(MassUtility.CountToPickUpUntilOverEncumbered(actor, items[0]), items[0].stackCount); //Log.Message(count + " " + items[0].stackCount + MassUtility.CountToPickUpUntilOverEncumbered(actor, items[0])); if (items.TryTransferToContainer(items[0], pawn.inventory.innerContainer, count, out Thing resultingItem, false) > 0) { if (!resultingItem.Destroyed && resultingItem.stackCount > 0) { LoadedFish.Add(resultingItem); } } } items.TryDropAll(pawn.Position, pawn.Map, ThingPlaceMode.Near); //actor.jobs.EndCurrentJob(JobCondition.Succeeded); }, defaultCompleteMode = ToilCompleteMode.Instant }; this.FailOnDespawnedNullOrForbidden(CrabPotIndex); this.FailOnBurningImmobile(CrabPotIndex); this.FailOnThingHavingDesignation(CrabPotIndex, DesignationDefOf.Uninstall); yield return(Toils_Goto.GotoThing(CrabPotIndex, PathEndMode.Touch) .FailOnDespawnedNullOrForbidden(CrabPotIndex) .FailOnBurningImmobile(CrabPotIndex) .FailOnThingHavingDesignation(CrabPotIndex, DesignationDefOf.Uninstall)); yield return(unloadProcess); yield return(unloadPot); //todo: repeatetive haul Toil finishAndStartHaul = FinishAndStartHaul(); yield return(finishAndStartHaul); yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, HaulableInd)); yield return(Toils_Reserve.Reserve(StoreCellInd)); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(StoreCellInd); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(StoreCellInd, carryToCell, storageMode: true, tryStoreInSameStorageIfSpotCantHoldWholeStack: true)); yield return(Toils_Jump.JumpIf(finishAndStartHaul, () => LoadedFish.Count > 0)); }
protected override void SaveFields(StreamWriter writer) { foreach (Bill bill in Bills) { if (bill is Bill_Production productionBill) { ThingFilter filter = productionBill.ingredientFilter; ThingFilterReflection reflection = new ThingFilterReflection(filter); string defName = "recipeDefName"; if (bill is Bill_ProductionWithUft) { defName = "recipeDefNameUft"; } WriteField(writer, defName, productionBill.recipe.defName); WriteField(writer, "suspended", productionBill.suspended.ToString()); WriteField(writer, "countEquipped", productionBill.includeEquipped.ToString()); WriteField(writer, "countTainted", productionBill.includeTainted.ToString()); WriteField(writer, "skillRange", productionBill.allowedSkillRange.ToString()); WriteField(writer, "ingSearchRadius", productionBill.ingredientSearchRadius.ToString()); WriteField(writer, "repeatMode", productionBill.repeatMode.defName); WriteField(writer, "repeatCount", productionBill.repeatCount.ToString()); WriteField(writer, "targetCount", productionBill.targetCount.ToString()); WriteField(writer, "pauseWhenSatisfied", productionBill.pauseWhenSatisfied.ToString()); WriteField(writer, "unpauseWhenYouHave", productionBill.unpauseWhenYouHave.ToString()); WriteField(writer, "hpRange", productionBill.hpRange.ToString()); WriteField(writer, "qualityRange", productionBill.qualityRange.ToString()); WriteField(writer, "onlyAllowedIngredients", productionBill.limitToAllowedStuff.ToString()); BillStoreModeDef storeMode = productionBill.GetStoreMode(); WriteField(writer, "storeMode", storeMode.ToString()); if (storeMode == BillStoreModeDefOf.SpecificStockpile) { WriteField(writer, "storeZone", productionBill.GetStoreZone().label); } if (productionBill.includeFromZone != null) { WriteField(writer, "lookIn", productionBill.includeFromZone.label); } StringBuilder builder = new StringBuilder(); foreach (ThingDef thing in filter.AllowedThingDefs) { if (builder.Length > 0) { builder.Append("/"); } builder.Append(thing.defName); } WriteField(writer, "allowedDefs", builder.ToString()); if (filter.allowedHitPointsConfigurable) { builder = new StringBuilder(); builder.Append(Math.Round(filter.AllowedHitPointsPercents.min, 2).ToString()); builder.Append(":"); builder.Append(Math.Round(filter.AllowedHitPointsPercents.max, 2).ToString()); WriteField(writer, "allowedHitPointsPercents", builder.ToString()); } if (filter.allowedQualitiesConfigurable) { builder = new StringBuilder(); builder.Append(filter.AllowedQualityLevels.min.ToString()); builder.Append(":"); builder.Append(filter.AllowedQualityLevels.max.ToString()); WriteField(writer, "allowedQualities", builder.ToString()); } builder = new StringBuilder(); foreach (SpecialThingFilterDef def in reflection.DisallowedSpecialFilters) { if (builder.Length > 0) { builder.Append("/"); } builder.Append(def.defName); } WriteField(writer, "disallowedSpecialFilters", builder.ToString()); writer.WriteLine(BREAK); } } }
private bool TryCreateBill(Dictionary <string, string> fields, out Bill_Production bill) { bill = null; RecipeDef def; ThingFilter filter = null; ThingFilterReflection reflection = null; bool changed = false; foreach (var field in fields) { string key = field.Key; string value = field.Value; switch (key) { case BREAK: return(true); case "recipeDefName": case "recipeDefNameUft": def = DefDatabase <RecipeDef> .GetNamed(value); if (def == null) { string msg = "SaveStorageSettings.UnableToLoadRecipeDef".Translate().Replace("%s", value); Messages.Message(msg, MessageTypeDefOf.SilentInput); Log.Warning(msg); return(false); } if (def.researchPrerequisite != null && !def.researchPrerequisite.IsFinished) { string msg = "SaveStorageSettings.ResearchNotDoneForRecipeDef".Translate().Replace("%s", def.label); Messages.Message(msg, MessageTypeDefOf.SilentInput); Log.Warning(msg); return(false); } if (key == "recipeDefName") { bill = new Bill_Production(def); } else { bill = new Bill_ProductionWithUft(def); } filter = bill.ingredientFilter; reflection = new ThingFilterReflection(filter); break; case "suspended": bill.suspended = bool.Parse(value); break; case "countEquipped": bill.includeEquipped = bool.Parse(value); break; case "countTainted": bill.includeTainted = bool.Parse(value); break; case "skillRange": string[] skillRange = value.Split('~'); bill.allowedSkillRange = new IntRange(int.Parse(skillRange[0]), int.Parse(skillRange[1])); break; case "ingSearchRadius": bill.ingredientSearchRadius = float.Parse(value); break; case "repeatMode": bill.repeatMode = null; if (BillRepeatModeDefOf.Forever.defName.Equals(value)) { bill.repeatMode = BillRepeatModeDefOf.Forever; } else if (BillRepeatModeDefOf.RepeatCount.defName.Equals(value)) { bill.repeatMode = BillRepeatModeDefOf.RepeatCount; } else if (BillRepeatModeDefOf.TargetCount.defName.Equals(value)) { bill.repeatMode = BillRepeatModeDefOf.TargetCount; } else if ("TD_ColonistCount".Equals(value)) { EverybodyGetsOneUtil.TryGetRepeatModeDef("TD_ColonistCount", out bill.repeatMode); } else if ("TD_XPerColonist".Equals(value)) { EverybodyGetsOneUtil.TryGetRepeatModeDef("TD_XPerColonist", out bill.repeatMode); } else if ("TD_WithSurplusIng".Equals(value)) { EverybodyGetsOneUtil.TryGetRepeatModeDef("TD_WithSurplusIng", out bill.repeatMode); } if (bill.repeatMode == null) { Log.Warning("Unknown repeatMode of [" + value + "] for bill " + bill.recipe.defName); bill = null; return(false); } break; case "repeatCount": bill.repeatCount = int.Parse(value); break; case "targetCount": bill.targetCount = int.Parse(value); break; case "pauseWhenSatisfied": bill.pauseWhenSatisfied = bool.Parse(value); break; case "unpauseWhenYouHave": bill.unpauseWhenYouHave = int.Parse(value); break; case "hpRange": string[] hpRange = value.Split('~'); bill.hpRange = new FloatRange(float.Parse(hpRange[0]), float.Parse(hpRange[1])); break; case "qualityRange": if (!string.IsNullOrEmpty(value) && value.IndexOf('~') != -1) { string[] qualityRange = value.Split('~'); bill.qualityRange = new QualityRange( (QualityCategory)Enum.Parse(typeof(QualityCategory), qualityRange[0], true), (QualityCategory)Enum.Parse(typeof(QualityCategory), qualityRange[1], true)); } break; case "onlyAllowedIngredients": bill.limitToAllowedStuff = bool.Parse(value); break; case "storeMode": BillStoreModeDef storeMode = DefDatabase <BillStoreModeDef> .GetNamedSilentFail(value); if (storeMode == null || value == BillStoreModeDefOf.SpecificStockpile.ToString()) { storeMode = BillStoreModeDefOf.BestStockpile; } bill.SetStoreMode(storeMode); break; case "storeZone": var destinationZone = (Zone_Stockpile)Current.Game.CurrentMap.zoneManager.AllZones.Find(z => z.label == value); if (destinationZone != null) { bill.SetStoreMode(BillStoreModeDefOf.SpecificStockpile, destinationZone); } else { bill.SetStoreMode(BillStoreModeDefOf.BestStockpile); } break; case "lookIn": var ingredientZone = (Zone_Stockpile)Current.Game.CurrentMap.zoneManager.AllZones.Find(z => z.label == value); bill.includeFromZone = ingredientZone; 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]); filter.AllowedHitPointsPercents = new FloatRange(min, max); changed = true; } break; case "allowedQualities": if (!string.IsNullOrEmpty(value) && value.IndexOf(':') != -1) { string[] values = value.Split(':'); 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 specialDef in DefDatabase <SpecialThingFilterDef> .AllDefs) { if (specialDef != null && specialDef.configurable && expected.Contains(specialDef.defName)) { l.Add(specialDef); } } reflection.DisallowedSpecialFilters = l; } changed = true; break; } } if (changed) { reflection.SettingsChangedCallback(); } return(false); }
public override void DoWindowContents(Rect inRect) { AddRenameButton(inRect); AddRenamedLabel(); #region Origianl Text.Font = GameFont.Small; Rect rect2 = new Rect(0f, 50f, 180f, inRect.height - 50f); Listing_Standard listing_Standard = new Listing_Standard(); listing_Standard.Begin(rect2); if (bill.suspended) { if (listing_Standard.ButtonText("Suspended".Translate(), null)) { bill.suspended = false; } } else if (listing_Standard.ButtonText("NotSuspended".Translate(), null)) { bill.suspended = true; } #endregion AddAssignWorkerButton(listing_Standard); if (listing_Standard.ButtonText(bill.repeatMode.GetLabel(), null)) { BillRepeatModeUtility.MakeConfigFloatMenu(bill); } var label = ("BillStoreMode_" + bill.storeMode).Translate(); if (listing_Standard.ButtonText(label, null)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (BillStoreModeDef current in from bsm in DefDatabase <BillStoreModeDef> .AllDefs orderby bsm.listOrder select bsm) { BillStoreModeDef smLocal = current; list.Add(new FloatMenuOption(("BillStoreMode_" + current).Translate(), delegate { this.bill.storeMode = smLocal; }, MenuOptionPriority.Default, null, null, 0f, null, null)); } Find.WindowStack.Add(new FloatMenu(list)); } listing_Standard.Gap(12f); if (bill.repeatMode == BillRepeatModeDefOf.RepeatCount) { listing_Standard.Label("RepeatCount".Translate(bill.RepeatInfoText)); listing_Standard.IntSetter(ref bill.repeatCount, 1, "1", 42f); listing_Standard.IntAdjuster(ref bill.repeatCount, 1, 25, 1); // changed listing_Standard.IntAdjuster(ref bill.repeatCount, 10, 250, 1); } else if (bill.repeatMode == BillRepeatModeDefOf.TargetCount) { var text = "CurrentlyHave".Translate() + ": "; text += bill.recipe.WorkerCounter.CountProducts(bill); text += " / "; text += bill.targetCount >= 999999 ? "Infinite".Translate().ToLower() : bill.targetCount.ToString(); var text2 = bill.recipe.WorkerCounter.ProductsDescription(bill); if (!text2.NullOrEmpty()) { var text3 = text; text = string.Concat(text3, "\n", "CountingProducts".Translate(), ": ", text2); } listing_Standard.Label(text); // changed // todo : extract method listing_Standard.IntSetter(ref bill.targetCount, 1, "1", 42f); listing_Standard.IntAdjuster(ref bill.targetCount, 1, 25, 1); listing_Standard.IntAdjuster(ref bill.targetCount, 10, 250, 1); } listing_Standard.Gap(12f); listing_Standard.Label("IngredientSearchRadius".Translate() + ": " + bill.ingredientSearchRadius.ToString("F0")); bill.ingredientSearchRadius = listing_Standard.Slider(bill.ingredientSearchRadius, 3f, 100f, null); // changed if (bill.ingredientSearchRadius >= 100f) { bill.ingredientSearchRadius = 999f; } //listing_Standard.Gap(-4f); // °¸ ��»ף if (bill.recipe.workSkill != null) { listing_Standard.Label("AllowedSkillRange".Translate(bill.recipe.workSkill.label.ToLower())); listing_Standard.IntRange(ref bill.allowedSkillRange, 0, 20); } AddMinBarButton(listing_Standard); #region original listing_Standard.End(); Rect rect3 = new Rect(rect2.xMax + 6f, 50f, 280f, -1f); rect3.yMax = inRect.height - this.CloseButSize.y - 6f; ThingFilterUI.DoThingFilterConfigWindow(rect3, ref this.scrollPosition, this.bill.ingredientFilter, this.bill.recipe.fixedIngredientFilter, 4, null, null); Rect rect4 = new Rect(rect3.xMax + 6f, rect3.y + 30f, 0f, 0f); rect4.xMax = inRect.xMax; rect4.yMax = inRect.height - this.CloseButSize.y - 6f; StringBuilder stringBuilder = new StringBuilder(); if (this.bill.recipe.description != null) { stringBuilder.AppendLine(this.bill.recipe.description); stringBuilder.AppendLine(); } stringBuilder.AppendLine(Translator.Translate("WorkAmount") + ": " + GenText.ToStringWorkAmount(this.bill.recipe.WorkAmountTotal(null))); stringBuilder.AppendLine(); for (int i = 0; i < this.bill.recipe.ingredients.Count; i++) { IngredientCount ingredientCount = this.bill.recipe.ingredients[i]; if (!GenText.NullOrEmpty(ingredientCount.filter.Summary)) { stringBuilder.AppendLine(this.bill.recipe.IngredientValueGetter.BillRequirementsDescription(this.bill.recipe, ingredientCount)); } } stringBuilder.AppendLine(); string text5 = this.bill.recipe.IngredientValueGetter.ExtraDescriptionLine(this.bill.recipe); if (text5 != null) { stringBuilder.AppendLine(text5); stringBuilder.AppendLine(); } stringBuilder.AppendLine(Translator.Translate("MinimumSkills")); stringBuilder.AppendLine(this.bill.recipe.MinSkillString); Text.Font = GameFont.Small; string text6 = stringBuilder.ToString(); if (Text.CalcHeight(text6, rect4.width) > rect4.height) { Text.Font = GameFont.Tiny; } Widgets.Label(rect4, text6); Text.Font = GameFont.Small; if (this.bill.recipe.products.Count == 1) { Widgets.InfoCardButton(rect4.x, rect3.y, this.bill.recipe.products[0].thingDef); } #endregion }
public override void DoWindowContents(Rect inRect) { Text.Font = GameFont.Medium; Rect rect = new Rect(0f, 0f, 400f, 50f); Widgets.Label(rect, bill.LabelCap); Rect rect2 = new Rect(0f, 80f, 200f, inRect.height - 80f); Rect rect3 = new Rect(rect2.xMax + 17f, 50f, 180f, inRect.height - 50f - CloseButSize.y); Rect rect4 = new Rect(rect3.xMax + 17f, 50f, inRect.width - (rect3.xMax + 17f), inRect.height - 50f - CloseButSize.y); Text.Font = GameFont.Small; Listing_Standard listing_Standard = new Listing_Standard(); listing_Standard.Begin(rect3); if (bill.suspended) { if (listing_Standard.ButtonText("Suspended".Translate(), null)) { bill.suspended = false; } } else if (listing_Standard.ButtonText("NotSuspended".Translate(), null)) { bill.suspended = true; } string labelCap = bill.storeMode.LabelCap; if (listing_Standard.ButtonText(labelCap, null)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (BillStoreModeDef current in from bsm in DefDatabase <BillStoreModeDef> .AllDefs orderby bsm.listOrder select bsm) { BillStoreModeDef smLocal = current; list.Add(new FloatMenuOption(smLocal.LabelCap, delegate { bill.storeMode = smLocal; }, MenuOptionPriority.Default, null, null, 0f, null, null)); } Find.WindowStack.Add(new FloatMenu(list)); } listing_Standard.Gap(12f); if (bill.workSkill != null) { listing_Standard.Label("AllowedSkillRange".Translate(new object[] { bill.workSkill.label }), -1f); listing_Standard.IntRange(ref bill.allowedSkillRange, 0, 20); } listing_Standard.End(); StringBuilder stringBuilder = new StringBuilder(); if (bill.enchantmentTask.description != null) { stringBuilder.AppendLine(bill.enchantmentTask.description); stringBuilder.AppendLine(); } stringBuilder.AppendLine("WorkAmount".Translate() + ": " + bill.enchantmentTask.WorkAmountTotal().ToStringWorkAmount()); stringBuilder.AppendLine(); // Display the item and the soul gem. if (!bill.enchantmentTask.skillRequirements.NullOrEmpty()) { stringBuilder.AppendLine("MinimumSkills".Translate()); stringBuilder.AppendLine(bill.enchantmentTask.MinSkillString); } Text.Font = GameFont.Small; string text5 = stringBuilder.ToString(); if (Text.CalcHeight(text5, rect2.width) > rect2.height) { Text.Font = GameFont.Tiny; } Widgets.Label(rect2, text5); Text.Font = GameFont.Small; if (bill.enchantmentTask.products.Count > 0) { Widgets_Extensions.InfoCardButton(rect2.x, rect4.y, bill.enchantmentTask.products); } }
private static bool TryCreateBill(StreamReader sr, out Bill_Production bill) { bill = null; string[] kv = null; try { while (!sr.EndOfStream) { if (ReadField(sr, out kv)) { RecipeDef def; switch (kv[0]) { case BREAK: return(true); case "recipeDefName": def = DefDatabase <RecipeDef> .GetNamed(kv[1]); if (def == null) { string msg = "SaveStorageSettings.UnableToLoadRecipeDef".Translate().Replace("%s", kv[1]); Messages.Message(msg, MessageTypeDefOf.SilentInput); Log.Warning(msg); return(false); } if (def.researchPrerequisite != null && !def.researchPrerequisite.IsFinished) { string msg = "SaveStorageSettings.ResearchNotDoneForRecipeDef".Translate().Replace("%s", def.label); Messages.Message(msg, MessageTypeDefOf.SilentInput); Log.Warning(msg); return(false); } bill = new Bill_Production(def); break; case "recipeDefNameUft": def = DefDatabase <RecipeDef> .GetNamed(kv[1]); if (def == null) { string msg = "SaveStorageSettings.UnableToLoadRecipeDef".Translate().Replace("%s", kv[1]); Messages.Message(msg, MessageTypeDefOf.SilentInput); Log.Warning(msg); return(false); } if (def.researchPrerequisite != null && !def.researchPrerequisite.IsFinished) { string msg = "SaveStorageSettings.ResearchNotDoneForRecipeDef".Translate().Replace("%s", def.label); Messages.Message(msg, MessageTypeDefOf.SilentInput); Log.Warning(msg); return(false); } bill = new Bill_ProductionWithUft(def); break; case "skillRange": kv = kv[1].Split('~'); bill.allowedSkillRange = new IntRange(int.Parse(kv[0]), int.Parse(kv[1])); break; case "suspended": bill.suspended = bool.Parse(kv[1]); break; case "ingSearchRadius": bill.ingredientSearchRadius = float.Parse(kv[1]); break; case "repeatMode": bill.repeatMode = null; if (BillRepeatModeDefOf.Forever.defName.Equals(kv[1])) { bill.repeatMode = BillRepeatModeDefOf.Forever; } else if (BillRepeatModeDefOf.RepeatCount.defName.Equals(kv[1])) { bill.repeatMode = BillRepeatModeDefOf.RepeatCount; } else if (BillRepeatModeDefOf.TargetCount.defName.Equals(kv[1])) { bill.repeatMode = BillRepeatModeDefOf.TargetCount; } else if ("TD_ColonistCount".Equals(kv[1])) { EverybodyGetsOneUtil.TryGetRepeatModeDef("TD_ColonistCount", out bill.repeatMode); } else if ("TD_XPerColonist".Equals(kv[1])) { EverybodyGetsOneUtil.TryGetRepeatModeDef("TD_XPerColonist", out bill.repeatMode); } else if ("TD_WithSurplusIng".Equals(kv[1])) { EverybodyGetsOneUtil.TryGetRepeatModeDef("TD_WithSurplusIng", out bill.repeatMode); } if (bill.repeatMode == null) { Log.Warning("Unknown repeatMode of [" + kv[1] + "] for bill " + bill.recipe.defName); bill = null; return(false); } break; case "repeatCount": bill.repeatCount = int.Parse(kv[1]); break; case "storeMode": string[] storeSplit = kv[1].Split('/'); BillStoreModeDef storeMode = DefDatabase <BillStoreModeDef> .GetNamedSilentFail(storeSplit[0]); if (storeMode == null) { Log.Message("Bill [" + bill.recipe.defName + "] storeMode [" + kv[1] + "] cannot be found. Defaulting to [" + BillStoreModeDefOf.BestStockpile.ToString() + "]."); storeMode = BillStoreModeDefOf.BestStockpile; } Zone_Stockpile storeZone = null; if (storeMode == BillStoreModeDefOf.SpecificStockpile) { if (storeSplit.Length > 1) { storeZone = (Zone_Stockpile)Find.CurrentMap?.zoneManager.AllZones.FirstOrFallback(z => z.GetUniqueLoadID() == storeSplit[1]); } if (storeZone == null) { Log.Message("Bill [" + bill.recipe.defName + "] storeZone [" + kv[1] + "] cannot be found. Defaulting to storeMode [" + BillStoreModeDefOf.BestStockpile.ToString() + "]."); storeMode = BillStoreModeDefOf.BestStockpile; } } bill.SetStoreMode(storeMode, storeZone); break; case "targetCount": bill.targetCount = int.Parse(kv[1]); break; case "includeEquipped": bill.includeEquipped = bool.Parse(kv[1]); break; case "includeTainted": bill.includeTainted = bool.Parse(kv[1]); break; case "includeFromZone": Zone_Stockpile zone = (Zone_Stockpile)Find.CurrentMap?.zoneManager.AllZones.FirstOrFallback(z => z.GetUniqueLoadID() == kv[1]); if (zone == null) { Log.Message("Bill [" + bill.recipe.defName + "] includeFromZone [" + kv[1] + "] cannot be found. Defaulting to Everywhere (null)."); } bill.includeFromZone = zone; break; case "limitToAllowedStuff": bill.limitToAllowedStuff = bool.Parse(kv[1]); break; case "pauseWhenSatisfied": bill.pauseWhenSatisfied = bool.Parse(kv[1]); break; case "unpauseWhenYouHave": bill.unpauseWhenYouHave = int.Parse(kv[1]); break; case "hpRange": kv = kv[1].Split('~'); bill.hpRange = new FloatRange(float.Parse(kv[0]), float.Parse(kv[1])); break; case "qualityRange": bill.qualityRange = QualityRange.FromString(kv[1]); break; case "ingredientFilter": ReadFiltersFromFile(bill.ingredientFilter, sr); return(true); } } } } catch { string error = ""; if (bill != null && bill.recipe != null) { error = "Unable to load bill [" + bill.recipe.defName + "]."; } else { error = "Unable to load a bill."; } if (kv == null || kv.Length < 2) { error += " Current line: [" + kv[0] + ":" + kv[1] + "]"; } Log.Warning(error); bill = null; return(false); } return(true); }
public static bool SaveCraftingSettings(BillStack bills, FileInfo fi) { try { // Write Data using (FileStream fileStream = File.Open(fi.FullName, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fileStream)) { WriteField(sw, "Version", "2"); foreach (Bill b in bills) { if (b is Bill_Production) { Bill_Production p = b as Bill_Production; BillStoreModeDef storeMode = p.GetStoreMode(); Zone_Stockpile storeZone = p.GetStoreZone(); Zone_Stockpile includeFromZone = p.includeFromZone; WriteField(sw, "bill", p.recipe.defName); if (b is Bill_ProductionWithUft) { WriteField(sw, "recipeDefNameUft", p.recipe.defName); } else { WriteField(sw, "recipeDefName", p.recipe.defName); } WriteField(sw, "skillRange", p.allowedSkillRange.ToString()); WriteField(sw, "suspended", p.suspended.ToString()); WriteField(sw, "ingSearchRadius", p.ingredientSearchRadius.ToString()); WriteField(sw, "storeMode", storeMode == BillStoreModeDefOf.SpecificStockpile ? string.Join("/", storeMode.defName, storeZone.GetUniqueLoadID()) : storeMode.defName ); WriteField(sw, "repeatMode", p.repeatMode.defName); WriteField(sw, "repeatCount", p.repeatCount.ToString()); WriteField(sw, "targetCount", p.targetCount.ToString()); WriteField(sw, "includeEquipped", p.includeEquipped.ToString()); WriteField(sw, "includeTainted", p.includeTainted.ToString()); if (includeFromZone != null) { WriteField(sw, "includeFromZone", includeFromZone.GetUniqueLoadID()); } WriteField(sw, "limitToAllowedStuff", p.limitToAllowedStuff.ToString()); WriteField(sw, "pauseWhenSatisfied", p.pauseWhenSatisfied.ToString()); WriteField(sw, "unpauseWhenYouHave", p.unpauseWhenYouHave.ToString()); WriteField(sw, "hpRange", p.hpRange.ToString()); WriteField(sw, "qualityRange", p.qualityRange.ToString()); WriteField(sw, "ingredientFilter", ""); WriteFiltersToFile(p.ingredientFilter, sw); } WriteField(sw, BREAK, BREAK); } } } } catch (Exception e) { LogException("Problem saving crafting bills file '" + fi.Name + "'.", e); return(false); } return(true); }
protected override void FillTab() { if (this.SelThing is Building_ShellfishTrap trap) { float y = 20; Rect label1 = new Rect(xLeft, y, width, 32f).ContractedBy(4f); y += 32; Rect storage = new Rect(xLeft, y, width, 40f); y += 60; Rect label2 = new Rect(xLeft, y, width, 32f).ContractedBy(4f); y += 32; Rect slider = new Rect(xLeft, y, width, 32f).ContractedBy(4f); Rect rectPaste = new Rect(size.x - PasteX, PasteY, PasteSize, PasteSize); Rect rectCopy = new Rect(size.x - CopyX, CopyY, CopySize, CopySize); if (HasCopy) { if (Widgets.ButtonImageFitted(rectPaste, ResourceBank.Paste, Color.white)) { trap.StoreMode = StoreModeCopy; trap.OpenFrequency = OpenDelayCopy; SoundDefOf.Tick_Low.PlayOneShotOnCamera(); } } else { GUI.color = Color.gray; Widgets.DrawTextureFitted(rectPaste, ResourceBank.Paste, 1f); GUI.color = Color.white; } TooltipHandler.TipRegionByKey(rectPaste, ResourceBank.Strings.PasteTip); if (Widgets.ButtonImageFitted(rectCopy, ResourceBank.Copy, Color.white)) { HasCopy = true; StoreModeCopy = trap.StoreMode; OpenDelayCopy = trap.OpenFrequency; SoundDefOf.Tick_Low.PlayOneShotOnCamera(); } TooltipHandler.TipRegionByKey(rectCopy, ResourceBank.Strings.CopyTip); Text.Font = GameFont.Small; //stockpile setting Widgets.Label(label1, StockpileString.Translate()); Listing_Standard listing_Standard = new Listing_Standard(); listing_Standard.Begin(storage); Listing_Standard listing_Standard2 = listing_Standard.BeginSection(StoreModeSubdialogHeight); string text = trap.StoreMode.LabelCap; if (listing_Standard2.ButtonText(text)) { Text.Font = GameFont.Small; List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption(BillStoreModeDefOf.BestStockpile.LabelCap, delegate { trap.StoreMode = BillStoreModeDefOf.BestStockpile; })); list.Add(new FloatMenuOption(BillStoreModeDefOf.DropOnFloor.LabelCap, delegate { trap.StoreMode = BillStoreModeDefOf.DropOnFloor; })); Find.WindowStack.Add(new FloatMenu(list)); } Text.Font = GameFont.Small; listing_Standard.EndSection(listing_Standard2); listing_Standard.End(); Text.Font = GameFont.Small; //delay setting Widgets.Label(label2, ResourceBank.Strings.UnloadFrequency.Translate()); Text.Font = GameFont.Small; trap.OpenFrequency = Widgets.FrequencyHorizontalSlider(slider, trap.OpenFrequency, 0.1f, 25f, roundToInt: true); } else { DrawTabNothing(); } }