From 462462331a2e6f700d49e191ebef48dd7358882a Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 25 Dec 2018 09:58:31 -0500 Subject: [PATCH] Add hierarchy --- tools/leveleditor/CMakeLists.txt | 4 ++- tools/leveleditor/include/hierarchy.h | 21 +++++++++++++++ tools/leveleditor/include/mainwindow.h | 1 + tools/leveleditor/src/hierarchy.cpp | 36 ++++++++++++++++++++++++++ tools/leveleditor/src/mainwindow.cpp | 8 ++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tools/leveleditor/include/hierarchy.h create mode 100644 tools/leveleditor/src/hierarchy.cpp diff --git a/tools/leveleditor/CMakeLists.txt b/tools/leveleditor/CMakeLists.txt index 06209cd..7731351 100644 --- a/tools/leveleditor/CMakeLists.txt +++ b/tools/leveleditor/CMakeLists.txt @@ -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) diff --git a/tools/leveleditor/include/hierarchy.h b/tools/leveleditor/include/hierarchy.h new file mode 100644 index 0000000..a675937 --- /dev/null +++ b/tools/leveleditor/include/hierarchy.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +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; +}; diff --git a/tools/leveleditor/include/mainwindow.h b/tools/leveleditor/include/mainwindow.h index 73635a7..4a70b3c 100644 --- a/tools/leveleditor/include/mainwindow.h +++ b/tools/leveleditor/include/mainwindow.h @@ -12,6 +12,7 @@ public: private: void addSceneView(); + void addHierarchy(); Context& context; ToolWindowManager* manager = nullptr; diff --git a/tools/leveleditor/src/hierarchy.cpp b/tools/leveleditor/src/hierarchy.cpp new file mode 100644 index 0000000..e6808b0 --- /dev/null +++ b/tools/leveleditor/src/hierarchy.cpp @@ -0,0 +1,36 @@ +#include "hierarchy.h" + +#include + +#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(entity); + if(info) + list << info->name.c_str(); + } + + listModel->setStringList(list); +} diff --git a/tools/leveleditor/src/mainwindow.cpp b/tools/leveleditor/src/mainwindow.cpp index 7439f84..b65fbde 100644 --- a/tools/leveleditor/src/mainwindow.cpp +++ b/tools/leveleditor/src/mainwindow.cpp @@ -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)); +} +