2017-08-28 19:29:07 +00:00
|
|
|
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ImGuiContextProxy.h"
|
|
|
|
|
|
|
|
|
2018-11-27 20:54:26 +00:00
|
|
|
// TODO: It might be useful to broadcast FContextProxyCreatedDelegate to users, to support similar cases to our ImGui
|
|
|
|
// demo, but we would need to remove from that interface internal classes.
|
|
|
|
|
|
|
|
// Delegate called when new context proxy is created.
|
|
|
|
// @param ContextIndex - Index for that world
|
|
|
|
// @param ContextProxy - Created context proxy
|
|
|
|
DECLARE_MULTICAST_DELEGATE_TwoParams(FContextProxyCreatedDelegate, int32, FImGuiContextProxy&);
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
// Manages ImGui context proxies.
|
|
|
|
class FImGuiContextManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-10-28 21:25:44 +00:00
|
|
|
FImGuiContextManager();
|
2017-08-28 19:29:07 +00:00
|
|
|
|
|
|
|
FImGuiContextManager(const FImGuiContextManager&) = delete;
|
|
|
|
FImGuiContextManager& operator=(const FImGuiContextManager&) = delete;
|
|
|
|
|
|
|
|
FImGuiContextManager(FImGuiContextManager&&) = delete;
|
|
|
|
FImGuiContextManager& operator=(FImGuiContextManager&&) = delete;
|
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
~FImGuiContextManager();
|
|
|
|
|
2018-05-09 19:22:48 +00:00
|
|
|
ImFontAtlas& GetFontAtlas() { return FontAtlas; }
|
|
|
|
const ImFontAtlas& GetFontAtlas() const { return FontAtlas; }
|
|
|
|
|
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
#if WITH_EDITOR
|
|
|
|
// Get or create editor ImGui context proxy.
|
2019-08-03 16:45:53 +00:00
|
|
|
FORCEINLINE FImGuiContextProxy& GetEditorContextProxy() { return *GetEditorContextData().ContextProxy; }
|
2017-09-27 20:16:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !WITH_EDITOR
|
|
|
|
// Get or create standalone game ImGui context proxy.
|
2019-08-03 16:45:53 +00:00
|
|
|
FORCEINLINE FImGuiContextProxy& GetWorldContextProxy() { return *GetStandaloneWorldContextData().ContextProxy; }
|
2017-09-27 20:16:54 +00:00
|
|
|
#endif
|
2017-08-28 19:29:07 +00:00
|
|
|
|
|
|
|
// Get or create ImGui context proxy for given world.
|
2019-08-03 16:45:53 +00:00
|
|
|
FORCEINLINE FImGuiContextProxy& GetWorldContextProxy(const UWorld& World) { return *GetWorldContextData(World).ContextProxy; }
|
2017-08-28 19:29:07 +00:00
|
|
|
|
2017-10-03 20:16:17 +00:00
|
|
|
// Get or create ImGui context proxy for given world. Additionally get context index for that proxy.
|
2019-08-03 16:45:53 +00:00
|
|
|
FORCEINLINE FImGuiContextProxy& GetWorldContextProxy(const UWorld& World, int32& OutContextIndex) { return *GetWorldContextData(World, &OutContextIndex).ContextProxy; }
|
2017-10-03 20:16:17 +00:00
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
// Get context proxy by index, or null if context with that index doesn't exist.
|
|
|
|
FORCEINLINE FImGuiContextProxy* GetContextProxy(int32 ContextIndex)
|
|
|
|
{
|
|
|
|
FContextData* Data = Contexts.Find(ContextIndex);
|
2019-08-03 16:45:53 +00:00
|
|
|
return Data ? Data->ContextProxy.Get() : nullptr;
|
2017-08-28 19:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 20:16:17 +00:00
|
|
|
// Delegate called for all contexts in manager, right after calling context specific draw event. Allows listeners
|
|
|
|
// draw the same content to multiple contexts.
|
|
|
|
FSimpleMulticastDelegate& OnDrawMultiContext() { return DrawMultiContextEvent; }
|
|
|
|
|
2018-11-27 20:54:26 +00:00
|
|
|
// Delegate called when new context proxy is created.
|
|
|
|
FContextProxyCreatedDelegate& OnContextProxyCreated() { return ContextProxyCreatedEvent; }
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
void Tick(float DeltaSeconds);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
struct FContextData
|
|
|
|
{
|
2018-11-25 20:36:55 +00:00
|
|
|
FContextData(const FString& ContextName, int32 ContextIndex, FSimpleMulticastDelegate& SharedDrawEvent, ImFontAtlas& FontAtlas, int32 InPIEInstance = -1)
|
2017-09-27 20:16:54 +00:00
|
|
|
: PIEInstance(InPIEInstance)
|
2019-08-03 16:45:53 +00:00
|
|
|
, ContextProxy(new FImGuiContextProxy(ContextName, ContextIndex, &SharedDrawEvent, &FontAtlas))
|
2017-09-27 20:16:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE bool CanTick() const { return PIEInstance < 0 || GEngine->GetWorldContextFromPIEInstance(PIEInstance); }
|
|
|
|
|
|
|
|
int32 PIEInstance = -1;
|
2019-08-03 16:45:53 +00:00
|
|
|
TUniquePtr<FImGuiContextProxy> ContextProxy;
|
2017-08-28 19:29:07 +00:00
|
|
|
};
|
|
|
|
|
2020-01-27 21:51:42 +00:00
|
|
|
#if ENGINE_COMPATIBILITY_LEGACY_WORLD_ACTOR_TICK
|
2017-10-28 21:25:44 +00:00
|
|
|
void OnWorldTickStart(ELevelTick TickType, float DeltaSeconds);
|
2020-01-27 21:51:42 +00:00
|
|
|
#endif
|
|
|
|
void OnWorldTickStart(UWorld* World, ELevelTick TickType, float DeltaSeconds);
|
2017-10-28 21:25:44 +00:00
|
|
|
|
2019-04-14 11:16:15 +00:00
|
|
|
#if ENGINE_COMPATIBILITY_WITH_WORLD_POST_ACTOR_TICK
|
2018-10-28 19:54:18 +00:00
|
|
|
void OnWorldPostActorTick(UWorld* World, ELevelTick TickType, float DeltaSeconds);
|
|
|
|
#endif
|
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
#if WITH_EDITOR
|
|
|
|
FContextData& GetEditorContextData();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !WITH_EDITOR
|
|
|
|
FContextData& GetStandaloneWorldContextData();
|
|
|
|
#endif
|
|
|
|
|
2017-10-03 20:16:17 +00:00
|
|
|
FContextData& GetWorldContextData(const UWorld& World, int32* OutContextIndex = nullptr);
|
2017-08-28 19:29:07 +00:00
|
|
|
|
|
|
|
TMap<int32, FContextData> Contexts;
|
|
|
|
|
2017-10-03 20:16:17 +00:00
|
|
|
FSimpleMulticastDelegate DrawMultiContextEvent;
|
2018-05-09 19:22:48 +00:00
|
|
|
|
2018-11-27 20:54:26 +00:00
|
|
|
FContextProxyCreatedDelegate ContextProxyCreatedEvent;
|
|
|
|
|
2018-05-09 19:22:48 +00:00
|
|
|
ImFontAtlas FontAtlas;
|
2017-08-28 19:29:07 +00:00
|
|
|
};
|