Fixed Interaction Pop-Ups

Interaction is now working with the merchant also added interaction class to setup this up.
This commit is contained in:
MH261677 2022-11-13 16:43:01 +00:00
parent eeaf52df89
commit 846b21e4e9
7 changed files with 85 additions and 27 deletions

BIN
Content/Blueprints/BP_Interaction.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/Levels/MerchantPrototype.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -0,0 +1,37 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction.h"
#include "Components/WidgetComponent.h"
// Sets default values
AInteraction::AInteraction()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
WidgetBase = CreateDefaultSubobject<UWidgetComponent>(TEXT("Widget Base Class"));
}
// Called when the game starts or when spawned
void AInteraction::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AInteraction::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AInteraction::OnInteract()
{
auto spawnedWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
spawnedWidget->AddToViewport(0);
}

View File

@ -0,0 +1,33 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Interaction.generated.h"
UCLASS()
class THE_TWILIGHT_ABYSS_API AInteraction : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AInteraction();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(VisibleAnywhere)
class UWidgetComponent* WidgetBase;
UPROPERTY(EditAnywhere)
TSubclassOf<UUserWidget> Widget;
virtual void OnInteract();
};

View File

@ -6,6 +6,7 @@
#include "Engine/GameViewportClient.h"
#include "Blueprint/UserWidget.h"
#include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h"
#include "the_twilight_abyss/MerchantInteraction/Interaction.h"
// CONSTRUCTOR
@ -13,16 +14,6 @@ ATempCharacter::ATempCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
//WidgetRef = CreateDefaultSubobject<UUserWidget>(TEXT("Widget Reference"));
//FStringClassReference WidgetClassRef(TEXT("/Game/Merchant/BP_OPENDIAL.BP_OPENDIAL"));
//WidgetClass = WidgetClassRef.TryLoadClass<UUserWidget>();
//WidgetClass = CreateWidget<UUserWidget>(GetWorld(),WidgetClass);
if(WidgetRef)
{
WidgetRef->AddToViewport(0);
}
}
// Called when the game starts or when spawned
@ -82,10 +73,15 @@ void ATempCharacter::LineTraceLogic()
bool bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams);
if (bHit)
{
if (OutHit.GetActor()->ActorHasTag("MerchantTag"))
if(OutHit.GetActor() == nullptr)
{
WidgetRef->AddToViewport(0);
return;
}
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
{
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
MyInteractable->OnInteract();
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
}
}

View File

@ -4,7 +4,6 @@
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Blueprint/UserWidget.h"
#include "TempCharacter.generated.h"
UCLASS()
@ -22,8 +21,6 @@ protected:
void ForwardInput(float Axis);
void RightMoveInput(float Axis);
TSubclassOf<UUserWidget> WidgetClass; //defining the widget class
public:
// Called every frame
@ -38,12 +35,4 @@ public:
float TraceDistance = 200;
void LineTraceLogic();
UPROPERTY(EditBlueprintReadWrite, meta = (BindWidget))
UUserWidget* WidgetRef;
//private:
//UPROPERTY(EditDefaultsOnly)
//TSubclassOf<UUserWidget> WidgetClass;
};