// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "EdGraph/EdGraphNode.h" #include "NiagaraObjectSelection.h" #include "EditorUndoClient.h" #include "Styling/SlateColor.h" #include "UICommandList.h" class UNiagaraScript; class UNiagaraGraph; /** A view model for editing a niagara script in a graph editor. */ class FNiagaraScriptGraphViewModel : public TSharedFromThis, public FEditorUndoClient { public: /** A multicast delegate which is called when nodes are pasted in the graph which supplies the pasted nodes. */ DECLARE_MULTICAST_DELEGATE_OneParam(FOnNodesPasted, const TSet&); DECLARE_MULTICAST_DELEGATE(FOnGraphChanged); public: /** Create a new view model with the supplied script. */ FNiagaraScriptGraphViewModel(UNiagaraScript* InScript, FText InDisplayName); ~FNiagaraScriptGraphViewModel(); /** Sets this view model to a new script. */ void SetScript(UNiagaraScript* InScript); /** Gets the display text for this graph. */ FText GetDisplayName() const; /** Gets the script displayed and edited by this view model. */ UNiagaraScript* GetScript(); /** Gets the graph which is used to edit, view, and compile the script. */ UNiagaraGraph* GetGraph() const; /** Gets commands used for editing the graph. */ TSharedRef GetCommands(); /** Gets the currently selected graph nodes. */ TSharedRef GetSelection(); /** Sets the currently selected graph nodes. */ void SetSelectedNodes(const TSet& InSelectedNodes); /** Clears the currently selected graph nodes. */ void ClearSelectedNodes(); /** Gets a multicast delegate which is called any time nodes are pasted in the graph. */ FOnNodesPasted& OnNodesPasted(); /** Gets a multicast delegate which is called whenever the graph object is changed to a different graph. */ FOnGraphChanged& OnGraphChanged(); EVisibility GetGraphErrorTextVisible() const; FText GetGraphErrorText() const; FSlateColor GetGraphErrorColor() const; FText GetGraphErrorMsgToolTip() const; void SetErrorTextToolTip(FString ErrorMsgToolTip); //~ FEditorUndoClient interface. virtual void PostUndo(bool bSuccess) override; virtual void PostRedo(bool bSuccess) override { PostUndo(bSuccess); } private: void SetupCommands(); void SelectAllNodes(); void DeleteSelectedNodes(); bool CanDeleteNodes() const; void CutSelectedNodes(); bool CanCutNodes() const; void CopySelectedNodes(); bool CanCopyNodes() const; void PasteNodes(); bool CanPasteNodes() const; void DuplicateNodes(); bool CanDuplicateNodes() const; private: /** The script being view and edited by this view model. */ TWeakObjectPtr Script; /** The display name for the script graph. */ FText DisplayName; /** Commands for editing the graph. */ TSharedRef Commands; /** The set of objects currently selected in the graph. */ TSharedRef Selection; /** A multicast delegate which is called whenever nodes are pasted into the graph. */ FOnNodesPasted OnNodesPastedDelegate; /** A multicast delegate which is called whenever the graph object is changed to a different graph. */ FOnGraphChanged OnGraphChangedDelegate; /** Used to report errors on the node */ FString ErrorMsg; /** Used to set the error color */ FSlateColor ErrorColor; };