Updated Interaction.cpp

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.
This commit is contained in:
MARCEL HARA 2023-01-26 17:43:07 +00:00
parent 2f22ec811f
commit 6faa177f96
2 changed files with 66 additions and 2 deletions

View File

@ -42,7 +42,21 @@ void AInteraction::BeginPlay()
ItemSelectorWidget = CreateWidget<UUserWidget>(GetWorld(), ItemSelector); ItemSelectorWidget = CreateWidget<UUserWidget>(GetWorld(), ItemSelector);
ItemSelectorWidget->SetVisibility(ESlateVisibility::Hidden); ItemSelectorWidget->SetVisibility(ESlateVisibility::Hidden);
ItemSelectorWidget->AddToViewport(); 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"); 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 // Called every frame
@ -83,6 +97,7 @@ void AInteraction::RemoveWidget()
if (Property == nullptr) if (Property == nullptr)
{ {
UE_LOG(LogTemp, Error, TEXT("Property not found")); UE_LOG(LogTemp, Error, TEXT("Property not found"));
return;
} }
else else
{ {
@ -103,7 +118,7 @@ void AInteraction::RemoveWidget()
void AInteraction::CameraLeftMover() void AInteraction::CameraLeftMover()
{ {
UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed")); UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed"));
if (TempCharacter == nullptr) if (TempCharacter == nullptr || BuyHealingProperty == nullptr)
{ {
UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
return; return;
@ -118,10 +133,14 @@ void AInteraction::CameraLeftMover()
} }
else else
{ {
FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(BuyHealingProperty);
ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(BuyHealingTextWidget), this);
CameraLocation = MainCamera->GetComponentLocation(); CameraLocation = MainCamera->GetComponentLocation();
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation); FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation);
MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetWorldRotation(CameraRotation);
MainCamera->SetFieldOfView(40); MainCamera->SetFieldOfView(40);
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Visible);
} }
} }
} }
@ -129,7 +148,7 @@ void AInteraction::CameraLeftMover()
void AInteraction::CameraRightMover() void AInteraction::CameraRightMover()
{ {
UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed")); UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed"));
if (TempCharacter == nullptr) if (TempCharacter == nullptr || BuyBuffProperty == nullptr)
{ {
UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
return; return;
@ -144,10 +163,33 @@ void AInteraction::CameraRightMover()
} }
else else
{ {
FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(BuyBuffProperty);
ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(BuyBuffTextWidget), this);
CameraLocation = MainCamera->GetComponentLocation(); CameraLocation = MainCamera->GetComponentLocation();
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation); FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation);
MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetWorldRotation(CameraRotation);
MainCamera->SetFieldOfView(40); MainCamera->SetFieldOfView(40);
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Visible);
} }
} }
} }
void AInteraction::CancelPurchase()
{
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Hidden);
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Hidden);
}
void AInteraction::HealingPurchase()
{
}
void AInteraction::BuffPurchase()
{
}

View File

@ -30,6 +30,12 @@ public:
UPROPERTY(EditAnywhere, Category= "Widgets") UPROPERTY(EditAnywhere, Category= "Widgets")
TSubclassOf<UUserWidget> ItemSelector; TSubclassOf<UUserWidget> ItemSelector;
UPROPERTY(EditAnywhere, Category = "Widgets")
TSubclassOf<UUserWidget> BuyBuffText;
UPROPERTY(EditAnywhere, Category = "Widgets")
TSubclassOf<UUserWidget> BuyHealingText;
virtual void OnInteract(); virtual void OnInteract();
virtual void RemoveWidget(); virtual void RemoveWidget();
@ -40,6 +46,12 @@ public:
UPROPERTY() UPROPERTY()
UUserWidget* ItemSelectorWidget; UUserWidget* ItemSelectorWidget;
UPROPERTY()
UUserWidget* BuyBuffTextWidget;
UPROPERTY()
UUserWidget* BuyHealingTextWidget;
UPROPERTY(EditAnywhere, Category= "Widgets") UPROPERTY(EditAnywhere, Category= "Widgets")
float WaitTimer = 8.0f; float WaitTimer = 8.0f;
@ -67,6 +79,14 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items")
AActor* BuffItem; AActor* BuffItem;
UFUNCTION(BlueprintCallable, Category = "ConfirmButtons")
virtual void CancelPurchase();
UFUNCTION(BlueprintCallable, Category = "ConfirmButtons")
virtual void HealingPurchase();
UFUNCTION(BlueprintCallable, Category = "ConfirmButtons")
virtual void BuffPurchase();
private: private:
@ -75,5 +95,7 @@ private:
FVector CameraLocation; FVector CameraLocation;
FProperty* Property; FProperty* Property;
FProperty* BuyBuffProperty;
FProperty* BuyHealingProperty;
}; };