aboutsummaryrefslogtreecommitdiff
path: root/source/EditorCore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/EditorCore.cpp')
-rw-r--r--source/EditorCore.cpp141
1 files changed, 126 insertions, 15 deletions
diff --git a/source/EditorCore.cpp b/source/EditorCore.cpp
index 7a77b26..1846962 100644
--- a/source/EditorCore.cpp
+++ b/source/EditorCore.cpp
@@ -16,6 +16,8 @@
#include <GLFW/glfw3.h>
#include <ImGuizmo.h>
+#include <imgui.h>
+#include <misc/cpp/imgui_stdlib.h>
#include <functional>
#include <memory>
#include <utility>
@@ -36,6 +38,34 @@ void PushKeyCodeRecorder(App* app, int* writeKey, bool* writeKeyStatus) {
return false;
});
}
+
+void ShowShaderName(const Shader* shader) {
+ if (shader) {
+ auto& name = shader->GetName();
+ bool isAnnoymous = name.empty();
+ if (isAnnoymous) {
+ ImGui::Text("Shader <annoymous at %p>", (void*)shader);
+ } else {
+ ImGui::Text("Shader: %s", name.c_str());
+ }
+ } else {
+ ImGui::TextUnformatted("Shader: <null>");
+ }
+}
+
+void ShowMaterialName(const Material* material) {
+ if (material) {
+ auto& name = material->GetName();
+ bool isAnnoymous = name.empty();
+ if (isAnnoymous) {
+ ImGui::Text("Material: <annoymous at %p>", (void*)material);
+ } else {
+ ImGui::Text("Material: %s", name.c_str());
+ }
+ } else {
+ ImGui::TextUnformatted("Material: <null>");
+ }
+}
} // namespace ProjectBrussel_UNITY_ID
EditorInstance::EditorInstance(App* app, GameWorld* world)
@@ -66,6 +96,7 @@ void EditorInstance::Show() {
switch (mSelectedItt) {
case ITT_GameObject: ShowInspector(static_cast<GameObject*>(mSelectedItPtr)); break;
case ITT_Shader: ShowInspector(static_cast<Shader*>(mSelectedItPtr)); break;
+ case ITT_Material: ShowInspector(static_cast<Material*>(mSelectedItPtr)); break;
case ITT_None: break;
}
ImGui::End();
@@ -89,6 +120,15 @@ void EditorInstance::ShowInspector(Shader* shader) {
using namespace Tags;
using namespace ProjectBrussel_UNITY_ID;
+ EaShader* attachment;
+ if (auto ea = shader->GetEditorAttachment()) {
+ attachment = static_cast<EaShader*>(ea);
+ } else {
+ attachment = new EaShader();
+ attachment->shader = shader;
+ shader->SetEditorAttachment(attachment);
+ }
+
auto info = shader->GetInfo();
if (!info) {
ImGui::TextUnformatted("No info present for this shader.");
@@ -103,26 +143,14 @@ void EditorInstance::ShowInspector(Shader* shader) {
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());
- }
+ ShowShaderName(shader);
- // 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);
+ info->LoadFromFile(shader->GetDesignatedMetadataPath());
}
ImGui::SameLine();
if (ImGui::Button("Export metadata", isAnnoymous)) {
- char path[512];
- GetMetadataPath(path, sizeof(path));
- info->SaveToFile(path);
+ info->SaveToFile(shader->GetDesignatedMetadataPath());
}
auto ShowThing = [&](const std::vector<ShaderInfo::InputOutputThing>& things) {
@@ -148,6 +176,89 @@ void EditorInstance::ShowInspector(Shader* shader) {
}
}
+void EditorInstance::ShowInspector(Material* material) {
+ using namespace Tags;
+ using namespace ProjectBrussel_UNITY_ID;
+
+ EaMaterial* attachment;
+ if (auto ea = material->GetEditorAttachment()) {
+ attachment = static_cast<EaMaterial*>(ea);
+ } else {
+ attachment = new EaMaterial();
+ material->SetEditorAttachment(attachment);
+ }
+
+ auto& name = material->GetName();
+ bool isAnnoymous = name.empty();
+ auto shader = material->GetShader();
+
+ if (isAnnoymous) {
+ ImGui::Text("<Annoymous Material at %p>", (void*)(&material));
+ } else {
+ if (attachment->isEditingName) {
+ bool save = false;
+ save |= ImGui::InputText("##", &attachment->editingScratch, ImGuiInputTextFlags_EnterReturnsTrue);
+ ImGui::SameLine();
+ save |= ImGui::Button("Save");
+ if (save) {
+ bool success = MaterialManager::instance->RenameMaterial(material, attachment->editingScratch);
+ if (success) {
+ attachment->isEditingName = false;
+ }
+ }
+ ImGui::SameLine();
+ if (ImGui::Button("Cancel")) {
+ attachment->isEditingName = false;
+ }
+
+ ImGui::Text("%s", attachment->editingScratch.c_str());
+ } else {
+ // NOTE: ReadOnly shouldn't write any data into the buffer
+ ImGui::InputText("##", material->mName.data(), name.size() + 1, ImGuiInputTextFlags_ReadOnly);
+ ImGui::SameLine();
+ if (ImGui::Button("Edit")) {
+ attachment->editingScratch = name; // Copy
+ attachment->isEditingName = true;
+ }
+ }
+ }
+
+ ShowShaderName(shader);
+ if (ImGui::BeginDragDropTarget()) {
+ if (auto payload = ImGui::AcceptDragDropPayload(BRUSSEL_DRAG_DROP_SHADER)) {
+ auto shader = *static_cast<Shader* const*>(payload->Data);
+ material->SetShader(shader);
+ }
+ ImGui::EndDragDropTarget();
+ }
+ ImGui::SameLine();
+ if (ImGui::Button("GoTo", shader == nullptr)) {
+ mSelectedItt = ITT_Shader;
+ mSelectedItPtr = shader;
+ }
+
+ if (ImGui::Button("Reload", isAnnoymous)) {
+ material->LoadFromFile(material->GetDesignatedPath());
+ }
+ ImGui::SameLine();
+ if (ImGui::Button("Save", isAnnoymous)) {
+ material->SaveToFile(material->GetDesignatedPath());
+ }
+
+ for (auto& field : material->mBoundScalars) {
+ // TODO
+ }
+ for (auto& field : material->mBoundVectors) {
+ // TODO
+ }
+ for (auto& field : material->mBoundMatrices) {
+ // TODO
+ }
+ for (auto& field : material->mBoundTextures) {
+ // TODO
+ }
+}
+
void EditorInstance::ShowInspector(GameObject* object) {
using namespace Tags;
using namespace ProjectBrussel_UNITY_ID;