2022-11-03 19:33:14 +00:00
|
|
|
#include "widgets.h"
|
2022-11-05 11:29:50 +00:00
|
|
|
#include "EditorConsole.h"
|
2022-11-03 19:33:14 +00:00
|
|
|
#include <iostream>
|
2022-11-04 13:14:53 +00:00
|
|
|
#include "../../YoggieEngine/src/Scene/Components.h"
|
|
|
|
#include "../../YoggieEngine/src/Scene/Entity.h"
|
2022-11-03 19:33:14 +00:00
|
|
|
class Editor;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Inspector(entt::entity ent , Scene& scene) {
|
|
|
|
ImGui::Begin("Inspector");
|
2022-11-04 13:14:53 +00:00
|
|
|
static char* names[] = { "Script Component", "Camera Component" };
|
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
static float Zoom = 90;
|
|
|
|
static glm::vec3 Position = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
|
|
static glm::vec3 Rotation = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
|
|
if (scene.getReg().valid(ent)) {
|
|
|
|
Entity entity = Entity(ent, &scene);
|
2022-11-05 11:50:01 +00:00
|
|
|
|
2022-11-04 13:14:53 +00:00
|
|
|
if (ImGui::Button("Add Component"))
|
|
|
|
ImGui::OpenPopup("Component picker");
|
2022-11-05 11:50:01 +00:00
|
|
|
|
2022-11-04 13:14:53 +00:00
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::BeginPopup("Component picker")) {
|
2022-11-03 19:33:14 +00:00
|
|
|
|
2022-11-04 13:14:53 +00:00
|
|
|
for (int i = 0; i < IM_ARRAYSIZE(names); i++)
|
|
|
|
if (ImGui::MenuItem(names[i])) {
|
2022-11-05 11:50:01 +00:00
|
|
|
std::cout << "Add a " << names[i] << " to "
|
2022-11-04 13:14:53 +00:00
|
|
|
<< entity.GetComponent<IdentifierComponent>().name << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-05 11:50:01 +00:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
auto component = entity.GetComponent<IdentifierComponent>();
|
2022-11-05 16:17:08 +00:00
|
|
|
char* buf = new char(component.name.size());
|
2022-11-05 11:50:01 +00:00
|
|
|
strcpy(buf, component.name.c_str());
|
2022-11-05 16:17:08 +00:00
|
|
|
ImGui::InputText("Name:",buf , sizeof(buf), ImGuiInputTextFlags_ReadOnly);
|
2022-11-05 11:50:01 +00:00
|
|
|
|
|
|
|
|
2022-11-04 13:14:53 +00:00
|
|
|
if (entity.HasComponent<TransformComponent>()) {
|
|
|
|
auto& transform = entity.GetComponent<TransformComponent>();
|
2022-11-05 11:50:01 +00:00
|
|
|
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
|
2022-11-05 16:17:08 +00:00
|
|
|
ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.01f);
|
|
|
|
ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.01f);
|
|
|
|
ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.01f, 0.0f);
|
2022-11-04 13:14:53 +00:00
|
|
|
}
|
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 13:14:53 +00:00
|
|
|
if (entity.HasComponent<LightComponent>()) {
|
|
|
|
auto& light = entity.GetComponent<LightComponent>();
|
2022-11-05 11:50:01 +00:00
|
|
|
if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
ImGui::DragFloat("Strength", &light.Strength, 0.001f);
|
|
|
|
ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color));
|
|
|
|
}
|
2022-11-03 19:33:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-04 13:14:53 +00:00
|
|
|
if (entity.HasComponent <CameraComponent>()) {
|
|
|
|
auto& camera = entity.GetComponent<CameraComponent>();
|
2022-11-03 19:33:14 +00:00
|
|
|
ComponentView("Camera", [] {
|
|
|
|
ImGui::SliderFloat("Zoom", &Zoom, 10, 190);
|
|
|
|
ImGui::InputFloat3("Position:", &Position[0]);
|
|
|
|
ImGui::InputFloat3("Rotation:", &Rotation[0]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-04 13:14:53 +00:00
|
|
|
if (entity.HasComponent<ScriptComponent>()) {
|
2022-11-03 19:33:14 +00:00
|
|
|
ComponentView("Scripting", [] {
|
|
|
|
ImGui::LabelText("##--", "Hello scripting");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneExplorer(entt::entity& selected, Scene& scene )
|
|
|
|
{
|
|
|
|
ImGui::Begin("Scene Explorer");
|
|
|
|
|
|
|
|
scene.getReg().each([&](entt::entity enttNumber) {
|
|
|
|
Entity entity = Entity(enttNumber, &scene);
|
2022-11-04 13:14:53 +00:00
|
|
|
auto id = entity.GetComponent<IdentifierComponent>();
|
2022-11-03 19:33:14 +00:00
|
|
|
|
|
|
|
if (ImGui::Selectable(id.name.c_str(), enttNumber == selected )) {
|
|
|
|
selected = enttNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2022-11-05 18:14:23 +00:00
|
|
|
void Viewport(Framebuffer& framebuffer) {
|
2022-11-03 19:33:14 +00:00
|
|
|
|
|
|
|
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoTitleBar
|
|
|
|
| ImGuiWindowFlags_NoDecoration
|
|
|
|
| ImGuiWindowFlags_NoScrollbar
|
|
|
|
| ImGuiWindowFlags_NoMove
|
|
|
|
| ImGuiWindowFlags_NoCollapse;
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 });
|
|
|
|
ImGui::Begin("Viewport", false, viewportWindowFlags);
|
|
|
|
ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{ (float)800,(float)600 });
|
|
|
|
|
|
|
|
ImGuizmo::SetDrawlist();
|
|
|
|
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
|
|
|
ImGuizmo::Enable(true);
|
|
|
|
auto cam = glm::mat4(1.0f);
|
|
|
|
auto eye = glm::vec3(0.0f);
|
|
|
|
auto center = glm::vec3(0.0f);
|
|
|
|
auto up = glm::vec3(0.0f, 1.0f, 0.0f);
|
|
|
|
auto view = glm::lookAt(eye, center, up);
|
|
|
|
|
|
|
|
glm::mat4 projection = glm::perspective(glm::radians(90.0f), (800.0f / 600.0f), 0.001f, 100.0f);
|
|
|
|
auto transformMatrix = glm::mat4(1.0f);
|
|
|
|
|
|
|
|
ImGuizmo::Manipulate(glm::value_ptr(view), glm::value_ptr(projection), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(transformMatrix));
|
|
|
|
|
|
|
|
|
|
|
|
//ImGuizmo::Manipulate(glm::value_ptr(static_cam), glm::value_ptr(static_projection), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(trans));
|
|
|
|
ImGuizmo::ViewManipulate(glm::value_ptr(cam), 8.0f, ImVec2{ 0.0f,0.0f }, ImVec2{ 128.0f,128.0f }, 0x10101010);
|
|
|
|
ImGui::End();
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings() {
|
|
|
|
ImGui::Begin("Settings");
|
2022-11-05 12:47:19 +00:00
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
ImGui::LabelText("##title-settings", "Fine grain control over your engine... ");
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2022-11-05 11:29:50 +00:00
|
|
|
auto console = EditorConsole();
|
2022-11-04 13:14:53 +00:00
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
void Console() {
|
|
|
|
ImGui::Begin("Console", false);
|
2022-11-05 11:29:50 +00:00
|
|
|
console.Draw();
|
2022-11-03 19:33:14 +00:00
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AssetsFinder() {
|
|
|
|
ImGui::Begin("Asset-Finder", false);
|
|
|
|
ImGui::Dummy(ImVec2{ 128, 128 });
|
|
|
|
ImGui::End();
|
|
|
|
}
|