Improve behavior tree

add hover feedback on gamepad buttons
This commit is contained in:
Arnaud Jamin
2023-10-17 17:18:56 -04:00
parent 9b7304004d
commit c8c68ee2b4
12 changed files with 67 additions and 23 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -288,7 +288,7 @@ void UCogEngineWindow_Selection::DrawActorContextMenu(AActor* Actor)
//------------------------
// ContextMenu
//------------------------
ImGui::SetNextWindowSize(ImVec2(FCogWindowWidgets::GetFontWidth() * 20, 0));
ImGui::SetNextWindowSize(ImVec2(FCogWindowWidgets::GetFontWidth() * 30, 0));
if (ImGui::BeginPopupContextItem())
{
if (ImGui::Button("Reset Selection", ImVec2(-1, 0)))
@@ -331,6 +331,10 @@ void UCogEngineWindow_Selection::DrawActorContextMenu(AActor* Actor)
}
}
ImGui::Separator();
ImGui::Checkbox("Save selection", &bReapplySelection);
ImGui::EndPopup();
}
}
@@ -375,7 +375,8 @@ void UCogWindowManager::RenderMenuItem(UCogWindow& Window, const char* MenuItemN
{
if (bShowWindowsInMainMenu)
{
ImGui::SetNextWindowSizeConstraints(ImVec2(FCogWindowWidgets::GetFontWidth() * 40, ImGui::GetTextLineHeightWithSpacing() * 1),
ImGui::SetNextWindowSizeConstraints(
ImVec2(FCogWindowWidgets::GetFontWidth() * 40, ImGui::GetTextLineHeightWithSpacing() * 5),
ImVec2(FCogWindowWidgets::GetFontWidth() * 50, ImGui::GetTextLineHeightWithSpacing() * 60));
if (ImGui::BeginMenu(MenuItemName))
@@ -7,6 +7,7 @@
#include "BehaviorTree/Tasks/BTTask_BlueprintBase.h"
#include "BehaviorTree/Tasks/BTTask_Wait.h"
#include "BrainComponent.h"
#include "CogImguiHelper.h"
#include "CogWindowWidgets.h"
#include "GameFramework/Pawn.h"
#include "imgui_internal.h"
@@ -35,6 +36,8 @@ void UCogAIWindow_BehaviorTree::RenderContent()
{
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::EndMenu();
}
@@ -78,6 +81,19 @@ void UCogAIWindow_BehaviorTree::RenderContent()
return;
}
UBehaviorTree* RootTree = BehaviorTreeComponent->GetRootTree();
if (CurrentTree != RootTree)
{
if (ImGui::CollapsingHeader(TCHAR_TO_ANSI(*GetNameSafe(RootTree)), nullptr, ImGuiTreeNodeFlags_DefaultOpen))
{
RenderNode(*BehaviorTreeComponent, RootTree->RootNode, false);
ImGui::Spacing();
ImGui::Spacing();
}
}
//----------------------------------------------------------------------------------------
// If we use the current tree root node it doesn't seem to be the one instanced.
// Not sure if there is a better way to access it, but we find the root node from
@@ -92,7 +108,10 @@ void UCogAIWindow_BehaviorTree::RenderContent()
if (RootNodeInstanced != nullptr)
{
RenderNode(*BehaviorTreeComponent, const_cast<UBTNode*>(RootNodeInstanced), false);
if (ImGui::CollapsingHeader(TCHAR_TO_ANSI(*GetNameSafe(CurrentTree)), nullptr, ImGuiTreeNodeFlags_DefaultOpen))
{
RenderNode(*BehaviorTreeComponent, const_cast<UBTNode*>(RootNodeInstanced), false);
}
}
}
@@ -104,15 +123,7 @@ void UCogAIWindow_BehaviorTree::RenderNode(UBehaviorTreeComponent& BehaviorTreeC
const UBTCompositeNode* CompositeNode = Cast<UBTCompositeNode>(Node);
bool IsActive = false;
for (const UBTNode* ActiveParentNode = BehaviorTreeComponent.GetActiveNode(); ActiveParentNode != nullptr; ActiveParentNode = ActiveParentNode->GetParentNode())
{
if (Node == ActiveParentNode)
{
IsActive = true;
break;
}
}
const bool IsActive = BehaviorTreeComponent.IsExecutingBranch(Node);
bool OpenChildren = false;
@@ -245,7 +256,7 @@ void UCogAIWindow_BehaviorTree::RenderNode(UBehaviorTreeComponent& BehaviorTreeC
// Name
//------------------------
ImGui::SameLine();
ImVec4 NameColor = IsActive ? ImVec4(0.0f, 1.0f, 0.0f, 1.0f) : ImVec4(1.0f, 1.0f, 1.0f, 0.6f);
const ImVec4 NameColor = IsActive ? FCogImguiHelper::ToImVec4(ActiveColor) : FCogImguiHelper::ToImVec4(InactiveColor);
ImGui::TextColored(NameColor, "%s", NodeName);
}
@@ -26,5 +26,11 @@ protected:
private:
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;
};
@@ -38,6 +38,7 @@ void UCogInputWindow_Gamepad::ResetConfig()
ButtonColor = FVector4f(0.2f, 0.2f, 0.2f, 1.0f);
BorderColor = FVector4f(0.03f, 0.03f, 0.03f, 1.0f);
PressedColor = FVector4f(0.6f, 0.6f, 0.6f, 1.0f);
HoveredColor = FVector4f(0.3f, 0.3f, 0.3f, 1.0f);
InjectColor = FVector4f(1.0f, 0.5f, 0.0f, 0.5f);
Border = 0.02f;
}
@@ -105,8 +106,7 @@ void UCogInputWindow_Gamepad::AddButton(const FKey& Key, const ImVec2& RelativeP
const ImVec2& Size = RelativeSize * CanvasSize.x;
const ImVec2 Position = (CanvasMin + CanvasSize * RelativePosition) - Alignment * Size;
ImU32 Color = ImGui::GetColorU32(ImLerp(FCogImguiHelper::ToImVec4(ButtonColor), FCogImguiHelper::ToImVec4(PressedColor), Value));
bool IsPressed = false;
FCogInjectActionInfo* ActionInfo = Actions.Find(Key);
if (ActionInfo != nullptr)
{
@@ -114,7 +114,7 @@ void UCogInputWindow_Gamepad::AddButton(const FKey& Key, const ImVec2& RelativeP
{
if (Input->GetActionValue(ActionInfo->Action).Get<bool>())
{
Color = FCogImguiHelper::ToImU32(PressedColor);
IsPressed = true;
}
}
}
@@ -125,6 +125,16 @@ void UCogInputWindow_Gamepad::AddButton(const FKey& Key, const ImVec2& RelativeP
OnButtonClicked(ActionInfo);
}
ImU32 Color = FCogImguiHelper::ToImU32(ButtonColor);
if (IsPressed)
{
Color = FCogImguiHelper::ToImU32(PressedColor);
}
else if (ImGui::IsItemHovered())
{
Color = FCogImguiHelper::ToImU32(HoveredColor);
}
InputContextMenu(Key, ActionInfo, nullptr);
if (Border > 0.0f)
@@ -144,8 +154,6 @@ void UCogInputWindow_Gamepad::AddStick(const FKey& Key2D, const FKey& KeyBool, b
{
ImGui::PushID((void*)(&Key2D));
ImU32 Color = Input->GetKeyValue(KeyBool) > 0.0f ? FCogImguiHelper::ToImU32(PressedColor) : FCogImguiHelper::ToImU32(ButtonColor);
FCogInjectActionInfo* ActionInfoBool = Actions.Find(KeyBool);
FCogInjectActionInfo* ActionInfo2D = Actions.Find(Key2D);
@@ -169,6 +177,16 @@ void UCogInputWindow_Gamepad::AddStick(const FKey& Key2D, const FKey& KeyBool, b
OnButtonClicked(ActionInfoBool);
}
ImU32 Color = FCogImguiHelper::ToImU32(ButtonColor);
if (Input->GetKeyValue(KeyBool) > 0.0f)
{
Color = FCogImguiHelper::ToImU32(PressedColor);
}
else if (ImGui::IsItemHovered())
{
Color = FCogImguiHelper::ToImU32(HoveredColor);
}
InputContextMenu(Key2D, ActionInfoBool, ActionInfo2D);
if (Border > 0.0f)
@@ -302,11 +320,12 @@ void UCogInputWindow_Gamepad::RenderContent()
ImGui::Checkbox("Invert Left Stick Y", &bInvertLeftStickY);
ImGui::Checkbox("Invert Right Stick Y", &bInvertRightStickY);
ImGui::Separator();
ImGui::ColorEdit4("Background Color", (float*)&BackgroundColor, ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Border Color", (float*)&BorderColor, ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Button Color", (float*)&ButtonColor, ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Pressed Color", (float*)&PressedColor, ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Inject Color", (float*)&InjectColor, ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Background Color", (float*)&BackgroundColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Border Color", (float*)&BorderColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Button Color", (float*)&ButtonColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Pressed Color", (float*)&PressedColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Hovered Color", (float*)&HoveredColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Inject Color", (float*)&InjectColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogWindowWidgets::SliderWithReset("Border", &Border, 0.0f, 0.1f, 0.02f, "%0.3f");
ImGui::EndPopup();
}
@@ -63,6 +63,9 @@ private:
UPROPERTY(Config)
FVector4f PressedColor = FVector4f(0.6f, 0.6f, 0.6f, 1.0f);
UPROPERTY(Config)
FVector4f HoveredColor = FVector4f(0.3f, 0.3f, 0.3f, 1.0f);
UPROPERTY(Config)
FVector4f InjectColor = FVector4f(1.0f, 0.5f, 0.0f, 0.5f);