Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(engine): add toolbox plugin #783

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/tesseratos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(TESSERATOS_SOURCE
"src/tesseratos/scene_editor/plugin.cpp"
"src/tesseratos/debug_camera/plugin.cpp"
"src/tesseratos/voxel_palette_editor/plugin.cpp"
"src/tesseratos/toolbox/plugin.cpp"
)

add_library(tesseratos ${TESSERATOS_SOURCE})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace tesseratos
/// ## Dependencies
/// - @ref imgui-plugin
/// - @ref assets-plugin
/// - @ref tesseratos-toolbox-plugin

/// @brief Event sent when an asset is selected.
struct AssetSelectedEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace tesseratos
/// ## Dependencies
/// - @ref imgui-plugin
/// - @ref renderer-plugin
/// - @ref tesseratos-toolbox-plugin

/// @brief Plugin entry function.
/// @param cubos @b CUBOS. main class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace tesseratos
/// ## Dependencies
/// - @ref imgui-plugin
/// - @ref tesseratos-entity-selector-plugin
/// - @ref tesseratos-toolbox-plugin

/// @brief Plugin entry function.
/// @param cubos @b CUBOS. main class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace tesseratos
///
/// ## Resources
/// - @ref EntitySelector - identifies the currently selected entity.
///
/// ## Dependencies
/// - @ref tesseratos-toolbox-plugin

/// @brief Resource which identifies the currently selected entity.
struct EntitySelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace tesseratos
/// - @ref scene-plugin
/// - @ref tesseratos-asset-explorer-plugin
/// - @ref tesseratos-entity-selector-plugin
/// - @ref tesseratos-toolbox-plugin

/// @brief Plugin entry function.
/// @param cubos @b CUBOS. main class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace tesseratos
/// ## Dependencies
/// - @ref settings-plugin
/// - @ref imgui-plugin
/// - @ref tesseratos-toolbox-plugin

/// @brief Plugin entry function.
/// @param cubos @b CUBOS. main class
Expand Down
68 changes: 68 additions & 0 deletions tools/tesseratos/include/tesseratos/toolbox/plugin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/// @dir
/// @brief @ref tesseratos-toolbox-plugin plugin directory.

/// @file
/// @brief Plugin entry point.
/// @ingroup tesseratos-toolbox-plugin

#pragma once

#include <cubos/engine/cubos.hpp>

namespace tesseratos
{
/// @defgroup tesseratos-toolbox-plugin Toolbox
/// @ingroup tesseratos
/// @brief Adds a resource used to keep track of whether each tool is open or not.
///
/// ## Resources
/// - @ref Toolbox
///
/// ## Dependencies
/// - @ref imguiPlugin

/// @brief Resource which manages other tools windows.
/// @ingroup tesseratos-toolbox-plugin
class Toolbox final
{
public:
/// @brief Checks if the tool with the given name is open.
/// @param toolName Tool name.
///@return Whether the tool is open.
bool isOpen(const std::string& toolName);

/// @brief Opens a tool.
/// @param toolName Tool name.
void open(const std::string& toolName);

/// @brief Closes a tool.
/// @param toolName Tool name.
void close(const std::string& toolName);

/// @brief If the given tool is open, closes it. Otherwise, opens it.
/// @param toolName Tool name.
void toggle(const std::string& toolName);

/// @brief Returns the beggining of the map with known tools.
/// @return Begginng of the map.
auto begin() const
{
return mToolsMap.begin();
}

/// @brief Returns the end of the map with known tools.
/// @return End of the map.
auto end() const
{
return mToolsMap.end();
}

private:
std::unordered_map<std::string, bool> mToolsMap;
};

/// @brief Plugin entry function.
/// @param cubos @b CUBOS. main class
/// @ingroup tesseratos-toolbox-plugin
void toolboxPlugin(cubos::engine::Cubos& cubos);
} // namespace tesseratos
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace tesseratos
/// @defgroup tesseratos-voxel-palette-editor-plugin Palette editor
/// @ingroup tesseratos
/// @brief Allows the user to open and inspect/edit a palette asset.
///
/// ## Dependencies
/// - @ref tesseratos-toolbox-plugin

/// @brief Plugin entry function.
/// @param cubos @b CUBOS. main class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace tesseratos
/// ## Dependencies
/// - @ref imgui-plugin
/// - @ref tesseratos-entity-selector-plugin
/// - @ref tesseratos-toolbox-plugin

/// @brief Plugin entry function.
/// @param cubos @b CUBOS. main class
Expand Down
11 changes: 9 additions & 2 deletions tools/tesseratos/src/tesseratos/asset_explorer/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cubos/engine/settings/plugin.hpp>

