Skip to content

Commit

Permalink
A14 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockdown committed Aug 31, 2016
1 parent ae17ddf commit 747f24d
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 0 deletions.
9 changes: 9 additions & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ModMetaData>
<name>Animal Keybinds</name>
<author>Lockdown</author>
<targetVersion>0.14.1249</targetVersion>
<description>
New keybinds to cycle through tamed animals. (Default 'Home' and 'End')
</description>
</ModMetaData>
Binary file added Assemblies/AnimalKeybinds.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions Defs/KeyBindingCategoryDefs/KeyBindingCategories.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<KeyBindingCategoryDefs>

<KeyBindingCategoryDef>
<defName>AnimalKeybinds</defName>
<label>Animal Keybinds</label>
<description>Keybinds for animals.</description>
</KeyBindingCategoryDef>

</KeyBindingCategoryDefs>
20 changes: 20 additions & 0 deletions Defs/KeyBindingDefs/KeyBindings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<KeyBindingDefs>

<KeyBindingDef Name="GameMapKeyBinding" Abstract="true">
<category>AnimalKeybinds</category>
</KeyBindingDef>

<KeyBindingDef ParentName="GameMapKeyBinding">
<defName>PreviousAnimal</defName>
<label>Previous Animal</label>
<defaultKeyCodeA>Home</defaultKeyCodeA>
</KeyBindingDef>

<KeyBindingDef ParentName="GameMapKeyBinding">
<defName>NextAnimal</defName>
<label>Next Animal</label>
<defaultKeyCodeA>End</defaultKeyCodeA>
</KeyBindingDef>

</KeyBindingDefs>
68 changes: 68 additions & 0 deletions Source/AnimalKeybinds/AnimalKeybinds.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>AnimalKeybinds</RootNamespace>
<AssemblyName>AnimalKeybinds</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworkProfile />
<NoWin32Manifest>False</NoWin32Manifest>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<BaseAddress>4194304</BaseAddress>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>..\..\Assemblies\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\RimWorld1249Win_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\RimWorld1249Win_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AnimalKeybindsMapComponent.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
22 changes: 22 additions & 0 deletions Source/AnimalKeybinds/AnimalKeybinds.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimalKeybinds", "AnimalKeybinds.csproj", "{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8D24DDF-633D-4BE5-BE0B-5B3B23409C2F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
126 changes: 126 additions & 0 deletions Source/AnimalKeybinds/AnimalKeybindsMapComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using RimWorld;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using UnityEngine;
using Verse;

namespace AnimalKeybinds
{
public class AnimalKeybindsMapComponent : MapComponent
{

private KeyBindingDef previousAnimalKey = KeyBindingDef.Named("PreviousAnimal");
private KeyBindingDef nextAnimalKey = KeyBindingDef.Named("NextAnimal");
private MethodInfo remoteSingleSelectAndJumpTo;
private List<object> remoteSelected;

public override void MapComponentUpdate()
{

if (previousAnimalKey.KeyDownEvent)
{
SelectPreviousAnimal();
}
else if (nextAnimalKey.KeyDownEvent)
{
SelectNextAnimal();
}


}

public void getRemoteFieldsIfNeeded()
{
//retrieving private Core methods
if (remoteSingleSelectAndJumpTo == null)
{
remoteSingleSelectAndJumpTo = typeof(Selector).GetMethod("SingleSelectAndJumpTo", BindingFlags.Instance | BindingFlags.NonPublic);
}

//retrieving private Core fields
if (remoteSelected == null)
{
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.
}
}

public List<Pawn> getAnimalsList()
{
IEnumerable<Pawn> sorted = from p in Find.MapPawns.PawnsInFaction(Faction.OfPlayer)
where p.RaceProps.Animal
orderby p.RaceProps.petness descending, p.RaceProps.baseBodySize, p.def.label
select p;
return sorted.ToList();
}

public void SelectPreviousAnimal()
{
getRemoteFieldsIfNeeded();
List<Pawn> list = getAnimalsList();


if (list.Count == 0)
{
return;
}
int num = -1;
for (int i = 0; i < this.remoteSelected.Count; i++)
{
Pawn pawn = this.remoteSelected[i] as Pawn;
if (pawn != null)
{
num = Mathf.Max(num, list.IndexOf(pawn));
}
}
if (num == -1)
{
//this.SingleSelectAndJumpTo(list[list.Count - 1]);
remoteSingleSelectAndJumpTo.Invoke(Find.Selector, new object[] { list[list.Count - 1] });
}
else
{
num--;
if (num < 0)
{
num += list.Count;
}
//this.SingleSelectAndJumpTo(list[num]);
remoteSingleSelectAndJumpTo.Invoke(Find.Selector, new object[] { list[num] });
}
}

public void SelectNextAnimal()
{
getRemoteFieldsIfNeeded();
List<Pawn> list = getAnimalsList();

if (list.Count == 0)
{
return;
}
int num = -1;
for (int i = 0; i < this.remoteSelected.Count; i++)
{
Pawn pawn = this.remoteSelected[i] as Pawn;
if (pawn != null)
{
num = Mathf.Max(num, list.IndexOf(pawn));
}
}
if (num == -1)
{
//Find.Selector.SingleSelectAndJumpTo(list[0]);
remoteSingleSelectAndJumpTo.Invoke(Find.Selector, new object[] { list[0] });
}
else
{
//this.SingleSelectAndJumpTo(list[(num + 1) % list.Count]);
remoteSingleSelectAndJumpTo.Invoke(Find.Selector, new object[] { list[(num + 1) % list.Count] });
}
}
}
}
31 changes: 31 additions & 0 deletions Source/AnimalKeybinds/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#region Using directives

using System;
using System.Reflection;
using System.Runtime.InteropServices;

#endregion

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AnimalKeybinds")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AnimalKeybinds")]
[assembly: AssemblyCopyright("Copyright 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]

// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]

0 comments on commit 747f24d

Please sign in to comment.