From 2fdff77420bade71a1e8bfa3bf03d9af68722ec7 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Thu, 10 Nov 2022 23:01:09 +0800 Subject: [PATCH] Asset browser is wonky now Refresh asset browser Compile asset --- .../AssetBrowser/SHAssetBrowser.cpp | 73 +++++++++++++++---- .../AssetBrowser/SHAssetBrowser.h | 4 +- 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index 37b8ecd4..9159be7e 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -36,13 +36,27 @@ namespace SHADE DrawCurrentFolder(); } ImGui::End(); + if (queueReset) + { + SHAssetManager::RefreshDirectory(); + rootFolder = SHAssetManager::GetRootFolder(); + queueReset = false; + } + } + + void SHAssetBrowser::Refresh() + { + queueReset = true; } void SHAssetBrowser::DrawMenuBar() { if (ImGui::BeginMenuBar()) { - + if(ImGui::SmallButton("Refresh")) + { + Refresh(); + } ImGui::EndMenuBar(); } } @@ -102,16 +116,14 @@ namespace SHADE } for (auto const& file : files) { - if(file.assetMeta == nullptr) - continue; const float horizontalLineSize = 25.0f; - const ImRect childRect = DrawFile(file.assetMeta); + const ImRect childRect = DrawFile(file); const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); vertLineEnd.y = midPoint; } drawList->AddLine(vertLineStart, vertLineEnd, treeLineColor, 1); - if(assetBeingCreated.has_value() && std::get<0>(assetBeingCreated.value()) == folder) + if (assetBeingCreated.has_value() && std::get<0>(assetBeingCreated.value()) == folder) DrawAssetBeingCreated(); ImGui::TreePop(); @@ -148,12 +160,40 @@ namespace SHADE //} } - ImRect SHAssetBrowser::DrawFile(SHAsset const* const asset) noexcept + ImRect SHAssetBrowser::DrawFile(SHFile file) noexcept { - if (asset == nullptr) - return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); - const bool isSelected = std::ranges::find(selectedAssets, asset->id) != selectedAssets.end(); - ImGuiTreeNodeFlags flags = (!asset->subAssets.empty()) ? ImGuiTreeNodeFlags_OpenOnArrow : ImGuiTreeNodeFlags_Leaf; + + SHAsset const* const asset = file.assetMeta; + if (file.compilable) + { + ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf; + std::string icon{ ICON_MD_FILE_PRESENT }; + + bool const isOpen = ImGui::TreeNodeEx(file.name.data(), flags, "%s %s%s", icon.data(), file.name.data(), file.ext.data()); + const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); + + if (ImGui::BeginPopupContextItem()) + { + if (ImGui::Selectable("Compile")) + { + SHAssetManager::CompileAsset(file.path, true); + Refresh(); + } + ImGui::EndPopup(); + } + + ImGui::TreePop(); + + return nodeRect; + } + if (asset) + DrawAsset(asset); + } + + ImRect SHAssetBrowser::DrawAsset(SHAsset const* const asset) + { + const bool isSelected = asset ? std::ranges::find(selectedAssets, asset->id) != selectedAssets.end() : false; + ImGuiTreeNodeFlags flags = (asset && !asset->subAssets.empty()) ? ImGuiTreeNodeFlags_OpenOnArrow : ImGuiTreeNodeFlags_Leaf; if (isSelected) flags |= ImGuiTreeNodeFlags_Selected; std::string icon{}; @@ -172,9 +212,11 @@ namespace SHADE case AssetType::MAX_COUNT: break; default:; } - + bool const isOpen = ImGui::TreeNodeEx(asset, flags, "%s %s", icon.data(), asset->name.data()); const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); + + if (SHDragDrop::BeginSource()) { auto id = asset->id; @@ -197,7 +239,7 @@ namespace SHADE case AssetType::TEXTURE: break; case AssetType::MESH: break; case AssetType::SCENE: - if(auto editor = SHSystemManager::GetSystem()) + if (auto editor = SHSystemManager::GetSystem()) { editor->LoadScene(asset->id); } @@ -222,12 +264,12 @@ namespace SHADE ImVec2 vertLineStart = ImGui::GetCursorScreenPos(); vertLineStart.x += horizontalOffset; ImVec2 vertLineEnd = vertLineStart; - if(isOpen) + if (isOpen) { - for(auto const& subAsset : asset->subAssets) + for (auto const& subAsset : asset->subAssets) { const float horizontalLineSize = 25.0f; - const ImRect childRect = DrawFile(subAsset); + const ImRect childRect = DrawAsset(subAsset); const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); vertLineEnd.y = midPoint; @@ -253,6 +295,7 @@ namespace SHADE matInspector->OpenMaterial(assetId, true); } assetBeingCreated.reset(); + Refresh(); } } } diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h index 00023ebe..8258a6c7 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h @@ -21,7 +21,8 @@ namespace SHADE void DrawMenuBar(); ImRect RecursivelyDrawTree(FolderPointer folder); void DrawCurrentFolder(); - ImRect DrawFile(SHAsset const* const asset) noexcept; + ImRect DrawFile(SHFile file) noexcept; + ImRect DrawAsset(SHAsset const* const asset); void DrawAssetBeingCreated() noexcept; FolderPointer rootFolder, prevFolder, currentFolder; @@ -29,5 +30,6 @@ namespace SHADE std::vector selectedFolders; std::vector selectedAssets; static constexpr float tileWidth = 50.0f; + bool queueReset = false; }; }