Skip to content

Commit

Permalink
toolbar classes merged, a lot of Flow Asset methods made virtual
Browse files Browse the repository at this point in the history
  • Loading branch information
MothDoctor committed Sep 28, 2021
1 parent 24ce1b0 commit a73dfae
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 434 deletions.
153 changes: 52 additions & 101 deletions Source/FlowEditor/Private/Asset/FlowAssetEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

#include "Asset/FlowAssetToolbar.h"
#include "Asset/FlowDebugger.h"
#include "Asset/FlowDebuggerToolbar.h"
#include "FlowEditorCommands.h"
#include "FlowEditorModule.h"
#include "Graph/FlowGraph.h"
#include "Graph/FlowGraphSchema.h"
#include "Graph/FlowGraphSchema_Actions.h"
Expand Down Expand Up @@ -178,13 +176,13 @@ void FFlowAssetEditor::InitFlowAssetEditor(const EToolkitMode::Type Mode, const
GEditor->RegisterForUndo(this);

UFlowGraphSchema::SubscribeToAssetChanges();
FlowDebugger = MakeShareable(new FFlowDebugger);

FGraphEditorCommands::Register();
FFlowGraphCommands::Register();
FFlowSpawnNodeCommands::Register();
BindToolbarCommands();
CreateToolbar();

CreateWidgets();
BindGraphCommands();
CreateWidgets();

const TSharedRef<FTabManager::FLayout> StandaloneDefaultLayout = FTabManager::NewLayout("FlowAssetEditor_Layout_v3")
->AddArea
Expand All @@ -210,52 +208,16 @@ void FFlowAssetEditor::InitFlowAssetEditor(const EToolkitMode::Type Mode, const
)
);

const bool bCreateDefaultStandaloneMenu = true;
const bool bCreateDefaultToolbar = true;
constexpr bool bCreateDefaultStandaloneMenu = true;
constexpr bool bCreateDefaultToolbar = true;
InitAssetEditor(Mode, InitToolkitHost, TEXT("FlowEditorApp"), StandaloneDefaultLayout, bCreateDefaultStandaloneMenu, bCreateDefaultToolbar, ObjectToEdit, false);

FFlowToolbarCommands::Register();

AddFlowAssetToolbar();
AddPlayWorldToolbar();
CreateFlowDebugger();

FFlowEditorModule* FlowEditorModule = &FModuleManager::LoadModuleChecked<FFlowEditorModule>("FlowEditor");
AddMenuExtender(FlowEditorModule->GetFlowAssetMenuExtensibilityManager()->GetAllExtenders(GetToolkitCommands(), GetEditingObjects()));

RegenerateMenusAndToolbars();
FlowAsset->OnRegenerateToolbars().AddSP(this, &FFlowAssetEditor::RegenerateMenusAndToolbars);
}

void FFlowAssetEditor::AddFlowAssetToolbar()
{
AssetToolbar = MakeShareable(new FFlowAssetToolbar(SharedThis(this)));

BindAssetCommands();

TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);
ToolbarExtender->AddToolBarExtension(
"Asset",
EExtensionHook::After,
GetToolkitCommands(),
FToolBarExtensionDelegate::CreateSP(AssetToolbar.Get(), &FFlowAssetToolbar::AddToolbar)
);
AddToolbarExtender(ToolbarExtender);
}

void FFlowAssetEditor::BindAssetCommands()
{
const FFlowToolbarCommands& NodeCommands = FFlowToolbarCommands::Get();

ToolkitCommands->MapAction(NodeCommands.RefreshAsset,
FExecuteAction::CreateSP(this, &FFlowAssetEditor::RefreshAsset),
FCanExecuteAction::CreateStatic(&FFlowAssetEditor::CanEdit));
}

