Example #1
0
void AvatarEditor::RebuildEditView()
{
    if (!avatar_widget_)
        return;

    // Activate/deactivate export button based on whether export currently supported
    QPushButton *button = avatar_widget_->findChild<QPushButton *>("but_export");
    if (button)
        button->setEnabled(rexlogicmodule_->GetAvatarHandler()->AvatarExportSupported());

    QWidget* mat_panel = avatar_widget_->findChild<QWidget *>("panel_materials");
    QWidget* attachment_panel = avatar_widget_->findChild<QWidget *>("panel_attachments");
    if (!mat_panel || !attachment_panel)
        return;

    Scene::EntityPtr entity = rexlogicmodule_->GetAvatarHandler()->GetUserAvatar();
    if (!entity)
        return;
    EC_AvatarAppearance* appearance = entity->GetComponent<EC_AvatarAppearance>().get();
    if (!appearance)
        return;

    int width = 308-10;
    int tab_width = 302-10;
    int itemheight = 20;

    // Materials
    ClearPanel(mat_panel);
    const AvatarMaterialVector& materials = appearance->GetMaterials();
    mat_panel->resize(width, itemheight * (materials.size() + 1));

    for (uint y = 0; y < materials.size(); ++y)
    {
        QPushButton* button = new QPushButton("Change", mat_panel);
        button->setObjectName(QString::fromStdString(ToString<int>(y))); // Material index
        button->resize(50, 20);
        button->move(width - 50, y*itemheight);
        button->show();

        QObject::connect(button, SIGNAL(clicked()), this, SLOT(ChangeTexture()));
        // If there's a texture name, use it, because it is probably more understandable than material name
        std::string texname = materials[y].asset_.name_;
        if (materials[y].textures_.size())
            texname = materials[y].textures_[0].name_;

        QLabel* label = new QLabel(QString::fromStdString(texname), mat_panel);
        label->resize(200,20);
        label->move(0, y*itemheight);
        label->show();
    }

    // Attachments
    ClearPanel(attachment_panel);
    const AvatarAttachmentVector& attachments = appearance->GetAttachments();
    attachment_panel->resize(width, itemheight * (attachments.size() + 1));

    for (uint y = 0; y < attachments.size(); ++y)
    {
        QPushButton* button = new QPushButton("Remove", attachment_panel);
        button->setObjectName(QString::fromStdString(ToString<int>(y))); // Attachment index
        button->resize(50, 20);
        button->move(width - 50, y*itemheight);
        button->show();

        QObject::connect(button, SIGNAL(clicked()), this, SLOT(RemoveAttachment()));

        std::string attachment_name = attachments[y].name_;
        // Strip away .xml from the attachment name for slightly nicer display
        std::size_t pos = attachment_name.find(".xml");
        if (pos != std::string::npos)
            attachment_name = attachment_name.substr(0, pos);

        QLabel* label = new QLabel(QString::fromStdString(attachment_name), attachment_panel);
        label->resize(200,20);
        label->move(0, y*itemheight);
        label->show();
    }

    // Modifiers
    QTabWidget* tabs = avatar_widget_->findChild<QTabWidget *>("tab_appearance");
    if (!tabs)
        return;
    for (;;)
    {
        QWidget* tab = tabs->widget(0);
        if (!tab)
            break;
        tabs->removeTab(0);
        delete tab;
    }

    const MasterModifierVector& master_modifiers = appearance->GetMasterModifiers();
    // If no master modifiers, show the individual morph/bone controls
    if (!master_modifiers.size())
    {
        QWidget* morph_panel = GetOrCreateTabScrollArea(tabs, "Morphs");
        QWidget* bone_panel = GetOrCreateTabScrollArea(tabs, "Bones");
        if (!morph_panel || !bone_panel)
            return;

        const BoneModifierSetVector& bone_modifiers = appearance->GetBoneModifiers();
        const MorphModifierVector& morph_modifiers = appearance->GetMorphModifiers();
        morph_panel->resize(tab_width, itemheight * (morph_modifiers.size() + 1));
        bone_panel->resize(tab_width, itemheight * (bone_modifiers.size() + 1));

        for (uint i = 0; i < bone_modifiers.size(); ++i)
        {
            QScrollBar* slider = new QScrollBar(Qt::Horizontal, bone_panel);
            slider->setObjectName(QString::fromStdString(bone_modifiers[i].name_));
            slider->setMinimum(0);
            slider->setMaximum(100);
            slider->setPageStep(10);
            slider->setValue(bone_modifiers[i].value_ * 100.0f);
            slider->resize(150, 20);
            slider->move(tab_width - 150, i * itemheight);
            slider->show();

            QObject::connect(slider, SIGNAL(valueChanged(int)), this, SLOT(BoneModifierValueChanged(int)));

            QLabel* label = new QLabel(QString::fromStdString(bone_modifiers[i].name_), bone_panel);
            label->resize(100,20);
            label->move(0, i * itemheight);
            label->show();
        }

        for (uint i = 0; i < morph_modifiers.size(); ++i)
        {
            QScrollBar* slider = new QScrollBar(Qt::Horizontal, morph_panel);
            slider->setObjectName(QString::fromStdString(morph_modifiers[i].name_));
            slider->setMinimum(0);
            slider->setMaximum(100);
            slider->setPageStep(10);
            slider->setValue(morph_modifiers[i].value_ * 100.0f);
            slider->resize(150, 20);
            slider->move(tab_width - 150, i * itemheight);
            slider->show();

            QObject::connect(slider, SIGNAL(valueChanged(int)), this, SLOT(MorphModifierValueChanged(int)));

            QLabel* label = new QLabel(QString::fromStdString(morph_modifiers[i].name_), morph_panel);
            label->resize(100,20);
            label->move(0, i * itemheight);
            label->show();
        }
    }