// Fill out your copyright notice in the Description page of Project Settings. #include "Interaction.h" #include "NetworkMessage.h" #include "Chaos/BoundingVolumeUtilities.h" #include "Components/Button.h" #include "GameFramework/Character.h" #include "Components/WidgetComponent.h" #include "Kismet/KismetMathLibrary.h" // Sets default values AInteraction::AInteraction() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; } // Called when the game starts or when spawned void AInteraction::BeginPlay() { Super::BeginPlay(); } // Called every frame void AInteraction::Tick(float DeltaTime) { Super::Tick(DeltaTime); } void AInteraction::OnInteract() { bDisableShopDialMove = true; ShopDialogWidget = CreateWidget(GetWorld(), ShopDialog); if (ShopDialogWidget == nullptr) { return; } else { ShopDialogWidget->AddToViewport(0); } //handles the widget disappearing from the viewport FTimerHandle WidgetTimer; GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false); } void AInteraction::RemoveWidget() { bisDisabled = true; ShopDialogWidget->RemoveFromViewport(); UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true")); ItemSelectorWidget = CreateWidget(GetWorld(), ItemSelector); FProperty* Property = ItemSelectorWidget->GetClass()->FindPropertyByName("publicActor"); if (Property == nullptr) { UE_LOG(LogTemp, Error, TEXT("Property not found")); } else { FObjectPropertyBase* ObjectProperty = static_cast(Property); ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr(ItemSelectorWidget), this); } if (ItemSelectorWidget == nullptr) { return; } else { ItemSelectorWidget->AddToViewport(0); bisDisabled = false; } } void AInteraction::CameraLeftMover() { UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed")); TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); MainCamera = Cast(TempCharacter->FindComponentByClass()); if (TempCharacter == nullptr) { UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); return; } else { UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp")); if (MainCamera == nullptr) { UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp")); return; } else { FVector TargetLocation = FVector(5700,-1270,4040); FVector CameraLocation = MainCamera->GetComponentLocation(); FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation); MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetFieldOfView(40); } } } void AInteraction::CameraRightMover() { UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed")); TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); MainCamera = Cast(TempCharacter->FindComponentByClass()); if (TempCharacter == nullptr) { UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); return; } else { UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp")); if (MainCamera == nullptr) { UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp")); return; } else { FVector TargetLocation = FVector(5260, -840, 4070); FVector CameraLocation = MainCamera->GetComponentLocation(); FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation); MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetFieldOfView(40); } } }