Skip to content

Commit 747f24d

Browse files
author
Lockdown
committed
A14 release
1 parent ae17ddf commit 747f24d

8 files changed

Lines changed: 286 additions & 0 deletions

File tree

About/About.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ModMetaData>
3+
<name>Animal Keybinds</name>
4+
<author>Lockdown</author>
5+
<targetVersion>0.14.1249</targetVersion>
6+
<description>
7+
New keybinds to cycle through tamed animals. (Default 'Home' and 'End')
8+
</description>
9+
</ModMetaData>

Assemblies/AnimalKeybinds.dll

20 KB
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<KeyBindingCategoryDefs>
3+
4+
<KeyBindingCategoryDef>
5+
<defName>AnimalKeybinds</defName>
6+
<label>Animal Keybinds</label>
7+
<description>Keybinds for animals.</description>
8+
</KeyBindingCategoryDef>
9+
10+
</KeyBindingCategoryDefs>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<KeyBindingDefs>
3+
4+
<KeyBindingDef Name="GameMapKeyBinding" Abstract="true">
5+
<category>AnimalKeybinds</category>
6+
</KeyBindingDef>
7+
8+
<KeyBindingDef ParentName="GameMapKeyBinding">
9+
<defName>PreviousAnimal</defName>
10+
<label>Previous Animal</label>
11+
<defaultKeyCodeA>Home</defaultKeyCodeA>
12+
</KeyBindingDef>
13+
14+
<KeyBindingDef ParentName="GameMapKeyBinding">
15+
<defName>NextAnimal</defName>
16+
<label>Next Animal</label>
17+
<defaultKeyCodeA>End</defaultKeyCodeA>
18+
</KeyBindingDef>
19+
20+
</KeyBindingDefs>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
3+
<PropertyGroup>
4+
<ProjectGuid>{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}</ProjectGuid>
5+
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<OutputType>Library</OutputType>
9+
<RootNamespace>AnimalKeybinds</RootNamespace>
10+
<AssemblyName>AnimalKeybinds</AssemblyName>
11+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
12+
<AppDesignerFolder>Properties</AppDesignerFolder>
13+
<TargetFrameworkProfile />
14+
<NoWin32Manifest>False</NoWin32Manifest>
15+
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
16+
<NoStdLib>False</NoStdLib>
17+
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
18+
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
19+
<WarningLevel>4</WarningLevel>
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
22+
<PlatformTarget>AnyCPU</PlatformTarget>
23+
<BaseAddress>4194304</BaseAddress>
24+
<RegisterForComInterop>False</RegisterForComInterop>
25+
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
26+
<FileAlignment>4096</FileAlignment>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
29+
<OutputPath>..\..\Assemblies\</OutputPath>
30+
<DebugSymbols>True</DebugSymbols>
31+
<DebugType>None</DebugType>
32+
<Optimize>False</Optimize>
33+
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
34+
<DefineConstants>DEBUG;TRACE</DefineConstants>
35+
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
36+
</PropertyGroup>
37+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
38+
<OutputPath>bin\Release\</OutputPath>
39+
<DebugSymbols>False</DebugSymbols>
40+
<DebugType>None</DebugType>
41+
<Optimize>True</Optimize>
42+
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
43+
<DefineConstants>TRACE</DefineConstants>
44+
</PropertyGroup>
45+
<ItemGroup>
46+
<Reference Include="Assembly-CSharp">
47+
<HintPath>..\..\..\..\RimWorld1249Win_Data\Managed\Assembly-CSharp.dll</HintPath>
48+
<Private>False</Private>
49+
</Reference>
50+
<Reference Include="System" />
51+
<Reference Include="System.Core">
52+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
53+
</Reference>
54+
<Reference Include="System.Xml" />
55+
<Reference Include="System.Xml.Linq">
56+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
57+
</Reference>
58+
<Reference Include="UnityEngine">
59+
<HintPath>..\..\..\..\RimWorld1249Win_Data\Managed\UnityEngine.dll</HintPath>
60+
<Private>False</Private>
61+
</Reference>
62+
</ItemGroup>
63+
<ItemGroup>
64+
<Compile Include="AnimalKeybindsMapComponent.cs" />
65+
<Compile Include="Properties\AssemblyInfo.cs" />
66+
</ItemGroup>
67+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
68+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimalKeybinds", "AnimalKeybinds.csproj", "{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
using RimWorld;
2+
using System;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
using UnityEngine;
9+
using Verse;
10+
11+
namespace AnimalKeybinds
12+
{
13+
public class AnimalKeybindsMapComponent : MapComponent
14+
{
15+
16+
private KeyBindingDef previousAnimalKey = KeyBindingDef.Named("PreviousAnimal");
17+
private KeyBindingDef nextAnimalKey = KeyBindingDef.Named("NextAnimal");
18+
private MethodInfo remoteSingleSelectAndJumpTo;
19+
private List<object> remoteSelected;
20+
21+
public override void MapComponentUpdate()
22+
{
23+
24+
if (previousAnimalKey.KeyDownEvent)
25+
{
26+
SelectPreviousAnimal();
27+
}
28+
else if (nextAnimalKey.KeyDownEvent)
29+
{
30+
SelectNextAnimal();
31+
}
32+
33+
34+
}
35+
36+
public void getRemoteFieldsIfNeeded()
37+
{
38+
//retrieving private Core methods
39+
if (remoteSingleSelectAndJumpTo == null)
40+
{
41+
remoteSingleSelectAndJumpTo = typeof(Selector).GetMethod("SingleSelectAndJumpTo", BindingFlags.Instance | BindingFlags.NonPublic);
42+
}
43+
44+
//retrieving private Core fields
45+
if (remoteSelected == null)
46+
{
47+
remoteSelected = (List<object>) typeof(Selector).GetField("selected", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Find.Selector); //null because this is a static class. Would need an instance object of HealthCardUtility otherwise.
48+
}
49+
}
50+
51+
public List<Pawn> getAnimalsList()
52+
{
53+
IEnumerable<Pawn> sorted = from p in Find.MapPawns.PawnsInFaction(Faction.OfPlayer)
54+
where p.RaceProps.Animal
55+
orderby p.RaceProps.petness descending, p.RaceProps.baseBodySize, p.def.label
56+
select p;
57+
return sorted.ToList();
58+
}
59+
60+
public void SelectPreviousAnimal()
61+
{
62+
getRemoteFieldsIfNeeded();
63+
List<Pawn> list = getAnimalsList();
64+
65+
66+
if (list.Count == 0)
67+
{
68+
return;
69+
}
70+
int num = -1;
71+
for (int i = 0; i < this.remoteSelected.Count; i++)
72+
{
73+
Pawn pawn = this.remoteSelected[i] as Pawn;
74+
if (pawn != null)
75+
{
76+
num = Mathf.Max(num, list.IndexOf(pawn));
77+
}
78+
}
79+
if (num == -1)
80+
{
81+
//this.SingleSelectAndJumpTo(list[list.Count - 1]);
82+
remoteSingleSelectAndJumpTo.Invoke(Find.Selector, new object[] { list[list.Count - 1] });
83+
}
84+
else
85+
{
86+
num--;
87+
if (num < 0)
88+
{
89+
num += list.Count;
90+
}
91+
//this.SingleSelectAndJumpTo(list[num]);
92+
remoteSingleSelectAndJumpTo.Invoke(Find.Selector, new object[] { list[num] });
93+
}
94+
}
95+
96+
public void SelectNextAnimal()
97+
{
98+
getRemoteFieldsIfNeeded();
99+
List<Pawn> list = getAnimalsList();
100+
101+
if (list.Count == 0)
102+
{
103+
return;
104+
}
105+
int num = -1;
106+
for (int i = 0; i < this.remoteSelected.Count; i++)
107+
{
108+
Pawn pawn = this.remoteSelected[i] as Pawn;
109+
if (pawn != null)
110+
{
111+
num = Mathf.Max(num, list.IndexOf(pawn));
112+
}
113+
}
114+
if (num == -1)
115+
{
116+
//Find.Selector.SingleSelectAndJumpTo(list[0]);
117+
remoteSingleSelectAndJumpTo.Invoke(Find.Selector, new object[] { list[0] });
118+
}
119+
else
120+
{
121+
//this.SingleSelectAndJumpTo(list[(num + 1) % list.Count]);
122+
remoteSingleSelectAndJumpTo.Invoke(Find.Selector, new object[] { list[(num + 1) % list.Count] });
123+
}
124+
}
125+
}
126+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#region Using directives
2+
3+
using System;
4+
using System.Reflection;
5+
using System.Runtime.InteropServices;
6+
7+
#endregion
8+
9+
// General Information about an assembly is controlled through the following
10+
// set of attributes. Change these attribute values to modify the information
11+
// associated with an assembly.
12+
[assembly: AssemblyTitle("AnimalKeybinds")]
13+
[assembly: AssemblyDescription("")]
14+
[assembly: AssemblyConfiguration("")]
15+
[assembly: AssemblyCompany("")]
16+
[assembly: AssemblyProduct("AnimalKeybinds")]
17+
[assembly: AssemblyCopyright("Copyright 2016")]
18+
[assembly: AssemblyTrademark("")]
19+
[assembly: AssemblyCulture("")]
20+
21+
// This sets the default COM visibility of types in the assembly to invisible.
22+
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
23+
[assembly: ComVisible(false)]
24+
25+
// The assembly version has following format :
26+
//
27+
// Major.Minor.Build.Revision
28+
//
29+
// You can specify all the values or you can use the default the Revision and
30+
// Build Numbers by using the '*' as shown below:
31+
[assembly: AssemblyVersion("1.0.*")]

0 commit comments

Comments
 (0)