using System.Collections.Generic; using System.Linq; using HarmonyLib; using RimWorld; using UnityEngine; using Verse; #pragma warning disable IDE1006 // Naming Styles namespace AIImages { /// /// Harmony patch to add a gizmo (button) to all colonist pawns /// [HarmonyPatch(typeof(Pawn), "GetGizmos")] [System.Diagnostics.CodeAnalysis.SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "RimWorld Harmony patch naming convention" )] [System.Diagnostics.CodeAnalysis.SuppressMessage( "Minor Code Smell", "S101:Types should be named in PascalCase", Justification = "RimWorld Harmony patch naming convention" )] public static class Pawn_GetGizmos_Patch { [HarmonyPostfix] public static IEnumerable Postfix(IEnumerable __result, Pawn __instance) { // First, return all original gizmos foreach (Gizmo gizmo in __result) { yield return gizmo; } // Only add button to colonist pawns that are spawned if ( __instance.IsColonist && __instance.Spawned && __instance.Faction == Faction.OfPlayer ) { yield return new Command_Action { defaultLabel = "AI Image", defaultDesc = "Open AI Image window", icon = ContentFinder.Get("UI/Commands/AttackMelee", true), action = delegate() { // Проверяем, открыто ли уже окно AI Image Window_AIImage existingWindow = Find .WindowStack.Windows.OfType() .FirstOrDefault(); if (existingWindow != null) { // Если окно открыто, обновляем пешку existingWindow.UpdatePawn(__instance); } else { // Если окна нет, создаём новое Find.WindowStack.Add(new Window_AIImage(__instance)); } }, }; } } } }