92 lines
2.7 KiB
ActionScript

class ResourceExplorer : DockPanel {
string currentPath = "";
array<string> subFolders;
array<string> subFiles;
void onInit() {
setPath("");
}
void setPath(string&in path) {
currentPath = path;
subFolders = Resource::getResourceFolders(path);
subFiles = Resource::getResourceFiles(path);
}
void onRender() {
renderTopBar();
UI::automaticColumns(160);
string temp_path = currentPath;
// Render navigation folders
for (uint i = 0; i < subFolders.length(); i++) {
if (drawFolder(Path::getName(subFolders[i]))) {
setPath(subFolders[i]);
}
}
for (uint i = 0; i < subFiles.length(); i++) {
drawResource(subFiles[i]);
}
}
void drawResource(string&in filename) {
ResourceType resType = Resource::getResourceType(filename);
bool selected = filename == selectedResource;
if (resType == ResourceType::Mesh) {
if (drawFileIcon(Path::getName(filename), "MESH", any(filename), Path::getName(filename), "mesh.png", selected)) {
selectedResource = filename;
}
return;
}
if (resType == ResourceType::Shader) {
if (drawFileIcon(Path::getName(filename), "SHADER", any(filename), Path::getName(filename), "shader.png", selected)) {
selectedResource = filename;
}
return;
}
if (resType == ResourceType::Texture) {
TextureResource textureResource = Resource::loadTexture(filename);
if (drawTextureIcon(Path::getName(filename), "TEXTURE", any(textureResource), Path::getName(filename), textureResource, selected)) {
selectedResource = filename;
}
return;
}
drawIcon(Path::getName(filename), "file.png");
}
void renderTopBar() {
UI::text("\t");
UI::sameline();
// If we select that path
if (UI::button("Resources")) {
setPath("");
}
array<string>@ paths = Path::divide(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];
}
setPath(changePath);
}
}
}
}