// Copyright Epic Games, Inc. All Rights Reserved. #include "Actions/AsyncAction_ShowConfirmation.h" #include "Messaging/CommonGameDialog.h" UAsyncAction_ShowConfirmation::UAsyncAction_ShowConfirmation(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { } UAsyncAction_ShowConfirmation* UAsyncAction_ShowConfirmation::ShowConfirmationYesNo(UObject* InWorldContextObject, FText Title, FText Message) { UAsyncAction_ShowConfirmation* Action = NewObject(); Action->WorldContextObject = InWorldContextObject; Action->Descriptor = UCommonGameDialogDescriptor::CreateConfirmationYesNo(Title, Message); Action->RegisterWithGameInstance(InWorldContextObject); return Action; } UAsyncAction_ShowConfirmation* UAsyncAction_ShowConfirmation::ShowConfirmationOkCancel(UObject* InWorldContextObject, FText Title, FText Message) { UAsyncAction_ShowConfirmation* Action = NewObject(); Action->WorldContextObject = InWorldContextObject; Action->Descriptor = UCommonGameDialogDescriptor::CreateConfirmationOkCancel(Title, Message); Action->RegisterWithGameInstance(InWorldContextObject); return Action; } UAsyncAction_ShowConfirmation* UAsyncAction_ShowConfirmation::ShowConfirmationCustom(UObject* InWorldContextObject, UCommonGameDialogDescriptor* Descriptor) { UAsyncAction_ShowConfirmation* Action = NewObject(); Action->WorldContextObject = InWorldContextObject; Action->Descriptor = Descriptor; Action->RegisterWithGameInstance(InWorldContextObject); return Action; } void UAsyncAction_ShowConfirmation::Activate() { if (WorldContextObject && !TargetLocalPlayer) { if (UUserWidget* UserWidget = Cast(WorldContextObject)) { TargetLocalPlayer = UserWidget->GetOwningLocalPlayer(); } else if (APlayerController* PC = Cast(WorldContextObject)) { TargetLocalPlayer = PC->GetLocalPlayer(); } else if (UWorld* World = WorldContextObject->GetWorld()) { if (UGameInstance* GameInstance = World->GetGameInstance()) { TargetLocalPlayer = GameInstance->GetPrimaryPlayerController(false)->GetLocalPlayer(); } } } if (TargetLocalPlayer) { if (UCommonMessagingSubsystem* Messaging = TargetLocalPlayer->GetSubsystem()) { FCommonMessagingResultDelegate ResultCallback = FCommonMessagingResultDelegate::CreateUObject(this, &UAsyncAction_ShowConfirmation::HandleConfirmationResult); Messaging->ShowConfirmation(Descriptor, ResultCallback); return; } } // If we couldn't make the confirmation, just handle an unknown result and broadcast nothing HandleConfirmationResult(ECommonMessagingResult::Unknown); } void UAsyncAction_ShowConfirmation::HandleConfirmationResult(ECommonMessagingResult ConfirmationResult) { OnResult.Broadcast(ConfirmationResult); SetReadyToDestroy(); }