2022-11-13 16:43:01 +00:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "Interaction.h"
|
|
|
|
|
2023-01-16 17:35:11 +00:00
|
|
|
#include "NetworkMessage.h"
|
2023-01-14 20:35:49 +00:00
|
|
|
#include "Chaos/BoundingVolumeUtilities.h"
|
2023-01-16 17:02:12 +00:00
|
|
|
#include "Components/Button.h"
|
2023-01-16 17:35:11 +00:00
|
|
|
#include "GameFramework/Character.h"
|
2022-11-13 16:43:01 +00:00
|
|
|
#include "Components/WidgetComponent.h"
|
2023-01-16 20:44:47 +00:00
|
|
|
#include "Kismet/KismetMathLibrary.h"
|
2023-01-30 17:21:10 +00:00
|
|
|
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
|
2022-11-13 16:43:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
// 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();
|
2023-01-23 17:41:55 +00:00
|
|
|
|
2023-01-30 17:23:19 +00:00
|
|
|
//Character & Camera refs
|
2023-01-30 17:21:10 +00:00
|
|
|
TempCharacterRef = Cast<ATempCharacter>(GetWorld()->GetFirstPlayerController()->GetCharacter());
|
|
|
|
MainCamera = Cast<UCameraComponent>(TempCharacterRef->FindComponentByClass<UCameraComponent>());
|
2023-01-23 17:41:55 +00:00
|
|
|
//Item refs
|
|
|
|
|
2023-01-23 16:14:15 +00:00
|
|
|
TargetHealingLocation = HealingItem->GetActorLocation();
|
|
|
|
TargetBuffLocation = BuffItem->GetActorLocation();
|
2023-01-23 17:41:55 +00:00
|
|
|
|
|
|
|
// Dialog refs
|
|
|
|
|
|
|
|
ShopDialogWidget = CreateWidget<UUserWidget>(GetWorld(), ShopDialog);
|
|
|
|
ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
|
|
ShopDialogWidget->AddToViewport();
|
|
|
|
|
|
|
|
//Item Selector refs
|
|
|
|
ItemSelectorWidget = CreateWidget<UUserWidget>(GetWorld(), ItemSelector);
|
|
|
|
ItemSelectorWidget->SetVisibility(ESlateVisibility::Hidden);
|
2023-03-14 03:26:14 +00:00
|
|
|
//ItemSelectorWidget->AddToViewport();
|
2023-01-26 17:43:07 +00:00
|
|
|
//We are getting the property of interaction since we need a reference for when we cast in BP and we need the reference to be self
|
2023-01-23 17:41:55 +00:00
|
|
|
Property = ItemSelectorWidget->GetClass()->FindPropertyByName("publicActor");
|
2023-01-26 17:43:07 +00:00
|
|
|
|
|
|
|
//Confirm Buy refs
|
|
|
|
BuyBuffTextWidget = CreateWidget<UUserWidget>(GetWorld(), BuyBuffText);
|
|
|
|
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
|
|
BuyBuffTextWidget->AddToViewport();
|
|
|
|
//We are getting the property of interaction since we need a reference for when we cast in BP and we need the reference to be self
|
|
|
|
BuyBuffProperty = BuyBuffTextWidget->GetClass()->FindPropertyByName("publicActor");
|
|
|
|
|
|
|
|
BuyHealingTextWidget = CreateWidget<UUserWidget>(GetWorld(), BuyHealingText);
|
|
|
|
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
|
|
BuyHealingTextWidget->AddToViewport();
|
|
|
|
//We are getting the property of interaction since we need a reference for when we cast in BP and we need the reference to be self
|
|
|
|
BuyHealingProperty = BuyHealingTextWidget->GetClass()->FindPropertyByName("publicActor");
|
2023-01-30 17:21:10 +00:00
|
|
|
|
2022-11-13 16:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called every frame
|
|
|
|
void AInteraction::Tick(float DeltaTime)
|
|
|
|
{
|
|
|
|
Super::Tick(DeltaTime);
|
2023-01-14 20:35:49 +00:00
|
|
|
|
2022-11-13 16:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AInteraction::OnInteract()
|
|
|
|
{
|
2023-01-16 20:44:47 +00:00
|
|
|
bDisableShopDialMove = true;
|
2023-01-15 16:13:11 +00:00
|
|
|
if (ShopDialogWidget == nullptr)
|
|
|
|
{
|
2023-01-23 17:41:55 +00:00
|
|
|
UE_LOG(LogTemp, Display, TEXT("ShopDialogWidget is null"));
|
2023-01-15 16:13:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-23 17:41:55 +00:00
|
|
|
//Shop Widget to visible
|
|
|
|
ShopDialogWidget->SetVisibility(ESlateVisibility::Visible);
|
|
|
|
//Call a custom event in a blueprint called "PlayText"
|
|
|
|
ShopDialogWidget->CallFunctionByNameWithArguments(TEXT("PlayText"), *GLog, nullptr, true);
|
2023-01-15 16:13:11 +00:00
|
|
|
}
|
|
|
|
//handles the widget disappearing from the viewport
|
2022-11-28 22:52:51 +00:00
|
|
|
FTimerHandle WidgetTimer;
|
2022-11-28 23:15:41 +00:00
|
|
|
GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false);
|
2023-01-14 20:35:49 +00:00
|
|
|
|
2022-11-13 16:43:01 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 22:52:51 +00:00
|
|
|
void AInteraction::RemoveWidget()
|
|
|
|
{
|
2023-01-14 20:35:49 +00:00
|
|
|
bisDisabled = true;
|
2023-01-23 17:41:55 +00:00
|
|
|
//Setting ShopWidgetText back to hidden
|
|
|
|
ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden);
|
2023-01-30 21:07:36 +00:00
|
|
|
if (ShopDialogWidget->IsVisible())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("You cant open this widget when this widget is open"));
|
|
|
|
}
|
2023-01-14 20:35:49 +00:00
|
|
|
UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true"));
|
2023-03-14 03:26:14 +00:00
|
|
|
ExitScreen();
|
2023-01-23 17:41:55 +00:00
|
|
|
|
2023-01-16 17:02:12 +00:00
|
|
|
if (Property == nullptr)
|
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Error, TEXT("Property not found"));
|
2023-01-26 17:43:07 +00:00
|
|
|
return;
|
2023-01-16 17:02:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(Property);
|
|
|
|
ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(ItemSelectorWidget), this);
|
|
|
|
}
|
2023-01-15 16:13:11 +00:00
|
|
|
if (ItemSelectorWidget == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-23 17:41:55 +00:00
|
|
|
ItemSelectorWidget->SetVisibility(ESlateVisibility::Visible);
|
2023-01-15 16:15:06 +00:00
|
|
|
bisDisabled = false;
|
2023-01-15 16:13:11 +00:00
|
|
|
}
|
2023-01-16 17:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AInteraction::CameraLeftMover()
|
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed"));
|
2023-01-30 17:21:10 +00:00
|
|
|
if (TempCharacterRef == nullptr || BuyHealingProperty == nullptr)
|
2023-01-16 17:35:11 +00:00
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
|
2023-01-23 16:14:15 +00:00
|
|
|
if (MainCamera == nullptr || HealingItem == nullptr)
|
2023-01-16 17:35:11 +00:00
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-26 17:43:07 +00:00
|
|
|
FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(BuyHealingProperty);
|
|
|
|
ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(BuyHealingTextWidget), this);
|
|
|
|
|
2023-01-23 16:14:15 +00:00
|
|
|
CameraLocation = MainCamera->GetComponentLocation();
|
|
|
|
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation);
|
2023-01-16 20:44:47 +00:00
|
|
|
MainCamera->SetWorldRotation(CameraRotation);
|
|
|
|
MainCamera->SetFieldOfView(40);
|
2023-01-26 17:43:07 +00:00
|
|
|
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Visible);
|
2023-01-16 17:35:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-16 17:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AInteraction::CameraRightMover()
|
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed"));
|
2023-01-30 17:21:10 +00:00
|
|
|
if (TempCharacterRef == nullptr || BuyBuffProperty == nullptr)
|
2023-01-16 17:35:11 +00:00
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
|
2023-01-23 16:14:15 +00:00
|
|
|
if (MainCamera == nullptr || BuffItem == nullptr)
|
2023-01-16 17:35:11 +00:00
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-26 17:43:07 +00:00
|
|
|
FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(BuyBuffProperty);
|
|
|
|
ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(BuyBuffTextWidget), this);
|
|
|
|
|
2023-01-23 16:14:15 +00:00
|
|
|
CameraLocation = MainCamera->GetComponentLocation();
|
|
|
|
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation);
|
2023-01-16 20:44:47 +00:00
|
|
|
MainCamera->SetWorldRotation(CameraRotation);
|
|
|
|
MainCamera->SetFieldOfView(40);
|
2023-01-26 17:43:07 +00:00
|
|
|
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Visible);
|
2023-01-16 17:35:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-16 17:02:12 +00:00
|
|
|
}
|
2023-01-26 17:43:07 +00:00
|
|
|
|
|
|
|
void AInteraction::CancelPurchase()
|
|
|
|
{
|
|
|
|
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
|
|
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
|
|
}
|
|
|
|
|
2023-01-30 17:21:10 +00:00
|
|
|
void AInteraction::ExitScreen()
|
2023-01-26 17:43:07 +00:00
|
|
|
{
|
2023-01-30 17:21:10 +00:00
|
|
|
if (TempCharacterRef == nullptr)
|
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("TempCharacterRef in Interaction.cpp not found"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TempCharacterRef->InputEnabler();
|
|
|
|
ItemSelectorWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
|
|
}
|
2023-01-26 17:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|