CogWindow: CogWindows are not UObject anymore

CogWindows are now normal object because we want to be able to Ifdef them, and UObject cannot be ifdef. CogWindows were UObject mainly for saving their config. The configs have been moved in separated class, which are UObject.
This commit is contained in:
Arnaud Jamin
2023-10-27 02:39:33 -04:00
parent 42ca1afc6a
commit e72504b47a
73 changed files with 1448 additions and 981 deletions
@@ -14,8 +14,19 @@
#include "GameFramework/Pawn.h"
#include "imgui_internal.h"
//--------------------------------------------------------------------------------------------------------------------------
void UCogAIWindow_BehaviorTree::RenderHelp()
void FCogAIWindow_BehaviorTree::Initialize()
{
Super::Initialize();
bHasMenu = true;
Config = GetConfig<UCogAIConfig_BehaviorTree>();
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogAIWindow_BehaviorTree::RenderHelp()
{
ImGui::Text(
"This window displays the behavior tree of the selected actor. "
@@ -23,13 +34,7 @@ void UCogAIWindow_BehaviorTree::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
UCogAIWindow_BehaviorTree::UCogAIWindow_BehaviorTree()
{
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAIWindow_BehaviorTree::GameTick(float DeltaTime)
void FCogAIWindow_BehaviorTree::GameTick(float DeltaTime)
{
Super::GameTick(DeltaTime);
@@ -72,9 +77,9 @@ void UCogAIWindow_BehaviorTree::GameTick(float DeltaTime)
if (i > 0)
{
FCogDebugDraw::Arrow(LogCogAI, this, LastLocation, Location, FColor::White, false, 0);
FCogDebugDraw::Point(LogCogAI, this, LastLocation, 10.0f, FColor::White, false, 0);
FCogDebugDraw::Point(LogCogAI, this, Location, 10.0f, FColor::White, false, 0);
FCogDebugDraw::Arrow(LogCogAI, Pawn, LastLocation, Location, FColor::White, false, 0);
FCogDebugDraw::Point(LogCogAI, Pawn, LastLocation, 10.0f, FColor::White, false, 0);
FCogDebugDraw::Point(LogCogAI, Pawn, Location, 10.0f, FColor::White, false, 0);
}
LastLocation = Location;
@@ -118,16 +123,22 @@ void UCogAIWindow_BehaviorTree::GameTick(float DeltaTime)
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAIWindow_BehaviorTree::RenderContent()
void FCogAIWindow_BehaviorTree::RenderContent()
{
Super::RenderContent();
if (Config == nullptr)
{
ImGui::TextDisabled("No Config");
return;
}
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("Options"))
{
ImGui::ColorEdit4("Active Color", (float*)&ActiveColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Inactive Color", (float*)&InactiveColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Active Color", (float*)&Config->ActiveColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Inactive Color", (float*)&Config->InactiveColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::EndMenu();
}
@@ -206,7 +217,7 @@ void UCogAIWindow_BehaviorTree::RenderContent()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAIWindow_BehaviorTree::RenderNode(UBehaviorTreeComponent& BehaviorTreeComponent, UBTNode* Node, bool OpenAllChildren)
void FCogAIWindow_BehaviorTree::RenderNode(UBehaviorTreeComponent& BehaviorTreeComponent, UBTNode* Node, bool OpenAllChildren)
{
const char* NodeName = TCHAR_TO_ANSI(*Node->GetNodeName());
const bool ShowNode = Filter.PassFilter(NodeName);
@@ -346,7 +357,7 @@ void UCogAIWindow_BehaviorTree::RenderNode(UBehaviorTreeComponent& BehaviorTreeC
// Name
//------------------------
ImGui::SameLine();
const ImVec4 NameColor = IsActive ? FCogImguiHelper::ToImVec4(ActiveColor) : FCogImguiHelper::ToImVec4(InactiveColor);
const ImVec4 NameColor = IsActive ? FCogImguiHelper::ToImVec4(Config->ActiveColor) : FCogImguiHelper::ToImVec4(Config->InactiveColor);
ImGui::TextColored(NameColor, "%s", NodeName);
}
@@ -6,9 +6,18 @@
#include "GameFramework/Pawn.h"
#include "BehaviorTree/BlackboardComponent.h"
//--------------------------------------------------------------------------------------------------------------------------
void FCogAIWindow_Blackboard::Initialize()
{
Super::Initialize();
bHasMenu = true;
Config = GetConfig<UCogAIConfig_Blackboard>();
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAIWindow_Blackboard::RenderHelp()
void FCogAIWindow_Blackboard::RenderHelp()
{
ImGui::Text(
"This window displays the blackboard of the selected actor. "
@@ -16,22 +25,23 @@ void UCogAIWindow_Blackboard::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
UCogAIWindow_Blackboard::UCogAIWindow_Blackboard()
void FCogAIWindow_Blackboard::ResetConfig()
{
bHasMenu = true;
Super::ResetConfig();
Config->Reset();
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAIWindow_Blackboard::RenderContent()
void FCogAIWindow_Blackboard::RenderContent()
{
Super::RenderContent();
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("Options"))
{
ImGui::Checkbox("Sort by name", &bSortByName);
ImGui::Checkbox("Sort by name", &Config->bSortByName);
ImGui::EndMenu();
}
@@ -96,7 +106,7 @@ void UCogAIWindow_Blackboard::RenderContent()
Offset += It->Keys.Num();
}
if (bSortByName)
if (Config->bSortByName)
{
Keys.Sort([](const FBlackboardEntry& Key1, const FBlackboardEntry& Key2)
{
@@ -2,19 +2,21 @@
#include "CoreMinimal.h"
#include "CogWindow.h"
#include "CogWindowConfig.h"
#include "CogAIWindow_BehaviorTree.generated.h"
class UBehaviorTreeComponent;
class UBTNode;
class UCogAIConfig_BehaviorTree;
UCLASS(Config = Cog)
class COGAI_API UCogAIWindow_BehaviorTree : public UCogWindow
//--------------------------------------------------------------------------------------------------------------------------
class COGAI_API FCogAIWindow_BehaviorTree : public FCogWindow
{
GENERATED_BODY()
typedef FCogWindow Super;
public:
UCogAIWindow_BehaviorTree();
virtual void Initialize() override;
protected:
@@ -28,11 +30,30 @@ protected:
private:
ImGuiTextFilter Filter;
TObjectPtr<UCogAIConfig_BehaviorTree> Config = nullptr;
};
//--------------------------------------------------------------------------------------------------------------------------
UCLASS(Config = Cog)
class UCogAIConfig_BehaviorTree : public UCogWindowConfig
{
GENERATED_BODY()
public:
UPROPERTY(Config)
FVector4f ActiveColor = FVector4f(1.0f, 1.0f, 1.0f, 1.0f);
UPROPERTY(Config)
FVector4f InactiveColor = FVector4f(1.0f, 1.0f, 1.0f, 0.2f);
ImGuiTextFilter Filter;
};
virtual void Reset() override
{
Super::Reset();
ActiveColor = FVector4f(1.0f, 1.0f, 1.0f, 1.0f);
InactiveColor = FVector4f(1.0f, 1.0f, 1.0f, 0.2f);
}
};
@@ -2,27 +2,50 @@
#include "CoreMinimal.h"
#include "CogWindow.h"
#include "CogWindowConfig.h"
#include "CogAIWindow_Blackboard.generated.h"
UCLASS(Config = Cog)
class COGAI_API UCogAIWindow_Blackboard : public UCogWindow
class UCogAIConfig_Blackboard;
//--------------------------------------------------------------------------------------------------------------------------
class COGAI_API FCogAIWindow_Blackboard : public FCogWindow
{
GENERATED_BODY()
typedef FCogWindow Super;
public:
UCogAIWindow_Blackboard();
virtual void Initialize() override;
protected:
void RenderHelp();
virtual void ResetConfig() override;
virtual void RenderHelp() override;
virtual void RenderContent() override;
private:
ImGuiTextFilter Filter;
TObjectPtr<UCogAIConfig_Blackboard> Config;
};
//--------------------------------------------------------------------------------------------------------------------------
UCLASS(Config = Cog)
class UCogAIConfig_Blackboard : public UCogWindowConfig
{
GENERATED_BODY()
public:
UPROPERTY(Config)
bool bSortByName = true;
ImGuiTextFilter Filter;
};
virtual void Reset() override
{
Super::Reset();
bSortByName = true;
}
};