Merge branch 'Dialogue-System' into dev
# Conflicts: # Content/Blueprints/Combat_UI/CombatCharacter.uasset
This commit is contained in:
commit
d21486797d
BIN
Content/Dialogue/DialogueTest.umap
(Stored with Git LFS)
Normal file
BIN
Content/Dialogue/DialogueTest.umap
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Dialogue/NPCTest.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Dialogue/NPCTest.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Dialogue/TextPrompt.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Dialogue/TextPrompt.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
118
Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp
Normal file
118
Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "DialogueNPC.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "GameFramework/Character.h"
|
||||
|
||||
// Sets default values for this component's properties
|
||||
UDialogueNPC::UDialogueNPC()
|
||||
{
|
||||
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
||||
// off to improve performance if you don't need them.
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
|
||||
static ConstructorHelpers::FClassFinder<UUserWidget> DialogueWidgetClass(TEXT("/Game/Dialogue/TextPrompt"));
|
||||
DialogueWidget = DialogueWidgetClass.Class;
|
||||
}
|
||||
|
||||
|
||||
// Called when the game starts
|
||||
void UDialogueNPC::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
DialogueWidgetInstance = CreateWidget<UUserWidget>(GetWorld(), DialogueWidget);
|
||||
|
||||
NPCNameText = Cast<UTextBlock>(DialogueWidgetInstance->GetWidgetFromName("Text_Name"));
|
||||
DialogueText = Cast<UTextBlock>(DialogueWidgetInstance->GetWidgetFromName("Text_Dialogue"));
|
||||
NextButton = Cast<UButton>(DialogueWidgetInstance->GetWidgetFromName("Button_Next"));
|
||||
NextButton->OnClicked.AddDynamic(this, &UDialogueNPC::NextDialogue);
|
||||
}
|
||||
|
||||
|
||||
void UDialogueNPC::NextDialogue()
|
||||
{
|
||||
//Dialogue Skip
|
||||
if (CurrentDialogue.Len() < Dialogue[DialogueIndex].Len())
|
||||
{
|
||||
CurrentDialogue = Dialogue[DialogueIndex];
|
||||
DialogueText->SetText(FText::FromString(CurrentDialogue));
|
||||
return;
|
||||
}
|
||||
|
||||
DialogueIndex++;
|
||||
if (DialogueIndex >= Dialogue.Num())
|
||||
{
|
||||
EndDialogue();
|
||||
return;
|
||||
}
|
||||
CurrentDialogue = "";
|
||||
}
|
||||
|
||||
void UDialogueNPC::NextCharacter()
|
||||
{
|
||||
if (DialogueIndex >= Dialogue.Num()) return;
|
||||
|
||||
if (CurrentDialogue.Len() < Dialogue[DialogueIndex].Len())
|
||||
{
|
||||
CurrentDialogue.AppendChar(Dialogue[DialogueIndex][CurrentDialogue.Len()]);
|
||||
DialogueText->SetText(FText::FromString(CurrentDialogue));
|
||||
}
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void UDialogueNPC::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
void UDialogueNPC::StartDialogue()
|
||||
{
|
||||
//Disable Character Movement
|
||||
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
|
||||
{
|
||||
PlayerCharacter->DisableInput(GetWorld()->GetFirstPlayerController());
|
||||
}
|
||||
//Set to UI Mode Only
|
||||
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
|
||||
PlayerController->SetInputMode(FInputModeUIOnly());
|
||||
PlayerController->bShowMouseCursor = true;
|
||||
|
||||
DialogueWidgetInstance->AddToViewport();
|
||||
DialogueIndex = 1;
|
||||
NPCNameText->SetText(FText::FromString(NPCName));
|
||||
CurrentDialogue = "";
|
||||
GetWorld()->GetTimerManager().SetTimer(TextAnimationTimerHandle, this, &UDialogueNPC::NextCharacter, TextAnimationSpeed, true);
|
||||
}
|
||||
|
||||
void UDialogueNPC::EndDialogue()
|
||||
{
|
||||
TextAnimationTimerHandle.Invalidate();
|
||||
DialogueWidgetInstance->RemoveFromParent();
|
||||
|
||||
//Enable Character Movement
|
||||
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
|
||||
{
|
||||
PlayerCharacter->EnableInput(GetWorld()->GetFirstPlayerController());
|
||||
}
|
||||
//Reset UI Mode
|
||||
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
|
||||
PlayerController->SetInputMode(FInputModeGameOnly());
|
||||
PlayerController->bShowMouseCursor = false;
|
||||
}
|
||||
|
||||
TArray<FString> UDialogueNPC::AddDialogue(FText TextInput, TArray<FString> DialogueArrayInput)
|
||||
{
|
||||
if (TextInput.IsEmpty()) return DialogueArrayInput;
|
||||
DialogueArrayInput.Add(TextInput.ToString());
|
||||
return DialogueArrayInput;
|
||||
}
|
||||
|
||||
void UDialogueNPC::GetFinalDialogue(TArray<FString> DialogueArray)
|
||||
{
|
||||
Dialogue = DialogueArray;
|
||||
}
|
82
Source/the_twilight_abyss/Dialogue/DialogueNPC.h
Normal file
82
Source/the_twilight_abyss/Dialogue/DialogueNPC.h
Normal file
@ -0,0 +1,82 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "Components/Button.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "DialogueNPC.generated.h"
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class EChoices : uint8
|
||||
{
|
||||
Choice1 UMETA(DisplayName="Choice 1"),
|
||||
Choice2 UMETA(DisplayName="Choice 2"),
|
||||
Choice3 UMETA(DisplayName="Choice 3"),
|
||||
};
|
||||
|
||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
class THE_TWILIGHT_ABYSS_API UDialogueNPC : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this component's properties
|
||||
UDialogueNPC();
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
FString NPCName;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<FString> Dialogue;
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
float TextAnimationSpeed = 0.05f;
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
UPROPERTY()
|
||||
TSubclassOf<UUserWidget> DialogueWidget;
|
||||
|
||||
private:
|
||||
UPROPERTY()
|
||||
UUserWidget* DialogueWidgetInstance;
|
||||
|
||||
UPROPERTY()
|
||||
UTextBlock* NPCNameText;
|
||||
|
||||
UPROPERTY()
|
||||
UTextBlock* DialogueText;
|
||||
|
||||
UPROPERTY()
|
||||
UButton* NextButton;
|
||||
|
||||
int DialogueIndex = 1;
|
||||
FString CurrentDialogue;
|
||||
|
||||
UPROPERTY()
|
||||
FTimerHandle TextAnimationTimerHandle;
|
||||
|
||||
UFUNCTION()
|
||||
void NextDialogue();
|
||||
void NextCharacter();
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void StartDialogue();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void EndDialogue();
|
||||
|
||||
UFUNCTION(BlueprintPure)
|
||||
TArray<FString> AddDialogue(FText TextInput, TArray<FString> DialogueArrayInput);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void GetFinalDialogue(TArray<FString> DialogueArray);
|
||||
};
|
54
Source/the_twilight_abyss/Dialogue/InteractNPC.cpp
Normal file
54
Source/the_twilight_abyss/Dialogue/InteractNPC.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "InteractNPC.h"
|
||||
#include "DialogueNPC.h"
|
||||
|
||||
|
||||
// Sets default values for this component's properties
|
||||
UInteractNPC::UInteractNPC()
|
||||
{
|
||||
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
||||
// off to improve performance if you don't need them.
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
// Called when the game starts
|
||||
void UInteractNPC::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
// ...
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Called every frame
|
||||
void UInteractNPC::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
void UInteractNPC::Interact()
|
||||
{
|
||||
FVector Start = GetOwner()->GetActorLocation();
|
||||
FVector End = GetOwner()->GetActorForwardVector() * 100.0f + Start;
|
||||
FCollisionQueryParams CollisionParams;
|
||||
CollisionParams.AddIgnoredActor(GetOwner());
|
||||
if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn, CollisionParams))
|
||||
{
|
||||
//UE_LOG(LogTemp, Warning, TEXT("Hit: %s"), *HitResult.GetActor()->GetName());
|
||||
if (HitResult.GetActor()->Tags.Contains("NPC"))
|
||||
{
|
||||
//DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 5.0f, 0, 10.0f);
|
||||
HitResult.GetActor()->FindComponentByClass<UDialogueNPC>()->StartDialogue();
|
||||
}
|
||||
//DrawDebugLine(GetWorld(), Start, End, FColor::Red, false, 5.0f, 0, 10.0f);
|
||||
}
|
||||
}
|
||||
|
29
Source/the_twilight_abyss/Dialogue/InteractNPC.h
Normal file
29
Source/the_twilight_abyss/Dialogue/InteractNPC.h
Normal file
@ -0,0 +1,29 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "InteractNPC.generated.h"
|
||||
|
||||
|
||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
class THE_TWILIGHT_ABYSS_API UInteractNPC : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this component's properties
|
||||
UInteractNPC();
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void Interact();
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user