6faa177f96
Referenced the two buy confirms screen so I can just hide them and cache them upon the start of the game to optimize and fix many bugs such as being able to stack the buy screens.
196 lines
5.9 KiB
C++
196 lines
5.9 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();
|
|
|
|
//Character refs
|
|
TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
|
|
MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
|
|
|
|
//Item refs
|
|
|
|
TargetHealingLocation = HealingItem->GetActorLocation();
|
|
TargetBuffLocation = BuffItem->GetActorLocation();
|
|
|
|
// 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);
|
|
ItemSelectorWidget->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
|
|
Property = ItemSelectorWidget->GetClass()->FindPropertyByName("publicActor");
|
|
|
|
//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");
|
|
}
|
|
|
|
// Called every frame
|
|
void AInteraction::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick(DeltaTime);
|
|
|
|
}
|
|
|
|
void AInteraction::OnInteract()
|
|
{
|
|
bDisableShopDialMove = true;
|
|
if (ShopDialogWidget == nullptr)
|
|
{
|
|
UE_LOG(LogTemp, Display, TEXT("ShopDialogWidget is null"));
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
//Shop Widget to visible
|
|
ShopDialogWidget->SetVisibility(ESlateVisibility::Visible);
|
|
//Call a custom event in a blueprint called "PlayText"
|
|
ShopDialogWidget->CallFunctionByNameWithArguments(TEXT("PlayText"), *GLog, nullptr, true);
|
|
}
|
|
//handles the widget disappearing from the viewport
|
|
FTimerHandle WidgetTimer;
|
|
GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false);
|
|
|
|
}
|
|
|
|
void AInteraction::RemoveWidget()
|
|
{
|
|
bisDisabled = true;
|
|
//Setting ShopWidgetText back to hidden
|
|
ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true"));
|
|
|
|
if (Property == nullptr)
|
|
{
|
|
UE_LOG(LogTemp, Error, TEXT("Property not found"));
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(Property);
|
|
ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(ItemSelectorWidget), this);
|
|
}
|
|
if (ItemSelectorWidget == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
ItemSelectorWidget->SetVisibility(ESlateVisibility::Visible);
|
|
bisDisabled = false;
|
|
}
|
|
}
|
|
|
|
void AInteraction::CameraLeftMover()
|
|
{
|
|
UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed"));
|
|
if (TempCharacter == nullptr || BuyHealingProperty == 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
|
|
{
|
|
FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(BuyHealingProperty);
|
|
ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(BuyHealingTextWidget), this);
|
|
|
|
CameraLocation = MainCamera->GetComponentLocation();
|
|
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation);
|
|
MainCamera->SetWorldRotation(CameraRotation);
|
|
MainCamera->SetFieldOfView(40);
|
|
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Visible);
|
|
}
|
|
}
|
|
}
|
|
|
|
void AInteraction::CameraRightMover()
|
|
{
|
|
UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed"));
|
|
if (TempCharacter == nullptr || BuyBuffProperty == 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
|
|
{
|
|
FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(BuyBuffProperty);
|
|
ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(BuyBuffTextWidget), this);
|
|
|
|
CameraLocation = MainCamera->GetComponentLocation();
|
|
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation);
|
|
MainCamera->SetWorldRotation(CameraRotation);
|
|
MainCamera->SetFieldOfView(40);
|
|
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Visible);
|
|
}
|
|
}
|
|
}
|
|
|
|
void AInteraction::CancelPurchase()
|
|
{
|
|
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
}
|
|
|
|
void AInteraction::HealingPurchase()
|
|
{
|
|
|
|
}
|
|
|
|
void AInteraction::BuffPurchase()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|