ContentBrowserPanel

- Added ContentBrowserPanel
This commit is contained in:
Light 2021-10-23 19:04:29 +03:30
parent 0c06164509
commit cc4fc02931
4 changed files with 88 additions and 9 deletions

View file

@ -4,7 +4,7 @@
namespace Light {
EditorLayer::EditorLayer(const std::string& name, const std::vector<std::string>& args):
EditorLayer::EditorLayer(const std::string& name, const std::vector<std::string>& args) :
Layer(name),
m_SceneDir(args.empty() ? "" : args[0])
{
@ -12,6 +12,7 @@ namespace Light {
m_PropertiesPanel = CreateRef<PropertiesPanel>();
m_SceneHierarchyPanel = CreateRef<SceneHierarchyPanel>(m_Scene, m_PropertiesPanel);
m_ContentBrowserPanel = CreateRef<ContentBrowserPanel>();
m_Framebuffer = Framebuffer::Create({ 1, 1, 1 }, GraphicsContext::GetSharedContext());
@ -42,10 +43,10 @@ namespace Light {
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<TransformComponent>().translation;
cameraTranslation += glm::vec3(m_Direction * m_Speed * deltaTime, 0.0f);
@ -84,8 +85,10 @@ 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();
}

View file

@ -4,6 +4,7 @@
#include "Panels/SceneHierarchyPanel.h"
#include "Panels/PropertiesPanel.h"
#include "Panels/ContentBrowser.h"
#include <glm/gtc/matrix_transform.hpp>
@ -22,6 +23,7 @@ namespace Light {
Ref<SceneHierarchyPanel> m_SceneHierarchyPanel;
Ref<PropertiesPanel> m_PropertiesPanel;
Ref<ContentBrowserPanel> m_ContentBrowserPanel;
Ref<Framebuffer> m_Framebuffer;

View file

@ -0,0 +1,51 @@
#include "ContentBrowser.h"
#include <imgui.h>
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();
}
}

View file

@ -0,0 +1,23 @@
#pragma once
#include "Panel.h"
#include <filesystem>
namespace Light {
class ContentBrowserPanel : public Panel
{
private:
public:
ContentBrowserPanel();
void OnUserInterfaceUpdate();
private:
std::filesystem::path m_CurrentDirectory;
const std::filesystem::path m_AssetsPath;
};
}