Remove all singletons except EditorBaseApplication
This commit is contained in:
parent
00d0793b67
commit
7132511562
|
|
@ -11,8 +11,6 @@ namespace Nz
|
||||||
class NAZARAEDITOR_CORE_API ActionStack final
|
class NAZARAEDITOR_CORE_API ActionStack final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static ActionStack* Instance();
|
|
||||||
|
|
||||||
void ExecuteAction(const std::string& name)
|
void ExecuteAction(const std::string& name)
|
||||||
{
|
{
|
||||||
ExecuteAction(CreateAction(name));
|
ExecuteAction(CreateAction(name));
|
||||||
|
|
@ -57,10 +55,9 @@ namespace Nz
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ActionStack();
|
ActionStack();
|
||||||
~ActionStack();
|
|
||||||
|
|
||||||
ActionStack(ActionStack&) = delete;
|
ActionStack(ActionStack&) = delete;
|
||||||
ActionStack& operator=(ActionStack&) = delete;
|
ActionStack& operator=(const ActionStack&) = delete;
|
||||||
ActionStack(ActionStack&&) = delete;
|
ActionStack(ActionStack&&) = delete;
|
||||||
ActionStack& operator=(ActionStack&&) = delete;
|
ActionStack& operator=(ActionStack&&) = delete;
|
||||||
|
|
||||||
|
|
@ -70,8 +67,6 @@ namespace Nz
|
||||||
m_availableActions.push_back(std::make_unique<TAction>(properties));
|
m_availableActions.push_back(std::make_unique<TAction>(properties));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ActionStack* s_instance;
|
|
||||||
|
|
||||||
int64_t m_currentIndex;
|
int64_t m_currentIndex;
|
||||||
std::vector<std::shared_ptr<EditorAction>> m_undoRedoStack;
|
std::vector<std::shared_ptr<EditorAction>> m_undoRedoStack;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include <NazaraEditor/Core/Core.hpp>
|
#include <NazaraEditor/Core/Core.hpp>
|
||||||
#include <NazaraEditor/Core/Application/Action.hpp>
|
#include <NazaraEditor/Core/Application/Action.hpp>
|
||||||
#include <NazaraEditor/Core/Application/ActionStack.hpp>
|
#include <NazaraEditor/Core/Application/ActionStack.hpp>
|
||||||
|
#include <NazaraEditor/Core/Application/EditorLogger.hpp>
|
||||||
#include <NazaraEditor/Core/Application/Level.hpp>
|
#include <NazaraEditor/Core/Application/Level.hpp>
|
||||||
#include <NazaraEditor/Core/UI/PopupManager.hpp>
|
#include <NazaraEditor/Core/UI/PopupManager.hpp>
|
||||||
#include <NazaraEditor/Core/UI/Window.hpp>
|
#include <NazaraEditor/Core/UI/Window.hpp>
|
||||||
|
|
@ -38,10 +39,19 @@ namespace Nz
|
||||||
virtual ~EditorBaseApplication();
|
virtual ~EditorBaseApplication();
|
||||||
|
|
||||||
static EditorBaseApplication* Instance();
|
static EditorBaseApplication* Instance();
|
||||||
|
|
||||||
|
ActionStack& GetActionStack() { return m_actionStack; }
|
||||||
|
const ActionStack& GetActionStack() const { return m_actionStack; }
|
||||||
|
EditorPopupManager& GetPopupManager() { return m_popupManager; }
|
||||||
|
const EditorPopupManager& GetPopupManager() const { return m_popupManager; }
|
||||||
|
EditorLogger& GetLogger() { return *m_logger; }
|
||||||
|
const EditorLogger& GetLogger() const { return *m_logger; }
|
||||||
|
|
||||||
void SetResourceFolder(const std::filesystem::path& path) { m_resourceFolder = path; }
|
void SetResourceFolder(const std::filesystem::path& path) { m_resourceFolder = path; }
|
||||||
std::filesystem::path GetResourceFolder() const { return m_resourceFolder; }
|
std::filesystem::path GetResourceFolder() const { return m_resourceFolder; }
|
||||||
|
|
||||||
|
void SetLogger(EditorLogger& logger) { m_logger = &logger; }
|
||||||
|
|
||||||
Nz::Level& GetLevel();
|
Nz::Level& GetLevel();
|
||||||
virtual bool NewLevel();
|
virtual bool NewLevel();
|
||||||
virtual bool CloseLevel() { return false; }
|
virtual bool CloseLevel() { return false; }
|
||||||
|
|
@ -73,6 +83,7 @@ namespace Nz
|
||||||
std::filesystem::path m_resourceFolder;
|
std::filesystem::path m_resourceFolder;
|
||||||
Nz::ActionStack m_actionStack;
|
Nz::ActionStack m_actionStack;
|
||||||
Nz::EditorPopupManager m_popupManager;
|
Nz::EditorPopupManager m_popupManager;
|
||||||
|
Nz::EditorLogger* m_logger;
|
||||||
|
|
||||||
Nz::Level m_level;
|
Nz::Level m_level;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,17 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EditorLogger();
|
EditorLogger();
|
||||||
virtual ~EditorLogger();
|
|
||||||
|
|
||||||
static EditorLogger* Instance();
|
|
||||||
|
|
||||||
void Clear() { m_text.clear(); }
|
void Clear() { m_text.clear(); }
|
||||||
|
|
||||||
const std::vector<std::string>& GetLog() const { return m_text; }
|
const std::vector<std::string>& GetLog() const { return m_text; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static EditorLogger* s_instance;
|
EditorLogger(EditorLogger&) = delete;
|
||||||
|
EditorLogger& operator=(const EditorLogger&) = delete;
|
||||||
|
EditorLogger(EditorLogger&&) = delete;
|
||||||
|
EditorLogger& operator=(EditorLogger&&) = delete;
|
||||||
|
|
||||||
std::vector<std::string> m_text;
|
std::vector<std::string> m_text;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -38,8 +38,6 @@ namespace Nz
|
||||||
class NAZARAEDITOR_CORE_API EditorPopupManager
|
class NAZARAEDITOR_CORE_API EditorPopupManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static EditorPopupManager* Instance();
|
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
uint64_t CreatePopup(const EditorPopupParameters& parameters);
|
uint64_t CreatePopup(const EditorPopupParameters& parameters);
|
||||||
|
|
@ -47,7 +45,6 @@ namespace Nz
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EditorPopupManager();
|
EditorPopupManager();
|
||||||
~EditorPopupManager();
|
|
||||||
|
|
||||||
EditorPopupManager(const EditorPopupManager&) = delete;
|
EditorPopupManager(const EditorPopupManager&) = delete;
|
||||||
EditorPopupManager& operator=(const EditorPopupManager&) = delete;
|
EditorPopupManager& operator=(const EditorPopupManager&) = delete;
|
||||||
|
|
@ -61,7 +58,6 @@ namespace Nz
|
||||||
std::vector<std::unique_ptr<EditorPopup>> m_popups;
|
std::vector<std::unique_ptr<EditorPopup>> m_popups;
|
||||||
std::vector<uint64_t> m_popupsToDelete;
|
std::vector<uint64_t> m_popupsToDelete;
|
||||||
|
|
||||||
static EditorPopupManager* s_instance;
|
|
||||||
friend class EditorBaseApplication;
|
friend class EditorBaseApplication;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -2,24 +2,9 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
ActionStack* ActionStack::s_instance = nullptr;
|
|
||||||
ActionStack::ActionStack()
|
ActionStack::ActionStack()
|
||||||
: m_currentIndex(0)
|
: m_currentIndex(0)
|
||||||
{
|
{}
|
||||||
NazaraAssert(s_instance == nullptr, "ActionStack already exists");
|
|
||||||
s_instance = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ActionStack::~ActionStack()
|
|
||||||
{
|
|
||||||
s_instance = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ActionStack* ActionStack::Instance()
|
|
||||||
{
|
|
||||||
return s_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ActionStack::CanUndo() const { return !m_undoRedoStack.empty() && m_currentIndex >= 0; }
|
bool ActionStack::CanUndo() const { return !m_undoRedoStack.empty() && m_currentIndex >= 0; }
|
||||||
void ActionStack::Undo()
|
void ActionStack::Undo()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
void EditorAction_Level_New::Execute()
|
void EditorAction_Level_New::Execute()
|
||||||
{
|
{
|
||||||
Nz::EditorPopupManager::Instance()->CreatePopup({
|
Nz::EditorBaseApplication::Instance()->GetPopupManager().CreatePopup({
|
||||||
.title = "Warning",
|
.title = "Warning",
|
||||||
.description = "Are you sure you want to create a new level?",
|
.description = "Are you sure you want to create a new level?",
|
||||||
.choices = {
|
.choices = {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#include <NazaraEditor/Core/Application/Actions/EditorAction_Log_Clear.hpp>
|
#include <NazaraEditor/Core/Application/Actions/EditorAction_Log_Clear.hpp>
|
||||||
#include <NazaraEditor/Core/Application/EditorLogger.hpp>
|
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
void EditorAction_Log_Clear::Execute()
|
void EditorAction_Log_Clear::Execute()
|
||||||
{
|
{
|
||||||
Nz::EditorLogger::Instance()->Clear();
|
Nz::EditorBaseApplication::Instance()->GetLogger().Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include <NazaraEditor/Core/Application/Actions/EditorAction_Log_CopyToClipboard.hpp>
|
#include <NazaraEditor/Core/Application/Actions/EditorAction_Log_CopyToClipboard.hpp>
|
||||||
|
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||||
#include <NazaraEditor/Core/Application/EditorLogger.hpp>
|
#include <NazaraEditor/Core/Application/EditorLogger.hpp>
|
||||||
|
|
||||||
#include <Nazara/Platform.hpp>
|
#include <Nazara/Platform.hpp>
|
||||||
|
|
@ -9,7 +10,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
void EditorAction_Log_CopyToClipboard::Execute()
|
void EditorAction_Log_CopyToClipboard::Execute()
|
||||||
{
|
{
|
||||||
auto& lines = Nz::EditorLogger::Instance()->GetLog();
|
auto& lines = Nz::EditorBaseApplication::Instance()->GetLogger().GetLog();
|
||||||
if (lines.empty())
|
if (lines.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
void EditorAction_Quit::Execute()
|
void EditorAction_Quit::Execute()
|
||||||
{
|
{
|
||||||
Nz::EditorPopupManager::Instance()->CreatePopup({
|
Nz::EditorBaseApplication::Instance()->GetPopupManager().CreatePopup({
|
||||||
.title = "Warning",
|
.title = "Warning",
|
||||||
.description = "Are you sure you want to exit? All unsaved work will be discarded",
|
.description = "Are you sure you want to exit? All unsaved work will be discarded",
|
||||||
.choices = {
|
.choices = {
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,9 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
EditorLogger* EditorLogger::s_instance = nullptr;
|
|
||||||
|
|
||||||
EditorLogger::EditorLogger()
|
EditorLogger::EditorLogger()
|
||||||
{
|
{
|
||||||
NazaraAssert(s_instance == nullptr, "EditorLogger already exists");
|
|
||||||
s_instance = this;
|
|
||||||
|
|
||||||
Nz::Log::OnLogWrite.Connect([this](auto&& str) { m_text.emplace_back(str); });
|
Nz::Log::OnLogWrite.Connect([this](auto&& str) { m_text.emplace_back(str); });
|
||||||
Nz::Log::OnLogWriteError.Connect([this](ErrorType, auto&& str, int, const char*, const char*) { m_text.emplace_back(str); });
|
Nz::Log::OnLogWriteError.Connect([this](ErrorType, auto&& str, int, const char*, const char*) { m_text.emplace_back(str); });
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorLogger::~EditorLogger()
|
|
||||||
{
|
|
||||||
s_instance = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorLogger* EditorLogger::Instance()
|
|
||||||
{
|
|
||||||
return s_instance;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include <NazaraEditor/Core/UI/PopupManager.hpp>
|
#include <NazaraEditor/Core/UI/PopupManager.hpp>
|
||||||
|
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
|
@ -29,7 +30,7 @@ namespace Nz
|
||||||
if (choice.callback)
|
if (choice.callback)
|
||||||
choice.callback();
|
choice.callback();
|
||||||
|
|
||||||
EditorPopupManager::Instance()->DestroyPopup(m_id);
|
EditorBaseApplication::Instance()->GetPopupManager().DestroyPopup(m_id);
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
}
|
}
|
||||||
|
|
@ -38,23 +39,9 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorPopupManager* EditorPopupManager::s_instance = nullptr;
|
|
||||||
EditorPopupManager* EditorPopupManager::Instance()
|
|
||||||
{
|
|
||||||
return s_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorPopupManager::EditorPopupManager()
|
EditorPopupManager::EditorPopupManager()
|
||||||
: m_currentIndex(0)
|
: m_currentIndex(0)
|
||||||
{
|
{}
|
||||||
NazaraAssert(s_instance == nullptr, "EditorPopupManager already exists");
|
|
||||||
s_instance = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorPopupManager::~EditorPopupManager()
|
|
||||||
{
|
|
||||||
s_instance = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorPopupManager::Update()
|
void EditorPopupManager::Update()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Nz
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto name = prop.className;
|
auto name = prop.className;
|
||||||
AddMenuAction(prop.path, prop.shortcut.ToString(), [name]() { Nz::ActionStack::Instance()->ExecuteAction(name); }, prop.icon);
|
AddMenuAction(prop.path, prop.shortcut.ToString(), [name]() { Nz::EditorBaseApplication::Instance()->GetActionStack().ExecuteAction(name); }, prop.icon);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include <NazaraEditor/Editor/UI/OutputWindow.hpp>
|
#include <NazaraEditor/Editor/UI/OutputWindow.hpp>
|
||||||
|
|
||||||
|
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||||
#include <NazaraEditor/Core/Application/EditorLogger.hpp>
|
#include <NazaraEditor/Core/Application/EditorLogger.hpp>
|
||||||
|
|
||||||
namespace NzEditor
|
namespace NzEditor
|
||||||
|
|
@ -15,7 +16,7 @@ namespace NzEditor
|
||||||
{
|
{
|
||||||
if (ImGui::BeginChild("scrolling"))
|
if (ImGui::BeginChild("scrolling"))
|
||||||
{
|
{
|
||||||
for (auto&& line : Nz::EditorLogger::Instance()->GetLog())
|
for (auto&& line : Nz::EditorBaseApplication::Instance()->GetLogger().GetLog())
|
||||||
ImGui::TextUnformatted(line.c_str());
|
ImGui::TextUnformatted(line.c_str());
|
||||||
|
|
||||||
if (m_bScrollToBottom)
|
if (m_bScrollToBottom)
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ int WinMain(int argc, char* argv[])
|
||||||
|
|
||||||
NzEditor::Application app;
|
NzEditor::Application app;
|
||||||
app.SetResourceFolder(resourceDir);
|
app.SetResourceFolder(resourceDir);
|
||||||
|
app.SetLogger(logger);
|
||||||
|
|
||||||
ImGui::EnsureContextOnThisThread();
|
ImGui::EnsureContextOnThisThread();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue