添加简单文件资产视图, 添加资源拖拽功能

This commit is contained in:
2025-06-11 00:22:53 +08:00
parent f4aa895bbb
commit 91af2392ed
15 changed files with 194 additions and 10 deletions

View File

@ -16,6 +16,9 @@
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())
{
@ -191,6 +194,7 @@ namespace Hazel
// Scene Hierachy Panel
m_SceneHierachyPanel.OnImGuiRender();
m_ContentBroswerPanel.OnImGuiRender();
// Render Status
{
@ -236,6 +240,15 @@ namespace Hazel
ImGui::Image(m_FrameBuffer->GetColorAttachmentID(), {m_ViewPortSize.x, m_ViewPortSize.y}, {0, 1},
{1, 0});
if (ImGui::BeginDragDropTarget())
{
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);
}
ImGui::EndDragDropTarget();
}
auto windowsSize = ImGui::GetWindowSize();
ImVec2 minBound = ImGui::GetWindowPos();
@ -326,14 +339,17 @@ namespace Hazel
{
std::string filepath = FileDiaglogs::OpenFile("Scene(*.scene, *.yaml)\0*.scene;*.yaml\0All files\0*.*\0\0");
if (!filepath.empty())
{
m_ActiveScene = CreateRef<Scene>();
m_ActiveScene->OnViewportResize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
m_SceneHierachyPanel.SetContext(m_ActiveScene);
OpenScene(filepath);
}
SceneSerializer serializer(m_ActiveScene);
serializer.Deserialize(filepath);
}
void EditorLayer::OpenScene(const std::filesystem::path& scenePath)
{
m_ActiveScene = CreateRef<Scene>();
m_ActiveScene->OnViewportResize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
m_SceneHierachyPanel.SetContext(m_ActiveScene);
SceneSerializer serializer(m_ActiveScene);
serializer.Deserialize(scenePath.string());
}
void EditorLayer::NewScene()
@ -359,6 +375,7 @@ namespace Hazel
if (e.button.clicks && m_ViewportHovered && !ImGuizmo::IsOver() && Input::IsMouseButtonPressed(SDL_BUTTON_LEFT) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
m_SceneHierachyPanel.SetSelectedEntity(m_HoveredEntity);
#define SHORTCUT_EXIT (SDL_KMOD_CTRL | SDLK_W)
#define SHORTCUT_NEW (SDL_KMOD_CTRL | SDLK_N)
#define SHORTCUT_OPEN (SDL_KMOD_CTRL | SDLK_O)
#define SHORTCUT_SAVE_ALL (SDL_KMOD_CTRL | SDL_KMOD_SHIFT | SDLK_S)
@ -369,6 +386,9 @@ namespace Hazel
switch (ctrl | shift | e.key.key)
{
case SHORTCUT_EXIT:
Application::Get().Close();
break;
case SHORTCUT_NEW:
NewScene();
break;