2021-10-23 19:04:29 +03:30
|
|
|
#include "ContentBrowser.h"
|
|
|
|
|
2022-03-06 22:25:23 +03:30
|
|
|
#include <LightEngine.h>
|
2021-10-23 19:04:29 +03:30
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
namespace Light {
|
|
|
|
|
2022-03-04 22:40:20 +03:30
|
|
|
ContentBrowserPanel::ContentBrowserPanel()
|
2022-03-06 22:25:23 +03:30
|
|
|
: m_CurrentDirectory("Assets"), m_AssetsPath("Assets")
|
|
|
|
{
|
|
|
|
// ResourceManager::LoadTexture("_Assets_Directory", "EngineResources/Icons/Asset_Directory");
|
|
|
|
// m_DirectoryTexture = ResourceManager::GetTexture("_Assets_Directory");
|
|
|
|
}
|
2021-10-23 19:04:29 +03:30
|
|
|
|
2022-03-04 22:40:20 +03:30
|
|
|
void ContentBrowserPanel::OnUserInterfaceUpdate()
|
|
|
|
{
|
|
|
|
ImGui::Begin("Content Browser");
|
2021-10-23 19:04:29 +03:30
|
|
|
|
2022-03-04 22:40:20 +03:30
|
|
|
if (m_CurrentDirectory != std::filesystem::path("Assets"))
|
|
|
|
{
|
|
|
|
if (ImGui::Button(" <-- "))
|
2021-10-23 19:04:29 +03:30
|
|
|
{
|
2022-03-04 22:40:20 +03:30
|
|
|
m_CurrentDirectory = m_CurrentDirectory.parent_path();
|
2021-10-23 19:04:29 +03:30
|
|
|
}
|
2022-03-04 22:40:20 +03:30
|
|
|
}
|
2021-10-23 19:04:29 +03:30
|
|
|
|
2022-03-06 22:25:23 +03:30
|
|
|
|
|
|
|
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
|
|
|
uint32_t cellSize = m_FileSize + m_FilePadding;
|
|
|
|
uint32_t columnCount = std::clamp(static_cast<uint32_t>(std::floor(regionAvail.x / cellSize)), 1u, 64u);
|
|
|
|
|
|
|
|
if (ImGui::BeginTable("ContentBrowser", columnCount))
|
2022-03-04 22:40:20 +03:30
|
|
|
{
|
2022-03-06 22:25:23 +03:30
|
|
|
for (auto& dirEntry : std::filesystem::directory_iterator(m_CurrentDirectory))
|
2021-10-23 19:04:29 +03:30
|
|
|
{
|
2022-03-06 22:25:23 +03:30
|
|
|
ImGui::TableNextColumn();
|
|
|
|
LT_ENGINE_TRACE("File: ", dirEntry.path().string());
|
|
|
|
FileType assetType;
|
|
|
|
std::string extension = dirEntry.path().extension().string();
|
|
|
|
|
|
|
|
// TODO: Tidy up
|
|
|
|
assetType = extension.empty() ? FileType::Directory :
|
|
|
|
extension == ".txt" ? FileType::Text :
|
|
|
|
extension == ".png" ? FileType::Image :
|
|
|
|
FileType::None;
|
2021-10-23 19:04:29 +03:30
|
|
|
|
2022-03-06 22:25:23 +03:30
|
|
|
if (assetType == FileType::None)
|
2021-10-23 19:04:29 +03:30
|
|
|
{
|
2022-03-06 22:25:23 +03:30
|
|
|
LT_ENGINE_ERROR("Unsupported file exetnsion: {}", extension);
|
|
|
|
return;
|
2021-10-23 19:04:29 +03:30
|
|
|
}
|
2022-03-06 22:25:23 +03:30
|
|
|
|
|
|
|
const auto& path = dirEntry.path();
|
2021-10-23 19:04:29 +03:30
|
|
|
{
|
2022-03-06 22:25:23 +03:30
|
|
|
auto relativePath = std::filesystem::relative(path, m_AssetsPath);
|
|
|
|
std::string relativePathString = relativePath.string();
|
|
|
|
|
|
|
|
switch (assetType)
|
2021-10-23 19:04:29 +03:30
|
|
|
{
|
2022-03-06 22:25:23 +03:30
|
|
|
case FileType::Directory:
|
|
|
|
if (ImGui::Button(relativePathString.c_str(), ImVec2(m_FileSize, m_FileSize)))
|
|
|
|
{
|
|
|
|
m_CurrentDirectory /= path.filename();
|
|
|
|
}
|
|
|
|
ImGui::Text("Test");
|
|
|
|
break;
|
|
|
|
case FileType::Image:
|
|
|
|
if (ImGui::Button(relativePathString.c_str(), ImVec2(m_FileSize, m_FileSize)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileType::Text:
|
|
|
|
if (ImGui::Button(relativePathString.c_str(), ImVec2(m_FileSize, m_FileSize)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2021-10-23 19:04:29 +03:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-06 22:25:23 +03:30
|
|
|
ImGui::EndTable();
|
2021-10-23 19:04:29 +03:30
|
|
|
}
|
2022-03-06 22:25:23 +03:30
|
|
|
ImGui::DragInt("Size", (int*)&m_FileSize, 32u, 512u);
|
|
|
|
ImGui::DragInt("Padding", (int*)&m_FilePadding, 32u, 512u);
|
|
|
|
ImGui::End();
|
2022-03-04 22:40:20 +03:30
|
|
|
}
|
2021-10-23 19:04:29 +03:30
|
|
|
|
2022-03-04 22:40:20 +03:30
|
|
|
} // namespace Light
|