tanghai 13 лет назад
Родитель
Сommit
691332f206

+ 3 - 3
CSharp/App/Editor/Shell.xaml

@@ -4,12 +4,12 @@
 		WindowStartupLocation="CenterScreen">
 	<Grid>
 		<TabControl>
-			<TabItem Height="25" Width="80" Header="行为树">
-				<ContentControl Name="treeCanvas" prism:RegionManager.RegionName="TreeCanvasRegion" />
-			</TabItem>
 			<TabItem Height="25" Width="80" Header="机器人">
 				<ContentControl Name="robot" prism:RegionManager.RegionName="RobotRegion" />
 			</TabItem>
+			<TabItem Height="25" Width="80" Header="行为树">
+				<ContentControl Name="treeCanvas" prism:RegionManager.RegionName="TreeCanvasRegion" />
+			</TabItem>
             <TabItem Height="25" Width="80" Header="外挂">
                 <ContentControl Name="waigua" prism:RegionManager.RegionName="WaiGuaRegion" />
             </TabItem>

+ 7 - 3
CSharp/App/Modules/BehaviorTree/BehaviorTreeView.xaml

@@ -2,8 +2,12 @@
 		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+		xmlns:BehaviorTree="clr-namespace:Modules.BehaviorTree" 
 		x:Class="Modules.BehaviorTree.BehaviorTreeView"
-		mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="800">
+		mc:Ignorable="d" 
+		d:DesignHeight="600" 
+		d:DesignWidth="800" 
+		d:DataContext="{d:DesignInstance BehaviorTree:BehaviorTreeViewModel}">
 	<UserControl.Resources>
 		<LinearGradientBrush x:Key="treeNodeFillBrush" StartPoint="0,0" EndPoint="0,1">
 			<GradientStop Color="White" Offset="0" />
@@ -26,7 +30,7 @@
 		</ContextMenu>
 	</UserControl.ContextMenu>
 	<Grid>
-		<ListBox Name="listBox" SelectionMode="Single" ItemsSource="{Binding TreeNodes}" x:FieldModifier="private">
+		<ListBox Name="listBox" SelectionMode="Single" ItemsSource="{Binding TreeNodes}">
 			<ListBox.Resources>
 				<Style TargetType="{x:Type ListBoxItem}">
 					<Setter Property="Canvas.Left" Value="{Binding X}" />
@@ -39,7 +43,7 @@
 				</ItemsPanelTemplate>
 			</ListBox.ItemsPanel>
 			<ListBox.ItemTemplate>
-				<DataTemplate>
+				<DataTemplate DataType="BehaviorTree:TreeNodeViewModel">
 					<Canvas MouseDown="ListBoxItem_MouseDown" MouseUp="ListBoxItem_MouseUp" MouseMove="ListBoxItem_MouseMove">
 						<Rectangle Name="rectNode" Width="{Binding Width}" Height="{Binding Height}" Cursor="Hand" StrokeThickness="4"
 								RadiusX="4" RadiusY="4" Stroke="{StaticResource treeNodeBorderBrush}" Fill="{StaticResource treeNodeFillBrush}"/>

+ 9 - 4
CSharp/App/Modules/Robot/RobotView.xaml

@@ -5,11 +5,16 @@
 		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Robot="clr-namespace:Modules.Robot"
 		mc:Ignorable="d" 
 		d:DesignHeight="600" d:DesignWidth="800" d:DataContext="{d:DesignInstance Robot:RobotViewModel}">
-	<Grid Height="597" Margin="1,1,1,4">
+	<Grid>
 		<StackPanel>
-			<Button Name="btnStart" Content="开始" Width="80" Height="25" Click="btnStart_Click" />
-			<TextBox Name="tbLog" Text="{Binding LogText, Mode=OneWay}" Height="700"
-					VerticalScrollBarVisibility="Visible" TextChanged="tbLog_TextChanged" />
+			<StackPanel Orientation="Horizontal" >
+				<Label Content="loginIp: "></Label>
+				<TextBox Width="120" Text="{Binding LoginIp}" />
+				<Label Content="loginPort: "></Label>
+				<TextBox Width="40" Text="{Binding LoginPort}" />
+				<Button Name="btnStart" Content="Login" Width="80" Height="25" Click="btnLogin_Click" />
+				<TextBlock></TextBlock>
+			</StackPanel>
 		</StackPanel>
 	</Grid>
 </UserControl>

+ 2 - 7
CSharp/App/Modules/Robot/RobotView.xaml.cs

@@ -29,14 +29,9 @@ namespace Modules.Robot
 			}
 		}
 
-		private void btnStart_Click(object sender, RoutedEventArgs e)
+		private void btnLogin_Click(object sender, RoutedEventArgs e)
 		{
-			this.ViewModel.Start();
-		}
-
-		private void tbLog_TextChanged(object sender, TextChangedEventArgs e)
-		{
-			this.tbLog.ScrollToEnd();
+			this.ViewModel.Login();
 		}
 	}
 }

+ 28 - 18
CSharp/App/Modules/Robot/RobotViewModel.cs

@@ -13,28 +13,46 @@ using Robot.Protos;
 namespace Modules.Robot
 {
 	[Export(contractType: typeof (RobotViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
-	internal class RobotViewModel: NotificationObject, IDisposable
+	internal sealed class RobotViewModel: NotificationObject, IDisposable
 	{
 		private readonly ClientHost clientHost;
-		private string logText = "";
+		private string loginIp;
+		private ushort loginPort;
 
 		private readonly DispatcherTimer timer = new DispatcherTimer(DispatcherPriority.Normal)
 		{ Interval = new TimeSpan(0, 0, 0, 0, 50) };
 
-		public string LogText
+		public string LoginIp
 		{
 			get
 			{
-				return this.logText;
+				return this.loginIp;
 			}
 			set
 			{
-				if (this.logText == value)
+				if (this.loginIp == value)
 				{
 					return;
 				}
-				this.logText = value;
-				this.RaisePropertyChanged("LogText");
+				this.loginIp = value;
+				this.RaisePropertyChanged("LoginIp");
+			}
+		}
+
+		public ushort LoginPort
+		{
+			get
+			{
+				return this.loginPort;
+			}
+			set
+			{
+				if (this.loginPort == value)
+				{
+					return;
+				}
+				this.loginPort = value;
+				this.RaisePropertyChanged("LoginPort");
 			}
 		}
 
@@ -58,16 +76,16 @@ namespace Modules.Robot
 			GC.SuppressFinalize(this);
 		}
 
-		protected virtual void Disposing(bool disposing)
+		private void Disposing(bool disposing)
 		{	
 			this.clientHost.Dispose();
 		}
 
-		public async void StartClient()
+		public async void Login()
 		{
 			try
 			{
-				var address = new Address { HostName = "192.168.10.246", Port = 8900 };
+				var address = new Address { HostName = this.LoginIp, Port = this.LoginPort };
 				using (Peer peer = await this.clientHost.ConnectAsync(address))
 				{
 					using (Packet packet = await peer.ReceiveAsync())
@@ -86,13 +104,5 @@ namespace Modules.Robot
 				Logger.Debug(e.Message);
 			}
 		}
-
-		public void Start()
-		{
-			for (int i = 0; i < 1; ++i)
-			{
-				this.StartClient();
-			}
-		}
 	}
 }