void FFlowAssetEditor::AddPlayWorldToolbar() const
void FFlowAssetEditor::CreateToolbar()
{
// Append play world commands
ToolkitCommands->Append(FPlayWorldCommands::GlobalPlayWorldActions.ToSharedRef());

FName ParentToolbarName;
const FName ToolBarName = GetToolMenuToolbarName(ParentToolbarName);

Expand All @@ -268,40 +230,25 @@ void FFlowAssetEditor::AddPlayWorldToolbar() const

if (FoundMenu)
{
FToolMenuSection& Section = FoundMenu->AddSection("Debugging");
Section.InsertPosition = FToolMenuInsert("Asset", EToolMenuInsertType::After);

Section.AddDynamicEntry("DebuggingCommands", FNewToolMenuSectionDelegate::CreateLambda([](FToolMenuSection& InSection)
{
FPlayWorldCommands::BuildToolbar(InSection);
}));
AssetToolbar = MakeShareable(new FFlowAssetToolbar(SharedThis(this), FoundMenu));
}
}

void FFlowAssetEditor::CreateFlowDebugger()
void FFlowAssetEditor::BindToolbarCommands()
{
Debugger = MakeShareable(new FFlowDebugger);
DebuggerToolbar = MakeShareable(new FFlowDebuggerToolbar(SharedThis(this)));

BindDebuggerCommands();

TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);
ToolbarExtender->AddToolBarExtension(
"Debugging",
EExtensionHook::After,
GetToolkitCommands(),
FToolBarExtensionDelegate::CreateSP(DebuggerToolbar.Get(), &FFlowDebuggerToolbar::AddToolbar)
);
AddToolbarExtender(ToolbarExtender);
FFlowToolbarCommands::Register();
const FFlowToolbarCommands& ToolbarCommands = FFlowToolbarCommands::Get();

RegenerateMenusAndToolbars();
}
// Editing
ToolkitCommands->MapAction(ToolbarCommands.RefreshAsset,
FExecuteAction::CreateSP(this, &FFlowAssetEditor::RefreshAsset),
FCanExecuteAction::CreateStatic(&FFlowAssetEditor::CanEdit));

