From 71f257d1edae194f0b861120820aca3d53d732c9 Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:43:57 -0400 Subject: [PATCH] Add SetLocale action --- .../Actions/EditorAction_Editor.hpp | 25 +++++++++++++++++++ include/NazaraEditor/Editor/Application.hpp | 2 ++ .../Actions/EditorAction_Editor.cpp | 6 +++++ src/NazaraEditor/Editor/Application.cpp | 14 +++++++++++ src/NazaraEditor/Editor/main.cpp | 6 ++--- 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/include/NazaraEditor/Core/Application/Actions/EditorAction_Editor.hpp b/include/NazaraEditor/Core/Application/Actions/EditorAction_Editor.hpp index 7ae3a96..957e3c7 100644 --- a/include/NazaraEditor/Core/Application/Actions/EditorAction_Editor.hpp +++ b/include/NazaraEditor/Core/Application/Actions/EditorAction_Editor.hpp @@ -12,4 +12,29 @@ namespace Nz public: void Execute() override; }; + + class NAZARAEDITOR_CORE_API EditorAction_SetLocale final + : public EditorAction + { + public: + EditorAction_SetLocale(const Properties& properties, std::string_view locale) + : EditorAction(properties) + , m_locale(locale) + {} + EditorAction_SetLocale(const std::shared_ptr& properties, std::string_view locale) + : EditorAction(properties) + , m_locale(locale) + {} + ~EditorAction_SetLocale() = default; + + std::unique_ptr Clone() const override { return std::make_unique(m_properties, m_locale); } + const std::string& GetName() const override { return m_properties->className; } + bool IsUndoRedoable() const override { return false; } + static const char* GetClassName() { return "EditorAction_SetLocale"; } + + void Execute() override; + + protected: + std::string m_locale; + }; } \ No newline at end of file diff --git a/include/NazaraEditor/Editor/Application.hpp b/include/NazaraEditor/Editor/Application.hpp index 4608e83..48e43f4 100644 --- a/include/NazaraEditor/Editor/Application.hpp +++ b/include/NazaraEditor/Editor/Application.hpp @@ -8,6 +8,8 @@ namespace NzEditor : public Nz::EditorBaseApplication { public: + Application(); + virtual bool NewLevel() override; }; } \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/Actions/EditorAction_Editor.cpp b/src/NazaraEditor/Core/Application/Actions/EditorAction_Editor.cpp index 37e120a..be2a517 100644 --- a/src/NazaraEditor/Core/Application/Actions/EditorAction_Editor.cpp +++ b/src/NazaraEditor/Core/Application/Actions/EditorAction_Editor.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace Nz { @@ -21,4 +22,9 @@ namespace Nz }); } + + void EditorAction_SetLocale::Execute() + { + Nz::Localization::Instance()->SetLocale(m_locale); + } } \ No newline at end of file diff --git a/src/NazaraEditor/Editor/Application.cpp b/src/NazaraEditor/Editor/Application.cpp index 3b1aaf3..a23c9e0 100644 --- a/src/NazaraEditor/Editor/Application.cpp +++ b/src/NazaraEditor/Editor/Application.cpp @@ -1,7 +1,21 @@ #include +#include + namespace NzEditor { + Application::Application() + { + Nz::Localization::OnLocaleInstalled.Connect([this](std::string_view locale) { + RegisterAction({ + .className = std::format("{}_{}", Nz::EditorAction_SetLocale::GetClassName(), locale), + .description = locale, + .path = { "LOC_EDITOR_MENU_TOOLS", "LOC_EDITOR_MENU_LANGUAGE", locale }, + .category = "Tools", + }, locale); + }); + } + bool Application::NewLevel() { bool bResult = EditorBaseApplication::NewLevel(); diff --git a/src/NazaraEditor/Editor/main.cpp b/src/NazaraEditor/Editor/main.cpp index e186f14..c2a6f89 100644 --- a/src/NazaraEditor/Editor/main.cpp +++ b/src/NazaraEditor/Editor/main.cpp @@ -36,9 +36,6 @@ int WinMain(int argc, char* argv[]) app.SetResourceFolder(resourceDir); app.SetLogger(logger); - Nz::Localization::Instance()->LoadLocalizationFile(resourceDir / "localization.csv"); - Nz::Localization::Instance()->SetLocale("en-US"); - ImGui::EnsureContextOnThisThread(); app.RegisterWindow(); @@ -47,6 +44,9 @@ int WinMain(int argc, char* argv[]) app.RegisterWindow(); app.RegisterWindow(); + Nz::Localization::Instance()->LoadLocalizationFile(resourceDir / "localization.csv"); + Nz::Localization::Instance()->SetLocale("en-US"); + Nz::TextureParams texParams; texParams.renderDevice = Nz::Graphics::Instance()->GetRenderDevice(); texParams.loadFormat = Nz::PixelFormat::RGBA8_SRGB;