Add functionality to clear all generated portrait images in AIImages mod. Implement UI button for clearing images and add confirmation dialog. Update localized strings in English and Russian for new feature. Update AIImages.dll to reflect these changes.
This commit is contained in:
Binary file not shown.
@@ -80,4 +80,7 @@
|
||||
<AIImages.Settings.ShowTechnicalInfo>Show technical information</AIImages.Settings.ShowTechnicalInfo>
|
||||
<AIImages.Settings.SaveHistory>Save generation history</AIImages.Settings.SaveHistory>
|
||||
<AIImages.Settings.SavePath>Save Path</AIImages.Settings.SavePath>
|
||||
<AIImages.Settings.ClearAllImages>Clear All Generated Images</AIImages.Settings.ClearAllImages>
|
||||
<AIImages.Settings.ClearAllImagesConfirm>Are you sure you want to delete all generated portrait images? This action cannot be undone.</AIImages.Settings.ClearAllImagesConfirm>
|
||||
<AIImages.Settings.ClearAllImagesSuccess>Successfully deleted {0} portrait image(s)</AIImages.Settings.ClearAllImagesSuccess>
|
||||
</LanguageData>
|
||||
|
||||
@@ -80,4 +80,7 @@
|
||||
<AIImages.Settings.ShowTechnicalInfo>Показывать техническую информацию</AIImages.Settings.ShowTechnicalInfo>
|
||||
<AIImages.Settings.SaveHistory>Сохранять историю генераций</AIImages.Settings.SaveHistory>
|
||||
<AIImages.Settings.SavePath>Путь для сохранения</AIImages.Settings.SavePath>
|
||||
<AIImages.Settings.ClearAllImages>Очистить все сгенерированные изображения</AIImages.Settings.ClearAllImages>
|
||||
<AIImages.Settings.ClearAllImagesConfirm>Вы уверены, что хотите удалить все сгенерированные портреты? Это действие нельзя отменить.</AIImages.Settings.ClearAllImagesConfirm>
|
||||
<AIImages.Settings.ClearAllImagesSuccess>Успешно удалено {0} изображений портретов</AIImages.Settings.ClearAllImagesSuccess>
|
||||
</LanguageData>
|
||||
|
||||
@@ -86,5 +86,59 @@ namespace AIImages.Helpers
|
||||
comp.PortraitPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Очистить все сгенерированные портреты
|
||||
/// </summary>
|
||||
public static int ClearAllPortraits(string savePath)
|
||||
{
|
||||
int deletedCount = 0;
|
||||
|
||||
// Очищаем компоненты всех пешек
|
||||
if (Current.Game != null && Current.Game.Maps != null)
|
||||
{
|
||||
foreach (var map in Current.Game.Maps)
|
||||
{
|
||||
foreach (var pawn in map.mapPawns.AllPawns)
|
||||
{
|
||||
var comp = GetPortraitComp(pawn);
|
||||
if (comp != null && comp.HasPortrait)
|
||||
{
|
||||
comp.PortraitPath = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Удаляем файлы из директории
|
||||
string fullPath = Path.Combine(GenFilePaths.SaveDataFolderPath, savePath);
|
||||
|
||||
if (Directory.Exists(fullPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
var files = Directory.GetFiles(fullPath, "*.png");
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
deletedCount++;
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Log.Warning($"[AI Images] Failed to delete file {file}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
Log.Message($"[AI Images] Deleted {deletedCount} portrait files");
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Log.Error($"[AI Images] Error cleaning portraits directory: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return deletedCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,6 +366,14 @@ namespace AIImages
|
||||
|
||||
listingStandard.Label("AIImages.Settings.SavePath".Translate() + ":");
|
||||
settings.savePath = listingStandard.TextEntry(settings.savePath);
|
||||
|
||||
listingStandard.Gap(12f);
|
||||
|
||||
// Кнопка очистки всех изображений
|
||||
if (listingStandard.ButtonText("AIImages.Settings.ClearAllImages".Translate()))
|
||||
{
|
||||
ClearAllGeneratedImages(settings);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TestApiConnection(
|
||||
@@ -476,5 +484,23 @@ namespace AIImages
|
||||
selectedValue = availableValues[0];
|
||||
}
|
||||
}
|
||||
|
||||
private static void ClearAllGeneratedImages(AIImagesModSettings settings)
|
||||
{
|
||||
Find.WindowStack.Add(
|
||||
Dialog_MessageBox.CreateConfirmation(
|
||||
"AIImages.Settings.ClearAllImagesConfirm".Translate(),
|
||||
delegate
|
||||
{
|
||||
int deletedCount = PawnPortraitHelper.ClearAllPortraits(settings.savePath);
|
||||
Messages.Message(
|
||||
"AIImages.Settings.ClearAllImagesSuccess".Translate(deletedCount),
|
||||
MessageTypeDefOf.PositiveEvent
|
||||
);
|
||||
},
|
||||
destructive: true
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user