* Filling out script component inspector * adding error_callback for glfw * Measuring gflwInit time * Moving Swap interval set to be after making context current
175 lines
5.6 KiB
C++
175 lines
5.6 KiB
C++
#include "Inspector.h"
|
|
#include "../TransformVec3.h"
|
|
|
|
void Inspector::Draw()
|
|
{
|
|
if (selected.isValid()) {
|
|
AddComponentDropDown();
|
|
ShowComponents();
|
|
}
|
|
}
|
|
void AddComponent(YoggieEngine::Entity selected , int i) {
|
|
switch (i) {
|
|
case 0:
|
|
selected.AddComponent<YoggieEngine::ScriptComponent>();
|
|
break;
|
|
case 1:
|
|
selected.AddComponent<YoggieEngine::CameraComponent>();
|
|
break;
|
|
case 2:
|
|
selected.AddComponent<YoggieEngine::LightComponent>();
|
|
break;
|
|
case 3:
|
|
selected.AddComponent<YoggieEngine::Render3DComponent>();
|
|
default:
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Inspector::AddComponentDropDown()
|
|
{
|
|
static char* names[] = { "Script Component", "Camera Component", "Light Component", "Render3D"};
|
|
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]))
|
|
AddComponent(selected, i);
|
|
}
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
ImGui::NewLine();
|
|
}
|
|
|
|
|
|
void Inspector::ShowComponents()
|
|
{
|
|
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);
|
|
*/
|
|
auto something = glm::value_ptr(transform.Position);
|
|
|
|
ImGuiExtension::TransformVec3("Position", transform.Position);
|
|
ImGuiExtension::TransformVec3("Rotation", transform.Rotation);
|
|
ImGuiExtension::TransformVec3("Scale", transform.Scale);
|
|
|
|
|
|
}
|
|
if (selected.HasComponent<YoggieEngine::RelationComponent>()) {
|
|
ImGui::Text("Has relation");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (selected.HasComponent<YoggieEngine::Render3DComponent>()) {
|
|
auto& render3d = selected.GetComponent<YoggieEngine::Render3DComponent>();
|
|
const char* AssetNames[]{ "Asset1" , "Asset2" };
|
|
if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
if (ImGui::Button("Select Renderable Asset"))
|
|
ImGui::OpenPopup("Renderable_list_popup");
|
|
ImGui::SameLine();
|
|
ImGui::TextUnformatted(render3d.mesh.elements.empty() ? "<None>" : "ASSET_GUID_OR_ID");
|
|
if (ImGui::BeginPopup("Renderable_list_popup")) {
|
|
ImGui::Text("None");
|
|
ImGui::Separator();
|
|
for (int i = 0; i < IM_ARRAYSIZE(AssetNames); i++) {
|
|
if(ImGui::Selectable(AssetNames[i]))
|
|
{ }
|
|
}
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>()) {
|
|
const char* AssetNames[]{ "Script 1" , "Script 2" };
|
|
if (ImGui::CollapsingHeader("Script", ImGuiTreeNodeFlags_Leaf)) {
|
|
|
|
if (ImGui::Button("Select Renderable Asset"))
|
|
ImGui::OpenPopup("Scripts_list_popup");
|
|
|
|
if (ImGui::BeginPopup("Scripts_list_popup")) {
|
|
ImGui::Text("None");
|
|
ImGui::Separator();
|
|
for (int i = 0; i < IM_ARRAYSIZE(AssetNames); i++) {
|
|
if (ImGui::Selectable(AssetNames[i]))
|
|
{
|
|
}
|
|
}
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
std::string scriptAssetId = "<Random_GUID>";
|
|
ImGui::InputText("asset", scriptAssetId.data(), scriptAssetId.length(), ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AutoSelectAll);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
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();
|
|
}
|