添加简单场景ctrl+s保存功能
This commit is contained in:
@ -190,7 +190,7 @@ namespace Hazel
|
|||||||
if (ImGui::MenuItem("Open...", "Ctrl+O"))
|
if (ImGui::MenuItem("Open...", "Ctrl+O"))
|
||||||
OpenScene();
|
OpenScene();
|
||||||
if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S"))
|
if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S"))
|
||||||
SaveScene();
|
SaveSceneAs();
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
if (ImGui::MenuItem("Exit")) { Hazel::Application::Get().Close(); }
|
if (ImGui::MenuItem("Exit")) { Hazel::Application::Get().Close(); }
|
||||||
@ -222,11 +222,11 @@ namespace Hazel
|
|||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
std::string name = "none";
|
// std::string name = "none";
|
||||||
if (m_HoveredEntity)
|
// if (m_HoveredEntity)
|
||||||
name = m_HoveredEntity.GetComponent<TagComponent>().Tag;
|
// name = m_HoveredEntity.GetComponent<TagComponent>().Tag;
|
||||||
|
|
||||||
ImGui::Text("Hovered Entity: %s", name.c_str());
|
// ImGui::Text("Hovered Entity: %s", name.c_str());
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
@ -348,13 +348,12 @@ namespace Hazel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorLayer::SaveScene() const
|
void EditorLayer::SaveSceneAs() const
|
||||||
{
|
{
|
||||||
std::string filepath = FileDiaglogs::SaveFile("Hazel Scene (*.scene,*.yaml)\0*.scene;*.yaml\0*\0*.*\0\0");
|
std::string filepath = FileDiaglogs::SaveFile("Hazel Scene (*.scene,*.yaml)\0*.scene;*.yaml\0*\0*.*\0\0");
|
||||||
if (!filepath.empty())
|
if (!filepath.empty())
|
||||||
{
|
{
|
||||||
SceneSerializer serializer(m_ActiveScene);
|
SerializeScene(m_ActiveScene, filepath);
|
||||||
serializer.Serialize(filepath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,17 +379,9 @@ namespace Hazel
|
|||||||
m_ActiveScene = m_EditorScene;
|
m_ActiveScene = m_EditorScene;
|
||||||
|
|
||||||
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
||||||
|
|
||||||
|
m_EditorScenePath = 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()
|
void EditorLayer::NewScene()
|
||||||
@ -398,6 +389,22 @@ namespace Hazel
|
|||||||
m_ActiveScene = CreateRef<Scene>();
|
m_ActiveScene = CreateRef<Scene>();
|
||||||
m_ActiveScene->OnViewportResize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
|
m_ActiveScene->OnViewportResize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
|
||||||
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
||||||
|
|
||||||
|
m_EditorScenePath = std::filesystem::path();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorLayer::SaveScene() const
|
||||||
|
{
|
||||||
|
if (!m_EditorScenePath.empty())
|
||||||
|
{
|
||||||
|
SerializeScene(m_ActiveScene, m_EditorScenePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorLayer::SerializeScene(Ref<Scene> scene, const std::filesystem::path& scenePath) const
|
||||||
|
{
|
||||||
|
const SceneSerializer serializer(scene);
|
||||||
|
serializer.Serialize(scenePath.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorLayer::OnDuplicateEntity()
|
void EditorLayer::OnDuplicateEntity()
|
||||||
@ -411,6 +418,7 @@ namespace Hazel
|
|||||||
|
|
||||||
void EditorLayer::OnScenePlay()
|
void EditorLayer::OnScenePlay()
|
||||||
{
|
{
|
||||||
|
SaveScene();
|
||||||
m_SceneState = SceneState::Play;
|
m_SceneState = SceneState::Play;
|
||||||
|
|
||||||
m_ActiveScene = Scene::Copy(m_EditorScene);
|
m_ActiveScene = Scene::Copy(m_EditorScene);
|
||||||
@ -444,17 +452,20 @@ namespace Hazel
|
|||||||
if (e.button.clicks && m_ViewportHovered && !ImGuizmo::IsOver() && Input::IsMouseButtonPressed(SDL_BUTTON_LEFT) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
|
if (e.button.clicks && m_ViewportHovered && !ImGuizmo::IsOver() && Input::IsMouseButtonPressed(SDL_BUTTON_LEFT) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
|
||||||
m_SceneHierachyPanel.SetSelectedEntity(m_HoveredEntity);
|
m_SceneHierachyPanel.SetSelectedEntity(m_HoveredEntity);
|
||||||
|
|
||||||
#define SHORTCUT_EXIT (SDL_KMOD_CTRL | SDLK_W)
|
#define SHORTCUT_EXIT (SDL_KMOD_CTRL + SDLK_W)
|
||||||
#define SHORTCUT_NEW (SDL_KMOD_CTRL | SDLK_N)
|
#define SHORTCUT_NEW (SDL_KMOD_CTRL + SDLK_N)
|
||||||
#define SHORTCUT_OPEN (SDL_KMOD_CTRL | SDLK_O)
|
#define SHORTCUT_OPEN (SDL_KMOD_CTRL + SDLK_O)
|
||||||
#define SHORTCUT_SAVE_ALL (SDL_KMOD_CTRL | SDL_KMOD_SHIFT | SDLK_S)
|
#define SHORTCUT_SAVE (SDL_KMOD_CTRL + SDLK_S)
|
||||||
#define SHORTCUT_CTRL_D (SDL_KMOD_CTRL | SDLK_D)
|
#define SHORTCUT_SAVE_AS (SDL_KMOD_CTRL + SDL_KMOD_SHIFT + SDLK_S)
|
||||||
|
#define SHORTCUT_CTRL_D (SDL_KMOD_CTRL + SDLK_D)
|
||||||
|
|
||||||
|
|
||||||
const auto mod = SDL_GetModState();
|
const auto mod = SDL_GetModState();
|
||||||
const auto ctrl = (mod & SDL_KMOD_CTRL) ? SDL_KMOD_CTRL : 0;
|
const auto ctrl = (mod & SDL_KMOD_CTRL) ? SDL_KMOD_CTRL : 0;
|
||||||
const auto shift = (mod & SDL_KMOD_SHIFT) ? SDL_KMOD_SHIFT : 0;
|
const auto shift = (mod & SDL_KMOD_SHIFT) ? SDL_KMOD_SHIFT : 0;
|
||||||
if (e.key.down && e.key.repeat == 0)
|
if (e.key.down && e.key.repeat == 0)
|
||||||
switch (ctrl | shift | e.key.key)
|
{
|
||||||
|
switch (ctrl + shift + e.key.key)
|
||||||
{
|
{
|
||||||
case SHORTCUT_EXIT:
|
case SHORTCUT_EXIT:
|
||||||
Application::Get().Close();
|
Application::Get().Close();
|
||||||
@ -465,9 +476,12 @@ namespace Hazel
|
|||||||
case SHORTCUT_OPEN:
|
case SHORTCUT_OPEN:
|
||||||
OpenScene();
|
OpenScene();
|
||||||
break;
|
break;
|
||||||
case SHORTCUT_SAVE_ALL:
|
case SHORTCUT_SAVE:
|
||||||
SaveScene();
|
SaveScene();
|
||||||
break;
|
break;
|
||||||
|
case SHORTCUT_SAVE_AS:
|
||||||
|
SaveSceneAs();
|
||||||
|
break;
|
||||||
case SHORTCUT_CTRL_D:
|
case SHORTCUT_CTRL_D:
|
||||||
OnDuplicateEntity();
|
OnDuplicateEntity();
|
||||||
break;
|
break;
|
||||||
@ -490,6 +504,7 @@ namespace Hazel
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EditorLayer::UI_ToolBar()
|
void EditorLayer::UI_ToolBar()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -29,10 +29,13 @@ namespace Hazel
|
|||||||
void OnScenePlay();
|
void OnScenePlay();
|
||||||
void OnSceneStop();
|
void OnSceneStop();
|
||||||
|
|
||||||
void SaveScene() const;
|
void SaveSceneAs() const;
|
||||||
void OpenScene();
|
void OpenScene();
|
||||||
void OpenScene(const std::filesystem::path& scenePath);
|
void OpenScene(const std::filesystem::path& scenePath);
|
||||||
void NewScene();
|
void NewScene();
|
||||||
|
void SaveScene() const;
|
||||||
|
|
||||||
|
void SerializeScene(Ref<Scene> scene, const std::filesystem::path& scenePath) const;
|
||||||
|
|
||||||
void OnDuplicateEntity();
|
void OnDuplicateEntity();
|
||||||
|
|
||||||
@ -48,6 +51,7 @@ namespace Hazel
|
|||||||
Ref<Scene> m_ActiveScene;
|
Ref<Scene> m_ActiveScene;
|
||||||
Ref<Scene> m_EditorScene;
|
Ref<Scene> m_EditorScene;
|
||||||
EditorCamera m_EditorCamera;
|
EditorCamera m_EditorCamera;
|
||||||
|
std::filesystem::path m_EditorScenePath;
|
||||||
|
|
||||||
Entity m_HoveredEntity;
|
Entity m_HoveredEntity;
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,8 @@ namespace Hazel
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SceneHierachyPanel::OnImGuiRender()
|
void SceneHierachyPanel::OnImGuiRender()
|
||||||
|
{
|
||||||
|
if (m_Context)
|
||||||
{
|
{
|
||||||
ImGui::Begin("Scene Hierachy");
|
ImGui::Begin("Scene Hierachy");
|
||||||
|
|
||||||
@ -47,6 +49,7 @@ namespace Hazel
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::Begin("Properties");
|
ImGui::Begin("Properties");
|
||||||
if (m_SelectionContext)
|
if (m_SelectionContext)
|
||||||
|
|||||||
Reference in New Issue
Block a user