From 429123dbd3fe0837943a7870fd286f5448eabb11 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Fri, 3 Nov 2023 23:38:53 -0400 Subject: [PATCH] CogAbility: Add menu to sort and filter Tags window --- .../Private/CogAbilityWindow_Abilities.cpp | 2 +- .../Private/CogAbilityWindow_Tags.cpp | 175 ++++++++++++------ .../CogAbility/Public/CogAbilityWindow_Tags.h | 36 +++- TODO.txt | 6 +- 4 files changed, 154 insertions(+), 65 deletions(-) diff --git a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Abilities.cpp b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Abilities.cpp index 4b37b28..06b3a00 100644 --- a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Abilities.cpp +++ b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Abilities.cpp @@ -238,7 +238,7 @@ void FCogAbilityWindow_Abilities::RenderAbilitiesTable(UAbilitySystemComponent& | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable)) { - ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("##Activation", ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("Ability"); ImGui::TableSetupColumn("Level"); diff --git a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Tags.cpp b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Tags.cpp index 2b454c9..63ca430 100644 --- a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Tags.cpp +++ b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Tags.cpp @@ -10,7 +10,17 @@ void FCogAbilityWindow_Tags::Initialize() { Super::Initialize(); - bHasMenu = false; + bHasMenu = true; + + Config = GetConfig(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogAbilityWindow_Tags::ResetConfig() +{ + Super::ResetConfig(); + + Config->Reset(); } //-------------------------------------------------------------------------------------------------------------------------- @@ -24,6 +34,8 @@ void FCogAbilityWindow_Tags::RenderContent() { Super::RenderContent(); + RenderMenu(); + UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetSelection(), true); if (AbilitySystemComponent == nullptr) { @@ -34,11 +46,113 @@ void FCogAbilityWindow_Tags::RenderContent() AbilitySystemComponent->GetOwnedGameplayTags(OwnedTags); AbilitySystemComponent->GetBlockedAbilityTags(BlockedTags); - DrawTagContainer("Owned Tags", *AbilitySystemComponent, OwnedTags); + RenderTagContainer("Owned Tags", *AbilitySystemComponent, OwnedTags); } //-------------------------------------------------------------------------------------------------------------------------- -void FCogAbilityWindow_Tags::DrawTag(const UAbilitySystemComponent& AbilitySystemComponent, const FGameplayTag& Tag) +void FCogAbilityWindow_Tags::RenderMenu() +{ + if (ImGui::BeginMenuBar()) + { + if (ImGui::BeginMenu("Options")) + { + ImGui::Checkbox("Sort by Name", &Config->SortByName); + + ImGui::Separator(); + + if (ImGui::MenuItem("Reset")) + { + ResetConfig(); + } + + ImGui::EndMenu(); + } + + FCogWindowWidgets::MenuSearchBar(Filter); + + ImGui::EndMenuBar(); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogAbilityWindow_Tags::RenderTagContainer(const FString& TagContainerName, const UAbilitySystemComponent& AbilitySystemComponent, FGameplayTagContainer& TagContainer) +{ + if (ImGui::BeginTable(TCHAR_TO_ANSI(*TagContainerName), 2, ImGuiTableFlags_SizingFixedFit + | ImGuiTableFlags_Resizable + | ImGuiTableFlags_NoBordersInBodyUntilResize + | ImGuiTableFlags_ScrollY + | ImGuiTableFlags_RowBg + | ImGuiTableFlags_BordersOuter + | ImGuiTableFlags_BordersV + | ImGuiTableFlags_Reorderable + | ImGuiTableFlags_Hideable)) + { + ImGui::TableSetupScrollFreeze(0, 1); + ImGui::TableSetupColumn("Count"); + ImGui::TableSetupColumn(TCHAR_TO_ANSI(*TagContainerName)); + ImGui::TableHeadersRow(); + + TArray Tags; + TagContainer.GetGameplayTagArray(Tags); + + Tags.RemoveAll([&](const FGameplayTag& Tag) + { + return Filter.PassFilter(TCHAR_TO_ANSI(*Tag.GetTagName().ToString())) == false; + }); + + if (Config->SortByName) + { + Tags.Sort([](const FGameplayTag& Tag1, const FGameplayTag& Tag2) + { + return Tag1.GetTagName().Compare(Tag2.GetTagName()) < 0; + }); + } + + static int Selected = -1; + int Index = 0; + + for (const FGameplayTag& Tag : Tags) + { + ImGui::TableNextRow(); + + ImGui::PushID(Index); + + //------------------------ + // Count + //------------------------ + ImGui::TableNextColumn(); + const int32 TagCount = AbilitySystemComponent.GetTagCount(Tag); + ImGui::TextColored(TagCount > 1 ? ImVec4(1.0f, 1.0f, 0.0f, 1.0f) : ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "%d", TagCount); + + //------------------------ + // Name + //------------------------ + ImGui::TableNextColumn(); + if (ImGui::Selectable(TCHAR_TO_ANSI(*Tag.GetTagName().ToString()), Selected == Index, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap | ImGuiSelectableFlags_AllowDoubleClick)) + { + Selected = Index; + } + + //------------------------ + // Tooltip + //------------------------ + if (ImGui::IsItemHovered()) + { + FCogWindowWidgets::BeginTableTooltip(); + RenderTag(AbilitySystemComponent, Tag); + FCogWindowWidgets::EndTableTooltip(); + } + + ImGui::PopID(); + Index++; + } + + ImGui::EndTable(); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogAbilityWindow_Tags::RenderTag(const UAbilitySystemComponent& AbilitySystemComponent, const FGameplayTag& Tag) { if (ImGui::BeginTable("Tag", 2, ImGuiTableFlags_Borders)) { @@ -91,61 +205,6 @@ void FCogAbilityWindow_Tags::DrawTag(const UAbilitySystemComponent& AbilitySyste } } - ImGui::EndTable(); - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogAbilityWindow_Tags::DrawTagContainer(const FString& TagContainerName, const UAbilitySystemComponent& AbilitySystemComponent, FGameplayTagContainer& TagContainer) -{ - if (ImGui::BeginTable(TCHAR_TO_ANSI(*TagContainerName), 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_BordersOuterV)) - { - ImGui::TableSetupColumn("Count"); - ImGui::TableSetupColumn(TCHAR_TO_ANSI(*TagContainerName)); - ImGui::TableHeadersRow(); - - TArray Tags; - TagContainer.GetGameplayTagArray(Tags); - - static int Selected = -1; - int index = 0; - - for (const FGameplayTag& Tag : Tags) - { - ImGui::TableNextRow(); - - ImGui::PushID(index); - - //------------------------ - // Count - //------------------------ - ImGui::TableNextColumn(); - const int32 TagCount = AbilitySystemComponent.GetTagCount(Tag); - ImGui::TextColored(TagCount > 1 ? ImVec4(1.0f, 1.0f, 0.0f, 1.0f) : ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "%d", TagCount); - - //------------------------ - // Name - //------------------------ - ImGui::TableNextColumn(); - if (ImGui::Selectable(TCHAR_TO_ANSI(*Tag.GetTagName().ToString()), Selected == index, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap | ImGuiSelectableFlags_AllowDoubleClick)) - { - Selected = index; - } - - //------------------------ - // Tooltip - //------------------------ - if (ImGui::IsItemHovered()) - { - FCogWindowWidgets::BeginTableTooltip(); - DrawTag(AbilitySystemComponent, Tag); - FCogWindowWidgets::EndTableTooltip(); - } - - ImGui::PopID(); - index++; - } - ImGui::EndTable(); } } \ No newline at end of file diff --git a/Plugins/CogAbility/Source/CogAbility/Public/CogAbilityWindow_Tags.h b/Plugins/CogAbility/Source/CogAbility/Public/CogAbilityWindow_Tags.h index 53af4f7..b42d865 100644 --- a/Plugins/CogAbility/Source/CogAbility/Public/CogAbilityWindow_Tags.h +++ b/Plugins/CogAbility/Source/CogAbility/Public/CogAbilityWindow_Tags.h @@ -2,10 +2,13 @@ #include "CoreMinimal.h" #include "CogWindow.h" +#include "CogWindowConfig.h" +#include "CogAbilityWindow_Tags.generated.h" -class UAbilitySystemComponent; struct FGameplayTagContainer; struct FGameplayTag; +class UCogAbilityConfig_Tags; +class UAbilitySystemComponent; //-------------------------------------------------------------------------------------------------------------------------- class COGABILITY_API FCogAbilityWindow_Tags : public FCogWindow @@ -18,11 +21,38 @@ public: protected: + virtual void ResetConfig(); + virtual void RenderHelp() override; virtual void RenderContent() override; - virtual void DrawTagContainer(const FString& TagContainerName, const UAbilitySystemComponent& AbilitySystemComponent, FGameplayTagContainer& TagContainer); + virtual void RenderTagContainer(const FString& TagContainerName, const UAbilitySystemComponent& AbilitySystemComponent, FGameplayTagContainer& TagContainer); - virtual void DrawTag(const UAbilitySystemComponent& AbilitySystemComponent, const FGameplayTag& Tag); + virtual void RenderTag(const UAbilitySystemComponent& AbilitySystemComponent, const FGameplayTag& Tag); + + virtual void RenderMenu(); + + TObjectPtr Config = nullptr; + + ImGuiTextFilter Filter; }; + +//-------------------------------------------------------------------------------------------------------------------------- +UCLASS(Config = Cog) +class UCogAbilityConfig_Tags : public UCogWindowConfig +{ + GENERATED_BODY() + +public: + + UPROPERTY(Config) + bool SortByName = false; + + virtual void Reset() override + { + Super::Reset(); + + SortByName = false; + } +}; \ No newline at end of file diff --git a/TODO.txt b/TODO.txt index 7c47771..b3dd0aa 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,6 +3,8 @@ - CogWindow: Add reset window position menu item or reset layout (window can get far away) - CogWindow: Try to remove CogWindow dependency to cogimgui. Should only depends on imgui (currently use setdpiscale of cogimgui) +- CogWindow: Overlay window should have achnoring options (top bottom left right center mid) +- CogWindow: Hide menu is not saved anymore - CogEngine: More stats in the stats window - CogEngine: Overlay mode of stats. @@ -22,6 +24,4 @@ - CogSample: Add more debug for area (change color on tick, duration ...) - CogDebug: Check KismetExecutionMessage for warnings. As an exemple it is used by GEngine::GetWorldFromContextObject. -- CogDebug: Rework Tickness and Duration params. - -- CogInput: Add gamepad stick drag to set their values \ No newline at end of file +- CogDebug: Rework Thickness and Duration params.