|
|
|
|
|
|
| #include "PockmonPlayerController.h"
|
| #include "EnhancedInputSubsystems.h"
|
| #include "Engine/LocalPlayer.h"
|
| #include "InputMappingContext.h"
|
| #include "Blueprint/UserWidget.h"
|
| #include "Pockmon.h"
|
| #include "Widgets/Input/SVirtualJoystick.h"
|
|
|
| void APockmonPlayerController::BeginPlay()
|
| {
|
| Super::BeginPlay();
|
|
|
|
|
| if (ShouldUseTouchControls() && IsLocalPlayerController())
|
| {
|
|
|
| MobileControlsWidget = CreateWidget<UUserWidget>(this, MobileControlsWidgetClass);
|
|
|
| if (MobileControlsWidget)
|
| {
|
|
|
| MobileControlsWidget->AddToPlayerScreen(0);
|
|
|
| } else {
|
|
|
| UE_LOG(LogPockmon, Error, TEXT("Could not spawn mobile controls widget."));
|
|
|
| }
|
|
|
| }
|
| }
|
|
|
| void APockmonPlayerController::SetupInputComponent()
|
| {
|
| Super::SetupInputComponent();
|
|
|
|
|
| if (IsLocalPlayerController())
|
| {
|
|
|
| if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
|
| {
|
| for (UInputMappingContext* CurrentContext : DefaultMappingContexts)
|
| {
|
| Subsystem->AddMappingContext(CurrentContext, 0);
|
| }
|
|
|
|
|
| if (!ShouldUseTouchControls())
|
| {
|
| for (UInputMappingContext* CurrentContext : MobileExcludedMappingContexts)
|
| {
|
| Subsystem->AddMappingContext(CurrentContext, 0);
|
| }
|
| }
|
| }
|
| }
|
| }
|
|
|
| bool APockmonPlayerController::ShouldUseTouchControls() const
|
| {
|
|
|
| return SVirtualJoystick::ShouldDisplayTouchInterface() || bForceTouchControls;
|
| }
|
|
|