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:
Leonid Pershin
2025-10-26 22:56:38 +03:00
parent b9d7ea0c04
commit d67ec8c0ac
11 changed files with 470 additions and 94 deletions

View File

@@ -0,0 +1,90 @@
using System.IO;
using AIImages.Components;
using UnityEngine;
using Verse;
namespace AIImages.Helpers
{
/// <summary>
/// Вспомогательный класс для работы с портретами персонажей
/// </summary>
public static class PawnPortraitHelper
{
/// <summary>
/// Получить компонент портрета пешки
/// </summary>
public static PawnPortraitComp GetPortraitComp(Pawn pawn)
{
return pawn?.TryGetComp<PawnPortraitComp>();
}
/// <summary>
/// Сохранить путь к портрету на пешке
/// </summary>
public static void SavePortraitPath(Pawn pawn, string path)
{
var comp = GetPortraitComp(pawn);
if (comp != null)
{
comp.PortraitPath = path;
Log.Message($"[AI Images] Saved portrait path for {pawn.Name}: {path}");
}
}
/// <summary>
/// Получить путь к портрету пешки
/// </summary>
public static string GetPortraitPath(Pawn pawn)
{
var comp = GetPortraitComp(pawn);
return comp?.PortraitPath;
}
/// <summary>
/// Есть ли у пешки сохраненный портрет
/// </summary>
public static bool HasPortrait(Pawn pawn)
{
var comp = GetPortraitComp(pawn);
return comp != null && comp.HasPortrait;
}
/// <summary>
/// Загрузить портрет пешки как текстуру
/// </summary>
public static Texture2D LoadPortrait(Pawn pawn)
{
string path = GetPortraitPath(pawn);
if (string.IsNullOrEmpty(path) || !File.Exists(path))
{
return null;
}
try
{
byte[] imageData = File.ReadAllBytes(path);
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(imageData);
return texture;
}
catch (System.Exception ex)
{
Log.Warning($"[AI Images] Failed to load portrait for {pawn.Name}: {ex.Message}");
return null;
}
}
/// <summary>
/// Очистить портрет пешки
/// </summary>
public static void ClearPortrait(Pawn pawn)
{
var comp = GetPortraitComp(pawn);
if (comp != null)
{
comp.PortraitPath = null;
}
}
}
}