void FFlowAssetEditor::BindDebuggerCommands()
{
const FFlowToolbarCommands& NodeCommands = FFlowToolbarCommands::Get();
// Engine's Play commands
ToolkitCommands->Append(FPlayWorldCommands::GlobalPlayWorldActions.ToSharedRef());

ToolkitCommands->MapAction(NodeCommands.GoToMasterInstance,
// Debugging
ToolkitCommands->MapAction(ToolbarCommands.GoToMasterInstance,
FExecuteAction::CreateSP(this, &FFlowAssetEditor::GoToMasterInstance),
FCanExecuteAction::CreateSP(this, &FFlowAssetEditor::CanGoToMasterInstance),
FIsActionChecked(),
Expand All @@ -321,7 +268,7 @@ void FFlowAssetEditor::RefreshAsset()

void FFlowAssetEditor::GoToMasterInstance()
{
UFlowAsset* AssetThatInstancedThisAsset = FlowAsset->GetInspectedInstance()->GetMasterInstance();
const UFlowAsset* AssetThatInstancedThisAsset = FlowAsset->GetInspectedInstance()->GetMasterInstance();

GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAsset(AssetThatInstancedThisAsset->GetTemplateAsset());
AssetThatInstancedThisAsset->GetTemplateAsset()->SetInspectedInstance(AssetThatInstancedThisAsset->GetDisplayName());
Expand Down Expand Up @@ -356,7 +303,7 @@ TSharedRef<SGraphEditor> FFlowAssetEditor::CreateGraphWidget()
InEvents.OnSelectionChanged = SGraphEditor::FOnSelectionChanged::CreateSP(this, &FFlowAssetEditor::OnSelectedNodesChanged);
InEvents.OnNodeDoubleClicked = FSingleNodeEvent::CreateSP(this, &FFlowAssetEditor::OnNodeDoubleClicked);
InEvents.OnTextCommitted = FOnNodeTextCommitted::CreateSP(this, &FFlowAssetEditor::OnNodeTitleCommitted);
InEvents.OnSpawnNodeByShortcut = SGraphEditor::FOnSpawnNodeByShortcut::CreateSP(this, &FFlowAssetEditor::OnSpawnGraphNodeByShortcut, static_cast<UEdGraph*>(FlowAsset->GetGraph()));
InEvents.OnSpawnNodeByShortcut = SGraphEditor::FOnSpawnNodeByShortcut::CreateStatic(&FFlowAssetEditor::OnSpawnGraphNodeByShortcut, static_cast<UEdGraph*>(FlowAsset->GetGraph()));

return SNew(SGraphEditor)
.AdditionalCommands(ToolkitCommands)
Expand All @@ -373,7 +320,7 @@ FGraphAppearanceInfo FFlowAssetEditor::GetGraphAppearanceInfo() const
FGraphAppearanceInfo AppearanceInfo;
AppearanceInfo.CornerText = GetCornerText();

if (Debugger.IsValid() && FFlowDebugger::IsPlaySessionPaused())
if (FlowDebugger.IsValid() && FFlowDebugger::IsPlaySessionPaused())
{
AppearanceInfo.PIENotifyText = LOCTEXT("PausedLabel", "PAUSED");
}
Expand All @@ -388,6 +335,10 @@ FText FFlowAssetEditor::GetCornerText() const

void FFlowAssetEditor::BindGraphCommands()
{
FGraphEditorCommands::Register();
FFlowGraphCommands::Register();
FFlowSpawnNodeCommands::Register();

const FGenericCommands& GenericCommands = FGenericCommands::Get();
const FGraphEditorCommandsImpl& GraphCommands = FGraphEditorCommands::Get();
const FFlowGraphCommands& FlowGraphCommands = FFlowGraphCommands::Get();
Expand All @@ -402,11 +353,11 @@ void FFlowAssetEditor::BindGraphCommands()

// Generic Node commands
ToolkitCommands->MapAction(GenericCommands.Undo,
FExecuteAction::CreateSP(this, &FFlowAssetEditor::UndoGraphAction),
FExecuteAction::CreateStatic(&FFlowAssetEditor::UndoGraphAction),
FCanExecuteAction::CreateStatic(&FFlowAssetEditor::CanEdit));

ToolkitCommands->MapAction(GenericCommands.Redo,
FExecuteAction::CreateSP(this, &FFlowAssetEditor::RedoGraphAction),
FExecuteAction::CreateStatic(&FFlowAssetEditor::RedoGraphAction),
FCanExecuteAction::CreateStatic(&FFlowAssetEditor::CanEdit));

ToolkitCommands->MapAction(GenericCommands.SelectAll,
Expand Down Expand Up @@ -548,7 +499,7 @@ FReply FFlowAssetEditor::OnSpawnGraphNodeByShortcut(FInputChord InChord, const F

if (FFlowSpawnNodeCommands::IsRegistered())
{
TSharedPtr<FEdGraphSchemaAction> Action = FFlowSpawnNodeCommands::Get().GetActionByChord(InChord);
const TSharedPtr<FEdGraphSchemaAction> Action = FFlowSpawnNodeCommands::Get().GetActionByChord(InChord);
if (Action.IsValid())
{
TArray<UEdGraphPin*> DummyPins;
Expand Down Expand Up @@ -646,7 +597,7 @@ void FFlowAssetEditor::OnSelectedNodesChanged(const TSet<UObject*>& Nodes)

for (TSet<UObject*>::TConstIterator SetIt(Nodes); SetIt; ++SetIt)
{
if (UFlowGraphNode* GraphNode = Cast<UFlowGraphNode>(*SetIt))
if (const UFlowGraphNode* GraphNode = Cast<UFlowGraphNode>(*SetIt))
{
SelectedObjects.Add(Cast<UObject>(GraphNode->GetFlowNode()));
}
Expand Down Expand Up @@ -697,7 +648,7 @@ void FFlowAssetEditor::DeleteSelectedNodes()

if (Node->CanUserDeleteNode())
{
if (UFlowGraphNode* FlowGraphNode = Cast<UFlowGraphNode>(Node))
if (const UFlowGraphNode* FlowGraphNode = Cast<UFlowGraphNode>(Node))
{
if (FlowGraphNode->GetFlowNode())
{
Expand All @@ -713,7 +664,7 @@ void FFlowAssetEditor::DeleteSelectedNodes()
}
}

void FFlowAssetEditor::DeleteSelectedDuplicatableNodes()
void FFlowAssetEditor::DeleteSelectedDuplicableNodes()
{
// Cache off the old selection
const FGraphPanelSelectionSet OldSelectedNodes = FocusedGraphEditor->GetSelectedNodes();
Expand All @@ -737,7 +688,7 @@ void FFlowAssetEditor::DeleteSelectedDuplicatableNodes()
}
}

// Delete the duplicatable nodes
// Delete the duplicable nodes
DeleteSelectedNodes();

for (FGraphPanelSelectionSet::TConstIterator SelectedIt(RemainingNodes); SelectedIt; ++SelectedIt)
Expand Down Expand Up @@ -776,7 +727,7 @@ void FFlowAssetEditor::CutSelectedNodes()
CopySelectedNodes();

// Cut should only delete nodes that can be duplicated
DeleteSelectedDuplicatableNodes();
DeleteSelectedDuplicableNodes();
}

bool FFlowAssetEditor::CanCutNodes() const
Expand Down Expand Up @@ -857,7 +808,7 @@ void FFlowAssetEditor::PasteNodesHere(const FVector2D& Location)

for (TSet<UEdGraphNode*>::TIterator It(PastedNodes); It; ++It)
{
UEdGraphNode* Node = *It;
const UEdGraphNode* Node = *It;
AvgNodePosition.X += Node->NodePosX;
AvgNodePosition.Y += Node->NodePosY;
}
Expand All @@ -876,7 +827,7 @@ void FFlowAssetEditor::PasteNodesHere(const FVector2D& Location)
// Give new node a different Guid from the old one
Node->CreateNewGuid();

if (UFlowGraphNode* FlowGraphNode = Cast<UFlowGraphNode>(Node))
if (const UFlowGraphNode* FlowGraphNode = Cast<UFlowGraphNode>(Node))
{
FlowAsset->RegisterNode(Node->NodeGuid, FlowGraphNode->GetFlowNode());
}
Expand Down Expand Up @@ -976,7 +927,7 @@ bool FFlowAssetEditor::CanRefreshContextPins() const
{
if (CanEdit() && GetSelectedFlowNodes().Num() == 1)
{
for (UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
for (const UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
{
return SelectedNode->SupportsContextPins();
}
Expand All @@ -997,7 +948,7 @@ bool FFlowAssetEditor::CanAddInput() const
{
if (CanEdit() && GetSelectedFlowNodes().Num() == 1)
{
for (UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
for (const UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
{
return SelectedNode->CanUserAddInput();
}
Expand All @@ -1018,7 +969,7 @@ bool FFlowAssetEditor::CanAddOutput() const
{
if (CanEdit() && GetSelectedFlowNodes().Num() == 1)
{
for (UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
for (const UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
{
return SelectedNode->CanUserAddOutput();
}
Expand All @@ -1042,9 +993,9 @@ bool FFlowAssetEditor::CanRemovePin() const
{
if (CanEdit() && GetSelectedFlowNodes().Num() == 1)
{
if (UEdGraphPin* Pin = FocusedGraphEditor->GetGraphPinForMenu())
if (const UEdGraphPin* Pin = FocusedGraphEditor->GetGraphPinForMenu())
{
if (UFlowGraphNode* GraphNode = Cast<UFlowGraphNode>(Pin->GetOwningNode()))
if (const UFlowGraphNode* GraphNode = Cast<UFlowGraphNode>(Pin->GetOwningNode()))
{
if (Pin->Direction == EGPD_Input)
{
Expand Down Expand Up @@ -1083,7 +1034,7 @@ void FFlowAssetEditor::OnAddPinBreakpoint() const

bool FFlowAssetEditor::CanAddBreakpoint() const
{
for (UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
for (const UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
{
return !SelectedNode->NodeBreakpoint.HasBreakpoint();
}
Expand Down Expand Up @@ -1125,7 +1076,7 @@ void FFlowAssetEditor::OnRemovePinBreakpoint() const

bool FFlowAssetEditor::CanRemoveBreakpoint() const
{
for (UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
for (const UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
{
return SelectedNode->NodeBreakpoint.HasBreakpoint();
}
Expand All @@ -1137,7 +1088,7 @@ bool FFlowAssetEditor::CanRemovePinBreakpoint() const
{
if (UEdGraphPin* Pin = FocusedGraphEditor->GetGraphPinForMenu())
{
if (UFlowGraphNode* GraphNode = Cast<UFlowGraphNode>(Pin->GetOwningNode()))
if (const UFlowGraphNode* GraphNode = Cast<UFlowGraphNode>(Pin->GetOwningNode()))
{
return GraphNode->PinBreakpoints.Contains(Pin);
}
Expand Down Expand Up @@ -1169,13 +1120,13 @@ bool FFlowAssetEditor::CanEnableBreakpoint() const
{
if (UEdGraphPin* Pin = FocusedGraphEditor->GetGraphPinForMenu())
{
if (UFlowGraphNode* GraphNode = Cast<UFlowGraphNode>(Pin->GetOwningNode()))
if (const UFlowGraphNode* GraphNode = Cast<UFlowGraphNode>(Pin->GetOwningNode()))
{
return GraphNode->PinBreakpoints.Contains(Pin);
}
}

for (UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
for (const UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
{
return SelectedNode->NodeBreakpoint.CanEnableBreakpoint();
}
Expand Down Expand Up @@ -1217,7 +1168,7 @@ void FFlowAssetEditor::OnDisablePinBreakpoint() const

bool FFlowAssetEditor::CanDisableBreakpoint() const
{
for (UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
for (const UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
{
return SelectedNode->NodeBreakpoint.IsBreakpointEnabled();
}
Expand Down Expand Up @@ -1273,7 +1224,7 @@ void FFlowAssetEditor::FocusViewport() const
// Iterator used but should only contain one node
for (UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
{
UFlowNode* FlowNode = Cast<UFlowGraphNode>(SelectedNode)->GetFlowNode();
const UFlowNode* FlowNode = Cast<UFlowGraphNode>(SelectedNode)->GetFlowNode();
if (UFlowNode* NodeInstance = FlowNode->GetInspectedInstance())
{
if (AActor* ActorToFocus = NodeInstance->GetActorToFocus())
Expand All @@ -1284,8 +1235,8 @@ void FFlowAssetEditor::FocusViewport() const

GEditor->MoveViewportCamerasToActor(*ActorToFocus, false);

FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
TSharedPtr<SDockTab> LevelEditorTab = LevelEditorModule.GetLevelEditorInstanceTab().Pin();
const FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
const TSharedPtr<SDockTab> LevelEditorTab = LevelEditorModule.GetLevelEditorInstanceTab().Pin();
if (LevelEditorTab.IsValid())
{
LevelEditorTab->DrawAttention();
Expand All @@ -1305,7 +1256,7 @@ bool FFlowAssetEditor::CanFocusViewport() const
void FFlowAssetEditor::JumpToNodeDefinition() const
{
// Iterator used but should only contain one node
for (UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
for (const UFlowGraphNode* SelectedNode : GetSelectedFlowNodes())
{
SelectedNode->JumpToDefinition();
return;
Expand Down
Loading

0 comments on commit a73dfae

Please sign in to comment.