diff options
Diffstat (limited to 'source/EditorCore.cpp')
-rw-r--r-- | source/EditorCore.cpp | 95 |
1 files changed, 88 insertions, 7 deletions
diff --git a/source/EditorCore.cpp b/source/EditorCore.cpp index 7744793..7a77b26 100644 --- a/source/EditorCore.cpp +++ b/source/EditorCore.cpp @@ -7,7 +7,7 @@ #include "EditorAttachmentImpl.hpp" #include "EditorNotification.hpp" #include "EditorUtils.hpp" -#include "GameObjectTypeTag.hpp" +#include "GameObjectTags.hpp" #include "Level.hpp" #include "Mesh.hpp" #include "Player.hpp" @@ -41,8 +41,7 @@ void PushKeyCodeRecorder(App* app, int* writeKey, bool* writeKeyStatus) { EditorInstance::EditorInstance(App* app, GameWorld* world) : mApp{ app } , mWorld{ world } - , mEdInspector() - , mEdContentBrowser(&mEdInspector) {} + , mEdContentBrowser(this) {} EditorInstance::~EditorInstance() { } @@ -50,6 +49,11 @@ EditorInstance::~EditorInstance() { void EditorInstance::Show() { if (!mWorld) return; + auto& io = ImGui::GetIO(); + if (io.KeyCtrl && ImGui::IsKeyPressed(GLFW_KEY_SPACE, false)) { + mEdContentBrowserVisible = !mEdContentBrowserVisible; + } + ImGui::Begin("World properties"); ShowWorldProperties(); ImGui::End(); @@ -59,15 +63,91 @@ void EditorInstance::Show() { ImGui::End(); ImGui::Begin("Inspector"); - if (mSelectedGameObject) { - ShowInspector(mSelectedGameObject); + switch (mSelectedItt) { + case ITT_GameObject: ShowInspector(static_cast<GameObject*>(mSelectedItPtr)); break; + case ITT_Shader: ShowInspector(static_cast<Shader*>(mSelectedItPtr)); break; + case ITT_None: break; } ImGui::End(); + + if (mEdContentBrowserVisible) { + mEdContentBrowser.Show(&mEdContentBrowserVisible); + } +} + +void EditorInstance::SelectIt(void* ptr, InspectorTargetType itt) { + mSelectedItPtr = ptr; + mSelectedItt = itt; } void EditorInstance::ShowWorldProperties() { } +// TOOD move resource-specific and gameobject-specific inspector code into attachments mechanism + +void EditorInstance::ShowInspector(Shader* shader) { + using namespace Tags; + using namespace ProjectBrussel_UNITY_ID; + + auto info = shader->GetInfo(); + if (!info) { + ImGui::TextUnformatted("No info present for this shader."); + if (ImGui::Button("Create empty info")) { + shader->CreateEmptyInfoIfAbsent(); + } + if (ImGui::Button("Gather info")) { + shader->GatherInfoIfAbsent(); + } + return; + } + + auto& name = shader->GetName(); + bool isAnnoymous = name.empty(); + if (isAnnoymous) { + ImGui::Text("<Annoymous Shader at %p>", (void*)shader); + } else { + ImGui::Text("Name: %s", shader->GetName().c_str()); + } + + // TODO use std::filesystem::path + auto GetMetadataPath = [&](char* path, int pathLength) { + snprintf(path, pathLength, "%s/Shaders/%s.json", AppConfig::assetDir.c_str(), shader->GetName().c_str()); + }; + if (ImGui::Button("Reimport metadata", isAnnoymous)) { + char path[512]; + GetMetadataPath(path, sizeof(path)); + info->LoadFromFile(path); + } + ImGui::SameLine(); + if (ImGui::Button("Export metadata", isAnnoymous)) { + char path[512]; + GetMetadataPath(path, sizeof(path)); + info->SaveToFile(path); + } + + auto ShowThing = [&](const std::vector<ShaderInfo::InputOutputThing>& things) { + for (auto& thing : things) { + ImGui::BulletText("Location %d\nName: %s\nSemantic: %s\nType: %s %dx%d", + thing.variable.location, + thing.variable.name.c_str(), + Tags::NameOf(thing.semantic).data(), + Tags::NameOfGLType(thing.variable.scalarType).data(), + thing.variable.width, + thing.variable.height); + } + }; + if (ImGui::CollapsingHeader("Inputs")) { + ShowThing(info->inputs); + } + if (ImGui::CollapsingHeader("Outputs")) { + ShowThing(info->outputs); + } + if (ImGui::CollapsingHeader("Uniforms")) { + } + if (ImGui::CollapsingHeader("Uniform blocks")) { + } +} + void EditorInstance::ShowInspector(GameObject* object) { using namespace Tags; using namespace ProjectBrussel_UNITY_ID; @@ -160,13 +240,14 @@ void EditorInstance::ShowGameObjectInTree(GameObject* object) { flags |= ImGuiTreeNodeFlags_OpenOnDoubleClick; flags |= ImGuiTreeNodeFlags_OpenOnArrow; flags |= ImGuiTreeNodeFlags_SpanAvailWidth; - if (mSelectedGameObject == object) { + if (mSelectedItPtr == object) { flags |= ImGuiTreeNodeFlags_Selected; } if (ImGui::TreeNodeEx(attachment->name.c_str(), flags)) { if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen()) { - mSelectedGameObject = object; + mSelectedItPtr = object; + mSelectedItt = ITT_GameObject; } for (auto& child : object->GetChildren()) { |