From cc4fc0293164ca48efdc833d0054d3ff8e60b65d Mon Sep 17 00:00:00 2001 From: Light Date: Sat, 23 Oct 2021 19:04:29 +0330 Subject: [PATCH] ContentBrowserPanel - Added ContentBrowserPanel --- Mirror/src/EditorLayer.cpp | 19 ++++++----- Mirror/src/EditorLayer.h | 4 ++- Mirror/src/Panels/ContentBrowser.cpp | 51 ++++++++++++++++++++++++++++ Mirror/src/Panels/ContentBrowser.h | 23 +++++++++++++ 4 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 Mirror/src/Panels/ContentBrowser.cpp create mode 100644 Mirror/src/Panels/ContentBrowser.h diff --git a/Mirror/src/EditorLayer.cpp b/Mirror/src/EditorLayer.cpp index ffb884a..e6f1eb1 100644 --- a/Mirror/src/EditorLayer.cpp +++ b/Mirror/src/EditorLayer.cpp @@ -4,7 +4,7 @@ namespace Light { - EditorLayer::EditorLayer(const std::string& name, const std::vector& args): + EditorLayer::EditorLayer(const std::string& name, const std::vector& args) : Layer(name), m_SceneDir(args.empty() ? "" : args[0]) { @@ -12,6 +12,7 @@ namespace Light { m_PropertiesPanel = CreateRef(); m_SceneHierarchyPanel = CreateRef(m_Scene, m_PropertiesPanel); + m_ContentBrowserPanel = CreateRef(); m_Framebuffer = Framebuffer::Create({ 1, 1, 1 }, GraphicsContext::GetSharedContext()); @@ -36,16 +37,16 @@ namespace Light { serializer.Serialize(m_SceneDir); } } - + void EditorLayer::OnUpdate(float deltaTime) { m_Scene->OnUpdate(deltaTime); m_Direction.x = Input::GetKeyboardKey(Key::A) ? -1.0f : - Input::GetKeyboardKey(Key::D) ? 1.0f : 0.0f; - + Input::GetKeyboardKey(Key::D) ? 1.0f : 0.0f; + m_Direction.y = Input::GetKeyboardKey(Key::S) ? -1.0f : - Input::GetKeyboardKey(Key::W) ? 1.0f : 0.0f; + Input::GetKeyboardKey(Key::W) ? 1.0f : 0.0f; auto& cameraTranslation = m_CameraEntity.GetComponent().translation; cameraTranslation += glm::vec3(m_Direction * m_Speed * deltaTime, 0.0f); @@ -53,12 +54,12 @@ namespace Light { if (Input::GetKeyboardKey(Key::Escape)) Application::Quit(); } - + void EditorLayer::OnRender() { m_Scene->OnRender(m_Framebuffer); } - + void EditorLayer::OnUserInterfaceUpdate() { UserInterface::DockspaceBegin(); @@ -84,10 +85,12 @@ namespace Light { ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); } ImGui::End(); + // panels m_SceneHierarchyPanel->OnUserInterfaceUpdate(); m_PropertiesPanel->OnUserInterfaceUpdate(); + m_ContentBrowserPanel->OnUserInterfaceUpdate(); UserInterface::DockspaceEnd(); } - + } \ No newline at end of file diff --git a/Mirror/src/EditorLayer.h b/Mirror/src/EditorLayer.h index 2b9a44e..b451ad2 100644 --- a/Mirror/src/EditorLayer.h +++ b/Mirror/src/EditorLayer.h @@ -4,6 +4,7 @@ #include "Panels/SceneHierarchyPanel.h" #include "Panels/PropertiesPanel.h" +#include "Panels/ContentBrowser.h" #include @@ -11,7 +12,7 @@ namespace Light { class EditorLayer : public Layer { - private: + private: std::string m_SceneDir; // #todo: add camera controller class to the engine @@ -22,6 +23,7 @@ namespace Light { Ref m_SceneHierarchyPanel; Ref m_PropertiesPanel; + Ref m_ContentBrowserPanel; Ref m_Framebuffer; diff --git a/Mirror/src/Panels/ContentBrowser.cpp b/Mirror/src/Panels/ContentBrowser.cpp new file mode 100644 index 0000000..3b06bc1 --- /dev/null +++ b/Mirror/src/Panels/ContentBrowser.cpp @@ -0,0 +1,51 @@ +#include "ContentBrowser.h" + +#include + +namespace Light { + + ContentBrowserPanel::ContentBrowserPanel() : + m_CurrentDirectory("assets"), + m_AssetsPath("assets") + { + } + + void ContentBrowserPanel::OnUserInterfaceUpdate() + { + ImGui::Begin("Content Browser"); + + if (m_CurrentDirectory != std::filesystem::path("assets")) + { + if (ImGui::Button(" <-- ")) + { + m_CurrentDirectory = m_CurrentDirectory.parent_path(); + } + } + + for (auto& dirEntry : std::filesystem::directory_iterator(m_CurrentDirectory)) + { + const auto& path = dirEntry.path(); + Texture2D + auto relativePathasd; = std::filesystem::relative(path, m_AssetsPath); + std::string relativePathString = relativePath.string(); + + if (dirEntry.is_directory()) + { + if (ImGui::Button(relativePathString.c_str())) + { + m_CurrentDirectory /= path.filename(); + } + } + else + { + if (ImGui::Button(relativePathString.c_str())) + { + + } + } + } + + ImGui::End(); + } + +} \ No newline at end of file diff --git a/Mirror/src/Panels/ContentBrowser.h b/Mirror/src/Panels/ContentBrowser.h new file mode 100644 index 0000000..4f421aa --- /dev/null +++ b/Mirror/src/Panels/ContentBrowser.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Panel.h" + +#include + +namespace Light { + + class ContentBrowserPanel : public Panel + { + private: + + public: + ContentBrowserPanel(); + + void OnUserInterfaceUpdate(); + + private: + std::filesystem::path m_CurrentDirectory; + const std::filesystem::path m_AssetsPath; + }; + +} \ No newline at end of file