Skip to content

Commit e9af45f

Browse files
authored
Merge pull request #24 from DoctorVanGogh/master
bugfixes
2 parents 8224df2 + 2d94d62 commit e9af45f

19 files changed

+232
-98
lines changed

Assemblies/0Harmony.dll

2 KB
Binary file not shown.

Assemblies/ExtendedStorage.dll

2 KB
Binary file not shown.

Assemblies/_harmonycheck.dll

7.5 KB
Binary file not shown.

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
# Version 2.5(???)
1+
# Version 3.0.1
2+
3+
4+
## Bugfixes
5+
- Changes to storage priority correctly trigger hauling jobs to & from Extended Storage buildings
6+
- Correctly update total item count label when partial stack is used from output slot.
7+
- Move single non-max stacks from input cell to output.
8+
- Fix error for reinstalled non empty Extended Storage buildings.
9+
- Disallowing & reallowing a stored item while paused will no longer eject the stored item from storage after unpause.
10+
11+
## New features
12+
- Skip now officially supports storing stone chunks
13+
- (Debug) options in God mode (Allow switching displayed filter between User & Storage settings. User settings are default, storage settings are what is actually currently stored in the building).
14+
- Upgrade Harmony to 1.0.9.1
15+
16+
# Version 3.0
217

318
_Upgrading to this version in an existing savegame is fully supported._
419

Defs/ThingDefs/Storage/Storage_Skip.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<filter>
4040
<categories>
4141
<li>ResourcesRaw</li>
42+
<li>StoneChunks</li>
4243
</categories>
4344
</filter>
4445
</fixedStorageSettings>

Source/ExtendedStorage/Building_ExtendedStorage.cs

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@
1010

