10
10
11
11
namespace ExtendedStorage
12
12
{
13
- public class Building_ExtendedStorage : Building_Storage
13
+ public interface IUserSettingsOwner : IStoreSettingsParent
14
14
{
15
+ void Notify_UserSettingsChanged ( ) ;
16
+ }
17
+
18
+
19
+ public class Building_ExtendedStorage : Building_Storage , IUserSettingsOwner {
15
20
#region fields
16
21
17
22
internal Graphic _gfxStoredThing ;
18
23
private string _label ;
19
24
20
25
private ThingDef _storedThingDef ;
21
- internal Thing _suppressedDrawCandidate ;
22
26
23
27
private Func < IEnumerable < Gizmo > > Building_GetGizmos ;
24
28
private IntVec3 inputSlot ;
@@ -27,23 +31,18 @@ public class Building_ExtendedStorage : Building_Storage
27
31
private Action queuedTickAction ;
28
32
internal string label ;
29
33
30
- public StorageSettings userSettings ;
31
-
32
- internal static Action < ThingFilter , Action > SetSettingsChanged ;
34
+ public UserSettings userSettings ;
33
35
34
36
#endregion
35
37
36
- static Building_ExtendedStorage ( )
37
- {
38
- SetSettingsChanged = Access . GetFieldSetter < ThingFilter , Action > ( "settingsChangedCallback" ) ;
39
- }
40
-
41
38
42
39
#region Properties
43
40
44
41
public bool AtCapacity => StoredThingTotal >= ApparentMaxStorage ;
45
42
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 ) ) ;
47
46
48
47
public IntVec3 OutputSlot => outputSlot ;
49
48
@@ -85,7 +84,6 @@ public IEnumerable<Thing> StoredThings
85
84
86
85
public override string LabelNoCount => label ;
87
86
88
-
89
87
#endregion
90
88
91
89
#region Base overrides
@@ -107,38 +105,27 @@ public override void DrawGUIOverlay()
107
105
GenMapUI . DrawThingLabel ( StoredThings . First ( ) , _label , labelColor ) ;
108
106
}
109
107
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
+
110
120
public override void ExposeData ( )
111
121
{
112
122
base . ExposeData ( ) ;
113
123
Scribe_Defs . Look ( ref _storedThingDef , "storedThingDef" ) ;
114
- Scribe_Deep . Look ( ref userSettings , "userSettings" ) ;
124
+ Scribe_Deep . Look ( ref userSettings , "userSettings" , this ) ;
115
125
116
126
if ( Scribe . mode != LoadSaveMode . Saving || this . label != null ) {
117
127
Scribe_Values . Look < string > ( ref label , "label" , def . label , false ) ;
118
128
}
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
- }
142
129
}
143
130
144
131
public override IEnumerable < Gizmo > GetGizmos ( )
@@ -204,14 +191,11 @@ public override void PostMake()
204
191
base . PostMake ( ) ;
205
192
206
193
// create 'user' storage settings
207
- userSettings = new StorageSettings ( this ) ;
194
+ userSettings = new UserSettings ( this ) ;
208
195
209
196
// copy over default filter/priority
210
197
if ( def . building . defaultStorageSettings != null )
211
198
userSettings . CopyFrom ( def . building . defaultStorageSettings ) ;
212
-
213
- // change callback to point to our custom logic
214
- SetSettingsChanged ( userSettings . filter , Notify_UserSettingsChanged ) ;
215
199
}
216
200
217
201
@@ -269,6 +253,8 @@ public override void Tick()
269
253
base . Tick ( ) ;
270
254
if ( this . IsHashIntervalTick ( 10 ) )
271
255
{
256
+ TryGrabOutputItem ( ) ;
257
+
272
258
queuedTickAction ? . Invoke ( ) ;
273
259
queuedTickAction = null ;
274
260
@@ -278,12 +264,22 @@ public override void Tick()
278
264
}
279
265
}
280
266
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
+
281
276
#endregion
282
277
283
278
#region Notification handlers
284
279
285
280
public void Notify_UserSettingsChanged ( )
286
281
{
282
+
287
283
// the vanilla StorageSettings.TryNotifyChanged will alert the SlotGroupManager that
288
284
// storage settings have changed. We don't need this behaviour for user settings, as these
289
285
// don't directly influence the slotgroup, and any changes we make are propagated to the
@@ -303,7 +299,24 @@ public void Notify_UserSettingsChanged()
303
299
else
304
300
{
305
301
TryUnstackStoredItems ( ) ;
302
+ var storedDef = StoredThingDef ;
306
303
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 & 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 ;
307
320
}
308
321
}
309
322
@@ -460,6 +473,7 @@ private IEnumerable<Thing> SplurgeThings(IEnumerable<Thing> things, IntVec3 cent
460
473
private void TryMoveItem ( )
461
474
{
462
475
Thing input = StoredThingAtInput ;
476
+
463
477
if ( input == null )
464
478
return ;
465
479
@@ -500,9 +514,9 @@ internal void TrySplurgeStoredItems()
500
514
501
515
SplurgeThings ( storedThings , outputSlot , true ) ;
502
516
SoundDef . Named ( "DropPodOpen" ) . PlayOneShot ( new TargetInfo ( outputSlot , Map , false ) ) ;
517
+ StoredThingDef = null ;
503
518
}
504
519
505
-
506
520
/// <remarks>
507
521
/// we can't really dump items immediately - otherwise typical use scenarios like "clear all, reselect X" would dump items immediately
508
522
/// </remarks>
@@ -519,12 +533,13 @@ private void TryUnstackStoredItems()
519
533
if ( validThings . Length != 0 )
520
534
SoundDef . Named ( "DropPodOpen" ) . PlayOneShot ( new TargetInfo ( outputSlot , Map , false ) ) ;
521
535
} ;
536
+
522
537
}
523
538
524
539
/// <summary>
525
540
/// Update necessary data for label & icon overrides
526
541
/// </summary>
527
- private void UpdateCachedAttributes ( )
542
+ public void UpdateCachedAttributes ( )
528
543
{
529
544
if ( StoredThingDef != null )
530
545
{
@@ -561,19 +576,16 @@ private void UpdateCachedAttributes()
561
576
_gfxStoredThing = ( StoredThingDef . graphic as Graphic_StackCount )
562
577
? . SubGraphicForStackCount ( Math . Min ( total , StoredThingDef . stackLimit ) , StoredThingDef )
563
578
?? StoredThingDef . graphic ;
564
- _suppressedDrawCandidate = items [ 0 ] ;
565
579
}
566
580
else
567
581
{
568
582
_gfxStoredThing = null ;
569
- _suppressedDrawCandidate = null ;
570
583
}
571
584
}
572
585
else
573
586
{
574
587
_label = null ;
575
588
_gfxStoredThing = null ;
576
- _suppressedDrawCandidate = null ;
577
589
}
578
590
}
579
591
}
0 commit comments