mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-03 14:09:46 +03:00
Request to close window
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include <src/Core/Core.h>
|
||||
#include <src/Core/MulticastDelegate.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class Scene;
|
||||
@@ -12,6 +14,7 @@ class EditorRequests
|
||||
{
|
||||
private:
|
||||
MulticastDelegate<Ref<Nuake::File>> requestLoadScene;
|
||||
MulticastDelegate<std::string> requestCloseEditorWindow;
|
||||
|
||||
EditorRequests() = default;
|
||||
~EditorRequests() = default;
|
||||
@@ -24,10 +27,18 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
// Broadcast requests
|
||||
void RequestLoadScene(Ref<Nuake::File> sceneFile)
|
||||
{
|
||||
requestLoadScene.Broadcast(sceneFile);
|
||||
}
|
||||
|
||||
void RequestCloseEditorWindow(std::string windowId)
|
||||
{
|
||||
requestCloseEditorWindow.Broadcast(windowId.c_str());
|
||||
}
|
||||
|
||||
// Subcribe to requests
|
||||
auto& OnRequestCloseEditorWindow() { return requestCloseEditorWindow; }
|
||||
auto& OnRequestLoadScene() { return requestLoadScene; }
|
||||
};
|
||||
@@ -153,6 +153,7 @@ namespace Nuake {
|
||||
|
||||
EditorRequests& requests = EditorRequests::Get();
|
||||
requests.OnRequestLoadScene().AddRaw(this, &EditorInterface::OnRequestLoadScene);
|
||||
requests.OnRequestCloseEditorWindow().AddRaw(this, &EditorInterface::OnRequestCloseEditorWindow);
|
||||
|
||||
Engine::OnSceneLoaded.AddRaw(this, &EditorInterface::OnSceneLoaded);
|
||||
}
|
||||
@@ -2134,6 +2135,19 @@ namespace Nuake {
|
||||
OpenSceneWindow(file->GetRelativePath());
|
||||
}
|
||||
|
||||
void EditorInterface::OnRequestCloseEditorWindow(std::string windowName)
|
||||
{
|
||||
for (size_t i = 0; i < std::size(sceneEditors); i++)
|
||||
{
|
||||
// Erase window from sceneEditors
|
||||
if (auto window = sceneEditors[i]; window->GetWindowName() == windowName)
|
||||
{
|
||||
sceneEditors.erase(std::begin(sceneEditors) + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInterface::OpenPrefabWindow(const std::string& prefabPath)
|
||||
{
|
||||
if (!FileSystem::FileExists(prefabPath))
|
||||
@@ -2807,7 +2821,9 @@ namespace Nuake {
|
||||
prefabEditors->Draw();
|
||||
}
|
||||
|
||||
for (auto& sceneEditor : sceneEditors)
|
||||
// We need to cache, because we might delete one while iterating
|
||||
auto cachedEditors = sceneEditors;
|
||||
for (auto& sceneEditor : cachedEditors)
|
||||
{
|
||||
sceneEditor->Draw();
|
||||
}
|
||||
|
||||
@@ -125,7 +125,10 @@ namespace Nuake
|
||||
void DrawProjectSettings();
|
||||
void Overlay();
|
||||
|
||||
// Signals
|
||||
void OnRequestLoadScene(Ref<File> file);
|
||||
void OnRequestCloseEditorWindow(std::string windowName);
|
||||
|
||||
void OpenPrefabWindow(const std::string& prefabPath);
|
||||
void OpenSceneWindow(const std::string& scenePath);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "src/Scene/Scene.h"
|
||||
|
||||
#include "src/UI/ImUI.h"
|
||||
#include "../../Events/EditorRequests.h"
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -33,8 +34,7 @@ void SceneEditorWindow::Update(float ts)
|
||||
|
||||
void SceneEditorWindow::Draw()
|
||||
{
|
||||
Ref<Scene> scene = editorContext.GetScene();
|
||||
const std::string sceneName = scene->Path;
|
||||
const std::string sceneName = editorContext.GetScene()->Path;
|
||||
|
||||
// This is to prevent other windows of other scene editors to dock
|
||||
ImGuiWindowClass windowClass;
|
||||
@@ -43,7 +43,8 @@ void SceneEditorWindow::Draw()
|
||||
ImGui::SetNextWindowClass(&windowClass);
|
||||
|
||||
ImGui::SetNextWindowSizeConstraints({1280, 720}, { FLT_MAX, FLT_MAX });
|
||||
if (ImGui::Begin(std::string(ICON_FA_WINDOW_MAXIMIZE + std::string(" ") + sceneName).c_str()))
|
||||
bool shouldStayOpen = true;
|
||||
if (ImGui::Begin(std::string(ICON_FA_WINDOW_MAXIMIZE + std::string(" ") + sceneName).c_str(), &shouldStayOpen))
|
||||
{
|
||||
ImGuiWindowClass localSceneEditorClass;
|
||||
localSceneEditorClass.ClassId = ImHashStr(sceneName.c_str());
|
||||
@@ -73,5 +74,14 @@ void SceneEditorWindow::Draw()
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
if (!shouldStayOpen)
|
||||
{
|
||||
EditorRequests::Get().RequestCloseEditorWindow(editorContext.GetScene()->Path);
|
||||
}
|
||||
}
|
||||
|
||||
std::string SceneEditorWindow::GetWindowName() const
|
||||
{
|
||||
return editorContext.GetScene()->Path;
|
||||
}
|
||||
@@ -36,6 +36,8 @@ public:
|
||||
void Update(float ts);
|
||||
void Draw();
|
||||
|
||||
std::string GetWindowName() const;
|
||||
|
||||
private:
|
||||
template<DerivedFromEditorWidget T>
|
||||
inline void RegisterWidget()
|
||||
|
||||
@@ -498,9 +498,7 @@ void FileBrowserWidget::DrawFile(Ref<Nuake::File> file, uint32_t drawId)
|
||||
OS::OpenIn(file->GetAbsolutePath());
|
||||
break;
|
||||
case FileType::Scene:
|
||||
//shouldOpenScene = true;
|
||||
EditorRequests::Get().RequestLoadScene(file);
|
||||
//this->Editor->OpenSceneWindow(file->GetRelativePath());
|
||||
break;
|
||||
case FileType::Solution:
|
||||
OS::OpenIn(file->GetAbsolutePath());
|
||||
|
||||
Reference in New Issue
Block a user