1111
namespace ExtendedStorage
1212
{
13-
public class Building_ExtendedStorage : Building_Storage
13+
public interface IUserSettingsOwner : IStoreSettingsParent
1414
{
15+
void Notify_UserSettingsChanged();
16+
}
17+
18+
19+
public class Building_ExtendedStorage : Building_Storage, IUserSettingsOwner {
1520
#region fields
1621

1722
internal Graphic _gfxStoredThing;
1823
private string _label;
1924

2025
private ThingDef _storedThingDef;
21-
internal Thing _suppressedDrawCandidate;
2226

2327
private Func<IEnumerable<Gizmo>> Building_GetGizmos;
2428
private IntVec3 inputSlot;
@@ -27,23 +31,18 @@ public class Building_ExtendedStorage : Building_Storage
2731
private Action queuedTickAction;
2832
internal string label;
2933

30-
public StorageSettings userSettings;
31-
32-
internal static Action<ThingFilter, Action> SetSettingsChanged;
34+
public UserSettings userSettings;
3335

3436
#endregion
3537

36-
static Building_ExtendedStorage()
37-
{
38-
SetSettingsChanged = Access.GetFieldSetter<ThingFilter, Action>("settingsChangedCallback");
39-
}
40-
4138

4239
#region Properties
4340

4441
public bool AtCapacity => StoredThingTotal >= ApparentMaxStorage;
4542

46-
public int ApparentMaxStorage => (int) (StoredThingDef?.stackLimit*this.GetStatValue(DefReferences.Stat_ES_StorageFactor) ?? Int32.MaxValue);
43+
public int ApparentMaxStorage => StoredThingDef == null
44+
? Int32.MaxValue
45+
: (int) (StoredThingDef.stackLimit*this.GetStatValue(DefReferences.Stat_ES_StorageFactor));
4746

4847
public IntVec3 OutputSlot => outputSlot;
4948

@@ -85,7 +84,6 @@ public IEnumerable<Thing> StoredThings
8584

8685
public override string LabelNoCount => label;
8786

88-
8987
#endregion
9088

9189
#region Base overrides
@@ -107,38 +105,27 @@ public override void DrawGUIOverlay()
107105
GenMapUI.DrawThingLabel(StoredThings.First(), _label, labelColor);
108106
}
109107

108+
public override void Draw()
109+
{
110+
base.Draw();
111+
if (true == StoredThingDef?.IsApparel)
112+
return;
113+
114+
_gfxStoredThing?.DrawFromDef(
115+
Gen.TrueCenter(OutputSlot, Rot4.North, IntVec2.One, Altitudes.AltitudeFor(AltitudeLayer.Item)),
116+
Rot4.North,
117+
StoredThingDef);
118+
}
119+
110120
public override void ExposeData()
111121
{
112122
base.ExposeData();
113123
Scribe_Defs.Look(ref _storedThingDef, "storedThingDef");
114-
Scribe_Deep.Look(ref userSettings, "userSettings");
124+
Scribe_Deep.Look(ref userSettings, "userSettings", this);
115125

116126
if (Scribe.mode != LoadSaveMode.Saving || this.label != null) {
117127
Scribe_Values.Look<string>(ref label, "label", def.label, false);
118128
}
119-
120-
// we need to re-apply our callback on the userSettings after load.
121-
// in addition, we need some migration code for handling mid-save upgrades.
122-
// todo: the migration part of this can be removed on the A17 update.
123-
if (Scribe.mode == LoadSaveMode.PostLoadInit)
124-
{
125-
// migration
126-
if (userSettings == null)
127-
{
128-
// create 'user' storage settings
129-
userSettings = new StorageSettings(this);
130-
131-
// copy over previous filter/priority
132-
userSettings.filter.CopyAllowancesFrom(settings.filter);
133-
userSettings.Priority = settings.Priority;
134-
135-
// apply currently stored logic
136-
Notify_StoredThingDefChanged();
137-
}
138-
139-
// re-apply callback
140-
SetSettingsChanged(userSettings.filter, Notify_UserSettingsChanged);
141-
}
142129
}
143130

144131
public override IEnumerable<Gizmo> GetGizmos()
@@ -204,14 +191,11 @@ public override void PostMake()
204191
base.PostMake();
205192

206193
// create 'user' storage settings
207-
userSettings = new StorageSettings(this);
194+
userSettings = new UserSettings(this);
208195

209196
// copy over default filter/priority
210197
if (def.building.defaultStorageSettings != null)
211198
userSettings.CopyFrom(def.building.defaultStorageSettings);
212-
213-
// change callback to point to our custom logic
214-
SetSettingsChanged(userSettings.filter, Notify_UserSettingsChanged);
215199
}
216200

217201

@@ -269,6 +253,8 @@ public override void Tick()
269253
base.Tick();
270254
if (this.IsHashIntervalTick(10))
271255
{
256+
TryGrabOutputItem();
257+
272258
queuedTickAction?.Invoke();
273259
queuedTickAction = null;
274260

@@ -278,12 +264,22 @@ public override void Tick()
278264
}
279265
}
280266

267+
private void TryGrabOutputItem()
268+
{
269+
if (StoredThingDef == null)
270+
{
271+
StoredThingDef = Find.VisibleMap.thingGrid.ThingsAt(outputSlot).Where(userSettings.AllowedToAccept).FirstOrDefault()?.def;
272+
InvalidateThingSection(_storedThingDef);
273+
}
274+
}
275+
281276
#endregion
282277

283278
#region Notification handlers
284279

