diff --git a/examples/unrealstatus/Content/ShowTheUILevel.umap b/examples/unrealstatus/Content/ShowTheUILevel.umap index d99a0aa..8c72286 100644 Binary files a/examples/unrealstatus/Content/ShowTheUILevel.umap and b/examples/unrealstatus/Content/ShowTheUILevel.umap differ diff --git a/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/DiscordRpcBlueprint.cpp b/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/DiscordRpcBlueprint.cpp index 9635288..be8de6b 100644 --- a/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/DiscordRpcBlueprint.cpp +++ b/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/DiscordRpcBlueprint.cpp @@ -4,27 +4,41 @@ #include "discord-rpc.h" -DEFINE_LOG_CATEGORY(DiscordLogCategory) +DEFINE_LOG_CATEGORY(Discord) -/*static*/ void UDiscordRpcBlueprint::Initialize(const FString& applicationId, bool autoRegister) +static UDiscordRpc* self = nullptr; +static void ReadyHandler() { + UE_LOG(Discord, Log, TEXT("Discord connected")); + if (self) { + self->IsConnected = true; + } +} + +static void DisconnectHandler(int errorCode, const char* message) { + UE_LOG(Discord, Log, TEXT("Discord disconnected (%d): %s"), errorCode, message); + if (self) { + self->IsConnected = false; + } +}; + +void UDiscordRpc::Initialize(const FString& applicationId, bool autoRegister) { + self = this; + IsConnected = false; DiscordEventHandlers handlers{}; - handlers.ready = []() { - UE_LOG(DiscordLogCategory, Log, TEXT("Discord connected")); - }; - handlers.disconnected = [](int errorCode, const char* message) { - UE_LOG(DiscordLogCategory, Log, TEXT("Discord disconnected (%d): %s"), errorCode, message); - }; + handlers.ready = ReadyHandler; + handlers.disconnected = DisconnectHandler; auto appId = StringCast(*applicationId); Discord_Initialize((const char*)appId.Get(), &handlers, autoRegister); } -/*static*/ void UDiscordRpcBlueprint::Shutdown() +void UDiscordRpc::Shutdown() { Discord_Shutdown(); + self = nullptr; } -/*static*/ void UDiscordRpcBlueprint::RunCallbacks() +void UDiscordRpc::RunCallbacks() { Discord_RunCallbacks(); } diff --git a/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Public/DiscordRpcBlueprint.h b/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Public/DiscordRpcBlueprint.h index 0141256..fa9fd21 100644 --- a/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Public/DiscordRpcBlueprint.h +++ b/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Public/DiscordRpcBlueprint.h @@ -6,22 +6,27 @@ #include "CoreMinimal.h" #include "DiscordRpcBlueprint.generated.h" -DECLARE_LOG_CATEGORY_EXTERN(DiscordLogCategory, Log, All); +DECLARE_LOG_CATEGORY_EXTERN(Discord, Log, All); /** * */ -UCLASS() -class DISCORDRPC_API UDiscordRpcBlueprint : public UBlueprintFunctionLibrary +UCLASS(BlueprintType, meta = (DisplayName = "Discord RPC"), Category = "Discord") +class DISCORDRPC_API UDiscordRpc : public UObject { - GENERATED_BODY() + GENERATED_BODY() + +public: - UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord Initialize connection", Keywords = "Discord rpc"), Category = "Discord") - static void Initialize(const FString& applicationId, bool autoRegister); + UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord initialize connection", Keywords = "Discord rpc"), Category = "Discord") + void Initialize(const FString& applicationId, bool autoRegister); UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord shut down connection", Keywords = "Discord rpc"), Category = "Discord") - static void Shutdown(); + void Shutdown(); UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord check for callbacks", Keywords = "Discord rpc"), Category = "Discord") - static void RunCallbacks(); + void RunCallbacks(); + + UPROPERTY(BlueprintReadOnly, meta = (DisplayName = "Discord connected", Keywords = "Discord rpc"), Category = "Discord") + bool IsConnected; };