2026-02-05 21:38:30 +01:00

121 lines
3.9 KiB
ActionScript

class ResourceExplorer : Panel {
string selectedResource = "";
string currentPath = "";
array<string> subFolders;
array<string> subFiles;
bool alreadyRendered = false;
float fase = 0;
dictionary meshFrameBuffer;
void onInit() {
print("hy");
setPath("");
}
void setPath(string&in path) {
meshFrameBuffer.deleteAll();
currentPath = path;
subFolders = StudioAPI::getResourceFolders(path);
subFiles = StudioAPI::getResourceFiles(path);
fase = 0;
}
void onImGui() {
alreadyRendered = false;
renderMenuBar();
ImGui::space();
fase += 0.3;
ImGui::automaticColumns(182);
string temp_path = currentPath;
// Render navigation folders
for (uint i = 0; i < subFolders.length(); i++) {
Texture folder = StudioAPI::loadIcon("folder.png");
if (ImGui::cartIconButton(Path::getName(subFolders[i]), folder, 128, ImGui::getAvailableSizeX())) {
setPath(subFolders[i]);
}
ImGui::nextColumn();
}
for ( uint i = 0; i < subFiles.length(); i++) {
drawResource(subFiles[i]);
}
}
void drawResource(string&in filename) {
ResourceType resType = StudioAPI::getResourceType(filename);
bool selected = filename == selectedResource;
if (resType == ResourceType::Mesh) {
FrameBuffer frameBuffer;
GPUMesh mesh = StudioAPI::loadGPUMesh(filename);
//frameBuffer = Previewer::renderMeshPreview_fase(mesh, fase);
meshFrameBuffer[filename] = frameBuffer;
alreadyRendered = true;
Texture mesTexture = StudioAPI::loadIcon("mesh.png");
if (ImGui::cartIconButton(Path::getName(filename), mesTexture, 128, ImGui::getAvailableSizeX())) {
selectedResource = filename;
}
ImGui::dragDropSource("MESH", any(mesh), filename);
ImGui::nextColumn();
return;
}
if (resType == ResourceType::Shader) {
Texture shaderTexture = StudioAPI::loadIcon("shader.png");
Shader shader = StudioAPI::loadShader(filename);
if (ImGui::cartIconButton(Path::getName(filename), shaderTexture, 128, ImGui::getAvailableSizeX())) {
selectedResource = filename;
}
ImGui::dragDropSource("SHADER", any(shader), filename);
ImGui::nextColumn();
return;
}
if (resType == ResourceType::Texture) {
Texture texture = StudioAPI::loadTexture(filename);
if (ImGui::cartIconButton(Path::getName(filename), texture, 128, ImGui::getAvailableSizeX())) {
selectedResource = filename;
}
ImGui::dragDropSource("TEXTURE", any(texture), filename);
ImGui::nextColumn();
return;
}
Texture fileTexture = StudioAPI::loadIcon("file.png");
ImGui::cartIconButton(Path::getName(filename), fileTexture, 128, ImGui::getAvailableSizeX());
ImGui::nextColumn();
}
void renderMenuBar() {
// If we select that path
if (ImGui::button("Resources")) {
setPath("");
}
array<string>@ paths = Path::divide(currentPath);
for (uint i = 0; i < paths.length(); i++) {
ImGui::sameline();
ImGui::text("/");
ImGui::sameline();
// If we select that path
if (ImGui::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);
}
}
}
}