Download LyraStarterGame/Plugins/CommonGame/Source/Private/CommonUIExtensions.cpp from Alexhas2/unitysamples: direct link, hf CLI and curl.
- Browser
- Download file 5.58 kB
-
https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Plugins/CommonGame/Source/Private/CommonUIExtensions.cpp
- Command line
-
hf download hf://datasets/Alexhas2/unitysamples/LyraStarterGame/Plugins/CommonGame/Source/Private/CommonUIExtensions.cpp
-
curl -L -o CommonUIExtensions.cpp https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Plugins/CommonGame/Source/Private/CommonUIExtensions.cpp
5.58 kB
| // Copyright Epic Games, Inc. All Rights Reserved. | |
| int32 UCommonUIExtensions::InputSuspensions = 0; | |
| ECommonInputType UCommonUIExtensions::GetOwningPlayerInputType(const UUserWidget* WidgetContextObject) | |
| { | |
| if (WidgetContextObject) | |
| { | |
| if (const UCommonInputSubsystem* InputSubsystem = UCommonInputSubsystem::Get(WidgetContextObject->GetOwningLocalPlayer())) | |
| { | |
| return InputSubsystem->GetCurrentInputType(); | |
| } | |
| } | |
| return ECommonInputType::Count; | |
| } | |
| bool UCommonUIExtensions::IsOwningPlayerUsingTouch(const UUserWidget* WidgetContextObject) | |
| { | |
| if (WidgetContextObject) | |
| { | |
| if (const UCommonInputSubsystem* InputSubsystem = UCommonInputSubsystem::Get(WidgetContextObject->GetOwningLocalPlayer())) | |
| { | |
| return InputSubsystem->GetCurrentInputType() == ECommonInputType::Touch; | |
| } | |
| } | |
| return false; | |
| } | |
| bool UCommonUIExtensions::IsOwningPlayerUsingGamepad(const UUserWidget* WidgetContextObject) | |
| { | |
| if (WidgetContextObject) | |
| { | |
| if (const UCommonInputSubsystem* InputSubsystem = UCommonInputSubsystem::Get(WidgetContextObject->GetOwningLocalPlayer())) | |
| { | |
| return InputSubsystem->GetCurrentInputType() == ECommonInputType::Gamepad; | |
| } | |
| } | |
| return false; | |
| } | |
| UCommonActivatableWidget* UCommonUIExtensions::PushContentToLayer_ForPlayer(const ULocalPlayer* LocalPlayer, FGameplayTag LayerName, TSubclassOf<UCommonActivatableWidget> WidgetClass) | |
| { | |
| if (!ensure(LocalPlayer) || !ensure(WidgetClass != nullptr)) | |
| { | |
| return nullptr; | |
| } | |
| if (UGameUIManagerSubsystem* UIManager = LocalPlayer->GetGameInstance()->GetSubsystem<UGameUIManagerSubsystem>()) | |
| { | |
| if (UGameUIPolicy* Policy = UIManager->GetCurrentUIPolicy()) | |
| { | |
| if (UPrimaryGameLayout* RootLayout = Policy->GetRootLayout(CastChecked<UCommonLocalPlayer>(LocalPlayer))) | |
| { | |
| return RootLayout->PushWidgetToLayerStack(LayerName, WidgetClass); | |
| } | |
| } | |
| } | |
| return nullptr; | |
| } | |
| void UCommonUIExtensions::PushStreamedContentToLayer_ForPlayer(const ULocalPlayer* LocalPlayer, FGameplayTag LayerName, TSoftClassPtr<UCommonActivatableWidget> WidgetClass) | |
| { | |
| if (!ensure(LocalPlayer) || !ensure(!WidgetClass.IsNull())) | |
| { | |
| return; | |
| } | |
| if (UGameUIManagerSubsystem* UIManager = LocalPlayer->GetGameInstance()->GetSubsystem<UGameUIManagerSubsystem>()) | |
| { | |
| if (UGameUIPolicy* Policy = UIManager->GetCurrentUIPolicy()) | |
| { | |
| if (UPrimaryGameLayout* RootLayout = Policy->GetRootLayout(CastChecked<UCommonLocalPlayer>(LocalPlayer))) | |
| { | |
| const bool bSuspendInputUntilComplete = true; | |
| RootLayout->PushWidgetToLayerStackAsync(LayerName, bSuspendInputUntilComplete, WidgetClass); | |
| } | |
| } | |
| } | |
| } | |
| void UCommonUIExtensions::PopContentFromLayer(UCommonActivatableWidget* ActivatableWidget) | |
| { | |
| if (!ActivatableWidget) | |
| { | |
| // Ignore request to pop an already deleted widget | |
| return; | |
| } | |
| if (const ULocalPlayer* LocalPlayer = ActivatableWidget->GetOwningLocalPlayer()) | |
| { | |
| if (const UGameUIManagerSubsystem* UIManager = LocalPlayer->GetGameInstance()->GetSubsystem<UGameUIManagerSubsystem>()) | |
| { | |
| if (const UGameUIPolicy* Policy = UIManager->GetCurrentUIPolicy()) | |
| { | |
| if (UPrimaryGameLayout* RootLayout = Policy->GetRootLayout(CastChecked<UCommonLocalPlayer>(LocalPlayer))) | |
| { | |
| RootLayout->FindAndRemoveWidgetFromLayer(ActivatableWidget); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ULocalPlayer* UCommonUIExtensions::GetLocalPlayerFromController(APlayerController* PlayerController) | |
| { | |
| if (PlayerController) | |
| { | |
| return Cast<ULocalPlayer>(PlayerController->Player); | |
| } | |
| return nullptr; | |
| } | |
| FName UCommonUIExtensions::SuspendInputForPlayer(APlayerController* PlayerController, FName SuspendReason) | |
| { | |
| return SuspendInputForPlayer(PlayerController ? PlayerController->GetLocalPlayer() : nullptr, SuspendReason); | |
| } | |
| FName UCommonUIExtensions::SuspendInputForPlayer(ULocalPlayer* LocalPlayer, FName SuspendReason) | |
| { | |
| if (UCommonInputSubsystem* CommonInputSubsystem = UCommonInputSubsystem::Get(LocalPlayer)) | |
| { | |
| InputSuspensions++; | |
| FName SuspendToken = SuspendReason; | |
| SuspendToken.SetNumber(InputSuspensions); | |
| CommonInputSubsystem->SetInputTypeFilter(ECommonInputType::MouseAndKeyboard, SuspendToken, true); | |
| CommonInputSubsystem->SetInputTypeFilter(ECommonInputType::Gamepad, SuspendToken, true); | |
| CommonInputSubsystem->SetInputTypeFilter(ECommonInputType::Touch, SuspendToken, true); | |
| return SuspendToken; | |
| } | |
| return NAME_None; | |
| } | |
| void UCommonUIExtensions::ResumeInputForPlayer(APlayerController* PlayerController, FName SuspendToken) | |
| { | |
| ResumeInputForPlayer(PlayerController ? PlayerController->GetLocalPlayer() : nullptr, SuspendToken); | |
| } | |
| void UCommonUIExtensions::ResumeInputForPlayer(ULocalPlayer* LocalPlayer, FName SuspendToken) | |
| { | |
| if (SuspendToken == NAME_None) | |
| { | |
| return; | |
| } | |
| if (UCommonInputSubsystem* CommonInputSubsystem = UCommonInputSubsystem::Get(LocalPlayer)) | |
| { | |
| CommonInputSubsystem->SetInputTypeFilter(ECommonInputType::MouseAndKeyboard, SuspendToken, false); | |
| CommonInputSubsystem->SetInputTypeFilter(ECommonInputType::Gamepad, SuspendToken, false); | |
| CommonInputSubsystem->SetInputTypeFilter(ECommonInputType::Touch, SuspendToken, false); | |
| } | |
| } | |