tanghai 11 лет назад
Родитель
Сommit
1b6c9882a5

+ 2 - 0
CSharp/App/Modules/Tree/BehaviorTreeView.xaml

@@ -32,6 +32,7 @@
 		<SolidColorBrush x:Key="treeNodeBorderBrush" Color="Black" />
 		<Tree:NodeTypeColorConverter x:Key="NodeTypeColorConverter"/>
 		<Tree:NodeTypeToStringConverter x:Key="NodeTypeToStringConverter"/>
+		<Tree:FolderVisiableConverter x:Key="FolderVisiableConverter"/>
 	</UserControl.Resources>
 
 	<UserControl.CommandBindings>
@@ -77,6 +78,7 @@
 							PreviewMouseLeftButtonUp="ListBoxItem_PreviewMouseLeftButtonUp">
 						<Rectangle Name="rectNode" Width="{Binding Width}" Height="{Binding Height}" Cursor="Hand" StrokeThickness="2"
 								RadiusX="10" RadiusY="10" Stroke="{StaticResource treeNodeBorderBrush}" Fill="{StaticResource treeNodeSelectorFillBrush}"/>
+						<Label Content="+" Visibility="{Binding IsFolder, Converter={StaticResource FolderVisiableConverter}}" Canvas.Left="60" Canvas.Top="10"  ></Label>
 						<StackPanel>
 							<Label Content="{Binding Type, Converter={StaticResource NodeTypeToStringConverter}}" ></Label>
 							<Label Content="{Binding Comment}" ></Label>

+ 30 - 0
CSharp/App/Modules/Tree/FolderVisiableConverter.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace Tree
+{
+	[ValueConversion(typeof(bool), typeof(Visibility))]
+	public class FolderVisiableConverter : IValueConverter
+	{
+		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+		{
+			if (value == null)
+			{
+				return 0;
+			}
+			bool isFolder = (bool) value;
+			if (isFolder)
+			{
+				return Visibility.Visible;
+			}
+			return Visibility.Hidden;
+		}
+
+		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+		{
+			return null;
+		}
+	}
+}

+ 4 - 2
CSharp/App/Modules/Tree/NodeDataEditor.xaml

@@ -4,7 +4,7 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:tree="clr-namespace:Tree"
-             mc:Ignorable="d" Height="198" Width="211" DataContextChanged="OnDataContextChanged">
+             mc:Ignorable="d" Height="220" Width="211" DataContextChanged="OnDataContextChanged">
 	<UserControl.Resources>
 		<tree:ListToStringConverter x:Key="ListToStringConverter"/>
 	</UserControl.Resources>
@@ -14,6 +14,7 @@
 			<RowDefinition Height="*"/>
 			<RowDefinition Height="*"/>
 			<RowDefinition Height="4*"/>
+			<RowDefinition Height="*"/>
 		</Grid.RowDefinitions>
 		<Grid.ColumnDefinitions>
 			<ColumnDefinition Width="47*"/>
@@ -23,9 +24,10 @@
 		<Label Content="类型:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalAlignment="Top" Height="26" Margin="-2,0,9,0" Width="40" />
 		<Label Content="参数:" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalAlignment="Top" Height="26" Margin="-2,1,9,0" Width="40" />
 		<Label Content="备注:" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalAlignment="Top" Height="26" Margin="0,40,9,0" Width="40" />
-		<TextBox Name="tbId" Grid.Column="1" Grid.Row="0" Margin="2" Text="{Binding Id}" IsReadOnly="True" />
+		<Label Name="lblId" Grid.Column="1" Grid.Row="0" Margin="2" Content="{Binding Id}" />
 		<ComboBox Name="cbType" Grid.Column="1" Grid.Row="1" Margin="2" SelectionChanged="CbType_OnSelectionChanged" />
 		<TextBox Name="tbArgs" Grid.Column="1" Grid.Row="2" Margin="2" Text="{Binding Args, Converter={StaticResource ListToStringConverter}}" />
 		<TextBox Name="tbComment" Grid.Column="1" Grid.Row="3" Margin="2" Text="{Binding Comment}" />
+		<Button Content="OK" Grid.Row="4" Grid.Column="1" Margin="1,1,40,1"></Button>
 	</Grid>
 </UserControl>

+ 1 - 0
CSharp/App/Modules/Tree/Tree.csproj

@@ -91,6 +91,7 @@
     <Compile Include="BehaviorTreeView.xaml.cs">
       <DependentUpon>BehaviorTreeView.xaml</DependentUpon>
     </Compile>
+    <Compile Include="FolderVisiableConverter.cs" />
     <Compile Include="NodeTypeToStringConverter.cs" />
     <Compile Include="NodeTypeColorConverter.cs" />
     <Compile Include="ListToStringConverter.cs" />

+ 5 - 16
CSharp/App/Modules/Tree/TreeNodeData.cs

@@ -20,28 +20,22 @@ namespace Tree
 		[DataMember(Order = 2)]
 		public int Type { get; set; }
 
-		/// <summary>
-		/// 节点名字
-		/// </summary>
-		[DataMember(Order = 3)]
-		public string Name { get; set; }
-
 		/// <summary>
 		/// 节点配置参数
 		/// </summary>
-		[DataMember(Order = 4)]
+		[DataMember(Order = 3)]
 		public List<string> Args { get; set; }
 
 		/// <summary>
 		/// 父节点
 		/// </summary>
-		[DataMember(Order = 5)]
+		[DataMember(Order = 4)]
 		public int ParentId { get; set; }
 
 		/// <summary>
 		/// 子节点
 		/// </summary>
-		[DataMember(Order = 6)]
+		[DataMember(Order = 5)]
 		public List<int> ChildrenId
 		{
 			get
@@ -53,12 +47,7 @@ namespace Tree
 		/// <summary>
 		/// 节点说明
 		/// </summary>
-		[DataMember(Order = 7)]
-		public string Comment { get; set; }
-
-		/// <summary>
-		/// 节点是否折叠,给编辑器看的
-		/// </summary>
-		public bool IsFold { get; set; }
+		[DataMember(Order = 6)]
+		public string Comment { get; set; }
 	}
 }

+ 9 - 16
CSharp/App/Modules/Tree/TreeNodeViewModel.cs

@@ -19,7 +19,8 @@ namespace Tree
 		private double prelim;
 		private double modify;
 		private double ancestorModify;
-		private TreeNodeViewModel parent;
+		private TreeNodeViewModel parent;
+		private bool isFolder;
 
 		private ObservableCollection<TreeNodeViewModel> children = new ObservableCollection<TreeNodeViewModel>();
 
@@ -94,19 +95,6 @@ namespace Tree
 			}
 		}
 
-		public string Name
-		{
-			get
-			{
-				return this.treeNodeData.Name;
-			}
-			set
-			{
-				this.treeNodeData.Name = value;
-				this.OnPropertyChanged("Name");
-			}
-		}
-
 		public string Comment
 		{
 			get
@@ -319,11 +307,16 @@ namespace Tree
 		{
 			get
 			{
-				return this.treeNodeData.IsFold;
+				return this.isFolder;
 			}
 			set
 			{
-				this.treeNodeData.IsFold = value;
+				if (isFolder == value)
+				{
+					return;
+				}
+				this.isFolder = value;
+				this.OnPropertyChanged("IsFolder");
 			}
 		}