diff --git a/AdvancedSessions/Source/AdvancedSessions/Classes/AdvancedExternalUILibrary.h b/AdvancedSessions/Source/AdvancedSessions/Classes/AdvancedExternalUILibrary.h index 968f623..6153ed3 100644 --- a/AdvancedSessions/Source/AdvancedSessions/Classes/AdvancedExternalUILibrary.h +++ b/AdvancedSessions/Source/AdvancedSessions/Classes/AdvancedExternalUILibrary.h @@ -32,32 +32,32 @@ public: //********* External UI Functions *************// // Show the UI that handles the Friends list - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result")) - static void ShowFriendsUI(APlayerController *PlayerController, EBlueprintResultSwitch &Result); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result", WorldContext = "WorldContextObject")) + static void ShowFriendsUI(UObject* WorldContextObject, APlayerController *PlayerController, EBlueprintResultSwitch &Result); // Show the UI that handles inviting people to your game - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result")) - static void ShowInviteUI(APlayerController *PlayerController, EBlueprintResultSwitch &Result); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result", WorldContext = "WorldContextObject")) + static void ShowInviteUI(UObject* WorldContextObject, APlayerController *PlayerController, EBlueprintResultSwitch &Result); // Show the UI that shows the leaderboard (doesn't work with steam) - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result")) - static void ShowLeaderBoardUI(FString LeaderboardName, EBlueprintResultSwitch &Result); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result", WorldContext = "WorldContextObject")) + static void ShowLeaderBoardUI(UObject* WorldContextObject, FString LeaderboardName, EBlueprintResultSwitch &Result); // Show the UI that shows a web URL - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result", AutoCreateRefTerm = "AllowedDomains")) - static void ShowWebURLUI(FString URLToShow, EBlueprintResultSwitch &Result, TArray& AllowedDomains, bool bEmbedded = false , bool bShowBackground = false, bool bShowCloseButton = false, int32 OffsetX = 0, int32 OffsetY = 0, int32 SizeX = 0, int32 SizeY = 0); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result", AutoCreateRefTerm = "AllowedDomains", WorldContext = "WorldContextObject")) + static void ShowWebURLUI(UObject* WorldContextObject, FString URLToShow, EBlueprintResultSwitch &Result, TArray& AllowedDomains, bool bEmbedded = false , bool bShowBackground = false, bool bShowCloseButton = false, int32 OffsetX = 0, int32 OffsetY = 0, int32 SizeX = 0, int32 SizeY = 0); // Show the UI that shows a web URL - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI") - static void CloseWebURLUI(); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (WorldContext = "WorldContextObject")) + static void CloseWebURLUI(UObject* WorldContextObject); // Show the UI that shows the profile of a uniquenetid - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result")) - static void ShowProfileUI(const FBPUniqueNetId PlayerViewingProfile, const FBPUniqueNetId PlayerToViewProfileOf, EBlueprintResultSwitch &Result); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result", WorldContext = "WorldContextObject")) + static void ShowProfileUI(UObject* WorldContextObject, const FBPUniqueNetId PlayerViewingProfile, const FBPUniqueNetId PlayerToViewProfileOf, EBlueprintResultSwitch &Result); // Show the UI that shows the account upgrade UI (doesn't work with steam) - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result")) - static void ShowAccountUpgradeUI(const FBPUniqueNetId PlayerRequestingAccountUpgradeUI, EBlueprintResultSwitch &Result); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedExternalUI", meta = (ExpandEnumAsExecs = "Result", WorldContext = "WorldContextObject")) + static void ShowAccountUpgradeUI(UObject* WorldContextObject, const FBPUniqueNetId PlayerRequestingAccountUpgradeUI, EBlueprintResultSwitch &Result); }; diff --git a/AdvancedSessions/Source/AdvancedSessions/Classes/AdvancedIdentityLibrary.h b/AdvancedSessions/Source/AdvancedSessions/Classes/AdvancedIdentityLibrary.h index 392ab8c..5f0dc15 100644 --- a/AdvancedSessions/Source/AdvancedSessions/Classes/AdvancedIdentityLibrary.h +++ b/AdvancedSessions/Source/AdvancedSessions/Classes/AdvancedIdentityLibrary.h @@ -28,26 +28,26 @@ public: //********* Identity Functions *************// // Get the login status of a local player - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity", meta = (ExpandEnumAsExecs = "Result")) - static void GetLoginStatus(const FBPUniqueNetId & UniqueNetID, EBPLoginStatus & LoginStatus, EBlueprintResultSwitch &Result); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity", meta = (ExpandEnumAsExecs = "Result", WorldContext = "WorldContextObject")) + static void GetLoginStatus(UObject* WorldContextObject, const FBPUniqueNetId & UniqueNetID, EBPLoginStatus & LoginStatus, EBlueprintResultSwitch &Result); // Get the auth token for a local player - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity", meta = (ExpandEnumAsExecs = "Result")) - static void GetPlayerAuthToken(APlayerController * PlayerController, FString & AuthToken, EBlueprintResultSwitch &Result); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity", meta = (ExpandEnumAsExecs = "Result", WorldContext = "WorldContextObject")) + static void GetPlayerAuthToken(UObject* WorldContextObject, APlayerController * PlayerController, FString & AuthToken, EBlueprintResultSwitch &Result); // Get a players nickname - UFUNCTION(BlueprintPure, Category = "Online|AdvancedIdentity") - static void GetPlayerNickname(const FBPUniqueNetId & UniqueNetID, FString & PlayerNickname); + UFUNCTION(BlueprintPure, Category = "Online|AdvancedIdentity", meta = (WorldContext = "WorldContextObject")) + static void GetPlayerNickname(UObject* WorldContextObject, const FBPUniqueNetId & UniqueNetID, FString & PlayerNickname); //********* User Account Functions *************// // Get a users account - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity|UserAccount", meta = (ExpandEnumAsExecs = "Result")) - static void GetUserAccount(const FBPUniqueNetId & UniqueNetId, FBPUserOnlineAccount & AccountInfo, EBlueprintResultSwitch &Result); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity|UserAccount", meta = (ExpandEnumAsExecs = "Result", WorldContext = "WorldContextObject")) + static void GetUserAccount(UObject* WorldContextObject, const FBPUniqueNetId & UniqueNetId, FBPUserOnlineAccount & AccountInfo, EBlueprintResultSwitch &Result); // Get all known users accounts - UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity|UserAccount", meta = (ExpandEnumAsExecs = "Result")) - static void GetAllUserAccounts(TArray & AccountInfos, EBlueprintResultSwitch &Result); + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity|UserAccount", meta = (ExpandEnumAsExecs = "Result", WorldContext = "WorldContextObject")) + static void GetAllUserAccounts(UObject* WorldContextObject, TArray & AccountInfos, EBlueprintResultSwitch &Result); // Get a user account access token UFUNCTION(BlueprintPure, Category = "Online|AdvancedIdentity|UserAccount") diff --git a/AdvancedSessions/Source/AdvancedSessions/Private/AdvancedExternalUILibrary.cpp b/AdvancedSessions/Source/AdvancedSessions/Private/AdvancedExternalUILibrary.cpp index f4b1766..a1792a1 100644 --- a/AdvancedSessions/Source/AdvancedSessions/Private/AdvancedExternalUILibrary.cpp +++ b/AdvancedSessions/Source/AdvancedSessions/Private/AdvancedExternalUILibrary.cpp @@ -6,9 +6,17 @@ //General Log DEFINE_LOG_CATEGORY(AdvancedExternalUILog); -void UAdvancedExternalUILibrary::ShowAccountUpgradeUI(const FBPUniqueNetId PlayerRequestingAccountUpgradeUI, EBlueprintResultSwitch &Result) +void UAdvancedExternalUILibrary::ShowAccountUpgradeUI(UObject* WorldContextObject, const FBPUniqueNetId PlayerRequestingAccountUpgradeUI, EBlueprintResultSwitch &Result) { - IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(); + + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(World); if (!ExternalUIInterface.IsValid()) { @@ -21,10 +29,17 @@ void UAdvancedExternalUILibrary::ShowAccountUpgradeUI(const FBPUniqueNetId Playe Result = EBlueprintResultSwitch::OnSuccess; } -void UAdvancedExternalUILibrary::ShowProfileUI(const FBPUniqueNetId PlayerViewingProfile, const FBPUniqueNetId PlayerToViewProfileOf, EBlueprintResultSwitch &Result) +void UAdvancedExternalUILibrary::ShowProfileUI(UObject* WorldContextObject, const FBPUniqueNetId PlayerViewingProfile, const FBPUniqueNetId PlayerToViewProfileOf, EBlueprintResultSwitch &Result) { - IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(); + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(World); if (!ExternalUIInterface.IsValid()) { @@ -39,9 +54,16 @@ void UAdvancedExternalUILibrary::ShowProfileUI(const FBPUniqueNetId PlayerViewin -void UAdvancedExternalUILibrary::ShowWebURLUI(FString URLToShow, EBlueprintResultSwitch &Result, TArray& AllowedDomains, bool bEmbedded, bool bShowBackground, bool bShowCloseButton, int32 OffsetX, int32 OffsetY, int32 SizeX, int32 SizeY) +void UAdvancedExternalUILibrary::ShowWebURLUI(UObject* WorldContextObject, FString URLToShow, EBlueprintResultSwitch &Result, TArray& AllowedDomains, bool bEmbedded, bool bShowBackground, bool bShowCloseButton, int32 OffsetX, int32 OffsetY, int32 SizeX, int32 SizeY) { - IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(); + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(World); if (!ExternalUIInterface.IsValid()) { @@ -67,9 +89,15 @@ void UAdvancedExternalUILibrary::ShowWebURLUI(FString URLToShow, EBlueprintResul Result = EBlueprintResultSwitch::OnSuccess; } -void UAdvancedExternalUILibrary::CloseWebURLUI() +void UAdvancedExternalUILibrary::CloseWebURLUI(UObject* WorldContextObject) { - IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(); + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + return; + } + + IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(World); if (!ExternalUIInterface.IsValid()) { @@ -80,9 +108,16 @@ void UAdvancedExternalUILibrary::CloseWebURLUI() ExternalUIInterface->CloseWebURL(); } -void UAdvancedExternalUILibrary::ShowLeaderBoardUI(FString LeaderboardName, EBlueprintResultSwitch &Result) +void UAdvancedExternalUILibrary::ShowLeaderBoardUI(UObject* WorldContextObject, FString LeaderboardName, EBlueprintResultSwitch &Result) { - IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(); + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(World); if (!ExternalUIInterface.IsValid()) { @@ -97,7 +132,7 @@ void UAdvancedExternalUILibrary::ShowLeaderBoardUI(FString LeaderboardName, EBlu } -void UAdvancedExternalUILibrary::ShowInviteUI(APlayerController *PlayerController, EBlueprintResultSwitch &Result) +void UAdvancedExternalUILibrary::ShowInviteUI(UObject* WorldContextObject, APlayerController *PlayerController, EBlueprintResultSwitch &Result) { if (!PlayerController) { @@ -106,7 +141,14 @@ void UAdvancedExternalUILibrary::ShowInviteUI(APlayerController *PlayerControlle return; } - IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(); + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(World); if (!ExternalUIInterface.IsValid()) { @@ -128,7 +170,7 @@ void UAdvancedExternalUILibrary::ShowInviteUI(APlayerController *PlayerControlle Result = EBlueprintResultSwitch::OnSuccess; } -void UAdvancedExternalUILibrary::ShowFriendsUI(APlayerController *PlayerController, EBlueprintResultSwitch &Result) +void UAdvancedExternalUILibrary::ShowFriendsUI(UObject* WorldContextObject, APlayerController *PlayerController, EBlueprintResultSwitch &Result) { if (!PlayerController) { @@ -137,7 +179,14 @@ void UAdvancedExternalUILibrary::ShowFriendsUI(APlayerController *PlayerControll return; } - IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(); + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineExternalUIPtr ExternalUIInterface = Online::GetExternalUIInterface(World); if (!ExternalUIInterface.IsValid()) { diff --git a/AdvancedSessions/Source/AdvancedSessions/Private/AdvancedIdentityLibrary.cpp b/AdvancedSessions/Source/AdvancedSessions/Private/AdvancedIdentityLibrary.cpp index a44d5ae..47a554b 100644 --- a/AdvancedSessions/Source/AdvancedSessions/Private/AdvancedIdentityLibrary.cpp +++ b/AdvancedSessions/Source/AdvancedSessions/Private/AdvancedIdentityLibrary.cpp @@ -5,7 +5,7 @@ DEFINE_LOG_CATEGORY(AdvancedIdentityLog); -void UAdvancedIdentityLibrary::GetPlayerAuthToken(APlayerController * PlayerController, FString & AuthToken, EBlueprintResultSwitch &Result) +void UAdvancedIdentityLibrary::GetPlayerAuthToken(UObject* WorldContextObject, APlayerController * PlayerController, FString & AuthToken, EBlueprintResultSwitch &Result) { if (!PlayerController) { @@ -23,7 +23,14 @@ void UAdvancedIdentityLibrary::GetPlayerAuthToken(APlayerController * PlayerCont return; } - IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(World); if (!IdentityInterface.IsValid()) { @@ -36,15 +43,21 @@ void UAdvancedIdentityLibrary::GetPlayerAuthToken(APlayerController * PlayerCont Result = EBlueprintResultSwitch::OnSuccess; } -void UAdvancedIdentityLibrary::GetPlayerNickname(const FBPUniqueNetId & UniqueNetID, FString & PlayerNickname) -{ +void UAdvancedIdentityLibrary::GetPlayerNickname(UObject* WorldContextObject, const FBPUniqueNetId & UniqueNetID, FString & PlayerNickname) +{ if (!UniqueNetID.IsValid()) { UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetPlayerNickname was passed a bad player uniquenetid!")); return; } - IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + return; + } + + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(World); if (!IdentityInterface.IsValid()) { @@ -55,7 +68,7 @@ void UAdvancedIdentityLibrary::GetPlayerNickname(const FBPUniqueNetId & UniqueNe } -void UAdvancedIdentityLibrary::GetLoginStatus(const FBPUniqueNetId & UniqueNetID, EBPLoginStatus & LoginStatus, EBlueprintResultSwitch &Result) +void UAdvancedIdentityLibrary::GetLoginStatus(UObject* WorldContextObject, const FBPUniqueNetId & UniqueNetID, EBPLoginStatus & LoginStatus, EBlueprintResultSwitch &Result) { if (!UniqueNetID.IsValid()) { @@ -64,7 +77,14 @@ void UAdvancedIdentityLibrary::GetLoginStatus(const FBPUniqueNetId & UniqueNetID return; } - IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(World); if (!IdentityInterface.IsValid()) { @@ -78,9 +98,17 @@ void UAdvancedIdentityLibrary::GetLoginStatus(const FBPUniqueNetId & UniqueNetID } -void UAdvancedIdentityLibrary::GetAllUserAccounts(TArray & AccountInfos, EBlueprintResultSwitch &Result) +void UAdvancedIdentityLibrary::GetAllUserAccounts(UObject* WorldContextObject, TArray & AccountInfos, EBlueprintResultSwitch &Result) { - IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(World); if (!IdentityInterface.IsValid()) { @@ -99,9 +127,17 @@ void UAdvancedIdentityLibrary::GetAllUserAccounts(TArray & Result = EBlueprintResultSwitch::OnSuccess; } -void UAdvancedIdentityLibrary::GetUserAccount(const FBPUniqueNetId & UniqueNetId, FBPUserOnlineAccount & AccountInfo, EBlueprintResultSwitch &Result) +void UAdvancedIdentityLibrary::GetUserAccount(UObject* WorldContextObject, const FBPUniqueNetId & UniqueNetId, FBPUserOnlineAccount & AccountInfo, EBlueprintResultSwitch &Result) { - IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + + UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (!IsValid(World)) + { + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(World); if(!UniqueNetId.IsValid()) {