From 174974220f16675c990f0db345cf6cda61016d60 Mon Sep 17 00:00:00 2001 From: amevarashi Date: Fri, 6 May 2022 20:54:49 +0500 Subject: [PATCH] Move history gizmo to comp --- .../RJWSexperience/Patches/GetGizmos.cs | 46 ------------------- .../RJWSexperience/RJWSexperience.csproj | 1 - .../SexHistory/SexPartnerHistory.cs | 27 +++++++++++ 3 files changed, 27 insertions(+), 47 deletions(-) delete mode 100644 RJWSexperience/RJWSexperience/Patches/GetGizmos.cs diff --git a/RJWSexperience/RJWSexperience/Patches/GetGizmos.cs b/RJWSexperience/RJWSexperience/Patches/GetGizmos.cs deleted file mode 100644 index 0c3a483..0000000 --- a/RJWSexperience/RJWSexperience/Patches/GetGizmos.cs +++ /dev/null @@ -1,46 +0,0 @@ -using HarmonyLib; -using RJWSexperience.UI; -using System.Collections.Generic; -using System.Linq; -using Verse; - -namespace RJWSexperience -{ - [HarmonyPatch(typeof(Pawn), "GetGizmos")] - public static class Pawn_GetGizmos - { - public static void Postfix(ref IEnumerable __result, Pawn __instance) - { - if (Find.Selector.NumSelected > 1) - return; - - __result = AddHistoryGizmo(__instance, __result); - } - - private static IEnumerable AddHistoryGizmo(Pawn pawn, IEnumerable gizmos) - { - foreach (Gizmo gizmo in gizmos) - yield return gizmo; - - SexPartnerHistory history = pawn.GetPartnerHistory(); - if (history != null) yield return CreateHistoryGizmo(pawn, history); - } - - private static Gizmo CreateHistoryGizmo(Pawn pawn, SexPartnerHistory history) - { - Gizmo gizmo = new Command_Action - { - defaultLabel = Keyed.RS_Sex_History, - icon = HistoryUtility.HistoryIcon, - defaultIconColor = HistoryUtility.HistoryColor, - hotKey = VariousDefOf.OpenSexStatistics, - action = delegate - { - SexStatusWindow.ToggleWindow(pawn, history); - } - }; - - return gizmo; - } - } -} diff --git a/RJWSexperience/RJWSexperience/RJWSexperience.csproj b/RJWSexperience/RJWSexperience/RJWSexperience.csproj index ed3fc22..33e26f8 100644 --- a/RJWSexperience/RJWSexperience/RJWSexperience.csproj +++ b/RJWSexperience/RJWSexperience/RJWSexperience.csproj @@ -83,7 +83,6 @@ - diff --git a/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistory.cs b/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistory.cs index d9a40b9..61b6754 100644 --- a/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistory.cs +++ b/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistory.cs @@ -46,6 +46,8 @@ namespace RJWSexperience protected int mostsextickabscache = 0; protected int bestsextickabscache = 0; + protected Gizmo historyGizmo; + public SexPartnerHistoryRecord GetFirstPartnerHistory { get @@ -468,5 +470,30 @@ namespace RJWSexperience Pawn pawn = parent as Pawn; return pawn?.IsVirgin() == true; } + + public override void Initialize(CompProperties props) + { + base.Initialize(props); + + historyGizmo = new Command_Action + { + defaultLabel = Keyed.RS_Sex_History, + icon = HistoryUtility.HistoryIcon, + defaultIconColor = HistoryUtility.HistoryColor, + hotKey = VariousDefOf.OpenSexStatistics, + action = delegate + { + UI.SexStatusWindow.ToggleWindow(parent as Pawn, this); + } + }; + } + + public override IEnumerable CompGetGizmosExtra() + { + if (Find.Selector.NumSelected > 1) + yield break; + + yield return historyGizmo; + } } }