Merge remote-tracking branch 'origin/merchant-system-v4' into Turn-Based-Combat

# Conflicts:
#	Content/Blueprints/Combat_UI/CombatCharacter.uasset
This commit is contained in:
Philip W 2023-01-31 00:50:59 +00:00
commit 7e81387247
10 changed files with 183 additions and 49 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

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

Binary file not shown.

View File

@ -9,6 +9,7 @@
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
#include "Components/WidgetComponent.h" #include "Components/WidgetComponent.h"
#include "Kismet/KismetMathLibrary.h" #include "Kismet/KismetMathLibrary.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
// Sets default values // Sets default values
@ -23,6 +24,40 @@ void AInteraction::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
//Character & Camera refs
TempCharacterRef = Cast<ATempCharacter>(GetWorld()->GetFirstPlayerController()->GetCharacter());
MainCamera = Cast<UCameraComponent>(TempCharacterRef->FindComponentByClass<UCameraComponent>());
//Item refs
TargetHealingLocation = HealingItem->GetActorLocation();
TargetBuffLocation = BuffItem->GetActorLocation();
// Dialog refs
ShopDialogWidget = CreateWidget<UUserWidget>(GetWorld(), ShopDialog);
ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden);
ShopDialogWidget->AddToViewport();
//Item Selector refs
ItemSelectorWidget = CreateWidget<UUserWidget>(GetWorld(), ItemSelector);
ItemSelectorWidget->SetVisibility(ESlateVisibility::Hidden);
ItemSelectorWidget->AddToViewport();
//We are getting the property of interaction since we need a reference for when we cast in BP and we need the reference to be self
Property = ItemSelectorWidget->GetClass()->FindPropertyByName("publicActor");
//Confirm Buy refs
BuyBuffTextWidget = CreateWidget<UUserWidget>(GetWorld(), BuyBuffText);
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Hidden);
BuyBuffTextWidget->AddToViewport();
//We are getting the property of interaction since we need a reference for when we cast in BP and we need the reference to be self
BuyBuffProperty = BuyBuffTextWidget->GetClass()->FindPropertyByName("publicActor");
BuyHealingTextWidget = CreateWidget<UUserWidget>(GetWorld(), BuyHealingText);
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Hidden);
BuyHealingTextWidget->AddToViewport();
//We are getting the property of interaction since we need a reference for when we cast in BP and we need the reference to be self
BuyHealingProperty = BuyHealingTextWidget->GetClass()->FindPropertyByName("publicActor");
} }
// Called every frame // Called every frame
@ -35,14 +70,17 @@ void AInteraction::Tick(float DeltaTime)
void AInteraction::OnInteract() void AInteraction::OnInteract()
{ {
bDisableShopDialMove = true; bDisableShopDialMove = true;
ShopDialogWidget = CreateWidget<UUserWidget>(GetWorld(), ShopDialog);
if (ShopDialogWidget == nullptr) if (ShopDialogWidget == nullptr)
{ {
UE_LOG(LogTemp, Display, TEXT("ShopDialogWidget is null"));
return; return;
} }
else else
{ {
ShopDialogWidget->AddToViewport(0); //Shop Widget to visible
ShopDialogWidget->SetVisibility(ESlateVisibility::Visible);
//Call a custom event in a blueprint called "PlayText"
ShopDialogWidget->CallFunctionByNameWithArguments(TEXT("PlayText"), *GLog, nullptr, true);
} }
//handles the widget disappearing from the viewport //handles the widget disappearing from the viewport
FTimerHandle WidgetTimer; FTimerHandle WidgetTimer;
@ -53,13 +91,22 @@ void AInteraction::OnInteract()
void AInteraction::RemoveWidget() void AInteraction::RemoveWidget()
{ {
bisDisabled = true; bisDisabled = true;
ShopDialogWidget->RemoveFromViewport(); //Setting ShopWidgetText back to hidden
ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden);
if (ShopDialogWidget->IsVisible())
{
return;
}
else
{
UE_LOG(LogTemp, Display, TEXT("You cant open this widget when this widget is open"));
}
UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true")); UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true"));
ItemSelectorWidget = CreateWidget<UUserWidget>(GetWorld(), ItemSelector);
FProperty* Property = ItemSelectorWidget->GetClass()->FindPropertyByName("publicActor");
if (Property == nullptr) if (Property == nullptr)
{ {
UE_LOG(LogTemp, Error, TEXT("Property not found")); UE_LOG(LogTemp, Error, TEXT("Property not found"));
return;
} }
else else
{ {
@ -72,7 +119,7 @@ void AInteraction::RemoveWidget()
} }
else else
{ {
ItemSelectorWidget->AddToViewport(0); ItemSelectorWidget->SetVisibility(ESlateVisibility::Visible);
bisDisabled = false; bisDisabled = false;
} }
} }
@ -80,9 +127,7 @@ void AInteraction::RemoveWidget()
void AInteraction::CameraLeftMover() void AInteraction::CameraLeftMover()
{ {
UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed")); UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed"));
TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); if (TempCharacterRef == nullptr || BuyHealingProperty == nullptr)
MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
if (TempCharacter == nullptr)
{ {
UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
return; return;
@ -90,18 +135,21 @@ void AInteraction::CameraLeftMover()
else else
{ {
UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp")); UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
if (MainCamera == nullptr) if (MainCamera == nullptr || HealingItem == nullptr)
{ {
UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp")); UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
return; return;
} }
else else
{ {
FVector TargetLocation = FVector(5700,-1270,4040); FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(BuyHealingProperty);
FVector CameraLocation = MainCamera->GetComponentLocation(); ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(BuyHealingTextWidget), this);
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation);
CameraLocation = MainCamera->GetComponentLocation();
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation);
MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetWorldRotation(CameraRotation);
MainCamera->SetFieldOfView(40); MainCamera->SetFieldOfView(40);
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Visible);
} }
} }
} }
@ -109,9 +157,7 @@ void AInteraction::CameraLeftMover()
void AInteraction::CameraRightMover() void AInteraction::CameraRightMover()
{ {
UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed")); UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed"));
TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); if (TempCharacterRef == nullptr || BuyBuffProperty == nullptr)
MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
if (TempCharacter == nullptr)
{ {
UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
return; return;
@ -119,18 +165,45 @@ void AInteraction::CameraRightMover()
else else
{ {
UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp")); UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
if (MainCamera == nullptr) if (MainCamera == nullptr || BuffItem == nullptr)
{ {
UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp")); UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
return; return;
} }
else else
{ {
FVector TargetLocation = FVector(5260, -840, 4070); FObjectPropertyBase* ObjectProperty = static_cast<FObjectPropertyBase*>(BuyBuffProperty);
FVector CameraLocation = MainCamera->GetComponentLocation(); ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<void>(BuyBuffTextWidget), this);
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation);
CameraLocation = MainCamera->GetComponentLocation();
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation);
MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetWorldRotation(CameraRotation);
MainCamera->SetFieldOfView(40); MainCamera->SetFieldOfView(40);
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Visible);
} }
} }
} }
void AInteraction::CancelPurchase()
{
BuyBuffTextWidget->SetVisibility(ESlateVisibility::Hidden);
BuyHealingTextWidget->SetVisibility(ESlateVisibility::Hidden);
}
void AInteraction::ExitScreen()
{
if (TempCharacterRef == nullptr)
{
UE_LOG(LogTemp, Display, TEXT("TempCharacterRef in Interaction.cpp not found"));
return;
}
else
{
TempCharacterRef->InputEnabler();
ItemSelectorWidget->SetVisibility(ESlateVisibility::Hidden);
}
}

