Asset browser is wonky now
Refresh asset browser Compile asset
This commit is contained in:
parent
c95a6a2492
commit
2fdff77420
|
@ -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{};
|
||||
|
@ -175,6 +215,8 @@ namespace SHADE
|
|||
|
||||
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<SHEditor>())
|
||||
if (auto editor = SHSystemManager::GetSystem<SHEditor>())
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<FolderPointer> selectedFolders;
|
||||
std::vector<AssetID> selectedAssets;
|
||||
static constexpr float tileWidth = 50.0f;
|
||||
bool queueReset = false;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue