Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
EditorUI.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <glm/glm.hpp>
4#include <string>
5#include <vector>
6#include <functional>
7#include <vulkan/vulkan.h>
8
9#include "../ecs/Entity.hpp"
10#include "EditorModeState.hpp"
12
13struct GLFWwindow;
14class Registry;
15class SceneManager;
16class VulkanRenderer;
17
22class EditorUI {
23public:
24 using BuildGameCallback = std::function<int(const std::string& projectPath, const std::string& outPath)>;
25
33 EditorUI(Registry& registry, VulkanRenderer& renderer, SceneManager& sceneManager, EditorModeState& editorMode, const std::string& startScenePath = "assets/scenes/test_scene.json", BuildGameCallback buildGameCallback = {});
37 ~EditorUI();
38
43 void initialize(GLFWwindow* window);
47 void shutdown();
51 void beginFrame();
55 void drawPanels();
60 void render(VkCommandBuffer commandBuffer);
64 void toggleFlyMode();
65
66 // Dynamic UI Registration for dynamic plugins
67 using ComponentInspectorCallback = std::function<void(Registry&, Entity)>;
68 using ComponentAddCallback = std::function<void(Registry&, Entity)>;
69
70 static void registerComponentInspector(const std::string& name, ComponentInspectorCallback callback);
71 static void registerComponentAddCallback(const std::string& name, ComponentAddCallback callback);
72
73 static std::vector<std::pair<std::string, ComponentInspectorCallback>>& getDynamicInspectors();
74 static std::vector<std::pair<std::string, ComponentAddCallback>>& getDynamicAddCallbacks();
75
76private:
92 void drawSceneControls();
96 void drawHierarchyPanel();
100 void drawInspectorPanel();
104 void drawTransformEditor();
108 void drawMaterialEditor();
112 void drawAssetBrowser();
124
145 void drawMeshEditor();
149 void drawGridEditor();
153 void drawCameraEditor();
157 void drawSkeletonEditor();
161 void drawAnimatorEditor();
165 void drawHierarchyEditor();
169 void drawIKSolverEditor();
181 void drawColliderEditor();
186 void drawSectionHeader(const std::string& title);
194 bool drawVec3Control(const char* label, float* values, float speed = 0.05f);
198 void applyInputMode();
202 void drawDebugPanel();
206 void drawGizmo();
216 void decomposeMatrixToTransform(const glm::mat4& mat, Transform& t);
220 glm::mat4 getEntityWorldMatrix(Entity entity, int depth = 0);
229
239 GLFWwindow* window = nullptr;
241 VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
243 bool initialized = false;
245 std::string scenePath = "assets/scenes/test_scene.json";
247 std::string statusMessage = "Scene not saved yet.";
249 std::string renameBuffer;
253 bool hasSelection = false;
257 glm::vec3 lastPickRayOrigin{ 0.0f };
259 glm::vec3 lastPickRayDirection{ 0.0f, 0.0f, -1.0f };
261 std::string lastPickNearestEntityName = "None";
265 std::string lastPickResult = "No pick attempted yet.";
269 bool showColliders = false;
271 bool showBuildSettings = false;
273 std::string buildOutputPath = "build/";
277 bool buildInProgress = false;
280};
std::string renameBuffer
Cache buffer string for renaming entities.
Definition EditorUI.hpp:249
void drawTilemapGridOverlay()
Renders a 3D grid overlay on the tilemap for editor visual feedback.
Definition EditorUIGizmosAndPicking.cpp:671
void handleViewportPicking()
Processes viewport clicking rays for entity selection.
Definition EditorUIGizmosAndPicking.cpp:206
void drawColliderEditor()
Renders inline controls for Collider component fields.
Definition EditorUIComponentEditors.cpp:1635
void drawAnimatorEditor()
Renders inline controls for Animator component fields.
Definition EditorUIComponentEditors.cpp:573
VkDescriptorPool descriptorPool
ImGui dedicated descriptor pool.
Definition EditorUI.hpp:241
void drawHierarchyPanel()
Renders hierarchical entity list panel.
Definition EditorUIPanels.cpp:310
std::string buildStatusMessage
Status message from last build attempt.
Definition EditorUI.hpp:275
std::string lastPickResult
Human-readable pick results.
Definition EditorUI.hpp:265
std::string buildOutputPath
Output path for game builds.
Definition EditorUI.hpp:273
void drawTransformEditor()
Renders inline controls for Transform component fields.
Definition EditorUIComponentEditors.cpp:81
void drawPanels()
Processes and populates ImGui panel layout commands.
Definition EditorUIPanels.cpp:67
SceneManager & sceneManager
Reference to scene manager.
Definition EditorUI.hpp:235
glm::vec3 lastPickRayOrigin
Raycast origin caching.
Definition EditorUI.hpp:257
void drawDebugPanel()
Renders the debug metrics and raycast state panel.
Definition EditorUIPanels.cpp:819
float lastPickNearestDistance
Distance to the picked entity.
Definition EditorUI.hpp:263
void render(VkCommandBuffer commandBuffer)
Submits ImGui draw data to the current Vulkan command buffer.
Definition EditorUI.cpp:444
std::string lastPickNearestEntityName
Name of the picked entity.
Definition EditorUI.hpp:261
std::function< void(Registry &, Entity)> ComponentInspectorCallback
Definition EditorUI.hpp:67
void drawNodeGraphDemoWindow()
Definition EditorUIPanels.cpp:2916
bool drawVec3Control(const char *label, float *values, float speed=0.05f)
Renders custom controls for editing glm::vec3 variables.
Definition EditorUIComponentEditors.cpp:46
bool hasSelection
Selection flag.
Definition EditorUI.hpp:253
void drawMaterialEditor()
Renders inline controls for Material component fields.
Definition EditorUIComponentEditors.cpp:143
bool previousToggleKeyDown
Editor/Fly toggle key state cache.
Definition EditorUI.hpp:267
void createDescriptorPool()
Creates Vulkan descriptor pool specifically for ImGui.
Definition EditorUI.cpp:453
void drawAnimatorControllerWindow()
Definition EditorUIPanels.cpp:3060
EditorModeState & editorMode
Reference to editor mode state tracker.
Definition EditorUI.hpp:237
void drawColliderDebugOverlay()
Draws wireframe overlays for all active colliders when enabled.
Definition EditorUIGizmosAndPicking.cpp:442
void applyInputMode()
Applies mouse visibility cursor mode according to active editor mode.
Definition EditorUI.cpp:487
void drawImportSettingsWindow()
Renders the floating asset import settings window.
Definition EditorUIPanels.cpp:1363
void drawAnimationControllerEditor()
Renders inline controls for Animation Controller component fields.
Definition EditorUIComponentEditors.cpp:925
bool showBuildSettings
Whether the Build Settings panel is open.
Definition EditorUI.hpp:271
void drawSkeletonEditor()
Renders inline controls for Skeleton component fields.
Definition EditorUIComponentEditors.cpp:535
Registry & registry
Reference to registry.
Definition EditorUI.hpp:231
BuildGameCallback buildGameCallback
Optional callback used to build the game while the editor is running.
Definition EditorUI.hpp:279
std::function< int(const std::string &projectPath, const std::string &outPath)> BuildGameCallback
Definition EditorUI.hpp:24
void drawGizmo()
Processes and displays transformation gizmo overlay on the selected entity.
Definition EditorUIGizmosAndPicking.cpp:33
void drawHierarchyEditor()
Renders inline controls for Hierarchy component fields.
Definition EditorUIComponentEditors.cpp:747
void drawSpriteRendererInspector()
Renders the SpriteRenderer component inspector panel.
Definition EditorUIComponentEditors.cpp:2067
bool initialized
State flag for ImGui initialization status.
Definition EditorUI.hpp:243
void drawCameraEditor()
Renders inline controls for Camera component fields.
Definition EditorUIComponentEditors.cpp:495
void drawBuildSettingsPanel()
Renders the Build Settings panel for packaging the game.
Definition EditorUIPanels.cpp:1605
void drawSectionHeader(const std::string &title)
Draws a styled banner title inside component panels.
Definition EditorUIComponentEditors.cpp:40
static std::vector< std::pair< std::string, ComponentInspectorCallback > > & getDynamicInspectors()
Definition EditorUI.cpp:511
GLFWwindow * window
Pointer to GLFW window.
Definition EditorUI.hpp:239
std::string scenePath
Target json file path for scene serialization.
Definition EditorUI.hpp:245
static std::vector< std::pair< std::string, ComponentAddCallback > > & getDynamicAddCallbacks()
Definition EditorUI.cpp:516
void drawTilemapInspector()
Renders the Tilemap component inspector panel.
Definition EditorUIComponentEditors.cpp:1687
VulkanRenderer & renderer
Reference to Vulkan renderer.
Definition EditorUI.hpp:233
EditorUI(Registry &registry, VulkanRenderer &renderer, SceneManager &sceneManager, EditorModeState &editorMode, const std::string &startScenePath="assets/scenes/test_scene.json", BuildGameCallback buildGameCallback={})
Construct a new Editor UI object.
Definition EditorUI.cpp:281
void drawAnimationEditorWindow()
Definition EditorUIPanels.cpp:2226
void drawIKSolverEditor()
Renders inline controls for IK Solver component fields.
Definition EditorUIComponentEditors.cpp:809
void drawInspectorPanel()
Renders detail inspector panel for the selected entity.
Definition EditorUIPanels.cpp:627
bool buildInProgress
Whether a build is currently in progress.
Definition EditorUI.hpp:277
glm::mat4 getEntityWorldMatrix(Entity entity, int depth=0)
Recursively traverses parent references to build the entity's absolute world transform.
Definition EditorUIGizmosAndPicking.cpp:428
void drawSceneControls()
Renders panel controls for scene operations (New/Load/Save/Spawn).
Definition EditorUIPanels.cpp:220
bool previousLeftMouseDown
Mouse click state tracking.
Definition EditorUI.hpp:255
std::function< void(Registry &, Entity)> ComponentAddCallback
Definition EditorUI.hpp:68
void toggleFlyMode()
Toggles between first-person fly camera controls and editor UI control modes.
Definition EditorUI.cpp:499
void drawReflectedComponentsEditor()
Renders inline controls for all reflected component fields dynamically.
Definition EditorUIComponentEditors.cpp:1420
Entity selectedEntity
The entity currently selected.
Definition EditorUI.hpp:251
bool showColliders
Flag to toggle drawing collider wireframes in the viewport.
Definition EditorUI.hpp:269
glm::vec3 lastPickRayDirection
Raycast direction caching.
Definition EditorUI.hpp:259
void drawGridEditor()
Renders inline controls for Grid component fields.
Definition EditorUIComponentEditors.cpp:473
static void registerComponentAddCallback(const std::string &name, ComponentAddCallback callback)
Definition EditorUI.cpp:507
void destroyDescriptorPool()
Releases ImGui Vulkan descriptor pool resources.
Definition EditorUI.cpp:480
void drawTilesetEditorWindow()
Renders the Tileset Editor window.
Definition EditorUIPanels.cpp:1713
void beginFrame()
Starts a new ImGui frame.
Definition EditorUI.cpp:434
void drawPhysgunDebugOverlay()
Draws physics gun debug rays when activated by the user.
Definition EditorUIGizmosAndPicking.cpp:636
void drawAssetBrowser()
Renders the asset browser panel.
Definition EditorUIPanels.cpp:893
~EditorUI()
Destroy the Editor UI object.
Definition EditorUI.cpp:285
void drawMeshEditor()
Renders inline controls for Mesh component fields.
Definition EditorUIComponentEditors.cpp:283
std::string statusMessage
Status info message printed on UI panel.
Definition EditorUI.hpp:247
void initialize(GLFWwindow *window)
Initializes ImGui bindings and structures.
Definition EditorUI.cpp:289
void decomposeMatrixToTransform(const glm::mat4 &mat, Transform &t)
Helper function to extract Euler transform fields from a 4x4 matrix.
Definition EditorUIGizmosAndPicking.cpp:134
void drawUIComponentsEditor()
Renders custom editor inspectors for all game UI components.
Definition EditorUIComponentEditors.cpp:1757
void shutdown()
Shuts down ImGui and releases descriptor pools.
Definition EditorUI.cpp:421
static void registerComponentInspector(const std::string &name, ComponentInspectorCallback callback)
Definition EditorUI.cpp:503
Lightweight identifier representing a game object in the Entity Component System.
Definition Entity.hpp:11
Coordinates entities and components, providing creation, removal, lookup, and views.
Definition Registry.hpp:30
Manages a set of simultaneously loaded Scenes. Supports Single and Additive loading,...
Definition SceneManager.hpp:54
Manages core Vulkan pipeline states, device interaction, frames, buffers, and command submissions.
Definition VulkanRenderer.hpp:127
Struct keeping track of active editor states (e.g. fly mode vs editor UI interaction).
Definition EditorModeState.hpp:7
Represents the position, rotation, and scale of an entity in 3D space.
Definition Transform.hpp:127
static ufbxi_noinline int depth
Definition ufbx.cpp:7467
const char * name
Definition ufbx.cpp:9020