98 lines
2.8 KiB
ActionScript

string selectedResource = "";
class ResourceExplorer : Panel {
string currentPath = "";
array<string> subFolders;
array<string> subFiles;
void init() {
setPath("");
}
void setPath(string&in path) {
currentPath = path;
subFolders = Resource::getResourceFolders(path);
subFiles = Resource::getResourceFiles(path);
}
void render() {
renderMenuBar();
UI::space();
UI::automaticColumns(160);
string temp_path = currentPath;
// Render navigation folders
for (uint i = 0; i < subFolders.length(); i++) {
if (UI::cartIconButton(Path::getName(subFolders[i]), "folder.png", 64, UI::getAvailableSizeX())) {
setPath(subFolders[i]);
}
UI::nextColumn();
}
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 (UI::cartIconButton(Path::getName(filename), "mesh.png", 64, UI::getAvailableSizeX())) {
selectedResource = filename;
}
UI::nextColumn();
return;
}
if (resType == ResourceType::Shader) {
if (UI::cartIconButton(Path::getName(filename), "shader.png", 64, UI::getAvailableSizeX())) {
selectedResource = filename;
}
UI::nextColumn();
return;
}
if (resType == ResourceType::Texture) {
Texture texture = Resource::loadTexture(filename);
if (UI::cartIconButton(Path::getName(filename), "texture.png", 64, UI::getAvailableSizeX())) {
selectedResource = filename;
}
UI::nextColumn();
return;
}
UI::cartIconButton(Path::getName(filename), "file.png", 64, UI::getAvailableSizeX());
UI::nextColumn();
}
void renderMenuBar() {
// 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);
}
}
}
}