Added saving and loading
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
#ifndef EDITOR_HPP
|
||||
#define EDITOR_HPP
|
||||
|
||||
#include "open_engine/ref_scope.hpp"
|
||||
#include "panels/scene_hierarchy.hpp"
|
||||
#include <open_engine.hpp>
|
||||
|
||||
#include "panels/scene_hierarchy.hpp"
|
||||
|
||||
//#include <imfilebrowser.h>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/matrix.hpp>
|
||||
@@ -27,16 +28,18 @@ namespace OpenEngine {
|
||||
{
|
||||
auto delta = Time::DeltaTime();
|
||||
|
||||
auto& position = GetComponent<TransformComponent>().translation;
|
||||
if (HasComponent<TransformComponent>()) {
|
||||
auto& position = GetComponent<TransformComponent>().translation;
|
||||
|
||||
if (Input::IsKeyPressed(KeyCode::Up))
|
||||
position.y += 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Down))
|
||||
position.y -= 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Right))
|
||||
position.x += 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Left))
|
||||
position.x -= 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Up))
|
||||
position.y += 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Down))
|
||||
position.y -= 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Right))
|
||||
position.x += 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Left))
|
||||
position.x -= 5.0 * delta;
|
||||
}
|
||||
};
|
||||
|
||||
void OnDestroy()
|
||||
@@ -48,16 +51,11 @@ namespace OpenEngine {
|
||||
{
|
||||
public:
|
||||
EditorLayer()
|
||||
: Layer("editor_layer")/*,
|
||||
camera((float)Application::Get().GetWindow().GetWidth() /
|
||||
Application::Get().GetWindow().GetHeight(), 1.0f)
|
||||
*/
|
||||
{
|
||||
}
|
||||
: Layer("editor_layer")
|
||||
{
|
||||
}
|
||||
~EditorLayer() {};
|
||||
|
||||
entt::registry registry;
|
||||
|
||||
void OnAttach() override
|
||||
{
|
||||
OE_PROFILE_FUNCTION();
|
||||
@@ -70,15 +68,15 @@ namespace OpenEngine {
|
||||
|
||||
scene = CreateRef<Scene>();
|
||||
|
||||
sq_entity = scene->CreateEntity("square");
|
||||
//sq_entity = scene->CreateEntity("square");
|
||||
|
||||
sq_entity.AddComponents<TransformComponent>();
|
||||
sq_entity.AddComponents<SpriteRendererComponent>(glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
//sq_entity.AddComponents<TransformComponent>();
|
||||
//sq_entity.AddComponents<SpriteRendererComponent>(glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
||||
camera_bis = scene->CreateEntity("Main camera");
|
||||
camera_bis.AddComponents<TransformComponent>();
|
||||
camera_bis.AddComponents<CameraComponent>();
|
||||
camera_bis.AddComponents<NativeScriptComponent>().Bind<CameraController>();
|
||||
//camera_bis = scene->CreateEntity("Main camera");
|
||||
//camera_bis.AddComponents<TransformComponent>();
|
||||
//camera_bis.AddComponents<CameraComponent>();
|
||||
//camera_bis.AddComponents<NativeScriptComponent>().Bind<CameraController>();
|
||||
|
||||
scene_hierarchy.SetContext(scene);
|
||||
}
|
||||
@@ -258,10 +256,68 @@ namespace OpenEngine {
|
||||
ImGui::End();
|
||||
};
|
||||
|
||||
/*
|
||||
void test2()
|
||||
{
|
||||
// (optional) set browser properties
|
||||
fileDialog.SetTitle("title");
|
||||
fileDialog.SetTypeFilters({ ".oes" });
|
||||
fileDialog.Open();
|
||||
};
|
||||
*/
|
||||
|
||||
void OnImGuiRender() override
|
||||
{
|
||||
OE_PROFILE_FUNCTION();
|
||||
|
||||
{
|
||||
// Testing file pickers
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("Save As", "Ctrl+S")) {
|
||||
std::string file = FileDialogs::SaveFile("useless");
|
||||
OE_TRACE("saving to filename: {}", file);
|
||||
if (!file.empty()) {
|
||||
SceneSerializer serializer(scene);
|
||||
serializer.Serialize(file);
|
||||
}
|
||||
}
|
||||
if (ImGui::MenuItem("Load", "Ctrl+O")) {
|
||||
std::string file = FileDialogs::OpenFile("useless");
|
||||
OE_DEBUG("loading filename: {}", file);
|
||||
if (!file.empty()) {
|
||||
scene = CreateRef<Scene>();
|
||||
scene->OnViewportResize((uint32_t)viewport_size.x, (uint32_t)viewport_size.y);
|
||||
scene_hierarchy.SetContext(scene);
|
||||
|
||||
SceneSerializer serializer(scene);
|
||||
serializer.Deserialize(file);
|
||||
}
|
||||
}
|
||||
if (ImGui::MenuItem("New Scene", "Ctrl+N")) {
|
||||
scene = CreateRef<Scene>();
|
||||
scene->OnViewportResize((uint32_t)viewport_size.x, (uint32_t)viewport_size.y);
|
||||
scene_hierarchy.SetContext(scene);
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Exit"))
|
||||
Application::Get().Close();
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
/*
|
||||
fileDialog.Display();
|
||||
|
||||
if(fileDialog.HasSelected())
|
||||
{
|
||||
OE_TRACE("Selected filename {}", fileDialog.GetSelected().string());
|
||||
fileDialog.ClearSelected();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
ImGui::DockSpaceOverViewport();
|
||||
|
||||
DrawStats();
|
||||
@@ -279,12 +335,13 @@ namespace OpenEngine {
|
||||
glm::vec2 viewport_size = { 0.0f, 0.0f };
|
||||
Ref<OpenEngine::FrameBuffer> framebuffer;
|
||||
SceneHierarchy scene_hierarchy;
|
||||
//OrthographicCameraController camera;
|
||||
|
||||
Entity camera_bis;
|
||||
|
||||
Ref<Scene> scene;
|
||||
Entity sq_entity;
|
||||
//ImGui::FileBrowser fileDialog;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -296,3 +353,24 @@ class EditorApp : public OpenEngine::Application
|
||||
};
|
||||
|
||||
#endif // EDITOR_HPP
|
||||
|
||||
/*
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
std::string OpenFile() {
|
||||
char buffer[1024];
|
||||
// This command opens a native GTK file picker and returns the path
|
||||
FILE* pipe = popen("zenity --file-selection", "r");
|
||||
if (!pipe) return "";
|
||||
|
||||
if (fgets(buffer, sizeof(buffer), pipe) != NULL) {
|
||||
std::string path = buffer;
|
||||
path.erase(path.find_last_not_of("\n") + 1); // Clean newline
|
||||
pclose(pipe);
|
||||
return path;
|
||||
}
|
||||
pclose(pipe);
|
||||
return "";
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user