Sfoglia il codice sorgente

BehaviorNodeIf改成BehaviorNode,因为它不是纯接口

tanghai 14 anni fa
parent
commit
a581ce08b7

+ 0 - 1
CSharp/GameEditor/App.xaml

@@ -3,6 +3,5 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              StartupUri="MainWindow.xaml">
 	<Application.Resources>
-
 	</Application.Resources>
 </Application>

+ 38 - 0
CSharp/GameEditor/BehaviorNode.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace GameEditor
+{
+	class BehaviorNode
+	{
+		private int type;
+
+		private List<int> args;
+
+		public int Type
+		{
+			get 
+			{
+				return type; 
+			}
+			set
+			{
+				type = value;
+			}
+		}
+
+		public List<int> Args
+		{
+			get
+			{
+				return args;
+			}
+			set
+			{
+				args = value;
+			}
+		}
+	}
+}

+ 1 - 0
CSharp/GameEditor/GameEditor.csproj

@@ -63,6 +63,7 @@
       <DependentUpon>App.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="BehaviorNode.cs" />
     <Compile Include="MainWindow.xaml.cs">
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>

+ 25 - 5
CSharp/GameEditor/MainWindow.xaml

@@ -2,16 +2,36 @@
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         Title="MainWindow" Height="800" Width="1280">
-	<StackPanel Name="stackPanel1">
-		<Menu Height="23" Name="menu1" />
-		<Grid Name="grid1" Height="738" Width="Auto">
+	
+	<Window.CommandBindings>
+		<CommandBinding Command="ApplicationCommands.New" CanExecute="NewCanExecute" Executed="OnNewNode" />
+		<CommandBinding Command="ApplicationCommands.Delete" CanExecute="DeleteCanExecute" Executed="OnDeleteNode" />
+	</Window.CommandBindings>
+	
+	<Window.Resources>
+		<ContextMenu x:Key="NodeMenu" Name="behaviorNodeMenu">
+			<MenuItem Header="New" Command="ApplicationCommands.New" />
+			<MenuItem Header="Delete" Command="ApplicationCommands.Delete" />
+		</ContextMenu>
+	</Window.Resources>
+	
+	<StackPanel>
+		<Menu Height="23" >
+			<MenuItem Header="_File">
+				<MenuItem Header="New" Command="ApplicationCommands.New" />
+				<MenuItem Header="Delete" Command="ApplicationCommands.Delete" />
+			</MenuItem>
+		</Menu>
+		<Grid Height="738" Width="Auto">
 			<Grid.ColumnDefinitions>
 				<ColumnDefinition Width="132*" />
 				<ColumnDefinition Width="Auto" />
 				<ColumnDefinition Width="1092*" />
 			</Grid.ColumnDefinitions>
-			<ListBox HorizontalAlignment="Stretch" Margin="0" Name="listBox1" VerticalAlignment="Stretch" />
-			<GridSplitter Grid.Column="1" HorizontalAlignment="Center" Margin="0" Name="gridSplitter1" VerticalAlignment="Stretch" Width="5" />
+			<GridSplitter Grid.Column="1" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Stretch" Width="5" />
+			<TreeView HorizontalAlignment="Stretch" Margin="0" Name="behaviorTreeView" 
+					VerticalAlignment="Stretch" MouseRightButtonUp="behaviorTreeView_MouseRightButtonUp" 
+					Padding="0" BorderThickness="0" ContextMenu="{StaticResource NodeMenu}"/>
 		</Grid>
 	</StackPanel>
 </Window>

+ 33 - 0
CSharp/GameEditor/MainWindow.xaml.cs

@@ -11,6 +11,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using System.Collections;
 
 namespace GameEditor
 {
@@ -19,9 +20,41 @@ namespace GameEditor
 	/// </summary>
 	public partial class MainWindow : Window
 	{
+		private Hashtable treeViewNodes = new Hashtable();
+
 		public MainWindow()
 		{
 			InitializeComponent();
 		}
+
+		private void behaviorTreeView_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
+		{
+			var item = e.Source as TreeViewItem;
+			if (item == null)
+			{
+				return;
+			}
+			item.ContextMenu.IsOpen = true;
+			e.Handled = true;
+		}
+
+		private void NewCanExecute(object sender, CanExecuteRoutedEventArgs e)
+		{
+			e.CanExecute = true;
+		}
+
+		private void OnNewNode(object sender, ExecutedRoutedEventArgs e)
+		{
+		}
+
+		private void DeleteCanExecute(object sender, CanExecuteRoutedEventArgs e)
+		{
+			e.CanExecute = true;
+		}
+
+		private void OnDeleteNode(object sender, ExecutedRoutedEventArgs e)
+		{
+
+		}
 	}
 }

