Updated Interaction.cpp
Optimized more code by caching more widgets and instead of creating new widgets I am just toggling them on and off.
This commit is contained in:
parent
c58d5d5592
commit
ddc2ef526d
@ -22,10 +22,27 @@ AInteraction::AInteraction()
|
||||
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();
|
||||
Property = ItemSelectorWidget->GetClass()->FindPropertyByName("publicActor");
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
@ -38,14 +55,17 @@ void AInteraction::Tick(float DeltaTime)
|
||||
void AInteraction::OnInteract()
|
||||
{
|
||||
bDisableShopDialMove = true;
|
||||
ShopDialogWidget = CreateWidget<UUserWidget>(GetWorld(), ShopDialog);
|
||||
if (ShopDialogWidget == nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Display, TEXT("ShopDialogWidget is null"));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
ShopDialogWidget->AddToViewport(0);
|
||||
//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;
|
||||
@ -56,10 +76,10 @@ void AInteraction::OnInteract()
|
||||
void AInteraction::RemoveWidget()
|
||||
{
|
||||
bisDisabled = true;
|
||||
ShopDialogWidget->RemoveFromViewport();
|
||||
//Setting ShopWidgetText back to hidden
|
||||
ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden);
|
||||
UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true"));
|
||||
ItemSelectorWidget = CreateWidget<UUserWidget>(GetWorld(), ItemSelector);
|
||||
FProperty* Property = ItemSelectorWidget->GetClass()->FindPropertyByName("publicActor");
|
||||
|
||||
if (Property == nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("Property not found"));
|
||||
@ -75,7 +95,7 @@ void AInteraction::RemoveWidget()
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemSelectorWidget->AddToViewport(0);
|
||||
ItemSelectorWidget->SetVisibility(ESlateVisibility::Visible);
|
||||
bisDisabled = false;
|
||||
}
|
||||
}
|
||||
|
@ -66,11 +66,14 @@ public:
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items")
|
||||
AActor* BuffItem;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
FVector TargetHealingLocation;
|
||||
FVector TargetBuffLocation;
|
||||
FVector CameraLocation;
|
||||
|
||||
FProperty* Property;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user