添加生成内容次数配置
This commit is contained in:
parent
b7b1944729
commit
9a9675fa6d
@ -28,6 +28,9 @@ public class AIGC : ModuleRules
|
||||
{
|
||||
"Core",
|
||||
// ... add other public dependencies that you statically link with here ...
|
||||
"SlateCore",
|
||||
"Slate",
|
||||
"InputCore"
|
||||
}
|
||||
);
|
||||
|
||||
@ -37,8 +40,7 @@ public class AIGC : ModuleRules
|
||||
{
|
||||
"CoreUObject",
|
||||
"Engine",
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
|
||||
// ... add private dependencies that you statically link with here ...
|
||||
"EditorStyle",
|
||||
"ToolMenus",
|
||||
|
@ -46,7 +46,7 @@ void UWebSocketManager::HandleConnectionError(const FString& ErrorReason)
|
||||
|
||||
void UWebSocketManager::HandleOnMessageSend(const FString& Message)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Send Text %s to WebSocket Server "), *Message);
|
||||
//UE_LOG(LogTemp, Warning, TEXT("Send Text %s to WebSocket Server "), *Message);
|
||||
}
|
||||
|
||||
void UWebSocketManager::HandleOnReceiveText(const FString& Message)
|
||||
|
@ -19,7 +19,7 @@ void SAIGCWindow::Construct(const FArguments& InArgs)
|
||||
.AutoHeight()
|
||||
.Padding(10)
|
||||
[
|
||||
SAssignNew(ServerIP, SConfigItemWidget)
|
||||
SAssignNew(ServerIP, SConfigItem_Text)
|
||||
.Title(LOCTEXT("Server", "服务器ip"))
|
||||
.HintText(LOCTEXT("HintServer", "请输入服务器ip"))
|
||||
.DefaultText(LOCTEXT("InputServer", "127.0.0.1"))
|
||||
@ -28,7 +28,7 @@ void SAIGCWindow::Construct(const FArguments& InArgs)
|
||||
.AutoHeight()
|
||||
.Padding(10)
|
||||
[
|
||||
SAssignNew(DataName, SConfigItemWidget)
|
||||
SAssignNew(DataName, SConfigItem_Text)
|
||||
.Title(LOCTEXT("DataName", "配表名称"))
|
||||
.HintText(LOCTEXT("HintDataName", "请输入配表名称"))
|
||||
]
|
||||
@ -36,7 +36,7 @@ void SAIGCWindow::Construct(const FArguments& InArgs)
|
||||
.AutoHeight()
|
||||
.Padding(10)
|
||||
[
|
||||
SAssignNew(NPCName1, SConfigItemWidget)
|
||||
SAssignNew(NPCName1, SConfigItem_Text)
|
||||
.Title(LOCTEXT("Name1", "名称1"))
|
||||
.HintText(LOCTEXT("HintName", "请输入名称"))
|
||||
]
|
||||
@ -44,7 +44,7 @@ void SAIGCWindow::Construct(const FArguments& InArgs)
|
||||
.AutoHeight()
|
||||
.Padding(10)
|
||||
[
|
||||
SAssignNew(NPCJob1, SConfigItemWidget)
|
||||
SAssignNew(NPCJob1, SConfigItem_Text)
|
||||
.Title(LOCTEXT("Job1", "职业1"))
|
||||
.HintText(LOCTEXT("HintJon", "请输入职业"))
|
||||
]
|
||||
@ -52,7 +52,7 @@ void SAIGCWindow::Construct(const FArguments& InArgs)
|
||||
.AutoHeight()
|
||||
.Padding(10)
|
||||
[
|
||||
SAssignNew(NPCName2, SConfigItemWidget)
|
||||
SAssignNew(NPCName2, SConfigItem_Text)
|
||||
.Title(LOCTEXT("Name2", "名称2"))
|
||||
.HintText(LOCTEXT("HintName", "请输入名称"))
|
||||
]
|
||||
@ -61,7 +61,7 @@ void SAIGCWindow::Construct(const FArguments& InArgs)
|
||||
.AutoHeight()
|
||||
.Padding(10)
|
||||
[
|
||||
SAssignNew(NPCJob2, SConfigItemWidget)
|
||||
SAssignNew(NPCJob2, SConfigItem_Text)
|
||||
.Title(LOCTEXT("Job2", "职业2"))
|
||||
.HintText(LOCTEXT("HintJon", "请输入职业"))
|
||||
]
|
||||
@ -69,9 +69,18 @@ void SAIGCWindow::Construct(const FArguments& InArgs)
|
||||
.AutoHeight()
|
||||
.Padding(10)
|
||||
[
|
||||
SAssignNew(DialogScene, SConfigItemWidget)
|
||||
SAssignNew(DialogScene, SConfigItem_Text)
|
||||
.Title(LOCTEXT("DialogScene", "对话场景"))
|
||||
.HintText(LOCTEXT("HintDialogScene", "请输入对话场景"))
|
||||
]
|
||||
+ SVerticalBox::Slot()
|
||||
.AutoHeight()
|
||||
.Padding(10)
|
||||
[
|
||||
SAssignNew(GenerateCount, SConfigItem_NumberSpin<int32>)
|
||||
.Title(LOCTEXT("GenerateCount", "生成数量"))
|
||||
.MinNumber(1)
|
||||
.MaxNumber(99)
|
||||
]
|
||||
+ SVerticalBox::Slot()
|
||||
.AutoHeight()
|
||||
@ -111,13 +120,18 @@ EActiveTimerReturnType SAIGCWindow::OnPostPaint(double X, float Arg)
|
||||
void SAIGCWindow::OnAIGenerateClicked()
|
||||
{
|
||||
GenerateButton->SetEnabled(false);
|
||||
RequireGenerateCount = GenerateCount->GetNumber();
|
||||
UE_LOG(LogTemp, Warning, TEXT("生成次数 %d prompt:%s"), RequireGenerateCount, *GeneratePromptJson());
|
||||
WebSocketManager->SendData(GeneratePromptJson());
|
||||
}
|
||||
|
||||
|
||||
void SAIGCWindow::HandleReceiveData(TArray<FString> AiMessages)
|
||||
{
|
||||
GenerateButton->SetEnabled(true);
|
||||
UE_LOG(LogTemp, Warning, TEXT("AI当前进度 %d/%d"), GeneratedCount, RequireGenerateCount);
|
||||
//添加数据到dataTable中
|
||||
if (AiMessages.Num() > 0)
|
||||
{
|
||||
FAIGCModule* ModulePtr = FModuleManager::GetModulePtr<FAIGCModule>("AIGC");
|
||||
if (ModulePtr) {
|
||||
FString DataPath = FString::Printf(TEXT("/Game/Test/%s.%s"), *DataName->GetInputText(), *DataName->GetInputText());
|
||||
@ -130,6 +144,21 @@ void SAIGCWindow::HandleReceiveData(TArray<FString> AiMessages)
|
||||
}
|
||||
}
|
||||
|
||||
//是否生成足够数量
|
||||
if (GeneratedCount < RequireGenerateCount)
|
||||
{
|
||||
GeneratedCount++;
|
||||
WebSocketManager->SendData(GeneratePromptJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
GeneratedCount = 0;
|
||||
GenerateButton->SetEnabled(true);
|
||||
UE_LOG(LogTemp, Warning, TEXT("生成结束!"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FString SAIGCWindow::GeneratePromptJson()
|
||||
{
|
||||
FPrompt PromptData;
|
||||
|
@ -0,0 +1,6 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Widget/ConfigItem_NumberSpin.h"
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Widget/ConfigItemWidget.h"
|
||||
#include "Widget/ConfigItem_Text.h"
|
||||
|
||||
|
||||
|
||||
void SConfigItemWidget::Construct(const FArguments& InArgs)
|
||||
void SConfigItem_Text::Construct(const FArguments& InArgs)
|
||||
{
|
||||
InputText = InArgs._DefaultText.ToString();
|
||||
ChildSlot[
|
@ -3,7 +3,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "ConfigItemWidget.h"
|
||||
#include "ConfigItem_NumberSpin.h"
|
||||
#include "ConfigItem_Text.h"
|
||||
|
||||
/**
|
||||
*
|
||||
@ -25,15 +26,17 @@ public:
|
||||
|
||||
private:
|
||||
FString GeneratePromptJson();
|
||||
|
||||
int32 RequireGenerateCount;
|
||||
int32 GeneratedCount = 1;
|
||||
protected:
|
||||
TSharedPtr<SConfigItemWidget> ServerIP; //服务器IP
|
||||
TSharedPtr<SConfigItemWidget> DataName; //datatable 名称
|
||||
TSharedPtr<SConfigItemWidget> NPCName1; //npc1的名称
|
||||
TSharedPtr<SConfigItemWidget> NPCJob1; //npc1的职业
|
||||
TSharedPtr<SConfigItemWidget> NPCName2; //npc2的名称
|
||||
TSharedPtr<SConfigItemWidget> NPCJob2; //npc2的职业
|
||||
TSharedPtr<SConfigItemWidget> DialogScene; //对话场景
|
||||
TSharedPtr<SConfigItem_Text> ServerIP; //服务器IP
|
||||
TSharedPtr<SConfigItem_Text> DataName; //datatable 名称
|
||||
TSharedPtr<SConfigItem_Text> NPCName1; //npc1的名称
|
||||
TSharedPtr<SConfigItem_Text> NPCJob1; //npc1的职业
|
||||
TSharedPtr<SConfigItem_Text> NPCName2; //npc2的名称
|
||||
TSharedPtr<SConfigItem_Text> NPCJob2; //npc2的职业
|
||||
TSharedPtr<SConfigItem_Text> DialogScene; //对话场景
|
||||
TSharedPtr<SConfigItem_NumberSpin<int32>> GenerateCount; //生成数目
|
||||
TSharedPtr<SButton> GenerateButton; //生成按钮
|
||||
|
||||
UPROPERTY()
|
||||
|
@ -0,0 +1,71 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Widgets/Input/SNumericEntryBox.h"
|
||||
#include "Framework/Application/SlateApplication.h"
|
||||
/**
|
||||
*
|
||||
*/
|
||||
template <typename NumericType>
|
||||
class AIGC_API SConfigItem_NumberSpin : public SCompoundWidget
|
||||
{
|
||||
public:
|
||||
SLATE_BEGIN_ARGS(SConfigItem_NumberSpin)
|
||||
: _Title()
|
||||
, _MinNumber()
|
||||
, _MaxNumber()
|
||||
{}
|
||||
SLATE_ARGUMENT(FText, Title) // 标题参数
|
||||
SLATE_ARGUMENT(NumericType, MinNumber) // 最小范围
|
||||
SLATE_ARGUMENT(NumericType, MaxNumber) // 最大范围
|
||||
|
||||
SLATE_END_ARGS()
|
||||
|
||||
void Construct(const FArguments& InArgs)
|
||||
{
|
||||
ChildSlot
|
||||
[
|
||||
SNew(SHorizontalBox)
|
||||
+ SHorizontalBox::Slot()
|
||||
.AutoWidth()
|
||||
.Padding(10, 0)
|
||||
[
|
||||
SNew(STextBlock)
|
||||
.Text(InArgs._Title)
|
||||
]
|
||||
+ SHorizontalBox::Slot()
|
||||
.FillWidth(1.0f)
|
||||
.Padding(10, 0)
|
||||
[
|
||||
SNew(SNumericEntryBox<NumericType>)
|
||||
.AllowSpin(true)
|
||||
.MinValue(InArgs._MinNumber)
|
||||
.MaxValue(InArgs._MaxNumber)
|
||||
.MinSliderValue(InArgs._MinNumber)
|
||||
.MaxSliderValue(InArgs._MaxNumber)
|
||||
.Value(InArgs._MinNumber)
|
||||
.Delta(1)
|
||||
.Value_Lambda([this, InArgs]() { return FMath::Max(InArgs._MinNumber, InputValue); })
|
||||
.OnValueChanged(this, &SConfigItem_NumberSpin::OnValueChanged)
|
||||
]
|
||||
];
|
||||
}
|
||||
NumericType GetNumber() const { return InputValue; }
|
||||
|
||||
private:
|
||||
void OnValueChanged(NumericType NewValue)
|
||||
{
|
||||
UE_LOG(LogTemp, Display, TEXT("OnValueChanged newvalue = %d"), (int32)NewValue);
|
||||
InputValue = NewValue;
|
||||
Invalidate(EInvalidateWidget::Layout);
|
||||
}
|
||||
NumericType InputValue;
|
||||
};
|
||||
|
||||
// template <typename NumericType>
|
||||
// void SConfigItem_NumberSpin<NumericType>::Construct(const FArguments& InArgs)
|
||||
// {
|
||||
// }
|
||||
|
@ -7,9 +7,9 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class SConfigItemWidget : public SCompoundWidget {
|
||||
class AIGC_API SConfigItem_Text : public SCompoundWidget {
|
||||
public:
|
||||
SLATE_BEGIN_ARGS(SConfigItemWidget)
|
||||
SLATE_BEGIN_ARGS(SConfigItem_Text)
|
||||
: _Title()
|
||||
, _HintText()
|
||||
, _DefaultText()
|
Loading…
x
Reference in New Issue
Block a user