From 29c3fdcf09394da64e602c6e06b66649c9b08e43 Mon Sep 17 00:00:00 2001 From: MH261677 Date: Sat, 14 Jan 2023 20:35:49 +0000 Subject: [PATCH] Updated Interaction, TempCharacter.cpp Created InputDisabler functions to disable player controls when dialouge box stops to start working on merchant --- .../MerchantInteraction/Interaction.cpp | 8 ++++++- .../MerchantInteraction/Interaction.h | 5 ++++ .../PlayerTemp/TempCharacter.cpp | 23 +++++++++++++++++++ .../PlayerTemp/TempCharacter.h | 4 +++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp index f295c82..ead7abb 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp @@ -3,6 +3,7 @@ #include "Interaction.h" +#include "Chaos/BoundingVolumeUtilities.h" #include "Components/WidgetComponent.h" @@ -25,18 +26,23 @@ void AInteraction::BeginPlay() void AInteraction::Tick(float DeltaTime) { Super::Tick(DeltaTime); - + } void AInteraction::OnInteract() { CurrentWidget = CreateWidget(GetWorld(), Widget); CurrentWidget->AddToViewport(0); + //handles the widget dissapearing from the viewport FTimerHandle WidgetTimer; GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false); + } void AInteraction::RemoveWidget() { + bisDisabled = true; CurrentWidget->RemoveFromViewport(); + UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true")); + } \ No newline at end of file diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h index 64ddcbf..2a6104a 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h @@ -27,10 +27,15 @@ public: TSubclassOf Widget; virtual void OnInteract(); + virtual void RemoveWidget(); UPROPERTY() UUserWidget* CurrentWidget; + UPROPERTY(EditAnywhere) float WaitTimer = 8.0f; + + UPROPERTY() + bool bisDisabled = false; }; diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index 5b6bf51..7c09f12 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -96,15 +96,38 @@ void ATempCharacter::LineTraceLogic() UE_LOG(LogTemp, Display, TEXT("Not Enough Gold")); } } + // if the actor hit has the interaction component/script then it will activate the code + if (AInteraction* MyInteractable = Cast(OutHit.GetActor())) { DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f); MyInteractable->OnInteract(); + UE_LOG(LogTemp, Display, TEXT("OnInteract activated")); UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); + + // While loop to check bisDisabled var until it changes to true + while (MyInteractable->bisDisabled == false) + { + if (MyInteractable->bisDisabled == true) + { + //I am creating a 5 second timer here that then executes the inputdisabler function + FTimerHandle TimerHandle; + FTimerDelegate TimerDelegate = FTimerDelegate::CreateUObject(this, &ATempCharacter::InputDisabler); + GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, 6.0f, false); + break; + } + } } } } +void ATempCharacter::InputDisabler() +{ + UE_LOG(LogTemp, Display, TEXT("Disabling playermovement")); + GetWorld()->GetFirstPlayerController()->SetIgnoreLookInput(false); + GetWorld()->GetFirstPlayerController()->SetIgnoreMoveInput(true); +} + void ATempCharacter::UseItem(class UBaseItem* Item) { if(Item) diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index 56cc8d3..5b607c2 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -37,7 +37,8 @@ public: UPROPERTY(EditAnyWhere) float TraceDistance = 200; - + + void InputDisabler(); void LineTraceLogic(); UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health") @@ -52,4 +53,5 @@ public: //Using the item in the inventory UFUNCTION(BlueprintCallable, Category= "Items") void UseItem(class UBaseItem* Item); // Overriding the BaseItem Class + };