From 705313e1211651ab8380333adf4aaf24ba82b52b Mon Sep 17 00:00:00 2001 From: roby2014 Date: Wed, 11 Oct 2023 20:39:00 +0100 Subject: [PATCH] refactor to voxel palette editor --- engine/CMakeLists.txt | 2 +- .../plugin.hpp | 8 +++--- .../plugin.cpp | 25 ++++++++----------- tools/tesseratos/src/main.cpp | 5 ++-- 4 files changed, 19 insertions(+), 21 deletions(-) rename engine/include/cubos/engine/tools/{palette_editor => voxel_palette_editor}/plugin.hpp (63%) rename engine/src/cubos/engine/tools/{palette_editor => voxel_palette_editor}/plugin.cpp (87%) diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 37782932d..4aad9da17 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -28,7 +28,7 @@ set(CUBOS_ENGINE_SOURCE "src/cubos/engine/tools/world_inspector/plugin.cpp" "src/cubos/engine/tools/entity_inspector/plugin.cpp" "src/cubos/engine/tools/scene_editor/plugin.cpp" - "src/cubos/engine/tools/palette_editor/plugin.cpp" + "src/cubos/engine/tools/voxel_palette_editor/plugin.cpp" "src/cubos/engine/transform/plugin.cpp" "src/cubos/engine/transform/local_to_world.cpp" diff --git a/engine/include/cubos/engine/tools/palette_editor/plugin.hpp b/engine/include/cubos/engine/tools/voxel_palette_editor/plugin.hpp similarity index 63% rename from engine/include/cubos/engine/tools/palette_editor/plugin.hpp rename to engine/include/cubos/engine/tools/voxel_palette_editor/plugin.hpp index 21346ff68..e5fec8d25 100644 --- a/engine/include/cubos/engine/tools/palette_editor/plugin.hpp +++ b/engine/include/cubos/engine/tools/voxel_palette_editor/plugin.hpp @@ -1,9 +1,9 @@ /// @dir -/// @brief @ref palette-editor-tool-plugin plugin directory. +/// @brief @ref voxel-palette-editor-tool-plugin plugin directory. /// @file /// @brief Plugin entry point. -/// @ingroup palette-editor-tool-plugin +/// @ingroup voxel-palette-editor-tool-plugin #pragma once @@ -11,12 +11,12 @@ namespace cubos::engine::tools { - /// @defgroup palette-editor-tool-plugin Palette editor + /// @defgroup voxel-palette-editor-tool-plugin Palette editor /// @ingroup tool-plugins /// @brief Allows the user to open and inspect/edit a palette asset. /// @brief Plugin entry function. /// @param cubos @b CUBOS. main class /// @ingroup palette-editor-tool-plugin - void paletteEditorPlugin(Cubos& cubos); + void voxelPaletteEditorPlugin(Cubos& cubos); } // namespace cubos::engine::tools diff --git a/engine/src/cubos/engine/tools/palette_editor/plugin.cpp b/engine/src/cubos/engine/tools/voxel_palette_editor/plugin.cpp similarity index 87% rename from engine/src/cubos/engine/tools/palette_editor/plugin.cpp rename to engine/src/cubos/engine/tools/voxel_palette_editor/plugin.cpp index 26b5633ae..086b1b7b2 100644 --- a/engine/src/cubos/engine/tools/palette_editor/plugin.cpp +++ b/engine/src/cubos/engine/tools/voxel_palette_editor/plugin.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include using cubos::core::data::old::Debug; @@ -39,9 +39,9 @@ static void savePaletteUiGuard(Write assets, Write bool optionSelected = false; ImVec2 center = ImGui::GetMainViewport()->GetCenter(); - ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); - if (ImGui::BeginPopupModal("Save Palette?", NULL, ImGuiWindowFlags_AlwaysAutoResize)) + if (ImGui::BeginPopupModal("Save Palette?", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::Text("Do you want to save the modified palette?"); ImGui::Separator(); @@ -70,7 +70,6 @@ static void savePaletteUiGuard(Write assets, Write selectedPalette->paletteAsset = assets->load(selectedPalette->selectedPaletteAnyAsset); selectedPalette->paletteCopy = assets->read(selectedPalette->paletteAsset).get(); selectedPalette->modified = false; - optionSelected = false; } ImGui::EndPopup(); @@ -103,19 +102,18 @@ static void checkAssetEventSystem(EventReader reader, Write< savePaletteUiGuard(assets, selectedPalette); } -static void paletteEditorSystem(Write assets, Write renderer, - Write selectedPalette) +static void voxelPaletteEditorSystem(Write assets, Write renderer, + Write selectedPalette) { if (assets->status(selectedPalette->paletteAsset) != Assets::Status::Loaded) { return; } - bool isPaletteEmpty = selectedPalette->paletteCopy.size() == 0; - bool materialModified = false; - ImGui::Begin("Palette Editor"); + bool materialModified = false; + for (uint16_t i = 0; i < selectedPalette->paletteCopy.size(); ++i) { const uint16_t materialIndex = i + 1; @@ -136,14 +134,13 @@ static void paletteEditorSystem(Write assets, Write renderer, auto [modifiedMaterialIndex, modifiedMaterial] = selectedPalette->modifiedMaterial; selectedPalette->paletteCopy.set(modifiedMaterialIndex, modifiedMaterial); selectedPalette->modified = true; - materialModified = false; } // Add material / Make Active / Save - if (ImGui::Button("Add Material") || isPaletteEmpty) + if (ImGui::Button("Add Material") || selectedPalette->paletteCopy.size() == 0) { - selectedPalette->paletteCopy.add(VoxelMaterial{{1.0f, 0.0f, 1.0f, 1.0f}}); // FIXME: push method + selectedPalette->paletteCopy.add(VoxelMaterial{{1.0F, 0.0F, 1.0F, 1.0F}}); // FIXME: push method selectedPalette->modified = true; } @@ -167,7 +164,7 @@ static void paletteEditorSystem(Write assets, Write renderer, ImGui::End(); } -void cubos::engine::tools::paletteEditorPlugin(Cubos& cubos) +void cubos::engine::tools::voxelPaletteEditorPlugin(Cubos& cubos) { cubos.addPlugin(rendererPlugin); cubos.addPlugin(imguiPlugin); @@ -176,5 +173,5 @@ void cubos::engine::tools::paletteEditorPlugin(Cubos& cubos) cubos.addResource(); cubos.system(checkAssetEventSystem).tagged("cubos.imgui"); - cubos.system(paletteEditorSystem).tagged("cubos.imgui"); + cubos.system(voxelPaletteEditorSystem).tagged("cubos.imgui"); } diff --git a/tools/tesseratos/src/main.cpp b/tools/tesseratos/src/main.cpp index 63ad7f5d1..bfbf9dbda 100644 --- a/tools/tesseratos/src/main.cpp +++ b/tools/tesseratos/src/main.cpp @@ -2,12 +2,13 @@ #include #include #include -#include #include #include +#include #include #include + using cubos::core::ecs::Commands; using cubos::core::ecs::Write; @@ -36,7 +37,7 @@ int main(int argc, char** argv) cubos.addPlugin(tools::sceneEditorPlugin); cubos.addPlugin(tools::entityInspectorPlugin); cubos.addPlugin(tools::worldInspectorPlugin); - cubos.addPlugin(tools::paletteEditorPlugin); + cubos.addPlugin(tools::voxelPaletteEditorPlugin); cubos.addPlugin(tools::assetExplorerPlugin); cubos.startupSystem(mockCamera).tagged("setup");