+ 8 - 8
Cpp/Game/BehaviorTree/BehaviorNodeIf.h → Cpp/Game/BehaviorTree/BehaviorNode.h

@@ -1,5 +1,5 @@
-#ifndef BEHAVIORTREE_BEHAVIORNODEIF_H
-#define BEHAVIORTREE_BEHAVIORNODEIF_H
+#ifndef BEHAVIORTREE_BEHAVIORNODE_H
+#define BEHAVIORTREE_BEHAVIORNODE_H
 
 #include <string>
 #include "Base/Typedef.h"
@@ -9,17 +9,17 @@ namespace Egametang {
 class ContexIf;
 class BehaviorNodeConf;
 
-class BehaviorNodeIf
+class BehaviorNode
 {
 private:
 	int32 type;
 
 public:
-	BehaviorNodeIf(int32 type): type(type)
+	BehaviorNode(int32 type): type(type)
 	{
 	}
 
-	virtual ~BehaviorNodeIf()
+	virtual ~BehaviorNode()
 	{
 	}
 
@@ -28,7 +28,7 @@ public:
 		return type;
 	}
 
-	virtual void AddChildNode(BehaviorNodeIf *node)
+	virtual void AddChildNode(BehaviorNode *node)
 	{
 	}
 
@@ -40,9 +40,9 @@ public:
 class BehaviorNodeFactoryIf
 {
 public:
-	virtual BehaviorNodeIf* GetInstance(const BehaviorNodeConf& conf) = 0;
+	virtual BehaviorNode* GetInstance(const BehaviorNodeConf& conf) = 0;
 };
 
 } // namespace Egametang
 
-#endif // BEHAVIORTREE_BEHAVIORNODEIF_H
+#endif // BEHAVIORTREE_BEHAVIORNODE_H

+ 2 - 2
Cpp/Game/BehaviorTree/BehaviorTree.cc

