Skip to content

Commit

Permalink
refactor to voxel palette editor
Browse files Browse the repository at this point in the history
  • Loading branch information
roby2014 committed Oct 11, 2023
1 parent b4f5578 commit 705313e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/// @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

#include <cubos/engine/cubos.hpp>

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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <cubos/engine/imgui/plugin.hpp>
#include <cubos/engine/renderer/plugin.hpp>
#include <cubos/engine/tools/asset_explorer/plugin.hpp>
#include <cubos/engine/tools/palette_editor/plugin.hpp>
#include <cubos/engine/tools/voxel_palette_editor/plugin.hpp>
#include <cubos/engine/voxels/plugin.hpp>

using cubos::core::data::old::Debug;
Expand Down Expand Up @@ -39,9 +39,9 @@ static void savePaletteUiGuard(Write<Assets> assets, Write<SelectedPaletteInfo>
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();
Expand Down Expand Up @@ -70,7 +70,6 @@ static void savePaletteUiGuard(Write<Assets> assets, Write<SelectedPaletteInfo>
selectedPalette->paletteAsset = assets->load(selectedPalette->selectedPaletteAnyAsset);
selectedPalette->paletteCopy = assets->read(selectedPalette->paletteAsset).get();
selectedPalette->modified = false;
optionSelected = false;
}

ImGui::EndPopup();
Expand Down Expand Up @@ -103,19 +102,18 @@ static void checkAssetEventSystem(EventReader<AssetSelectedEvent> reader, Write<
savePaletteUiGuard(assets, selectedPalette);
}

static void paletteEditorSystem(Write<Assets> assets, Write<Renderer> renderer,
Write<SelectedPaletteInfo> selectedPalette)
static void voxelPaletteEditorSystem(Write<Assets> assets, Write<Renderer> renderer,
Write<SelectedPaletteInfo> 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;
Expand All @@ -136,14 +134,13 @@ static void paletteEditorSystem(Write<Assets> assets, Write<Renderer> 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;
}

Expand All @@ -167,7 +164,7 @@ static void paletteEditorSystem(Write<Assets> assets, Write<Renderer> renderer,
ImGui::End();
}

void cubos::engine::tools::paletteEditorPlugin(Cubos& cubos)
void cubos::engine::tools::voxelPaletteEditorPlugin(Cubos& cubos)
{
cubos.addPlugin(rendererPlugin);
cubos.addPlugin(imguiPlugin);
Expand All @@ -176,5 +173,5 @@ void cubos::engine::tools::paletteEditorPlugin(Cubos& cubos)
cubos.addResource<SelectedPaletteInfo>();

cubos.system(checkAssetEventSystem).tagged("cubos.imgui");
cubos.system(paletteEditorSystem).tagged("cubos.imgui");
cubos.system(voxelPaletteEditorSystem).tagged("cubos.imgui");
}
5 changes: 3 additions & 2 deletions tools/tesseratos/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#include <cubos/engine/settings/settings.hpp>
#include <cubos/engine/tools/asset_explorer/plugin.hpp>
#include <cubos/engine/tools/entity_inspector/plugin.hpp>
#include <cubos/engine/tools/palette_editor/plugin.hpp>
#include <cubos/engine/tools/scene_editor/plugin.hpp>
#include <cubos/engine/tools/settings_inspector/plugin.hpp>
#include <cubos/engine/tools/voxel_palette_editor/plugin.hpp>
#include <cubos/engine/tools/world_inspector/plugin.hpp>
#include <cubos/engine/transform/plugin.hpp>


using cubos::core::ecs::Commands;
using cubos::core::ecs::Write;

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 705313e

Please sign in to comment.