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:
parent
2f22ec811f
commit
6faa177f96
@ -42,7 +42,21 @@ void AInteraction::BeginPlay()
|
||||
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
|
||||
@ -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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -30,6 +30,12 @@ public:
|
||||
UPROPERTY(EditAnywhere, Category= "Widgets")
|
||||
TSubclassOf<UUserWidget> ItemSelector;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Widgets")
|
||||
TSubclassOf<UUserWidget> BuyBuffText;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Widgets")
|
||||
TSubclassOf<UUserWidget> BuyHealingText;
|
||||
|
||||
virtual void OnInteract();
|
||||
|
||||
virtual void RemoveWidget();
|
||||
@ -40,6 +46,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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user