From 846b21e4e9e7b429134a9806d0a6414db760c837 Mon Sep 17 00:00:00 2001 From: MH261677 Date: Sun, 13 Nov 2022 16:43:01 +0000 Subject: [PATCH] Fixed Interaction Pop-Ups Interaction is now working with the merchant also added interaction class to setup this up. --- Content/Blueprints/BP_Interaction.uasset | 3 ++ Content/Blueprints/BP_MyTempCharacter.uasset | 4 +- Content/Levels/MerchantPrototype.umap | 4 +- .../MerchantInteraction/Interaction.cpp | 37 +++++++++++++++++++ .../MerchantInteraction/Interaction.h | 33 +++++++++++++++++ .../PlayerTemp/TempCharacter.cpp | 20 ++++------ .../PlayerTemp/TempCharacter.h | 11 ------ 7 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 Content/Blueprints/BP_Interaction.uasset create mode 100644 Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp create mode 100644 Source/the_twilight_abyss/MerchantInteraction/Interaction.h diff --git a/Content/Blueprints/BP_Interaction.uasset b/Content/Blueprints/BP_Interaction.uasset new file mode 100644 index 0000000..024952c --- /dev/null +++ b/Content/Blueprints/BP_Interaction.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14deaac2c8f6b6aa67592c8a806ed6059a566d3a767fbd18a092107b29913718 +size 27683 diff --git a/Content/Blueprints/BP_MyTempCharacter.uasset b/Content/Blueprints/BP_MyTempCharacter.uasset index 1f43a9e..0594c08 100644 --- a/Content/Blueprints/BP_MyTempCharacter.uasset +++ b/Content/Blueprints/BP_MyTempCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:09a051db65cef4e2912e96de44ad4da440b1c6fcc0ca839236ec49dc0eb8b943 -size 29574 +oid sha256:7ab40229553278ecf914c2fb5a78609d1bff1d3c451797bf175ecf6a8948d3d5 +size 29619 diff --git a/Content/Levels/MerchantPrototype.umap b/Content/Levels/MerchantPrototype.umap index 1a2b7c2..5e6ba54 100644 --- a/Content/Levels/MerchantPrototype.umap +++ b/Content/Levels/MerchantPrototype.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9e83d7e34f1e94c19d2edbe7aa2755b6261c1c7ddb3628e668fd77a1356b59e0 -size 23038 +oid sha256:b452da02d420447c486ed947537ab3030dddf2942de6533b784f7ec131498696 +size 23264 diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp new file mode 100644 index 0000000..df5bad3 --- /dev/null +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp @@ -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(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(GetWorld(), Widget); + spawnedWidget->AddToViewport(0); +} + diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h new file mode 100644 index 0000000..da9fd47 --- /dev/null +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h @@ -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 Widget; + + virtual void OnInteract(); +}; diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index c9c3d3e..b1f86e8 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -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(TEXT("Widget Reference")); - - //FStringClassReference WidgetClassRef(TEXT("/Game/Merchant/BP_OPENDIAL.BP_OPENDIAL")); - //WidgetClass = WidgetClassRef.TryLoadClass(); - - //WidgetClass = CreateWidget(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(OutHit.GetActor())) + { + DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f); + MyInteractable->OnInteract(); UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); } } diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index 0f3836c..3f170b4 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -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 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 WidgetClass; };