diff --git a/Projects/Editor/Source/Editor/CEditor.cpp b/Projects/Editor/Source/Editor/CEditor.cpp index a4eddd25d..55ae22cc9 100644 --- a/Projects/Editor/Source/Editor/CEditor.cpp +++ b/Projects/Editor/Source/Editor/CEditor.cpp @@ -376,6 +376,8 @@ namespace Skylicht GUI::CMenuItem* file = m_menuBar->addItem(L"File"); submenu = file->getMenu(); + submenu->addItem(L"New scene"); + submenu->addSeparator(); submenu->addItem(L"Save", GUI::ESystemIcon::Save, L"Ctrl + S"); submenu->addItem(L"Save As"); submenu->OnOpen = BIND_LISTENER(&CEditor::OnOpenMenuFile, this); @@ -1043,6 +1045,11 @@ namespace Skylicht } } + void CEditor::OnMenuNewScene(GUI::CBase* item) + { + CSceneController::getInstance()->newScene(); + } + void CEditor::OnMenuSave(GUI::CBase* item) { bool saveScene = true; @@ -1068,6 +1075,50 @@ namespace Skylicht } } + void CEditor::OnMenuSaveAs(GUI::CBase* item) + { + bool saveScene = true; + bool saveCanvas = false; + + CSelectObject* selectObject = CSelection::getInstance()->getLastSelected(); + if (selectObject != NULL) + { + if (selectObject->getType() == CSelectObject::GUIElement) + { + saveCanvas = true; + saveScene = false; + } + } + + std::string assetFolder = CAssetManager::getInstance()->getAssetFolder(); + + if (saveScene) + { + GUI::COpenSaveDialog* dialog = new GUI::COpenSaveDialog(m_canvas, + GUI::COpenSaveDialog::SaveAs, + assetFolder.c_str(), + assetFolder.c_str(), + "scene;*"); + dialog->OnSave = [&](std::string path) + { + CSceneController::getInstance()->save(path.c_str()); + }; + } + else if (saveCanvas) + { + GUI::COpenSaveDialog* dialog = new GUI::COpenSaveDialog(m_canvas, + GUI::COpenSaveDialog::Save, + assetFolder.c_str(), + assetFolder.c_str(), + "gui;*" + ); + dialog->OnSave = [&](std::string path) + { + CGUIDesignController::getInstance()->save(path.c_str()); + }; + } + } + void CEditor::onSaveScene() { std::string assetFolder = CAssetManager::getInstance()->getAssetFolder(); @@ -1110,9 +1161,9 @@ namespace Skylicht "gui;*" ); - dialog->OnSave = [&, controller = guiDesignController](std::string path) + dialog->OnSave = [&](std::string path) { - controller->save(path.c_str()); + CGUIDesignController::getInstance()->save(path.c_str()); }; } else @@ -1120,7 +1171,7 @@ namespace Skylicht guiDesignController->save(fileName.c_str()); } } - + void CEditor::OnCommandLogo(GUI::CBase* item) { GUI::CMenuItem* menuItem = dynamic_cast(item); @@ -1152,19 +1203,17 @@ namespace Skylicht GUI::CMenuItem* menuItem = dynamic_cast(item); const std::wstring& label = menuItem->getLabel(); - if (label == L"Save") + if (label == L"New scene") + { + OnMenuNewScene(item); + } + else if (label == L"Save") { OnMenuSave(item); } else if (label == L"Save As") { - std::string assetFolder = CAssetManager::getInstance()->getAssetFolder(); - - GUI::COpenSaveDialog* dialog = new GUI::COpenSaveDialog(m_canvas, GUI::COpenSaveDialog::SaveAs, assetFolder.c_str(), assetFolder.c_str(), "scene;*"); - dialog->OnSave = [&, controller = CSceneController::getInstance()](std::string path) - { - controller->save(path.c_str()); - }; + OnMenuSaveAs(item); } } diff --git a/Projects/Editor/Source/Editor/CEditor.h b/Projects/Editor/Source/Editor/CEditor.h index 24dd6ed2a..7f84831ec 100644 --- a/Projects/Editor/Source/Editor/CEditor.h +++ b/Projects/Editor/Source/Editor/CEditor.h @@ -152,8 +152,12 @@ namespace Skylicht void OnMenuQuit(GUI::CBase* item); + void OnMenuNewScene(GUI::CBase* item); + void OnMenuSave(GUI::CBase* item); + void OnMenuSaveAs(GUI::CBase* item); + void OnCommandLogo(GUI::CBase* item); void OnOpenMenuFile(GUI::CBase* item); @@ -177,9 +181,9 @@ namespace Skylicht public: void onSaveScene(); - + void onSaveGUICanvas(); - + void showProjectSetting(); void showGoogleMap(); diff --git a/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp b/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp index f6093e266..4f2127274 100644 --- a/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp +++ b/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp @@ -366,7 +366,7 @@ namespace Skylicht root->setDock(EGUIDock::NoDock); root->setRect(core::rectf(0.0f, 0.0f, 1920.0f, 1080.0f)); - // camera + // camera camObj = zone->createEmptyObject(); camObj->setName(L"GUICamera"); camObj->setEditorObject(true); diff --git a/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp b/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp index d6dcba673..e73b2e704 100644 --- a/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp +++ b/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp @@ -155,10 +155,78 @@ namespace Skylicht } } - void CSceneController::doLoadScene(const std::string& path) + void CSceneController::newScene() { - m_scenePath = path; + bool modify = true; + if (modify) + { + GUI::CMessageBox* msgBox = new GUI::CMessageBox(m_canvas, GUI::CMessageBox::YesNoCancel); + msgBox->setMessage(L"Do you want to save current scene?", m_scene->getName()); + msgBox->OnYes = [&](GUI::CBase* button) { + if (m_scenePath.empty() == true) + { + std::string assetFolder = CAssetManager::getInstance()->getAssetFolder(); + GUI::COpenSaveDialog* dialog = new GUI::COpenSaveDialog(m_canvas, GUI::COpenSaveDialog::Save, assetFolder.c_str(), assetFolder.c_str(), "scene;*"); + dialog->OnSave = [&](std::string path) + { + save(path.c_str()); + }; + } + else + { + save(m_scenePath.c_str()); + doNewScene(); + } + }; + msgBox->OnNo = [&](GUI::CBase* button) { + doNewScene(); + }; + } + else + { + doNewScene(); + } + } + + void CSceneController::doNewScene() + { + m_scenePath.clear(); + + // clear current scene gui + CSelection::getInstance()->clear(); + CSelecting::getInstance()->end(); + + CPropertyController::getInstance()->setProperty(NULL); + + CHandles::getInstance()->end(); + CHandles::getInstance()->setNullRenderer(); + + m_gizmos = NULL; + + if (m_history) + { + delete m_history; + m_history = NULL; + } + if (m_spaceHierarchy != NULL) + { + m_spaceHierarchy->deleteHierarchyNode(); + m_hierachyNode = NULL; + } + + deleteScene(); + + if (m_spaceScene == NULL) + { + return; + } + + m_spaceScene->initDefaultScene(); + } + + void CSceneController::doLoadScene(const std::string& path) + { // clear current scene gui CSelection::getInstance()->clear(); CSelecting::getInstance()->end(); @@ -182,6 +250,14 @@ namespace Skylicht m_hierachyNode = NULL; } + if (m_spaceScene == NULL) + { + deleteScene(); + return; + } + + m_scenePath = path; + // create new scene m_scene = m_spaceScene->initNullScene(); @@ -946,6 +1022,13 @@ namespace Skylicht propertyController->setProperty(NULL); } } + else + { + // remove last observer + CSelectObject* selectedObject = selection->getLastSelected(); + if (selectedObject != NULL) + selectedObject->removeAllObserver(); + } } void CSceneController::onObjectChange(CGameObject* object) diff --git a/Projects/Editor/Source/Editor/SpaceController/CSceneController.h b/Projects/Editor/Source/Editor/SpaceController/CSceneController.h index d19e33475..456a8a136 100644 --- a/Projects/Editor/Source/Editor/SpaceController/CSceneController.h +++ b/Projects/Editor/Source/Editor/SpaceController/CSceneController.h @@ -140,6 +140,10 @@ namespace Skylicht virtual void loadFile(const std::string& path); + void newScene(); + + void doNewScene(); + void doLoadScene(const std::string& path); void doFinishLoadScene(); diff --git a/Projects/Skylicht/Engine/RenderMesh/CMeshRendererInstancing.cpp b/Projects/Skylicht/Engine/RenderMesh/CMeshRendererInstancing.cpp index 0007aea6b..6fb3be3f2 100644 --- a/Projects/Skylicht/Engine/RenderMesh/CMeshRendererInstancing.cpp +++ b/Projects/Skylicht/Engine/RenderMesh/CMeshRendererInstancing.cpp @@ -43,6 +43,7 @@ namespace Skylicht { for (auto it : m_groups) { + it.first->InstancingGroup = NULL; delete it.second; } m_groups.clear();