Skip to content

Commit

Permalink
POTENTIALLY BREAKING CHANGE: Added UAssetDefinition_FlowAsset impleme…
Browse files Browse the repository at this point in the history
…nting a new way of defining editor-only asset properties like asset category.

This is a direct replacement for FAssetTypeActions_FlowAsset. If you had any custom asset class extending `UFlowAsset`, you probably need to convert your custom FAssetTypeActions to UAssetDefinition. This is quite a straightforward process.
  • Loading branch information
MothDoctor committed Nov 17, 2024
1 parent ce85ed5 commit 5ef45f3
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 82 deletions.
1 change: 1 addition & 0 deletions Source/FlowEditor/FlowEditor.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public FlowEditor(ReadOnlyTargetRules target) : base(target)
PrivateDependencyModuleNames.AddRange(new[]
{
"ApplicationCore",
"AssetDefinition",
"AssetSearch",
"AssetTools",
"BlueprintGraph",
Expand Down
77 changes: 77 additions & 0 deletions Source/FlowEditor/Private/Asset/AssetDefinition_FlowAsset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright https://github.com/MothCocoon/FlowGraph/graphs/contributors

#include "Asset/AssetDefinition_FlowAsset.h"
#include "Asset/SFlowDiff.h"
#include "FlowEditorModule.h"
#include "Graph/FlowGraphSettings.h"

#include "FlowAsset.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(AssetDefinition_FlowAsset)

#define LOCTEXT_NAMESPACE "AssetDefinition_FlowAsset"

FText UAssetDefinition_FlowAsset::GetAssetDisplayName() const
{
return LOCTEXT("AssetTypeActions_FlowAsset", "Flow Asset");
}

FLinearColor UAssetDefinition_FlowAsset::GetAssetColor() const
{
return FColor(255, 196, 128);
}

TSoftClassPtr<UObject> UAssetDefinition_FlowAsset::GetAssetClass() const
{
return UFlowAsset::StaticClass();
}

TConstArrayView<FAssetCategoryPath> UAssetDefinition_FlowAsset::GetAssetCategories() const
{
if (UFlowGraphSettings::Get()->bExposeFlowAssetCreation)
{
static const auto Categories = {FFLowAssetCategoryPaths::Flow};
return Categories;
}

return {};
}

FAssetSupportResponse UAssetDefinition_FlowAsset::CanLocalize(const FAssetData& InAsset) const
{
return FAssetSupportResponse::Supported();
}

EAssetCommandResult UAssetDefinition_FlowAsset::OpenAssets(const FAssetOpenArgs& OpenArgs) const
{
for (UFlowAsset* FlowAsset : OpenArgs.LoadObjects<UFlowAsset>())
{
const FFlowEditorModule* FlowModule = &FModuleManager::LoadModuleChecked<FFlowEditorModule>("FlowEditor");
FlowModule->CreateFlowAssetEditor(OpenArgs.GetToolkitMode(), OpenArgs.ToolkitHost, FlowAsset);
}

return EAssetCommandResult::Handled;
}

EAssetCommandResult UAssetDefinition_FlowAsset::PerformAssetDiff(const FAssetDiffArgs& DiffArgs) const
{
if (DiffArgs.OldAsset == nullptr && DiffArgs.NewAsset == nullptr)
{
return EAssetCommandResult::Unhandled;
}

const UFlowAsset* OldFlow = CastChecked<UFlowAsset>(DiffArgs.OldAsset);
const UFlowAsset* NewFlow = CastChecked<UFlowAsset>(DiffArgs.NewAsset);

// sometimes we're comparing different revisions of one single asset (other
// times we're comparing two completely separate assets altogether)
const bool bIsSingleAsset = (OldFlow->GetName() == NewFlow->GetName());

static const FText BasicWindowTitle = LOCTEXT("FlowAssetDiff", "FlowAsset Diff");
const FText WindowTitle = !bIsSingleAsset ? BasicWindowTitle : FText::Format(LOCTEXT("FlowAsset Diff", "{0} - FlowAsset Diff"), FText::FromString(NewFlow->GetName()));

SFlowDiff::CreateDiffWindow(WindowTitle, OldFlow, NewFlow, DiffArgs.OldRevision, DiffArgs.NewRevision);
return EAssetCommandResult::Handled;
}

#undef LOCTEXT_NAMESPACE
58 changes: 0 additions & 58 deletions Source/FlowEditor/Private/Asset/AssetTypeActions_FlowAsset.cpp

This file was deleted.

6 changes: 1 addition & 5 deletions Source/FlowEditor/Private/FlowEditorModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "FlowEditorModule.h"
#include "FlowEditorStyle.h"

#include "Asset/AssetTypeActions_FlowAsset.h"
#include "Asset/FlowAssetEditor.h"
#include "Asset/FlowAssetIndexer.h"
#include "Graph/FlowGraphConnectionDrawingPolicy.h"
Expand Down Expand Up @@ -56,6 +55,7 @@ static FName AssetSearchModuleName = TEXT("AssetSearch");
#define LOCTEXT_NAMESPACE "FlowEditorModule"

EAssetTypeCategories::Type FFlowEditorModule::FlowAssetCategory = static_cast<EAssetTypeCategories::Type>(0);
FAssetCategoryPath FFLowAssetCategoryPaths::Flow(LOCTEXT("Flow", "Flow"));

void FFlowEditorModule::StartupModule()
{
Expand Down Expand Up @@ -166,10 +166,6 @@ void FFlowEditorModule::RegisterAssets()
}
}

const TSharedRef<IAssetTypeActions> FlowAssetActions = MakeShareable(new FAssetTypeActions_FlowAsset());
RegisteredAssetActions.Add(FlowAssetActions);
AssetTools.RegisterAssetTypeActions(FlowAssetActions);

const TSharedRef<IAssetTypeActions> FlowNodeActions = MakeShareable(new FAssetTypeActions_FlowNodeBlueprint());
RegisteredAssetActions.Add(FlowNodeActions);
AssetTools.RegisterAssetTypeActions(FlowNodeActions);
Expand Down
25 changes: 25 additions & 0 deletions Source/FlowEditor/Public/Asset/AssetDefinition_FlowAsset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright https://github.com/MothCocoon/FlowGraph/graphs/contributors

#pragma once

#include "AssetDefinition.h"
#include "AssetDefinition_FlowAsset.generated.h"

/**
*
*/
UCLASS()
class FLOWEDITOR_API UAssetDefinition_FlowAsset : public UAssetDefinition
{
GENERATED_BODY()

public:
virtual FText GetAssetDisplayName() const override;
virtual FLinearColor GetAssetColor() const override;
virtual TSoftClassPtr<UObject> GetAssetClass() const override;
virtual TConstArrayView<FAssetCategoryPath> GetAssetCategories() const override;
virtual FAssetSupportResponse CanLocalize(const FAssetData& InAsset) const override;

virtual EAssetCommandResult OpenAssets(const FAssetOpenArgs& OpenArgs) const override;
virtual EAssetCommandResult PerformAssetDiff(const FAssetDiffArgs& DiffArgs) const override;
};
19 changes: 0 additions & 19 deletions Source/FlowEditor/Public/Asset/AssetTypeActions_FlowAsset.h

This file was deleted.

5 changes: 5 additions & 0 deletions Source/FlowEditor/Public/FlowEditorModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ struct FGraphPanelPinConnectionFactory;
class FFlowAssetEditor;
class UFlowAsset;

struct FLOWEDITOR_API FFLowAssetCategoryPaths : EAssetCategoryPaths
{
static FAssetCategoryPath Flow;
};

class FLOWEDITOR_API FFlowEditorModule : public IModuleInterface
{
public:
Expand Down

0 comments on commit 5ef45f3

Please sign in to comment.