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