UnrealImGui/Source/ImGui/Private/ImGuiSettings.cpp
Sebastian c5f3759664 Moved console variables and commands to wrapper objects:
- Moved property variables to ImGui Module Properties.
- Moved console command to ImGui Module Commands (one for now but more will be added).
- ImGui Module Commands is created by ImGui Module Manager, what means that commands are registered after module is loaded and unregistered when it is unloaded.
- Updated settings to allow more convenient use: Added global pointer to default object and event raised when it is loaded.
2018-11-24 19:54:01 +00:00

89 lines
1.9 KiB
C++

// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
#include "ImGuiPrivatePCH.h"
#include "ImGuiSettings.h"
UImGuiSettings* GImGuiSettings = nullptr;
FSimpleMulticastDelegate& UImGuiSettings::OnSettingsLoaded()
{
static FSimpleMulticastDelegate Instance;
return Instance;
}
UImGuiSettings::UImGuiSettings()
{
#if WITH_EDITOR
RegisterPropertyChangedDelegate();
#endif
}
UImGuiSettings::~UImGuiSettings()
{
#if WITH_EDITOR
UnregisterPropertyChangedDelegate();
#endif
}
void UImGuiSettings::PostInitProperties()
{
Super::PostInitProperties();
if (IsTemplate())
{
GImGuiSettings = this;
OnSettingsLoaded().Broadcast();
}
}
void UImGuiSettings::BeginDestroy()
{
Super::BeginDestroy();
if (GImGuiSettings == this)
{
GImGuiSettings = nullptr;
}
}
#if WITH_EDITOR
void UImGuiSettings::RegisterPropertyChangedDelegate()
{
if (!FCoreUObjectDelegates::OnObjectPropertyChanged.IsBoundToObject(this))
{
FCoreUObjectDelegates::OnObjectPropertyChanged.AddUObject(this, &UImGuiSettings::OnPropertyChanged);
}
}
void UImGuiSettings::UnregisterPropertyChangedDelegate()
{
FCoreUObjectDelegates::OnObjectPropertyChanged.RemoveAll(this);
}
void UImGuiSettings::OnPropertyChanged(class UObject* ObjectBeingModified, struct FPropertyChangedEvent& PropertyChangedEvent)
{
if (ObjectBeingModified == this)
{
const FName UpdatedPropertyName = PropertyChangedEvent.MemberProperty ? PropertyChangedEvent.MemberProperty->GetFName() : NAME_None;
if (UpdatedPropertyName == GET_MEMBER_NAME_CHECKED(UImGuiSettings, ImGuiInputHandlerClass))
{
OnImGuiInputHandlerClassChanged.Broadcast();
}
else if (UpdatedPropertyName == GET_MEMBER_NAME_CHECKED(UImGuiSettings, SwitchInputModeKey))
{
OnSwitchInputModeKeyChanged.Broadcast();
}
else if (UpdatedPropertyName == GET_MEMBER_NAME_CHECKED(UImGuiSettings, bUseSoftwareCursor))
{
OnSoftwareCursorChanged.Broadcast();
}
}
}
#endif // WITH_EDITOR