Asset browser updated - drag and drop concept implemented, double clicking on folder in content window will open the folder

gui_api_redesign
Joey Pollack 4 years ago
parent c3df5775d0
commit a80d98d0c0

@ -19,7 +19,7 @@ namespace editor
{ {
AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor) AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor)
: Panel("Asset Browser", gui::PanelDockZone::DDZ_BOTTOM, true), : Panel("Asset Browser", gui::PanelDockZone::DDZ_BOTTOM, true),
mAssetDirectory(dir), mTreeRoot(nullptr), mSelectedNode(nullptr), mpEditor(pEditor) mAssetDirectory(dir), mTreeRoot(nullptr), mSelectedNode(nullptr), mpEditor(pEditor), mNewFolder(false), mSyncTree(false)
{ {
mTreeRoot = ReloadAssets(mAssetDirectory); mTreeRoot = ReloadAssets(mAssetDirectory);
mSelectedNode = mTreeRoot; mSelectedNode = mTreeRoot;
@ -58,6 +58,7 @@ namespace editor
if (ImGui::BeginChild("Directory Tree", ImVec2(wind_size.x * 0.15f, wind_size.y), true, ImGuiWindowFlags_NoCollapse)) if (ImGui::BeginChild("Directory Tree", ImVec2(wind_size.x * 0.15f, wind_size.y), true, ImGuiWindowFlags_NoCollapse))
{ {
DoDirTree(mAssetDirectory); DoDirTree(mAssetDirectory);
mSyncTree = false;
} }
ImGui::EndChild(); ImGui::EndChild();
@ -85,6 +86,24 @@ namespace editor
// } // }
// } // }
// List directories
for(auto const& dir_entry: std::filesystem::directory_iterator{mSelectedDir})
{
if (dir_entry.is_directory())
{
ImGui::Text("DIRECTORY: %s", dir_entry.path().filename().string().c_str());
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
// TODO: Open relevant editor
Logger::Info(Editor::LogCat, "Directory double clicked on. Open Folder");
// This will force open the tree nodes on the next update so the tree is synced with the content window
mSelectedDir = dir_entry.path();
mSyncTree = true;
}
}
}
std::filesystem::path selected_final = mpEditor->GetProject()->MakeRelativeToAssets(mSelectedDir); std::filesystem::path selected_final = mpEditor->GetProject()->MakeRelativeToAssets(mSelectedDir);
std::vector<EditorAsset*> assets; std::vector<EditorAsset*> assets;
ContentManager::GetInstance().GetAllAssetsInDirectory(assets, selected_final); ContentManager::GetInstance().GetAllAssetsInDirectory(assets, selected_final);
@ -96,7 +115,12 @@ namespace editor
// TODO: Show properties if this is new selection (meaning wasn't selected last frame) // TODO: Show properties if this is new selection (meaning wasn't selected last frame)
Logger::Info(Editor::LogCat, "Asset selected. Properties shold show in the PropertiesView Panel"); Logger::Info(Editor::LogCat, "Asset selected. Properties shold show in the PropertiesView Panel");
} }
if (ImGui::BeginDragDropSource())
{
ImGui::SetDragDropPayload("EditorAsset", (void*)(*iter), sizeof(EditorAsset));
ImGui::Text("%s", (*iter)->GetFileLocation().stem().string().c_str());
ImGui::EndDragDropSource();
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{ {
// TODO: Open relevant editor // TODO: Open relevant editor
@ -104,15 +128,7 @@ namespace editor
} }
} }
if (ImGui::BeginPopupContextWindow(0, 1, false)) DoContextMenu();
{
if (ImGui::Button("Click Me!"))
{
Logger::Info(Editor::LogCat, "Context menu button clicked!");
}
ImGui::EndPopup();
}
} }
} }
ImGui::EndChild(); ImGui::EndChild();
@ -129,9 +145,30 @@ namespace editor
if (!std::filesystem::is_directory(dir)) if (!std::filesystem::is_directory(dir))
return; return;
if (ImGui::TreeNode(dir.filename().string().c_str())) std::string next_node_name = dir.filename().string();
if (mSyncTree && mSelectedDir.string().find(next_node_name) != std::string::npos)
{
ImGui::SetNextItemOpen(true);
}
if (ImGui::TreeNode(next_node_name.c_str()))
{
if (!mSyncTree)
{ {
mSelectedDir = dir; mSelectedDir = dir;
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("EditorAsset"))
{
EditorAsset* pAsset = (EditorAsset*) payload->Data;
Logger::Info(Editor::LogCat, "Dropping asset: %s - To: %s",
pAsset->GetFileLocation().stem().string().c_str(), mSelectedDir.string().c_str());
// TODO: Handle moving the asset
}
ImGui::EndDragDropTarget();
}
}
for(auto const& dir_entry: std::filesystem::directory_iterator{dir}) for(auto const& dir_entry: std::filesystem::directory_iterator{dir})
{ {
DoDirTree(dir_entry); DoDirTree(dir_entry);
@ -140,6 +177,37 @@ namespace editor
} }
} }
void AssetBrowser::DoContextMenu()
{
if (ImGui::BeginPopupContextWindow(0, 1, false))
{
if (ImGui::Button("New Folder"))
{
mNewFolder = true;
}
// TODO: Buttons for creating/importing new assets
ImGui::EndPopup();
}
if (ImGui::BeginPopupContextItem("New Folder Name"))
{
char name_buf[64] = "New Folder";
ImGui::TextUnformatted("Folder Name: ");
ImGui::SameLine();
if (ImGui::InputText("##Folder Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
{
std::filesystem::create_directory(mSelectedDir / name_buf);
mNewFolder = false;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
if (mNewFolder)
ImGui::OpenPopup("New Folder Name");
}
AssetBrowser::Node* AssetBrowser::ReloadAssets(std::filesystem::path dir) AssetBrowser::Node* AssetBrowser::ReloadAssets(std::filesystem::path dir)
{ {
if ("" == dir) if ("" == dir)

@ -44,12 +44,15 @@ namespace editor
Node* mTreeRoot; Node* mTreeRoot;
Node* mSelectedNode; Node* mSelectedNode;
Editor* mpEditor; Editor* mpEditor;
bool mNewFolder;
bool mSyncTree;
private: private:
Node* ReloadAssets(std::filesystem::path dir); Node* ReloadAssets(std::filesystem::path dir);
Node* FindNodeAt(std::filesystem::path dir); Node* FindNodeAt(std::filesystem::path dir);
void DoDirTree(std::filesystem::path dir); void DoDirTree(std::filesystem::path dir);
void DoContextMenu();
}; };
} }
} }

Loading…
Cancel
Save