|
|
|
|
@ -7,11 +7,14 @@
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "asset_browser.h"
|
|
|
|
|
#include <gui/gui.h>
|
|
|
|
|
#include <dearimgui/imgui.h>
|
|
|
|
|
#include <editor/editor.h>
|
|
|
|
|
#include <editor/contents/content_manager.h>
|
|
|
|
|
#include <editor/contents/editor_asset.h>
|
|
|
|
|
#include <utils/logger.h>
|
|
|
|
|
#include <assets/types/image.h>
|
|
|
|
|
#include <internal_data/data_manager.h>
|
|
|
|
|
|
|
|
|
|
namespace lunarium
|
|
|
|
|
{
|
|
|
|
|
@ -19,10 +22,8 @@ namespace editor
|
|
|
|
|
{
|
|
|
|
|
AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor)
|
|
|
|
|
: Panel("Asset Browser", gui::PanelDockZone::DDZ_BOTTOM, true),
|
|
|
|
|
mAssetDirectory(dir), mTreeRoot(nullptr), mSelectedNode(nullptr), mpEditor(pEditor), mNewFolder(false), mSyncTree(false)
|
|
|
|
|
mAssetDirectory(dir), mpEditor(pEditor), mNewFolder(false), mSyncTree(false)
|
|
|
|
|
{
|
|
|
|
|
mTreeRoot = ReloadAssets(mAssetDirectory);
|
|
|
|
|
mSelectedNode = mTreeRoot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AssetBrowser::SetAssetDirectory(std::filesystem::path dir)
|
|
|
|
|
@ -66,6 +67,63 @@ namespace editor
|
|
|
|
|
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + wind_size.x * 0.15f);
|
|
|
|
|
|
|
|
|
|
// Contents
|
|
|
|
|
DoContentArea(wind_size);
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AssetBrowser::DoDirTree(std::filesystem::path dir)
|
|
|
|
|
{
|
|
|
|
|
if ("" == dir)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!std::filesystem::is_directory(dir))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::string next_node_name = dir.filename().string();
|
|
|
|
|
if (mSyncTree)
|
|
|
|
|
{
|
|
|
|
|
if (mSelectedDir.string().find(next_node_name) != std::string::npos)
|
|
|
|
|
{
|
|
|
|
|
ImGui::SetNextItemOpen(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ImGui::SetNextItemOpen(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::TreeNode(next_node_name.c_str()))
|
|
|
|
|
{
|
|
|
|
|
if (!mSyncTree)
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::IsItemClicked())
|
|
|
|
|
{
|
|
|
|
|
mSelectedDir = dir;
|
|
|
|
|
ImGui::SetNextItemOpen(false);
|
|
|
|
|
}
|
|
|
|
|
HandleAssetDrop(mSelectedDir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(auto const& dir_entry: std::filesystem::directory_iterator{dir})
|
|
|
|
|
{
|
|
|
|
|
DoDirTree(dir_entry);
|
|
|
|
|
}
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::IsItemClicked())
|
|
|
|
|
{
|
|
|
|
|
mSelectedDir = dir;
|
|
|
|
|
ImGui::SetNextItemOpen(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AssetBrowser::DoContentArea(ImVec2 wind_size)
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::BeginChild("Contents", ImVec2(wind_size.x * 0.85f, wind_size.y), true, ImGuiWindowFlags_NoCollapse))
|
|
|
|
|
{
|
|
|
|
|
if (std::filesystem::exists(mSelectedDir))
|
|
|
|
|
@ -74,7 +132,11 @@ namespace editor
|
|
|
|
|
float xPos = ImGui::GetCursorPosX();
|
|
|
|
|
float left = xPos;
|
|
|
|
|
|
|
|
|
|
ImGui::BeginChild("ToolBar", ImVec2(0, ImGui::GetFrameHeightWithSpacing()));
|
|
|
|
|
|
|
|
|
|
ImGui::BeginChild("ToolBar", ImVec2(0, ImGui::GetFrameHeightWithSpacing() * 1.5f));
|
|
|
|
|
ImGui::PushFont(GUI::GetInstance().GetFont(GuiFont::FONT_ROBO_SMALL));
|
|
|
|
|
ImGui::TextUnformatted(mpEditor->GetProject()->MakeRelativeToAssets(mSelectedDir, true).string().c_str());
|
|
|
|
|
ImGui::PopFont();
|
|
|
|
|
if (ImGui::Button("Back"))
|
|
|
|
|
{
|
|
|
|
|
mSelectedDir = mSelectedDir.parent_path();
|
|
|
|
|
@ -83,6 +145,7 @@ namespace editor
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::BeginChild("Files");
|
|
|
|
|
|
|
|
|
|
// List directories
|
|
|
|
|
@ -90,7 +153,10 @@ namespace editor
|
|
|
|
|
{
|
|
|
|
|
if (dir_entry.is_directory())
|
|
|
|
|
{
|
|
|
|
|
ImGui::Text("DIRECTORY: %s", dir_entry.path().filename().string().c_str());
|
|
|
|
|
ImGui::Image((ImTextureID)DataManager::mFolderIcon->GetGLTextureID64(),
|
|
|
|
|
ImVec2(DataManager::mFolderIcon->GetWidth(), DataManager::mFolderIcon->GetHeight()));
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::Selectable(dir_entry.path().filename().string().c_str());
|
|
|
|
|
HandleAssetDrop(dir_entry.path());
|
|
|
|
|
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
|
|
|
|
{
|
|
|
|
|
@ -136,46 +202,6 @@ namespace editor
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AssetBrowser::DoDirTree(std::filesystem::path dir)
|
|
|
|
|
{
|
|
|
|
|
if ("" == dir)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!std::filesystem::is_directory(dir))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::string next_node_name = dir.filename().string();
|
|
|
|
|
if (mSyncTree)
|
|
|
|
|
{
|
|
|
|
|
if (mSelectedDir.string().find(next_node_name) != std::string::npos)
|
|
|
|
|
{
|
|
|
|
|
ImGui::SetNextItemOpen(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ImGui::SetNextItemOpen(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::TreeNode(next_node_name.c_str()))
|
|
|
|
|
{
|
|
|
|
|
if (!mSyncTree)
|
|
|
|
|
{
|
|
|
|
|
mSelectedDir = dir;
|
|
|
|
|
HandleAssetDrop(mSelectedDir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(auto const& dir_entry: std::filesystem::directory_iterator{dir})
|
|
|
|
|
{
|
|
|
|
|
DoDirTree(dir_entry);
|
|
|
|
|
}
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AssetBrowser::DoContextMenu()
|
|
|
|
|
@ -209,29 +235,6 @@ namespace editor
|
|
|
|
|
ImGui::OpenPopup("New Folder Name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AssetBrowser::Node* AssetBrowser::ReloadAssets(std::filesystem::path dir)
|
|
|
|
|
{
|
|
|
|
|
if ("" == dir)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
Node* pNode = new Node;
|
|
|
|
|
pNode->Myself = dir;
|
|
|
|
|
for(auto const& dir_entry: std::filesystem::directory_iterator{dir})
|
|
|
|
|
{
|
|
|
|
|
if (std::filesystem::is_directory(dir_entry))
|
|
|
|
|
{
|
|
|
|
|
pNode->Children.push_back(ReloadAssets(dir_entry));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pNode->Files.push_back(dir_entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AssetBrowser::HandleAssetDrop(std::filesystem::path dir)
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::BeginDragDropTarget())
|
|
|
|
|
@ -252,25 +255,3 @@ namespace editor
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// void treeChildren(ImGuiTreeNodeFlags node_flags, bool isOpen, int index)
|
|
|
|
|
// {
|
|
|
|
|
// if (isOpen)
|
|
|
|
|
// {
|
|
|
|
|
// for (int p = 0; p < meshList[index].children.size(); p++)
|
|
|
|
|
// {
|
|
|
|
|
// if (meshList[index].children[p].children.empty())
|
|
|
|
|
// {
|
|
|
|
|
// node_flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; // ImGuiTreeNodeFlags_Bullet
|
|
|
|
|
// ImGui::TreeNodeEx((void *)(intptr_t)p, node_flags, meshList[index].children[p].name.c_str());
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// bool o = ImGui::TreeNodeEx((void *)(intptr_t)p, node_flags, meshList[index].children[p].name.c_str());
|
|
|
|
|
// ImGui::TreePop();
|
|
|
|
|
// treeChildren(node_flags, o, p);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// ImGui::TreePop();
|
|
|
|
|
// }
|
|
|
|
|
// }
|