Эх сурвалжийг харах

增加AddState节点功能

maboren 2 сар өмнө
parent
commit
6d89adba81

+ 27 - 37
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Private/AbleTreeEditorStyle.cpp

@@ -10,6 +10,7 @@
 #include "Misc/Paths.h"
 #include "Styling/StyleColors.h"
 //#include "StateTreeTypes.h"
+#include "EzAbilityTypes.h"
 #include "Styling/SlateStyleMacros.h"
 
 
@@ -432,41 +433,30 @@ FAbleTreeEditorStyle& FAbleTreeEditorStyle::Get()
 	return Instance;
 }
 
-const FSlateBrush* FAbleTreeEditorStyle::GetBrushForSelectionBehaviorType()
-{	
-
-	return  Get().GetBrush("StateTreeEditor.SelectNone");
-// 	if (InBehaviour == EStateTreeStateSelectionBehavior::None)
-// 	{
-// 		return Get().GetBrush("StateTreeEditor.SelectNone");
-// 	}
-// 	else if (InBehaviour == EStateTreeStateSelectionBehavior::TryEnterState)
-// 	{
-// 		return Get().GetBrush("StateTreeEditor.TryEnterState");			
-// 	}
-// 	else if (InBehaviour == EStateTreeStateSelectionBehavior::TrySelectChildrenInOrder
-// 		|| InBehaviour == EStateTreeStateSelectionBehavior::TrySelectChildrenWithHighestUtility
-// 		|| InBehaviour == EStateTreeStateSelectionBehavior::TrySelectChildrenAtRandomWeightedByUtility)
-// 	{
-// 		if (!bHasChildren
-// 			|| StateType == EStateTreeStateType::Linked
-// 			|| StateType == EStateTreeStateType::LinkedAsset)
-// 		{
-// 			return Get().GetBrush("StateTreeEditor.TryEnterState");			
-// 		}
-// 		else
-// 		{
-// 			return Get().GetBrush("StateTreeEditor.TrySelectChildrenInOrder");
-// 		}
-// 	}
-// 	else if (InBehaviour == EStateTreeStateSelectionBehavior::TrySelectChildrenAtRandom)
-// 	{
-// 		return Get().GetBrush("StateTreeEditor.TrySelectChildrenAtRandom");
-// 	}
-// 	else if (InBehaviour == EStateTreeStateSelectionBehavior::TryFollowTransitions)
-// 	{
-// 		return Get().GetBrush("StateTreeEditor.TryFollowTransitions");
-// 	}
-
-	//return nullptr;
+
+const FSlateBrush* FAbleTreeEditorStyle::GetBrushForSelectionBehaviorType(EEzAbilityStateSelectionBehavior InBehaviour, bool bHasChildren, EEzAbilityStateType StateType)
+{
+	if (InBehaviour == EEzAbilityStateSelectionBehavior::None)
+	{
+		return Get().GetBrush("StateTreeEditor.SelectNone");
+	}
+	else if (InBehaviour == EEzAbilityStateSelectionBehavior::TryEnterState)
+	{
+		return Get().GetBrush("StateTreeEditor.TryEnterState");
+	}
+	else if (InBehaviour == EEzAbilityStateSelectionBehavior::TrySelectChildrenInOrder)
+	{
+		if (!bHasChildren
+			|| StateType == EEzAbilityStateType::Linked
+			|| StateType == EEzAbilityStateType::LinkedAsset)
+		{
+			return Get().GetBrush("StateTreeEditor.TryEnterState");
+		}
+		else
+		{
+			return Get().GetBrush("StateTreeEditor.TrySelectChildrenInOrder");
+		}
+	}
+
+	return nullptr;
 }

+ 3 - 2
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Private/EzAbilityAbleTreeSummoner.cpp

@@ -16,9 +16,10 @@
 
 const FName FEzAbilityAbleTreeSummoner::EzAbilityAbleTreeSummonerID("EzAbilityAbleTree");
 
-FEzAbilityAbleTreeSummoner::FEzAbilityAbleTreeSummoner(TSharedPtr<class FAssetEditorToolkit> InHostingApp, const TSharedRef<FAdvancedPreviewScene>& InPreviewScene)
+FEzAbilityAbleTreeSummoner::FEzAbilityAbleTreeSummoner(TSharedPtr<class FAssetEditorToolkit> InHostingApp, const TSharedRef<FAdvancedPreviewScene>& InPreviewScene, TSharedPtr<FEzAbleTreeViewOperationMode> InAbleTreeViewOperationMode)
 	: FWorkflowTabFactory(EzAbilityAbleTreeSummonerID, InHostingApp)
 	, PreviewScene(InPreviewScene)
+	, AbleTreeViewOperationMode(InAbleTreeViewOperationMode)
 {
 	TabLabel = LOCTEXT("AbilityTab", "AbilityAbleTree");
 	TabIcon = FSlateIcon(FAppStyle::GetAppStyleSetName(), "LevelEditor.Tabs.Details");
@@ -48,7 +49,7 @@ FEzAbilityAbleTreeSummoner::FEzAbilityAbleTreeSummoner(TSharedPtr<class FAssetEd
 
 TSharedRef<SWidget> FEzAbilityAbleTreeSummoner::CreateTabBody(const FWorkflowTabSpawnInfo& Info) const
 {
-		return SNew(SEzAbleTreeViewWidget);
+		return SNew(SEzAbleTreeViewWidget, AbleTreeViewOperationMode);
 
 // 	 	return SNew(SButton)
 // 	 		.VAlign(VAlign_Center)

+ 13 - 0
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Private/EzAbilityEditor.cpp

@@ -41,6 +41,19 @@ void FEzAbilityEditor::InitEzAbilityEditor(const EToolkitMode::Type Mode, const
 {
 	EzAbilityDataAsset = InEzAbilityAsset;
 
+	// TODO::因为最初使用了Blueprint,此处临时做了处理
+	if (EzAbilityAsset =  NewObject<UEzAbility>(InEzAbilityAsset->ParentClass))
+	{
+		EzAbilityAsset->EditorData = NewObject<UEzAbilityEditorData>();
+		AbleTreeViewOperationMode = MakeShared<FEzAbleTreeViewOperationMode>();
+
+		if (EzAbilityAsset->EditorData != nullptr)
+		{
+			UEzAbilityEditorData* InTreeData = Cast<UEzAbilityEditorData>(EzAbilityAsset->EditorData);
+			AbleTreeViewOperationMode->Init(InTreeData);
+		}
+	}
+
 	/* 这里面需要注册FPersonaModule 之类的东西 */
 	/*if (!Toolbar.IsValid())
 	{

+ 1 - 1
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Private/EzAbilityEditorApplicationMode.cpp

@@ -28,7 +28,7 @@ FEzAbilityEditorApplicationMode::FEzAbilityEditorApplicationMode(const TSharedRe
 	PreviewScene = MakeShareable(new FAdvancedPreviewScene(FPreviewScene::ConstructionValues()));
 	EzAbilityEditorTabFactories.RegisterFactory(MakeShareable(new FEzAbilityViewPortSummoner(InHostingApp, PreviewScene.ToSharedRef())));
 	EzAbilityEditorTabFactories.RegisterFactory(MakeShareable(new FEzAbilityTimelineSummoner(InHostingApp, PreviewScene.ToSharedRef())));
-	EzAbilityEditorTabFactories.RegisterFactory(MakeShareable(new FEzAbilityAbleTreeSummoner(InHostingApp, PreviewScene.ToSharedRef())));
+	EzAbilityEditorTabFactories.RegisterFactory(MakeShareable(new FEzAbilityAbleTreeSummoner(InHostingApp, PreviewScene.ToSharedRef(), InEzAbilityEditor->AbleTreeViewOperationMode)));
 	
 	TabLayout = FTabManager::NewLayout("Standalone_EzAbilityEditor_Layout_v1.0")
 		->AddArea

+ 4 - 5
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Private/SEzAbleTreeViewRowWidget.cpp

@@ -54,7 +54,7 @@ void SEzAbleTreeViewRowWidget::Construct(const FArguments& InArgs, const TShared
 // 								.AutoWidth()
 // 								[
 // 									SNew(SImage)
-// 										.Image(this, &SStateTreeViewRow::GetTransitionsIcon, Trigger)
+// 										.Image(this, &SStateTreeViewRow::GetTransitionsIcon, Trigger)		//节点右边向上弯的箭头
 // 										.ColorAndOpacity(IconTint)
 // 								]
 // 						]
@@ -128,7 +128,7 @@ void SEzAbleTreeViewRowWidget::Construct(const FArguments& InArgs, const TShared
 								.BaseIndentLevel(0)
 								.ImageSize(FVector2f(16, 16))
 								.ImagePadding(FMargin(9, 14, 0, 0))
-								.Image(FAbleTreeEditorStyle::Get().GetBrush("StateTreeEditor.TryFollowTransitions")) // this, &SEzAbleTreeViewRowWidget::GetSelectorIcon
+								.Image(this, &SEzAbleTreeViewRowWidget::GetSelectorIcon) //FAbleTreeEditorStyle::Get().GetBrush("StateTreeEditor.TryFollowTransitions")
 								.ColorAndOpacity(FLinearColor(1, 1, 1, 0.2f))
 								.WireColorAndOpacity(FLinearColor(1, 1, 1, 0.2f))
 						]
@@ -224,7 +224,7 @@ void SEzAbleTreeViewRowWidget::Construct(const FArguments& InArgs, const TShared
 																								.Padding(FMargin(4.f, 0.f, 0.f, 0.f))
 																								[
 																									SNew(SImage)
-																										.Image(FAbleTreeEditorStyle::Get().GetBrush("StateTreeEditor.SelectNone"))//this, &SStateTreeViewRow::GetSelectorIcon 这里还不知道是哪个东西
+																										.Image(this, &SEzAbleTreeViewRowWidget::GetSelectorIcon)// 最前面的箭头 FAbleTreeEditorStyle::Get().GetBrush("StateTreeEditor.TrySelectChildrenInOrder")
 																										.ColorAndOpacity(IconTint)
 																										//.ToolTipText(this, &SStateTreeViewRow::GetSelectorTooltip)
 																								]
@@ -463,8 +463,7 @@ const FSlateBrush* SEzAbleTreeViewRowWidget::GetSelectorIcon() const
 {
 	if (const UEzAbilityState* State = WeakState.Get())
 	{
-		return FAbleTreeEditorStyle::GetBrushForSelectionBehaviorType();
-		//return FStateTreeEditorStyle::GetBrushForSelectionBehaviorType(State->SelectionBehavior, !State->Children.IsEmpty(), State->Type);
+		return FAbleTreeEditorStyle::GetBrushForSelectionBehaviorType(State->SelectionBehavior, !State->Children.IsEmpty(), State->Type);
 	}
 
 	return nullptr;

+ 45 - 2
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Private/SEzAbleTreeViewWidget.cpp

@@ -10,8 +10,12 @@
 #define LOCTEXT_NAMESPACE "AbleStateTreeEditor"
 
 BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
-void SEzAbleTreeViewWidget::Construct(const FArguments& InArgs)
+void SEzAbleTreeViewWidget::Construct(const FArguments& InArgs, TSharedPtr<FEzAbleTreeViewOperationMode> InAbleTreeViewOperationMode)
 {
+	AbleTreeViewOperationMode = InAbleTreeViewOperationMode;
+
+	AbleTreeViewOperationMode->GetOnStateAdded().AddSP(this, &SEzAbleTreeViewWidget::HandleModelStateAdded);
+
 	TSharedRef<SScrollBar> HorizontalScrollBar = SNew(SScrollBar)
 		.Orientation(Orient_Horizontal)
 		.Thickness(FVector2D(12.0f, 12.0f));
@@ -99,8 +103,39 @@ END_SLATE_FUNCTION_BUILD_OPTIMIZATION
 
 FReply SEzAbleTreeViewWidget::HandleAddStateButton()
 {
-	UE_LOG(LogTemp, Log, TEXT("SEzAbleTreeViewWidget::HandleAddStateButton"));
+	if (AbleTreeViewOperationMode == nullptr)
+	{
+		return FReply::Handled();
+	}
+
+	TArray<UEzAbilityState*> SelectedStates;
+	//AbleTreeViewOperationMode->GetSelectedStates(SelectedStates);
+	//UStateTreeState* FirstSelectedState = SelectedStates.Num() > 0 ? SelectedStates[0] : nullptr;
+
+// 	if (FirstSelectedState != nullptr)
+// 	{
+// 		// If the state is root, add child state, else sibling.
+// 		if (FirstSelectedState->Parent == nullptr)
+// 		{
+// 			StateTreeViewModel->AddChildState(FirstSelectedState);
+// 			TreeView->SetItemExpansion(FirstSelectedState, true);
+// 		}
+// 		else
+// 		{
+// 			StateTreeViewModel->AddState(FirstSelectedState);
+// 		}
+// 	}
+// 	else
+// 	{
+// 		// Add root state at the lowest level.
+// 		StateTreeViewModel->AddState(nullptr);
+// 	}
+
+	AbleTreeViewOperationMode->AddState(nullptr);
+
 	return FReply::Handled();
+// 	UE_LOG(LogTemp, Log, TEXT("SEzAbleTreeViewWidget::HandleAddStateButton"));
+// 	return FReply::Handled();
 }
 
 TSharedRef<ITableRow> SEzAbleTreeViewWidget::HandleGenerateRow(TWeakObjectPtr<UEzAbilityState> InState, const TSharedRef<STableViewBase>& InOwnerTableView)
@@ -127,4 +162,12 @@ void SEzAbleTreeViewWidget::UpdateTree(bool bExpandPersistent /*= false*/)
 
 }
 
+void SEzAbleTreeViewWidget::HandleModelStateAdded(UEzAbilityState* ParentState, UEzAbilityState* NewState)
+{
+	TreeView->SetItemSelection(NewState, true);
+	TreeView->SetItemExpansion(NewState, true);
+// 	TreeView->RequestScrollIntoView(TestAddState);
+// 	TreeView->RequestTreeRefresh();
+}
+
 #undef LOCTEXT_NAMESPACE

+ 1 - 1
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Public/AbleTreeEditorStyle.h

@@ -14,7 +14,7 @@ class  FAbleTreeEditorStyle : public FSlateStyleSet
 public:
 	static FAbleTreeEditorStyle& Get();
 	
-	static const FSlateBrush* GetBrushForSelectionBehaviorType(); //EAbleTreeStateSelectionBehavior InBehaviour, bool bHasChildren, EAbleTreeStateType StateType	
+	static const FSlateBrush* GetBrushForSelectionBehaviorType(EEzAbilityStateSelectionBehavior InBehaviour, bool bHasChildren, EEzAbilityStateType StateType); 
 
 protected:
 	//friend class FStateTreeEditorModule;

+ 3 - 2
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Public/EzAbilityAbleTreeSummoner.h

@@ -21,6 +21,7 @@
 #include "PersonaTabs.h"
 #include "AdvancedPreviewSceneModule.h"
 #include "SAbilityEditorViewport.h"
+#include "EzAbleTreeViewOperationMode.h"
 
 #define LOCTEXT_NAMESPACE "AbilityMode"
 
@@ -33,13 +34,13 @@ class SToolTip;
 struct FEzAbilityAbleTreeSummoner : public FWorkflowTabFactory
 {
 public:
-	FEzAbilityAbleTreeSummoner(TSharedPtr<class FAssetEditorToolkit> InHostingApp, const TSharedRef<FAdvancedPreviewScene>& InPreviewScene);
+	FEzAbilityAbleTreeSummoner(TSharedPtr<class FAssetEditorToolkit> InHostingApp, const TSharedRef<FAdvancedPreviewScene>& InPreviewScene, TSharedPtr<FEzAbleTreeViewOperationMode> InAbleTreeViewOperationMode);
 	virtual TSharedRef<SWidget> CreateTabBody(const FWorkflowTabSpawnInfo& Info) const override;
 	virtual FText GetTabToolTipText(const FWorkflowTabSpawnInfo& Info) const override;
 	static const FName EzAbilityAbleTreeSummonerID;
 private:
 	TWeakPtr<class FAdvancedPreviewScene> PreviewScene;
-
+	TSharedPtr<FEzAbleTreeViewOperationMode> AbleTreeViewOperationMode;
 };
 
 

+ 4 - 1
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Public/EzAbilityEditor.h

@@ -7,6 +7,7 @@
 //#include "SDialogueEditorViewport.h"
 #include "Widgets/Input/SButton.h"
 #include "IPersonaToolkit.h"
+#include "EzAbleTreeViewOperationMode.h"
 /**
  * 
  */
@@ -55,12 +56,14 @@ public:
 
 	TObjectPtr<UEZAbilityBlueprint>		EzAbilityDataAsset;
 
+	TObjectPtr<UEzAbility>				EzAbilityAsset;
+
 	static const FName					EzAbilityEditorMode;
 
 	/** Persona toolkit used to support skeletal mesh preview */
 	TSharedPtr<IPersonaToolkit>			PersonaToolkit;
 
-
+	TSharedPtr<FEzAbleTreeViewOperationMode>	AbleTreeViewOperationMode;
 // 	/* 图表 */
 // 	void RestoreEzAbilityGraph();
 // 

+ 2 - 0
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Public/EzAbleTreeViewOperationMode.h

@@ -29,6 +29,8 @@ public:
 
 	void AddState(UEzAbilityState* AfterState);
 
+
+	FOnStateAdded& GetOnStateAdded() { return OnStateAdded; }
 protected:
 
 	TWeakObjectPtr<UEzAbilityEditorData> TreeDataWeak;

+ 8 - 1
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Public/SEzAbleTreeViewWidget.h

@@ -6,6 +6,7 @@
 #include "Widgets/SCompoundWidget.h"
 #include "Widgets/Layout/SScrollBox.h"
 #include "EzAbilityState.h"
+#include "EzAbleTreeViewOperationMode.h"
 
 /**
  * 
@@ -18,18 +19,24 @@ public:
 	SLATE_END_ARGS()
 
 	/** Constructs this widget with InArgs */
-	void Construct(const FArguments& InArgs);
+	void Construct(const FArguments& InArgs, TSharedPtr<FEzAbleTreeViewOperationMode> InAbleTreeViewOperationMode);
 	FReply HandleAddStateButton();
 
 	// Treeview handlers
 	TSharedRef<ITableRow> HandleGenerateRow(TWeakObjectPtr<UEzAbilityState> InState, const TSharedRef<STableViewBase>& InOwnerTableView);
 	void HandleGetChildren(TWeakObjectPtr<UEzAbilityState> InParent, TArray<TWeakObjectPtr<UEzAbilityState>>& OutChildren);
 	void UpdateTree(bool bExpandPersistent = false);
+
+	void HandleModelStateAdded(UEzAbilityState* ParentState, UEzAbilityState* NewState);
 public:
 
+	TSharedPtr<FEzAbleTreeViewOperationMode> AbleTreeViewOperationMode;
+
 	TSharedPtr<STreeView<TWeakObjectPtr<UEzAbilityState>>> TreeView;
 	TSharedPtr<SScrollBox> ViewBox;
 
 	TArray<TWeakObjectPtr<UEzAbilityState>> TestState;
 	TArray<TObjectPtr<UEzAbilityState>>	TestStrongState;
+
+	TObjectPtr<UEzAbilityState>	TestAddState;
 };