CogAbility: Add open asset button on effect and abilities context menu

This commit is contained in:
Arnaud Jamin
2025-01-16 07:56:28 -05:00
parent 24cc2971c8
commit d7ab3f18b9
9 changed files with 153 additions and 34 deletions
@@ -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>