Refactor AIImages mod to streamline API loading functionality, consolidating model, sampler, and scheduler loading into a single method. Update localized strings in English and Russian for improved clarity and consistency. Enhance UI with scrollable prompt display for better user experience. Update AIImages.dll to reflect these changes.
This commit is contained in:
@@ -70,18 +70,13 @@ namespace AIImages
|
||||
_ = TestApiConnection(settings.apiEndpoint);
|
||||
}
|
||||
|
||||
if (listingStandard.ButtonText("AIImages.Settings.LoadModels".Translate()))
|
||||
if (listingStandard.ButtonText("AIImages.Settings.LoadFromApi".Translate()))
|
||||
{
|
||||
_ = LoadModelsFromApi(settings);
|
||||
_ = LoadAllFromApi(settings);
|
||||
}
|
||||
|
||||
DrawModelDropdown(listingStandard, settings);
|
||||
|
||||
if (listingStandard.ButtonText("AIImages.Settings.LoadSamplersSchedulers".Translate()))
|
||||
{
|
||||
_ = LoadSamplersAndSchedulers(settings);
|
||||
}
|
||||
|
||||
listingStandard.Gap(12f);
|
||||
}
|
||||
|
||||
@@ -376,23 +371,43 @@ namespace AIImages
|
||||
}
|
||||
}
|
||||
|
||||
private static async System.Threading.Tasks.Task LoadModelsFromApi(
|
||||
private static async System.Threading.Tasks.Task LoadAllFromApi(
|
||||
AIImagesModSettings settings
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Message("[AI Images] Loading models from API...");
|
||||
Log.Message("[AI Images] Loading models, samplers and schedulers from API...");
|
||||
|
||||
// Загружаем модели
|
||||
var models = await AIImagesMod.ApiService.GetAvailableModels(settings.apiEndpoint);
|
||||
settings.availableModels = models;
|
||||
|
||||
if (models.Count > 0)
|
||||
// Загружаем семплеры
|
||||
var samplers = await AIImagesMod.ApiService.GetAvailableSamplers(
|
||||
settings.apiEndpoint
|
||||
);
|
||||
settings.availableSamplers = samplers;
|
||||
|
||||
// Загружаем schedulers
|
||||
var schedulers = await AIImagesMod.ApiService.GetAvailableSchedulers(
|
||||
settings.apiEndpoint
|
||||
);
|
||||
settings.availableSchedulers = schedulers;
|
||||
|
||||
int totalCount = models.Count + samplers.Count + schedulers.Count;
|
||||
if (totalCount > 0)
|
||||
{
|
||||
Messages.Message(
|
||||
"AIImages.Settings.ModelsLoaded".Translate(models.Count),
|
||||
"AIImages.Settings.AllLoaded".Translate(
|
||||
models.Count,
|
||||
samplers.Count,
|
||||
schedulers.Count
|
||||
),
|
||||
MessageTypeDefOf.PositiveEvent
|
||||
);
|
||||
|
||||
// Автовыбор модели
|
||||
if (
|
||||
(
|
||||
string.IsNullOrEmpty(settings.selectedModel)
|
||||
@@ -403,53 +418,8 @@ namespace AIImages
|
||||
{
|
||||
settings.selectedModel = models[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Messages.Message(
|
||||
"AIImages.Settings.NoModelsFound".Translate(),
|
||||
MessageTypeDefOf.RejectInput
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Messages.Message(
|
||||
$"Error loading models: {ex.Message}",
|
||||
MessageTypeDefOf.RejectInput
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static async System.Threading.Tasks.Task LoadSamplersAndSchedulers(
|
||||
AIImagesModSettings settings
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Message("[AI Images] Loading samplers and schedulers from API...");
|
||||
|
||||
var samplers = await AIImagesMod.ApiService.GetAvailableSamplers(
|
||||
settings.apiEndpoint
|
||||
);
|
||||
settings.availableSamplers = samplers;
|
||||
|
||||
var schedulers = await AIImagesMod.ApiService.GetAvailableSchedulers(
|
||||
settings.apiEndpoint
|
||||
);
|
||||
settings.availableSchedulers = schedulers;
|
||||
|
||||
int totalCount = samplers.Count + schedulers.Count;
|
||||
if (totalCount > 0)
|
||||
{
|
||||
Messages.Message(
|
||||
"AIImages.Settings.SamplersSchedulersLoaded".Translate(
|
||||
samplers.Count,
|
||||
schedulers.Count
|
||||
),
|
||||
MessageTypeDefOf.PositiveEvent
|
||||
);
|
||||
|
||||
// Автовыбор семплера
|
||||
if (
|
||||
(
|
||||
string.IsNullOrEmpty(settings.selectedSampler)
|
||||
@@ -461,6 +431,7 @@ namespace AIImages
|
||||
settings.selectedSampler = samplers[0];
|
||||
}
|
||||
|
||||
// Автовыбор scheduler
|
||||
if (
|
||||
(
|
||||
string.IsNullOrEmpty(settings.selectedScheduler)
|
||||
@@ -475,7 +446,7 @@ namespace AIImages
|
||||
else
|
||||
{
|
||||
Messages.Message(
|
||||
"AIImages.Settings.NoSamplersSchedulersFound".Translate(),
|
||||
"AIImages.Settings.NothingLoaded".Translate(),
|
||||
MessageTypeDefOf.RejectInput
|
||||
);
|
||||
}
|
||||
@@ -483,7 +454,7 @@ namespace AIImages
|
||||
catch (Exception ex)
|
||||
{
|
||||
Messages.Message(
|
||||
$"Error loading samplers/schedulers: {ex.Message}",
|
||||
$"Error loading from API: {ex.Message}",
|
||||
MessageTypeDefOf.RejectInput
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace AIImages
|
||||
public override Vector2 InitialSize => new Vector2(900f, 800f);
|
||||
|
||||
private Vector2 scrollPosition = Vector2.zero;
|
||||
private Vector2 promptScrollPosition = Vector2.zero;
|
||||
private float copiedMessageTime = 0f;
|
||||
|
||||
/// <summary>
|
||||
@@ -337,13 +338,29 @@ namespace AIImages
|
||||
generationSettings
|
||||
);
|
||||
|
||||
float promptHeight = Mathf.Min(Text.CalcHeight(promptText, rect.width), 150f);
|
||||
Rect promptRect = new Rect(rect.x, rect.y + curY, rect.width, promptHeight);
|
||||
// Фиксированная высота для области промпта
|
||||
float promptBoxHeight = 150f;
|
||||
float actualPromptHeight = Text.CalcHeight(promptText, rect.width - 20f);
|
||||
|
||||
// Рисуем промпт в скроллируемой области если он длинный
|
||||
Widgets.DrawBoxSolid(promptRect, new Color(0.1f, 0.1f, 0.1f, 0.5f));
|
||||
Widgets.Label(promptRect.ContractedBy(5f), promptText);
|
||||
curY += promptHeight + 10f;
|
||||
Rect promptOuterRect = new Rect(rect.x, rect.y + curY, rect.width, promptBoxHeight);
|
||||
Rect promptViewRect = new Rect(0f, 0f, rect.width - 20f, actualPromptHeight);
|
||||
|
||||
// Рисуем фон
|
||||
Widgets.DrawBoxSolid(promptOuterRect, new Color(0.1f, 0.1f, 0.1f, 0.5f));
|
||||
|
||||
// Рисуем промпт с прокруткой
|
||||
Widgets.BeginScrollView(
|
||||
promptOuterRect.ContractedBy(5f),
|
||||
ref promptScrollPosition,
|
||||
promptViewRect
|
||||
);
|
||||
Widgets.Label(
|
||||
new Rect(0f, 0f, promptViewRect.width, promptViewRect.height),
|
||||
promptText
|
||||
);
|
||||
Widgets.EndScrollView();
|
||||
|
||||
curY += promptBoxHeight + 10f;
|
||||
|
||||
// Кнопка копирования промпта
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user