add project work
This commit is contained in:
@ -14,14 +14,13 @@
|
||||
#include <Hazel/Utils/PlatformUtils.h>
|
||||
|
||||
#include "imgui_internal.h"
|
||||
#include "Hazel/Project/Project.h"
|
||||
#include "Hazel/Scripting/ScriptEngine.h"
|
||||
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
|
||||
extern const std::filesystem::path g_AssetPath;
|
||||
|
||||
EditorLayer::EditorLayer()
|
||||
: Layer("HazelEditor"), m_CameraController((float)Application::Get().GetWindow().GetWidth() / (float)Application::Get().GetWindow().GetHeight())
|
||||
{
|
||||
@ -61,10 +60,12 @@ namespace Hazel
|
||||
auto commandLineArgs = Application::Get().GetSpecification().commandLineArgs;
|
||||
if (commandLineArgs.count > 1)
|
||||
{
|
||||
auto scenePath = commandLineArgs.args[1];
|
||||
SceneSerializer sceneSerializer(m_ActiveScene);
|
||||
|
||||
sceneSerializer.Deserialize(scenePath);
|
||||
auto projectFilePath = commandLineArgs.args[1];
|
||||
OpenProject(projectFilePath);
|
||||
}else
|
||||
{
|
||||
if (!OpenProject())
|
||||
Application::Get().Close();
|
||||
}
|
||||
|
||||
}
|
||||
@ -275,11 +276,13 @@ namespace Hazel
|
||||
// ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen);
|
||||
// ImGui::MenuItem("Padding", NULL, &opt_padding);
|
||||
// ImGui::Separator();
|
||||
if (ImGui::MenuItem("New", "Ctrl+N"))
|
||||
NewScene();
|
||||
if (ImGui::MenuItem("Open...", "Ctrl+O"))
|
||||
OpenScene();
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S", false, m_ActiveScene ? true : false))
|
||||
if (ImGui::MenuItem("Open Project", "Ctrl+O"))
|
||||
OpenProject();
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::MenuItem("New Scene", "Ctrl+N"))
|
||||
NewScene();
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S", false, m_ActiveScene ? true : false))
|
||||
SaveScene();
|
||||
if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S"))
|
||||
SaveSceneAs();
|
||||
@ -305,7 +308,7 @@ namespace Hazel
|
||||
|
||||
// Scene Hierachy Panel
|
||||
m_SceneHierachyPanel.OnImGuiRender();
|
||||
m_ContentBroswerPanel.OnImGuiRender();
|
||||
m_ContentBroswerPanel->OnImGuiRender();
|
||||
|
||||
// Render Status
|
||||
{
|
||||
@ -391,7 +394,7 @@ namespace Hazel
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CONTENT_BROSWER_ITEM"))
|
||||
{
|
||||
const wchar_t* path = (const wchar_t*)payload->Data;
|
||||
OpenScene(std::filesystem::path(g_AssetPath) / path);
|
||||
OpenScene(path);
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
@ -543,6 +546,37 @@ namespace Hazel
|
||||
}
|
||||
}
|
||||
|
||||
void EditorLayer::NewProject()
|
||||
{
|
||||
Project::New();
|
||||
}
|
||||
|
||||
bool EditorLayer::OpenProject()
|
||||
{
|
||||
std::string path = FileDiaglogs::OpenFile("Hazel Project (*.proj)\0*.proj\0");
|
||||
if (path.empty())
|
||||
return false;
|
||||
|
||||
OpenProject(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorLayer::OpenProject(const std::filesystem::path& projectPath)
|
||||
{
|
||||
if (Project::Load(projectPath))
|
||||
{
|
||||
ScriptEngine::Init();
|
||||
auto startScenePath = Project::GetAssetsFileSystemPath(Project::GetActive()->GetConfig().StartScene);
|
||||
OpenScene(startScenePath);
|
||||
m_ContentBroswerPanel = CreateScope<ContentBroswerPanel>();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorLayer::SaveProject() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditorLayer::SerializeScene(Ref<Scene> scene, const std::filesystem::path& scenePath) const
|
||||
{
|
||||
const SceneSerializer serializer(scene);
|
||||
@ -555,7 +589,12 @@ namespace Hazel
|
||||
return;
|
||||
Entity selectedEntity = m_SceneHierachyPanel.GetSelectedEntity();
|
||||
if (selectedEntity)
|
||||
m_EditorScene->DuplicateEntity(selectedEntity);
|
||||
{
|
||||
Entity newEntity = m_EditorScene->DuplicateEntity(selectedEntity);
|
||||
m_SceneHierachyPanel.SetSelectedEntity(newEntity);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void EditorLayer::OnScenePlay()
|
||||
@ -649,7 +688,7 @@ namespace Hazel
|
||||
else if (Input::IsKeyPressed(KeyCode::S))
|
||||
SaveScene();
|
||||
else if (Input::IsKeyPressed(KeyCode::O))
|
||||
OpenScene();
|
||||
OpenProject();
|
||||
else if (Input::IsKeyPressed(KeyCode::N))
|
||||
NewScene();
|
||||
else if (Input::IsKeyPressed(KeyCode::D))
|
||||
@ -668,6 +707,19 @@ namespace Hazel
|
||||
else if (Input::IsKeyPressed(KeyCode::R))
|
||||
ChangeOptMode(ImGuizmo::OPERATION::ROTATE);
|
||||
}
|
||||
|
||||
if (Input::IsKeyPressed(KeyCode::DELETE))
|
||||
{
|
||||
if (Application::Get().GetImGuiLayer()->GetActiveWidgetID() == 0)
|
||||
{
|
||||
Entity selectedEntity = m_SceneHierachyPanel.GetSelectedEntity();
|
||||
if (selectedEntity)
|
||||
{
|
||||
m_SceneHierachyPanel.SetSelectedEntity({});
|
||||
m_ActiveScene->DestroyEntity(selectedEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -38,6 +38,11 @@ namespace Hazel
|
||||
void NewScene();
|
||||
void SaveScene() const;
|
||||
|
||||
void NewProject();
|
||||
bool OpenProject();
|
||||
void OpenProject(const std::filesystem::path& projectPath);
|
||||
void SaveProject() const;
|
||||
|
||||
void SerializeScene(Ref<Scene> scene, const std::filesystem::path& scenePath) const;
|
||||
|
||||
void OnDuplicateEntity();
|
||||
@ -70,8 +75,9 @@ namespace Hazel
|
||||
Ref<FrameBuffer> m_FrameBuffer;
|
||||
Ref<FrameBuffer> m_RuntimeFrameBuffer;
|
||||
|
||||
// Panels
|
||||
SceneHierachyPanel m_SceneHierachyPanel;
|
||||
ContentBroswerPanel m_ContentBroswerPanel;
|
||||
Scope<ContentBroswerPanel> m_ContentBroswerPanel;
|
||||
|
||||
int m_GizmoType = -1;
|
||||
int m_GizmoMode = -1;
|
||||
|
||||
@ -8,13 +8,13 @@
|
||||
#include <../../../../Hazel/vendor/imgui/imgui.h>
|
||||
#include <string>
|
||||
|
||||
#include "Hazel/Project/Project.h"
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
|
||||
extern const std::filesystem::path g_AssetPath = "assets";
|
||||
|
||||
ContentBroswerPanel::ContentBroswerPanel()
|
||||
: m_CurrentDirectory(g_AssetPath)
|
||||
: m_BaseDirectory(Project::GetAssetsDirectory()), m_CurrentDirectory(m_BaseDirectory)
|
||||
{
|
||||
m_DirectoryIcon = Texture2D::Create("Resources/Icons/ContentBrowser/DirectoryIcon.png");
|
||||
m_FileIcon = Texture2D::Create("Resources/Icons/ContentBrowser/FileIcon.png");
|
||||
@ -28,7 +28,7 @@ namespace Hazel
|
||||
ImGui::Text("%s", m_CurrentDirectory.string().c_str());
|
||||
ImGui::Separator();
|
||||
|
||||
if (m_CurrentDirectory != std::filesystem::path(g_AssetPath))
|
||||
if (m_CurrentDirectory != std::filesystem::path(m_BaseDirectory))
|
||||
{
|
||||
if (ImGui::Button(".."))
|
||||
{
|
||||
@ -60,7 +60,7 @@ namespace Hazel
|
||||
|
||||
if (ImGui::BeginDragDropSource())
|
||||
{
|
||||
auto relativePath = std::filesystem::relative(path, g_AssetPath);
|
||||
auto relativePath = std::filesystem::relative(path);
|
||||
const wchar_t* itemPath = relativePath.c_str();
|
||||
ImGui::SetDragDropPayload("CONTENT_BROSWER_ITEM", itemPath, (wcslen(itemPath) + 1) * sizeof(wchar_t), ImGuiCond_Once);
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ namespace Hazel
|
||||
void OnImGuiRender();
|
||||
private:
|
||||
|
||||
std::filesystem::path m_BaseDirectory;
|
||||
std::filesystem::path m_CurrentDirectory;
|
||||
|
||||
Ref<Texture2D> m_DirectoryIcon;
|
||||
|
||||
@ -9,13 +9,12 @@
|
||||
#include <imgui_internal.h>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <Hazel/Scene/Components.h>
|
||||
#include "Hazel/UI/UI.h"
|
||||
|
||||
#include "Hazel/Scripting/ScriptEngine.h"
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
extern const std::filesystem::path g_AssetPath;
|
||||
|
||||
SceneHierachyPanel::SceneHierachyPanel(const Ref<Scene>& context)
|
||||
{
|
||||
SetContext(context);
|
||||
@ -99,7 +98,7 @@ namespace Hazel
|
||||
|
||||
if (entityDeleted)
|
||||
{
|
||||
m_Context->DestoryEntity(entity);
|
||||
m_Context->DestroyEntity(entity);
|
||||
if (m_SelectionContext == entity)
|
||||
{
|
||||
m_SelectionContext = {};
|
||||
@ -365,21 +364,15 @@ namespace Hazel
|
||||
DrawComponent<ScriptComponent>("Script", entity, [entity, &scene = m_Context](auto& component) mutable
|
||||
{
|
||||
bool scriptClassExists = ScriptEngine::ClassExists(component.ClassName);
|
||||
bool setStyleFlag = false;
|
||||
|
||||
static char buffer[64] = {};
|
||||
strcpy_s(buffer, sizeof(buffer), component.ClassName.c_str());
|
||||
|
||||
if (!scriptClassExists)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.9f, 0.2f, 0.3f, 1.0f));
|
||||
setStyleFlag = true;
|
||||
}
|
||||
|
||||
UI::ScopedStyleColor textColor(ImGuiCol_Text, ImVec4(0.9f, 0.2f, 0.3f, 1.0f), !scriptClassExists);
|
||||
if (ImGui::InputText("Class", buffer, sizeof(buffer)))
|
||||
{
|
||||
component.ClassName = buffer;
|
||||
scriptClassExists = ScriptEngine::ClassExists(component.ClassName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -447,10 +440,6 @@ namespace Hazel
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (setStyleFlag)
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
});
|
||||
|
||||
DrawComponent<SpriteRendererComponent>("Sprite Renderer", entity, [](auto& component)
|
||||
@ -471,7 +460,7 @@ namespace Hazel
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CONTENT_BROSWER_ITEM"))
|
||||
{
|
||||
const wchar_t* path = (const wchar_t*)payload->Data;
|
||||
std::filesystem::path texturePath = std::filesystem::path(g_AssetPath) / path;
|
||||
const std::filesystem::path texturePath(path);
|
||||
component.Texture = Texture2D::Create(texturePath.string());
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
|
||||
Reference in New Issue
Block a user