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

+ 11 - 2
CSharp/App/Modules/Tree/AllTreeView.xaml

@@ -9,7 +9,7 @@
 		d:DesignWidth="1280" 
 		d:DataContext="{d:DesignInstance Tree:AllTreeViewModel}">
 	<DockPanel>
-	<Menu DockPanel.Dock="Top">
+	<Menu DockPanel.Dock="Top" Height="24">
 		<MenuItem Header="File">
 			<MenuItem Header="打开" Click="MenuItem_Open" />
 			<MenuItem Header="保存" Click="MenuItem_Save" />
@@ -27,7 +27,16 @@
 			<ColumnDefinition />
 		</Grid.ColumnDefinitions>
 		<GroupBox Grid.Row="0" Grid.Column="0" Header="行为树列表:">
-			<ListBox Name="lbTreeId" ItemsSource="{Binding TreeList}" ></ListBox>
+			<ListBox Name="lbTreeId" ItemsSource="{Binding TreeList}" VerticalAlignment="Stretch" >
+				<ListBox.ItemTemplate>
+					<DataTemplate DataType="Tree:TreeInfoViewModel">
+						<StackPanel MouseLeftButtonDown="OnMouseLeftButtonDown" Orientation="Horizontal" Margin="1,0">
+							<Label Content="{Binding Id}" VerticalAlignment="Stretch" Width="20" ></Label>
+							<Label Content="{Binding Comment}" VerticalAlignment="Stretch" Width="150"></Label>
+						</StackPanel>
+					</DataTemplate>
+				</ListBox.ItemTemplate>
+			</ListBox>
 		</GroupBox>
 		<GroupBox Grid.Row="1" Grid.Column="0" Header="节点编辑:">
 			<Tree:NodeDataEditor x:Name="nodeDataEditor" VerticalAlignment="Top" />

+ 21 - 8
CSharp/App/Modules/Tree/AllTreeView.xaml.cs

@@ -1,5 +1,8 @@
-using System.ComponentModel.Composition;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
 using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
 using Infrastructure;
 using Microsoft.Practices.Prism.PubSubEvents;
 
@@ -11,27 +14,24 @@ namespace Tree
     [ViewExport(RegionName = "BehaviorTreeRegion"), PartCreationPolicy(CreationPolicy.NonShared)]
     public partial class AllTreeView
     {
-        private AllTreeViewModel allTreeViewModel;
-
         public AllTreeView()
         {
             this.InitializeComponent();
 
             this.nodeDataEditor.AllTreeView = this;
             this.treeView.AllTreeView = this;
-            this.treeView.TreeViewModel = new TreeViewModel();
         }
 
         [Import]
-        private AllTreeViewModel AllTreeViewModel
+        private AllTreeViewModel ViewModel
         {
             get
             {
-                return allTreeViewModel;
+                return this.DataContext as AllTreeViewModel;
             }
             set
             {
-                this.allTreeViewModel = value;
+                this.DataContext = value;
             }
         }
 
@@ -45,7 +45,20 @@ namespace Tree
 
         private void MenuItem_New(object sender, RoutedEventArgs e)
         {
-            this.treeView.TreeViewModel = new TreeViewModel();
+            TreeViewModel treeViewModel = new TreeViewModel(new List<TreeNodeData>());
+            this.ViewModel.Add(treeViewModel);
+            this.treeView.ViewModel = treeViewModel;
+        }
+
+        private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+        {
+            var item = (FrameworkElement)sender;
+            var treeInfoViewModel = item.DataContext as TreeInfoViewModel;
+            if (this.treeView.ViewModel.TreeId == treeInfoViewModel.Id)
+            {
+                return;
+            }
+            this.treeView.ViewModel = this.ViewModel.Get(treeInfoViewModel.Id);
         }
     }
 }

+ 49 - 12
CSharp/App/Modules/Tree/AllTreeViewModel.cs

