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