285280
public void Notify_UserSettingsChanged()
286281
{
282+
287283
// the vanilla StorageSettings.TryNotifyChanged will alert the SlotGroupManager that
288284
// storage settings have changed. We don't need this behaviour for user settings, as these
289285
// don't directly influence the slotgroup, and any changes we make are propagated to the
@@ -303,7 +299,24 @@ public void Notify_UserSettingsChanged()
303299
else
304300
{
305301
TryUnstackStoredItems();
302+
var storedDef = StoredThingDef;
306303
StoredThingDef = null;
304+
InvalidateThingSection(storedDef);
305+
}
306+
}
307+
308+
/// <summary>
309+
/// Checks if the storedDef has a mapMesh painting - if so, invalidate the apppropriate SectionLayer (needed for
310+
/// chunks to appear immediately while game is paused &amp; exclusion by filter)
311+
/// </summary>
312+
private void InvalidateThingSection(ThingDef storedDef)
313+
{
314+
switch (storedDef?.drawerType)
315+
{
316+
case DrawerType.MapMeshOnly:
317+
case DrawerType.MapMeshAndRealTime:
318+
Map?.mapDrawer.SectionAt(OutputSlot).RegenerateLayers(MapMeshFlag.Things);
319+
break;
307320
}
308321
}
309322

@@ -460,6 +473,7 @@ private IEnumerable<Thing> SplurgeThings(IEnumerable<Thing> things, IntVec3 cent
460473
private void TryMoveItem()
461474
{
462475
Thing input = StoredThingAtInput;
476+
463477
if (input == null)
464478
return;
465479

@@ -500,9 +514,9 @@ internal void TrySplurgeStoredItems()
500514

501515
SplurgeThings(storedThings, outputSlot, true);
502516
SoundDef.Named("DropPodOpen").PlayOneShot(new TargetInfo(outputSlot, Map, false));
517+
StoredThingDef = null;
503518
}
504519

505-
506520
/// <remarks>
507521
/// we can't really dump items immediately - otherwise typical use scenarios like "clear all, reselect X" would dump items immediately
508522
/// </remarks>
@@ -519,12 +533,13 @@ private void TryUnstackStoredItems()
519533
if (validThings.Length != 0)
520534
SoundDef.Named("DropPodOpen").PlayOneShot(new TargetInfo(outputSlot, Map, false));
521535
};
536+
522537
}
523538

524539
/// <summary>
525540
/// Update necessary data for label &amp; icon overrides
526541
/// </summary>
527-
private void UpdateCachedAttributes()
542+
public void UpdateCachedAttributes()
528543
{
529544
if (StoredThingDef != null)
530545
{
@@ -561,19 +576,16 @@ private void UpdateCachedAttributes()
561576
_gfxStoredThing = (StoredThingDef.graphic as Graphic_StackCount)
562577
?.SubGraphicForStackCount(Math.Min(total, StoredThingDef.stackLimit), StoredThingDef)
563578
?? StoredThingDef.graphic;
564-
_suppressedDrawCandidate = items[0];
565579
}
566580
else
567581
{
568582
_gfxStoredThing = null;
569-
_suppressedDrawCandidate = null;
570583
}
571584
}
572585
else
573586
{
574587
_label = null;
575588
_gfxStoredThing = null;
576-
_suppressedDrawCandidate = null;
577589
}
578590
}
579591
}

