diff --git a/Source/RJWSexperience/Patches/DefInjection.cs b/Source/RJWSexperience/Patches/DefInjection.cs index ba832ff..b8c4cd6 100644 --- a/Source/RJWSexperience/Patches/DefInjection.cs +++ b/Source/RJWSexperience/Patches/DefInjection.cs @@ -15,15 +15,16 @@ namespace RJWSexperience InjectRaces(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1146:Use conditional access.", Justification = "race != null is needed")] private static void InjectRaces() { IEnumerable PawnDefs = DefDatabase.AllDefs.Where(x => x.race != null && !x.race.IsMechanoid); if (PawnDefs.EnumerableNullOrEmpty()) return; - CompProperties comp = new CompProperties(typeof(SexHistoryComp)); + CompProperties compProperties = new CompProperties(typeof(SexHistoryComp)); foreach (ThingDef def in PawnDefs) - def.comps.Add(comp); + def.comps.Add(compProperties); LogManager.GetLogger("StaticConstructorOnStartup").Message($"Injected SexHistoryComp into {PawnDefs.Count()} pawn Defs"); } diff --git a/Source/RJWSexperience/Patches/GetGizmos.cs b/Source/RJWSexperience/Patches/GetGizmos.cs deleted file mode 100644 index 5541616..0000000 --- a/Source/RJWSexperience/Patches/GetGizmos.cs +++ /dev/null @@ -1,41 +0,0 @@ -using HarmonyLib; -using RJWSexperience.SexHistory; -using System.Collections.Generic; -using Verse; - -namespace RJWSexperience -{ - [HarmonyPatch(typeof(Pawn), nameof(Pawn.GetGizmos))] - public static class Pawn_GetGizmos - { - private static Configurations Settings => SexperienceMod.Settings; - - public static bool Prepare() => Settings.EnableSexHistory; - - public static void Postfix(ref IEnumerable __result, Pawn __instance) - { - if (Settings.HideGizmoWhenDrafted && __instance.Drafted) - return; - - if (Find.Selector.NumSelected > 1) - return; - - if (Settings.HideGizmoWithRJW && !rjw.RJWSettings.show_RJW_designation_box) - return; - - SexHistoryComp history = __instance.TryGetComp(); - if (history == null) - return; - - __result = AddHistoryGizmo(history.Gizmo, __result); - } - - private static IEnumerable AddHistoryGizmo(Gizmo historyGizmo, IEnumerable gizmos) - { - foreach (Gizmo gizmo in gizmos) - yield return gizmo; - - yield return historyGizmo; - } - } -} diff --git a/Source/RJWSexperience/RJWSexperience.csproj b/Source/RJWSexperience/RJWSexperience.csproj index 7ace043..6540f16 100644 --- a/Source/RJWSexperience/RJWSexperience.csproj +++ b/Source/RJWSexperience/RJWSexperience.csproj @@ -59,7 +59,6 @@ - diff --git a/Source/RJWSexperience/SexHistory/SexHistoryComp.cs b/Source/RJWSexperience/SexHistory/SexHistoryComp.cs index 61c3639..2b05842 100644 --- a/Source/RJWSexperience/SexHistory/SexHistoryComp.cs +++ b/Source/RJWSexperience/SexHistory/SexHistoryComp.cs @@ -424,6 +424,20 @@ namespace RJWSexperience.SexHistory return pawn?.IsVirgin() == true; } + public override IEnumerable CompGetGizmosExtra() + { + if (SexperienceMod.Settings.HideGizmoWhenDrafted && (parent as Pawn)?.Drafted == true) + yield break; + + if (Find.Selector.NumSelected > 1) + yield break; + + if (SexperienceMod.Settings.HideGizmoWithRJW && !RJWSettings.show_RJW_designation_box) + yield break; + + yield return Gizmo; + } + public override void Initialize(CompProperties props) { base.Initialize(props);