From 6faa177f962175d15c851fc27e05f03f3a85dbbd Mon Sep 17 00:00:00 2001 From: MARCEL HARA Date: Thu, 26 Jan 2023 17:43:07 +0000 Subject: [PATCH] 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. --- .../MerchantInteraction/Interaction.cpp | 46 ++++++++++++++++++- .../MerchantInteraction/Interaction.h | 22 +++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp index 89e3eef..a029e95 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp @@ -42,7 +42,21 @@ void AInteraction::BeginPlay() ItemSelectorWidget = CreateWidget(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(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(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 @@ -83,6 +97,7 @@ void AInteraction::RemoveWidget() if (Property == nullptr) { UE_LOG(LogTemp, Error, TEXT("Property not found")); + return; } else { @@ -103,7 +118,7 @@ void AInteraction::RemoveWidget() void AInteraction::CameraLeftMover() { 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")); return; @@ -118,10 +133,14 @@ void AInteraction::CameraLeftMover() } else { + FObjectPropertyBase* ObjectProperty = static_cast(BuyHealingProperty); + ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr(BuyHealingTextWidget), this); + CameraLocation = MainCamera->GetComponentLocation(); FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation); MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetFieldOfView(40); + BuyHealingTextWidget->SetVisibility(ESlateVisibility::Visible); } } } @@ -129,7 +148,7 @@ void AInteraction::CameraLeftMover() void AInteraction::CameraRightMover() { 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")); return; @@ -144,10 +163,33 @@ void AInteraction::CameraRightMover() } else { + FObjectPropertyBase* ObjectProperty = static_cast(BuyBuffProperty); + ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr(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() +{ + +} + + + diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h index 8b9e5a7..72b0afb 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h @@ -30,6 +30,12 @@ public: UPROPERTY(EditAnywhere, Category= "Widgets") TSubclassOf ItemSelector; + UPROPERTY(EditAnywhere, Category = "Widgets") + TSubclassOf BuyBuffText; + + UPROPERTY(EditAnywhere, Category = "Widgets") + TSubclassOf BuyHealingText; + virtual void OnInteract(); virtual void RemoveWidget(); @@ -39,6 +45,12 @@ public: UPROPERTY() UUserWidget* ItemSelectorWidget; + + UPROPERTY() + UUserWidget* BuyBuffTextWidget; + + UPROPERTY() + UUserWidget* BuyHealingTextWidget; UPROPERTY(EditAnywhere, Category= "Widgets") float WaitTimer = 8.0f; @@ -67,6 +79,14 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items") AActor* BuffItem; + UFUNCTION(BlueprintCallable, Category = "ConfirmButtons") + virtual void CancelPurchase(); + + UFUNCTION(BlueprintCallable, Category = "ConfirmButtons") + virtual void HealingPurchase(); + + UFUNCTION(BlueprintCallable, Category = "ConfirmButtons") + virtual void BuffPurchase(); private: @@ -75,5 +95,7 @@ private: FVector CameraLocation; FProperty* Property; + FProperty* BuyBuffProperty; + FProperty* BuyHealingProperty; };