Update Character Interact to Include Dialogue

This commit is contained in:
Philip W 2024-01-22 23:04:39 +00:00
parent d30425d6e5
commit e6b7edcf8c
10 changed files with 158 additions and 47 deletions

View File

@ -16,6 +16,7 @@
### UnrealEngine ###
# Visual Studio 2015 user specific files
.vs/
.idea/
# Compiled Object files
*.slo

View File

@ -3,8 +3,12 @@
#pragma once
#include "CoreMinimal.h"
#include "AC_PlayerDialogueInterpreter.h"
#include "DialogueTree.h"
#include "Components/ActorComponent.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "EndlessVendetta/InteractionInterface.h"
#include "Kismet/GameplayStatics.h"
#include "AC_Dialogue.generated.h"
@ -14,6 +18,18 @@ class ENDLESSVENDETTA_API UAC_Dialogue : public UActorComponent
GENERATED_BODY()
public:
void Interact() const;
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Dialogue")
UDialogueTree* DialogueTree;
};
inline void UAC_Dialogue::Interact() const
{
GLog->Log("Interacting with dialogue");
if (!IsValid(DialogueTree)) return;
AEndlessVendettaCharacter* Character = Cast<AEndlessVendettaCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
if (!IsValid(Cast<UAC_PlayerDialogueInterpreter>(Character->GetComponentByClass(UAC_PlayerDialogueInterpreter::StaticClass())))) return;
Cast<UAC_PlayerDialogueInterpreter>(Character->GetComponentByClass(UAC_PlayerDialogueInterpreter::StaticClass()))->StartDialogue(DialogueTree);
Character->bIsInDialogue = true;
}

View File

@ -3,6 +3,8 @@
#include "AC_PlayerDialogueInterpreter.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
// Sets default values for this component's properties
UAC_PlayerDialogueInterpreter::UAC_PlayerDialogueInterpreter()
@ -37,39 +39,65 @@ void UAC_PlayerDialogueInterpreter::StartDialogue(UDialogueTree* DialogueTree)
CurrentDialogueTree = DialogueTree;
CurrentTextNode = Cast<UDialogueTextNode>(DialogueTree->RootNodes[0]->ChildrenNodes[0]);
OnStartDialogue.Broadcast(CurrentTextNode);
if (APlayerController* PlayerController = GetWorld()->GetFirstPlayerController())
{
FInputModeUIOnly InputModeData;
InputModeData.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
PlayerController->SetInputMode(InputModeData);
PlayerController->bShowMouseCursor = true;
}
}
void UAC_PlayerDialogueInterpreter::NextDialogue()
{
if (IsValid(CurrentTextNode))
if (!IsValid(CurrentTextNode)) return;
if (CurrentTextNode->ChildrenNodes.Num() == 0)
{
if (Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[0]))
{
CurrentTextNode = nullptr;
CurrentChoiceNode = Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[0]);
OnChoiceDialogue.Broadcast(CurrentChoiceNode);
}
else
{
CurrentChoiceNode = nullptr;
CurrentTextNode = Cast<UDialogueTextNode>(CurrentTextNode->ChildrenNodes[0]);
OnNextDialogue.Broadcast(CurrentTextNode);
}
EndDialogue();
return;
}
if (Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[0]))
{
CurrentChoiceNode = Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[0]);
OnChoiceDialogue.Broadcast(CurrentChoiceNode);
CurrentTextNode = nullptr;
}
else
{
CurrentTextNode = Cast<UDialogueTextNode>(CurrentTextNode->ChildrenNodes[0]);
OnNextDialogue.Broadcast(CurrentTextNode);
CurrentChoiceNode = nullptr;
}
}
void UAC_PlayerDialogueInterpreter::MakeChoiceDialogue(const int Choice)
{
if (Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[Choice]))
if (!IsValid(CurrentChoiceNode)) return;
if (Cast<UDialogueChoiceNode>(CurrentChoiceNode->ChildrenNodes[Choice]))
{
CurrentTextNode = nullptr;
CurrentChoiceNode = Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[Choice]);
CurrentChoiceNode = Cast<UDialogueChoiceNode>(CurrentChoiceNode->ChildrenNodes[Choice]);
OnChoiceDialogue.Broadcast(CurrentChoiceNode);
CurrentTextNode = nullptr;
}
else
{
CurrentChoiceNode = nullptr;
CurrentTextNode = Cast<UDialogueTextNode>(CurrentTextNode->ChildrenNodes[Choice]);
CurrentTextNode = Cast<UDialogueTextNode>(CurrentChoiceNode->ChildrenNodes[Choice]);
OnNextDialogue.Broadcast(CurrentTextNode);
CurrentChoiceNode = nullptr;
}
}
void UAC_PlayerDialogueInterpreter::EndDialogue()
{
CurrentChoiceNode = nullptr;
CurrentTextNode = nullptr;
OnEndDialogue.Broadcast();
if (APlayerController* PlayerController = GetWorld()->GetFirstPlayerController())
{
const FInputModeGameAndUI InputModeData;
PlayerController->SetInputMode(InputModeData);
PlayerController->bShowMouseCursor = false;
}
}

