Refactor AIImages mod to replace ArtStyle enum with ArtStyleDef name for improved flexibility in prompt generation. Update UI components to reflect changes in art style selection and enhance scrolling functionality in the right column. Update AIImages.dll to incorporate the latest modifications.

This commit is contained in:
Leonid Pershin
2025-10-27 00:19:31 +03:00
parent 9e675dd804
commit ce98638e55
11 changed files with 594 additions and 138 deletions

View File

@@ -70,6 +70,7 @@ namespace AIImages
public override Vector2 InitialSize => new Vector2(900f, 800f);
private Vector2 scrollPosition = Vector2.zero;
private Vector2 rightColumnScrollPosition = Vector2.zero;
private Vector2 promptScrollPosition = Vector2.zero;
private Vector2 negativePromptScrollPosition = Vector2.zero;
private float copiedMessageTime = 0f;
@@ -440,17 +441,23 @@ namespace AIImages
private void DrawRightColumn(Rect rect)
{
// Рассчитываем высоту контента для скролла
float contentHeight = CalculateRightColumnHeight(rect);
Rect scrollViewRect = new Rect(0f, 0f, rect.width - 20f, contentHeight);
Widgets.BeginScrollView(rect, ref rightColumnScrollPosition, scrollViewRect);
float curY = 0f;
curY = DrawImagePreview(rect, curY);
curY = DrawGenerationStatus(rect, curY);
curY = DrawProgressBar(rect, curY);
curY = DrawGenerationButton(rect, curY);
curY = DrawImagePreview(scrollViewRect, curY);
curY = DrawGenerationStatus(scrollViewRect, curY);
curY = DrawProgressBar(scrollViewRect, curY);
curY = DrawGenerationButton(scrollViewRect, curY);
// Позитивный промпт секция
Text.Font = GameFont.Medium;
Widgets.Label(
new Rect(rect.x, rect.y + curY, rect.width, 30f),
new Rect(0f, curY, scrollViewRect.width, 30f),
"AIImages.Prompt.PositiveTitle".Translate()
);
curY += 35f;
@@ -464,10 +471,18 @@ namespace AIImages
// Фиксированная высота для области промпта
float promptBoxHeight = 100f;
float actualPositiveHeight = Text.CalcHeight(positivePrompt, rect.width - 20f);
float actualPositiveHeight = Text.CalcHeight(
positivePrompt,
scrollViewRect.width - 20f
);
Rect positiveOuterRect = new Rect(rect.x, rect.y + curY, rect.width, promptBoxHeight);
Rect positiveViewRect = new Rect(0f, 0f, rect.width - 20f, actualPositiveHeight);
Rect positiveOuterRect = new Rect(0f, curY, scrollViewRect.width, promptBoxHeight);
Rect positiveViewRect = new Rect(
0f,
0f,
scrollViewRect.width - 20f,
actualPositiveHeight
);
// Рисуем фон
Widgets.DrawBoxSolid(positiveOuterRect, new Color(0.1f, 0.3f, 0.1f, 0.5f));
@@ -489,7 +504,7 @@ namespace AIImages
// Негативный промпт секция
Text.Font = GameFont.Medium;
Widgets.Label(
new Rect(rect.x, rect.y + curY, rect.width, 30f),
new Rect(0f, curY, scrollViewRect.width, 30f),
"AIImages.Prompt.NegativeTitle".Translate()
);
curY += 35f;
@@ -500,10 +515,18 @@ namespace AIImages
generationSettings
);
float actualNegativeHeight = Text.CalcHeight(negativePrompt, rect.width - 20f);
float actualNegativeHeight = Text.CalcHeight(
negativePrompt,
scrollViewRect.width - 20f
);
Rect negativeOuterRect = new Rect(rect.x, rect.y + curY, rect.width, promptBoxHeight);
Rect negativeViewRect = new Rect(0f, 0f, rect.width - 20f, actualNegativeHeight);
Rect negativeOuterRect = new Rect(0f, curY, scrollViewRect.width, promptBoxHeight);
Rect negativeViewRect = new Rect(
0f,
0f,
scrollViewRect.width - 20f,
actualNegativeHeight
);
// Рисуем фон (красноватый для негативного)
Widgets.DrawBoxSolid(negativeOuterRect, new Color(0.3f, 0.1f, 0.1f, 0.5f));
@@ -525,7 +548,7 @@ namespace AIImages
// Кнопки копирования промптов
if (
Widgets.ButtonText(
new Rect(rect.x, rect.y + curY, rect.width / 2f - 5f, 30f),
new Rect(0f, curY, scrollViewRect.width / 2f - 5f, 30f),
"AIImages.Prompt.CopyPositive".Translate()
)
)
@@ -541,9 +564,9 @@ namespace AIImages
if (
Widgets.ButtonText(
new Rect(
rect.x + rect.width / 2f + 5f,
rect.y + curY,
rect.width / 2f - 5f,
scrollViewRect.width / 2f + 5f,
curY,
scrollViewRect.width / 2f - 5f,
30f
),
"AIImages.Prompt.CopyNegative".Translate()
@@ -561,7 +584,7 @@ namespace AIImages
// Кнопка обновления данных
if (
Widgets.ButtonText(
new Rect(rect.x, rect.y + curY, rect.width, 30f),
new Rect(0f, curY, scrollViewRect.width, 30f),
"AIImages.Window.Refresh".Translate()
)
)
@@ -575,11 +598,13 @@ namespace AIImages
curY += 35f;
GUI.color = new Color(0f, 1f, 0f, copiedMessageTime / 2f);
Widgets.Label(
new Rect(rect.x, rect.y + curY, rect.width, 25f),
new Rect(0f, curY, scrollViewRect.width, 25f),
"AIImages.Prompt.Copied".Translate()
);
GUI.color = Color.white;
}
Widgets.EndScrollView();
}
private float CalculateContentHeight()
@@ -613,15 +638,46 @@ namespace AIImages
// Дополнительный отступ
height += 50f;
// Позитивный промпт заголовок
height += 35f;
// Позитивный промпт контент
height += 100f + 10f;
return height;
}
// Негативный промпт заголовок
height += 35f;
// Негативный промпт контент
height += 100f + 10f;
private float CalculateRightColumnHeight(Rect rect)
{
float height = 0f;
float contentWidth = rect.width - 20f;
// Превью изображения
if (generatedImage != null)
{
height += 200f + 10f;
}
else if (!isGenerating)
{
height += 100f + 10f;
}
// Статус генерации
if (!string.IsNullOrEmpty(generationStatus))
{
height += 30f;
}
// Прогресс бар
if (isGenerating && generationProgress > 0.0)
{
height += 30f;
}
// Кнопка генерации
height += 40f;
// Позитивный промпт
height += 35f; // Заголовок
height += 100f + 10f; // Бокс
// Негативный промпт
height += 35f; // Заголовок
height += 100f + 10f; // Бокс
// Кнопки копирования
height += 35f;
@@ -635,7 +691,7 @@ namespace AIImages
height += 30f;
}
return height;
return height + 50f; // Дополнительный отступ
}
private float DrawImagePreview(Rect rect, float curY)