From a02469b935acc7e17e8f23e8f7eb38dfef098cfb Mon Sep 17 00:00:00 2001 From: Chewico Date: Wed, 2 Jul 2025 23:01:54 +0200 Subject: [PATCH] Working on Asset Manager Explorer --- DeerStudio/imgui.ini | 4 +- .../src/DeerStudio/EditorEngine/API/Asset.h | 3 + .../src/DeerStudio/EditorEngine/API/Service.h | 6 -- .../API_Implementation/Resource.cpp | 8 ++ .../API_Registration/RegisterFunctions.cpp | 4 + .../experiments/Subfolder/Example.dmesh | 0 .../Panels/AssetExplorer/AssetExplorer.as | 10 ++- roe/Editor/Panels/AssetExplorer/IconRender.as | 28 +++++++ .../Panels/AssetExplorer/MeshExplorer.as | 73 ++++++++----------- .../{Generics.as => RootAssets.as} | 2 +- roe/Editor/Panels/AssetExplorer/as.predefined | 4 + .../Panels/EntityManipulation/as.predefined | 4 + roe/Editor/Panels/TreeExplorer/as.predefined | 4 + roe/Editor/Panels/Viewport/as.predefined | 4 + .../Services/ActiveEntity/as.predefined | 2 + 15 files changed, 103 insertions(+), 53 deletions(-) delete mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API/Service.h create mode 100644 roe/Assets/Meshes/experiments/Subfolder/Example.dmesh rename roe/Editor/Panels/AssetExplorer/{Generics.as => RootAssets.as} (92%) diff --git a/DeerStudio/imgui.ini b/DeerStudio/imgui.ini index cc8a51b..3bfee56 100644 --- a/DeerStudio/imgui.ini +++ b/DeerStudio/imgui.ini @@ -30,7 +30,7 @@ DockId=0x00000005,1 Pos=0,439 Size=1280,281 Collapsed=0 -DockId=0x00000004,1 +DockId=0x00000004,0 [Window][TreePannel] Pos=0,24 @@ -76,7 +76,7 @@ DockId=0x00000005,2 Pos=0,439 Size=1280,281 Collapsed=0 -DockId=0x00000004,2 +DockId=0x00000004,1 [Docking][Data] DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y Selected=0x34A4C10F diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Asset.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Asset.h index e180000..b10ac67 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/Asset.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Asset.h @@ -27,6 +27,9 @@ namespace Deer { // dir std::string getDirNameById(AssetType, std::string& dir, int i); + std::string getParentPath(std::string&); + std::string getParentPathName(std::string&); + // INTERNAL const char* getAssetTypePath(AssetType); const char* getAssetTypeExtension(AssetType); diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Service.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Service.h deleted file mode 100644 index b7a6a6c..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/Service.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -namespace Deer { - namespace EditorEngine { - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/Resource.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/Resource.cpp index 132597e..a598ac2 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/Resource.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/Resource.cpp @@ -100,6 +100,14 @@ namespace Deer { return dirData.elements[i].stem().string(); } + std::string getParentPath(std::string& path) { + return Path(path).parent_path().string(); + } + + std::string getParentPathName(std::string& path) { + return Path(path).parent_path().stem().string(); + } + std::string getAssetTypePathById(AssetType type, std::string& dir, int i) { const char* resourcePath = getAssetTypePath(type); diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/RegisterFunctions.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/RegisterFunctions.cpp index 25a2c05..4ba8e29 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/RegisterFunctions.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/RegisterFunctions.cpp @@ -42,6 +42,10 @@ namespace Deer { scriptEngine->SetDefaultNamespace("Engine"); REGISTER_GLOBAL_FUNC("void print(const string& in)", print); + REGISTER_GLOBAL_FUNC("string getParentPath(const string&in)", + getParentPath); + REGISTER_GLOBAL_FUNC("string getParentPathName(const string&in)", + getParentPathName); scriptEngine->SetDefaultNamespace(""); scriptEngine->SetDefaultNamespace("UI"); diff --git a/roe/Assets/Meshes/experiments/Subfolder/Example.dmesh b/roe/Assets/Meshes/experiments/Subfolder/Example.dmesh new file mode 100644 index 0000000..e69de29 diff --git a/roe/Editor/Panels/AssetExplorer/AssetExplorer.as b/roe/Editor/Panels/AssetExplorer/AssetExplorer.as index e5cbd97..edeebf3 100644 --- a/roe/Editor/Panels/AssetExplorer/AssetExplorer.as +++ b/roe/Editor/Panels/AssetExplorer/AssetExplorer.as @@ -6,7 +6,15 @@ class AssetExplorer : DockPanel { UI::setupAutomaticColumns(128); if (searchAssetType == AssetType::None) { - searchAssetType = renderGenerics(); + searchAssetType = renderRootAssets(); + } + + if (searchAssetType == AssetType::Mesh) { + currentPath = renderMeshExplorer(currentPath); + if (currentPath == "..") { + searchAssetType = AssetType::None; + currentPath = ""; + } } } } diff --git a/roe/Editor/Panels/AssetExplorer/IconRender.as b/roe/Editor/Panels/AssetExplorer/IconRender.as index 8338f53..ea87afd 100644 --- a/roe/Editor/Panels/AssetExplorer/IconRender.as +++ b/roe/Editor/Panels/AssetExplorer/IconRender.as @@ -10,3 +10,31 @@ bool drawFolder(string&in name) { UI::nextColumn(); return click; } + +bool drawFile(string&in name) { + bool click = false; + UI::drawIconCentered("file", 64); + if (UI::isItemClicked(0) and UI::isMouseDoubleClicked(0)) { + click = true; + } + + UI::textCenter(name); + UI::nextColumn(); + return click; +} + +bool drawFile(string&in name, string&in dragId, any dragData, string&in overlay) { + bool click = false; + UI::drawIconCentered("file", 64); + if (UI::isItemClicked(0) and UI::isMouseDoubleClicked(0)) { + click = true; + } + + UI::dragDropSource(dragId, + dragData, + overlay); + + UI::textCenter(name); + UI::nextColumn(); + return click; +} diff --git a/roe/Editor/Panels/AssetExplorer/MeshExplorer.as b/roe/Editor/Panels/AssetExplorer/MeshExplorer.as index 6da1ec4..d295f17 100644 --- a/roe/Editor/Panels/AssetExplorer/MeshExplorer.as +++ b/roe/Editor/Panels/AssetExplorer/MeshExplorer.as @@ -1,46 +1,33 @@ -class MeshExplorer : DockPanel { - string currentPath = ""; - - void onRender() { - - UI::setupAutomaticColumns(128); - - // To avoid problems we will cache the current path - const string cache_currentPath = currentPath; - if (cache_currentPath != "") { - UI::drawIconCentered("folder", 64); - if (UI::isItemClicked(0) and UI::isMouseDoubleClicked(0)) { - currentPath = ""; - } - UI::textCenter(cache_currentPath + "/.."); - UI::nextColumn(); +string renderMeshExplorer(string&in dir) { + string return_dir = dir; + + if (dir == "") { + if (drawFolder("Assets/..")) { + return_dir = ".."; } - - AssetType resourceType = AssetType::Mesh; - int dirCount = Assets::getDirCount(resourceType, cache_currentPath); - for (int i = 0; i < dirCount; i++) { - UI::drawIconCentered("folder", 64); - - if (UI::isItemClicked(0) and UI::isMouseDoubleClicked(0)) { - Engine::print(Assets::getDirPathById(AssetType::Mesh, cache_currentPath, i)); - currentPath = Assets::getDirPathById(AssetType::Mesh, cache_currentPath, i); - } - - UI::textCenter(Assets::getDirNameById(AssetType::Mesh, cache_currentPath, i)); - UI::nextColumn(); - } - - int meshCount = Assets::getAssetCount(AssetType::Mesh, cache_currentPath); - for (int i = 0; i < meshCount; i++) { - UI::drawIconCentered("file", 64); - UI::dragDropSource("MESH", - any(Assets::getAssetTypePathById(AssetType::Mesh, cache_currentPath, i)), - Assets::getAssetTypePathById(AssetType::Mesh, cache_currentPath, i)); - - UI::textCenter(Assets::getAssetNameById(AssetType::Mesh, cache_currentPath, i)); - UI::nextColumn(); - } - UI::endColumns(); - } + + if (dir != "" && drawFolder(Engine::getParentPathName(dir) + "/..")) { + return_dir = Engine::getParentPath(dir); + } + + AssetType resourceType = AssetType::Mesh; + + int dirCount = Assets::getDirCount(resourceType, dir); + for (int i = 0; i < dirCount; i++) { + if (drawFolder(Assets::getDirNameById(AssetType::Mesh, dir, i))) { + return_dir = Assets::getDirPathById(AssetType::Mesh, dir, i); + } + } + + //int meshCount = Assets::getAssetCount(AssetType::Mesh, dir); + //for (int i = 0; i < meshCount; i++) { + // drawFile( + // Assets::getAssetNameById(AssetType::Mesh, dir, i), + // "MESH", + // any(Assets::getAssetTypePathById(AssetType::Mesh, dir, i)), + // Assets::getAssetTypePathById(AssetType::Mesh, dir, i)); + //} + + return return_dir; } diff --git a/roe/Editor/Panels/AssetExplorer/Generics.as b/roe/Editor/Panels/AssetExplorer/RootAssets.as similarity index 92% rename from roe/Editor/Panels/AssetExplorer/Generics.as rename to roe/Editor/Panels/AssetExplorer/RootAssets.as index 55f4f02..0403e47 100644 --- a/roe/Editor/Panels/AssetExplorer/Generics.as +++ b/roe/Editor/Panels/AssetExplorer/RootAssets.as @@ -1,5 +1,5 @@ // Here we render the base folders -AssetType renderGenerics() { +AssetType renderRootAssets() { AssetType selectedAssetType = AssetType::None; if (drawFolder("Scripts")) selectedAssetType = AssetType::None; diff --git a/roe/Editor/Panels/AssetExplorer/as.predefined b/roe/Editor/Panels/AssetExplorer/as.predefined index 1e93a8f..3051b62 100644 --- a/roe/Editor/Panels/AssetExplorer/as.predefined +++ b/roe/Editor/Panels/AssetExplorer/as.predefined @@ -389,6 +389,8 @@ namespace Assets { int getDirCount(AssetType, const string&in); } namespace Assets { string getDirPathById(AssetType, const string&in, int); } namespace Assets { string getDirNameById(AssetType, const string&in, int); } namespace Engine { void print(const string&in); } +namespace Engine { string getParentPath(const string&in); } +namespace Engine { string getParentPathName(const string&in); } namespace UI { void treeNodeLeaf(const string&in, bool); } namespace UI { bool treeNode(const string&in, bool, any@, ReciverFunc@); } namespace UI { bool componentNode(const string&in, any@, ReciverFunc@); } @@ -792,6 +794,8 @@ namespace Assets { int getDirCount(AssetType, const string&in); } namespace Assets { string getDirPathById(AssetType, const string&in, int); } namespace Assets { string getDirNameById(AssetType, const string&in, int); } namespace Engine { void print(const string&in); } +namespace Engine { string getParentPath(const string&in); } +namespace Engine { string getParentPathName(const string&in); } namespace UI { void treeNodeLeaf(const string&in, bool); } namespace UI { bool treeNode(const string&in, bool, any@, ReciverFunc@); } namespace UI { bool componentNode(const string&in, any@, ReciverFunc@); } diff --git a/roe/Editor/Panels/EntityManipulation/as.predefined b/roe/Editor/Panels/EntityManipulation/as.predefined index 1e93a8f..3051b62 100644 --- a/roe/Editor/Panels/EntityManipulation/as.predefined +++ b/roe/Editor/Panels/EntityManipulation/as.predefined @@ -389,6 +389,8 @@ namespace Assets { int getDirCount(AssetType, const string&in); } namespace Assets { string getDirPathById(AssetType, const string&in, int); } namespace Assets { string getDirNameById(AssetType, const string&in, int); } namespace Engine { void print(const string&in); } +namespace Engine { string getParentPath(const string&in); } +namespace Engine { string getParentPathName(const string&in); } namespace UI { void treeNodeLeaf(const string&in, bool); } namespace UI { bool treeNode(const string&in, bool, any@, ReciverFunc@); } namespace UI { bool componentNode(const string&in, any@, ReciverFunc@); } @@ -792,6 +794,8 @@ namespace Assets { int getDirCount(AssetType, const string&in); } namespace Assets { string getDirPathById(AssetType, const string&in, int); } namespace Assets { string getDirNameById(AssetType, const string&in, int); } namespace Engine { void print(const string&in); } +namespace Engine { string getParentPath(const string&in); } +namespace Engine { string getParentPathName(const string&in); } namespace UI { void treeNodeLeaf(const string&in, bool); } namespace UI { bool treeNode(const string&in, bool, any@, ReciverFunc@); } namespace UI { bool componentNode(const string&in, any@, ReciverFunc@); } diff --git a/roe/Editor/Panels/TreeExplorer/as.predefined b/roe/Editor/Panels/TreeExplorer/as.predefined index 1e93a8f..3051b62 100644 --- a/roe/Editor/Panels/TreeExplorer/as.predefined +++ b/roe/Editor/Panels/TreeExplorer/as.predefined @@ -389,6 +389,8 @@ namespace Assets { int getDirCount(AssetType, const string&in); } namespace Assets { string getDirPathById(AssetType, const string&in, int); } namespace Assets { string getDirNameById(AssetType, const string&in, int); } namespace Engine { void print(const string&in); } +namespace Engine { string getParentPath(const string&in); } +namespace Engine { string getParentPathName(const string&in); } namespace UI { void treeNodeLeaf(const string&in, bool); } namespace UI { bool treeNode(const string&in, bool, any@, ReciverFunc@); } namespace UI { bool componentNode(const string&in, any@, ReciverFunc@); } @@ -792,6 +794,8 @@ namespace Assets { int getDirCount(AssetType, const string&in); } namespace Assets { string getDirPathById(AssetType, const string&in, int); } namespace Assets { string getDirNameById(AssetType, const string&in, int); } namespace Engine { void print(const string&in); } +namespace Engine { string getParentPath(const string&in); } +namespace Engine { string getParentPathName(const string&in); } namespace UI { void treeNodeLeaf(const string&in, bool); } namespace UI { bool treeNode(const string&in, bool, any@, ReciverFunc@); } namespace UI { bool componentNode(const string&in, any@, ReciverFunc@); } diff --git a/roe/Editor/Panels/Viewport/as.predefined b/roe/Editor/Panels/Viewport/as.predefined index 1e93a8f..3051b62 100644 --- a/roe/Editor/Panels/Viewport/as.predefined +++ b/roe/Editor/Panels/Viewport/as.predefined @@ -389,6 +389,8 @@ namespace Assets { int getDirCount(AssetType, const string&in); } namespace Assets { string getDirPathById(AssetType, const string&in, int); } namespace Assets { string getDirNameById(AssetType, const string&in, int); } namespace Engine { void print(const string&in); } +namespace Engine { string getParentPath(const string&in); } +namespace Engine { string getParentPathName(const string&in); } namespace UI { void treeNodeLeaf(const string&in, bool); } namespace UI { bool treeNode(const string&in, bool, any@, ReciverFunc@); } namespace UI { bool componentNode(const string&in, any@, ReciverFunc@); } @@ -792,6 +794,8 @@ namespace Assets { int getDirCount(AssetType, const string&in); } namespace Assets { string getDirPathById(AssetType, const string&in, int); } namespace Assets { string getDirNameById(AssetType, const string&in, int); } namespace Engine { void print(const string&in); } +namespace Engine { string getParentPath(const string&in); } +namespace Engine { string getParentPathName(const string&in); } namespace UI { void treeNodeLeaf(const string&in, bool); } namespace UI { bool treeNode(const string&in, bool, any@, ReciverFunc@); } namespace UI { bool componentNode(const string&in, any@, ReciverFunc@); } diff --git a/roe/Editor/Services/ActiveEntity/as.predefined b/roe/Editor/Services/ActiveEntity/as.predefined index f9b8e36..73e8fef 100644 --- a/roe/Editor/Services/ActiveEntity/as.predefined +++ b/roe/Editor/Services/ActiveEntity/as.predefined @@ -389,6 +389,8 @@ namespace Assets { int getDirCount(AssetType, const string&in); } namespace Assets { string getDirPathById(AssetType, const string&in, int); } namespace Assets { string getDirNameById(AssetType, const string&in, int); } namespace Engine { void print(const string&in); } +namespace Engine { string getParentPath(const string&in); } +namespace Engine { string getParentPathName(const string&in); } namespace UI { void treeNodeLeaf(const string&in, bool); } namespace UI { bool treeNode(const string&in, bool, any@, ReciverFunc@); } namespace UI { bool componentNode(const string&in, any@, ReciverFunc@); }