View File

@ -24,14 +24,18 @@ public:
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnChoiceDialogue, UDialogueChoiceNode*, ChoiceNode);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnEndDialogue);
UPROPERTY(BlueprintAssignable, Category = "Dialogue")
FOnStartDialogue OnStartDialogue;
UPROPERTY(BlueprintAssignable, Category = "Dialogue")
FOnNextDialogue OnNextDialogue;
UPROPERTY(BlueprintAssignable, Category = "Dialogue")
FOnChoiceDialogue OnChoiceDialogue;
UPROPERTY(BlueprintAssignable, Category = "Dialogue")
FOnEndDialogue OnEndDialogue;
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Dialogue")
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Dialogue")
UDialogueTree* CurrentDialogueTree;
protected:
@ -54,4 +58,6 @@ public:
void NextDialogue();
UFUNCTION(BlueprintCallable, Category = "Dialogue")
void MakeChoiceDialogue(int Choice);
UFUNCTION(BlueprintCallable, Category = "Dialogue")
void EndDialogue();
};

View File

@ -0,0 +1,31 @@
#include "DialogueRootNode.h"
#include "DialogueTree.h"
#define LOCTEXT_NAMESPACE "UDialogueChoiceNode"
UDialogueRootNode::UDialogueRootNode()
{
#if WITH_EDITORONLY_DATA
CompatibleGraphType = UDialogueTree::StaticClass();
ContextMenuName = LOCTEXT("ConextMenuName", "Root Node");
#endif
}
#if WITH_EDITOR
FText UDialogueRootNode::GetNodeTitle() const
{
return LOCTEXT("Root Node", "ROOT");
}
FLinearColor UDialogueRootNode::GetBackgroundColor() const
{
if (const UDialogueTree* DialogueTree = Cast<UDialogueTree>(GetGraph()); DialogueTree == nullptr)
return Super::GetBackgroundColor();
return FLinearColor(1.f, 1.f, 1.f, 1.f);
}
#endif
#undef LOCTEXT_NAMESPACE

View File

@ -0,0 +1,20 @@
#pragma once
#include "CoreMinimal.h"
#include "GenericGraphNode.h"
#include "DialogueRootNode.generated.h"
UCLASS(Blueprintable)
class UDialogueRootNode : public UGenericGraphNode
{
GENERATED_BODY()
public:
UDialogueRootNode();;
#if WITH_EDITOR
virtual FText GetNodeTitle() const override;
virtual FLinearColor GetBackgroundColor() const override;
#endif
};

View File