Source/ExtendedStorage/ExtendedStorage.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@
7171
<DesignTime>True</DesignTime>
7272
<DependentUpon>LanguageKeys.Generated.tt</DependentUpon>
7373
</Compile>
74-
<Compile Include="Patches\FloatMenuMakerMap_AddHumanlikeOrders.cs" />
74+
<Compile Include="Patches\CompressibilityDeciderUtility_IsSaveCompressible.cs" />
75+
<Compile Include="Patches\StorageSettings.cs" />
76+
<Compile Include="Patches\Thing_SplitOff.cs" />
77+
<Compile Include="Patches\[GUI]\FloatMenuMakerMap_AddHumanlikeOrders.cs" />
7578
<Compile Include="Patches\ITab_Storage_FillTab.cs" />
7679
<Compile Include="Patches\MinifyUtility_MakeMinified.cs" />
77-
<Compile Include="Patches\Thing_DrawAt.cs" />
80+
<Compile Include="Patches\[GUI]\Thing_DrawAt.cs" />
7881
<Compile Include="Patches\Thing_SpawnSetup.cs" />
79-
<Compile Include="Patches\Thing_DrawGUIOverlay.cs" />
82+
<Compile Include="Patches\[GUI]\Thing_DrawGUIOverlay.cs" />
8083
<Compile Include="Properties\AssemblyInfo.cs" />
81-
<Compile Include="Dialog_Rename.cs" />
84+
<Compile Include="Dialog_Rename.cs" />
85+
<Compile Include="UserSettings.cs" />
8286
<Compile Include="Utility\AccessUtility.cs" />
8387
<Compile Include="Utility\EnumUtility.cs" />
8488
<Compile Include="Utility\StorageUtility.cs" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=languages/@EntryIndexedValue">True</s:Boolean>
33
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=patches/@EntryIndexedValue">True</s:Boolean>
4+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=patches_005C_005Bgui_005D/@EntryIndexedValue">True</s:Boolean>
45
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utility/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Reflection;
2+
using Harmony;
3+
using RimWorld;
4+
using Verse;
5+
6+
namespace ExtendedStorage {
7+
8+
[HarmonyPatch(typeof(CompressibilityDeciderUtility), nameof(CompressibilityDeciderUtility.IsSaveCompressible))]
9+
class CompressibilityDeciderUtility_IsSaveCompressible {
10+
11+
public static void Postfix(ref bool __result, Thing t)
12+
{
13+
__result = __result && !(t.GetSlotGroup()?.parent is Building_ExtendedStorage);
14+
}
15+
}
16+
}

Source/ExtendedStorage/Patches/ITab_Storage_FillTab.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
24
using System.Reflection;
35
using System.Reflection.Emit;
46
using Harmony;
57
using RimWorld;
8+
using UnityEngine;
9+
using Verse;
610

711
namespace ExtendedStorage
812
{
@@ -11,6 +15,8 @@ public class ITab_Storage_FillTab
1115
{
1216
private static readonly PropertyInfo piSelStoreSettingsParent;
1317

18+
public static bool showStoreSettings = false;
19+
1420
static ITab_Storage_FillTab()
1521
{
1622
// accessor for private field
@@ -41,7 +47,7 @@ public static StorageSettings GetSettings(RimWorld.ITab_Storage tab, out IStoreS
4147
{
4248
ITab_Storage extended = tab as ITab_Storage;
4349

44-
if (extended == null)
50+
if (extended == null || (DebugSettings.godMode && showStoreSettings))
4551
{
4652
parent = GetSelStoreSettingsParent(tab);
4753
return parent.GetStoreSettings();
@@ -52,6 +58,26 @@ public static StorageSettings GetSettings(RimWorld.ITab_Storage tab, out IStoreS
5258
return building?.userSettings;
5359
}
5460

61+
/// <summary>
62+
/// Add debug dropdown to toggle displayed settings to tab. Only visible in GodMode.
63+
/// </summary>
64+
public static void Postfix(RimWorld.ITab_Storage __instance) {
65+
if (!DebugSettings.godMode || !(__instance is ITab_Storage))
66+
return;
67+
68+
Rect rect = new Rect(160f+10f+5f, 10f, 100f, 29f);
69+
70+
Text.Font = GameFont.Tiny;
71+
if (Widgets.ButtonText(rect, $"[Debug] {(showStoreSettings ? "Store" : "User")}", true, false, true)) {
72+
List<FloatMenuOption> list = new List<FloatMenuOption>
73+
{
74+
new FloatMenuOption("User", () => { showStoreSettings = false; }),
75+
new FloatMenuOption("Store", () => { showStoreSettings = true; })
76+
};
77+
Find.WindowStack.Add(new FloatMenu(list));
78+
}
79+
}
80+
5581

5682
/// <remarks>
5783
/// Changes the IL code so the patched method beginning is functionally changed from

0 commit comments

Comments
 (0)