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 <QWidget>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
struct Context;
|
struct Context;
|
||||||
struct InfoComponent;
|
struct InfoComponent;
|
||||||
|
@ -24,6 +25,8 @@ private:
|
||||||
|
|
||||||
QVBoxLayout* layout = nullptr;
|
QVBoxLayout* layout = nullptr;
|
||||||
|
|
||||||
|
QPushButton* addComponentButton;
|
||||||
|
|
||||||
QList<QWidget*> sections;
|
QList<QWidget*> sections;
|
||||||
|
|
||||||
Context& context;
|
Context& context;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "ecs.h"
|
#include "ecs.h"
|
||||||
|
@ -20,11 +21,38 @@ Properties::Properties(Context& context, QWidget* parent) : QWidget(parent), con
|
||||||
layout->setAlignment(Qt::AlignTop);
|
layout->setAlignment(Qt::AlignTop);
|
||||||
layout->setSpacing(0);
|
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);
|
setLayout(layout);
|
||||||
|
|
||||||
rebuild();
|
rebuild();
|
||||||
|
|
||||||
connect(&context, &Context::selectionChanged, this, &Properties::rebuild);
|
connect(&context, &Context::selectionChanged, this, &Properties::rebuild);
|
||||||
|
connect(&context, &Context::entitiesChanged, this, &Properties::rebuild);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Properties::rebuild() {
|
void Properties::rebuild() {
|
||||||
|
@ -35,6 +63,8 @@ void Properties::rebuild() {
|
||||||
|
|
||||||
sections.clear();
|
sections.clear();
|
||||||
|
|
||||||
|
addComponentButton->setEnabled(context.selectedEntities.size() != 0);
|
||||||
|
|
||||||
if(context.selectedEntities.size() == 0)
|
if(context.selectedEntities.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Reference in a new issue