2019-04-10 19:19:11 +00:00
|
|
|
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
|
|
|
|
#include "ImGuiDelegatesContainer.h"
|
|
|
|
|
2020-07-31 09:24:53 +00:00
|
|
|
#include "ImGuiModule.h"
|
|
|
|
#include "Utilities/RedirectingHandle.h"
|
2019-04-10 19:19:11 +00:00
|
|
|
#include "Utilities/WorldContextIndex.h"
|
|
|
|
|
|
|
|
|
2020-07-31 09:24:53 +00:00
|
|
|
// Redirecting handle which will automatically bind to another one, if a different instance of the module is loaded.
|
|
|
|
struct FImGuiDelegatesContainerHandle : Utilities::TRedirectingHandle<FImGuiDelegatesContainer>
|
|
|
|
{
|
|
|
|
FImGuiDelegatesContainerHandle(FImGuiDelegatesContainer& InDefaultContainer)
|
|
|
|
: Utilities::TRedirectingHandle<FImGuiDelegatesContainer>(InDefaultContainer)
|
|
|
|
{
|
|
|
|
if (FImGuiModule* Module = FModuleManager::GetModulePtr<FImGuiModule>("ImGui"))
|
|
|
|
{
|
|
|
|
SetParent(&Module->GetDelegatesContainerHandle());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-04-10 19:19:11 +00:00
|
|
|
|
2020-07-31 09:24:53 +00:00
|
|
|
static FImGuiDelegatesContainer DelegatesContainer;
|
|
|
|
static FImGuiDelegatesContainerHandle DelegatesHandle(DelegatesContainer);
|
|
|
|
|
|
|
|
FImGuiDelegatesContainer& FImGuiDelegatesContainer::Get()
|
|
|
|
{
|
|
|
|
return GetHandle().Get();
|
|
|
|
}
|
|
|
|
|
|
|
|
FImGuiDelegatesContainerHandle& FImGuiDelegatesContainer::GetHandle()
|
|
|
|
{
|
|
|
|
return DelegatesHandle;
|
|
|
|
}
|
2019-04-10 19:19:11 +00:00
|
|
|
|
2020-07-31 09:24:53 +00:00
|
|
|
void FImGuiDelegatesContainer::MoveContainer(FImGuiDelegatesContainerHandle& OtherContainerHandle)
|
2019-04-10 19:19:11 +00:00
|
|
|
{
|
|
|
|
// Only move data if pointer points to default instance, otherwise our data has already been moved and we only
|
|
|
|
// keep pointer to a more recent version.
|
2020-07-31 09:24:53 +00:00
|
|
|
if (GetHandle().IsDefault())
|
2019-04-10 19:19:11 +00:00
|
|
|
{
|
2020-07-31 09:24:53 +00:00
|
|
|
OtherContainerHandle.Get() = MoveTemp(GetHandle().Get());
|
|
|
|
GetHandle().Get().Clear();
|
2019-04-10 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update pointer to the most recent version.
|
2020-07-31 09:24:53 +00:00
|
|
|
GetHandle().SetParent(&OtherContainerHandle);
|
2019-04-10 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
2019-04-14 11:16:15 +00:00
|
|
|
int32 FImGuiDelegatesContainer::GetContextIndex(UWorld* World)
|
2019-04-10 19:19:11 +00:00
|
|
|
{
|
2019-04-14 11:16:15 +00:00
|
|
|
return Utilities::GetWorldContextIndex(*World);
|
2019-04-10 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FImGuiDelegatesContainer::Clear()
|
|
|
|
{
|
2019-04-14 11:16:15 +00:00
|
|
|
WorldEarlyDebugDelegates.Empty();
|
|
|
|
WorldDebugDelegates.Empty();
|
|
|
|
MultiContextEarlyDebugDelegate.Clear();
|
|
|
|
MultiContextDebugDelegate.Clear();
|
2019-04-10 19:19:11 +00:00
|
|
|
}
|