Implement interaction prompt
This commit is contained in:
@@ -69,6 +69,11 @@ void AAgrarianGameCharacter::Tick(float DeltaSeconds)
|
||||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
|
||||
if (IsLocallyControlled())
|
||||
{
|
||||
UpdateInteractionPrompt();
|
||||
}
|
||||
|
||||
ApplyMovementSpeed();
|
||||
|
||||
if (!HasAuthority() || !bWantsToSprint)
|
||||
@@ -498,6 +503,36 @@ void AAgrarianGameCharacter::DoJumpEnd()
|
||||
}
|
||||
|
||||
void AAgrarianGameCharacter::TryInteract()
|
||||
{
|
||||
AActor* HitActor = FindFocusedInteractable();
|
||||
if (!HitActor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasAuthority())
|
||||
{
|
||||
IAgrarianInteractable::Execute_Interact(HitActor, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerInteract(HitActor);
|
||||
}
|
||||
}
|
||||
|
||||
bool AAgrarianGameCharacter::HasInteractionPrompt() const
|
||||
{
|
||||
return FocusedInteractableActor != nullptr && !InteractionPromptText.IsEmpty();
|
||||
}
|
||||
|
||||
void AAgrarianGameCharacter::UpdateInteractionPrompt()
|
||||
{
|
||||
FText NewPromptText;
|
||||
FocusedInteractableActor = FindFocusedInteractable(&NewPromptText);
|
||||
InteractionPromptText = FocusedInteractableActor ? NewPromptText : FText::GetEmpty();
|
||||
}
|
||||
|
||||
AActor* AAgrarianGameCharacter::FindFocusedInteractable(FText* OutPromptText) const
|
||||
{
|
||||
FVector TraceStart;
|
||||
FRotator TraceRotation;
|
||||
@@ -518,26 +553,26 @@ void AAgrarianGameCharacter::TryInteract()
|
||||
|
||||
if (!GetWorld() || !GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, Params))
|
||||
{
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AActor* HitActor = Hit.GetActor();
|
||||
if (!HitActor || !HitActor->GetClass()->ImplementsInterface(UAgrarianInteractable::StaticClass()))
|
||||
{
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (HasAuthority())
|
||||
if (!IAgrarianInteractable::Execute_CanInteract(HitActor, this))
|
||||
{
|
||||
if (IAgrarianInteractable::Execute_CanInteract(HitActor, this))
|
||||
{
|
||||
IAgrarianInteractable::Execute_Interact(HitActor, this);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
|
||||
if (OutPromptText)
|
||||
{
|
||||
ServerInteract(HitActor);
|
||||
*OutPromptText = IAgrarianInteractable::Execute_GetInteractionText(HitActor, this);
|
||||
}
|
||||
|
||||
return HitActor;
|
||||
}
|
||||
|
||||
void AAgrarianGameCharacter::ServerSetWantsToSprint_Implementation(bool bNewWantsToSprint)
|
||||
|
||||
Reference in New Issue
Block a user