2018-07-10 16:40:57 +00:00
|
|
|
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
|
2020-06-25 09:52:46 +00:00
|
|
|
#include "ImGuiEditor.h"
|
2018-07-10 16:40:57 +00:00
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
2020-05-10 20:05:27 +00:00
|
|
|
#include "ImGuiCanvasSizeInfoCustomization.h"
|
2018-07-31 21:09:01 +00:00
|
|
|
#include "ImGuiKeyInfoCustomization.h"
|
2018-12-08 21:15:20 +00:00
|
|
|
#include "ImGuiModuleSettings.h"
|
2018-07-10 16:40:57 +00:00
|
|
|
|
|
|
|
#include <ISettingsModule.h>
|
2020-06-14 20:50:26 +00:00
|
|
|
#include <Modules/ModuleManager.h>
|
2018-07-10 16:40:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "ImGuiEditor"
|
|
|
|
|
|
|
|
#define SETTINGS_CONTAINER TEXT("Project"), TEXT("Plugins"), TEXT("ImGui")
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
ISettingsModule* GetSettingsModule()
|
|
|
|
{
|
|
|
|
return FModuleManager::GetModulePtr<ISettingsModule>("Settings");
|
|
|
|
}
|
2018-07-31 21:09:01 +00:00
|
|
|
|
|
|
|
FPropertyEditorModule* GetPropertyEditorModule()
|
|
|
|
{
|
|
|
|
return FModuleManager::GetModulePtr<FPropertyEditorModule>("PropertyEditor");
|
|
|
|
}
|
2018-07-10 16:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FImGuiEditor::FImGuiEditor()
|
|
|
|
{
|
|
|
|
Register();
|
|
|
|
|
|
|
|
// As a side effect of being part of the ImGui module, we need to support deferred registration (only executed if
|
|
|
|
// module is loaded manually at the very early stage).
|
|
|
|
if (!IsRegistrationCompleted())
|
|
|
|
{
|
|
|
|
CreateRegistrator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FImGuiEditor::~FImGuiEditor()
|
|
|
|
{
|
|
|
|
Unregister();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FImGuiEditor::Register()
|
|
|
|
{
|
|
|
|
// Only register after UImGuiSettings class is initialized (necessary to check in early loading stages).
|
2018-12-08 21:03:18 +00:00
|
|
|
if (!bSettingsRegistered && UImGuiSettings::Get())
|
2018-07-10 16:40:57 +00:00
|
|
|
{
|
|
|
|
if (ISettingsModule* SettingsModule = GetSettingsModule())
|
|
|
|
{
|
|
|
|
bSettingsRegistered = true;
|
|
|
|
|
|
|
|
SettingsModule->RegisterSettings(SETTINGS_CONTAINER,
|
|
|
|
LOCTEXT("ImGuiSettingsName", "ImGui"),
|
|
|
|
LOCTEXT("ImGuiSettingsDescription", "Configure the Unreal ImGui plugin."),
|
2018-12-08 21:03:18 +00:00
|
|
|
UImGuiSettings::Get());
|
2018-07-10 16:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-31 21:09:01 +00:00
|
|
|
|
|
|
|
if (!bCustomPropertyTypeLayoutsRegistered)
|
|
|
|
{
|
|
|
|
if (FPropertyEditorModule* PropertyModule = GetPropertyEditorModule())
|
|
|
|
{
|
|
|
|
bCustomPropertyTypeLayoutsRegistered = true;
|
|
|
|
|
2020-05-10 20:05:27 +00:00
|
|
|
PropertyModule->RegisterCustomPropertyTypeLayout("ImGuiCanvasSizeInfo",
|
|
|
|
FOnGetPropertyTypeCustomizationInstance::CreateStatic(&FImGuiCanvasSizeInfoCustomization::MakeInstance));
|
2018-07-31 21:09:01 +00:00
|
|
|
PropertyModule->RegisterCustomPropertyTypeLayout("ImGuiKeyInfo",
|
|
|
|
FOnGetPropertyTypeCustomizationInstance::CreateStatic(&FImGuiKeyInfoCustomization::MakeInstance));
|
|
|
|
}
|
|
|
|
}
|
2018-07-10 16:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FImGuiEditor::Unregister()
|
|
|
|
{
|
|
|
|
if (bSettingsRegistered)
|
|
|
|
{
|
|
|
|
bSettingsRegistered = false;
|
|
|
|
|
|
|
|
if (ISettingsModule* SettingsModule = GetSettingsModule())
|
|
|
|
{
|
|
|
|
SettingsModule->UnregisterSettings(SETTINGS_CONTAINER);
|
|
|
|
}
|
|
|
|
}
|
2018-07-31 21:09:01 +00:00
|
|
|
|
|
|
|
if (bCustomPropertyTypeLayoutsRegistered)
|
|
|
|
{
|
|
|
|
bCustomPropertyTypeLayoutsRegistered = false;
|
|
|
|
|
|
|
|
if (FPropertyEditorModule* PropertyModule = GetPropertyEditorModule())
|
|
|
|
{
|
2020-05-10 20:05:27 +00:00
|
|
|
PropertyModule->UnregisterCustomPropertyTypeLayout("ImGuiCanvasSizeInfo");
|
2018-07-31 21:09:01 +00:00
|
|
|
PropertyModule->UnregisterCustomPropertyTypeLayout("ImGuiKeyInfo");
|
|
|
|
}
|
|
|
|
}
|
2018-07-10 16:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FImGuiEditor::CreateRegistrator()
|
|
|
|
{
|
|
|
|
if (!RegistratorHandle.IsValid())
|
|
|
|
{
|
|
|
|
RegistratorHandle = FModuleManager::Get().OnModulesChanged().AddLambda([this](FName Name, EModuleChangeReason Reason)
|
|
|
|
{
|
|
|
|
if (Reason == EModuleChangeReason::ModuleLoaded)
|
|
|
|
{
|
|
|
|
Register();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsRegistrationCompleted())
|
|
|
|
{
|
|
|
|
ReleaseRegistrator();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FImGuiEditor::ReleaseRegistrator()
|
|
|
|
{
|
|
|
|
if (RegistratorHandle.IsValid())
|
|
|
|
{
|
|
|
|
FModuleManager::Get().OnModulesChanged().Remove(RegistratorHandle);
|
|
|
|
RegistratorHandle.Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#undef SETTINGS_CONTAINER
|
|
|
|
#undef LOCTEXT_NAMESPACE
|
|
|
|
|
|
|
|
#endif // WITH_EDITOR
|