Skip to content

Commit

Permalink
v2.3.1 works with RimWorld 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Apr 10, 2024
1 parent 107342a commit b7506c8
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 95 deletions.
Binary file modified 1.4/Assemblies/CrossPromotion.dll
Binary file not shown.
Binary file added 1.5/Assemblies/CrossPromotion.dll
Binary file not shown.
Binary file added 1.5/Assemblies/ReverseCommands.dll
Binary file not shown.
45 changes: 24 additions & 21 deletions About/About.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<ModMetaData>
<name>Reverse Commands</name>
<author>Andreas Pardeike</author>
<supportedVersions>
<li>1.0</li>
<li>1.1</li>
<li>1.2</li>
<li>1.3</li>
<li>1.4</li>
</supportedVersions>
<modDependencies>
<li>
<packageId>brrainz.harmony</packageId>
<displayName>Harmony</displayName>
<steamWorkshopUrl>steam://url/CommunityFilePage/2009463077</steamWorkshopUrl>
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li>
</modDependencies>
<packageId>brrainz.reversecommands</packageId>
<description>Reverses the context menu so you can select something to interact with, followed by an action and the colonist that should execute that action. No need to select colonists first and much less scrolling through the map.
<name>Reverse Commands</name>
<author>Andreas Pardeike</author>
<supportedVersions>
<li>1.0</li>
<li>1.1</li>
<li>1.2</li>
<li>1.3</li>
<li>1.4</li>
<li>1.5</li>
</supportedVersions>
<modDependencies>
<li>
<packageId>brrainz.harmony</packageId>
<displayName>Harmony</displayName>
<steamWorkshopUrl>steam://url/CommunityFilePage/2009463077</steamWorkshopUrl>
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li>
</modDependencies>
<packageId>brrainz.reversecommands</packageId>
<modVersion>2.3.1.0</modVersion>
<steamAppId>858744731</steamAppId>
<description>Reverses the context menu so you can select something to interact with, followed by an action and the colonist that should execute that action. No need to select colonists first and much less scrolling through the map.

Powered by Harmony Patch Library

Andreas Pardeike
Email: andreas@pardeike.net
Steam: pardeike
Twitter: @pardeike</description>
</ModMetaData>
</ModMetaData>
3 changes: 2 additions & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>net.pardeike.rimworld.mod.reversecommands</identifier>
<version>2.3.0.0</version>
<version>2.3.1.0</version>
<targetVersions>
<li>1.0.0</li>
<li>1.1.0</li>
<li>1.2.0</li>
<li>1.3.0</li>
<li>1.4.0</li>
<li>1.5.0</li>
</targetVersions>
<dependencies>
</dependencies>
Expand Down
11 changes: 11 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>

<PropertyGroup>
<ModName>Reverse Commands</ModName>
<ModFileName>ReverseCommands</ModFileName>
<Repository>https://github.com/pardeike/ReverseCommands</Repository>
<ModVersion>2.3.1.0</ModVersion>
<ProjectGuid>{7B65D4DA-B570-401B-A0C3-EECCDC285677}</ProjectGuid>
</PropertyGroup>

</Project>
4 changes: 4 additions & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
<li>/</li>
<li>1.4</li>
</v1.4>
<v1.5>
<li>/</li>
<li>1.5</li>
</v1.5>
</loadFolders>
10 changes: 2 additions & 8 deletions Source/FloatMenuColonists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@ public override void PostClose()
}
}

