mirror of
https://github.com/Ed94/Cog.git
synced 2026-06-13 00:01:37 -07:00
CogAbility: Add open asset button on effect and abilities context menu
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -18,19 +18,7 @@ void FCogEngineHelper::ActorContextMenu(AActor& Actor)
|
||||
FCogWindowWidgets::ThinSeparatorText("Object");
|
||||
|
||||
#if WITH_EDITOR
|
||||
const UObject* DefaultObject = Actor.GetClass()->GetDefaultObject();
|
||||
if (DefaultObject == nullptr)
|
||||
{
|
||||
ImGui::BeginDisabled();
|
||||
}
|
||||
if (ImGui::Button("Browse To Asset", ImVec2(-1, 0)))
|
||||
{
|
||||
IAssetTools::Get().SyncBrowserToAssets({ DefaultObject });
|
||||
}
|
||||
if (DefaultObject == nullptr)
|
||||
{
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
FCogWindowWidgets::OpenObjectAssetButton(&Actor, ImVec2(-1, 0));
|
||||
#endif
|
||||
|
||||
if (ImGui::Button("Delete", ImVec2(-1, 0)))
|
||||
|
||||
@@ -40,9 +40,18 @@ public class CogWindow : ModuleRules
|
||||
"NetCore",
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
DynamicallyLoadedModuleNames.AddRange(
|
||||
|
||||
if (Target.bBuildEditor)
|
||||
{
|
||||
PrivateDependencyModuleNames.AddRange(new string[]
|
||||
{
|
||||
"UnrealEd",
|
||||
"AssetTools"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
DynamicallyLoadedModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
}
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
#include "CogWindowHelper.h"
|
||||
#include "Components/PrimitiveComponent.h"
|
||||
#include "EngineUtils.h"
|
||||
#include "IAssetTools.h"
|
||||
#include "GameFramework/Pawn.h"
|
||||
#include "GameFramework/PlayerInput.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "InputCoreTypes.h"
|
||||
#include "Subsystems/AssetEditorSubsystem.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogWindowWidgets::BeginTableTooltip()
|
||||
@@ -1100,3 +1102,99 @@ void FCogWindowWidgets::MenuItemShortcut(const char* Id, const FString& Text)
|
||||
EndRightAlign();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogWindowWidgets::BrowseToAssetButton(const UObject* InAsset, const ImVec2& InSize)
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
|
||||
if (InAsset == nullptr)
|
||||
{
|
||||
ImGui::BeginDisabled();
|
||||
}
|
||||
|
||||
const bool result = ImGui::Button("Browse To Asset", InSize);
|
||||
if (result)
|
||||
{
|
||||
IAssetTools::Get().SyncBrowserToAssets({ InAsset });
|
||||
}
|
||||
|
||||
if (InAsset == nullptr)
|
||||
{
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
return result;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogWindowWidgets::BrowseToObjectAssetButton(const UObject* InObject, const ImVec2& InSize)
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
|
||||
const UObject* ObjectAsset = nullptr;
|
||||
if (InObject != nullptr && InObject->GetClass() != nullptr)
|
||||
{
|
||||
ObjectAsset = InObject->GetClass()->ClassGeneratedBy;
|
||||
}
|
||||
|
||||
return BrowseToAssetButton(ObjectAsset, InSize);
|
||||
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogWindowWidgets::OpenAssetButton(const UObject* InAsset, const ImVec2& InSize)
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
|
||||
UAssetEditorSubsystem* editorSubsystem = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
|
||||
if (InAsset == nullptr || editorSubsystem == nullptr)
|
||||
{
|
||||
ImGui::BeginDisabled();
|
||||
}
|
||||
|
||||
const bool result = ImGui::Button("Open Asset", InSize);
|
||||
if (result)
|
||||
{
|
||||
if (editorSubsystem != nullptr)
|
||||
{
|
||||
editorSubsystem->OpenEditorForAsset(InAsset);
|
||||
}
|
||||
}
|
||||
|
||||
if (InAsset == nullptr)
|
||||
{
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
return result;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogWindowWidgets::OpenObjectAssetButton(const UObject* InObject, const ImVec2& InSize)
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
|
||||
const UObject* ObjectAsset = nullptr;
|
||||
if (InObject != nullptr && InObject->GetClass() != nullptr)
|
||||
{
|
||||
ObjectAsset = InObject->GetClass()->ClassGeneratedBy;
|
||||
}
|
||||
|
||||
return OpenAssetButton(ObjectAsset, InSize);
|
||||
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -120,6 +120,15 @@ public:
|
||||
static void EndRightAlign();
|
||||
|
||||
static void MenuItemShortcut(const char* Id, const FString& Text);
|
||||
|
||||
static bool BrowseToAssetButton(const UObject* InAsset, const ImVec2& InSize = ImVec2(0, 0));
|
||||
|
||||
static bool BrowseToObjectAssetButton(const UObject* InObject, const ImVec2& InSize = ImVec2(0, 0));
|
||||
|
||||
static bool OpenAssetButton(const UObject* InAsset, const ImVec2& InSize = ImVec2(0, 0));
|
||||
|
||||
static bool OpenObjectAssetButton(const UObject* InObject, const ImVec2& InSize = ImVec2(0, 0));
|
||||
|
||||
};
|
||||
|
||||
template<typename EnumType>
|
||||
|
||||
@@ -222,7 +222,7 @@ void FCogAbilityWindow_Abilities::RenderAbilitiesTableAbilityName(UAbilitySystem
|
||||
|
||||
if (ImGui::IsMouseDoubleClicked(0))
|
||||
{
|
||||
OpenAbility(Spec.Handle);
|
||||
OpenAbilityDetails(Spec.Handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ void FCogAbilityWindow_Abilities::RenderAbilitiesTable(UAbilitySystemComponent&
|
||||
{
|
||||
TArray<FGameplayAbilitySpec>& Abilities = AbilitySystemComponent.GetActivatableAbilities();
|
||||
|
||||
TArray<FGameplayAbilitySpec> FitleredAbilities;
|
||||
TArray<FGameplayAbilitySpec> FilteredAbilities;
|
||||
|
||||
for (FGameplayAbilitySpec& Spec : Abilities)
|
||||
{
|
||||
@@ -280,12 +280,12 @@ void FCogAbilityWindow_Abilities::RenderAbilitiesTable(UAbilitySystemComponent&
|
||||
continue;
|
||||
}
|
||||
|
||||
FitleredAbilities.Add(Spec);
|
||||
FilteredAbilities.Add(Spec);
|
||||
}
|
||||
|
||||
if (Config->SortByName)
|
||||
{
|
||||
FitleredAbilities.Sort([](const FGameplayAbilitySpec& Lhs, const FGameplayAbilitySpec& Rhs)
|
||||
FilteredAbilities.Sort([](const FGameplayAbilitySpec& Lhs, const FGameplayAbilitySpec& Rhs)
|
||||
{
|
||||
return Lhs.Ability.GetName().Compare(Rhs.Ability.GetName()) < 0;
|
||||
});
|
||||
@@ -296,7 +296,7 @@ void FCogAbilityWindow_Abilities::RenderAbilitiesTable(UAbilitySystemComponent&
|
||||
static int SelectedIndex = -1;
|
||||
int Index = 0;
|
||||
|
||||
for (FGameplayAbilitySpec& Spec : FitleredAbilities)
|
||||
for (FGameplayAbilitySpec& Spec : FilteredAbilities)
|
||||
{
|
||||
UGameplayAbility* Ability = Spec.GetPrimaryInstance();
|
||||
if (Ability == nullptr)
|
||||
@@ -474,36 +474,45 @@ void FCogAbilityWindow_Abilities::RenderAbilityContextMenu(UAbilitySystemCompone
|
||||
if (ImGui::BeginPopupContextItem())
|
||||
{
|
||||
bool bOpen = OpenedAbilities.Contains(Spec.Handle);
|
||||
if (ImGui::Checkbox("Open", &bOpen))
|
||||
if (ImGui::Checkbox("Open Details", &bOpen))
|
||||
{
|
||||
if (bOpen)
|
||||
{
|
||||
OpenAbility(Spec.Handle);
|
||||
OpenAbilityDetails(Spec.Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
CloseAbility(Spec.Handle);
|
||||
CloseAbilityDetails(Spec.Handle);
|
||||
}
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
if (ImGui::Button("Remove"))
|
||||
const ImVec2 ButtonsSize= ImVec2(ImGui::GetFontSize() * 10, 0);
|
||||
|
||||
if (ImGui::Button("Cancel", ButtonsSize))
|
||||
{
|
||||
AbilitySystemComponent.CancelAbilityHandle(Spec.Handle);
|
||||
}
|
||||
|
||||
if (ImGui::Button("Remove", ButtonsSize))
|
||||
{
|
||||
AbilityHandleToRemove = Spec.Handle;
|
||||
}
|
||||
|
||||
FCogWindowWidgets::OpenObjectAssetButton(Spec.Ability, ButtonsSize);
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogAbilityWindow_Abilities::OpenAbility(const FGameplayAbilitySpecHandle& Handle)
|
||||
void FCogAbilityWindow_Abilities::OpenAbilityDetails(const FGameplayAbilitySpecHandle& Handle)
|
||||
{
|
||||
OpenedAbilities.AddUnique(Handle);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogAbilityWindow_Abilities::CloseAbility(const FGameplayAbilitySpecHandle& Handle)
|
||||
void FCogAbilityWindow_Abilities::CloseAbilityDetails(const FGameplayAbilitySpecHandle& Handle)
|
||||
{
|
||||
OpenedAbilities.Remove(Handle);
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ void FCogAbilityWindow_Effects::ResetConfig()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogAbilityWindow_Effects::RenderTick(float DetlaTime)
|
||||
void FCogAbilityWindow_Effects::RenderTick(float DeltaTime)
|
||||
{
|
||||
Super::RenderTick(DetlaTime);
|
||||
Super::RenderTick(DeltaTime);
|
||||
|
||||
RenderOpenEffects();
|
||||
}
|
||||
@@ -224,8 +224,10 @@ void FCogAbilityWindow_Effects::RenderEffectRow(UAbilitySystemComponent& Ability
|
||||
//------------------------
|
||||
if (ImGui::BeginPopupContextItem())
|
||||
{
|
||||
const ImVec2 ButtonsSize = ImVec2(ImGui::GetFontSize() * 10, 0);
|
||||
|
||||
bool bOpen = OpenedEffects.Contains(ActiveHandle);
|
||||
if (ImGui::Checkbox("Open", &bOpen))
|
||||
if (ImGui::Checkbox("Open Details", &bOpen))
|
||||
{
|
||||
if (bOpen)
|
||||
{
|
||||
@@ -238,12 +240,14 @@ void FCogAbilityWindow_Effects::RenderEffectRow(UAbilitySystemComponent& Ability
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
if (ImGui::Button("Remove"))
|
||||
if (ImGui::Button("Remove", ButtonsSize))
|
||||
{
|
||||
AbilitySystemComponent.RemoveActiveGameplayEffect(ActiveHandle);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
FCogWindowWidgets::OpenObjectAssetButton(EffectPtr, ButtonsSize);
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
|
||||
@@ -73,9 +73,9 @@ protected:
|
||||
|
||||
virtual void DeactivateAbility(UAbilitySystemComponent& AbilitySystemComponent, FGameplayAbilitySpec& Spec);
|
||||
|
||||
virtual void OpenAbility(const FGameplayAbilitySpecHandle& Handle);
|
||||
virtual void OpenAbilityDetails(const FGameplayAbilitySpecHandle& Handle);
|
||||
|
||||
virtual void CloseAbility(const FGameplayAbilitySpecHandle& Handle);
|
||||
virtual void CloseAbilityDetails(const FGameplayAbilitySpecHandle& Handle);
|
||||
|
||||
virtual ImVec4 GetAbilityColor(const UAbilitySystemComponent& AbilitySystemComponent, FGameplayAbilitySpec& Spec);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ protected:
|
||||
|
||||
virtual void RenderContent() override;
|
||||
|
||||
virtual void RenderTick(float DetlaTime) override;
|
||||
virtual void RenderTick(float DeltaTime) override;
|
||||
|
||||
virtual void ResetConfig() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user