Updated Interaction, TempCharacter.cpp

Created InputDisabler functions to disable player controls when dialouge box stops to start working on merchant
This commit is contained in:
MH261677 2023-01-14 20:35:49 +00:00
parent a582a05a59
commit 29c3fdcf09
4 changed files with 38 additions and 2 deletions

View File

@ -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<UUserWidget>(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"));
}

View File

@ -27,10 +27,15 @@ public:
TSubclassOf<UUserWidget> Widget;
virtual void OnInteract();
virtual void RemoveWidget();
UPROPERTY()
UUserWidget* CurrentWidget;
UPROPERTY(EditAnywhere)
float WaitTimer = 8.0f;
UPROPERTY()
bool bisDisabled = false;
};

View File

@ -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<AInteraction>(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)

View File

@ -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
};