@@ -22,14 +22,14 @@ BehaviorTree::BehaviorTree(NodeFactories& factories, const BehaviorTreeConf& tre
 
 void BehaviorTree::BuildTree(
 		NodeFactories& factories, const BehaviorNodeConf& node_conf,
-		BehaviorNodeIf*& node)
+		BehaviorNode*& node)
 {
 	int32 type = node_conf.type();
 	node = factories.GetInstance(node_conf);
 	for (int i = 0; i < node_conf.node_size(); ++i)
 	{
 		const BehaviorNodeConf& logic_node_conf = node_conf.node(i);
-		BehaviorNodeIf* logic_node = NULL;
+		BehaviorNode* logic_node = NULL;
 		BuildTree(factories, logic_node_conf, logic_node);
 		node->AddChildNode(logic_node);
 	}

+ 3 - 3
Cpp/Game/BehaviorTree/BehaviorTree.h

@@ -1,7 +1,7 @@
 #ifndef BEHAVIORTREE_BEHAVIORTREE_H
 #define BEHAVIORTREE_BEHAVIORTREE_H
 
-#include "BehaviorTree/BehaviorNodeIf.h"
+#include "BehaviorTree/BehaviorNode.h"
 
 namespace Egametang {
 
@@ -13,10 +13,10 @@ class BehaviorTree
 {
 private:
 	int type;
-	BehaviorNodeIf* node;
+	BehaviorNode* node;
 
 	void BuildTree(NodeFactories& factories, const BehaviorNodeConf& node_conf,
-			BehaviorNodeIf*& node);
+			BehaviorNode*& node);
 
 public:
 	BehaviorTree(NodeFactories& factories, const BehaviorTreeConf& tree_conf);

+ 2 - 2
Cpp/Game/BehaviorTree/BuffType.cc

@@ -6,7 +6,7 @@
 namespace Egametang {
 
 BuffType::BuffType(int32 type, int32 buff_type):
-		BehaviorNodeIf(type), buff_type(buff_type)
+		BehaviorNode(type), buff_type(buff_type)
 {
 }
 
@@ -31,7 +31,7 @@ BuffTypeFactory::~BuffTypeFactory()
 {
 }
 
-BehaviorNodeIf* BuffTypeFactory::GetInstance(const BehaviorNodeConf& conf)
+BehaviorNode* BuffTypeFactory::GetInstance(const BehaviorNodeConf& conf)
 {
 	return new BuffType(conf.type(), conf.args(0));
 }

+ 3 - 3
Cpp/Game/BehaviorTree/BuffType.h

@@ -1,7 +1,7 @@
 #ifndef BEHAVIORTREE_BUFFTYPE_H
 #define BEHAVIORTREE_BUFFTYPE_H
 
-#include "BehaviorTree/BehaviorNodeIf.h"
+#include "BehaviorTree/BehaviorNode.h"
 
 namespace Egametang {
 
@@ -10,7 +10,7 @@ class ContexIf;
 // 条件节点还可以预绑定一些配置参数,
 // 例如下面的buff_type字段由策划配置
 // 可配置成dot hot之类的, 由工厂类设置
-class BuffType: public BehaviorNodeIf
+class BuffType: public BehaviorNode
 {
 private:
 	int32 buff_type;
@@ -30,7 +30,7 @@ class BuffTypeFactory: public BehaviorNodeFactoryIf
 public:
 	virtual ~BuffTypeFactory();
 
-	virtual BehaviorNodeIf* GetInstance(const BehaviorNodeConf& conf);
+	virtual BehaviorNode* GetInstance(const BehaviorNodeConf& conf);
 };
 
 } // namespace Egametang

+ 2 - 2
Cpp/Game/BehaviorTree/ChangeHealth.cc

@@ -7,7 +7,7 @@
 namespace Egametang {
 
 ChangeHealth::ChangeHealth(int32 type, int32 unit, int32 value):
-		BehaviorNodeIf(type), unit(unit), value(value)
+		BehaviorNode(type), unit(unit), value(value)
 {
 }
 
@@ -41,7 +41,7 @@ std::string ChangeHealth::ToString()
 	return s;
 }
 
-BehaviorNodeIf* ChangeHealthFactory::GetInstance(const BehaviorNodeConf& conf)
+BehaviorNode* ChangeHealthFactory::GetInstance(const BehaviorNodeConf& conf)
 {
 	return new ChangeHealth(conf.type(), conf.args(0), conf.args(1));
 }

+ 3 - 3
Cpp/Game/BehaviorTree/ChangeHealth.h

@@ -2,11 +2,11 @@
 #define BEHAVIORTREE_CHANGEHEALTH_H
 
 #include "Base/Typedef.h"
-#include "BehaviorTree/BehaviorNodeIf.h"
+#include "BehaviorTree/BehaviorNode.h"
 
 namespace Egametang {
 
-class ChangeHealth: public BehaviorNodeIf
+class ChangeHealth: public BehaviorNode
 {
 private:
 	int32 unit;
@@ -25,7 +25,7 @@ public:
 class ChangeHealthFactory: public BehaviorNodeFactoryIf
 {
 public:
-	virtual BehaviorNodeIf* GetInstance(const BehaviorNodeConf& conf);
+	virtual BehaviorNode* GetInstance(const BehaviorNodeConf& conf);
 };
 
 } // namespace Egametang

+ 2 - 2
Cpp/Game/BehaviorTree/GameEvents.cc

@@ -14,9 +14,9 @@ GameEvents::GameEvents(NodeFactories& factories):
 
 GameEvents::~GameEvents()
 {
-	foreach(std::list<BehaviorTree*> list, events)
+	foreach (std::list<BehaviorTree*> list, events)
 	{
-		foreach(BehaviorTree* tree, list)
+		foreach (BehaviorTree* tree, list)
 		{
 			delete tree;
 		}

+ 1 - 1
Cpp/Game/BehaviorTree/NodeFactories.cc

@@ -35,7 +35,7 @@ NodeFactories::~NodeFactories()
 	}
 }
 
-BehaviorNodeIf* NodeFactories::GetInstance(const BehaviorNodeConf& conf)
+BehaviorNode* NodeFactories::GetInstance(const BehaviorNodeConf& conf)
 {
 	int32 type = conf.type();
 	return factories[type]->GetInstance(conf);

+ 2 - 2
Cpp/Game/BehaviorTree/NodeFactories.h

@@ -2,7 +2,7 @@
 #define BEHAVIORTREE_NODEFACTORIES_H
 
 #include <vector>
-#include "BehaviorTree/BehaviorNodeIf.h"
+#include "BehaviorTree/BehaviorNode.h"
 
 namespace Egametang {
 
@@ -16,7 +16,7 @@ public:
 
 	virtual ~NodeFactories();
 
-	virtual BehaviorNodeIf* GetInstance(const BehaviorNodeConf& conf);
+	virtual BehaviorNode* GetInstance(const BehaviorNodeConf& conf);
 };
 
 } // namespace Egametang

+ 3 - 3
Cpp/Game/BehaviorTree/NotNode.cc

@@ -4,7 +4,7 @@
 
 namespace Egametang {
 
-NotNode::NotNode(int32 type): BehaviorNodeIf(type), node(NULL)
+NotNode::NotNode(int32 type): BehaviorNode(type), node(NULL)
 {
 }
 
@@ -18,7 +18,7 @@ bool NotNode::Run(ContexIf* contex)
 	return !node->Run(contex);
 }
 
-void NotNode::AddChildNode(BehaviorNodeIf *node)
+void NotNode::AddChildNode(BehaviorNode *node)
 {
 	this->node = node;
 }
@@ -31,7 +31,7 @@ std::string NotNode::ToString()
 	return s;
 }
 
-BehaviorNodeIf* NotNodeFactory::GetInstance(const BehaviorNodeConf& conf)
+BehaviorNode* NotNodeFactory::GetInstance(const BehaviorNodeConf& conf)
 {
 	return new NotNode(conf.type());
 }

+ 5 - 5
Cpp/Game/BehaviorTree/NotNode.h

@@ -1,14 +1,14 @@
 #ifndef BEHAVIORTREE_NOTNODE_H
 #define BEHAVIORTREE_NOTNODE_H
 
-#include "BehaviorTree/BehaviorNodeIf.h"
+#include "BehaviorTree/BehaviorNode.h"
 
 namespace Egametang {
 
-class NotNode: public BehaviorNodeIf
+class NotNode: public BehaviorNode
 {
 private:
-	BehaviorNodeIf* node;
+	BehaviorNode* node;
 
 public:
 	NotNode(int32 type);
@@ -17,7 +17,7 @@ public:
 
 	virtual bool Run(ContexIf* contex);
 
-	virtual void AddChildNode(BehaviorNodeIf *node);
+	virtual void AddChildNode(BehaviorNode *node);
 
 	virtual std::string ToString();
 };
@@ -25,7 +25,7 @@ public:
 class NotNodeFactory: public BehaviorNodeFactoryIf
 {
 public:
-	virtual BehaviorNodeIf* GetInstance(const BehaviorNodeConf& conf);
+	virtual BehaviorNode* GetInstance(const BehaviorNodeConf& conf);
 };
 
 } // namespace Egametang

+ 6 - 6
Cpp/Game/BehaviorTree/SelectorNode.cc

@@ -5,13 +5,13 @@
 
 namespace Egametang {
 
-SelectorNode::SelectorNode(int32 type): BehaviorNodeIf(type)
+SelectorNode::SelectorNode(int32 type): BehaviorNode(type)
 {
 }
 
 SelectorNode::~SelectorNode()
 {
-	foreach(BehaviorNodeIf* node, nodes)
+	foreach (BehaviorNode* node, nodes)
 	{
 		delete node;
 	}
@@ -19,7 +19,7 @@ SelectorNode::~SelectorNode()
 
 bool SelectorNode::Run(ContexIf* contex)
 {
-	foreach(BehaviorNodeIf* node, nodes)
+	foreach (BehaviorNode* node, nodes)
 	{
 		if (node->Run(contex))
 		{
@@ -29,7 +29,7 @@ bool SelectorNode::Run(ContexIf* contex)
 	return false;
 }
 
-void SelectorNode::AddChildNode(BehaviorNodeIf *node)
+void SelectorNode::AddChildNode(BehaviorNode *node)
 {
 	nodes.push_back(node);
 }
@@ -38,14 +38,14 @@ std::string SelectorNode::ToString()
 {
 	std::string s;
 	s += "SelectorNode: \n";
-	foreach(BehaviorNodeIf* node, nodes)
+	foreach (BehaviorNode* node, nodes)
 	{
 		s += "    " + node->ToString() + "\n";
 	}
 	return s;
 }
 
-BehaviorNodeIf* SelectorNodeFactory::GetInstance(const BehaviorNodeConf& conf)
+BehaviorNode* SelectorNodeFactory::GetInstance(const BehaviorNodeConf& conf)
 {
 	return new SelectorNode(conf.type());
 }

+ 5 - 5
Cpp/Game/BehaviorTree/SelectorNode.h

@@ -2,14 +2,14 @@
 #define BEHAVIORTREE_SELECTORNODE_H
 
 #include <list>
-#include "BehaviorTree/BehaviorNodeIf.h"
+#include "BehaviorTree/BehaviorNode.h"
 
 namespace Egametang {
 
-class SelectorNode: public BehaviorNodeIf
+class SelectorNode: public BehaviorNode
 {
 private:
-	std::list<BehaviorNodeIf*> nodes;
+	std::list<BehaviorNode*> nodes;
 
 public:
 	SelectorNode(int32 type);
@@ -18,7 +18,7 @@ public:
 
 	virtual bool Run(ContexIf* contex);
 
-	virtual void AddChildNode(BehaviorNodeIf *node);
+	virtual void AddChildNode(BehaviorNode *node);
 
 	virtual std::string ToString();
 };
@@ -26,7 +26,7 @@ public:
 class SelectorNodeFactory: public BehaviorNodeFactoryIf
 {
 public:
-	virtual BehaviorNodeIf* GetInstance(const BehaviorNodeConf& conf);
+	virtual BehaviorNode* GetInstance(const BehaviorNodeConf& conf);
 };
 
 } // namespace Egametang

+ 6 - 6
Cpp/Game/BehaviorTree/SequenceNode.cc

@@ -6,13 +6,13 @@
 
 namespace Egametang {
 
-SequenceNode::SequenceNode(int32 type): BehaviorNodeIf(type)
+SequenceNode::SequenceNode(int32 type): BehaviorNode(type)
 {
 }
 
 SequenceNode::~SequenceNode()
 {
-	foreach(BehaviorNodeIf* node, nodes)
+	foreach (BehaviorNode* node, nodes)
 	{
 		delete node;
 	}
@@ -20,7 +20,7 @@ SequenceNode::~SequenceNode()
 
 bool SequenceNode::Run(ContexIf* contex)
 {
-	foreach(BehaviorNodeIf* node, nodes)
+	foreach (BehaviorNode* node, nodes)
 	{
 		if (!node->Run(contex))
 		{
@@ -30,7 +30,7 @@ bool SequenceNode::Run(ContexIf* contex)
 	return true;
 }
 
-void SequenceNode::AddChildNode(BehaviorNodeIf *node)
+void SequenceNode::AddChildNode(BehaviorNode *node)
 {
 	nodes.push_back(node);
 }
@@ -39,14 +39,14 @@ std::string SequenceNode::ToString()
 {
 	std::string s;
 	s += "SequenceNode: \n";
-	foreach(BehaviorNodeIf* node, nodes)
+	foreach (BehaviorNode* node, nodes)
 	{
 		s += "    " + node->ToString() + "\n";
 	}
 	return s;
 }
 
-BehaviorNodeIf* SequenceNodeFactory::GetInstance(const BehaviorNodeConf& conf)
+BehaviorNode* SequenceNodeFactory::GetInstance(const BehaviorNodeConf& conf)
 {
 	return new SequenceNode(conf.type());
 }

+ 5 - 5
Cpp/Game/BehaviorTree/SequenceNode.h

@@ -2,14 +2,14 @@
 #define BEHAVIORTREE_SEQUENCENODE_H
 
 #include <list>
-#include "BehaviorTree/BehaviorNodeIf.h"
+#include "BehaviorTree/BehaviorNode.h"
 
 namespace Egametang {
 
-class SequenceNode: public BehaviorNodeIf
+class SequenceNode: public BehaviorNode
 {
 private:
-	std::list<BehaviorNodeIf*> nodes;
+	std::list<BehaviorNode*> nodes;
 
 public:
 	SequenceNode(int32 type);
@@ -18,7 +18,7 @@ public:
 
 	virtual bool Run(ContexIf* contex);
 
-	virtual void AddChildNode(BehaviorNodeIf *node);
+	virtual void AddChildNode(BehaviorNode *node);
 
 	virtual std::string ToString();
 };
@@ -26,7 +26,7 @@ public:
 class SequenceNodeFactory: public BehaviorNodeFactoryIf
 {
 public:
-	virtual BehaviorNodeIf* GetInstance(const BehaviorNodeConf& conf);
+	virtual BehaviorNode* GetInstance(const BehaviorNodeConf& conf);
 };
 
 } // namespace Egametang

+ 2 - 2
Cpp/Platform/Python/PythonInterpreter.cc

@@ -30,7 +30,7 @@ bool PythonInterpreter::GetExecString(const std::string& main_fun, std::string&
 		LOG(WARNING) << "no python path";
 		return false;
 	}
-	foreach(std::string path, python_paths)
+	foreach (std::string path, python_paths)
 	{
 		exec_string += boost::str(boost::format("sys.path.append('%1%')\n") % path);
 	}
@@ -40,7 +40,7 @@ bool PythonInterpreter::GetExecString(const std::string& main_fun, std::string&
 		LOG(WARNING) << "no python module";
 		return false;
 	}
-	foreach(std::string module, python_modules)
+	foreach (std::string module, python_modules)
 	{
 		exec_string += boost::str(boost::format("import %1%\n") % module);
 	}