2025-07-20 12:25:26 +02:00

114 lines
3.4 KiB
ActionScript

class AssetExplorer : DockPanel {
AssetType searchAssetType = AssetType::None;
string currentPath = "";
void onRender() {
renderTopBar();
UI::setupAutomaticColumns(128);
if (searchAssetType == AssetType::None) {
searchAssetType = renderRootAssets();
UI::setupColumns(1);
return;
}
string temp_path = currentPath;
// Render navigation folders
int folderCount = Assets::getDirCount(searchAssetType, temp_path);
for (int i = 0; i < folderCount; i++) {
if (drawFolder(Assets::getDirNameById(AssetType::Mesh, temp_path, i)))
currentPath = Assets::getDirPathById(AssetType::Mesh, temp_path, i);
}
switch (searchAssetType) {
case AssetType::Mesh:
renderMeshes(temp_path);
break;
case AssetType::Shader:
renderShaders(temp_path);
break;
}
}
void renderMeshes(string&in dir) {
int assetCount = Assets::getAssetCount(AssetType::Mesh, dir);
for (int i = 0; i < assetCount; i++) {
drawFile(
Assets::getAssetNameById(AssetType::Mesh, dir, i),
"MESH",
any(Assets::getAssetTypePathById(AssetType::Mesh, dir, i)),
Assets::getAssetTypePathById(AssetType::Mesh, dir, i));
}
}
void renderShaders(string&in dir) {
int assetCount = Assets::getAssetCount(AssetType::Shader, dir);
for (int i = 0; i < assetCount; i++) {
drawFile(
Assets::getAssetNameById(AssetType::Shader, dir, i),
"SHADER",
any(Assets::getAssetTypePathById(AssetType::Shader, dir, i)),
Assets::getAssetTypePathById(AssetType::Shader, dir, i));
}
}
void renderTopBar() {
UI::text("\t");
UI::sameline();
if (UI::button("Assets")) {
searchAssetType = AssetType::None;
currentPath = "";
}
if (searchAssetType != AssetType::None) {
UI::sameline();
UI::text("/");
UI::sameline();
switch (searchAssetType) {
case AssetType::Mesh :
if (UI::button("Meshes")) {
currentPath = "";
}
break;
case AssetType::Shader :
if (UI::button("Shaders")) {
currentPath = "";
}
break;
default:
UI::text("Error");
break;
}
if (currentPath != "") {
array<string>@ paths = Engine::dividePath(currentPath);
for (uint i = 0; i < paths.length(); i++) {
UI::sameline();
UI::text("/");
UI::sameline();
// If we select that path
if (UI::button(paths[i])) {
// We obtain that pat
string changePath = "";
for (uint z = 0; z <= i; z++) {
if (z != 0)
changePath += "/";
changePath += paths[z];
}
currentPath = changePath;
}
}
}
}
}
}