97 lines
3.4 KiB
C++
97 lines
3.4 KiB
C++
// IAEngine: 2D Game Engine by IA
|
|
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#include <View/AssetBrowser.hpp>
|
|
|
|
namespace ia::iae
|
|
{
|
|
VOID View_AssetBrowser::Initialize()
|
|
{
|
|
if (!std::filesystem::exists("Assets"))
|
|
THROW_INVALID_DATA("Not a valid IAEngine project directory");
|
|
m_assetDirectoryPath = std::filesystem::current_path() / "Assets/";
|
|
ChangeCurrentOpenDirectory(m_assetDirectoryPath);
|
|
FillFileEntries(m_assetDirectoryPath, m_assetDirectoryFiles);
|
|
}
|
|
|
|
VOID View_AssetBrowser::Terminate()
|
|
{
|
|
}
|
|
|
|
VOID View_AssetBrowser::Render()
|
|
{
|
|
PreRender();
|
|
|
|
if (ImGui::BeginTable("root", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp))
|
|
{
|
|
ImGui::TableSetupColumn("Navigation", ImGuiTableColumnFlags_WidthStretch, 0.25f);
|
|
ImGui::TableSetupColumn("Asset Browser", ImGuiTableColumnFlags_WidthStretch, 0.75f);
|
|
|
|
ImGui::TableNextColumn();
|
|
if (ImGui::BeginChild("Navigation", ImVec2(0, -FLT_MIN)))
|
|
{
|
|
for (const auto &t : m_assetDirectoryFiles)
|
|
{
|
|
ImGui::Text("%s %s", t.Icon, t.Name.c_str());
|
|
}
|
|
}
|
|
ImGui::EndChild();
|
|
|
|
ImGui::TableNextColumn();
|
|
if (ImGui::BeginChild("Asset Browser", ImVec2(0, -FLT_MIN)))
|
|
{
|
|
}
|
|
ImGui::EndChild();
|
|
|
|
ImGui::EndTable();
|
|
}
|
|
|
|
PostRender();
|
|
}
|
|
|
|
VOID View_AssetBrowser::ChangeCurrentOpenDirectory(IN CONST std::filesystem::path &path)
|
|
{
|
|
m_currentOpenDirectoryPath = path;
|
|
std::filesystem::current_path(m_currentOpenDirectoryPath);
|
|
FillFileEntries(m_currentOpenDirectoryPath, m_currentOpenDirectoryFiles);
|
|
}
|
|
|
|
VOID View_AssetBrowser::FillFileEntries(IN CONST std::filesystem::path &path, IN Vector<FileEntry> &fileEntries)
|
|
{
|
|
for (const auto &t : std::filesystem::directory_iterator(path))
|
|
{
|
|
if (!t.is_directory())
|
|
continue;
|
|
fileEntries.pushBack(
|
|
{.Icon = ICON_FA_FOLDER, .Name = t.path().filename().string().c_str(), .IsDirectory = true});
|
|
}
|
|
for (const auto &t : std::filesystem::directory_iterator(path))
|
|
{
|
|
if (t.is_directory())
|
|
continue;
|
|
fileEntries.pushBack({.Icon = GetFileEntryIcon(t.path().extension().string().c_str()),
|
|
.Name = t.path().filename().string().c_str(),
|
|
.IsDirectory = false});
|
|
}
|
|
}
|
|
|
|
PCCHAR View_AssetBrowser::GetFileEntryIcon(IN PCCHAR extension)
|
|
{
|
|
if(!strcmp(extension, ".xml"))
|
|
return ICON_FA_CODE;
|
|
return "";
|
|
}
|
|
} // namespace ia::iae::editor
|