소스 검색

只有root可以移动,并且所有子节点随着父节点一起移动
重新布局时,root节点保持位置不变,其它节点位置做相应改变

tanghai 14 년 전
부모
커밋
eecf69aa6c

+ 1 - 0
CSharp/CSharp.sln.DotSettings

@@ -3,6 +3,7 @@
 	<s:Boolean x:Key="/Default/CodeEditing/Intellisense/LookupWindow/ShowSummary/@EntryValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/CodeEditing/Localization/CSharpLocalizationOptions/DontAnalyseVerbatimStrings/@EntryValue">False</s:Boolean>
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
+	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToAutoProperty/@EntryIndexedValue">DO_NOT_SHOW</s:String>
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForCanBeConvertedToForeach/@EntryIndexedValue">DO_NOT_SHOW</s:String>
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue">DO_NOT_SHOW</s:String>
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBeConvertedToQuery/@EntryIndexedValue">DO_NOT_SHOW</s:String>

+ 25 - 5
CSharp/Modules/BehaviorTree/BehaviorTreeLayout.cs

@@ -6,9 +6,13 @@ namespace Modules.BehaviorTree
 	{
 		private const double XGap = 20;
 		private const double YGap = 10;
+		private static double rootOrigX;
+		private static double rootOrigY;
+		private static double rootOffsetX;
+		private static double rootOffsetY;
 		private static readonly Logger logger = LogManager.GetCurrentClassLogger();
 
-		public static TreeNodeViewModel LeftMostOffspring(TreeNodeViewModel treeNode, int currentLevel, int searchLevel)
+		private static TreeNodeViewModel LeftMostOffspring(TreeNodeViewModel treeNode, int currentLevel, int searchLevel)
 		{
 			if (currentLevel == searchLevel)
 			{
@@ -28,7 +32,7 @@ namespace Modules.BehaviorTree
 			return null;
 		}
 
-		public static TreeNodeViewModel RightMostOffspring(TreeNodeViewModel treeNode, int currentLevel, int searchLevel)
+		private static TreeNodeViewModel RightMostOffspring(TreeNodeViewModel treeNode, int currentLevel, int searchLevel)
 		{
 			if (currentLevel == searchLevel)
 			{
@@ -126,11 +130,11 @@ namespace Modules.BehaviorTree
 			logger.Debug("Num: " + treeNode.Num + " Prelim: " + treeNode.Prelim + " Modify: " + treeNode.Modify);
 		}
 
-		private static void CalculateXAndY(TreeNodeViewModel treeNode, int level, double totalModify)
+		private static void CalculateRelativeXAndY(TreeNodeViewModel treeNode, int level, double totalModify)
 		{
 			foreach (TreeNodeViewModel node in treeNode.Children)
 			{
-				CalculateXAndY(node, level + 1, treeNode.Modify + totalModify);
+				CalculateRelativeXAndY(node, level + 1, treeNode.Modify + totalModify);
 			}
 			if (treeNode.IsLeaf)
 			{
@@ -143,14 +147,30 @@ namespace Modules.BehaviorTree
 			treeNode.Y = level * (TreeNodeViewModel.Height + YGap);
 		}
 
+		private static void FixXAndY(TreeNodeViewModel treeNode)
+		{
+			treeNode.X += rootOffsetX;
+			treeNode.Y += rootOffsetY;
+			foreach (var node in treeNode.Children)
+			{
+				FixXAndY(node);
+			}
+		}
+
 		public static void ExcuteLayout(TreeNodeViewModel root)
 		{
 			if (root == null)
 			{
 				return;
 			}
+			rootOrigX = root.X;
+			rootOrigY = root.Y;
 			CalculatePrelimAndModify(root);
-			CalculateXAndY(root, 0, 0);
+			CalculateRelativeXAndY(root, 0, 0);
+
+			rootOffsetX = rootOrigX - root.X;
+			rootOffsetY = rootOrigY - root.Y;
+			FixXAndY(root);
 		}
 	}
 }

+ 0 - 11
CSharp/Modules/BehaviorTree/BehaviorTreeView.xaml

@@ -45,17 +45,6 @@
 								RadiusX="4" RadiusY="4" Stroke="{StaticResource treeNodeBorderBrush}" Fill="{StaticResource treeNodeFillBrush}"/>
 						<Line X1="{Binding ConnectorX1}" Y1="{Binding ConnectorY1}" X2="{Binding ConnectorX2}" Y2="{Binding ConnectorY2}"
 								Stroke="Black" StrokeThickness="2" />
-						<StackPanel>
-							<StackPanel Orientation="Horizontal">
-								<Label Content="{Binding Num}"></Label>
-								<Label Content="{Binding X}"></Label>
-								<Label Content="{Binding Y}"></Label>
-							</StackPanel>
-							<StackPanel Orientation="Horizontal">
-								<Label Content="{Binding Prelim}"></Label>
-								<Label Content="{Binding Modify}"></Label>
-							</StackPanel>
-						</StackPanel>
 					</Canvas>
 					<DataTemplate.Triggers>
 						<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">

+ 12 - 13
CSharp/Modules/BehaviorTree/BehaviorTreeView.xaml.cs

@@ -138,6 +138,17 @@ namespace Modules.BehaviorTree
 
 		private void ListBoxItem_MouseMove(object sender, MouseEventArgs e)
 		{
+			var item = (FrameworkElement) sender;
+			var treeNodeViewModel = item.DataContext as TreeNodeViewModel;
+			if (treeNodeViewModel == null)
+			{
+				return;
+			}
+			if (!treeNodeViewModel.IsRoot)
+			{
+				return;
+			}
+
 			Point curMouseDownPoint;
 			Vector dragDelta;
 			if (this.isDragging)
@@ -147,11 +158,7 @@ namespace Modules.BehaviorTree
 
 				this.origMouseDownPoint = curMouseDownPoint;
 
-				foreach (TreeNodeViewModel selectedItem in this.listBox.SelectedItems)
-				{
-					selectedItem.X += dragDelta.X;
-					selectedItem.Y += dragDelta.Y;
-				}
+				this.ViewModel.Move(dragDelta.X, dragDelta.Y);
 				return;
 			}
 
@@ -160,14 +167,6 @@ namespace Modules.BehaviorTree
 				return;
 			}
 
-			var item = (FrameworkElement) sender;
-			var treeNodeViewModel = item.DataContext as TreeNodeViewModel;
-
-			if (!this.listBox.SelectedItems.Contains(treeNodeViewModel))
-			{
-				return;
-			}
-
 			curMouseDownPoint = e.GetPosition(this);
 			dragDelta = curMouseDownPoint - this.origMouseDownPoint;
 			double dragDistance = Math.Abs(dragDelta.Length);

+ 15 - 0
CSharp/Modules/BehaviorTree/BehaviorTreeViewModel.cs

@@ -50,5 +50,20 @@ namespace Modules.BehaviorTree
 			this.RecursionRemove(treeNodeViewModel);
 			BehaviorTreeLayout.ExcuteLayout(this.Root);
 		}