View File

@ -5,6 +5,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Camera/CameraComponent.h" #include "Camera/CameraComponent.h"
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
#include "Interaction.generated.h" #include "Interaction.generated.h"
UCLASS() UCLASS()
@ -24,12 +25,18 @@ public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere, Category= "Widgets")
TSubclassOf<UUserWidget> ShopDialog; TSubclassOf<UUserWidget> ShopDialog;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere, Category= "Widgets")
TSubclassOf<UUserWidget> ItemSelector; TSubclassOf<UUserWidget> ItemSelector;
UPROPERTY(EditAnywhere, Category = "Widgets")
TSubclassOf<UUserWidget> BuyBuffText;
UPROPERTY(EditAnywhere, Category = "Widgets")
TSubclassOf<UUserWidget> BuyHealingText;
virtual void OnInteract(); virtual void OnInteract();
virtual void RemoveWidget(); virtual void RemoveWidget();
@ -40,7 +47,13 @@ public:
UPROPERTY() UPROPERTY()
UUserWidget* ItemSelectorWidget; UUserWidget* ItemSelectorWidget;
UPROPERTY(EditAnywhere) UPROPERTY()
UUserWidget* BuyBuffTextWidget;
UPROPERTY()
UUserWidget* BuyHealingTextWidget;
UPROPERTY(EditAnywhere, Category= "Widgets")
float WaitTimer = 8.0f; float WaitTimer = 8.0f;
UPROPERTY() UPROPERTY()
@ -49,6 +62,7 @@ public:
UPROPERTY() UPROPERTY()
bool bDisableShopDialMove = false; bool bDisableShopDialMove = false;
UFUNCTION(BlueprintCallable, Category= "ButtonLeft") UFUNCTION(BlueprintCallable, Category= "ButtonLeft")
virtual void CameraLeftMover(); virtual void CameraLeftMover();
@ -58,7 +72,29 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
UCameraComponent* MainCamera; UCameraComponent* MainCamera;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items")
ACharacter* TempCharacter; AActor* HealingItem;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items")
AActor* BuffItem;
UFUNCTION(BlueprintCallable, Category = "ConfirmButtons")
virtual void CancelPurchase();
UFUNCTION(BlueprintCallable, Category = "ConfirmButtons")
virtual void ExitScreen();
UPROPERTY(EditAnywhere, Category = "Player")
ATempCharacter* TempCharacterRef;
private:
FVector TargetHealingLocation;
FVector TargetBuffLocation;
FVector CameraLocation;
FProperty* Property;
FProperty* BuyBuffProperty;
FProperty* BuyHealingProperty;
}; };

