修复组件能多次加载得问题
This commit is contained in:
parent
cdb7894e64
commit
37b0259579
@ -13,7 +13,7 @@ public:
|
||||
~AngleReflexComponent();
|
||||
|
||||
static std::string GetTypeName();
|
||||
std::string GetSelfTypeName() override {
|
||||
std::string GetSelfTypeName() const override {
|
||||
return AngleReflexComponent::GetTypeName();
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ public:
|
||||
~ChaffBombsComponent();
|
||||
|
||||
static std::string GetTypeName();
|
||||
std::string GetSelfTypeName() override {
|
||||
std::string GetSelfTypeName() const override {
|
||||
return ChaffBombsComponent::GetTypeName();
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,10 @@ std::vector<SceneComponent*> Component::GetChildren() const {
|
||||
return std::vector<SceneComponent*>();
|
||||
}
|
||||
|
||||
bool Component::HasComponent(const std::string& name) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Component::OnDestroy() {
|
||||
return true;
|
||||
}
|
||||
@ -94,7 +98,7 @@ std::string Component::GetTypeName() {
|
||||
return "Component";
|
||||
}
|
||||
|
||||
std::string Component::GetSelfTypeName() {
|
||||
std::string Component::GetSelfTypeName() const {
|
||||
return Component::GetTypeName();
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,10 @@ public:
|
||||
virtual bool OnDestroy();
|
||||
|
||||
static std::string GetTypeName();
|
||||
virtual std::string GetSelfTypeName();
|
||||
virtual std::string GetSelfTypeName() const;
|
||||
virtual void AttachEntity(class Entity* owner);
|
||||
virtual bool AttachTo(class SceneComponent* parent);
|
||||
virtual bool HasComponent(const std::string& name) const;
|
||||
class Entity* GetEntity() const {
|
||||
return owner_;
|
||||
}
|
||||
@ -36,6 +37,7 @@ public:
|
||||
return uuid_;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
void SetUUId(const QString& uuid) {
|
||||
uuid_ = uuid;
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
~ConeWaveComponent();
|
||||
|
||||
static std::string GetTypeName();
|
||||
std::string GetSelfTypeName() override {
|
||||
std::string GetSelfTypeName() const override {
|
||||
return ConeWaveComponent::GetTypeName();
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ public:
|
||||
~DashedLineComponent();
|
||||
|
||||
static std::string GetTypeName();
|
||||
std::string GetSelfTypeName() override {
|
||||
std::string GetSelfTypeName() const override {
|
||||
return DashedLineComponent::GetTypeName();
|
||||
}
|
||||
|
||||
|
@ -183,6 +183,13 @@ void Entity::SetParent(Entity* parent) {
|
||||
parent_->childer_.push_back(this);
|
||||
}
|
||||
|
||||
bool Entity::HasComponent(const std::string& name) const {
|
||||
if (nullptr == rootComponet_) {
|
||||
return false;
|
||||
}
|
||||
return rootComponet_->HasComponent(name);
|
||||
}
|
||||
|
||||
void Entity::SetVisible(bool v) {
|
||||
LOG_INFO("set visible: {}", v);
|
||||
if (nullptr == rootComponet_) {
|
||||
|
@ -56,6 +56,8 @@ public:
|
||||
return rootComponet_->GetComponent();
|
||||
}
|
||||
|
||||
bool HasComponent(const std::string& name) const;
|
||||
|
||||
void SetRootComponent(SceneComponent* root) {
|
||||
rootComponet_ = root;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ bool LabelComponent::SaveAttribute(tinyxml2::XMLElement* element) {
|
||||
return SceneComponent::SaveAttribute(element);
|
||||
}
|
||||
|
||||
std::string LabelComponent::GetSelfTypeName() {
|
||||
std::string LabelComponent::GetSelfTypeName() const {
|
||||
return LabelComponent::GetTypeName();
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
void AttachEntity(class Entity* owner) override;
|
||||
bool SetAttribute(const char* name, const char* value) override;
|
||||
bool SaveAttribute(tinyxml2::XMLElement* element) override;
|
||||
std::string GetSelfTypeName() override;
|
||||
std::string GetSelfTypeName() const override;
|
||||
|
||||
void Begin() override;
|
||||
void Update(double dt) override;
|
||||
|
@ -29,7 +29,7 @@ bool MeshComponent::SaveAttribute(tinyxml2::XMLElement* element) {
|
||||
return SceneComponent::SaveAttribute(element);
|
||||
}
|
||||
|
||||
std::string MeshComponent::GetSelfTypeName() {
|
||||
std::string MeshComponent::GetSelfTypeName() const {
|
||||
return MeshComponent::GetTypeName();
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ public:
|
||||
|
||||
bool SetAttribute(const char* name, const char* value) override;
|
||||
bool SaveAttribute(tinyxml2::XMLElement* element) override;
|
||||
std::string GetSelfTypeName() override;
|
||||
std::string GetSelfTypeName() const override;
|
||||
|
||||
bool LoadNode(const char* mesh);
|
||||
const std::string& GetMesh() const {
|
||||
|
@ -12,7 +12,7 @@ public:
|
||||
~PathComponent();
|
||||
|
||||
static std::string GetTypeName();
|
||||
std::string GetSelfTypeName() override {
|
||||
std::string GetSelfTypeName() const override {
|
||||
return PathComponent::GetTypeName();
|
||||
}
|
||||
|
||||
|
@ -262,6 +262,19 @@ void SceneComponent::AddToRender() {
|
||||
}
|
||||
}
|
||||
|
||||
bool SceneComponent::HasComponent(const std::string& name) const {
|
||||
if (GetSelfTypeName() == name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto& componet : children_) {
|
||||
if (componet->GetSelfTypeName() == name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SceneComponent::SetVisible(bool v) {
|
||||
visible_ = v;
|
||||
if (nullptr == mt_) {
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "osg/Vec3"
|
||||
#include "osg/MatrixTransform"
|
||||
#include "Entity.h"
|
||||
|
||||
class SceneComponent : public Component {
|
||||
Q_OBJECT
|
||||
@ -30,6 +31,7 @@ public:
|
||||
bool AttachTo(SceneComponent* parent) override;
|
||||
|
||||
virtual void AddToRender();
|
||||
virtual bool HasComponent(const std::string& name) const override;
|
||||
|
||||
SceneComponent* GetRootComponent() const;
|
||||
|
||||
|
@ -668,22 +668,22 @@
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="270"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="273"/>
|
||||
<source>Add Label Component</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="277"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="283"/>
|
||||
<source>Add Mesh Component</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="280"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="293"/>
|
||||
<source>Add Path Component</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="287"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="301"/>
|
||||
<source>Delete</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -258,33 +258,47 @@ void ModelTreeWidget::PopupEntityMenu(QContextMenuEvent* event, Entity* entity)
|
||||
);
|
||||
menu.addAction(releaseTrack);
|
||||
}
|
||||
} else {
|
||||
QAction* addEntiy = new QAction(tr("Track"), this);
|
||||
else {
|
||||
QAction* addEntiy = new QAction(tr("Track"), this);
|
||||
menu.addAction(addEntiy);
|
||||
connect(addEntiy, &QAction::triggered, [this, entity]() {
|
||||
OnTrackEntity(entity);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool hasLableComponent = entity->HasComponent("LabelComponent");
|
||||
if (!hasLableComponent) {
|
||||
QAction* addEntiy = new QAction(tr("Add Label Component"), this);
|
||||
menu.addAction(addEntiy);
|
||||
connect(addEntiy, &QAction::triggered, [this, entity]() {
|
||||
OnTrackEntity(entity);
|
||||
OnAddComponent("LabelComponent", entity);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
QAction* addEntiy = new QAction(tr("Add Label Component"), this);
|
||||
menu.addAction(addEntiy);
|
||||
connect(addEntiy, &QAction::triggered, [this, entity]() {
|
||||
OnAddComponent("LabelComponent", entity);
|
||||
}
|
||||
);
|
||||
bool hasMeshComponent = entity->HasComponent("MeshComponent");
|
||||
if (!hasMeshComponent) {
|
||||
QAction* addEntiy = new QAction(tr("Add Mesh Component"), this);
|
||||
menu.addAction(addEntiy);
|
||||
connect(addEntiy, &QAction::triggered, [this, entity]() {
|
||||
OnAddComponent("MeshComponent", entity);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
addEntiy = new QAction(tr("Add Mesh Component"), this);
|
||||
menu.addAction(addEntiy);
|
||||
bool hasPathComponent = entity->HasComponent("PathComponent");
|
||||
if (!hasPathComponent) {
|
||||
QAction* addEntiy = new QAction(tr("Add Path Component"), this);
|
||||
menu.addAction(addEntiy);
|
||||
connect(addEntiy, &QAction::triggered, [this, entity]() {
|
||||
OnAddComponent("PathComponent", entity);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
addEntiy = new QAction(tr("Add Path Component"), this);
|
||||
menu.addAction(addEntiy);
|
||||
connect(addEntiy, &QAction::triggered, [this, entity]() {
|
||||
OnAddComponent("PathComponent", entity);
|
||||
}
|
||||
);
|
||||
|
||||
addEntiy = new QAction(tr("Delete"), this);
|
||||
QAction* addEntiy = new QAction(tr("Delete"), this);
|
||||
menu.addAction(addEntiy);
|
||||
connect(addEntiy, &QAction::triggered, [this, entity]() {
|
||||
OnDeleteEntity(entity);
|
||||
|
Loading…
Reference in New Issue
Block a user