parent
57941cd2dc
commit
aad83d9e32
|
@ -36,27 +36,13 @@ namespace SHADE
|
||||||
DrawCurrentFolder();
|
DrawCurrentFolder();
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
if (queueReset)
|
|
||||||
{
|
|
||||||
SHAssetManager::RefreshDirectory();
|
|
||||||
rootFolder = SHAssetManager::GetRootFolder();
|
|
||||||
queueReset = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SHAssetBrowser::Refresh()
|
|
||||||
{
|
|
||||||
queueReset = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAssetBrowser::DrawMenuBar()
|
void SHAssetBrowser::DrawMenuBar()
|
||||||
{
|
{
|
||||||
if (ImGui::BeginMenuBar())
|
if (ImGui::BeginMenuBar())
|
||||||
{
|
{
|
||||||
if(ImGui::SmallButton("Refresh"))
|
|
||||||
{
|
|
||||||
Refresh();
|
|
||||||
}
|
|
||||||
ImGui::EndMenuBar();
|
ImGui::EndMenuBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,14 +102,16 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
for (auto const& file : files)
|
for (auto const& file : files)
|
||||||
{
|
{
|
||||||
|
if(file.assetMeta == nullptr)
|
||||||
|
continue;
|
||||||
const float horizontalLineSize = 25.0f;
|
const float horizontalLineSize = 25.0f;
|
||||||
const ImRect childRect = DrawFile(file);
|
const ImRect childRect = DrawFile(file.assetMeta);
|
||||||
const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f;
|
const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f;
|
||||||
drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1);
|
drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1);
|
||||||
vertLineEnd.y = midPoint;
|
vertLineEnd.y = midPoint;
|
||||||
}
|
}
|
||||||
drawList->AddLine(vertLineStart, vertLineEnd, treeLineColor, 1);
|
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();
|
DrawAssetBeingCreated();
|
||||||
|
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
|
@ -160,40 +148,12 @@ namespace SHADE
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImRect SHAssetBrowser::DrawFile(SHFile file) noexcept
|
ImRect SHAssetBrowser::DrawFile(SHAsset const* const asset) noexcept
|
||||||
{
|
{
|
||||||
|
if (asset == nullptr)
|
||||||
SHAsset const* const asset = file.assetMeta;
|
return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
|
||||||
if (file.compilable)
|
const bool isSelected = std::ranges::find(selectedAssets, asset->id) != selectedAssets.end();
|
||||||
{
|
ImGuiTreeNodeFlags flags = (!asset->subAssets.empty()) ? ImGuiTreeNodeFlags_OpenOnArrow : ImGuiTreeNodeFlags_Leaf;
|
||||||
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)
|
if (isSelected)
|
||||||
flags |= ImGuiTreeNodeFlags_Selected;
|
flags |= ImGuiTreeNodeFlags_Selected;
|
||||||
std::string icon{};
|
std::string icon{};
|
||||||
|
@ -212,11 +172,9 @@ namespace SHADE
|
||||||
case AssetType::MAX_COUNT: break;
|
case AssetType::MAX_COUNT: break;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool const isOpen = ImGui::TreeNodeEx(asset, flags, "%s %s", icon.data(), asset->name.data());
|
bool const isOpen = ImGui::TreeNodeEx(asset, flags, "%s %s", icon.data(), asset->name.data());
|
||||||
const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
|
const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
|
||||||
|
|
||||||
|
|
||||||
if (SHDragDrop::BeginSource())
|
if (SHDragDrop::BeginSource())
|
||||||
{
|
{
|
||||||
auto id = asset->id;
|
auto id = asset->id;
|
||||||
|
@ -239,7 +197,7 @@ namespace SHADE
|
||||||
case AssetType::TEXTURE: break;
|
case AssetType::TEXTURE: break;
|
||||||
case AssetType::MESH: break;
|
case AssetType::MESH: break;
|
||||||
case AssetType::SCENE:
|
case AssetType::SCENE:
|
||||||
if (auto editor = SHSystemManager::GetSystem<SHEditor>())
|
if(auto editor = SHSystemManager::GetSystem<SHEditor>())
|
||||||
{
|
{
|
||||||
editor->LoadScene(asset->id);
|
editor->LoadScene(asset->id);
|
||||||
}
|
}
|
||||||
|
@ -264,12 +222,12 @@ namespace SHADE
|
||||||
ImVec2 vertLineStart = ImGui::GetCursorScreenPos();
|
ImVec2 vertLineStart = ImGui::GetCursorScreenPos();
|
||||||
vertLineStart.x += horizontalOffset;
|
vertLineStart.x += horizontalOffset;
|
||||||
ImVec2 vertLineEnd = vertLineStart;
|
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 float horizontalLineSize = 25.0f;
|
||||||
const ImRect childRect = DrawAsset(subAsset);
|
const ImRect childRect = DrawFile(subAsset);
|
||||||
const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f;
|
const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f;
|
||||||
drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1);
|
drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1);
|
||||||
vertLineEnd.y = midPoint;
|
vertLineEnd.y = midPoint;
|
||||||
|
@ -295,7 +253,6 @@ namespace SHADE
|
||||||
matInspector->OpenMaterial(assetId, true);
|
matInspector->OpenMaterial(assetId, true);
|
||||||
}
|
}
|
||||||
assetBeingCreated.reset();
|
assetBeingCreated.reset();
|
||||||
Refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,7 @@ namespace SHADE
|
||||||
void DrawMenuBar();
|
void DrawMenuBar();
|
||||||
ImRect RecursivelyDrawTree(FolderPointer folder);
|
ImRect RecursivelyDrawTree(FolderPointer folder);
|
||||||
void DrawCurrentFolder();
|
void DrawCurrentFolder();
|
||||||
ImRect DrawFile(SHFile file) noexcept;
|
ImRect DrawFile(SHAsset const* const asset) noexcept;
|
||||||
ImRect DrawAsset(SHAsset const* const asset);
|
|
||||||
void DrawAssetBeingCreated() noexcept;
|
void DrawAssetBeingCreated() noexcept;
|
||||||
|
|
||||||
FolderPointer rootFolder, prevFolder, currentFolder;
|
FolderPointer rootFolder, prevFolder, currentFolder;
|
||||||
|
@ -30,6 +29,5 @@ namespace SHADE
|
||||||
std::vector<FolderPointer> selectedFolders;
|
std::vector<FolderPointer> selectedFolders;
|
||||||
std::vector<AssetID> selectedAssets;
|
std::vector<AssetID> selectedAssets;
|
||||||
static constexpr float tileWidth = 50.0f;
|
static constexpr float tileWidth = 50.0f;
|
||||||
bool queueReset = false;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue