2022-03-08 21:19:19 +03:30
|
|
|
#include "ContentBrowser.hpp"
|
2021-10-23 19:04:29 +03:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
#include <LightEngine.hpp>
|
2021-10-23 19:04:29 +03:30
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
namespace Light {
|
|
|
|
|
2022-03-07 20:01:44 +03:30
|
|
|
AssetBrowserPanel::AssetBrowserPanel()
|
2022-03-06 22:25:23 +03:30
|
|
|
: m_CurrentDirectory("Assets"), m_AssetsPath("Assets")
|
|
|
|
{
|
2022-03-07 20:01:44 +03:30
|
|
|
ResourceManager::LoadTexture("_Assets_Directory", "EngineResources/Icons/Asset_Directory.png");
|
|
|
|
ResourceManager::LoadTexture("_Assets_Image", "EngineResources/Icons/Asset_Image.png");
|
|
|
|
ResourceManager::LoadTexture("_Assets_Text", "EngineResources/Icons/Asset_Text.png");
|
|
|
|
m_DirectoryTexture = ResourceManager::GetTexture("_Assets_Directory");
|
|
|
|
m_ImageTexture = ResourceManager::GetTexture("_Assets_Image");
|
|
|
|
m_TextTexture = ResourceManager::GetTexture("_Assets_Text");
|
2022-03-06 22:25:23 +03:30
|
|
|
}
|
2021-10-23 19:04:29 +03:30
|
|
|
|
2022-03-07 20:01:44 +03:30
|
|
|
void AssetBrowserPanel::OnUserInterfaceUpdate()
|
2022-03-04 22:40:20 +03:30
|
|
|
{
|
|
|
|
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-07 20:01:44 +03:30
|
|
|
m_DirectoryTexture->Bind(0u);
|
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-07 20:01:44 +03:30
|
|
|
AssetType assetType;
|
2022-03-06 22:25:23 +03:30
|
|
|
std::string extension = dirEntry.path().extension().string();
|
|
|
|
|
|
|
|
// TODO: Tidy up
|
2022-03-07 20:01:44 +03:30
|
|
|
assetType = extension.empty() ? AssetType::Directory :
|
|
|
|
|
|
|
|
extension == ".txt" ? AssetType::Text :
|
|
|
|
extension == ".glsl" ? AssetType::Text :
|
|
|
|
|
|
|
|
extension == ".png" ? AssetType::Image :
|
2021-10-23 19:04:29 +03:30
|
|
|
|
2022-03-07 20:01:44 +03:30
|
|
|
AssetType::None;
|
|
|
|
|
|
|
|
// Unsupported asset type
|
|
|
|
if (assetType == AssetType::None)
|
2021-10-23 19:04:29 +03:30
|
|
|
{
|
2022-03-07 20:01:44 +03:30
|
|
|
continue;
|
2021-10-23 19:04:29 +03:30
|
|
|
}
|
2022-03-06 22:25:23 +03:30
|
|
|
|
2022-03-07 20:01:44 +03:30
|
|
|
const auto& path = dirEntry.path();
|
|
|
|
auto relativePath = std::filesystem::relative(path, m_AssetsPath);
|
|
|
|
std::string relativePathString = relativePath.string();
|
|
|
|
|
|
|
|
// Button
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::PushID(path.c_str());
|
|
|
|
switch (assetType)
|
2021-10-23 19:04:29 +03:30
|
|
|
{
|
2022-03-07 20:01:44 +03:30
|
|
|
case AssetType::Directory:
|
|
|
|
if (ImGui::ImageButton(m_DirectoryTexture->GetTexture(), ImVec2(m_FileSize, m_FileSize), ImVec2 { 0.0f, 0.0f }, ImVec2 { 1.0f, 1.0f }, 0, ImVec4 { 0.0f, 0.0f, 0.0f, 0.0f }, ImVec4 { 1.0f, 1.0f, 1.0f, 1.0f }))
|
|
|
|
{
|
|
|
|
m_CurrentDirectory /= path.filename();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AssetType::Image:
|
|
|
|
if (ImGui::ImageButton(m_ImageTexture->GetTexture(), ImVec2(m_FileSize, m_FileSize), ImVec2 { 0.0f, 0.0f }, ImVec2 { 1.0f, 1.0f }, 0, ImVec4 { 0.0f, 0.0f, 0.0f, 0.0f }, ImVec4 { 1.0f, 1.0f, 1.0f, 1.0f }))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
break;
|
2022-03-06 22:25:23 +03:30
|
|
|
|
2022-03-07 20:01:44 +03:30
|
|
|
case AssetType::Text:
|
|
|
|
if (ImGui::ImageButton(m_TextTexture->GetTexture(), ImVec2(m_FileSize, m_FileSize), ImVec2 { 0.0f, 0.0f }, ImVec2 { 1.0f, 1.0f }, 0, ImVec4 { 0.0f, 0.0f, 0.0f, 0.0f }, ImVec4 { 1.0f, 1.0f, 1.0f, 1.0f }))
|
2021-10-23 19:04:29 +03:30
|
|
|
{
|
|
|
|
}
|
2022-03-07 20:01:44 +03:30
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2021-10-23 19:04:29 +03:30
|
|
|
}
|
2022-03-07 20:01:44 +03:30
|
|
|
// Label
|
|
|
|
ImGui::Text("%s", path.filename().c_str());
|
|
|
|
ImGui::PopID();
|
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::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
|