From f950f9c5be47c5a64a7fc4a7ccfb4b6e793e83b2 Mon Sep 17 00:00:00 2001 From: Sn1p3rr3c0n Date: Fri, 19 Aug 2022 09:53:48 +0200 Subject: [PATCH] #612 initial PoC --- .../AutoMachineTool/Building_BeltConveyor.cs | 5 +- .../HarmonyPatches/AdvancedIO_PatchHelper.cs | 2 +- .../Common/HarmonyPatches/PatchStorage.cs | 132 +--------------- .../Patch_HaulAIUtility_HaulToStorageJob.cs | 111 +++++++++++++ .../Common/HarmonyPatches/SetPositionPatch.cs | 4 +- .../Common/PRFMapComponent.cs | 40 +---- .../Industry/UI/ITab_PaperclipDuplicator.cs | 2 +- .../Storage/Building_ItemSlide.cs | 2 +- .../Storage/Building_MassStorageUnit.cs | 149 ++++++++---------- .../Building_MassStorageUnitPowered.cs | 24 --- .../Storage/Building_StorageUnitIOPort.cs | 18 +-- .../Storage/UI/ITab_Items.cs | 11 +- 12 files changed, 196 insertions(+), 304 deletions(-) create mode 100644 Source/ProjectRimFactory/Common/HarmonyPatches/Patch_HaulAIUtility_HaulToStorageJob.cs diff --git a/Source/ProjectRimFactory/AutoMachineTool/Building_BeltConveyor.cs b/Source/ProjectRimFactory/AutoMachineTool/Building_BeltConveyor.cs index 82f8f9f8..ec88efe4 100644 --- a/Source/ProjectRimFactory/AutoMachineTool/Building_BeltConveyor.cs +++ b/Source/ProjectRimFactory/AutoMachineTool/Building_BeltConveyor.cs @@ -262,13 +262,14 @@ public override void SpawnSetup(Map map, bool respawningAfterLoad) { } // already set, but just in case: this.products = thingOwnerInt.InnerListForReading; - map.GetComponent().RegisterIHideItemPos(this.Position, this); + //Why is this here ??? seems to work just fine without it... + // map.GetComponent().RegisterIHideItemPos(this.Position, this); } public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) { var targets = AllNearbyLinkables().ToList(); - this.Map.GetComponent().DeRegisterIHideItemPos(this.Position,this); + // this.Map.GetComponent().DeRegisterIHideItemPos(this.Position,this); base.DeSpawn(mode); targets.ForEach(x => x.Unlink(this)); diff --git a/Source/ProjectRimFactory/Common/HarmonyPatches/AdvancedIO_PatchHelper.cs b/Source/ProjectRimFactory/Common/HarmonyPatches/AdvancedIO_PatchHelper.cs index 193fb7e4..ee39b8f1 100644 --- a/Source/ProjectRimFactory/Common/HarmonyPatches/AdvancedIO_PatchHelper.cs +++ b/Source/ProjectRimFactory/Common/HarmonyPatches/AdvancedIO_PatchHelper.cs @@ -112,7 +112,7 @@ public static bool CanMoveItem(Building_AdvancedStorageUnitIOPort port, Thing th /// public static bool CanMoveItem(Building_AdvancedStorageUnitIOPort port, IntVec3 thingPos) { - return port.boundStorageUnit?.AllSlotCells()?.Contains(thingPos) ?? false; + return port.boundStorageUnit.Position == thingPos; } diff --git a/Source/ProjectRimFactory/Common/HarmonyPatches/PatchStorage.cs b/Source/ProjectRimFactory/Common/HarmonyPatches/PatchStorage.cs index 83a37da8..74399bd4 100644 --- a/Source/ProjectRimFactory/Common/HarmonyPatches/PatchStorage.cs +++ b/Source/ProjectRimFactory/Common/HarmonyPatches/PatchStorage.cs @@ -12,138 +12,8 @@ namespace ProjectRimFactory.Common.HarmonyPatches { - [HarmonyPatch(typeof(ForbidUtility), "IsForbidden", new Type[] { typeof(Thing), typeof(Pawn) })] - class Patch_ForbidUtility_IsForbidden - { - static bool Prefix(Thing t, Pawn pawn, out bool __result) - { - __result = true; - if (t != null) - { - Map thingmap = t.Map; - if (thingmap != null && t.def.category == ThingCategory.Item) - { - if (PatchStorageUtil.GetPRFMapComponent(thingmap)?.ShouldForbidPawnOutputAtPos(t.Position) ?? false) - { - return false; - } - } - } - return true; - } - } - - [HarmonyPatch(typeof(Building_Storage), "Accepts")] - class Patch_Building_Storage_Accepts - { - static bool Prefix(Building_Storage __instance, Thing t, out bool __result) - { - __result = false; - if ((__instance as IForbidPawnInputItem)?.ForbidPawnInput ?? false) - { - if (!__instance.slotGroup.HeldThings.Contains(t)) - { - return false; - } - } - return true; - } - } - - [HarmonyPatch(typeof(FloatMenuMakerMap), "ChoicesAtFor")] - class Patch_FloatMenuMakerMap_ChoicesAtFor - { - static bool Prefix(Vector3 clickPos, Pawn pawn, out List __result) - { - if (pawn.Map.GetComponent().iHideRightMenus.Contains(clickPos.ToIntVec3())) - { - __result = new List(); - return false; - } - __result = null; - return true; - } - } - - [HarmonyPatch(typeof(Thing), "DrawGUIOverlay")] - class Patch_Thing_DrawGUIOverlay - { - static bool Prefix(Thing __instance) - { - if (__instance.def.category == ThingCategory.Item) - { - if (PatchStorageUtil.GetPRFMapComponent(__instance.Map)?.ShouldHideItemsAtPos(__instance.Position) ?? false) - { - return false; - } - } - return true; - } - } - [HarmonyPatch(typeof(ThingWithComps), "DrawGUIOverlay")] - class Patch_ThingWithComps_DrawGUIOverlay - { - static bool Prefix(Thing __instance) - { - if (__instance.def.category == ThingCategory.Item) - { - if (PatchStorageUtil.GetPRFMapComponent(__instance.Map)?.ShouldHideItemsAtPos(__instance.Position) ?? false) - { - return false; - } - } - return true; - } - } - - [HarmonyPatch(typeof(ThingWithComps), "Draw")] - class Patch_ThingWithComps_Draw - { - static bool Prefix(Thing __instance) - { - if (__instance.def.category == ThingCategory.Item) - { - if (PatchStorageUtil.GetPRFMapComponent(__instance.Map)?.ShouldHideItemsAtPos(__instance.Position) ?? false) - { - return false; - } - } - return true; - } - } - - [HarmonyPatch(typeof(Thing), "Print")] - class Patch_Thing_Print - { - static bool Prefix(Thing __instance, SectionLayer layer) - { - if (__instance.def.category == ThingCategory.Item) - { - if (PatchStorageUtil.GetPRFMapComponent(__instance.Map)?.ShouldHideItemsAtPos(__instance.Position) ?? false) - { - return false; - } - } - return true; - } - } - - [HarmonyPatch(typeof(MinifiedThing), "Print")] - class Patch_MinifiedThing_Print - { - static bool Prefix(Thing __instance, SectionLayer layer) - { - if (__instance.def.category == ThingCategory.Item) - { - if (PatchStorageUtil.GetPRFMapComponent(__instance.Map)?.ShouldHideItemsAtPos(__instance.Position) ?? false) - { - return false; - } - } - return true; - } - } + //The DSU Pawn Access coud / Must be added somwhere else static class PatchStorageUtil { diff --git a/Source/ProjectRimFactory/Common/HarmonyPatches/Patch_HaulAIUtility_HaulToStorageJob.cs b/Source/ProjectRimFactory/Common/HarmonyPatches/Patch_HaulAIUtility_HaulToStorageJob.cs new file mode 100644 index 00000000..664087fd --- /dev/null +++ b/Source/ProjectRimFactory/Common/HarmonyPatches/Patch_HaulAIUtility_HaulToStorageJob.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HarmonyLib; +using ProjectRimFactory.Storage; +using RimWorld; +using Verse; +using Verse.AI; +using System.Reflection.Emit; + +namespace ProjectRimFactory.Common.HarmonyPatches +{ + [HarmonyPatch(typeof(Verse.AI.HaulAIUtility), "HaulToStorageJob")] + class Patch_HaulAIUtility_HaulToStorageJob + { + + static bool foundPos = false; + static int cnt = 0; + + + static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + + Label end = generator.DefineLabel(); + Label preend = generator.DefineLabel(); + + foreach (var instruction in instructions) + { + + if (instruction.opcode == OpCodes.Brfalse_S) cnt++; + + if (instruction.opcode == OpCodes.Brfalse_S && (cnt == 2 || cnt == 3)) + { + yield return new CodeInstruction(OpCodes.Brfalse_S, preend); + continue; + } + + + + if (!foundPos && instruction.opcode == OpCodes.Ldstr) + { + foundPos = true; + CodeInstruction code = new CodeInstruction(OpCodes.Nop); + code.labels.Add(preend); + + yield return code; + + yield return new CodeInstruction(OpCodes.Ldloc_2); + + yield return new CodeInstruction(OpCodes.Call, AccessTools.Method( + typeof(Patch_HaulAIUtility_HaulToStorageJob), + nameof(Patch_HaulAIUtility_HaulToStorageJob.IsDSU), new[] { typeof(IHaulDestination) })); + + yield return new CodeInstruction(OpCodes.Brfalse_S, end); + + + + yield return new CodeInstruction(OpCodes.Ldarg_0); + yield return new CodeInstruction(OpCodes.Ldarg_1); + + yield return new CodeInstruction(OpCodes.Ldloc_2); + + yield return new CodeInstruction(OpCodes.Call, AccessTools.Method( + typeof(Patch_HaulAIUtility_HaulToStorageJob), + nameof(Patch_HaulAIUtility_HaulToStorageJob.HaulToCellStorageJob), new[] { typeof(Pawn) , typeof(Thing) , typeof(IHaulDestination) })); + yield return new CodeInstruction(OpCodes.Ret); + + + instruction.labels.Add(end); + //yield return new CodeInstruction(end); + + + } + + + + yield return instruction; + } + + } + + public static Job HaulToCellStorageJob(Pawn p, Thing t, IHaulDestination dest) + { + //Probaly not that good + //When do i register it? + Building_MassStorageUnit dsu = dest as Building_MassStorageUnit; + + Job job = JobMaker.MakeJob(JobDefOf.HaulToContainer, t, dsu); + + + + job.count = 99999; + + job.haulOpportunisticDuplicates = true; + job.haulMode = HaulMode.ToCellStorage; + + + + return job; + } + + public static bool IsDSU(IHaulDestination destination) + { + return (destination as Building_MassStorageUnit) != null; + } + + + } +} diff --git a/Source/ProjectRimFactory/Common/HarmonyPatches/SetPositionPatch.cs b/Source/ProjectRimFactory/Common/HarmonyPatches/SetPositionPatch.cs index 7f327871..8ff93f8d 100644 --- a/Source/ProjectRimFactory/Common/HarmonyPatches/SetPositionPatch.cs +++ b/Source/ProjectRimFactory/Common/HarmonyPatches/SetPositionPatch.cs @@ -20,9 +20,9 @@ public static void Prefix(Thing __instance, out Building_MassStorageUnit __state __state = pos.GetFirst(__instance.Map); } } - public static void Postfix(Thing __instance, Building_MassStorageUnit __state) + /* public static void Postfix(Thing __instance, Building_MassStorageUnit __state) { __state?.Notify_LostThing(__instance); - } + }*/ } } diff --git a/Source/ProjectRimFactory/Common/PRFMapComponent.cs b/Source/ProjectRimFactory/Common/PRFMapComponent.cs index 02cbcecc..ee777724 100644 --- a/Source/ProjectRimFactory/Common/PRFMapComponent.cs +++ b/Source/ProjectRimFactory/Common/PRFMapComponent.cs @@ -39,29 +39,7 @@ public void DeRegisteradvancedIOLocations(IntVec3 pos) } - public void RegisterIHideItemPos(IntVec3 pos, HarmonyPatches.IHideItem hideItem) - { - if(hideItemLocations.ContainsKey(pos)) - { - hideItemLocations[pos].Add(hideItem); - } - else - { - hideItemLocations.Add(pos,new List() { hideItem}); - } - } - public void DeRegisterIHideItemPos(IntVec3 pos, HarmonyPatches.IHideItem hideItem) - { - if (hideItemLocations[pos].Count <= 1) - { - hideItemLocations.Remove(pos); - } - else - { - hideItemLocations[pos].Remove(hideItem); - } - - } + public void RegisterIForbidPawnOutputItem(IntVec3 pos, HarmonyPatches.IForbidPawnOutputItem ForbidPawnOutput) { if (ForbidPawnOutputItemLocations.ContainsKey(pos)) @@ -128,21 +106,7 @@ public void RemoveTicker(ITicker ticker) { this.tickers.Remove(ticker); } - public void AddIHideRightClickMenu(Building b) - { - foreach (var v in b.OccupiedRect()) { - iHideRightMenus.Add(v); - } - } - public void RemoveIHideRightClickMenu(Building b) - { - foreach (var v in b.OccupiedRect()) { - iHideRightMenus.Remove(v); - foreach (var t in map.thingGrid.ThingsListAt(v)) { - if (t != b && t is IHideRightClickMenu) iHideRightMenus.Add(v); - } - } - } + } public interface ITicker diff --git a/Source/ProjectRimFactory/Industry/UI/ITab_PaperclipDuplicator.cs b/Source/ProjectRimFactory/Industry/UI/ITab_PaperclipDuplicator.cs index 5a74e54b..f857fc1a 100644 --- a/Source/ProjectRimFactory/Industry/UI/ITab_PaperclipDuplicator.cs +++ b/Source/ProjectRimFactory/Industry/UI/ITab_PaperclipDuplicator.cs @@ -114,7 +114,7 @@ private void HandleDepositWithdrawRequest() for (int i = 0; i < output.Count; i++) { GenPlace.TryPlaceThing(output[i], SelBuilding.Position, SelBuilding.Map, ThingPlaceMode.Direct); - SelBuilding.boundStorageUnit.Notify_ReceivedThing(output[i]); + SelBuilding.boundStorageUnit.RegisterNewItem(output[i]); } SelBuilding.WithdrawPaperclips(result); Messages.Message("SuccessfullyWithdrawnPaperclips".Translate(result), MessageTypeDefOf.PositiveEvent); diff --git a/Source/ProjectRimFactory/Storage/Building_ItemSlide.cs b/Source/ProjectRimFactory/Storage/Building_ItemSlide.cs index 4b7be5d9..74cf030e 100644 --- a/Source/ProjectRimFactory/Storage/Building_ItemSlide.cs +++ b/Source/ProjectRimFactory/Storage/Building_ItemSlide.cs @@ -30,7 +30,7 @@ public bool AcceptsThing(Thing newThing, IPRF_Building giver = null) { if (base.Accepts(newThing)){ - Notify_ReceivedThing(newThing); + //Notify_ReceivedThing(newThing); return true; } else diff --git a/Source/ProjectRimFactory/Storage/Building_MassStorageUnit.cs b/Source/ProjectRimFactory/Storage/Building_MassStorageUnit.cs index 5250dfb4..114cbb75 100644 --- a/Source/ProjectRimFactory/Storage/Building_MassStorageUnit.cs +++ b/Source/ProjectRimFactory/Storage/Building_MassStorageUnit.cs @@ -12,18 +12,20 @@ namespace ProjectRimFactory.Storage { [StaticConstructorOnStartup] - public abstract class Building_MassStorageUnit : Building_Storage, IHideItem, IHideRightClickMenu, - IForbidPawnOutputItem, IForbidPawnInputItem ,IRenameBuilding + public abstract class Building_MassStorageUnit : Building, IRenameBuilding, IHaulDestination, IStoreSettingsParent { private static readonly Texture2D RenameTex = ContentFinder.Get("UI/Buttons/Rename"); - private readonly List items = new List(); + private List items = new List(); + private List ports = new List(); public string UniqueName { get => uniqueName; set => uniqueName = value; } private string uniqueName; public Building Building => this; + public StorageSettings settings; + //Initialized at spawn public DefModExtension_Crate ModExtension_Crate = null; @@ -43,20 +45,6 @@ public abstract class Building_MassStorageUnit : Building_Storage, IHideItem, IH public virtual bool ForbidPawnInput => ForbidPawnAccess; - public override void Notify_ReceivedThing(Thing newItem) - { - base.Notify_ReceivedThing(newItem); - if (newItem.Position != Position) RegisterNewItem(newItem); - RefreshStorage(); - } - - public override void Notify_LostThing(Thing newItem) - { - base.Notify_LostThing(newItem); - items.Remove(newItem); - RefreshStorage(); - } - public virtual bool ForbidPawnOutput => ForbidPawnAccess; public virtual bool HideItems => ModExtension_Crate?.hideItems ?? false; @@ -64,6 +52,12 @@ public override void Notify_LostThing(Thing newItem) public virtual bool HideRightClickMenus => ModExtension_Crate?.hideRightClickMenus ?? false; + IntVec3 IHaulDestination.Position => this.Position; + + Map IHaulDestination.Map => this.Map; + + bool IStoreSettingsParent.StorageTabVisible => true; + public void DeregisterPort(Building_StorageUnitIOBase port) { ports.Remove(port); @@ -86,17 +80,6 @@ public override IEnumerable GetGizmos() defaultLabel = "PRFRenameMassStorageUnitLabel".Translate(), defaultDesc = "PRFRenameMassStorageUnitDesc".Translate() }; - yield return new Command_Action - { - icon = TexUI.RotRightTex, - action = () => - { - RefreshStorage(); - Messages.Message("PRFReorganize_Message".Translate(), MessageTypeDefOf.NeutralEvent); - }, - defaultLabel = "PRFReorganize".Translate(), - defaultDesc = "PRFReorganize_Desc".Translate() - }; } public virtual string GetUIThingLabel() @@ -111,11 +94,16 @@ public virtual string GetITabString(int itemsSelected) public virtual void RegisterNewItem(Thing newItem) { - var things = Position.GetThingList(Map); - for (var i = 0; i < things.Count; i++) + + Log.Message($"RegisterNewItem: {newItem}"); + if (items.Contains(newItem)) + { + Log.Message($"dup: {newItem}"); + return; + } + for (var i = 0; i < items.Count; i++) { - var item = things[i]; - if (item == newItem) continue; + var item = items[i]; if (item.def.category == ThingCategory.Item && item.CanStackWith(newItem)) item.TryAbsorbStack(newItem, true); if (newItem.Destroyed) break; @@ -124,12 +112,14 @@ public virtual void RegisterNewItem(Thing newItem) //Add a new stack of a thing if (!newItem.Destroyed) { - if (!items.Contains(newItem)) - items.Add(newItem); + items.Add(newItem); //What appens if its full? - if (CanStoreMoreItems) newItem.Position = Position; - if (!newItem.Spawned) newItem.SpawnSetup(Map, false); + if (CanStoreMoreItems) + { + newItem.Position = Position; + } + if (newItem.Spawned) newItem.DeSpawn(); } } @@ -137,7 +127,9 @@ public override void ExposeData() { base.ExposeData(); Scribe_Collections.Look(ref ports, "ports", LookMode.Reference); + Scribe_Collections.Look(ref items, "items", LookMode.Deep); Scribe_Values.Look(ref uniqueName, "uniqueName"); + Scribe_Deep.Look(ref settings, "settings", this); ModExtension_Crate ??= def.GetModExtension(); } @@ -159,26 +151,19 @@ public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) thingsToSplurge[i].DeSpawn(); GenPlace.TryPlaceThing(thingsToSplurge[i], Position, Map, ThingPlaceMode.Near); } - Map.GetComponent().RemoveIHideRightClickMenu(this); - foreach (var cell in this.OccupiedRect().Cells) - { - Map.GetComponent().DeRegisterIHideItemPos(cell, this); - Map.GetComponent().DeRegisterIForbidPawnOutputItem(cell, this); - } base.DeSpawn(mode); } public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); - Map.GetComponent().AddIHideRightClickMenu(this); - foreach (var cell in this.OccupiedRect().Cells) + ModExtension_Crate ??= def.GetModExtension(); + + Log.Message("----------------"); + foreach (var item in this.StoredItems) { - map.GetComponent().RegisterIHideItemPos(cell, this); - map.GetComponent().RegisterIForbidPawnOutputItem(cell, this); + Log.Message(item.ToString()); } - ModExtension_Crate ??= def.GetModExtension(); - RefreshStorage(); } @@ -195,45 +180,6 @@ public bool OutputItem(Thing item) return GenPlace.TryPlaceThing(item.SplitOff(item.stackCount), outputCell, Map, ThingPlaceMode.Near); } - public virtual void RefreshStorage() - { - items.Clear(); - if (!Spawned) return; // don't want to try getting lists of things when not on a map (see 155) - foreach (var cell in AllSlotCells()) - { - var things = new List(cell.GetThingList(Map)); - for (var i = 0; i < things.Count; i++) - { - var item = things[i]; - if (item.def.category == ThingCategory.Item) - { - if (cell != Position) - { - RegisterNewItem(item); - } - else - { - if (!items.Contains(item)) - items.Add(item); - } - } - } - } - - // Even though notifying I/O ports that the contents inside the storage unit have changed seems like a good idea, it can cause recursion issues. - //for (int i = 0; i < ports.Count; i++) - //{ - // if (ports[i] == null) - // { - // ports.RemoveAt(i); - // i--; - // } - // else - // { - // ports[i].Notify_NeedRefresh(); - // } - //} - } //----------- For compatibility with Pick Up And Haul: ----------- // (not used internally in any way) // true if can store, capacity is how many can store (more than one stack possible) @@ -280,13 +226,42 @@ public bool CapacityAt(Thing thing, IntVec3 cell, Map map, out int capacity) } return capacity > 0; } + // ...The above? I think? But without needing to know how many public bool StackableAt(Thing thing, IntVec3 cell, Map map) { return CapacityAt(thing, cell, map, out _); } + public bool Accepts(Thing t) + { + return settings.AllowedToAccept(t); + } + StorageSettings IStoreSettingsParent.GetStoreSettings() + { + return settings; + } + + StorageSettings IStoreSettingsParent.GetParentStoreSettings() + { + StorageSettings fixedStorageSettings = def.building.fixedStorageSettings; + if (fixedStorageSettings != null) + { + return fixedStorageSettings; + } + return StorageSettings.EverStorableFixedSettings(); + } + + public override void PostMake() + { + base.PostMake(); + settings = new StorageSettings(this); + if (def.building.defaultStorageSettings != null) + { + settings.CopyFrom(def.building.defaultStorageSettings); + } + } } } \ No newline at end of file diff --git a/Source/ProjectRimFactory/Storage/Building_MassStorageUnitPowered.cs b/Source/ProjectRimFactory/Storage/Building_MassStorageUnitPowered.cs index aa36b610..2b9f3b95 100644 --- a/Source/ProjectRimFactory/Storage/Building_MassStorageUnitPowered.cs +++ b/Source/ProjectRimFactory/Storage/Building_MassStorageUnitPowered.cs @@ -29,16 +29,6 @@ public class Building_MassStorageUnitPowered : Building_MassStorageUnit private bool pawnAccess = true; - public override void Notify_ReceivedThing(Thing newItem) - { - base.Notify_ReceivedThing(newItem); - UpdatePowerConsumption(); - } - public override void Notify_LostThing(Thing newItem) - { - base.Notify_LostThing(newItem); - UpdatePowerConsumption(); - } public void UpdatePowerConsumption() { compPowerTrader ??= GetComp(); @@ -52,19 +42,6 @@ public override void ExposeData() compPowerTrader ??= GetComp(); } - protected override void ReceiveCompSignal(string signal) - { - base.ReceiveCompSignal(signal); - switch (signal) - { - case "PowerTurnedOn": - RefreshStorage(); - break; - default: - break; - } - } - public override void Tick() { base.Tick(); @@ -78,7 +55,6 @@ public override void PostMapInit() { base.PostMapInit(); compPowerTrader ??= GetComp(); - this.RefreshStorage(); } public override IEnumerable GetGizmos() diff --git a/Source/ProjectRimFactory/Storage/Building_StorageUnitIOPort.cs b/Source/ProjectRimFactory/Storage/Building_StorageUnitIOPort.cs index 6d0ffe04..756b8c16 100644 --- a/Source/ProjectRimFactory/Storage/Building_StorageUnitIOPort.cs +++ b/Source/ProjectRimFactory/Storage/Building_StorageUnitIOPort.cs @@ -238,14 +238,7 @@ public virtual void RefreshInput() Thing item = WorkPosition.GetFirstItem(Map); if (mode == StorageIOMode.Input && item != null && boundStorageUnit != null && boundStorageUnit.settings.AllowedToAccept(item) && boundStorageUnit.CanReceiveIO && boundStorageUnit.CanStoreMoreItems) { - foreach (IntVec3 cell in boundStorageUnit.AllSlotCells()) - { - if (cell.GetFirstItem(Map) == null) - { - boundStorageUnit.RegisterNewItem(item); - break; - } - } + boundStorageUnit.RegisterNewItem(item); } } } @@ -475,14 +468,7 @@ public override void RefreshInput() Thing item = Position.GetFirstItem(Map); if (mode == StorageIOMode.Input && item != null && boundStorageUnit != null && boundStorageUnit.settings.AllowedToAccept(item) && boundStorageUnit.CanReceiveIO && boundStorageUnit.CanStoreMoreItems) { - foreach (IntVec3 cell in boundStorageUnit.AllSlotCells()) - { - if (cell.GetFirstItem(Map) == null) - { - boundStorageUnit.RegisterNewItem(item); - break; - } - } + boundStorageUnit.RegisterNewItem(item); } } } diff --git a/Source/ProjectRimFactory/Storage/UI/ITab_Items.cs b/Source/ProjectRimFactory/Storage/UI/ITab_Items.cs index 5b7711a9..13b4f15d 100644 --- a/Source/ProjectRimFactory/Storage/UI/ITab_Items.cs +++ b/Source/ProjectRimFactory/Storage/UI/ITab_Items.cs @@ -102,6 +102,8 @@ protected override void FillTab() Widgets.ListSeparator(ref curY, frame.width, labelKey.Translate()); curY += 5f; + + // Sniper: t.Label also contains the count (Rice x20) do we want that? // Rider: This new search method is REALLLYYYYYY FAST // This is meant to stop a possible spam call of the Fuzzy Search @@ -191,7 +193,7 @@ orderby t.Label descending // Credits to LWM Deep Storage :) private void DrawThingRow(ref float y, float width, Thing thing, List colonists) { - if (thing == null || !thing.Spawned) return; // not here, whatever happened... + // if (thing == null || !thing.Spawned) return; // not here, whatever happened... //each call to LabelCap also accesses MaxHitPoints therefor it is read here slightly diffrently; @@ -307,9 +309,16 @@ private void dropThing(Thing thing) var item = SelectedMassStorageUnit .StoredItems.Where(i => i == thing).ToList(); if (IOPortSelected && SelectedIOPort.OutputItem(item[0])) + { itemsToShow.Remove(thing); + SelectedIOPort.boundStorageUnit.StoredItems.Remove(thing); + } else if (SelectedMassStorageUnit.OutputItem(item[0])) + { itemsToShow.Remove(thing); + SelectedMassStorageUnit.StoredItems.Remove(thing); + } + }