diff --git a/Plugins/CogAI/Source/CogAI/CogAI.Build.cs b/Plugins/CogAI/Source/CogAI/CogAI.Build.cs index ba8d7b6..efd8209 100644 --- a/Plugins/CogAI/Source/CogAI/CogAI.Build.cs +++ b/Plugins/CogAI/Source/CogAI/CogAI.Build.cs @@ -34,8 +34,9 @@ public class CogAI : ModuleRules { "CoreUObject", "Engine", - } - ); + "AIModule", + } + ); DynamicallyLoadedModuleNames.AddRange( diff --git a/Plugins/CogAI/Source/CogAI/Private/CogAIWindow_Blackboard.cpp b/Plugins/CogAI/Source/CogAI/Private/CogAIWindow_Blackboard.cpp index a5d946a..40301a8 100644 --- a/Plugins/CogAI/Source/CogAI/Private/CogAIWindow_Blackboard.cpp +++ b/Plugins/CogAI/Source/CogAI/Private/CogAIWindow_Blackboard.cpp @@ -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(Selection); + if (Pawn == nullptr) + { + ImGui::TextDisabled("Selection is not a pawn"); + return; + } + + AAIController* AIController = Cast(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(); } } + diff --git a/Plugins/CogAI/Source/CogAI/Public/CogAIWindow_Blackboard.h b/Plugins/CogAI/Source/CogAI/Public/CogAIWindow_Blackboard.h index 4fa8560..2888046 100644 --- a/Plugins/CogAI/Source/CogAI/Public/CogAIWindow_Blackboard.h +++ b/Plugins/CogAI/Source/CogAI/Public/CogAIWindow_Blackboard.h @@ -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 Asset = nullptr; }; diff --git a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Attributes.cpp b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Attributes.cpp index bd7336f..f71a2d8 100644 --- a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Attributes.cpp +++ b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Attributes.cpp @@ -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(); } diff --git a/Plugins/CogAbility/Source/CogAbility/Public/CogAbilityWindow_Attributes.h b/Plugins/CogAbility/Source/CogAbility/Public/CogAbilityWindow_Attributes.h index 34a45e4..215d150 100644 --- a/Plugins/CogAbility/Source/CogAbility/Public/CogAbilityWindow_Attributes.h +++ b/Plugins/CogAbility/Source/CogAbility/Public/CogAbilityWindow_Attributes.h @@ -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;