Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ find_package(SDL3 CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(tinyobjloader CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(unofficial-imgui-node-editor CONFIG REQUIRED)
find_package(Vulkan REQUIRED)

# Sources.
Expand Down
3 changes: 3 additions & 0 deletions editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ add_executable(FrameEditor
menubar_file.h
window_start.cpp
window_start.h
window_level.cpp
window_level.h
${CMAKE_CURRENT_SOURCE_DIR}/../asset/json/new_project_template.json
)

Expand All @@ -30,6 +32,7 @@ target_link_libraries(FrameEditor
FrameOpenGLGui
FrameOpenGLFile
FrameProto
unofficial::imgui-node-editor::imgui-node-editor
imgui::imgui
ImGuiColorTextEdit
)
Expand Down
6 changes: 6 additions & 0 deletions editor/menubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "frame/gui/window_logger.h"
#include "frame/gui/window_resolution.h"
#include "frame/logger.h"
#include "window_level.h"
#include <imgui.h>
#include <set>

Expand Down Expand Up @@ -77,6 +78,11 @@ void Menubar::MenuEdit()
std::make_unique<WindowJsonFile>(
menubar_file_.GetFileName(), device_));
}
if (ImGui::MenuItem("Level Editor"))
{
menubar_view_.GetDrawGui().AddWindow(
std::make_unique<WindowLevel>(device_));
}
if (ImGui::BeginMenu("Shader"))
{
std::set<std::string> shader_names;
Expand Down
100 changes: 100 additions & 0 deletions editor/window_level.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include "window_level.h"

#include <imgui.h>
#include <imgui_node_editor.h>

namespace ed = ax::NodeEditor;

namespace frame::gui
{

WindowLevel::WindowLevel(DeviceInterface& device) : device_(device)
{
}

WindowLevel::~WindowLevel()
{
if (context_)
ed::DestroyEditor(context_);
}

void WindowLevel::DisplayNode(LevelInterface& level, EntityId id)
{
std::string name = level.GetNameFromId(id);
ed::BeginNode(id);
ImGui::Text("%s", name.c_str());
ed::EndNode();
for (auto child : level.GetChildList(id))
{
DisplayNode(level, child);
}
}

bool WindowLevel::DrawCallback()
{
auto& level = device_.GetLevel();
if (!context_)
context_ = ed::CreateEditor();
if (ImGui::BeginTabBar("##level_tabs"))
{
if (ImGui::BeginTabItem("Textures"))
{
for (auto id : level.GetTextures())
{
auto& tex = level.GetTextureFromId(id);
ImGui::BulletText("%s", tex.GetName().c_str());
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Programs"))
{
for (auto id : level.GetPrograms())
{
auto& prog = level.GetProgramFromId(id);
ImGui::BulletText("%s", prog.GetName().c_str());
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Materials"))
{
for (auto id : level.GetMaterials())
{
auto& mat = level.GetMaterialFromId(id);
ImGui::BulletText("%s", mat.GetName().c_str());
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Scene"))
{
ed::SetCurrentEditor(context_);
ed::Begin("SceneEditor");
auto root = level.GetDefaultRootSceneNodeId();
if (root)
{
DisplayNode(level, root);
}
ed::End();
ed::SetCurrentEditor(nullptr);
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
return true;
}

bool WindowLevel::End() const
{
return end_;
}

std::string WindowLevel::GetName() const
{
return name_;
}

void WindowLevel::SetName(const std::string& name)
{
name_ = name;
}

} // namespace frame::gui
30 changes: 30 additions & 0 deletions editor/window_level.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "frame/device_interface.h"
#include "frame/gui/gui_window_interface.h"
#include <imgui_node_editor.h>

namespace frame::gui
{

class WindowLevel : public GuiWindowInterface
{
public:
explicit WindowLevel(DeviceInterface& device);
~WindowLevel() override;

bool DrawCallback() override;
bool End() const override;
std::string GetName() const override;
void SetName(const std::string& name) override;

private:
void DisplayNode(LevelInterface& level, EntityId id);

DeviceInterface& device_;
ax::NodeEditor::EditorContext* context_ = nullptr;
std::string name_ = "Level Editor";
bool end_ = false;
};

} // namespace frame::gui
9 changes: 7 additions & 2 deletions src/frame/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ add_library(FrameGui
window_texture.cpp
window_json_file.cpp
window_glsl_file.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../../external/imgui-node-editor/imgui_node_editor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../../external/imgui-node-editor/imgui_node_editor_api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../../external/imgui-node-editor/imgui_canvas.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../../external/imgui-node-editor/crude_json.cpp
)

target_include_directories(FrameGui
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../src
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../../external/ImGuiColorTextEdit
)
${CMAKE_CURRENT_SOURCE_DIR}/../../../external/ImGuiColorTextEdit
${CMAKE_CURRENT_SOURCE_DIR}/../../../external/imgui-node-editor
)

target_link_libraries(FrameGui
PUBLIC
Expand Down
1 change: 1 addition & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"name": "imgui",
"features": [ "opengl3-binding", "sdl3-binding", "docking-experimental" ]
},
"imgui-node-editor",
"opengl",
"protobuf",
{
Expand Down
Loading