Brunot
Loading...
Searching...
No Matches
Editor.h
Go to the documentation of this file.
1// File: Editor.h
2// Description: The system manager, handles all systems in the engine
3// Author(s): Marcelo Escamilla, Bryley Elder (marcelo.escamilla@digipen.edu), (bryley.elder@digipen.edu)
4// 2025 / 10 / 03
5// (C) Digipen 2025
6// ____ __ __ __
7// /\__ _\/\ \ /\ \/\ \
8// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
9// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
10// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
11// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
12// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
13#pragma once
14
15#include "System/opengl.h"
16
17// NOTE: Some of these includes are unused, so that you can include editor.h for all the ImGui things
18#define IMGUI_DEFINE_MATH_OPERATORS
19#include <filesystem>
20
21#include "../Submodules/imgui/imgui.h"
22#include "../Submodules/imgui/backends/imgui_impl_opengl3.h"
23#include "../Submodules/imgui/backends/imgui_impl_glfw.h"
24#include "../Submodules/ImGuizmo/src/ImGuizmo.h"
25#include "misc/cpp/imgui_stdlib.h"
26#include "Audio/AudioObject.h"
27#include "Framework/Factory.h"
28
29#ifndef EDITOR_H
30#define EDITOR_H
31#endif
32
33#ifndef NDEBUG
34#define START_WITH_IMGUI true
35#else
36#define START_WITH_IMGUI false
37#endif
38
39class ParticleEmitter;
40
41namespace gfx
42{
43class Texture;
44class Mesh;
45}
46
47namespace sys
48{
49class Editor : public System
50{
51public:
52 auto getDefaultFont() -> ImFont*
53 {
54 return defaultFont;
55 }
56
57#pragma region static_functions
58
62 static auto getEnum() -> Type
63 {
64 return Type::Editor;
65 }
66
67 static const ImVec2 SmallButtonSize;
68
69 static const float IndentWidth;
70
71#pragma endregion
72
73 Editor();
74 ~Editor() override;
75 Editor(const Editor& other) = default;
76 Editor(Editor&& other) noexcept;
77 auto operator=(const Editor& other) -> Editor&;
78
79 auto operator=(Editor&& other) noexcept -> Editor& = default;
80
81
82#pragma region overridden_functions
83
84 auto clone() const -> std::unique_ptr<GameObject> override
85 {
86 return std::make_unique<Editor>(*this);
87 }
88
89 auto onUpdate(float dt) -> void override;
90
91 auto endWindow() -> void override
92 {
93 }; // for debug ImGUI
94
95 auto onRender() -> void override;
96 auto load(const Stream& stream) -> void override;
97 auto save(Stream& stream) const -> void override;
98
99#pragma endregion
100
101#pragma region Editor_Functions
102
103 auto PreRender() -> void;
104 auto PostRender() -> void;
105
106 auto shouldShowGui() const -> bool
107 {
108 return showImGui;
109 }
110
111
115 auto drawSystemMenu() -> void;
116
117
118 // Scene Menu Things
119
123 auto drawSceneMenu() -> void;
124
125 auto EntityComponentsEditor() const -> void;
126
131 auto drawEntitiesCompact() -> bool;
132
136 auto EmitterEditor() const -> void;
137
138
143 static auto showTexturePickerMenu() -> gfx::Texture*;
144
149 static auto showMeshPickerMenu() -> gfx::Mesh*;
150
160 template <typename T, int instance = 0>
161 static auto showMakeFromFileMenu(const std::filesystem::path& directory) -> std::unique_ptr<T>;
162
163
168 static auto displayTexture(const gfx::Texture* texture) -> void;
169
175 auto receiveShowGUIKeyPressed(const Message* message) -> Message;
176
181 auto select(Entity* selected) -> void;
182
188 auto isSelected(Entity* entity) -> bool;
189
195 auto getSelectedEntity() -> Entity*;
196
202 auto deselect(Entity* entity) -> void;
203
211 auto isPassingFilter(Entity* entity) -> bool;
212
213 // Helper function to toggle the guizmos baseed on key input. W for translate, E for scale, R for rotate.
214 // Called in the Editor's sceneViewport function
215 auto toggleGuizmos() -> void;
216
217 [[nodiscard]] auto getSliderRatio() const -> float;
218
223 auto select(ParticleEmitter* selected) -> void;
224
225
231 auto isSelected(ParticleEmitter* emitter) -> bool;
232
238 auto deselect(ParticleEmitter* toDeselect) -> void;
239
241
242#pragma endregion
243
244private:
245#pragma region member_variables
247 ImFont* defaultFont;
249 float sliderRatio = 0.4f;
250
252 ImGuiTextFilter entityFilter;
256 bool compactEntityView = false;
257
258
261
263 Vector4D editorMousePos = {0.f, 0.f, 0.f, 1.f};
264
265
268#pragma endregion
269
270#pragma region helper_functions
271
272 auto SceneViewPort() -> void;
273
277 static void drawEditorTopBar();
278
284 void calculateViewportCoords(float width, float height);
285
286#pragma endregion
287
288#pragma region messaging_functions
289
290 auto linkMessages() -> void;
291 auto deleteSelectedEntity(const Message* message) -> Message;
292
293#pragma endregion
294
295#pragma region static_variables
296
297#pragma endregion
298
299};
300
301template <typename T, int instance>
302auto Editor::showMakeFromFileMenu(const std::filesystem::path& directory) -> std::unique_ptr<T>
303{
304 // I want cpp to make each call of this function different
305 namespace fs = std::filesystem;
306 // Make the button
307 // Drop Down list for components to add
308 static auto index = 0;
309 static std::vector<std::string> itemNames;
310 itemNames.clear();
311 for (auto& entry : fs::directory_iterator("Data" / directory))
312 {
313 if (entry.path().extension() == ".json")
314 {
315 itemNames.push_back(entry.path().stem().string());
316 }
317 }
318
319 std::vector<const char*> items;
320 for (auto& name : itemNames)
321 {
322 items.push_back(name.c_str());
323 }
324
325 ImGui::Text("Select %s :", directory.string().c_str());
326 ImGui::SetNextItemWidth(150.0f); // width in pixels
327 ImGui::Combo("##Items",
328 &index,
329 items.data(),
330 static_cast<int>(items.size())
331 );
332 ImGui::SameLine();
333 if (ImGui::Button("Add"))
334 {
335 // if we click the button, then we return the object
336 const auto& selected = itemNames[index];
337 return th::Factory::make<T>((directory / selected).string());
338 }
339 return nullptr;
340}
341} // namespace sys
342
343
344#undef START_WITH_IMGUI
sys::Json Stream
Definition AudioObject.h:20
#define START_WITH_IMGUI
Definition Editor.h:34
Definition Entity.h:41
friend Entity
Definition GameObject.h:90
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
An object that manages many of a single type of particle.
Definition ParticleEmitter.h:32
Type
Definition System.h:20
@ Editor
Definition System.h:25
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
bool compactEntityView
Whether the Scene Tree should be rendered more compact.
Definition Editor.h:256
auto getSliderRatio() const -> float
Definition Editor.cpp:797
ParticleEmitter * selectedEmitter
the emitter last selected on a particleGenerator
Definition Editor.h:267
auto deleteSelectedEntity(const Message *message) -> Message
Definition Editor.cpp:991
Entity * selectedEntity
The entity currently selected in the Scene Tree.
Definition Editor.h:254
static const float IndentWidth
Definition Editor.h:69
auto PreRender() -> void
Definition Editor.cpp:384
auto shouldShowGui() const -> bool
Definition Editor.h:106
static void drawEditorTopBar()
draw the top bar of the editor
Definition Editor.cpp:922
auto drawEntitiesCompact() -> bool
used to determine how much spacing to give entities in the scene view
Definition Editor.cpp:460
static auto getEnum() -> Type
function required by all systems
Definition Editor.h:62
auto deselect(Entity *entity) -> void
deselects and entity if it is currently selected.
Definition Editor.cpp:782
auto operator=(Editor &&other) noexcept -> Editor &=default
ImFont * defaultFont
The default font of the Editor.
Definition Editor.h:247
auto drawSceneMenu() -> void
draw the tree of Entities that exist in a scene
Definition Editor.cpp:420
auto getSceneViewPortMousePosition() -> Vector4D &
Definition Editor.cpp:751
void calculateViewportCoords(float width, float height)
helper function to calculate the coordinates of the mouse over the viewport
Definition Editor.cpp:955
auto isPassingFilter(Entity *entity) -> bool
See if the an Entity is passing the filter and should be drawn in the Scene View Currently unimplemen...
Definition Editor.cpp:790
auto getSelectedEntity() -> Entity *
return selected entity, or nullptr if no entity is selected
Definition Editor.cpp:777
auto EntityComponentsEditor() const -> void
Definition Editor.cpp:542
auto isSelected(Entity *entity) -> bool
check whether an entity is currently selected in the editor
Definition Editor.cpp:772
auto select(Entity *selected) -> void
selects an Entity, and shows it's children in the Component view editor
Definition Editor.cpp:767
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Editor.h:91
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Editor.h:84
auto linkMessages() -> void
Definition Editor.cpp:980
static auto displayTexture(const gfx::Texture *texture) -> void
show a texture in a small square
Definition Editor.cpp:635
Vector4D editorMousePos
Position of the mouse relative to the scene viewport.
Definition Editor.h:263
~Editor() override
Definition Editor.cpp:514
auto PostRender() -> void
Post render will run all the normal Render() stuff instead of old function to allow for frame bufferi...
Definition Editor.cpp:804
static const ImVec2 SmallButtonSize
Definition Editor.h:67
static auto showMakeFromFileMenu(const std::filesystem::path &directory) -> std::unique_ptr< T >
Shows a dropdown menu of every json in a directory inside the Data/ folder, and constructs objects fr...
Definition Editor.h:302
auto operator=(const Editor &other) -> Editor &
Definition Editor.cpp:528
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Editor.cpp:728
auto EmitterEditor() const -> void
draw editor for adjusting settings of the selected emitter
Definition Editor.cpp:554
auto toggleGuizmos() -> void
Definition Editor.cpp:829
auto receiveShowGUIKeyPressed(const Message *message) -> Message
Definition Editor.cpp:759
Editor()
Definition Editor.cpp:465
auto drawSystemMenu() -> void
Draw the window that shows all the systems in the game.
Definition Editor.cpp:394
bool showImGui
Whether the Editor should be shown.
Definition Editor.h:260
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Editor.cpp:719
float sliderRatio
The ratio of the total width a slider should take up.
Definition Editor.h:249
Editor(const Editor &other)=default
static auto showTexturePickerMenu() -> gfx::Texture *
creates a dropdown menu to select a new texture.
Definition Editor.cpp:564
ImGuiTextFilter entityFilter
IMGui filter for searching the scene tree. currently unused, as filtering a tree is non-trivial.
Definition Editor.h:252
auto getDefaultFont() -> ImFont *
Definition Editor.h:52
auto onUpdate(float dt) -> void override
called once every frame.
Definition Editor.cpp:688
auto SceneViewPort() -> void
This is the Window that activates the viewport and renders the framebuffer.
Definition Editor.cpp:1004
static auto showMeshPickerMenu() -> gfx::Mesh *
shows a dropdown menu to choose meshes
Definition Editor.cpp:643
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Editor.cpp:723
static auto make(const std::string &name) -> std::unique_ptr< T >
create an object and heap allocate it.
Definition Factory.h:45
Definition FlipCardAction.h:25
the type of elements in a basic_json container
Definition GameObject.h:37
Definition Message.h:35
Definition Vector4D.h:28