@@ -8,20 +8,20 @@ namespace Tree
 {
     [Export(contractType: typeof (AllTreeViewModel)),
      PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
-    internal class AllTreeViewModel
+    public class AllTreeViewModel
     {
         private AllTreeData allTreeData;
 
         public int MaxNodeId { get; set; }
         public int MaxTreeId { get; set; }
 
-        private readonly ObservableCollection<int> treeList =
-                new ObservableCollection<int>();
+        public Dictionary<int, List<TreeNodeData>> treeDict = new Dictionary<int, List<TreeNodeData>>();
 
-        public Dictionary<int, ObservableCollection<TreeNodeViewModel>> oneTree = 
-            new Dictionary<int, ObservableCollection<TreeNodeViewModel>>();
+        private readonly Dictionary<int, TreeViewModel> treeViewModelsDict = new Dictionary<int, TreeViewModel>(); 
 
-        public ObservableCollection<int> TreeList
+        public ObservableCollection<TreeInfoViewModel> treeList = new ObservableCollection<TreeInfoViewModel>();
+
+        public ObservableCollection<TreeInfoViewModel> TreeList
         {
             get
             {
@@ -31,20 +31,33 @@ namespace Tree
 
         public void Load(string file)
         {
-            this.treeList.Clear();
+            treeDict.Clear();
+            treeList.Clear();
             byte[] bytes = File.ReadAllBytes(file);
             this.allTreeData = ProtobufHelper.FromBytes<AllTreeData>(bytes);
 
+            this.MaxNodeId = 0;
+            this.MaxTreeId = 0;
             foreach (TreeNodeData treeNodeData in allTreeData.TreeNodeDatas)
             {
-                ObservableCollection<TreeNodeViewModel> tree;
-                this.oneTree.TryGetValue(treeNodeData.TreeId, out tree);
+                List<TreeNodeData> tree;
+                this.treeDict.TryGetValue(treeNodeData.TreeId, out tree);
                 if (tree == null)
                 {
-                    tree = new ObservableCollection<TreeNodeViewModel>();
-                    oneTree[treeNodeData.TreeId] = tree;
+                    tree = new List<TreeNodeData>();
+                    this.treeDict[treeNodeData.TreeId] = tree;
+                }
+                tree.Add(treeNodeData);
+                if (treeNodeData.Id > this.MaxNodeId)
+                {
+                    this.MaxNodeId = treeNodeData.Id;
+                }
+                if (treeNodeData.TreeId > this.MaxTreeId)
+                {
+                    this.MaxTreeId = treeNodeData.TreeId;
                 }
-                //tree.Add(new TreeNodeViewModel(treeNodeData));
+
+                treeList.Add(new TreeInfoViewModel(treeNodeData.TreeId, treeNodeData.TreeId.ToString()));
             }
         }
 
@@ -52,5 +65,29 @@ namespace Tree
         {
             
         }
+
+        public void New(TreeViewModel treeViewModel)
+        {
+        }
+
+        public void Add(TreeViewModel treeViewModel)
+        {
+            treeViewModel.TreeId = ++this.MaxTreeId;
+            treeViewModel.AllTreeViewModel = this;
+            treeDict[treeViewModel.TreeId] = treeViewModel.TreeNodeDatas;
+            treeViewModelsDict[treeViewModel.TreeId] = treeViewModel;
+            this.treeList.Add(new TreeInfoViewModel(treeViewModel.TreeId, treeViewModel.TreeId.ToString()));
+        }
+
+        public TreeViewModel Get(int treeId)
+        {
+            if (this.treeViewModelsDict.ContainsKey(treeId))
+            {
+                return this.treeViewModelsDict[treeId];
+            }
+            var treeViewModel = new TreeViewModel(this.treeDict[treeId]);
+            this.treeViewModelsDict[treeId] = treeViewModel;
+            return treeViewModel;
+        }
     }
 }

+ 0 - 8
CSharp/App/Modules/Tree/SelectNodeChangeEvent.cs

@@ -1,8 +0,0 @@
-using Microsoft.Practices.Prism.PubSubEvents;
-
-namespace Tree
-{
-    public class SelectNodeChangeEvent: PubSubEvent<TreeNodeViewModel>
-    {
-    }
-}

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

@@ -85,7 +85,6 @@
     <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="SelectNodeChangeEvent.cs" />
     <Compile Include="TreeInfoViewModel.cs" />
     <Compile Include="AllTreeViewModel.cs" />
     <Compile Include="OneTreeData.cs" />

+ 2 - 4
CSharp/App/Modules/Tree/TreeInfoViewModel.cs

@@ -1,9 +1,7 @@
-using System.ComponentModel.Composition;
-
+
 namespace Tree
 {
-    [Export(contractType: typeof(TreeInfoViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
-    internal class TreeInfoViewModel
+    public class TreeInfoViewModel
     {
         private int id;
         private string comment;

+ 6 - 7
CSharp/App/Modules/Tree/TreeNodeViewModel.cs

@@ -6,13 +6,12 @@ namespace Tree
 {
     public class TreeNodeViewModel: BindableBase
     {
-        private static int globalNum;
         private static double width = 80;
         private static double height = 50;
-        private TreeViewModel treeViewModel;
+        private readonly TreeViewModel treeViewModel;
+        private readonly TreeNodeData treeNodeData;
         private double x;
         private double y;
-        private readonly TreeNodeData treeNodeData;
         private double connectorX2;
         private double connectorY2;
         private double prelim;
@@ -26,7 +25,7 @@ namespace Tree
             this.x = x;
             this.y = y;
             this.treeNodeData = new TreeNodeData();
-            this.treeNodeData.Id = globalNum++;
+            this.treeNodeData.Id = ++treeViewModel.AllTreeViewModel.MaxNodeId;
             this.treeNodeData.Parent = 0;
             this.connectorX2 = 0;
             this.connectorY2 = Height / 2;
@@ -36,14 +35,14 @@ namespace Tree
         {
             this.treeViewModel = treeViewModel;
             this.treeNodeData = new TreeNodeData();
-            this.treeNodeData.Id = globalNum++;
+            this.treeNodeData.Id = ++treeViewModel.AllTreeViewModel.MaxNodeId;
             this.Parent = parent;
 
             this.connectorX2 = Width + this.Parent.X - this.X;
             this.connectorY2 = Height / 2 + this.Parent.Y - this.Y;
         }
 
-        public TreeNodeViewModel(TreeViewModel treeViewModel, TreeNodeData data, TreeNodeViewModel parent)
+        public TreeNodeViewModel(TreeViewModel treeViewModel, TreeNodeData data)
         {
             this.treeViewModel = treeViewModel;
             this.treeNodeData = data;
@@ -292,7 +291,7 @@ namespace Tree
         {
             get
             {
-                if (this.Id == 0)
+                if (this.treeNodeData.Parent == 0)
                 {
                     return null;
                 }

+ 16 - 11
CSharp/App/Modules/Tree/TreeView.xaml.cs

@@ -23,7 +23,7 @@ namespace Tree
             this.InitializeComponent();
         }
 
-        public TreeViewModel TreeViewModel
+        public TreeViewModel ViewModel
         {
             get
             {
@@ -49,11 +49,11 @@ namespace Tree
                 var treeNodeViewModel = item.DataContext as TreeNodeViewModel;
                 if (treeNodeViewModel.IsFolder)
                 {
-                    this.TreeViewModel.UnFold(treeNodeViewModel);
+                    this.ViewModel.UnFold(treeNodeViewModel);
                 }
                 else
                 {
-                    this.TreeViewModel.Fold(treeNodeViewModel);
+                    this.ViewModel.Fold(treeNodeViewModel);
                 }
             }
             e.Handled = true;
@@ -105,7 +105,7 @@ namespace Tree
 
                 this.origMouseDownPoint = curMouseDownPoint;
 
-                this.TreeViewModel.MoveToPosition(dragDelta.X, dragDelta.Y);
+                this.ViewModel.MoveToPosition(dragDelta.X, dragDelta.Y);
                 return;
             }
 
@@ -155,33 +155,38 @@ namespace Tree
             {
                 return;
             }
-            this.TreeViewModel.MoveToNode(this.moveFromNode, moveToNode);
+            this.ViewModel.MoveToNode(this.moveFromNode, moveToNode);
             this.moveFromNode = null;
         }
 
         private void MenuItem_New(object sender, RoutedEventArgs e)
         {
+            if (this.ViewModel == null)
+            {
+                return;
+            }
+
             Point point = Mouse.GetPosition(this.listBox);
 
             // one root node
-            if (this.TreeViewModel.TreeNodes.Count == 0)
+            if (this.ViewModel.TreeNodes.Count == 0)
             {
-                var addTreeNode = new TreeNodeViewModel(this.TreeViewModel, point.X, point.Y)
+                var addTreeNode = new TreeNodeViewModel(this.ViewModel, point.X, point.Y)
                 {
                     Type = (int)NodeType.Selector
                 };
-                this.TreeViewModel.Add(addTreeNode, null);
+                this.ViewModel.Add(addTreeNode, null);
             }
             else
             {
                 if (this.listBox.SelectedItem != null)
                 {
                     var parentNode = this.listBox.SelectedItem as TreeNodeViewModel;
-                    var addTreeNode = new TreeNodeViewModel(this.TreeViewModel, parentNode)
+                    var addTreeNode = new TreeNodeViewModel(this.ViewModel, parentNode)
                     {
                         Type = (int)NodeType.Selector
                     };
-                    this.TreeViewModel.Add(addTreeNode, parentNode);
+                    this.ViewModel.Add(addTreeNode, parentNode);
                 }
             }
             this.listBox.SelectedItem = null;
@@ -195,7 +200,7 @@ namespace Tree
                 return;
             }
             var treeNodeViewModel = this.listBox.SelectedItem as TreeNodeViewModel;
-            this.TreeViewModel.Remove(treeNodeViewModel);
+            this.ViewModel.Remove(treeNodeViewModel);
             this.listBox.SelectedItem = null;
             e.Handled = true;
         }

+ 22 - 26
CSharp/App/Modules/Tree/TreeViewModel.cs

@@ -8,6 +8,8 @@ namespace Tree
     [Export(typeof (TreeViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
     public class TreeViewModel: BindableBase
     {
+        private readonly List<TreeNodeData> treeNodeDatas = new List<TreeNodeData>();
+
         private readonly ObservableCollection<TreeNodeViewModel> treeNodes =
                 new ObservableCollection<TreeNodeViewModel>();
 
@@ -21,6 +23,26 @@ namespace Tree
             }
         }
 
+        public int TreeId { get; set; }
+
+        public TreeViewModel(List<TreeNodeData> treeNodeDatas)
+        {
+            foreach (TreeNodeData treeNodeData in treeNodeDatas)
+            {
+                TreeNodeViewModel treeNodeViewModel = new TreeNodeViewModel(this, treeNodeData);       
+            }
+        }
+
+        public List<TreeNodeData> TreeNodeDatas
+        {
+            get
+            {
+                return this.treeNodeDatas;
+            }
+        }
+
+        public AllTreeViewModel AllTreeViewModel { get; set; }
+
         private TreeNodeViewModel Root
         {
             get
@@ -178,31 +200,5 @@ namespace Tree
                 this.RecursionAdd(child);
             }
         }
-
-        /// <summary>
-        /// 序列化保存
-        /// </summary>
-        public void Save(string filePath)
-        {
-            //this.RecursionSave(treeNodeDataArray, this.Root);
-            //byte[] bytes = ProtobufHelper.ToBytes(treeNodeDataArray);
-            //using (Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
-            //{
-            //    stream.Write(bytes, 0, bytes.Length);
-            //}
-        }
-
-        private void RecursionSave(AllTreeData allTreeData, TreeNodeViewModel node)
-        {
-            //if (node == null)
-            //{
-            //    return;
-            //}
-            //allTreeData.Add(node.TreeNodeData);
-            //foreach (TreeNodeViewModel childNode in node.Children)
-            //{
-            //    this.RecursionSave(allTreeData, childNode);
-            //}
-        }
     }
 }

+ 2 - 0
CSharp/CSharp.sln.DotSettings

@@ -11,8 +11,10 @@
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ImplicitlyCapturedClosure/@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>
+	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBePartlyConvertedToQuery/@EntryIndexedValue">DO_NOT_SHOW</s:String>
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">DO_NOT_SHOW</s:String>
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantAssignment/@EntryIndexedValue">DO_NOT_SHOW</s:String>
+	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SpecifyACultureInStringConversionExplicitly/@EntryIndexedValue">DO_NOT_SHOW</s:String>
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestUseVarKeywordEverywhere/@EntryIndexedValue">DO_NOT_SHOW</s:String>
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestUseVarKeywordEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
 	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedAutoPropertyAccessor_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>