From d633d0130fd860f9c745172c452b1b015d3a6f2f Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Tue, 1 Jul 2025 00:45:32 +0800 Subject: [PATCH] update --- ComponentBasic/BehaviorPerform.cpp | 24 +++++- ComponentBasic/BehaviorPerform.h | 86 ++++++++++++------- ComponentBasic/ComponentBasic.vcxproj | 2 +- ComponentBasic/ComponentBasic.vcxproj.filters | 6 +- SimsWorld/BehaviorEditor.cpp | 19 ++++ SimsWorld/BehaviorEditor.h | 6 ++ 6 files changed, 103 insertions(+), 40 deletions(-) diff --git a/ComponentBasic/BehaviorPerform.cpp b/ComponentBasic/BehaviorPerform.cpp index 7cd7e39..abbb62f 100644 --- a/ComponentBasic/BehaviorPerform.cpp +++ b/ComponentBasic/BehaviorPerform.cpp @@ -52,8 +52,6 @@ QString BehaviorPerformPlugin::name() const #include MapKernal::MapKernal(std::shared_ptr ins) : _bind_loader(ins) { - for (auto key : ins->allType()) - registData(ins->makeDefault(key)); } QList MapKernal::compareTypes() const @@ -64,6 +62,7 @@ QList MapKernal::compareTypes() const void MapKernal::registCompare(std::shared_ptr ins) { _compare_types[ins->name()] = ins; + emit this->compareTypeListChanged(); } std::shared_ptr MapKernal::getCompare(const QString& name) @@ -76,6 +75,7 @@ std::shared_ptr MapKernal::getCompare(const QString& name) void MapKernal::registConvert(std::shared_ptr ins) { _convert_types[ins->name()] = ins; + emit this->convertTypeListChanged(); } QList MapKernal::convertTypes() const @@ -93,6 +93,7 @@ std::shared_ptr MapKernal::getConvert(const QString& name) void MapKernal::registExecute(std::shared_ptr ins) { _execute_types[ins->typeName()] = ins; + emit this->executeTypeListChanged(); } std::shared_ptr MapKernal::messageLoader() const @@ -100,6 +101,22 @@ std::shared_ptr MapKernal::messageLoader() const return this->_bind_loader; } +void MapKernal::initial() +{ + // 注册基础数据类型 + registData(std::make_shared()); + for (auto key : messageLoader()->allType()) + registData(messageLoader()->makeDefault(key)); + + // 注册可用节点类型 + registNode(std::make_shared()); + registNode(std::make_shared()); + registNode(std::make_shared()); + registNode(std::make_shared(this->shared_from_this())); + registNode(std::make_shared(this->shared_from_this())); + registNode(std::make_shared(this->shared_from_this())); +} + void MapKernal::registData(std::shared_ptr init) { if (_variable_types.contains(init->topicString())) @@ -741,7 +758,7 @@ QList> ExecuteNode::getForwards() const QString ExecuteNode::typeName() const { - return QString("执行节点<%1>(%2)").arg(delegateName()).arg(getID()); + return QString(u8"执行节点<%1>").arg(delegateName()); } QHash> ExecuteNode::inputList() const @@ -785,7 +802,6 @@ std::shared_ptr ExecuteNode::newDefault() const return std::make_shared(this->_bind_kernal); } -#include void ExecuteNode::recoveryFrom(const QJsonObject& obj) { QString delegate_name = ""; diff --git a/ComponentBasic/BehaviorPerform.h b/ComponentBasic/BehaviorPerform.h index e396cbe..cca540b 100644 --- a/ComponentBasic/BehaviorPerform.h +++ b/ComponentBasic/BehaviorPerform.h @@ -28,7 +28,10 @@ struct COMPONENTBASIC_EXPORT GeneralData : public TopicData { /// /// 行为树实例化节点 /// -class COMPONENTBASIC_EXPORT MapKernal : virtual public Serializable { +class COMPONENTBASIC_EXPORT MapKernal : + public QObject, virtual public Serializable, + public std::enable_shared_from_this { + Q_OBJECT private: /// /// 绑定载入器 @@ -58,6 +61,21 @@ private: /// QHash> _logicalnode_types; +signals: + /// + /// 比较器类型列表变更 + /// + void compareTypeListChanged(); + /// + /// 转换器类型列表变更 + /// + void convertTypeListChanged(); + /// + /// 执行节点类型列表变更 + /// + void executeTypeListChanged(); + + public: MapKernal(std::shared_ptr ins); virtual ~MapKernal() = default; @@ -68,6 +86,8 @@ public: /// std::shared_ptr messageLoader() const; + void initial(); + // 数据类型管理 ====================================================== /// /// 注册数据类型 @@ -84,7 +104,29 @@ public: /// /// /// - virtual std::shared_ptr getData(const QString &topic); + virtual std::shared_ptr getData(const QString& topic); + + + + + // 逻辑树类型管理 ==================================================== + /// + /// 注册逻辑节点 + /// + /// + virtual void registNode(std::shared_ptr ins); + /// + /// 执行器类型名称 + /// + /// + virtual QList nodeTypes() const; + /// + /// 获取指定类型的执行器节点 + /// + /// + /// + virtual std::shared_ptr getNode(const QString& name); + @@ -108,6 +150,7 @@ public: + // 转换器类型管理 ====================================================== /// /// 注册转换器 @@ -148,31 +191,10 @@ public: - - // 逻辑树类型管理 ==================================================== - /// - /// 注册逻辑节点 - /// - /// - virtual void registNode(std::shared_ptr ins); - /// - /// 执行器类型名称 - /// - /// - virtual QList nodeTypes() const; - /// - /// 获取指定类型的执行器节点 - /// - /// - /// - virtual std::shared_ptr getNode(const QString& name); - - - // 通过 Serializable 继承 std::shared_ptr newDefault() const override; - void recoveryFrom(const QJsonObject& obj) override{} - void saveTo(QJsonObject& obj) const override{} + void recoveryFrom(const QJsonObject& obj) override {} + void saveTo(QJsonObject& obj) const override {} }; /// @@ -219,7 +241,7 @@ public: /// 重置输入变量类型表 /// /// list{pair{类型名称,绑定输入变量名}} - void inputReset(const QList> &table); + void inputReset(const QList>& table); /// /// 输入变量 /// @@ -442,13 +464,13 @@ enum class IO_TYPE { class COMPONENTBASIC_EXPORT BehaviorMapNode : public LogicalNode { private: std::shared_ptr _bind_kernal; - QString _map_name = u8"未命名行为树"; + QString _map_name = u8"行为树节点"; /// /// 地图变量表 /// QHash>> _variables; - LogicalResult _state_value; + LogicalResult _state_value = LogicalResult::FAILURE; public: BehaviorMapNode(std::shared_ptr kernal); @@ -639,7 +661,7 @@ class COMPONENTBASIC_EXPORT ExecuteNode : public LogicalNode { private: std::shared_ptr _bind_kernal; std::shared_ptr _bind_delegate; - + public: ExecuteNode(std::shared_ptr kernal); @@ -669,18 +691,18 @@ public: /// 行为树组件 /// class COMPONENTBASIC_EXPORT BehaviorPerformPlugin : -public RespondRoute< + public RespondRoute< WsRespond, WsRespond, WsRespond, WsRespond>, -public RequestRoute<> + public RequestRoute<> { private: std::weak_ptr _bind_entity; public: - void mapReset(const QString &path); + void mapReset(const QString& path); // 通过 ProcList 继承 void execute(std::shared_ptr in, QList>& out) override; diff --git a/ComponentBasic/ComponentBasic.vcxproj b/ComponentBasic/ComponentBasic.vcxproj index 857fb75..79e73fa 100644 --- a/ComponentBasic/ComponentBasic.vcxproj +++ b/ComponentBasic/ComponentBasic.vcxproj @@ -108,7 +108,7 @@ - + diff --git a/ComponentBasic/ComponentBasic.vcxproj.filters b/ComponentBasic/ComponentBasic.vcxproj.filters index ee8baa6..026a9ba 100644 --- a/ComponentBasic/ComponentBasic.vcxproj.filters +++ b/ComponentBasic/ComponentBasic.vcxproj.filters @@ -41,9 +41,6 @@ Header Files - - Header Files - @@ -72,5 +69,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/SimsWorld/BehaviorEditor.cpp b/SimsWorld/BehaviorEditor.cpp index ecff5a4..099b7e0 100644 --- a/SimsWorld/BehaviorEditor.cpp +++ b/SimsWorld/BehaviorEditor.cpp @@ -187,14 +187,33 @@ BehaviorEditor::BehaviorEditor(QWidget* parent /*= nullptr*/) _logical_present(new BehaviorsPresent(this)), _logs_present(new QTextBrowser(this)) { + _glbal_loader = std::make_shared(); + _global_kernal = std::make_shared(_glbal_loader); + _global_kernal->initial(); + auto split_h = new QSplitter(Qt::Horizontal, this); this->setCentralWidget(split_h); split_h->addWidget(_type_view); _type_view->setModel(_type_model); + auto split_v = new QSplitter(Qt::Vertical, this); split_h->addWidget(split_v); split_v->addWidget(_logical_present); split_v->addWidget(_logs_present); + + nodeTypesViewInit(_type_model); +} + +#include +void BehaviorEditor::nodeTypesViewInit(QStandardItemModel* m) +{ + auto types = this->_global_kernal->nodeTypes(); + std::sort(types.begin(), types.end()); + for (auto type : types) { + auto row_item = new QStandardItem(type); + row_item->setEditable(false); + m->appendRow(row_item); + } } diff --git a/SimsWorld/BehaviorEditor.h b/SimsWorld/BehaviorEditor.h index 6e23f5f..01c27aa 100644 --- a/SimsWorld/BehaviorEditor.h +++ b/SimsWorld/BehaviorEditor.h @@ -90,6 +90,7 @@ public: #include #include #include +#include class BehaviorEditor : public QMainWindow { private: QListView *const _type_view; @@ -97,6 +98,11 @@ private: BehaviorsPresent *const _logical_present; QTextBrowser *const _logs_present; + std::shared_ptr _glbal_loader; + std::shared_ptr _global_kernal; + public: BehaviorEditor(QWidget *parent = nullptr); + + void nodeTypesViewInit(QStandardItemModel *m); }; \ No newline at end of file