Editor Refactor
This refactor of the editor code makes the code more maintainable. All widget objects have now moved away from RAII and are now just allocated object that live for the entirety of the applications lifetime. This feels better as I am used to this style plus constantly pushing and popping objects from the stack seems a little wasteful (although I as of right now have no way to prove that it is ).
This commit is contained in:
104
Editor/src/PropertyPanels/Inspector.cpp
Normal file
104
Editor/src/PropertyPanels/Inspector.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
#include "Inspector.h"
|
||||
|
||||
|
||||
void Inspector::Draw()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Inspector::AddComponentDropDown(YoggieEngine::Entity& selected)
|
||||
{
|
||||
static char* names[] = { "Script Component", "Camera Component", "Light Component" };
|
||||
if (ImGui::Button("Add Component"))
|
||||
ImGui::OpenPopup("Component picker");
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::BeginPopup("Component picker")) {
|
||||
|
||||
for (int i = 0; i < IM_ARRAYSIZE(names); i++)
|
||||
if (ImGui::MenuItem(names[i])) {
|
||||
std::cout << "Add a " << names[i] << " to "
|
||||
<< selected.GetComponent<YoggieEngine::IdentifierComponent>().name << std::endl;
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::NewLine();
|
||||
}
|
||||
|
||||
|
||||
void Inspector::ShowComponents(YoggieEngine::Entity& selected)
|
||||
{
|
||||
auto component = selected.GetComponent<YoggieEngine::IdentifierComponent>();
|
||||
ImGui::InputText("Name:", (char*)component.name.c_str(), component.name.size() * sizeof(char), ImGuiInputTextFlags_ReadOnly);
|
||||
|
||||
|
||||
if (selected.HasComponent<YoggieEngine::TransformComponent>()) {
|
||||
auto& transform = selected.GetComponent<YoggieEngine::TransformComponent>();
|
||||
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.1f);
|
||||
ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.1f);
|
||||
ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.1f, 0.0f);
|
||||
}
|
||||
if (selected.HasComponent<YoggieEngine::RelationComponent>()) {
|
||||
ImGui::Text("Has relation");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (selected.HasComponent<YoggieEngine::Render3DComponent>()) {
|
||||
auto& render3d = selected.GetComponent<YoggieEngine::Render3DComponent>();
|
||||
if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color));
|
||||
|
||||
ImGui::Checkbox("Use static rendering:", &render3d.isStatic);
|
||||
}
|
||||
}
|
||||
static bool deferred = true;
|
||||
if (selected.HasComponent<YoggieEngine::LightComponent>()) {
|
||||
auto& light = selected.GetComponent<YoggieEngine::LightComponent>();
|
||||
if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color));
|
||||
ImGui::Checkbox("Deferred", &deferred);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (selected.HasComponent <YoggieEngine::CameraComponent>()) {
|
||||
auto& camera = selected.GetComponent<YoggieEngine::CameraComponent>();
|
||||
if (ImGui::CollapsingHeader("Camera")) {
|
||||
ImGui::DragFloat3("Position:", glm::value_ptr(camera.Position), 0.01f);
|
||||
ImGui::DragFloat3("Rotation:", glm::value_ptr(camera.Rotation), 0.01f);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (selected.HasComponent<YoggieEngine::RigidBody>()) {
|
||||
auto& rigibody = selected.GetComponent<YoggieEngine::RigidBody>();
|
||||
if (ImGui::CollapsingHeader("RigidBody")) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (selected.HasComponent<YoggieEngine::ScriptComponent>()) {
|
||||
ComponentView("Scripting", [] {
|
||||
ImGui::LabelText("##--", "Hello scripting");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ComponentView(const std::string& componentName, voidFunction func)
|
||||
{
|
||||
ImGuiWindowFlags_ window_flags = ImGuiWindowFlags_None;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f);
|
||||
ImGui::BeginChild(componentName.c_str());
|
||||
|
||||
func();
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
20
Editor/src/PropertyPanels/Inspector.h
Normal file
20
Editor/src/PropertyPanels/Inspector.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||
#include "../EditorWindow.h"
|
||||
|
||||
typedef void (*voidFunction) (void);
|
||||
|
||||
inline void ComponentView(const std::string& componentName, voidFunction func);
|
||||
|
||||
class Inspector : public EditorWindow {
|
||||
public:
|
||||
Inspector() : EditorWindow("Inspector") {}
|
||||
|
||||
void Draw()override;
|
||||
|
||||
|
||||
void AddComponentDropDown(YoggieEngine::Entity& selected);
|
||||
|
||||
void ShowComponents(YoggieEngine::Entity& selected);
|
||||
|
||||
};
|
13
Editor/src/PropertyPanels/SceneExplorer.cpp
Normal file
13
Editor/src/PropertyPanels/SceneExplorer.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "SceneExplorer.h"
|
||||
|
||||
void SceneExplorer::Draw()
|
||||
{
|
||||
scene.getReg().each([&](entt::entity enttNumber) {
|
||||
YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &scene);
|
||||
auto id = entity.GetComponent<YoggieEngine::IdentifierComponent>();
|
||||
|
||||
if (ImGui::Selectable(id.name.c_str(), enttNumber == selected)) {
|
||||
selected = enttNumber;
|
||||
}
|
||||
});
|
||||
}
|
20
Editor/src/PropertyPanels/SceneExplorer.h
Normal file
20
Editor/src/PropertyPanels/SceneExplorer.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||
#include "../EditorWindow.h"
|
||||
#include "../../src/Scene/Entity.h"
|
||||
|
||||
class SceneExplorer : public EditorWindow {
|
||||
public:
|
||||
SceneExplorer(entt::entity& selected, YoggieEngine::Scene& scene)
|
||||
: EditorWindow("SceneExplorer"), scene(scene), selected(selected)
|
||||
{}
|
||||
|
||||
void Draw() override;
|
||||
|
||||
|
||||
private:
|
||||
entt::entity selected;
|
||||
YoggieEngine::Scene& scene;
|
||||
|
||||
|
||||
};
|
Reference in New Issue
Block a user