Skip to content

Commit

Permalink
Gear gizmo only for controlled pawns, how long has this been showing …
Browse files Browse the repository at this point in the history
…for enemies ... ?

Also static global for the gamecomp.
Also  command for some reason.
  • Loading branch information
alextd committed Sep 25, 2023
1 parent 920da89 commit 07a3aa7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
10 changes: 0 additions & 10 deletions Patches/GearUpAndGoPatches.xml

This file was deleted.

4 changes: 2 additions & 2 deletions Source/Alert_GearedUp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public Alert_GearedUp()

public override AlertReport GetReport()
{
return Current.Game.GetComponent<GearUpPolicyComp>().IsOn();
return GearUpPolicyComp.comp.IsOn();
}

private const float Padding = 6f;
Expand All @@ -34,7 +34,7 @@ public override Rect DrawAt(float topY, bool minimized)
}
if (Widgets.ButtonInvisible(rect, false))
{
Current.Game.GetComponent<GearUpPolicyComp>().Revert();
GearUpPolicyComp.comp.Revert();
}
return rect;
}
Expand Down
31 changes: 22 additions & 9 deletions Source/GearUpAndGizGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using RimWorld;
using Verse.Sound;
using Verse.AI;
using HarmonyLib;

namespace GearUpAndGo
{
Expand All @@ -30,7 +31,7 @@ public static void Go(LocalTargetInfo target, string policy)
Log.Message($"GearUpAndGo to {target}, setting {policy}");

if (!Event.current.alt)
Current.Game.GetComponent<GearUpPolicyComp>().Set(policy);
GearUpPolicyComp.comp.Set(policy);

foreach (Pawn p in Find.Selector.SelectedObjects
.Where(o => o is Pawn p && p.IsColonistPlayerControlled).Cast<Pawn>())
Expand All @@ -41,14 +42,14 @@ public static void Go(LocalTargetInfo target, string policy)

public static void End()
{
Current.Game.GetComponent<GearUpPolicyComp>().Revert();
GearUpPolicyComp.comp.Revert();
}

public override void ProcessInput(Event ev)
{
base.ProcessInput(ev);
SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(null);
if (ev.shift && Current.Game.GetComponent<GearUpPolicyComp>().IsOn())
if (ev.shift && GearUpPolicyComp.comp.IsOn())
End();
else
Target();
Expand All @@ -75,9 +76,13 @@ public class TexGearUpAndGo

public class GearUpPolicyComp : GameComponent
{
public static GearUpPolicyComp comp;

public string lastPolicy = "";

public GearUpPolicyComp(Game game) { }
public GearUpPolicyComp(Game game) {
comp = this;
}

public override void ExposeData()
{
Expand Down Expand Up @@ -106,18 +111,26 @@ public bool IsOn()
}
}

public class CompGearUpAndGizGo : ThingComp

[HarmonyPatch(typeof(Pawn), nameof(Pawn.GetGizmos))]
public static class GearUpAndGizGo
{
public override IEnumerable<Gizmo> CompGetGizmosExtra()
// public override IEnumerable<Gizmo> GetGizmos()
public static IEnumerable<Gizmo> Postfix(IEnumerable<Gizmo> __result, Pawn __instance)
{
if (this.parent is Pawn gizmoPawn)
if (__instance.IsColonistPlayerControlled)
{
GearUpPolicyComp component = Current.Game.GetComponent<GearUpPolicyComp>();
yield return new Command_GearUpAndGo()
{
icon = component.lastPolicy != "" ? TexGearUpAndGo.guagIconActive : TexGearUpAndGo.guagIcon
icon = GearUpPolicyComp.comp.lastPolicy != "" ? TexGearUpAndGo.guagIconActive : TexGearUpAndGo.guagIcon
};
}

foreach (var r in __result)
yield return r;
}
}

// backcompat dummy so it doesn't log error loading old saves
public class CompGearUpAndGizGo : ThingComp { }
}
8 changes: 8 additions & 0 deletions Source/GearUpAndGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Verse.AI;
using RimWorld;
using UnityEngine;
using HarmonyLib;

namespace GearUpAndGo
{
Expand All @@ -14,6 +15,13 @@ public Mod(ModContentPack content) : base(content)
{
// initialize settings
settings = GetSettings<Settings>();

#if DEBUG
Harmony.DEBUG = true;
#endif
Harmony harmony = new Harmony("uuugggg.rimworld.GearUpAndGo.main");

harmony.PatchAll();
}

public override void DoSettingsWindowContents(Rect inRect)
Expand Down
2 changes: 0 additions & 2 deletions Source/SetBetterPawnControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Verse;
using RimWorld;
using HarmonyLib;

namespace GearUpAndGo
{
Expand Down

0 comments on commit 07a3aa7

Please sign in to comment.