#include <tesseratos/asset_explorer/plugin.hpp>
#include <tesseratos/toolbox/plugin.hpp>

using cubos::core::ecs::EventWriter;
using cubos::core::ecs::Read;
Expand Down Expand Up @@ -112,8 +113,14 @@ static std::vector<AnyAsset>::iterator showFolder(Assets const& assets, std::str
return iter;
}

static void showAssets(Read<Assets> assets, Write<Settings> settings, EventWriter<AssetSelectedEvent> events)
static void showAssets(Read<Assets> assets, Write<Settings> settings, Write<Toolbox> toolbox,
EventWriter<AssetSelectedEvent> events)
{
if (!toolbox->isOpen("Asset Explorer"))
{
return;
}

ImGui::Begin("Asset Explorer");

std::string folder = settings->getString("assets.io.path", "");
Expand Down Expand Up @@ -142,6 +149,6 @@ void tesseratos::assetExplorerPlugin(Cubos& cubos)

cubos.addPlugin(cubos::engine::imguiPlugin);
cubos.addPlugin(cubos::engine::assetsPlugin);

cubos.addPlugin(toolboxPlugin);
cubos.system(showAssets).tagged("cubos.imgui");
}
11 changes: 9 additions & 2 deletions tools/tesseratos/src/tesseratos/debug_camera/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cubos/engine/transform/plugin.hpp>

#include <tesseratos/debug_camera/plugin.hpp>
#include <tesseratos/toolbox/plugin.hpp>

using cubos::core::ecs::Commands;
using cubos::core::ecs::Entity;
Expand All @@ -31,8 +32,14 @@ static void createDebugCameraSystem(Commands commands, Write<DebugCameraInfo> de
debugCamera->ent = commands.create().add(Camera{}).add(Position{{}}).entity();
}

