Просмотр исходного кода

右键功能:增加兄弟节点、子节点

maboren 2 месяцев назад
Родитель
Сommit
66b87d45be

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

@@ -109,6 +109,26 @@ void FEzAbleTreeViewOperationMode::AddState(UEzAbilityState* AfterState)
 }
 
 
+void FEzAbleTreeViewOperationMode::AddChildState(UEzAbilityState* ParentState)
+{
+	UEzAbilityEditorData* TreeData = TreeDataWeak.Get();
+	if (TreeData == nullptr || ParentState == nullptr)
+	{
+		return;
+	}
+
+	const FScopedTransaction Transaction(LOCTEXT("AddChildStateTransaction", "Add Child State"));
+
+	UEzAbilityState* NewState = NewObject<UEzAbilityState>(ParentState, FName(), RF_Transactional);
+
+	ParentState->Modify();
+
+	ParentState->Children.Add(NewState);
+	NewState->Parent = ParentState;
+
+	OnStateAdded.Broadcast(ParentState, NewState);
+}
+
 void FEzAbleTreeViewOperationMode::ClearSelection()
 {
 	SelectedStates.Reset();

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

@@ -269,6 +269,26 @@ void SEzAbleTreeViewWidget::BindCommands()
 		Commands.DeleteStates,
 		FExecuteAction::CreateSP(this, &SEzAbleTreeViewWidget::HandleDeleteStates),
 		FCanExecuteAction::CreateSP(this, &SEzAbleTreeViewWidget::HasSelection));
+
+	CommandList->MapAction(
+		Commands.AddChildState,
+		FExecuteAction::CreateSP(this, &SEzAbleTreeViewWidget::HandleAddChildState),
+		FCanExecuteAction::CreateSP(this, &SEzAbleTreeViewWidget::HasSelection));
+
+	CommandList->MapAction(
+		Commands.AddSiblingState,
+		FExecuteAction::CreateSP(this, &SEzAbleTreeViewWidget::HandleAddSiblingState),
+		FCanExecuteAction());
+}
+
+UEzAbilityState* SEzAbleTreeViewWidget::GetFirstSelectedState() const
+{
+	TArray<UEzAbilityState*> SelectedStates;
+	if (AbleTreeViewOperationMode)
+	{
+		AbleTreeViewOperationMode->GetSelectedStates(SelectedStates);
+	}
+	return SelectedStates.IsEmpty() ? nullptr : SelectedStates[0];
 }
 
 void SEzAbleTreeViewWidget::HandleDeleteStates()
@@ -280,6 +300,27 @@ void SEzAbleTreeViewWidget::HandleDeleteStates()
 	}
 }
 
+void SEzAbleTreeViewWidget::HandleAddChildState()
+{
+	if (AbleTreeViewOperationMode)
+	{
+		UEzAbilityState* ParentState = GetFirstSelectedState();
+		if (ParentState)
+		{
+			AbleTreeViewOperationMode->AddChildState(ParentState);
+			TreeView->SetItemExpansion(ParentState, true);
+		}
+	}
+}
+
+void SEzAbleTreeViewWidget::HandleAddSiblingState()
+{
+	if (AbleTreeViewOperationMode)
+	{
+		AbleTreeViewOperationMode->AddState(GetFirstSelectedState());
+	}
+}
+
 FReply SEzAbleTreeViewWidget::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
 {
 	if (CommandList->ProcessCommandBindings(InKeyEvent))

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

@@ -30,6 +30,7 @@ public:
 	virtual void PostRedo(bool bSuccess) override;
 
 	void AddState(UEzAbilityState* AfterState);
+	void AddChildState(UEzAbilityState* ParentState);
 	void ClearSelection();
 	void SetSelection(UEzAbilityState* Selected);
 	void SetSelection(const TArray<TWeakObjectPtr<UEzAbilityState>>& InSelection);

+ 3 - 0
Ability/Plugins/EzAbility/Source/EzAbilityEditor/Public/SEzAbleTreeViewWidget.h

@@ -37,7 +37,10 @@ public:
 	void BindCommands();
 
 	//Action Handlers
+	UEzAbilityState* GetFirstSelectedState() const;
 	void HandleDeleteStates();
+	void HandleAddChildState();
+	void HandleAddSiblingState();
 
 private:
 	virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override;