Add convAI plugin
This commit is contained in:
64
ConvAI/Convai/Source/ConvaiEditor/ConvaiEditor.Build.cs
Normal file
64
ConvAI/Convai/Source/ConvaiEditor/ConvaiEditor.Build.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright 2022 Convai Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class ConvaiEditor : ModuleRules
|
||||
{
|
||||
public ConvaiEditor(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicIncludePaths.AddRange(
|
||||
new string[] {
|
||||
// ... add public include paths required here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PrivateIncludePaths.AddRange(
|
||||
new string[] {
|
||||
// ... add other private include paths required here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Core",
|
||||
"CoreUObject",
|
||||
"Engine",
|
||||
"InputCore",
|
||||
"UMG",
|
||||
"Convai",
|
||||
"UMGEditor",
|
||||
"Blutility",
|
||||
// ... add other public dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
"UnrealEd",
|
||||
"LevelEditor",
|
||||
"EditorScriptingUtilities",
|
||||
"PropertyEditor",
|
||||
"DeveloperSettings",
|
||||
"Convai",
|
||||
// ... add private dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
DynamicallyLoadedModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
// ... add any modules that your module loads dynamically here ...
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "ConvaiEUWBase.h"
|
||||
|
||||
103
ConvAI/Convai/Source/ConvaiEditor/Private/ConvaiEditor.cpp
Normal file
103
ConvAI/Convai/Source/ConvaiEditor/Private/ConvaiEditor.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
// Copyright 2022 Convai Inc. All Rights Reserved.
|
||||
|
||||
#include "ConvaiEditor.h"
|
||||
#include "EditorUtilitySubsystem.h"
|
||||
#include "Widgets/Input/SButton.h"
|
||||
#include "DetailLayoutBuilder.h"
|
||||
#include "DetailCategoryBuilder.h"
|
||||
#include "DetailWidgetRow.h"
|
||||
#include "../Convai.h"
|
||||
#include "EditorUtilityWidgetBlueprint.h"
|
||||
#include "Utility/Log/ConvaiLogger.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FConvaiEditorModule"
|
||||
|
||||
void FConvaiEditorModule::StartupModule()
|
||||
{
|
||||
// Register settings customization
|
||||
FPropertyEditorModule& PropertyEditor = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
|
||||
PropertyEditor.RegisterCustomClassLayout(
|
||||
UConvaiSettings::StaticClass()->GetFName(),
|
||||
FOnGetDetailCustomizationInstance::CreateStatic(&FConvaiEditorSettingsCustomization::MakeInstance)
|
||||
);
|
||||
|
||||
// Notify customization module
|
||||
PropertyEditor.NotifyCustomizationModuleChanged();
|
||||
}
|
||||
|
||||
void FConvaiEditorModule::ShutdownModule()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
IMPLEMENT_MODULE(FConvaiEditorModule, ConvaiEditor)
|
||||
|
||||
|
||||
|
||||
|
||||
TSharedRef<IDetailCustomization> FConvaiEditorSettingsCustomization::MakeInstance()
|
||||
{
|
||||
return MakeShareable(new FConvaiEditorSettingsCustomization);
|
||||
}
|
||||
|
||||
void FConvaiEditorSettingsCustomization::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
|
||||
{
|
||||
IDetailCategoryBuilder& ParentCategory = DetailBuilder.EditCategory(TEXT("Convai API"), FText::FromString("Convai API"));
|
||||
|
||||
ParentCategory.AddCustomRow(FText::FromString(""))
|
||||
.WholeRowWidget
|
||||
[
|
||||
SNew(SHorizontalBox)
|
||||
];
|
||||
|
||||
IDetailCategoryBuilder& SubCategory = DetailBuilder.EditCategory(TEXT("Long Term Memory"), FText::FromString("Long Term Memory"));
|
||||
|
||||
// Add a compact button to the category
|
||||
SubCategory.AddCustomRow(FText::FromString("Spawn Tab"))
|
||||
.WholeRowWidget
|
||||
[
|
||||
SNew(SHorizontalBox)
|
||||
+ SHorizontalBox::Slot()
|
||||
.HAlign(HAlign_Left)
|
||||
.VAlign(VAlign_Center)
|
||||
.AutoWidth()
|
||||
[
|
||||
SNew(SButton)
|
||||
.Text(FText::FromString("Manage Speaker ID"))
|
||||
.HAlign(HAlign_Center)
|
||||
.VAlign(VAlign_Center)
|
||||
.ContentPadding(FMargin(8.0f, 2.0f))
|
||||
.OnClicked(this, &FConvaiEditorSettingsCustomization::OnSpawnTabClicked)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
FReply FConvaiEditorSettingsCustomization::OnSpawnTabClicked()
|
||||
{
|
||||
const FString WidgetPath = TEXT("/ConvAI/Editor/EUW_LTM.EUW_LTM");
|
||||
|
||||
UEditorUtilityWidgetBlueprint* WidgetBlueprint = LoadObject<UEditorUtilityWidgetBlueprint>(nullptr, *WidgetPath);
|
||||
|
||||
if (WidgetBlueprint)
|
||||
{
|
||||
if (UEditorUtilitySubsystem* Subsystem = GEditor->GetEditorSubsystem<UEditorUtilitySubsystem>())
|
||||
{
|
||||
Subsystem->SpawnAndRegisterTab(WidgetBlueprint);
|
||||
CONVAI_LOG(LogTemp, Log, TEXT("Successfully spawned the Editor Utility Widget: %s"), *WidgetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
CONVAI_LOG(LogTemp, Warning, TEXT("Failed to get Editor Utility Subsystem."));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CONVAI_LOG(LogTemp, Error, TEXT("Failed to load Editor Utility Widget Blueprint at path: %s"), *WidgetPath);
|
||||
}
|
||||
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "ConvaiEditorUtils.h"
|
||||
|
||||
#include "EditorUtilityLibrary.h"
|
||||
#include "../Convai.h"
|
||||
#include "ISettingsModule.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
#include "EditorAssetLibrary.h"
|
||||
#include "Utility/Log/ConvaiLogger.h"
|
||||
|
||||
void UConvaiEditorUtils::ConvaiAddSpeakerID(const FConvaiSpeakerInfo& Speaker)
|
||||
{
|
||||
UConvaiSettings* Settings = GetMutableDefault<UConvaiSettings>();
|
||||
if (!Settings)
|
||||
{
|
||||
CONVAI_LOG(LogTemp, Warning, TEXT("ConvaiSettings not found."));
|
||||
return;
|
||||
}
|
||||
|
||||
int32 Index = Settings->SpeakerIDs.IndexOfByPredicate([&](const FConvaiSpeakerInfo& Info)
|
||||
{
|
||||
return Info.SpeakerID == Speaker.SpeakerID;
|
||||
});
|
||||
|
||||
if (Index == INDEX_NONE)
|
||||
{
|
||||
Settings->SpeakerIDs.Add(Speaker);
|
||||
//CONVAI_LOG(LogTemp, Log, TEXT("Added Speaker: ID=%s, Name=%s"), *Speaker.SpeakerID, *Speaker.Name);
|
||||
}
|
||||
|
||||
Settings->SaveConfig(CPF_Config, *Settings->GetDefaultConfigFilename());
|
||||
|
||||
RefreshConvaiSettings();
|
||||
}
|
||||
|
||||
void UConvaiEditorUtils::ConvaiRemoveSpeakerID(const FString& SpeakerID)
|
||||
{
|
||||
UConvaiSettings* Settings = GetMutableDefault<UConvaiSettings>();
|
||||
if (!Settings)
|
||||
{
|
||||
CONVAI_LOG(LogTemp, Warning, TEXT("ConvaiSettings not found."));
|
||||
return;
|
||||
}
|
||||
|
||||
int32 Index = Settings->SpeakerIDs.IndexOfByPredicate([&](const FConvaiSpeakerInfo& Info)
|
||||
{
|
||||
return Info.SpeakerID == SpeakerID;
|
||||
});
|
||||
|
||||
if (Index != INDEX_NONE)
|
||||
{
|
||||
Settings->SpeakerIDs.RemoveAt(Index);
|
||||
//CONVAI_LOG(LogTemp, Log, TEXT("Removed Speaker: ID=%s"), *SpeakerID);
|
||||
}
|
||||
else
|
||||
{
|
||||
CONVAI_LOG(LogTemp, Warning, TEXT("Speaker ID not found: %s"), *SpeakerID);
|
||||
}
|
||||
|
||||
Settings->SaveConfig(CPF_Config, *Settings->GetDefaultConfigFilename());
|
||||
|
||||
RefreshConvaiSettings();
|
||||
}
|
||||
|
||||
#define LOCTEXT_NAMESPACE "Convai"
|
||||
void UConvaiEditorUtils::RefreshConvaiSettings()
|
||||
{
|
||||
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
|
||||
{
|
||||
// Unregister the settings
|
||||
SettingsModule->UnregisterSettings("Project", "Plugins", "Convai");
|
||||
|
||||
// Re-register the settings
|
||||
UConvaiSettings* Settings = GetMutableDefault<UConvaiSettings>();
|
||||
SettingsModule->RegisterSettings("Project", "Plugins", "Convai",
|
||||
LOCTEXT("RuntimeSettingsName", "Convai"),
|
||||
LOCTEXT("RuntimeSettingsDescription", "Configure Convai settings"),
|
||||
Settings);
|
||||
}
|
||||
}
|
||||
|
||||
TArray<UObject*> UConvaiEditorUtils::BeginTransactionAndGetSelectedAssets(const FString& Context, const FText& Description)
|
||||
{
|
||||
UKismetSystemLibrary::BeginTransaction(Context, Description, nullptr);
|
||||
return UEditorUtilityLibrary::GetSelectedAssets();
|
||||
}
|
||||
|
||||
void UConvaiEditorUtils::SaveLoadedAssetAndEndTransaction(const TArray<UObject*>& LoadedAssets)
|
||||
{
|
||||
UEditorAssetLibrary::CheckoutLoadedAssets(LoadedAssets);
|
||||
UEditorAssetLibrary::SaveLoadedAssets(LoadedAssets);
|
||||
UKismetSystemLibrary::EndTransaction();
|
||||
}
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
17
ConvAI/Convai/Source/ConvaiEditor/Public/ConvaiEUWBase.h
Normal file
17
ConvAI/Convai/Source/ConvaiEditor/Public/ConvaiEUWBase.h
Normal file
@@ -0,0 +1,17 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "EditorUtilityWidget.h"
|
||||
#include "ConvaiEUWBase.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(Abstract)
|
||||
class CONVAIEDITOR_API UConvaiEUWBase : public UEditorUtilityWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
};
|
||||
39
ConvAI/Convai/Source/ConvaiEditor/Public/ConvaiEditor.h
Normal file
39
ConvAI/Convai/Source/ConvaiEditor/Public/ConvaiEditor.h
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2022 Convai Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Engine/DeveloperSettings.h"
|
||||
#include "IDetailCustomization.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
|
||||
class FToolBarBuilder;
|
||||
class FMenuBuilder;
|
||||
|
||||
class FConvaiEditorModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
|
||||
/** IModuleInterface implementation */
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class FConvaiEditorSettingsCustomization : public IDetailCustomization
|
||||
{
|
||||
public:
|
||||
static TSharedRef<IDetailCustomization> MakeInstance();
|
||||
|
||||
virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override;
|
||||
|
||||
private:
|
||||
FReply OnSpawnTabClicked();
|
||||
};
|
||||
52
ConvAI/Convai/Source/ConvaiEditor/Public/ConvaiEditorUtils.h
Normal file
52
ConvAI/Convai/Source/ConvaiEditor/Public/ConvaiEditorUtils.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
#include "ConvaiDefinitions.h"
|
||||
|
||||
#include "ConvaiEditorUtils.generated.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CONVAIEDITOR_API UConvaiEditorUtils : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Convai|LTM")
|
||||
static void ConvaiAddSpeakerID(const FConvaiSpeakerInfo& Speaker);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Convai|LTM")
|
||||
static void ConvaiRemoveSpeakerID(const FString& SpeakerID);
|
||||
|
||||
//UFUNCTION(BlueprintCallable, Category = "Convai|LTM")
|
||||
static void RefreshConvaiSettings();
|
||||
|
||||
// ---------------------------------CCPack---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begins a transaction in the editor and retrieves the currently selected assets.
|
||||
*
|
||||
* @param Context A string describing the context of the transaction.
|
||||
* @param Description A text description of the transaction.
|
||||
* @return An array of selected assets as UObject references.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Convai|Editor")
|
||||
static TArray<UObject*> BeginTransactionAndGetSelectedAssets(const FString& Context, const FText& Description);
|
||||
|
||||
/**
|
||||
* Saves the loaded assets and ends the current transaction.
|
||||
* @param LoadedAssets An array of assets to save.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Convai|Editor")
|
||||
static void SaveLoadedAssetAndEndTransaction(const TArray<UObject*>& LoadedAssets);
|
||||
|
||||
// ---------------------------------END CCPack---------------------------------------------------------------------
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user