Пример #1
0
bool ComponentGroup::AddComponent(ComponentPtr comp)
{
    PROFILE(ComponentGroup_AddComponent);
    //Check if the component have already added to component group or it's name or type are different for the component group.
    if(ContainsComponent(comp) || comp->Name() != name_ || comp->TypeName() != typeName_) 
        return false;
    components_.push_back(ComponentWeakPtr(comp));
    editor_->AddNewComponent(comp);
    return true;
}
Пример #2
0
ComponentItem::ComponentItem(const ComponentPtr &comp, EntityItem *parent) :
    QTreeWidgetItem(parent),
    parentItem(parent),
    ptr(comp),
    typeId(comp->TypeId()),
    typeName(comp->TypeName()),
    name(comp->Name())
{
    SetText(comp.get());
}
Пример #3
0
ComponentGroup::ComponentGroup(ComponentPtr component, ECComponentEditor *editor, bool isDynamic):
    editor_(editor),
    isDynamic_(isDynamic)
{
    assert(component);
    // No point to add component to editor cause it's already added in ECBrowser's AddNewComponentToGroup mehtod.
    if(component)
    {
        components_.push_back(ComponentWeakPtr(component));
        name_ = component->Name();
        typeName_ = component->TypeName();
    }
}
Пример #4
0
    void Entity::RemoveComponent(const ComponentPtr &component, AttributeChange::Type change)
    {
        if (component)
        {
            ComponentVector::iterator iter = std::find(components_.begin(), components_.end(), component);
            if (iter != components_.end())
            {
                QString componentTypeName = component->TypeName();
                componentTypeName.replace(0, 3, "");
                componentTypeName = componentTypeName.toLower();
                    
                if(property(componentTypeName.toStdString().c_str()).isValid())
                {
                    QObject *obj = property(componentTypeName.toStdString().c_str()).value<QObject*>();
                    //Make sure that QObject is inherited by the IComponent.
                    if (obj && dynamic_cast<IComponent*>(obj))
                    {
                        //Make sure that name is matching incase there are many of same type of components in entity.
                        if (dynamic_cast<IComponent*>(obj)->Name() == component->Name())
                            setProperty(componentTypeName.toStdString().c_str(), QVariant());
                    }
                }
                

                if (change != AttributeChange::Disconnected)
                    emit ComponentRemoved((*iter).get(), change == AttributeChange::Default ? component->GetUpdateMode() : change);
                if (scene_)
                    scene_->EmitComponentRemoved(this, (*iter).get(), change);

                (*iter)->SetParentEntity(0);
                components_.erase(iter);
            }
            else
            {
                LogWarning("Failed to remove component: " + component->TypeName() + " from entity: " + QString::number(GetId()));
            }
        }
    }
Пример #5
0
/// @todo made some major changes to this function - ensure that everything is working right.
bool ComponentGroup::IsSameComponent(ComponentPtr component) const
{
    assert(component);
    if(!IsValid())
        return false;

    PROFILE(ComponentGroup_IsSameComponent);
    if(component->TypeName() != typeName_ || component->Name() != name_)
        return false;

    // If component type is dynamic component we need to compere their attributes aswell. To ensure
    // that they are holding exactly the same attributes.
    if(isDynamic_)
    {
        EC_DynamicComponent *thisComponent = dynamic_cast<EC_DynamicComponent*>(components_[0].lock().get());
        EC_DynamicComponent *compareComponent = dynamic_cast<EC_DynamicComponent*>(component.get());
        if(!compareComponent || !thisComponent)
            return false;

        if(!thisComponent->ContainSameAttributes(*compareComponent))
            return false;
    }
    return true;
}
Пример #6
0
void Entity::RemoveComponent(const ComponentPtr &component, AttributeChange::Type change)
{
    if (component)
    {
        for(ComponentMap::Iterator it = components_.Begin(); it != components_.End(); ++it)
            if (it->second_ == component)
            {
                RemoveComponent(it, change);
                return;
            }

        LogWarning("Entity::RemoveComponent: Failed to find " + component->TypeName() + " \"" + component->Name() + "\" from " + ToString() + ".");
    }
}