Skip to content

Commit

Permalink
Added rotational stackoffsets, sorting for contents tab, packable con…
Browse files Browse the repository at this point in the history
…tainers compatibility

Also removed an unnecessary label patch that was reported to contribute a minor performance hit with large quantities of things in view
  • Loading branch information
bbradson committed May 3, 2024
1 parent d4a0872 commit 67f178a
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 123 deletions.
Binary file modified 1.4/Assemblies/AdaptiveStorageFramework.dll
Binary file not shown.
Binary file modified 1.4/Assemblies/AdaptiveStorageFramework.pdb
Binary file not shown.
Binary file modified 1.5/Assemblies/AdaptiveStorageFramework.dll
Binary file not shown.
Binary file modified 1.5/Assemblies/AdaptiveStorageFramework.pdb
Binary file not shown.
44 changes: 0 additions & 44 deletions Source/1.4.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>AdaptiveStorageFramework</AssemblyName>
<RootNamespace>AdaptiveStorage</RootNamespace>
<OutDir>..\1.4\Assemblies\</OutDir>
<Authors>Bradson</Authors>
<Copyright>Copyright (c) 2023 Bradson</Copyright>
<Version>1.1.0</Version>
<TargetFramework>net48</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<PlatformTarget>AnyCPU</PlatformTarget>
<Optimize>true</Optimize>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>preview-recommended</AnalysisLevel>
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>5</WarningLevel>
<NoWarn>CA1000;CA1051;CA1305;CA1707;CA1708;CA1711;CA1725;CA1852;CA2201</NoWarn>
<DefaultItemExcludes>$(DefaultItemExcludes);obj/**/*.*</DefaultItemExcludes>
<PublicizerClearCacheOnClean>true</PublicizerClearCacheOnClean>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>DEBUG;V1_4</DefineConstants>
Expand All @@ -31,30 +12,5 @@
<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.4.*" />
<PackageReference Include="Lib.Harmony" Version="2.2.*" ExcludeAssets="runtime" />
<PackageReference Include="PolySharp" Version="1.*" />
<PackageReference Include="Krafs.Publicizer" Version="2.*" />
<Publicize Include="Assembly-CSharp:RimWorld.Building_Storage.storageGroup" />
<Publicize Include="Assembly-CSharp:RimWorld.InspectPaneUtility.IsOpen" />
<Publicize Include="Assembly-CSharp:RimWorld.ITab_ContentsBase.thingsToSelect" />
<Publicize Include="Assembly-CSharp:RimWorld.MinifiedThing.get_CrateFrontGraphic" />
<Publicize Include="Assembly-CSharp:RimWorld.OverlayDrawer.RenderForbiddenOverlay" />
<Publicize Include="Assembly-CSharp:RimWorld.Selector.SelectableObjectsUnderMouse" />
<Publicize Include="Assembly-CSharp:RimWorld.Planet.CaravanThingsTabUtility.DrawMass" />
<Publicize Include="Assembly-CSharp:Verse.DefDatabase`1.SetIndices" />
<Publicize Include="Assembly-CSharp:Verse.Graphic.AngleFromRot" />
<Publicize Include="Assembly-CSharp:Verse.Graphic_Shadow.GlobalShadowPosOffsetX" />
<Publicize Include="Assembly-CSharp:Verse.Graphic_Shadow.GlobalShadowPosOffsetZ" />
<Publicize Include="Assembly-CSharp:Verse.Graphic_Shadow.shadowInfo" />
<Publicize Include="Assembly-CSharp:Verse.GraphicData.Init" />
<Publicize Include="Assembly-CSharp:Verse.Listing.curY" />
<Publicize Include="Assembly-CSharp:Verse.SectionLayer_ThingsGeneral.TakePrintFrom" />
<Publicize Include="Assembly-CSharp:Verse.Text.tmpTextGUIContent" />
<Publicize Include="Assembly-CSharp:Verse.ThingFilter.categories" />
<Publicize Include="Assembly-CSharp:Verse.ThingWithComps.Comps_PostDraw" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.curY" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.IncrementYIfWillExceedMaxWidth" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.IncrementPosition" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.LeftX" />
<Publicize Include="UnityEngine.CoreModule:UnityEngine.Graphics.Internal_DrawMesh_Injected" />
</ItemGroup>
</Project>
45 changes: 1 addition & 44 deletions Source/1.5.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>AdaptiveStorageFramework</AssemblyName>
<RootNamespace>AdaptiveStorage</RootNamespace>
<OutDir>..\1.5\Assemblies\</OutDir>
<Authors>Bradson</Authors>
<Copyright>Copyright (c) 2023 Bradson</Copyright>
<Version>1.1.0</Version>
<TargetFramework>net48</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<PlatformTarget>AnyCPU</PlatformTarget>
<Optimize>true</Optimize>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>preview-recommended</AnalysisLevel>
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>5</WarningLevel>
<NoWarn>CA1000;CA1051;CA1305;CA1707;CA1708;CA1711;CA1725;CA1852;CA2201</NoWarn>
<DefaultItemExcludes>$(DefaultItemExcludes);obj/**/*.*</DefaultItemExcludes>
<PublicizerClearCacheOnClean>true</PublicizerClearCacheOnClean>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>DEBUG;V1_5</DefineConstants>
Expand All @@ -29,31 +10,7 @@
<DefineConstants>V1_5</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.5.*-*" />
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.5.*" />
<PackageReference Include="Lib.Harmony" Version="2.3.*" ExcludeAssets="runtime" />
<PackageReference Include="PolySharp" Version="1.*" />
<PackageReference Include="Krafs.Publicizer" Version="2.*" />
<Publicize Include="Assembly-CSharp:RimWorld.InspectPaneUtility.IsOpen" />
<Publicize Include="Assembly-CSharp:RimWorld.ITab_ContentsBase.thingsToSelect" />
<Publicize Include="Assembly-CSharp:RimWorld.MinifiedThing.get_CrateFrontGraphic" />
<Publicize Include="Assembly-CSharp:RimWorld.OverlayDrawer.RenderForbiddenOverlay" />
<Publicize Include="Assembly-CSharp:RimWorld.Selector.SelectableObjectsUnderMouse" />
<Publicize Include="Assembly-CSharp:RimWorld.Planet.CaravanThingsTabUtility.DrawMass" />
<Publicize Include="Assembly-CSharp:Verse.DefDatabase`1.SetIndices" />
<Publicize Include="Assembly-CSharp:Verse.Graphic.AngleFromRot" />
<Publicize Include="Assembly-CSharp:Verse.Graphic_Shadow.GlobalShadowPosOffsetX" />
<Publicize Include="Assembly-CSharp:Verse.Graphic_Shadow.GlobalShadowPosOffsetZ" />
<Publicize Include="Assembly-CSharp:Verse.Graphic_Shadow.shadowInfo" />
<Publicize Include="Assembly-CSharp:Verse.GraphicData.Init" />
<Publicize Include="Assembly-CSharp:Verse.Listing.curY" />
<Publicize Include="Assembly-CSharp:Verse.SectionLayer_ThingsGeneral.TakePrintFrom" />
<Publicize Include="Assembly-CSharp:Verse.Text.tmpTextGUIContent" />
<Publicize Include="Assembly-CSharp:Verse.ThingFilter.categories" />
<Publicize Include="Assembly-CSharp:Verse.ThingWithComps.Comps_PostDraw" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.curY" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.IncrementYIfWillExceedMaxWidth" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.IncrementPosition" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.LeftX" />
<Publicize Include="UnityEngine.CoreModule:UnityEngine.Graphics.Internal_DrawMesh_Injected" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions Source/ContentsITab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ protected override void FillTab()
protected override void DoItemsLists(Rect outRect, ref float curY)
{
var storedThings = container;

if (storedThings is Thing[] thingArray)
{
Array.Sort(thingArray, (Comparison<Thing>)(static (a, b) =>
{
var result = string.Compare(a.GetInnerIfMinified().LabelNoCount, b.GetInnerIfMinified().LabelNoCount,
StringComparison.OrdinalIgnoreCase);
if (result == 0)
result = a.stackCount.CompareTo(b.stackCount);

return result;
}));
}

using var massList = new ScopedStatList(storedThings, StatDefOf.Mass);
using var groupScope = new GUIScope.WidgetGroup(outRect);
Expand Down
47 changes: 47 additions & 0 deletions Source/Directory.Build.Props
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<AssemblyName>AdaptiveStorageFramework</AssemblyName>
<RootNamespace>AdaptiveStorage</RootNamespace>
<Authors>Bradson</Authors>
<Copyright>Copyright (c) 2023 Bradson</Copyright>
<Version>1.1.1</Version>
<TargetFramework>net48</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<PlatformTarget>AnyCPU</PlatformTarget>
<Optimize>true</Optimize>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>preview-recommended</AnalysisLevel>
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>5</WarningLevel>
<NoWarn>CA1000;CA1051;CA1305;CA1310;CA1707;CA1708;CA1711;CA1725;CA1852;CA2201</NoWarn>
<DefaultItemExcludes>$(DefaultItemExcludes);obj/**/*.*</DefaultItemExcludes>
<BaseIntermediateOutputPath>obj\$(MSBuildProjectName)\$(Configuration)\</BaseIntermediateOutputPath>
<MSBuildProjectExtensionsPath>obj\$(MSBuildProjectName)\$(Configuration)\</MSBuildProjectExtensionsPath>
<PublicizerClearCacheOnClean>true</PublicizerClearCacheOnClean>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PolySharp" Version="1.*" />
<PackageReference Include="Krafs.Publicizer" Version="2.*" />
<Publicize Include="Assembly-CSharp:RimWorld.Building_Storage.cachedOccupiedCells" />
<Publicize Include="Assembly-CSharp:RimWorld.InspectPaneUtility.IsOpen" />
<Publicize Include="Assembly-CSharp:RimWorld.ITab_ContentsBase.thingsToSelect" />
<Publicize Include="Assembly-CSharp:RimWorld.MinifiedThing.get_CrateFrontGraphic" />
<Publicize Include="Assembly-CSharp:RimWorld.OverlayDrawer.RenderForbiddenOverlay" />
<Publicize Include="Assembly-CSharp:RimWorld.Selector.SelectableObjectsUnderMouse" />
<Publicize Include="Assembly-CSharp:RimWorld.Planet.CaravanThingsTabUtility.DrawMass" />
<Publicize Include="Assembly-CSharp:Verse.DefDatabase`1.SetIndices" />
<Publicize Include="Assembly-CSharp:Verse.Graphic.AngleFromRot" />
<Publicize Include="Assembly-CSharp:Verse.Graphic_Shadow.GlobalShadowPosOffsetX" />
<Publicize Include="Assembly-CSharp:Verse.Graphic_Shadow.GlobalShadowPosOffsetZ" />
<Publicize Include="Assembly-CSharp:Verse.Graphic_Shadow.shadowInfo" />
<Publicize Include="Assembly-CSharp:Verse.GraphicData.Init" />
<Publicize Include="Assembly-CSharp:Verse.Listing.curY" />
<Publicize Include="Assembly-CSharp:Verse.MapDrawer.sections" />
<Publicize Include="Assembly-CSharp:Verse.SectionLayer_ThingsGeneral.TakePrintFrom" />
<Publicize Include="Assembly-CSharp:Verse.Text.tmpTextGUIContent" />
<Publicize Include="Assembly-CSharp:Verse.ThingFilter.categories" />
<Publicize Include="Assembly-CSharp:Verse.ThingWithComps.Comps_PostDraw" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.curY" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.IncrementYIfWillExceedMaxWidth" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.IncrementPosition" />
<Publicize Include="Assembly-CSharp:Verse.WidgetRow.LeftX" />
<Publicize Include="UnityEngine.CoreModule:UnityEngine.Graphics.Internal_DrawMesh_Injected" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Source/HarmonyPatches/HideStoredThingLabels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This Source Code Form is subject to the terms of the MIT license.
// If a copy of the license was not distributed with this file,
// You can obtain one at https://opensource.org/licenses/MIT/.

/*
using System.Runtime.CompilerServices;
using HarmonyLib;
Expand All @@ -19,4 +19,4 @@ public static bool Prefix(ThingWithComps __instance)
=> !__instance.IsItem()
|| __instance.StoringThing() is not ThingClass storingThing
|| __instance == storingThing;
}
}*/
10 changes: 5 additions & 5 deletions Source/InspectStringUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public static string GetString(Building_Storage building)
var stringBuilder = SimplePool<StringBuilder>.Get();
stringBuilder.Clear();

if (building.storageGroup != null)
AppendLinkedStorageSettings(building, text, stringBuilder);
if (building is IStorageGroupMember { Group: { } group })
AppendLinkedStorageSettings(group, text, stringBuilder);

if (!text.NullOrEmpty() || stringBuilder.Length > 0)
stringBuilder.Append('\n');

var storedThings = building.StoredThings();

text += AppendCount(storedThings.Count > 0
text += AppendCount(storedThings.Length > 0
? AppendStoredThings(stringBuilder, storedThings)
: stringBuilder.Append(Strings.TranslatedWithBackup.Empty.CapitalizeFirst()), building, storedThings)
.ToString();
Expand Down Expand Up @@ -77,14 +77,14 @@ private static StringBuilder AppendStoredThings(StringBuilder stringBuilder, ILi
return stringBuilder;
}

private static void AppendLinkedStorageSettings(Building_Storage building, string text, StringBuilder stringBuilder)
private static void AppendLinkedStorageSettings(StorageGroup group, string text, StringBuilder stringBuilder)
{
if (!text.NullOrEmpty())
stringBuilder.Append('\n');

stringBuilder.Append(Strings.Translated.LinkedStorageSettings)
.Append(": ")
.Append(Strings.Translated.NumBuildings.Formatted(building.storageGroup.MemberCount).CapitalizeFirst());
.Append(Strings.Translated.NumBuildings.Formatted(group.MemberCount).CapitalizeFirst());
}

private static Func<ThingWithComps, string> _thingWithCompsGetInspectString
Expand Down
24 changes: 19 additions & 5 deletions Source/ItemGraphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public Vector3
drawOffset;

public Vector3?
stackOffsetNorth,
stackOffsetEast,
stackOffsetSouth,
stackOffsetWest,
drawOffsetNorth,
drawOffsetEast,
drawOffsetSouth,
Expand Down Expand Up @@ -72,13 +76,23 @@ public void LoadDataFromXmlCustom(XmlNode xmlRoot)
}
}

