diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index 3c4579c7..fb670e7f 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -68,7 +68,8 @@ void EditorSelectionPanel::ResolveFile(Ref file) void EditorSelectionPanel::Draw(EditorSelection selection, const std::string& id) { - if (ImGui::Begin(std::string("Properties##" + id).c_str())) + const std::string& windowID = id.empty() ? "Properties" : std::string("Properties##" + id); + if (ImGui::Begin(windowID.c_str())) { switch (selection.Type) { diff --git a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp index 409f19bc..605aaa82 100644 --- a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp +++ b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp @@ -36,7 +36,8 @@ PrefabEditorWindow::PrefabEditorWindow(Ref inPrefab) : virtualScene->GetEnvironment()->CurrentSkyType = SkyType::ProceduralSky; virtualScene->GetEnvironment()->ProceduralSkybox->SunDirection = { 0.58f, 0.34f, -0.74f }; - Prefab::InstanceInScene(inPrefab->Path, virtualScene); + prefab = Prefab::InstanceInScene(inPrefab->Path, virtualScene); + prefab->Path = inPrefab->Path; Ref outputTexture = CreateRef(defaultSize, GL_RGB); outputTexture->SetParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -78,8 +79,10 @@ void PrefabEditorWindow::Draw() { if (ImGui::BeginMenu("File")) { - ImGui::MenuItem("New", "Ctrl+N"); - ImGui::MenuItem("Open", "Ctrl+O"); + if(ImGui::MenuItem("Save", "Ctrl+S")) + { + Save(); + } ImGui::EndMenu(); } ImGui::EndMenuBar(); @@ -268,28 +271,15 @@ void PrefabEditorWindow::Draw() ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0, 0)); std::vector entities = scene->GetAllEntities(); - for (auto& e : entities) - { - ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanFullWidth; - std::string name = e.GetComponent().Name; - // If selected add selected flag. - if (Selection.Type == EditorSelectionType::Entity && Selection.Entity == e) - base_flags |= ImGuiTreeNodeFlags_Selected; - // Draw all entity without parents. - if (!e.GetComponent().HasParent) - { - // Recursively draw childrens. - DrawEntityTree(e); - } + ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanFullWidth; + std::string name = prefab->Root.GetComponent().Name; + // If selected add selected flag. + if (Selection.Type == EditorSelectionType::Entity && Selection.Entity == prefab->Root) + base_flags |= ImGuiTreeNodeFlags_Selected; - // Pop font. - //ImGui::PopFont(); + DrawEntityTree(prefab->Root); - // Right click menu - //if (ImGui::BeginPopupContextItem()) - // ImGui::EndPopup(); - } ImGui::PopStyleVar(); } ImGui::EndTable(); @@ -624,3 +614,10 @@ void PrefabEditorWindow::DrawEntityTree(Nuake::Entity e) ImGui::PopStyleVar(); //ImGui::PopFont(); } + +void PrefabEditorWindow::Save() +{ + Ref newPrefab = Prefab::CreatePrefabFromEntity(prefab->Root); + newPrefab->Path = prefab->Path; + newPrefab->SaveAs(newPrefab->Path); +} diff --git a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.h b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.h index 15a0da6b..e9a866b5 100644 --- a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.h +++ b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.h @@ -41,4 +41,5 @@ private: void DrawViewportWindow(); void RenderScene(); void DrawEntityTree(Nuake::Entity e); + void Save(); }; \ No newline at end of file diff --git a/Nuake/src/Resource/Prefab.h b/Nuake/src/Resource/Prefab.h index e1f63309..563b3e21 100644 --- a/Nuake/src/Resource/Prefab.h +++ b/Nuake/src/Resource/Prefab.h @@ -39,7 +39,7 @@ namespace Nuake { { Path = path; - FileSystem::BeginWriteFile(path, true); + FileSystem::BeginWriteFile(path, false); FileSystem::WriteLine(Serialize().dump(4)); FileSystem::EndWriteFile(); }