109 lines
2.9 KiB
C
109 lines
2.9 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include "Core/IEditorContext.h"
|
||
|
|
#include "Core/IProjectManager.h"
|
||
|
|
#include "Core/ISelectionManager.h"
|
||
|
|
#include "Core/ISceneManager.h"
|
||
|
|
#include "Core/IUndoManager.h"
|
||
|
|
#include "Utils/SceneEditorUtils.h"
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
namespace XCEngine {
|
||
|
|
namespace Editor {
|
||
|
|
namespace Commands {
|
||
|
|
|
||
|
|
inline void ResetSceneEditingState(IEditorContext& context) {
|
||
|
|
context.GetSelectionManager().ClearSelection();
|
||
|
|
context.GetUndoManager().ClearHistory();
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool NewScene(IEditorContext& context, const std::string& sceneName = "Untitled Scene") {
|
||
|
|
if (!SceneEditorUtils::ConfirmSceneSwitch(context)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
context.GetSceneManager().NewScene(sceneName);
|
||
|
|
ResetSceneEditingState(context);
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool LoadScene(IEditorContext& context, const std::string& filePath, bool confirmSwitch = true) {
|
||
|
|
if (filePath.empty()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (confirmSwitch && !SceneEditorUtils::ConfirmSceneSwitch(context)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (!context.GetSceneManager().LoadScene(filePath)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
ResetSceneEditingState(context);
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool OpenSceneWithDialog(IEditorContext& context) {
|
||
|
|
if (!SceneEditorUtils::ConfirmSceneSwitch(context)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
const std::string filePath = SceneEditorUtils::OpenSceneFileDialog(
|
||
|
|
context.GetProjectPath(),
|
||
|
|
context.GetSceneManager().GetCurrentScenePath());
|
||
|
|
if (filePath.empty()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return LoadScene(context, filePath, false);
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool SaveCurrentScene(IEditorContext& context) {
|
||
|
|
return SceneEditorUtils::SaveCurrentScene(context);
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool SaveSceneAsWithDialog(IEditorContext& context) {
|
||
|
|
auto& sceneManager = context.GetSceneManager();
|
||
|
|
const std::string filePath = SceneEditorUtils::SaveSceneFileDialog(
|
||
|
|
context.GetProjectPath(),
|
||
|
|
sceneManager.GetCurrentScenePath(),
|
||
|
|
sceneManager.GetCurrentSceneName());
|
||
|
|
if (filePath.empty()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
const bool saved = sceneManager.SaveSceneAs(filePath);
|
||
|
|
if (saved) {
|
||
|
|
context.GetProjectManager().RefreshCurrentFolder();
|
||
|
|
}
|
||
|
|
return saved;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool LoadStartupScene(IEditorContext& context) {
|
||
|
|
const bool loaded = context.GetSceneManager().LoadStartupScene(context.GetProjectPath());
|
||
|
|
context.GetProjectManager().RefreshCurrentFolder();
|
||
|
|
ResetSceneEditingState(context);
|
||
|
|
return loaded;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool SaveDirtySceneWithFallback(IEditorContext& context, const std::string& fallbackPath) {
|
||
|
|
auto& sceneManager = context.GetSceneManager();
|
||
|
|
if (!sceneManager.HasActiveScene() || !sceneManager.IsSceneDirty()) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (sceneManager.SaveScene()) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (fallbackPath.empty()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return sceneManager.SaveSceneAs(fallbackPath);
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace Commands
|
||
|
|
} // namespace Editor
|
||
|
|
} // namespace XCEngine
|