public Vector3 StackOffsetForRot(Rot4 rot)
=> rot.AsInt switch
{
Rot4.NorthInt => stackOffsetNorth,
Rot4.EastInt => stackOffsetEast,
Rot4.SouthInt => stackOffsetSouth,
Rot4.WestInt => stackOffsetWest,
_ => stackOffset
} ?? stackOffset;

public Vector3 DrawOffsetForRot(Rot4 rot)
=> rot.AsInt switch
{
0 => drawOffsetNorth ?? drawOffset,
1 => drawOffsetEast ?? drawOffset,
2 => drawOffsetSouth ?? drawOffset,
3 => drawOffsetWest ?? drawOffset,
Rot4.NorthInt => drawOffsetNorth,
Rot4.EastInt => drawOffsetEast,
Rot4.SouthInt => drawOffsetSouth,
Rot4.WestInt => drawOffsetWest,
_ => drawOffset
};
} ?? drawOffset;
}
4 changes: 2 additions & 2 deletions Source/LegacyStorageUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace AdaptiveStorage;

public static class LegacyStorageUtility
{
public static IList<Thing> StoredThings(this object? obj)
public static Thing[] StoredThings(this object? obj)
{
if (obj is ThingClass adaptive)
return adaptive.StoredThings;
return adaptive.StoredThings.ToArray();

var list = SimplePool<List<Thing>>.Get();
list.Clear();
Expand Down
10 changes: 6 additions & 4 deletions Source/ModCompatibility/PerformanceFish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ private static readonly MethodInfo?
_addToGroupListMethod
= Active
? AccessTools.DeclaredMethod("PerformanceFish.Listers.ThingsPrepatches:AddToGroupList")
?? throw new MissingMethodException("PerformanceFish.Listers.ThingsPrepatches:AddToGroupList")
: null,
_removeFromGroupListMethod
= Active
? AccessTools.DeclaredMethod("PerformanceFish.Listers.ThingsPrepatches:RemoveFromGroupList")
?? throw new MissingMethodException("PerformanceFish.Listers.ThingsPrepatches:RemoveFromGroupList")
: null;

private static readonly Action<ListerThings, Thing, ThingRequestGroup>?
_addToGroupListFunc
= Active && _addToGroupListMethod != null
? (Action<ListerThings, Thing, ThingRequestGroup>)_addToGroupListMethod.CreateDelegate(
= Active
? (Action<ListerThings, Thing, ThingRequestGroup>)_addToGroupListMethod!.CreateDelegate(
typeof(Action<ListerThings, Thing, ThingRequestGroup>))
: null,
_removeFromGroupListFunc
= Active && _removeFromGroupListMethod != null
? (Action<ListerThings, Thing, ThingRequestGroup>)_removeFromGroupListMethod.CreateDelegate(
= Active
? (Action<ListerThings, Thing, ThingRequestGroup>)_removeFromGroupListMethod!.CreateDelegate(
typeof(Action<ListerThings, Thing, ThingRequestGroup>))
: null;

Expand Down
9 changes: 6 additions & 3 deletions Source/ModCompatibility/ToggleableOverlays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ private static readonly MethodInfo? _checkMouseOverMethod
= Active
? AccessTools.DeclaredMethod("ToggleableOverlays.ToggleableOverlaysUtility:CheckMouseOver",
[typeof(Thing), typeof(bool), typeof(bool)])
?? throw new MissingMethodException(
"ToggleableOverlays.ToggleableOverlaysUtility:CheckMouseOver(Thing,bool,bool)")
: null;

private static readonly FieldInfo? _hideStorageBuildingField
= Active
? AccessTools.DeclaredField("ToggleableOverlays.ModSettings_ToggleableOverlays:hideStorageBuilding")
?? throw new MissingFieldException("ToggleableOverlays.ModSettings_ToggleableOverlays:hideStorageBuilding")
: null;

private static readonly Func<Thing, bool, bool, bool>? _checkMouseOverFunc
= Active && _checkMouseOverMethod != null
? (Func<Thing, bool, bool, bool>)_checkMouseOverMethod.CreateDelegate(typeof(Func<Thing, bool, bool, bool>))
= Active
? (Func<Thing, bool, bool, bool>)_checkMouseOverMethod!.CreateDelegate(typeof(Func<Thing, bool, bool, bool>))
: null;

private static readonly AccessTools.FieldRef<bool>? _hideStorageBuildingsFunc
= Active && _hideStorageBuildingField != null
= Active
? AccessTools.StaticFieldRefAccess<bool>(_hideStorageBuildingField)
: null;

Expand Down
Loading

0 comments on commit 67f178a

Please sign in to comment.