blackboard window now display key and values

This commit is contained in:
Arnaud Jamin
2023-10-16 12:14:46 -04:00
parent fc5abf7e8f
commit 283608e6ff
5 changed files with 147 additions and 34 deletions
+3 -2
View File
@@ -34,8 +34,9 @@ public class CogAI : ModuleRules
{
"CoreUObject",
"Engine",
}
);
"AIModule",
}
);
DynamicallyLoadedModuleNames.AddRange(
@@ -1,6 +1,11 @@
#include "CogAIWindow_Blackboard.h"
#include "AIController.h"
#include "CogWindowWidgets.h"
#include "BrainComponent.h"
#include "GameFramework/Pawn.h"
#include "BehaviorTree/BlackboardComponent.h"
//--------------------------------------------------------------------------------------------------------------------------
void UCogAIWindow_Blackboard::RenderHelp()
@@ -21,17 +26,117 @@ void UCogAIWindow_Blackboard::RenderContent()
{
Super::RenderContent();
if (ImGui::BeginTable("Actions", 3, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize))
if (ImGui::BeginMenuBar())
{
ImGui::TableSetupColumn("Action", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Inject", ImGuiTableColumnFlags_WidthStretch);
if (ImGui::BeginMenu("Options"))
{
ImGui::Checkbox("Sort by name", &bSortByName);
ImGui::EndMenu();
}
FCogWindowWidgets::MenuSearchBar(Filter);
ImGui::EndMenuBar();
}
AActor* Selection = GetSelection();
if (Selection == nullptr)
{
ImGui::TextDisabled("No Selection");
return;
}
APawn* Pawn = Cast<APawn>(Selection);
if (Pawn == nullptr)
{
ImGui::TextDisabled("Selection is not a pawn");
return;
}
AAIController* AIController = Cast<AAIController>(Pawn->Controller);
if (AIController == nullptr)
{
ImGui::TextDisabled("Selection has no AIController");
return;
}
UBrainComponent* Brain = AIController->GetBrainComponent();
if (Brain == nullptr)
{
ImGui::TextDisabled("Selection controller has no BrainComponent");
return;
}
UBlackboardComponent* Blackboard = Brain->GetBlackboardComponent();
if (Blackboard == nullptr)
{
ImGui::TextDisabled("Selection controller has no BlackboardComponent");
return;
}
UBlackboardData* BlackboardAsset = Blackboard->GetBlackboardAsset();
if (BlackboardAsset == nullptr)
{
ImGui::TextDisabled("BlackboardComponent has no BlackboardAsset");
return;
}
if (ImGui::BeginTable("Blackboard", 3, ImGuiTableFlags_SizingFixedFit
| ImGuiTableFlags_Resizable
| ImGuiTableFlags_NoBordersInBodyUntilResize
| ImGuiTableFlags_ScrollY
| ImGuiTableFlags_RowBg
| ImGuiTableFlags_BordersOuter
| ImGuiTableFlags_BordersV
| ImGuiTableFlags_Reorderable
| ImGuiTableFlags_Hideable))
{
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_DefaultHide);
ImGui::TableSetupColumn("Key");
ImGui::TableSetupColumn("Value");
ImGui::TableHeadersRow();
const FString CommonTypePrefix = UBlackboardKeyType::StaticClass()->GetName().AppendChar(TEXT('_'));
ImGui::TableNextColumn();
ImGui::TableNextColumn();
uint8 Offset = 0;
for (UBlackboardData* It = BlackboardAsset; It; It = It->Parent)
{
for (int32 KeyID = 0; KeyID < It->Keys.Num(); KeyID++)
{
const FBlackboardEntry* Key = BlackboardAsset->GetKey(KeyID);
if (Key == nullptr)
{
continue;
}
const char* KeyName = TCHAR_TO_ANSI(*Key->EntryName.ToString());
if (Filter.PassFilter(KeyName) == false)
{
continue;
}
ImGui::TableNextRow();
ImGui::TableNextColumn();
const FString FullKeyType = Key->KeyType ? GetNameSafe(Key->KeyType->GetClass()) : FString();
const FString DescKeyType = FullKeyType.StartsWith(CommonTypePrefix) ? FullKeyType.RightChop(CommonTypePrefix.Len()) : FullKeyType;
ImGui::Text("%s", TCHAR_TO_ANSI(*DescKeyType));
ImGui::TableNextColumn();
ImGui::Text("%s", KeyName);
ImGui::TableNextColumn();
const uint8* ValueData = Blackboard->GetKeyRawData(KeyID);
FString ValueDesc = Key->KeyType && ValueData ? *(Key->KeyType->WrappedDescribeValue(*Blackboard, ValueData)) : TEXT("Empty");
ImGui::Text("%s", TCHAR_TO_ANSI(*ValueDesc));
}
Offset += It->Keys.Num();
}
ImGui::EndTable();
}
}
@@ -4,7 +4,8 @@
#include "CogWindow.h"
#include "CogAIWindow_Blackboard.generated.h"
class UCogAIDataAsset;
namespace FBlackboard { typedef uint8 FKey; }
class UBlackboardData;
UCLASS(Config = Cog)
class COGAI_API UCogAIWindow_Blackboard : public UCogWindow
@@ -15,10 +16,6 @@ public:
UCogAIWindow_Blackboard();
//const UCogAIDataAsset* GetAsset() const { return Asset.Get(); }
//void SetAsset(const UCogAIDataAsset* Value) { Asset = Value; }
protected:
void RenderHelp();
@@ -27,7 +24,9 @@ protected:
private:
UPROPERTY(Config)
bool bSortByName = true;
ImGuiTextFilter Filter;
//UPROPERTY()
//TWeakObjectPtr<const UCogAIDataAsset> Asset = nullptr;
};
@@ -33,9 +33,9 @@ void UCogAbilityWindow_Attributes::ResetConfig()
{
Super::ResetConfig();
bSortByNameSetting = true;
bGroupByAttributeSetSetting = false;
bGroupByCategorySetting = false;
bSortByName = true;
bGroupByAttributeSet = false;
bGroupByCategory = false;
bShowOnlyModified = false;
}
@@ -54,9 +54,9 @@ void UCogAbilityWindow_Attributes::RenderContent()
{
if (ImGui::BeginMenu("Options"))
{
ImGui::Checkbox("Sort by name", &bSortByNameSetting);
ImGui::Checkbox("Group by attribute set", &bGroupByAttributeSetSetting);
ImGui::Checkbox("Group by category", &bGroupByCategorySetting);
ImGui::Checkbox("Sort by name", &bSortByName);
ImGui::Checkbox("Group by attribute set", &bGroupByAttributeSet);
ImGui::Checkbox("Group by category", &bGroupByCategory);
ImGui::Checkbox("Show Only Modified", &bShowOnlyModified);
ImGui::EndMenu();
}
@@ -66,10 +66,18 @@ void UCogAbilityWindow_Attributes::RenderContent()
ImGui::EndMenuBar();
}
bool bGroupByAttributeSet = Filter.IsActive() == false && bShowOnlyModified == false && bGroupByAttributeSetSetting;
bool bGroupByCategory = Filter.IsActive() == false && bShowOnlyModified == false && bGroupByCategorySetting;
bool bGroupByAttributeSetValue = Filter.IsActive() == false && bShowOnlyModified == false && bGroupByAttributeSet;
bool bGroupByCategoryValue = Filter.IsActive() == false && bShowOnlyModified == false && bGroupByCategory;
if (ImGui::BeginTable("Attributes", 3, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable))
if (ImGui::BeginTable("Attributes", 3, ImGuiTableFlags_SizingFixedFit
| ImGuiTableFlags_Resizable
| ImGuiTableFlags_NoBordersInBodyUntilResize
| ImGuiTableFlags_ScrollY
| ImGuiTableFlags_RowBg
| ImGuiTableFlags_BordersOuter
| ImGuiTableFlags_BordersV
| ImGuiTableFlags_Reorderable
| ImGuiTableFlags_Hideable))
{
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Attribute");
@@ -89,7 +97,7 @@ void UCogAbilityWindow_Attributes::RenderContent()
// Add an tree node categories are shown
//------------------------------------------------------------------------------------------
bool bOpenAttributeSet = true;
if (bGroupByAttributeSet)
if (bGroupByAttributeSetValue)
{
ImGui::TableNextRow();
ImGui::TableNextColumn();
@@ -114,7 +122,7 @@ void UCogAbilityWindow_Attributes::RenderContent()
// Sort attributes by category to make sure categories are displayed in alphabetical order
//------------------------------------------------------------------------------------------
#if WITH_EDITORONLY_DATA
if (bGroupByCategory)
if (bGroupByCategoryValue)
{
AllAttributes.Sort([](const FGameplayAttribute& Attribute1, const FGameplayAttribute& Attribute2)
{
@@ -134,7 +142,7 @@ void UCogAbilityWindow_Attributes::RenderContent()
FString Category = TEXT("Default");
#if WITH_EDITORONLY_DATA
if (bGroupByCategory)
if (bGroupByCategoryValue)
{
FString ActualCategory = Attribute.GetUProperty() != nullptr ? Attribute.GetUProperty()->GetMetaData(TEXT("Category")) : "";
if (ActualCategory.IsEmpty() == false)
@@ -153,7 +161,7 @@ void UCogAbilityWindow_Attributes::RenderContent()
// Add a tree node with the name of the category if categories are shown
//------------------------------------------------------------------------------------------
bool bOpenCategory = true;
if (bGroupByCategory)
if (bGroupByCategoryValue)
{
ImGui::TableNextRow();
ImGui::TableNextColumn();
@@ -167,7 +175,7 @@ void UCogAbilityWindow_Attributes::RenderContent()
//------------------------------------------------------------------------------------------
// Sort attributes within a category by their name
//------------------------------------------------------------------------------------------
if (bSortByNameSetting)
if (bSortByName)
{
AttributesInCategory.Sort([](const FGameplayAttribute& Lhs, const FGameplayAttribute& Rhs)
{
@@ -264,14 +272,14 @@ void UCogAbilityWindow_Attributes::RenderContent()
}
}
if (bOpenCategory && bGroupByCategory)
if (bOpenCategory && bGroupByCategoryValue)
{
ImGui::TreePop();
}
}
}
if (bOpenAttributeSet && bGroupByAttributeSet)
if (bOpenAttributeSet && bGroupByAttributeSetValue)
{
ImGui::TreePop();
}
@@ -40,13 +40,13 @@ protected:
private:
UPROPERTY(Config)
bool bSortByNameSetting = true;
bool bSortByName = true;
UPROPERTY(Config)
bool bGroupByAttributeSetSetting = false;
bool bGroupByAttributeSet = false;
UPROPERTY(Config)
bool bGroupByCategorySetting = false;
bool bGroupByCategory = false;
UPROPERTY(Config)
bool bShowOnlyModified = false;