@ -37,7 +37,6 @@ FText UDialogueTextNode::GetNodeTitle() const
}
}
}
UE_LOG(LogTemp, Warning, TEXT("Wrapped Text: %s"), *WrappedText);
return FText::FromString(WrappedText);
}

View File

@ -14,6 +14,7 @@
#include "GameFramework/MovementComponent.h"
#include "Inventory/InventoryComponent.h"
#include "EndlessVendettaGameMode.h"
#include "DialogueSystem/AC_Dialogue.h"
//////////////////////////////////////////////////////////////////////////
@ -102,7 +103,7 @@ void AEndlessVendettaCharacter::Tick(float DeltaTime)
}
if (bPressedJump)
{
if(CurrentStamina <= 0.0f)
if (CurrentStamina <= 0.0f)
{
CurrentStamina -= 20.0f;
}
@ -123,7 +124,7 @@ void AEndlessVendettaCharacter::Tick(float DeltaTime)
}
if (!bIsPlayerSprinting)
{
if(CurrentStamina >= 100.0f)
if (CurrentStamina >= 100.0f)
{
CurrentStamina = 100.0f;
return;
@ -174,7 +175,7 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
//Jumping
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &ACharacter::Jump);
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
//Moving
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::Move);
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::Sprint);
@ -211,6 +212,11 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
void AEndlessVendettaCharacter::Interact()
{
if (bIsInDialogue)
{
Cast<UAC_PlayerDialogueInterpreter>(GetComponentByClass(UAC_PlayerDialogueInterpreter::StaticClass()))->NextDialogue();
return;
}
if (PlayerOnShip)
{
SpaceShip->PlayerInteracting();
@ -234,6 +240,10 @@ void AEndlessVendettaCharacter::Interact()
UE_LOG(LogTemp, Warning, TEXT("Hit actor: %s"), *HitActor->GetName());
IInteractionInterface* InteractableActor = Cast<IInteractionInterface>(HitActor);
if (InteractableActor) InteractableActor->Interact();
if (UAC_Dialogue* Dialogue = Cast<UAC_Dialogue>(HitActor->GetComponentByClass(UAC_Dialogue::StaticClass())))
{
Dialogue->Interact();
}
}
@ -341,7 +351,7 @@ void AEndlessVendettaCharacter::EquipPrimary()
if (IsValid(PrimaryWeapon))
{
PrimaryWeapon->DetachFromActor(DetatchRules);
PrimaryWeapon->SetActorLocation(FVector(0,0,0), false, nullptr, ETeleportType::None);
PrimaryWeapon->SetActorLocation(FVector(0, 0, 0), false, nullptr, ETeleportType::None);
PrimaryWeapon->SetActorHiddenInGame(true);
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
UE_LOG(LogTemp, Warning, TEXT("Primary Weapon Is Hidden: %hhd"), PrimaryWeapon->IsHidden());
@ -351,7 +361,7 @@ void AEndlessVendettaCharacter::EquipPrimary()
Cast<AEndlessVendettaGameMode>(GetWorld()->GetAuthGameMode())->SendEvent("DeEquip", "Pri");
return;
}
if(bIsWeaponPickedUp)
if (bIsWeaponPickedUp)
{
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
bIsWeaponPickedUp = false;
@ -390,12 +400,12 @@ void AEndlessVendettaCharacter::EquipSecondary()
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
FDetachmentTransformRules DetatchRules(EDetachmentRule::KeepWorld, false);
if (bIsReloading) return;
if (IsValid(SecondaryWeapon))
{
SecondaryWeapon->DetachFromActor(DetatchRules);
SecondaryWeapon->SetActorLocation(FVector(0,0,0), false, nullptr, ETeleportType::None);
SecondaryWeapon->SetActorLocation(FVector(0, 0, 0), false, nullptr, ETeleportType::None);
SecondaryWeapon->SetActorHiddenInGame(true);
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
UE_LOG(LogTemp, Warning, TEXT("Secondary Weapon Is Hidden: %hhd"), SecondaryWeapon->IsHidden());
@ -404,8 +414,8 @@ void AEndlessVendettaCharacter::EquipSecondary()
GLog->Log("Secondary Weapon Put Away");
return;
}
if(bIsWeaponPickedUp)
if (bIsWeaponPickedUp)
{
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
bIsWeaponPickedUp = false;
@ -415,11 +425,11 @@ void AEndlessVendettaCharacter::EquipSecondary()
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;
if(!IsValid(SecondaryWeapon))
if (!IsValid(SecondaryWeapon))
{
bHasRifle = true;
if(!bIsSecondaryWeaponCreated)
if (!bIsSecondaryWeaponCreated)
{
SecondaryWeaponActor = GetWorld()->SpawnActor<AActor>(SecondaryWeaponClass, spawnParams);
SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
@ -438,7 +448,7 @@ void AEndlessVendettaCharacter::EquipSecondary()
void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
{
if(Outhit->ActorHasTag("PrimaryWeapon"))
if (Outhit->ActorHasTag("PrimaryWeapon"))
{
if (IsValid(PrimaryWeapon))
{
@ -449,7 +459,7 @@ void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
Outhit->Destroy();
EquipPrimary();
}
if(Outhit->ActorHasTag("SecondaryWeapon"))
if (Outhit->ActorHasTag("SecondaryWeapon"))
{
if (IsValid(SecondaryWeapon))
{
@ -565,7 +575,7 @@ void AEndlessVendettaCharacter::Move(const FInputActionValue& Value)
SpaceShip->MoveShip(MovementVector);
return;
}
if (Controller != nullptr)
{
// add movement
@ -669,7 +679,7 @@ void AEndlessVendettaCharacter::UpdateInventorySize(int Cols, int Rows)
{
Inventory->UpdateInventorySize(Cols, Rows);
}
else
else
{
UE_LOG(LogTemp, Warning, TEXT("No Vaild Inventory"));
}
@ -690,6 +700,5 @@ void AEndlessVendettaCharacter::ExitShip(FTransform ExitLoc)
SetActorLocation(ExitLoc.GetLocation());
GetController()->SetControlRotation(ExitLoc.Rotator());
SpaceShip->Destroy();
PlayerOnShip = false;
PlayerOnShip = false;
}

View File

@ -26,12 +26,12 @@ UCLASS(config=Game)
class AEndlessVendettaCharacter : public ACharacter
{
GENERATED_BODY()
protected:
/** Pawn mesh: 1st person view (arms; seen only by self) */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Mesh)
USkeletalMeshComponent* Mesh1P;
private:
/** First person camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
@ -95,7 +95,7 @@ public:
//STAMINA AND SPRINT SPEED
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats")
float MaxStamina = 100;
float MaxStamina = 100;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats")
float CurrentStamina;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats")
@ -118,6 +118,9 @@ public:
bool bIsSecondaryWeaponCreated = false;
bool bIsWeaponPickedUp = false;
UPROPERTY(BlueprintReadWrite)
bool bIsInDialogue = false;
protected:
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
@ -217,7 +220,6 @@ protected:
void Interact();
protected:
// Used by vault it plugin to run vaulting animations
USkeletalMeshComponent* FP_SkeletalMesh = nullptr;
@ -226,8 +228,6 @@ protected:
// End of APawn interface
public:
UFUNCTION(BlueprintCallable, Category = "Stealth")
void SetCrouch();
UFUNCTION(BlueprintCallable, Category = "Stealth")
@ -264,7 +264,8 @@ private:
UPROPERTY(EditDefaultsOnly, Category = "Space Ship")
TSubclassOf<ASpaceShip> SpaceShipClass;
ASpaceShip* SpaceShip;
public:
public:
void ExitShip(FTransform ExitLoc);
void EnterShip(FTransform TakeoffLoc);
};