public class FloatMenuOptionPawn : FloatMenuOption
public class FloatMenuOptionPawn(Pawn pawn, Action action, MenuOptionPriority priority, Action<Rect> mouseOverAction) : FloatMenuOption("", action, priority, mouseOverAction, null, 0, null, null)
{
public Pawn pawn;

public FloatMenuOptionPawn(Pawn pawn, Action action, MenuOptionPriority priority, Action<Rect> mouseOverAction)
: base("", action, priority, mouseOverAction, null, 0, null, null)
{
this.pawn = pawn;
}
public Pawn pawn = pawn;

public override bool DoGUI(Rect rect, bool colonistOrdering, FloatMenu floatMenu)
{
Expand Down
5 changes: 1 addition & 4 deletions Source/FloatMenuLabels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ public FloatMenuLabels(List<FloatMenuOption> options) : base(options, null, fals
}
}

public class FloatMenuOptionNoClose : FloatMenuOption
public class FloatMenuOptionNoClose(string label, Action action) : FloatMenuOption(label, action, MenuOptionPriority.Default, null, null, 0, null, null)
{
public FloatMenuOptionNoClose(string label, Action action)
: base(label, action, MenuOptionPriority.Default, null, null, 0, null, null) { }

public override bool DoGUI(Rect rect, bool colonistOrdering, FloatMenu floatMenu)
{
_ = base.DoGUI(rect, colonistOrdering, floatMenu);
Expand Down
23 changes: 15 additions & 8 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void Prefix()
if (PathInfo.current != null)
{
var path = PathInfo.GetPath(PathInfo.current);
if (path != null) path.DrawPath(null);
path?.DrawPath(null);
}
PathInfo.current = null;
}
Expand All @@ -59,10 +59,13 @@ class MainTabsRoot_HandleLowPriorityShortcuts_Patch
{
public static bool Prefix()
{
if (WorldRendererUtility.WorldRenderedNow) return true;
if (Event.current.type != EventType.MouseDown) return true;
if (WorldRendererUtility.WorldRenderedNow)
return true;
if (Event.current.type != EventType.MouseDown)
return true;
Tools.CloseLabelMenu(true);
if (Event.current.button != 1) return true;
if (Event.current.button != 1)
return true;
return !Tools.GetPawnActions().Any();
}
}
Expand All @@ -72,16 +75,20 @@ class Selector_HandleMapClicks_Patch
{
public static bool Prefix()
{
if (WorldRendererUtility.WorldRenderedNow) return true;
if (WorldRendererUtility.WorldRenderedNow)
return true;

if (Event.current.isKey && Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
Tools.CloseLabelMenu(true);

if (Event.current.type != EventType.MouseDown) return true;
if (Event.current.button != 1) return true;
if (Event.current.type != EventType.MouseDown)
return true;
if (Event.current.button != 1)
return true;

var labeledPawnActions = Tools.GetPawnActions();
if (!labeledPawnActions.Any()) return true;
if (!labeledPawnActions.Any())
return true;

var cell = UI.MouseCell();
Find.CurrentMap.mapPawns.FreeColonists.Where(Tools.PawnUsable).Do(pawn => PathInfo.AddInfo(pawn, cell));
Expand Down
38 changes: 17 additions & 21 deletions Source/PathInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

namespace ReverseCommands
{
public class PathInfo
public class PathInfo(Pawn pawn, IntVec3 cell)
{
public static Pawn current;
static readonly Dictionary<Pawn, PathInfo> storage = new Dictionary<Pawn, PathInfo>();
static readonly Dictionary<Pawn, PathInfo> storage = [];

public static List<Pawn> GetPawns()
{
return storage.Keys.ToList();
return [.. storage.Keys];
}

public static void AddInfo(Pawn pawn, IntVec3 cell)
Expand All @@ -26,15 +26,18 @@ public static void AddInfo(Pawn pawn, IntVec3 cell)
public static PawnPath GetPath(Pawn pawn)
{
var val = storage.GetValueSafe(pawn);
if (val == null) return null;
if (val == null)
return null;
return val.GetPath();
}

public static string GetJobReport(Pawn pawn)
{
if (pawn == null) return "";
if (pawn == null)
return "";
var val = storage.GetValueSafe(pawn);
if (val == null) return "";
if (val == null)
return "";
return val.GetJobReport();
}

Expand All @@ -47,34 +50,25 @@ public static void Clear()
if (info != null)
{
var path = info.path;
if (path != null) path.ReleaseToPool();
path?.ReleaseToPool();
}
});
storage.Clear();
}

public Pawn pawn;
public IntVec3 cell;
public Pawn pawn = pawn;
public IntVec3 cell = cell;

public PawnPath path;
public IntVec3 lastPawnLocation = IntVec3.Invalid;

//public string jobDescription;
//public Job lastJob;

public PathInfo(Pawn pawn, IntVec3 cell)
{
this.pawn = pawn;
this.cell = cell;
}

public PawnPath GetPath()
{
var pos = pawn.Position;
if (lastPawnLocation != pos)
{
var traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassDoors, false);
if (path != null) path.ReleaseToPool();
path?.ReleaseToPool();
path = pawn.Map.pathFinder.FindPath(pawn.Position, cell, traverseParams, PathEndMode.Touch);
lastPawnLocation = pos;
}
Expand All @@ -85,9 +79,11 @@ public string GetJobReport()
{
var m = Math.Floor(GetPath(pawn).TotalCost * 60f / GenDate.TicksPerHour);
var mins = "";
if (m > 0) mins = ", [" + m + " min]";
if (m > 0)
mins = ", [" + m + " min]";
var job = pawn.jobs.curJob != null ? (", " + pawn.jobs.curDriver.GetReport()) : "";
if (job.EndsWith(".", StringComparison.Ordinal)) job = job.Substring(0, job.Length - 1);
if (job.EndsWith(".", StringComparison.Ordinal))
job = job.Substring(0, job.Length - 1);
return pawn.Name.ToStringShort + job + mins;
}
}
Expand Down
87 changes: 57 additions & 30 deletions Source/ReverseCommands.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ProjectGuid>{7B65D4DA-B570-401B-A0C3-EECCDC285677}</ProjectGuid>
<RootNamespace>ReverseCommands</RootNamespace>
<AssemblyName>ReverseCommands</AssemblyName>
<RootNamespace>$(ModFileName)</RootNamespace>
<AssemblyName>$(ModFileName)</AssemblyName>
<TargetFramework>net472</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<PlatformTarget>x64</PlatformTarget>
<OutputPath>..\1.4\Assemblies\</OutputPath>
<OutputPath>..\1.5\Assemblies\</OutputPath>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<Version>2.3.0.0</Version>
<Version>$(ModVersion)</Version>
<AssemblyVersion>$(ModVersion)</AssemblyVersion>
<FileVersion>$(ModVersion)</FileVersion>
<PackageVersion>$(ModVersion)</PackageVersion>
<InformationalVersion>$(ModVersion)</InformationalVersion>
<Company>Brrainz</Company>
<Authors>Andreas Pardeike</Authors>
<Copyright>Copyright Andreas Pardeike</Copyright>
<PackageProjectUrl>$(Repository)</PackageProjectUrl>
<RepositoryUrl>$(Repository)</RepositoryUrl>
<Product>$(ModName)</Product>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand All @@ -30,10 +38,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Brrainz.RimWorld.CrossPromotion" Version="1.0.0" />
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.4.3521-beta" GeneratePathProperty="true" />
<PackageReference Include="Lib.Harmony" Version="2.2.2" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="6.0.6" />
<Content Include="..\Directory.Build.props">
<Link>%(Filename)%(Extension)</Link>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Brrainz.RimWorld.CrossPromotion" Version="1.1.2" />
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.5.4060-beta" GeneratePathProperty="true" />
<PackageReference Include="Lib.Harmony" Version="2.3.3.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net472" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down Expand Up @@ -67,24 +81,37 @@
</ItemGroup>
</Target>

<PropertyGroup>
<PostBuildEvent>
echo Postprocessing
where ModBuilder 2&gt; nul | find /i "ModBuilder.exe"
if not errorlevel 1 (
ModBuilder AssemblyVersion -file "$(MSBuildProjectDirectory)\$(OutputPath)$(AssemblyName).dll" -save "$(MSBuildProjectName)-version"
ModBuilder XMLPut -file "$(MSBuildProjectDirectory)\..\About\Manifest.xml" -xpath /Manifest/version -value "{{$(MSBuildProjectName)-version}}"
)
if defined INSTALL_MOD (
"%INSTALL_MOD%" "$(Configuration)" "$(MSBuildProjectDirectory)\..\" "$(MSBuildProjectName)" "1.2 1.3 1.4 About Assemblies" "LoadFolders.xml"
)
</PostBuildEvent>
<Company>Brrainz</Company>
<Authors>Andreas Pardeike</Authors>
<Description></Description>
<PackageProjectUrl>https://github.com/pardeike/ReverseCommands</PackageProjectUrl>
<RepositoryUrl>https://github.com/pardeike/ReverseCommands</RepositoryUrl>
<Product>Reverse Commands</Product>
</PropertyGroup>
<Target Name="PostBuildAction" AfterTargets="Build">
<XmlPoke XmlInputPath="$(MSBuildProjectDirectory)\..\About\About.xml" Query="//ModMetaData/modVersion" Value="$(ModVersion)" />
<XmlPoke XmlInputPath="$(MSBuildProjectDirectory)\..\About\Manifest.xml" Query="//Manifest/version" Value="$(ModVersion)" />
</Target>

<Target Name="CopyToRimworld" AfterTargets="PostBuildAction" Condition="'$(RIMWORLD_MOD_DIR)' != ''">
<RemoveDir Directories="$(RIMWORLD_MOD_DIR)\$(ModFileName)" />
<ItemGroup>
<Copy_12 Include="..\1.2\**" />
<Copy_13 Include="..\1.3\**" />
<Copy_14 Include="..\1.4\**" />
<Copy_15 Include="..\1.5\**" />
<CopyAbout Include="..\About\**" />
<CopyAssemblies Include="..\Assemblies\**" />
<CopyLicense Include="..\LICENSE" />
<CopyLoadFolders Include="..\LoadFolders.xml" />
<CopyReadme Include="..\Readme.md" />
</ItemGroup>
<Copy SourceFiles="@(Copy_12)" DestinationFolder="$(RIMWORLD_MOD_DIR)\$(ModFileName)\1.2\%(RecursiveDir)" />
<Copy SourceFiles="@(Copy_13)" DestinationFolder="$(RIMWORLD_MOD_DIR)\$(ModFileName)\1.3\%(RecursiveDir)" />
<Copy SourceFiles="@(Copy_14)" DestinationFolder="$(RIMWORLD_MOD_DIR)\$(ModFileName)\1.4\%(RecursiveDir)" />
<Copy SourceFiles="@(Copy_15)" DestinationFolder="$(RIMWORLD_MOD_DIR)\$(ModFileName)\1.5\%(RecursiveDir)" />
<Copy SourceFiles="@(CopyAbout)" DestinationFolder="$(RIMWORLD_MOD_DIR)\$(ModFileName)\About\%(RecursiveDir)" />
<Copy SourceFiles="@(CopyAssemblies)" DestinationFolder="$(RIMWORLD_MOD_DIR)\$(ModFileName)\Assemblies\%(RecursiveDir)" />
<Copy SourceFiles="@(CopyLicense)" DestinationFolder="$(RIMWORLD_MOD_DIR)\$(ModFileName)" />
<Copy SourceFiles="@(CopyLoadFolders)" DestinationFolder="$(RIMWORLD_MOD_DIR)\$(ModFileName)" />
<Copy SourceFiles="@(CopyReadme)" DestinationFolder="$(RIMWORLD_MOD_DIR)\$(ModFileName)" />
</Target>

<Target Name="ZipMod" AfterTargets="CopyToRimworld" Condition="'$(RIMWORLD_MOD_DIR)' != ''">
<ZipDirectory SourceDirectory="$(RIMWORLD_MOD_DIR)\$(ModFileName)" DestinationFile="$(RIMWORLD_MOD_DIR)\$(ModFileName).zip" Overwrite="true" />
</Target>

</Project>
</Project>
4 changes: 2 additions & 2 deletions Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class Tools
public static FloatMenuLabels labelMenu;
public static FloatMenuColonists actionMenu;

public static Dictionary<Pawn, PathInfo> PawnInfo = new Dictionary<Pawn, PathInfo>();
public static Dictionary<Pawn, PathInfo> PawnInfo = [];

public static void CloseLabelMenu(bool sound)
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public static Dictionary<string, Dictionary<Pawn, FloatMenuOption>> GetPawnActio
var dict = result.GetValueSafe(option.Label);
if (dict == null)
{
dict = new Dictionary<Pawn, FloatMenuOption>();
dict = [];
result[option.Label] = dict;
}
dict[pawn] = option;
Expand Down

0 comments on commit b7506c8

Please sign in to comment.