diff --git a/CHANGELOG.md b/CHANGELOG.md index 4925daca2c..6efc18f0e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Sane default placement for tools in tesseratos (#1387, **@jdbaracho**). - Layout structure with loading and ImGui application (#1387, **@jdbaracho**). - Allow generating metas with random UUIDs through Quadrados (#1441, **@Fkatar**) +- Allow initializing new projects through quadrados (#1480 **@PedroSimoes24**) ### Changed diff --git a/core/include/cubos/core/memory/opt.hpp b/core/include/cubos/core/memory/opt.hpp index 7e3afd948f..f45acce61e 100644 --- a/core/include/cubos/core/memory/opt.hpp +++ b/core/include/cubos/core/memory/opt.hpp @@ -218,6 +218,8 @@ namespace cubos::core::memory { } + Opt& operator=(const Opt& other) = default; + bool contains() const { return mValue != nullptr; diff --git a/engine/src/tools/world_inspector/plugin.cpp b/engine/src/tools/world_inspector/plugin.cpp index 619d0e8744..7e0ed3248f 100644 --- a/engine/src/tools/world_inspector/plugin.cpp +++ b/engine/src/tools/world_inspector/plugin.cpp @@ -1,5 +1,4 @@ #include -#include #include #include @@ -161,6 +160,65 @@ static void showHierarchy(Entity entity, Query, const C ImGui::PopStyleColor(); } +static void sortAlphabetical(std::vector>>& entities) +{ + std::sort(entities.begin(), entities.end(), [](auto& a, auto& b) { + std::string nameA = a.second.contains() ? a.second->value : std::to_string(a.first.index); + std::string nameB = b.second.contains() ? b.second->value : std::to_string(b.first.index); + return nameA < nameB; + }); +} + +static void sortReverseAlphabetical(std::vector>>& entities) +{ + std::sort(entities.begin(), entities.end(), [](auto& a, auto& b) { + std::string nameA = a.second.contains() ? a.second->value : std::to_string(a.first.index); + std::string nameB = b.second.contains() ? b.second->value : std::to_string(b.first.index); + return nameA > nameB; + }); +} + +static void sortByEntityIdAscending(std::vector>>& entities) +{ + std::sort(entities.begin(), entities.end(), + [](const auto& a, const auto& b) { return a.first.index < b.first.index; }); +} + +static void sortByEntityIdDescending(std::vector>>& entities) +{ + std::sort(entities.begin(), entities.end(), + [](const auto& a, const auto& b) { return a.first.index > b.first.index; }); +} + + +static void sortEntities(std::vector>>& entities, int sortMode) +{ + switch (sortMode) + { + case 0: // A-Z + sortAlphabetical(entities); + break; + + case 1: // Z-A + sortReverseAlphabetical(entities); + break; + + case 2: // ID (Asc.) + sortByEntityIdAscending(entities); + break; + + case 3: // ID (Des.) + sortByEntityIdDescending(entities); + break; + + + default: + // Default to alphabetical + sortAlphabetical(entities); + break; + } +} + void cubos::engine::worldInspectorPlugin(Cubos& cubos) { cubos.depends(imguiPlugin); @@ -180,13 +238,25 @@ void cubos::engine::worldInspectorPlugin(Cubos& cubos) ImGui::Begin("World Inspector"); if (!ImGui::IsWindowCollapsed()) - { - std::string searchQuery{}; + { + // Spacing float windowWidth = ImGui::GetContentRegionAvail().x; + float searchWidth = windowWidth * 0.58F; + float comboWidth = windowWidth * 0.40F; + + // Widget variables + std::string searchQuery{}; static char searchBuffer[512]; - ImGui::PushItemWidth(windowWidth); + const char* sortModes[] = {"Name (Asc.)", "Name (Des.)", "ID (Asc.)", "ID (Des.)"}; + static int currentsortMode = 0; + + ImGui::PushItemWidth(searchWidth); ImGui::InputText("##searchQuery", searchBuffer, sizeof(searchBuffer)); ImGui::PopItemWidth(); + ImGui::SameLine(); + ImGui::PushItemWidth(comboWidth); + ImGui::Combo("sortItems", ¤tsortMode, sortModes, IM_ARRAYSIZE(sortModes)); + ImGui::PopItemWidth(); ImGui::Spacing(); ImGui::Separator(); ImGui::Spacing(); @@ -198,13 +268,23 @@ void cubos::engine::worldInspectorPlugin(Cubos& cubos) } else { + std::vector>> entities; for (auto [entity, name] : all) { if (!query.pin(0, entity).empty()) { continue; // Skip all entities with parents } + + entities.emplace_back(entity, name); + } + + // Sort the entities + sortEntities(entities, currentsortMode); + // Display sorted entities + for (const auto& [entity, name] : entities) + { showHierarchy(entity, query, name, selection); } }