Add add component button
This commit is contained in:
parent
a80495b3dd
commit
a2893303ae
2 changed files with 33 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
|
||||
struct Context;
|
||||
struct InfoComponent;
|
||||
|
@ -24,6 +25,8 @@ private:
|
|||
|
||||
QVBoxLayout* layout = nullptr;
|
||||
|
||||
QPushButton* addComponentButton;
|
||||
|
||||
QList<QWidget*> sections;
|
||||
|
||||
Context& context;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QComboBox>
|
||||
#include <QMenu>
|
||||
|
||||
#include "context.h"
|
||||
#include "ecs.h"
|
||||
|
@ -20,11 +21,38 @@ Properties::Properties(Context& context, QWidget* parent) : QWidget(parent), con
|
|||
layout->setAlignment(Qt::AlignTop);
|
||||
layout->setSpacing(0);
|
||||
|
||||
QMenu* addComponentMenu = new QMenu();
|
||||
|
||||
QAction* addMeshComponent = new QAction("Mesh");
|
||||
connect(addMeshComponent, &QAction::triggered, [&context] {
|
||||
const auto& entity = context.selectedEntities[0];
|
||||
|
||||
ECS::addComponent<MeshComponent>(entity);
|
||||
|
||||
emit context.entitiesChanged();
|
||||
});
|
||||
addComponentMenu->addAction(addMeshComponent);
|
||||
|
||||
QAction* addLightComponent = new QAction("Light");
|
||||
connect(addLightComponent, &QAction::triggered, [&context] {
|
||||
const auto& entity = context.selectedEntities[0];
|
||||
|
||||
ECS::addComponent<LightComponent>(entity);
|
||||
|
||||
emit context.entitiesChanged();
|
||||
});
|
||||
addComponentMenu->addAction(addLightComponent);
|
||||
|
||||
addComponentButton = new QPushButton("Add Component...");
|
||||
addComponentButton->setMenu(addComponentMenu);
|
||||
layout->addWidget(addComponentButton);
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
rebuild();
|
||||
|
||||
connect(&context, &Context::selectionChanged, this, &Properties::rebuild);
|
||||
connect(&context, &Context::entitiesChanged, this, &Properties::rebuild);
|
||||
}
|
||||
|
||||
void Properties::rebuild() {
|
||||
|
@ -35,6 +63,8 @@ void Properties::rebuild() {
|
|||
|
||||
sections.clear();
|
||||
|
||||
addComponentButton->setEnabled(context.selectedEntities.size() != 0);
|
||||
|
||||
if(context.selectedEntities.size() == 0)
|
||||
return;
|
||||
|
||||
|
|
Reference in a new issue