#pragma once #include #include #include #include #include #include #include "AssetManagement/SceneSerializer.h" #include "AssetManagement/AssetRegistry.h" #include "AssetManagement/AssetFinder.h" #include "PropertyPanels/Inspector.h" #include "AssetManagement/uuid.h" #include "Project/Settings.h" #include "Console.h" #include "AssetManagement/AssetLoaders/ModelLoader.h" #include "IconsMaterialDesign.h" #include "Project/Project.h" #include using namespace YoggieEngine; class EditorLayer : public Layer { public: EditorLayer(): Layer(), inspector (Selected) { } void OnStartup() override { std::string path = (std::filesystem::current_path()).string(); project.setProjectDirectory(path); assetsView = AssetFinder(project.GetProjectDirectory()); LoadLastOrEmptyProject(); AssetRegistry assetManager = AssetRegistry(); ModelLoader modelLoader = ModelLoader(); spdlog::info( "{0}", project.GetProjectDirectory().string()); auto latern = modelLoader.LoadAsset(std::filesystem::path("build/debug/Models/Latern.gltf")); spdlog::info( "Loaded mesh: {0}" , latern.GetName() ); //Settings settings = Settings(); //Console console = Console(); Logo = Texture("rsc/Yoggie.png", true); Selected = YoggieEngine::Entity((entt::entity)-1, &scene); } void OnUpdate() override { scene.Update(); /* * if (Sceneview.isFocused) { UpdateSceneCamera(sceneview); } */ } void OnUI() override { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { ImGui::GetWindowWidth(), 7 }); ImGui::BeginMainMenuBar(); int scaleFactor = 30; ImGui::Image((ImTextureID)Logo.GetID(), { Logo.getSize().x / scaleFactor , Logo.getSize().y / scaleFactor }); ImGui::PopStyleVar(); if (ImGui::BeginMenu("App")) { if (ImGui::MenuItem("Load Project")) { nfdresult_t result = NFD_OpenDialog({ "yproj" }, NULL, &path); switch (result) { case(NFD_OKAY): //Project::LoadProject(path, project); //AssetRegistry::setAssetPath(project.GetProjectDirectory()); //AssetRegistry::BuildAssetView(); break; case(NFD_CANCEL): break; case(NFD_ERROR): spdlog::error("NFD_Error: {0}", NFD_GetError()); break; } } if (ImGui::MenuItem("Save project as...")) { nfdresult_t result = NFD_SaveDialog({ "yproj" }, NULL, &path); switch (result) { case(NFD_OKAY): spdlog::info("Save as: {0}", path); //Project::SaveProject(path, project); break; case(NFD_CANCEL): break; case(NFD_ERROR): spdlog::error("NFD_Error: {0}", NFD_GetError()); break; } } ImGui::EndMenu(); } if (ImGui::BeginMenu("Scene")) { if (ImGui::MenuItem("Save scene")) { nfdresult_t result = NFD_SaveDialog({ "yscene" }, NULL, &path); switch (result) { case(NFD_OKAY): //SaveScene(path, scene); //project.AddScene(scene); break; case(NFD_CANCEL): break; case(NFD_ERROR): std::cout << "NFD_Error: " << NFD_GetError() << std::endl; break; } } if (ImGui::MenuItem("Load scene")) { auto result = NFD_OpenDialog({ "yscene" }, NULL, &path); switch (result) { case (NFD_OKAY): //LoadScene(path, scene); break; case(NFD_CANCEL): break; case(NFD_ERROR): std::cout << "NFD_Error: " << NFD_GetError() << std::endl; break; } } if (ImGui::MenuItem("Add Entity")) { //scene.AddEntity("New Entity"); } if (ImGui::MenuItem("Import Model")) { auto result = NFD_OpenDialog("obj,fbx,gltf", NULL, &path); switch (result) { case(NFD_OKAY): // Import Model AssetRegistry::LoadFromSource( path, "build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets" ); break; case(NFD_CANCEL): break; case(NFD_ERROR): std::cout << "NFD_Error: " << NFD_GetError() << std::endl; break; } } if (ImGui::MenuItem("Import MeshAsset (temp)")) { auto result = NFD_OpenDialog("mesh", NULL, &path); switch (result) { case(NFD_OKAY): { YoggieEngine::Mesh* importedMesh = AssetRegistry::LoadFromAssetFile(path); if (importedMesh != nullptr) { auto full_name = std::filesystem::path(path); // auto importedModel = scene.AddEntity(full_name.filename().u8string()); // auto& rendererComponent = importedModel.AddComponent(); // rendererComponent.mesh = *importedMesh; } } break; case(NFD_CANCEL): spdlog::debug("User cancelled action"); break; case(NFD_ERROR): spdlog::warn("Something went wrong!"); break; } } ImGui::EndMenu(); } ImGui::SameLine(ImGui::GetWindowWidth() / 4 * 3); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.3f, 0.3f, 0.3f, 1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::Button(ICON_MD_ROCKET_LAUNCH "Project"); ImGui::SameLine(ImGui::GetWindowWidth() - 120); /* ImGui::PopStyleColor(); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.1f, 0.1f, 0.1f, 0.01f)); if (ImGui::Button(ICON_MD_MINIMIZE)) { spdlog::info("Minimize"); } if (ImGui::Button(ICON_MD_MAXIMIZE)) { spdlog::info("Maximize"); } if (ImGui::Button(ICON_MD_CLOSE)) { spdlog::info("Quit"); } */ ImGui::PopStyleColor(1); ImGui::PopStyleVar(); ImGui::EndMainMenuBar(); ImGui::Begin("RuntimeControls"); ImGui::SameLine((ImGui::GetWindowContentRegionMax().x / 2) - (90)); auto color = ImVec4{ 0.001 * 12 , 0.001 * 201 , 0.001 * 69, 1.0f }; ImGui::PushStyleColor(ImGuiCol_Button, color); const float strengthIncrease = 1.5f; ImGui::PushStyleColor( ImGuiCol_ButtonHovered, ImVec4{ color.x * strengthIncrease, color.y * strengthIncrease, color.z * strengthIncrease, color.w } ); if (ImGui::Button(ICON_MD_PLAY_ARROW, { 90,25 })) { // Play game } ImGui::PopStyleColor(2); ImGui::SameLine(); color = ImVec4{ 0.001 * 14, 0.001 * 157, 0.001 * 201, 1.0f }; ImGui::PushStyleColor(ImGuiCol_Button, color); ImGui::PushStyleColor( ImGuiCol_ButtonHovered, ImVec4{ color.x * strengthIncrease, color.y * strengthIncrease, color.z * strengthIncrease, color.w } ); if (ImGui::Button(ICON_MD_ELECTRIC_BOLT, { 90,25 })) { // Simulate physics } ImGui::PopStyleColor(2); ImGui::End(); ImGui::Begin("SceneView"); //ImGui::Image((ImTextureID)gameScreen.GetID(), gameScreen.getSize()); ImGuizmo::Enable(true); ImGuizmo::SetOrthographic(false); ImGuizmo::SetDrawlist(); ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetContentRegionMax().x, ImGui::GetContentRegionMax().y); /* const auto& projection = camera.projection; glm::mat4& view = glm::mat4(1.0f); ImGuizmo::DrawGrid(); ImGuizmo::ViewManipulate(); if(selected != nullptr && selected->isValid()){ auto& tc = selected->GetComponent(); glm::mat4 transform = tc.GetTransform(); ImGuizmo::Manipulate(); } */ ImGui::End(); ImGui::Begin(ICON_MD_MENU "SceneExplorer",nullptr); scene.getReg().each([&](entt::entity enttNumber) { YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &scene); auto id = entity.GetComponent(); if (ImGui::Selectable(id.name.c_str(), entity == Selected)) { Selected = YoggieEngine::Entity(enttNumber, &scene); } }); ImGui::End(); inspector.Update(); //settings.Update(); //console.Update(); assetsView.Update(); ImGui::ShowDemoWindow(); //ImGui::ShowMetricsWindow(); } void OnCreate() override { spdlog::info(" Layer Create!" ); } void OnDestroy() override { spdlog::info( " Layer Destroy!" ); } private: Inspector inspector; AssetFinder assetsView; bool SimulatePhysics = true; YoggieEngine::Entity Selected; Project project; Scene scene; char* path = nullptr; Texture Logo; void LoadLastOrEmptyProject() { // Check if there is a last known loaded project and // load that one . // Otherwise load no project.. // OR // Load an empty project. mINI::INIStructure ini; if (std::filesystem::exists("build\\Debug\\Editor.ini")) { mINI::INIFile file("build\\Debug\\Editor.ini"); file.read(ini); } else { spdlog::debug("Could not find an `Editor.ini` file."); } if (ini["editor"]["openlastproject"] == "TRUE") { Project::LoadProject(ini["cache"]["project"], project); LoadScene(ini["cache"]["scene"], scene); } else { spdlog::debug("Starting without a project. Please create one."); } } void UpdateSceneCamera() { const float movement_speed = 0.01f; static float lastX = 400, lastY = 300; const float sensitivity = 0.1; static bool firstMouse = true; /* if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) { glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); auto newX = getCursorPosX(appWindow); auto newY = getCursorPosY(appWindow); if (firstMouse) { lastX = newX; lastY = newY; firstMouse = false; } float xoffset = newX - lastX; float yoffset = newY - lastY; lastX = newX; lastY = newY; xoffset *= sensitivity; yoffset *= sensitivity; sceneview.cam.Rotation.x += (xoffset / 2); sceneview.cam.Rotation.y += (xoffset /2); sceneview.cam.Rotation.z += yoffset; if (sceneview.cam.pitch > 89.0f) sceneview.cam.pitch = 89.0f; if (sceneview.cam.pitch < -89.0f) sceneview.cam.pitch = -89.0f; } else if (firstMouse == false) { glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); firstMouse = true; } */ /* EditorCamera& cam = sceneview.GetCamera(); if (keyIsPressed(YOGGIE_KEY_UP)) cam.Rotation.x += movement_speed; if (keyIsPressed(YOGGIE_KEY_DOWN)) cam.Rotation.x -= movement_speed; if (keyIsPressed(YOGGIE_KEY_LEFT)) cam.Rotation.y += movement_speed; if (keyIsPressed(YOGGIE_KEY_RIGHT)) cam.Rotation.y -= movement_speed; cam.Update(); */ /* // Check for Camara movement input here! if (keyIsPressed(YOGGIE_KEY_W)) sceneview.cam.Position -= sceneview.cam.Front * movement_speed; if (keyIsPressed(YOGGIE_KEY_A)) sceneview.cam.Position += sceneview.cam.Right * movement_speed; if (keyIsPressed(YOGGIE_KEY_S)) sceneview.cam.Position += sceneview.cam.Front * movement_speed; if (keyIsPressed(YOGGIE_KEY_D)) sceneview.cam.Position -= sceneview.cam.Right * movement_speed; */ } };