Add entity menu
This commit is contained in:
parent
57b9648220
commit
a80495b3dd
3 changed files with 34 additions and 2 deletions
|
@ -15,4 +15,5 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void selectionChanged();
|
void selectionChanged();
|
||||||
|
void entitiesChanged();
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,9 +20,16 @@ Hierarchy::Hierarchy(Context& context, QWidget* parent) : QWidget(parent), conte
|
||||||
context.selectedEntities.clear();
|
context.selectedEntities.clear();
|
||||||
|
|
||||||
if(index.isValid()) {
|
if(index.isValid()) {
|
||||||
const auto entity = ECS::getWorldEntities(worldManager.getCurrentWorld())[index.row()];
|
const auto entities = ECS::getWorldEntities(worldManager.getCurrentWorld());
|
||||||
|
|
||||||
context.selectedEntities.push_back(entity);
|
QList<EntityID> filteredEntities;
|
||||||
|
for(auto entity : entities) {
|
||||||
|
const auto info = ECS::getComponent<InfoComponent>(entity);
|
||||||
|
if(info)
|
||||||
|
filteredEntities.push_back(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.selectedEntities.push_back(filteredEntities[index.row()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit context.selectionChanged();
|
emit context.selectionChanged();
|
||||||
|
@ -31,6 +38,8 @@ Hierarchy::Hierarchy(Context& context, QWidget* parent) : QWidget(parent), conte
|
||||||
listModel = new QStringListModel();
|
listModel = new QStringListModel();
|
||||||
listView->setModel(listModel);
|
listView->setModel(listModel);
|
||||||
|
|
||||||
|
connect(&context, &Context::entitiesChanged, this, &Hierarchy::rebuild);
|
||||||
|
|
||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "hierarchy.h"
|
#include "hierarchy.h"
|
||||||
#include "properties.h"
|
#include "properties.h"
|
||||||
|
#include "ecs.h"
|
||||||
|
#include "worldmanager.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(Context& context) : context(context) {
|
MainWindow::MainWindow(Context& context) : context(context) {
|
||||||
setWindowTitle("Level Editor");
|
setWindowTitle("Level Editor");
|
||||||
|
@ -82,6 +84,26 @@ MainWindow::MainWindow(Context& context) : context(context) {
|
||||||
editMenu->addAction(userPreferenes);
|
editMenu->addAction(userPreferenes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMenu* entityMenu = new QMenu("Entity");
|
||||||
|
mainMenuBar->addMenu(entityMenu);
|
||||||
|
|
||||||
|
// entity
|
||||||
|
{
|
||||||
|
QAction* createEntity = new QAction("Create");
|
||||||
|
connect(createEntity, &QAction::triggered, [&context] {
|
||||||
|
EntityID entity = ECS::createEntity(worldManager.getCurrentWorld());
|
||||||
|
|
||||||
|
InfoComponent* info = ECS::addComponent<InfoComponent>(entity);
|
||||||
|
info->name = "New Entity";
|
||||||
|
|
||||||
|
ECS::addComponent<TransformComponent>(entity);
|
||||||
|
|
||||||
|
emit context.entitiesChanged();
|
||||||
|
});
|
||||||
|
createEntity->setIcon(QIcon::fromTheme("list-add"));
|
||||||
|
entityMenu->addAction(createEntity);
|
||||||
|
}
|
||||||
|
|
||||||
QMenu* toolsMenu = new QMenu("Tools");
|
QMenu* toolsMenu = new QMenu("Tools");
|
||||||
mainMenuBar->addMenu(toolsMenu);
|
mainMenuBar->addMenu(toolsMenu);
|
||||||
|
|
||||||
|
|
Reference in a new issue