aboutsummaryrefslogtreecommitdiff
path: root/source/EditorResources.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-04-15 20:30:39 -0700
committerrtk0c <[email protected]>2022-04-15 20:30:39 -0700
commitafcac59c7d04f4337d6b04ebed8cac7e871ccc50 (patch)
tree8c32b90b4a0ab762a68f228dc8cc4e7f52fc5bd7 /source/EditorResources.cpp
parentf2a1481123ac23aeb4937df5f61c57e0e4f1ff52 (diff)
Changeset: 7 Work on Material system
Diffstat (limited to 'source/EditorResources.cpp')
-rw-r--r--source/EditorResources.cpp83
1 files changed, 77 insertions, 6 deletions
diff --git a/source/EditorResources.cpp b/source/EditorResources.cpp
index c6d4d09..be7cefb 100644
--- a/source/EditorResources.cpp
+++ b/source/EditorResources.cpp
@@ -3,9 +3,18 @@
#include "EditorCore.hpp"
#include "EditorNotification.hpp"
#include "EditorUtils.hpp"
+#include "Macros.hpp"
+#include "ScopeGuard.hpp"
#include "Shader.hpp"
#include <imgui.h>
+#include <misc/cpp/imgui_stdlib.h>
+#include <cstdlib>
+#include <limits>
+#include <string>
+#include <string_view>
+
+using namespace std::literals;
EditorContentBrowser::EditorContentBrowser(EditorInstance* editor)
: mEditor{ editor } {
@@ -37,6 +46,9 @@ void EditorContentBrowser::Show(bool* open) {
if (ImGui::Selectable("Shaders", mPane == P_Shader)) {
mPane = P_Shader;
}
+ if (ImGui::Selectable("Materials", mPane == P_Material)) {
+ mPane = P_Material;
+ }
}
ImGui::EndChild();
@@ -49,23 +61,82 @@ void EditorContentBrowser::Show(bool* open) {
} break;
case P_Shader: {
- // TODO reload shaders while keeping existing references working
- // if (ImGui::Button("Reload from disk")) {
- // ShaderManager::instance->DiscoverShaders();
- // }
+ if (ImGui::Button("Refresh")) {
+ // TODO reload shaders while keeping existing references working
+ }
+ ImGui::SameLine();
+ if (ImGui::Button("Save all")) {
+ auto& shaders = ShaderManager::instance->GetShaders();
+ for (auto&& [DISCARD, shader] : shaders) {
+ auto info = shader->GetInfo();
+ if (info) {
+ info->SaveToFile(shader->GetDesignatedMetadataPath());
+ }
+ }
+ }
auto& shaders = ShaderManager::instance->GetShaders();
for (auto it = shaders.begin(); it != shaders.end(); ++it) {
- auto name = it->first;
auto shader = it->second.Get();
+ auto& name = shader->GetName();
shader->GatherInfoIfAbsent();
auto details = shader->GetInfo();
bool selected = mEditor->GetSelectedItPtr() == shader;
- if (ImGui::Selectable(name.data(), selected)) {
+ if (ImGui::Selectable(name.c_str(), selected)) {
mEditor->SelectIt(shader, EditorInstance::ITT_Shader);
}
+
+ if (ImGui::BeginDragDropSource()) {
+ // Reason: intentionally using pointer as Fpayload
+ ImGui::SetDragDropPayload(BRUSSEL_DRAG_DROP_SHADER, &shader, sizeof(shader)); // NOLINT(bugprone-sizeof-expression)
+ ImGui::Text("Shader '%s'", name.c_str());
+ ImGui::EndDragDropSource();
+ }
+ }
+ } break;
+
+ case P_Material: {
+ if (ImGui::Button("New")) {
+ int n = std::rand();
+ auto mat = new Material(nullptr, "Unnamed Material " + std::to_string(n));
+ auto guard = GuardDeletion(mat);
+ auto [DISCARD, inserted] = MaterialManager::instance->SaveMaterial(mat);
+ if (inserted) {
+ guard.Dismiss();
+ } else {
+ ImGui::AddNotification(ImGuiToast(ImGuiToastType_Error, "Failed to create material."));
+ }
+ }
+ ImGui::SameLine();
+ if (ImGui::Button("Refresh")) {
+ // TODO
+ }
+ ImGui::SameLine();
+ if (ImGui::Button("Save all")) {
+ auto& mats = MaterialManager::instance->GetMaterials();
+ for (auto&& [DISCARD, mat] : mats) {
+ mat->SaveToFile(mat->GetDesignatedPath());
+ }
+ }
+
+ auto& mats = MaterialManager::instance->GetMaterials();
+ for (auto it = mats.begin(); it != mats.end(); ++it) {
+ auto mat = it->second.Get();
+ auto& name = mat->GetName();
+
+ bool selected = mEditor->GetSelectedItPtr() == mat;
+ if (ImGui::Selectable(name.c_str(), selected)) {
+ mEditor->SelectIt(mat, EditorInstance::ITT_Material);
+ }
+
+ if (ImGui::BeginDragDropSource()) {
+ // Reason: intentionally using pointer as payload
+ ImGui::SetDragDropPayload(BRUSSEL_DRAG_DROP_MATERIAL, &mat, sizeof(mat)); // NOLINT(bugprone-sizeof-expression)
+ ImGui::Text("Material '%s'", name.c_str());
+ ImGui::EndDragDropSource();
+ }
}
} break;
}