static void changeToDebugCameraSystem(Write<ActiveCameras> camera, Write<DebugCameraInfo> debugCamera)
static void changeToDebugCameraSystem(Write<ActiveCameras> camera, Write<Toolbox> toolbox,
Write<DebugCameraInfo> debugCamera)
{
if (!toolbox->isOpen("Debug Camera"))
{
return;
}

ImGui::Begin("Debug Camera");

ImGui::Text("Current camera: %s", debugCamera->ent == camera->entities[0] ? "Debug" : "Game");
Expand Down Expand Up @@ -61,7 +68,7 @@ static void changeToDebugCameraSystem(Write<ActiveCameras> camera, Write<DebugCa
void tesseratos::debugCameraPlugin(Cubos& cubos)
{
cubos.addPlugin(cubos::engine::imguiPlugin);

cubos.addPlugin(toolboxPlugin);
cubos.startupSystem(createDebugCameraSystem);
cubos.system(changeToDebugCameraSystem).tagged("cubos.imgui");

Expand Down
8 changes: 8 additions & 0 deletions tools/tesseratos/src/tesseratos/entity_inspector/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

#include <tesseratos/entity_inspector/plugin.hpp>
#include <tesseratos/entity_selector/plugin.hpp>
#include <tesseratos/toolbox/plugin.hpp>

using cubos::core::ecs::Entity;
using cubos::core::ecs::Read;
using cubos::core::ecs::World;
using cubos::core::ecs::Write;
using cubos::core::reflection::reflect;
Expand All @@ -22,6 +24,11 @@ using namespace tesseratos;

static void inspectEntity(Write<World> world)
{
if (!world->write<Toolbox>().get().isOpen("Entity Inspector"))
{
return;
}

ImGui::Begin("Entity Inspector");
if (!ImGui::IsWindowCollapsed())
{
Expand Down Expand Up @@ -56,6 +63,7 @@ void tesseratos::entityInspectorPlugin(Cubos& cubos)
{
cubos.addPlugin(cubos::engine::imguiPlugin);
cubos.addPlugin(entitySelectorPlugin);
cubos.addPlugin(toolboxPlugin);

cubos.system(inspectEntity).tagged("cubos.imgui");
}
10 changes: 9 additions & 1 deletion tools/tesseratos/src/tesseratos/scene_editor/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <tesseratos/asset_explorer/plugin.hpp>
#include <tesseratos/entity_selector/plugin.hpp>
#include <tesseratos/scene_editor/plugin.hpp>
#include <tesseratos/toolbox/plugin.hpp>

using cubos::core::ecs::Commands;
using cubos::core::ecs::Entity;
Expand Down Expand Up @@ -247,8 +248,14 @@ static void showSceneHierarchy(SceneInfo& scene, Commands& cmds, EntitySelector&
ImGui::PopID();
}

static void sceneEditorSystem(Commands cmds, Write<SceneInfo> scene, Write<EntitySelector> selector)
static void sceneEditorSystem(Commands cmds, Write<SceneInfo> scene, Write<EntitySelector> selector,
Write<Toolbox> toolbox)
{
if (!toolbox->isOpen("Scene Editor"))
{
return;
}

ImGui::Begin("Scene Editor");
showSceneHierarchy(*scene, cmds, *selector, 0);
ImGui::End();
Expand All @@ -260,6 +267,7 @@ void tesseratos::sceneEditorPlugin(Cubos& cubos)

cubos.addPlugin(entitySelectorPlugin);
cubos.addPlugin(assetExplorerPlugin);
cubos.addPlugin(toolboxPlugin);

cubos.addResource<SceneInfo>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cubos/engine/settings/plugin.hpp>

#include <tesseratos/settings_inspector/plugin.hpp>
#include <tesseratos/toolbox/plugin.hpp>

using cubos::core::ecs::Read;
using cubos::core::ecs::Write;
Expand All @@ -20,8 +21,13 @@ using cubos::engine::Settings;

using namespace tesseratos;

static void inspector(Write<Settings> settings, Write<DataInspector> inspector)
static void inspector(Write<Settings> settings, Write<DataInspector> inspector, Write<Toolbox> toolbox)
{
if (!toolbox->isOpen("Settings Inspector"))
{
return;
}

ImGui::Begin("Settings Inspector");
if (!ImGui::IsWindowCollapsed())
{
Expand All @@ -44,6 +50,7 @@ void tesseratos::settingsInspectorPlugin(Cubos& cubos)
{
cubos.addPlugin(cubos::engine::settingsPlugin);
cubos.addPlugin(cubos::engine::imguiPlugin);
cubos.addPlugin(toolboxPlugin);

cubos.system(inspector).tagged("cubos.imgui");
}
61 changes: 61 additions & 0 deletions tools/tesseratos/src/tesseratos/toolbox/plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <imgui.h>

#include <cubos/engine/imgui/plugin.hpp>

#include <tesseratos/toolbox/plugin.hpp>

using cubos::core::ecs::EventWriter;
using cubos::core::ecs::Write;

using cubos::core::ecs::Write;
using cubos::engine::Cubos;

using namespace tesseratos;

bool Toolbox::isOpen(const std::string& toolName)
{
if (mToolsMap.contains(toolName))
{
return mToolsMap[toolName];
}
mToolsMap[toolName] = false;
return false;
}

void Toolbox::open(const std::string& toolName)
{
mToolsMap[toolName] = true;
}

void Toolbox::close(const std::string& toolName)
{
mToolsMap[toolName] = false;
}

void Toolbox::toggle(const std::string& toolName)
{
mToolsMap[toolName] = !mToolsMap[toolName];
}

static void showToolbox(Write<Toolbox> toolbox)
{
ImGui::Begin("Toolbox");

for (const auto& [tool, open] : *toolbox)
{
bool check = open;
if (ImGui::Checkbox(data(tool), &check))
{
toolbox->toggle(tool);
}
}

ImGui::End();
}

void tesseratos::toolboxPlugin(Cubos& cubos)
{
cubos.addResource<Toolbox>();
cubos.addPlugin(cubos::engine::imguiPlugin);
cubos.system(showToolbox).tagged("cubos.imgui");
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cubos/engine/voxels/plugin.hpp>

#include <tesseratos/asset_explorer/plugin.hpp>
#include <tesseratos/toolbox/plugin.hpp>
#include <tesseratos/voxel_palette_editor/plugin.hpp>

using cubos::core::ecs::EventReader;
Expand Down Expand Up @@ -113,8 +114,13 @@ static void checkAssetEventSystem(EventReader<AssetSelectedEvent> reader, Write<
}

static void voxelPaletteEditorSystem(Write<Assets> assets, Write<SelectedPaletteInfo> selectedPalette,
Write<ActiveVoxelPalette> activePalette)
Write<ActiveVoxelPalette> activePalette, Write<Toolbox> toolbox)
{
if (!toolbox->isOpen("Palette Editor"))
{
return;
}

if (assets->status(selectedPalette->asset) != Assets::Status::Loaded)
{
return;
Expand Down Expand Up @@ -186,6 +192,7 @@ void tesseratos::voxelPaletteEditorPlugin(Cubos& cubos)
cubos.addPlugin(cubos::engine::voxelsPlugin);

cubos.addPlugin(assetExplorerPlugin);
cubos.addPlugin(toolboxPlugin);

cubos.addResource<SelectedPaletteInfo>();

Expand Down
Loading