Skip to content

Commit

Permalink
1.2 and Allow Tool compatibility
Browse files Browse the repository at this point in the history
Fixed:
Allow Tool preventing setting custom hotkeys.
Gizmos not displaying multi-keybindings.
Only the first gizmo hotkey using the same final key would work.
  • Loading branch information
AzeTheGreat committed Jan 2, 2021
1 parent 900d69e commit d237ef2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 66 deletions.
Binary file added 1.2/Assemblies/Hotkeys.dll
Binary file not shown.
1 change: 1 addition & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<supportedVersions>
<li>1.0</li>
<li>1.1</li>
<li>1.2</li>
</supportedVersions>
<packageId>Aze.HotkeysDev</packageId>
<description>This mod adds keybindings to the Architect subtabs, direct hotkeys to access any designator, and the ability to create multi-keybindings.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Hotkeys
{
[HarmonyPatch(typeof(Command), nameof(Command.GizmoOnGUI))]
[HarmonyPatch(typeof(Command), "GizmoOnGUIInt")]
public class Patch_CheckGizmoKeybindings
{
static void Postfix(Command __instance)
Expand All @@ -18,6 +18,3 @@ static void Postfix(Command __instance)
}
}
}



2 changes: 1 addition & 1 deletion Source/Hotkeys/Command Hotkeys/Patch_ApplyGizmoHotkeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Hotkeys
{
[HarmonyPatch(typeof(Command), nameof(Command.GizmoOnGUI))]
[HarmonyPatch(typeof(Command), "GizmoOnGUIInt")]
class Patch_ApplyGizmoHotkeys
{
public static List<Command> newCommands = new List<Command>();
Expand Down
108 changes: 49 additions & 59 deletions Source/Hotkeys/Command Hotkeys/Patch_AssignGizmoKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,93 +7,83 @@

namespace Hotkeys
{
[HarmonyPatch(typeof(Command), nameof(Command.GizmoOnGUI))]
class Patch_AssignGizmoKey
[HarmonyPatch(typeof(Command), "GizmoOnGUIInt")]
static class Patch_AssignGizmoKey
{
[HarmonyPriority(Priority.First)]
static void Postfix(ref GizmoResult __result, Command __instance)
{
if (__result.State != GizmoState.OpenedFloatMenu) { return; }
if (!Hotkeys.settings.useCommandHotkeys) { return; }
if (!Hotkeys.settings.useCommandHotkeys || __result.State != GizmoState.OpenedFloatMenu)
return;

KeyBindingDef keyDef = DefDatabase<KeyBindingDef>.AllDefsListForReading.Find(x => x.defName == "Hotkeys_GizmoAssigner");
if (Event.current.button == 1 && keyDef.IsDown)
{
var options = new List<FloatMenuOption>();
bool alreadyDirect = DirectKeys.KeyPresent(__instance);
bool alreadyGizmo = GizmoKeys.KeyPresent(__instance);
Log.Message("PATCH Proceeds: " + __result.State);

if (!alreadyGizmo)
{
if (!alreadyDirect)
{
options.Add(new FloatMenuOption("Make Hotkey", delegate ()
{
MakeGizmoHotkey(__instance);
}));
}
}
var keyDef = DefDatabase<KeyBindingDef>.AllDefsListForReading.Find(x => x.defName == "Hotkeys_GizmoAssigner");
if (!(Event.current.button == 1 && keyDef.IsDown))
return;

if (!alreadyDirect && __instance is Designator)
{
if (!alreadyGizmo)
{
options.Add(new FloatMenuOption("Make Direct Hotkey", delegate ()
{
MakeDirectHotkey(__instance);
}));
}
}
var options = GetFloatMenuOptions(__instance);
var window = new FloatMenu(options, "Select Category", false);
Find.WindowStack.Add(window);
__result = new GizmoResult(GizmoState.Clear, null);
}

if (alreadyGizmo)
{
options.Add(new FloatMenuOption("Edit Key", delegate ()
{
var edit = new Dialog_EditKeySpecificity();
edit.Command = __instance;
Find.WindowStack.Add(edit);
}));
}
private static List<FloatMenuOption> GetFloatMenuOptions(Command __instance)
{
var options = new List<FloatMenuOption>();
bool alreadyDirect = DirectKeys.KeyPresent(__instance);
bool alreadyGizmo = GizmoKeys.KeyPresent(__instance);

if (alreadyGizmo || alreadyDirect)
{
options.Add(new FloatMenuOption("Clear Hotkey", delegate ()
{
ClearHotkey(__instance, alreadyDirect, alreadyGizmo);
}));
}

var window = new FloatMenu(options, "Select Category", false);
Find.WindowStack.Add(window);
if (!alreadyGizmo && !alreadyDirect)
{
options.Add(new FloatMenuOption("Make Hotkey", () => __instance.MakeGizmoHotkey()));
if (__instance is Designator)
options.Add(new FloatMenuOption("Make Direct Hotkey", () => __instance.MakeDirectHotkey()));
}

__result = new GizmoResult(GizmoState.Mouseover, null);
if (alreadyGizmo)
{
options.Add(new FloatMenuOption("Edit Key", () =>
{
var edit = new Dialog_EditKeySpecificity();
edit.Command = __instance;
Find.WindowStack.Add(edit);
}));
}

if (alreadyGizmo || alreadyDirect)
options.Add(new FloatMenuOption("Clear Hotkey", () => __instance.ClearHotkey()));

return options;
}

private static void MakeGizmoHotkey(Command __instance)
private static void MakeGizmoHotkey(this Command __instance)
{
GizmoKeys.AddKey(__instance);
Messages.Message("Gizmo Hotkey '" + __instance.LabelCap + "' added.", MessageTypeDefOf.TaskCompletion, false);
Message(__instance, "Gizmo", "added");
}

private static void MakeDirectHotkey(Command __instance)
private static void MakeDirectHotkey(this Command __instance)
{
DirectKeys.AddKey(__instance);
Messages.Message("Direct Hotkey '" + __instance.LabelCap + "' added.", MessageTypeDefOf.TaskCompletion, false);
Message(__instance, "Direct", "added");
}

private static void ClearHotkey(Command __instance, bool alreadyDirect, bool alreadyGizmo)
private static void ClearHotkey(this Command __instance)
{
if (alreadyDirect)
if (DirectKeys.KeyPresent(__instance))
{
DirectKeys.RemoveKey(__instance);
Messages.Message("Direct Hotkey '" + __instance.LabelCap + "' cleared.", MessageTypeDefOf.TaskCompletion, false);
Message(__instance, "Direct", "cleared");
}
if (alreadyGizmo)
if (GizmoKeys.KeyPresent(__instance))
{
GizmoKeys.RemoveKey(__instance);
Messages.Message("Gizmo Hotkey '" + __instance.LabelCap + "' cleared.", MessageTypeDefOf.TaskCompletion, false);
Message(__instance, "Gizmo", "cleared");
}
}

private static void Message(Command __instance, string keyType, string change) =>
Messages.Message(keyType + " Hotkey " + __instance.LabelCap + " " + change, MessageTypeDefOf.TaskCompletion, false);
}
}
3 changes: 2 additions & 1 deletion Source/Hotkeys/Hotkeys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\1.1\Assemblies\</OutputPath>
<OutputPath>..\..\1.2\Assemblies\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -37,6 +37,7 @@
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.0.6, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Lib.Harmony.2.0.0.6\lib\net472\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion Source/Hotkeys/Multi Keys/Trans_GizmoRenderKeyMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Hotkeys
{
// Transpiler to show multi key labels
[HarmonyPatch(typeof(Command), nameof(Command.GizmoOnGUI))]
[HarmonyPatch(typeof(Command), "GizmoOnGUIInt")]
public class Trans_GizmoRenderKeyMods
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
Expand Down

0 comments on commit d237ef2

Please sign in to comment.