+
+		private void RecursionMove(TreeNodeViewModel treeNodeViewModel, double offsetX, double offsetY)
+		{
+			treeNodeViewModel.X += offsetX;
+			treeNodeViewModel.Y += offsetY;
+			foreach (var node in treeNodeViewModel.Children)
+			{
+				this.RecursionMove(node, offsetX, offsetY);
+			}
+		}
+
+		public void Move(double offsetX, double offsetY)
+		{
+			this.RecursionMove(this.Root, offsetX, offsetY);
+		}
 	}
 }

+ 0 - 10
CSharp/Modules/BehaviorTree/TreeNodeViewModel.cs

@@ -76,7 +76,6 @@ namespace Modules.BehaviorTree
 			set
 			{
 				this.prelim = value;
-				this.RaisePropertyChanged("Prelim");
 			}
 		}
 
@@ -88,7 +87,6 @@ namespace Modules.BehaviorTree
 			}
 			set
 			{
-				this.RaisePropertyChanged("Modify");
 				this.modify = value;
 			}
 		}
@@ -238,14 +236,6 @@ namespace Modules.BehaviorTree
 			}
 		}
 
-		public int Index
-		{
-			get
-			{
-				return this.IsRoot ? 0 : this.Parent.Children.IndexOf(this);
-			}
-		}
-
 		public TreeNodeViewModel LastChild
 		{
 			get