View File

@ -101,18 +101,35 @@ void ATempCharacter::LineTraceLogic()
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor())) if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
{ {
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f); if (MyInteractable->ShopDialogWidget->IsVisible())
MyInteractable->OnInteract();
UE_LOG(LogTemp, Display, TEXT("OnInteract activated"));
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
// While loop to check bisDisabled var until it changes to true
while (MyInteractable->bisDisabled == false || MyInteractable->bDisableShopDialMove == false)
{ {
if (MyInteractable->bisDisabled == true || MyInteractable->bDisableShopDialMove == true) UE_LOG(LogTemp, Display, TEXT("ShopKeeper text is visible"));
bShopKeeperText = true;
return;
}
//if there is no text on screen this triggers
else
{
if (MyInteractable->ItemSelectorWidget->IsVisible())
{ {
InputDisabler(); return;
break; }
else
{
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
MyInteractable->OnInteract();
UE_LOG(LogTemp, Display, TEXT("OnInteract activated"));
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
// While loop to check bisDisabled var until it changes to true
while (MyInteractable->bisDisabled == false || MyInteractable->bDisableShopDialMove == false)
{
if (MyInteractable->bisDisabled == true || MyInteractable->bDisableShopDialMove == true)
{
InputDisabler();
break;
}
}
} }
} }
} }
@ -122,6 +139,7 @@ void ATempCharacter::LineTraceLogic()
void ATempCharacter::InputDisabler() void ATempCharacter::InputDisabler()
{ {
UE_LOG(LogTemp, Display, TEXT("Disabling playermovement")); UE_LOG(LogTemp, Display, TEXT("Disabling playermovement"));
//GetWorld()->GetFirstPlayerController()->InputComponent->RemoveActionBinding("Interact", IE_Pressed);
GetWorld()->GetFirstPlayerController()->SetIgnoreLookInput(true); GetWorld()->GetFirstPlayerController()->SetIgnoreLookInput(true);
GetWorld()->GetFirstPlayerController()->SetIgnoreMoveInput(true); GetWorld()->GetFirstPlayerController()->SetIgnoreMoveInput(true);
GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true; GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true;
@ -150,6 +168,7 @@ void ATempCharacter::InputEnabler()
GetWorld()->GetFirstPlayerController()->bShowMouseCursor = false; GetWorld()->GetFirstPlayerController()->bShowMouseCursor = false;
GetWorld()->GetFirstPlayerController()->bEnableClickEvents = false; GetWorld()->GetFirstPlayerController()->bEnableClickEvents = false;
GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = false; GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = false;
//GetWorld()->GetFirstPlayerController()->InputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed);
TraceDistance = 300; TraceDistance = 300;
ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>()); ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
if (ThisCamera == nullptr) if (ThisCamera == nullptr)
@ -161,7 +180,6 @@ void ATempCharacter::InputEnabler()
ThisCamera->SetWorldLocation(OriginalCameraLocation); ThisCamera->SetWorldLocation(OriginalCameraLocation);
ThisCamera->SetWorldRotation(OriginalCameraRotation); ThisCamera->SetWorldRotation(OriginalCameraRotation);
ThisCamera->FieldOfView = OriginalCameraFOV; ThisCamera->FieldOfView = OriginalCameraFOV;
//ulog the originalcameralocation value //ulog the originalcameralocation value
UE_LOG(LogTemp, Display, TEXT("Original Camera Location: %s"), *OriginalCameraLocation.ToString()); UE_LOG(LogTemp, Display, TEXT("Original Camera Location: %s"), *OriginalCameraLocation.ToString());
} }

View File

@ -32,6 +32,9 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = "true")) UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = "true"))
class UInventoryComponent* Inventory; //Using the InventoryComponent class class UInventoryComponent* Inventory; //Using the InventoryComponent class
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
UUserWidget* ItemSelectorWidget;
// Called to bind functionality to input // Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
@ -43,6 +46,8 @@ public:
void InputDisabler(); void InputDisabler();
void LineTraceLogic(); void LineTraceLogic();
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health") UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health")
float Health; float Health;
@ -71,4 +76,6 @@ public:
UFUNCTION(BlueprintCallable, Category= "Items") UFUNCTION(BlueprintCallable, Category= "Items")
void BuyItem(); void BuyItem();
bool bShopKeeperText = false;
}; };