Implement progress monitoring for image generation in AIImages mod, enhancing user experience with real-time updates. Add localized strings for new features in English and Russian. Refactor UI components for better organization and clarity. Update AIImages.dll to reflect these changes.
This commit is contained in:
42
Source/AIImages/Patches/PawnPortraitCompPatch.cs
Normal file
42
Source/AIImages/Patches/PawnPortraitCompPatch.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using AIImages.Components;
|
||||
using HarmonyLib;
|
||||
using Verse;
|
||||
|
||||
namespace AIImages.Patches
|
||||
{
|
||||
/// <summary>
|
||||
/// Патч для добавления PawnPortraitComp ко всем пешкам
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(ThingWithComps), nameof(ThingWithComps.InitializeComps))]
|
||||
public static class PawnPortraitCompPatch
|
||||
{
|
||||
private static FieldInfo allCompsField = AccessTools.Field(typeof(ThingWithComps), "comps");
|
||||
|
||||
[HarmonyPostfix]
|
||||
public static void AddPortraitComp(ThingWithComps __instance)
|
||||
{
|
||||
// Проверяем, является ли объект пешкой-гуманоидом и нет ли уже компонента
|
||||
if (
|
||||
__instance is Pawn pawn
|
||||
&& pawn.RaceProps?.Humanlike == true
|
||||
&& pawn.GetComp<PawnPortraitComp>() == null
|
||||
)
|
||||
{
|
||||
// Создаем компонент
|
||||
var comp = new PawnPortraitComp { parent = pawn };
|
||||
|
||||
// Инициализируем компонент
|
||||
comp.Initialize(null);
|
||||
|
||||
// Получаем список компонентов через рефлексию и добавляем наш
|
||||
var compsList = allCompsField.GetValue(pawn) as List<ThingComp>;
|
||||
if (compsList != null)
|
||||
{
|
||||
compsList.Add(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user