YoggieEngine/Editor/src/UI/widgets.cpp
Nigel Barink 628225af45 Asset explorer showing files
After loading a project the asset explorer now show all the project files.
2022-11-11 13:10:05 +01:00

228 lines
7.2 KiB
C++

#include "widgets.h"
#include "EditorConsole.h"
#include <iostream>
#include "../../YoggieEngine/src/Scene/Components.h"
#include "../../YoggieEngine/src/Scene/Entity.h"
#include "../AssetManagement/AssetManager.h"
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");
static char* names[] = { "Script Component", "Camera Component" };
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);
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 "
<< entity.GetComponent<IdentifierComponent>().name << std::endl;
}
ImGui::EndPopup();
}
ImGui::NewLine();
auto component = entity.GetComponent<IdentifierComponent>();
char* buf = new char(component.name.size());
strcpy(buf, component.name.c_str());
ImGui::InputText("Name:",buf , sizeof(buf), ImGuiInputTextFlags_ReadOnly);
if (entity.HasComponent<TransformComponent>()) {
auto& transform = entity.GetComponent<TransformComponent>();
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
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);
}
}
if (entity.HasComponent<Render3DComponent>()) {
auto& render3d = entity.GetComponent<Render3DComponent>();
if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color));
}
}
if (entity.HasComponent<LightComponent>()) {
auto& light = entity.GetComponent<LightComponent>();
if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::DragFloat("Strength", &light.Strength, 0.001f);
ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color));
}
}
if (entity.HasComponent <CameraComponent>()) {
auto& camera = entity.GetComponent<CameraComponent>();
ComponentView("Camera", [] {
ImGui::SliderFloat("Zoom", &Zoom, 10, 190);
ImGui::InputFloat3("Position:", &Position[0]);
ImGui::InputFloat3("Rotation:", &Rotation[0]);
});
}
if (entity.HasComponent<ScriptComponent>()) {
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);
auto id = entity.GetComponent<IdentifierComponent>();
if (ImGui::Selectable(id.name.c_str(), enttNumber == selected )) {
selected = enttNumber;
}
});
ImGui::End();
}
void Viewport(Framebuffer& framebuffer) {
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar ;
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();
}
void GamePort(Framebuffer& framebuffer)
{
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar;
ImGui::Begin("Game", false, viewportWindowFlags);
ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{ (float)800, (float)600 });
ImGui::End();
}
void Settings() {
ImGui::Begin("Settings");
ImGui::LabelText("##title-settings", "Fine grain control over your engine... ");
ImGui::End();
}
auto console = EditorConsole();
void Console() {
ImGui::Begin("Console", false);
console.Draw();
ImGui::End();
}
void AssetsFinder() {
static YoggieEngine::Texture folderIcon ("rsc/folderIcon.png");
static YoggieEngine::Texture AssetIcon("rsc/assetIcon.png");
static int iconSize = 60;
ImGui::Begin("Asset-Finder", false);
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
if (ImGui::BeginTable("##resources", 3))
{
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f));
int row = 0;
int column = 0 ;
for (auto& asset : AssetManager::assets) {
if (column % 3 == 0) {
ImGui::TableNextRow();
column = 0;
row++;
}
ImGui::TableSetColumnIndex(column);
if (asset.isFolder) {
ImGui::ImageButton(
(ImTextureID)folderIcon.GetID(),
ImVec2{ (float)iconSize,(float)iconSize });
ImGui::Text(asset.GetName(), row);
}
else {
ImGui::ImageButton(
(ImTextureID)AssetIcon.GetID(),
ImVec2{ (float)iconSize, (float)iconSize });
ImGui::Text(asset.GetName(), row);
}
column++;
}
ImGui::PopStyleColor(3);
ImGui::EndTable();
}
ImGui::End();
}