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;
};