3f4cdf5bfa
Optimized some functions and variables by storing them in beginplay
134 lines
3.5 KiB
C++
134 lines
3.5 KiB
C++
// 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();
|
|
TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
|
|
MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
|
|
TargetHealingLocation = HealingItem->GetActorLocation();
|
|
TargetBuffLocation = BuffItem->GetActorLocation();
|
|
}
|
|
|
|
// Called every frame
|
|
void AInteraction::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick(DeltaTime);
|
|
|
|
}
|
|
|
|
void AInteraction::OnInteract()
|
|
{
|
|
bDisableShopDialMove = true;
|
|
ShopDialogWidget = CreateWidget<UUserWidget>(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<UUserWidget>(GetWorld(), ItemSelector);
|
|
FProperty* Property = ItemSelectorWidget->GetClass()->FindPropertyByName("publicActor");
|
|
if (Property == nullptr)
|
|
{
|
|
UE_LOG(LogTemp, Error, TEXT("Property not found"));
|
|
}
|
|
else
|
|
{
|
|
FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(Property);
|
|
ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(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"));
|
|
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 || HealingItem == nullptr)
|
|
{
|
|
UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
CameraLocation = MainCamera->GetComponentLocation();
|
|
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation);
|
|
MainCamera->SetWorldRotation(CameraRotation);
|
|
MainCamera->SetFieldOfView(40);
|
|
}
|
|
}
|
|
}
|
|
|
|
void AInteraction::CameraRightMover()
|
|
{
|
|
UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed"));
|
|
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 || BuffItem == nullptr)
|
|
{
|
|
UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
CameraLocation = MainCamera->GetComponentLocation();
|
|
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation);
|
|
MainCamera->SetWorldRotation(CameraRotation);
|
|
MainCamera->SetFieldOfView(40);
|
|
}
|
|
}
|
|
}
|