From 91f8eff00d82a67c7a9d882effd8884e80e32a24 Mon Sep 17 00:00:00 2001 From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com> Date: Wed, 21 May 2025 11:49:17 -0500 Subject: [PATCH] Started in File Broswe Window --- CMakeLists.txt | 2 + src/core/systems/assets/Texture2D.cpp | 1 - src/editor/Editor.cpp | 2 + src/editor/Windows/FileBrowser.cpp | 70 +++++++++++++++++++++++++++ src/editor/Windows/FileBrowser.h | 12 +++++ 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/editor/Windows/FileBrowser.cpp create mode 100644 src/editor/Windows/FileBrowser.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a855c84..c58a66c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,8 @@ add_executable(Editor ${APP_SOURCES} src/editor/Windows/LoggerWindow.h src/editor/Windows/Viewport.cpp src/editor/Windows/Viewport.h + src/editor/Windows/FileBrowser.cpp + src/editor/Windows/FileBrowser.h ) target_include_directories(Editor PRIVATE diff --git a/src/core/systems/assets/Texture2D.cpp b/src/core/systems/assets/Texture2D.cpp index 1301e1c..6d9c3da 100644 --- a/src/core/systems/assets/Texture2D.cpp +++ b/src/core/systems/assets/Texture2D.cpp @@ -43,7 +43,6 @@ namespace OX glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); stbi_image_free(data); - Logger::LogVerbose("Loaded texture: %s (%dx%d)", path.c_str(), m_Width, m_Height); return true; } } // namespace OX diff --git a/src/editor/Editor.cpp b/src/editor/Editor.cpp index 7f5c04f..869781c 100644 --- a/src/editor/Editor.cpp +++ b/src/editor/Editor.cpp @@ -10,6 +10,7 @@ #include "Windows/LoggerWindow.h" #include "Windows/Viewport.h" +#include "Windows/FileBrowser.h" namespace OX { @@ -75,6 +76,7 @@ namespace OX ImGui::DockSpace(dockspaceID, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_PassthruCentralNode); LoggerWindow::Draw(); + FileBrowser::Draw(); primaryViewport->Draw(core); diff --git a/src/editor/Windows/FileBrowser.cpp b/src/editor/Windows/FileBrowser.cpp new file mode 100644 index 0000000..dad4612 --- /dev/null +++ b/src/editor/Windows/FileBrowser.cpp @@ -0,0 +1,70 @@ +// +// Created by spenc on 5/21/2025. +// + + + + +#include "FileBrowser.h" +#include "systems/AssetManager.h" +#include "imgui.h" +#include + +namespace OX { + + static std::string s_CurrentPath = "res://"; + + static void DrawGrid(const std::shared_ptr& node) { + const int columns = 4; + int itemIndex = 0; + + ImGui::BeginChild("FileGrid", ImVec2(0, 0), false, ImGuiWindowFlags_AlwaysUseWindowPadding); + ImGui::Columns(columns, nullptr, false); + + for (const auto& child : node->children) { + std::string label = (child->isDirectory ? "[folder] " : "[file] ") + child->name; + + if (ImGui::Selectable(label.c_str(), false, ImGuiSelectableFlags_AllowDoubleClick, ImVec2(0, 64))) { + if (child->isDirectory && ImGui::IsMouseDoubleClicked(0)) { + s_CurrentPath = child->path; + } + } + + ImGui::NextColumn(); + ++itemIndex; + } + + ImGui::Columns(1); + ImGui::EndChild(); + } + + static std::shared_ptr FindNode(const std::shared_ptr& root, const std::string& targetPath) { + if (root->path == targetPath) return root; + + for (const auto& child : root->children) { + if (child->isDirectory) { + auto found = FindNode(child, targetPath); + if (found) return found; + } + } + return nullptr; + } + + void FileBrowser::Draw() { + ImGui::Begin("File Browser"); + + ImGui::Text("Current Path: %s", s_CurrentPath.c_str()); + ImGui::Separator(); + + auto root = AssetManager::GetFileTree(); + auto currentNode = FindNode(root, s_CurrentPath); + if (currentNode) { + DrawGrid(currentNode); + } else { + ImGui::Text("Path not found: %s", s_CurrentPath.c_str()); + } + + ImGui::End(); + } + +} // namespace OX diff --git a/src/editor/Windows/FileBrowser.h b/src/editor/Windows/FileBrowser.h new file mode 100644 index 0000000..1e34df9 --- /dev/null +++ b/src/editor/Windows/FileBrowser.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace OX { + + class FileBrowser { + public: + static void Draw(); + }; + +} // namespace OX