Add hierarchy
This commit is contained in:
parent
3db85d922f
commit
462462331a
5 changed files with 69 additions and 1 deletions
|
@ -1,11 +1,13 @@
|
|||
set(INCLUDE_FILES
|
||||
include/mainwindow.h)
|
||||
include/mainwindow.h
|
||||
include/hierarchy.h)
|
||||
|
||||
qt5_wrap_cpp(EDITOR_SRC ${INCLUDE_FILES})
|
||||
|
||||
add_executable(LevelEditor
|
||||
src/main.cpp
|
||||
src/mainwindow.cpp
|
||||
src/hierarchy.cpp
|
||||
${EDITOR_SRC})
|
||||
target_include_directories(LevelEditor PRIVATE include)
|
||||
target_link_libraries(LevelEditor Qt5::Widgets Engine ToolWindowManager EditorCommon)
|
||||
|
|
21
tools/leveleditor/include/hierarchy.h
Normal file
21
tools/leveleditor/include/hierarchy.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QListView>
|
||||
#include <QStringListModel>
|
||||
|
||||
struct Context;
|
||||
|
||||
class Hierarchy : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Hierarchy(Context& context, QWidget* parent = nullptr);
|
||||
|
||||
private:
|
||||
void rebuild();
|
||||
|
||||
QListView* listView = nullptr;
|
||||
QStringListModel* listModel = nullptr;
|
||||
|
||||
Context& context;
|
||||
};
|
|
@ -12,6 +12,7 @@ public:
|
|||
|
||||
private:
|
||||
void addSceneView();
|
||||
void addHierarchy();
|
||||
|
||||
Context& context;
|
||||
ToolWindowManager* manager = nullptr;
|
||||
|
|
36
tools/leveleditor/src/hierarchy.cpp
Normal file
36
tools/leveleditor/src/hierarchy.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "hierarchy.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "context.h"
|
||||
#include "ecs.h"
|
||||
#include "worldmanager.h"
|
||||
|
||||
Hierarchy::Hierarchy(Context& context, QWidget* parent) : QWidget(parent), context(context) {
|
||||
setWindowTitle("Hierarchy");
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
setLayout(layout);
|
||||
|
||||
listView = new QListView();
|
||||
layout->addWidget(listView);
|
||||
|
||||
listModel = new QStringListModel();
|
||||
listView->setModel(listModel);
|
||||
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void Hierarchy::rebuild() {
|
||||
const auto entities = ECS::getWorldEntities(worldManager.getCurrentWorld());
|
||||
|
||||
QStringList list;
|
||||
|
||||
for(auto entity : entities) {
|
||||
const auto info = ECS::getComponent<InfoComponent>(entity);
|
||||
if(info)
|
||||
list << info->name.c_str();
|
||||
}
|
||||
|
||||
listModel->setStringList(list);
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "renderwindow.h"
|
||||
#include "renderer.h"
|
||||
#include "hierarchy.h"
|
||||
|
||||
MainWindow::MainWindow(Context& context) : context(context) {
|
||||
setWindowTitle("Level Editor");
|
||||
|
@ -131,6 +132,7 @@ MainWindow::MainWindow(Context& context) : context(context) {
|
|||
setCentralWidget(manager);
|
||||
|
||||
addSceneView();
|
||||
addHierarchy();
|
||||
}
|
||||
|
||||
void MainWindow::addSceneView() {
|
||||
|
@ -144,3 +146,9 @@ void MainWindow::addSceneView() {
|
|||
manager->addToolWindow(wrapper, ToolWindowManager::AreaReference(ToolWindowManager::EmptySpace));
|
||||
}
|
||||
|
||||
void MainWindow::addHierarchy() {
|
||||
Hierarchy* hierarchy = new Hierarchy(context);
|
||||
|
||||
manager->addToolWindow(hierarchy, ToolWindowManager::AreaReference(ToolWindowManager::EmptySpace));
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue