mirror of
https://github.com/Ed94/Cog.git
synced 2026-07-29 02:40:04 +00:00
blackboard window now display key and values
This commit is contained in:
@@ -34,8 +34,9 @@ public class CogAI : ModuleRules
|
|||||||
{
|
{
|
||||||
"CoreUObject",
|
"CoreUObject",
|
||||||
"Engine",
|
"Engine",
|
||||||
}
|
"AIModule",
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
DynamicallyLoadedModuleNames.AddRange(
|
DynamicallyLoadedModuleNames.AddRange(
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
#include "CogAIWindow_Blackboard.h"
|
#include "CogAIWindow_Blackboard.h"
|
||||||
|
|
||||||
|
#include "AIController.h"
|
||||||
#include "CogWindowWidgets.h"
|
#include "CogWindowWidgets.h"
|
||||||
|
#include "BrainComponent.h"
|
||||||
|
#include "GameFramework/Pawn.h"
|
||||||
|
#include "BehaviorTree/BlackboardComponent.h"
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void UCogAIWindow_Blackboard::RenderHelp()
|
void UCogAIWindow_Blackboard::RenderHelp()
|
||||||
@@ -21,17 +26,117 @@ void UCogAIWindow_Blackboard::RenderContent()
|
|||||||
{
|
{
|
||||||
Super::RenderContent();
|
Super::RenderContent();
|
||||||
|
|
||||||
if (ImGui::BeginTable("Actions", 3, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize))
|
|
||||||
|
if (ImGui::BeginMenuBar())
|
||||||
{
|
{
|
||||||
ImGui::TableSetupColumn("Action", ImGuiTableColumnFlags_WidthFixed);
|
if (ImGui::BeginMenu("Options"))
|
||||||
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthStretch);
|
{
|
||||||
ImGui::TableSetupColumn("Inject", ImGuiTableColumnFlags_WidthStretch);
|
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();
|
ImGui::TableHeadersRow();
|
||||||
|
|
||||||
|
const FString CommonTypePrefix = UBlackboardKeyType::StaticClass()->GetName().AppendChar(TEXT('_'));
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
uint8 Offset = 0;
|
||||||
ImGui::TableNextColumn();
|
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();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
#include "CogWindow.h"
|
#include "CogWindow.h"
|
||||||
#include "CogAIWindow_Blackboard.generated.h"
|
#include "CogAIWindow_Blackboard.generated.h"
|
||||||
|
|
||||||
class UCogAIDataAsset;
|
namespace FBlackboard { typedef uint8 FKey; }
|
||||||
|
class UBlackboardData;
|
||||||
|
|
||||||
UCLASS(Config = Cog)
|
UCLASS(Config = Cog)
|
||||||
class COGAI_API UCogAIWindow_Blackboard : public UCogWindow
|
class COGAI_API UCogAIWindow_Blackboard : public UCogWindow
|
||||||
@@ -15,10 +16,6 @@ public:
|
|||||||
|
|
||||||
UCogAIWindow_Blackboard();
|
UCogAIWindow_Blackboard();
|
||||||
|
|
||||||
//const UCogAIDataAsset* GetAsset() const { return Asset.Get(); }
|
|
||||||
|
|
||||||
//void SetAsset(const UCogAIDataAsset* Value) { Asset = Value; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void RenderHelp();
|
void RenderHelp();
|
||||||
@@ -27,7 +24,9 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
UPROPERTY(Config)
|
||||||
|
bool bSortByName = true;
|
||||||
|
|
||||||
|
ImGuiTextFilter Filter;
|
||||||
|
|
||||||
//UPROPERTY()
|
|
||||||
//TWeakObjectPtr<const UCogAIDataAsset> Asset = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ void UCogAbilityWindow_Attributes::ResetConfig()
|
|||||||
{
|
{
|
||||||
Super::ResetConfig();
|
Super::ResetConfig();
|
||||||
|
|
||||||
bSortByNameSetting = true;
|
bSortByName = true;
|
||||||
bGroupByAttributeSetSetting = false;
|
bGroupByAttributeSet = false;
|
||||||
bGroupByCategorySetting = false;
|
bGroupByCategory = false;
|
||||||
bShowOnlyModified = false;
|
bShowOnlyModified = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +54,9 @@ void UCogAbilityWindow_Attributes::RenderContent()
|
|||||||
{
|
{
|
||||||
if (ImGui::BeginMenu("Options"))
|
if (ImGui::BeginMenu("Options"))
|
||||||
{
|
{
|
||||||
ImGui::Checkbox("Sort by name", &bSortByNameSetting);
|
ImGui::Checkbox("Sort by name", &bSortByName);
|
||||||
ImGui::Checkbox("Group by attribute set", &bGroupByAttributeSetSetting);
|
ImGui::Checkbox("Group by attribute set", &bGroupByAttributeSet);
|
||||||
ImGui::Checkbox("Group by category", &bGroupByCategorySetting);
|
ImGui::Checkbox("Group by category", &bGroupByCategory);
|
||||||
ImGui::Checkbox("Show Only Modified", &bShowOnlyModified);
|
ImGui::Checkbox("Show Only Modified", &bShowOnlyModified);
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
@@ -66,10 +66,18 @@ void UCogAbilityWindow_Attributes::RenderContent()
|
|||||||
ImGui::EndMenuBar();
|
ImGui::EndMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bGroupByAttributeSet = Filter.IsActive() == false && bShowOnlyModified == false && bGroupByAttributeSetSetting;
|
bool bGroupByAttributeSetValue = Filter.IsActive() == false && bShowOnlyModified == false && bGroupByAttributeSet;
|
||||||
bool bGroupByCategory = Filter.IsActive() == false && bShowOnlyModified == false && bGroupByCategorySetting;
|
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::TableSetupScrollFreeze(0, 1);
|
||||||
ImGui::TableSetupColumn("Attribute");
|
ImGui::TableSetupColumn("Attribute");
|
||||||
@@ -89,7 +97,7 @@ void UCogAbilityWindow_Attributes::RenderContent()
|
|||||||
// Add an tree node categories are shown
|
// Add an tree node categories are shown
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
bool bOpenAttributeSet = true;
|
bool bOpenAttributeSet = true;
|
||||||
if (bGroupByAttributeSet)
|
if (bGroupByAttributeSetValue)
|
||||||
{
|
{
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
@@ -114,7 +122,7 @@ void UCogAbilityWindow_Attributes::RenderContent()
|
|||||||
// Sort attributes by category to make sure categories are displayed in alphabetical order
|
// Sort attributes by category to make sure categories are displayed in alphabetical order
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
if (bGroupByCategory)
|
if (bGroupByCategoryValue)
|
||||||
{
|
{
|
||||||
AllAttributes.Sort([](const FGameplayAttribute& Attribute1, const FGameplayAttribute& Attribute2)
|
AllAttributes.Sort([](const FGameplayAttribute& Attribute1, const FGameplayAttribute& Attribute2)
|
||||||
{
|
{
|
||||||
@@ -134,7 +142,7 @@ void UCogAbilityWindow_Attributes::RenderContent()
|
|||||||
FString Category = TEXT("Default");
|
FString Category = TEXT("Default");
|
||||||
|
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
if (bGroupByCategory)
|
if (bGroupByCategoryValue)
|
||||||
{
|
{
|
||||||
FString ActualCategory = Attribute.GetUProperty() != nullptr ? Attribute.GetUProperty()->GetMetaData(TEXT("Category")) : "";
|
FString ActualCategory = Attribute.GetUProperty() != nullptr ? Attribute.GetUProperty()->GetMetaData(TEXT("Category")) : "";
|
||||||
if (ActualCategory.IsEmpty() == false)
|
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
|
// Add a tree node with the name of the category if categories are shown
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
bool bOpenCategory = true;
|
bool bOpenCategory = true;
|
||||||
if (bGroupByCategory)
|
if (bGroupByCategoryValue)
|
||||||
{
|
{
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
@@ -167,7 +175,7 @@ void UCogAbilityWindow_Attributes::RenderContent()
|
|||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
// Sort attributes within a category by their name
|
// Sort attributes within a category by their name
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
if (bSortByNameSetting)
|
if (bSortByName)
|
||||||
{
|
{
|
||||||
AttributesInCategory.Sort([](const FGameplayAttribute& Lhs, const FGameplayAttribute& Rhs)
|
AttributesInCategory.Sort([](const FGameplayAttribute& Lhs, const FGameplayAttribute& Rhs)
|
||||||
{
|
{
|
||||||
@@ -264,14 +272,14 @@ void UCogAbilityWindow_Attributes::RenderContent()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bOpenCategory && bGroupByCategory)
|
if (bOpenCategory && bGroupByCategoryValue)
|
||||||
{
|
{
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bOpenAttributeSet && bGroupByAttributeSet)
|
if (bOpenAttributeSet && bGroupByAttributeSetValue)
|
||||||
{
|
{
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ protected:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY(Config)
|
UPROPERTY(Config)
|
||||||
bool bSortByNameSetting = true;
|
bool bSortByName = true;
|
||||||
|
|
||||||
UPROPERTY(Config)
|
UPROPERTY(Config)
|
||||||
bool bGroupByAttributeSetSetting = false;
|
bool bGroupByAttributeSet = false;
|
||||||
|
|
||||||
UPROPERTY(Config)
|
UPROPERTY(Config)
|
||||||
bool bGroupByCategorySetting = false;
|
bool bGroupByCategory = false;
|
||||||
|
|
||||||
UPROPERTY(Config)
|
UPROPERTY(Config)
|
||||||
bool bShowOnlyModified = false;
|
bool bShowOnlyModified = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user