Contextual interaction system #6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -31,6 +31,10 @@ public:
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
|
||||
TArray<FInteractionOption> GetInteractionOptions(AActor* Interactor);
|
||||
|
||||
/** Friendly object name for prompts, e.g. "Berry Bush", "Wooden Chest", "Workbench". Optional - an empty default just drops the "with X" part of the prompt. */
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
|
||||
FText GetInteractableDisplayName();
|
||||
|
||||
/** Runs the interaction identified by ActionID (one of the ActionIDs previously returned by GetInteractionOptions). */
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
|
||||
void ExecuteInteraction(AActor* Interactor, FName ActionID);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "InteractionContextMenuWidget.h"
|
||||
#include "Interaction/InteractionComponent.h"
|
||||
#include "Interaction/Interactable.h"
|
||||
#include "Components/VerticalBox.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "Blueprint/WidgetTree.h"
|
||||
@@ -50,15 +51,32 @@ void UInteractionContextMenuWidget::HandleFocusedInteractableChanged(AActor* Foc
|
||||
return;
|
||||
}
|
||||
|
||||
if (FocusedActor && Options.Num() > 0)
|
||||
{
|
||||
PromptText->SetText(Options[0].DisplayName);
|
||||
PromptText->SetVisibility(ESlateVisibility::HitTestInvisible);
|
||||
}
|
||||
else
|
||||
if (!FocusedActor || Options.Num() == 0)
|
||||
{
|
||||
PromptText->SetVisibility(ESlateVisibility::Collapsed);
|
||||
return;
|
||||
}
|
||||
|
||||
// "{Verb} with {ObjectName}" on line one, "Press E" always, then a hint for the
|
||||
// hold behaviour only when there is one (2 options = secondary, 3+ = Context Menu).
|
||||
const FText ObjectName = IInteractable::Execute_GetInteractableDisplayName(FocusedActor);
|
||||
FString Prompt = ObjectName.IsEmpty()
|
||||
? Options[0].DisplayName.ToString()
|
||||
: FString::Printf(TEXT("%s with %s"), *Options[0].DisplayName.ToString(), *ObjectName.ToString());
|
||||
|
||||
Prompt += TEXT("\nPress E");
|
||||
|
||||
if (Options.Num() == 2)
|
||||
{
|
||||
Prompt += TEXT("\nHold E for secondary interaction");
|
||||
}
|
||||
else if (Options.Num() >= 3)
|
||||
{
|
||||
Prompt += TEXT("\nHold E for Context Menu");
|
||||
}
|
||||
|
||||
PromptText->SetText(FText::FromString(Prompt));
|
||||
PromptText->SetVisibility(ESlateVisibility::HitTestInvisible);
|
||||
}
|
||||
|
||||
void UInteractionContextMenuWidget::RefreshOptions(const TArray<FInteractionOption>& Options, int32 HighlightedIndex)
|
||||
|
||||
Reference in New Issue
Block a user