diff --git a/Content/Blueprints/Merchant/Merchant_UI/BP_OPENDIAL.uasset b/Content/Blueprints/Merchant/Merchant_UI/BP_OPENDIAL.uasset index cb0fa3a..239df23 100644 --- a/Content/Blueprints/Merchant/Merchant_UI/BP_OPENDIAL.uasset +++ b/Content/Blueprints/Merchant/Merchant_UI/BP_OPENDIAL.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5aba7e76546797d974d8c1fbb2f989416f27912dbd289acc8c16a5bc5b25eefd -size 70965 +oid sha256:dd57bdf81793aa6f3b76784e3be306fef5ca81c5e2fa7065a29abadd420c4e0b +size 75420 diff --git a/Content/Blueprints/Merchant/Merchant_UI/BP_ShopSelector.uasset b/Content/Blueprints/Merchant/Merchant_UI/BP_ShopSelector.uasset index 0c71209..0c1f862 100644 --- a/Content/Blueprints/Merchant/Merchant_UI/BP_ShopSelector.uasset +++ b/Content/Blueprints/Merchant/Merchant_UI/BP_ShopSelector.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:22b2132cd76cdc49d851a897a8295bac996dd4b048ee16722f3747a0b0a0fd42 -size 68094 +oid sha256:0fe126443f981aa1875e8efe299d76c4f0f570aff93f9313cc9503bb811365a5 +size 51324 diff --git a/Content/Blueprints/Merchant/Merchant_UI/WBP_BuyBuff.uasset b/Content/Blueprints/Merchant/Merchant_UI/WBP_BuyBuff.uasset index 3d3b44f..7eecebb 100644 --- a/Content/Blueprints/Merchant/Merchant_UI/WBP_BuyBuff.uasset +++ b/Content/Blueprints/Merchant/Merchant_UI/WBP_BuyBuff.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8cc4e9151595d71a12c6f44c47b8f62ebb2687944cc124a6927fb8cddcf6a1fc -size 51431 +oid sha256:abe53946825159c2220acd237c3cc7360478b63836d52e3cbe000876e43eb5d5 +size 63822 diff --git a/Content/Blueprints/Merchant/Merchant_UI/WBP_BuyHealing.uasset b/Content/Blueprints/Merchant/Merchant_UI/WBP_BuyHealing.uasset index 5420305..8e7650a 100644 --- a/Content/Blueprints/Merchant/Merchant_UI/WBP_BuyHealing.uasset +++ b/Content/Blueprints/Merchant/Merchant_UI/WBP_BuyHealing.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4f15b92c944a3038b636058b7f8fb3a6573a2ec271c3a6a1670bb5b9541c9d7c -size 52018 +oid sha256:936f77df55a4f4c1baca361f8ca9384f1af821ab6c0e8c9b016a3ede25c9f8d1 +size 63821 diff --git a/Content/Blueprints/Player/BP_MyTempCharacter.uasset b/Content/Blueprints/Player/BP_MyTempCharacter.uasset index 3cd68ed..f1f038b 100644 --- a/Content/Blueprints/Player/BP_MyTempCharacter.uasset +++ b/Content/Blueprints/Player/BP_MyTempCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:48787fb18ad9d51b32e5b837c8c1605b11d1b60014c75f2efa1ab910d621415b -size 56881 +oid sha256:be58819ba52b5638a31c272d4b3d2b93cfd6c75d2ad1717183b971c1c9d78234 +size 54639 diff --git a/Content/Levels/MerchantPrototype.umap b/Content/Levels/MerchantPrototype.umap index 7daa7d9..ea85903 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:0ffba42fc8f6527bb83238b65ee72d5d2de2589f1d1bc825c23c5d86fc732889 -size 27144 +oid sha256:838c48c134383d4b1db178233640e11ef2c4bcd49102f53648cf621dd1dcbf8a +size 27100 diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp index 192d23c..beaad39 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp @@ -9,6 +9,7 @@ #include "GameFramework/Character.h" #include "Components/WidgetComponent.h" #include "Kismet/KismetMathLibrary.h" +#include "the_twilight_abyss/PlayerTemp/TempCharacter.h" // Sets default values @@ -23,6 +24,40 @@ void AInteraction::BeginPlay() { Super::BeginPlay(); + //Character & Camera refs + TempCharacterRef = Cast(GetWorld()->GetFirstPlayerController()->GetCharacter()); + MainCamera = Cast(TempCharacterRef->FindComponentByClass()); + //Item refs + + TargetHealingLocation = HealingItem->GetActorLocation(); + TargetBuffLocation = BuffItem->GetActorLocation(); + + // Dialog refs + + ShopDialogWidget = CreateWidget(GetWorld(), ShopDialog); + ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden); + ShopDialogWidget->AddToViewport(); + + //Item Selector refs + ItemSelectorWidget = CreateWidget(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(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(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 @@ -35,14 +70,17 @@ void AInteraction::Tick(float DeltaTime) void AInteraction::OnInteract() { bDisableShopDialMove = true; - ShopDialogWidget = CreateWidget(GetWorld(), ShopDialog); if (ShopDialogWidget == nullptr) { + UE_LOG(LogTemp, Display, TEXT("ShopDialogWidget is null")); return; } 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 FTimerHandle WidgetTimer; @@ -53,13 +91,22 @@ void AInteraction::OnInteract() void AInteraction::RemoveWidget() { 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")); - ItemSelectorWidget = CreateWidget(GetWorld(), ItemSelector); - FProperty* Property = ItemSelectorWidget->GetClass()->FindPropertyByName("publicActor"); + if (Property == nullptr) { UE_LOG(LogTemp, Error, TEXT("Property not found")); + return; } else { @@ -72,7 +119,7 @@ void AInteraction::RemoveWidget() } else { - ItemSelectorWidget->AddToViewport(0); + ItemSelectorWidget->SetVisibility(ESlateVisibility::Visible); bisDisabled = false; } } @@ -80,9 +127,7 @@ void AInteraction::RemoveWidget() void AInteraction::CameraLeftMover() { UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed")); - TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); - MainCamera = Cast(TempCharacter->FindComponentByClass()); - if (TempCharacter == nullptr) + if (TempCharacterRef == nullptr || BuyHealingProperty == nullptr) { UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); return; @@ -90,18 +135,21 @@ void AInteraction::CameraLeftMover() else { 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")); return; } else { - FVector TargetLocation = FVector(5700,-1270,4040); - FVector CameraLocation = MainCamera->GetComponentLocation(); - FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation); + FObjectPropertyBase* ObjectProperty = static_cast(BuyHealingProperty); + ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr(BuyHealingTextWidget), this); + + CameraLocation = MainCamera->GetComponentLocation(); + FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation); MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetFieldOfView(40); + BuyHealingTextWidget->SetVisibility(ESlateVisibility::Visible); } } } @@ -109,9 +157,7 @@ void AInteraction::CameraLeftMover() void AInteraction::CameraRightMover() { UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed")); - TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); - MainCamera = Cast(TempCharacter->FindComponentByClass()); - if (TempCharacter == nullptr) + if (TempCharacterRef == nullptr || BuyBuffProperty == nullptr) { UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); return; @@ -119,18 +165,45 @@ void AInteraction::CameraRightMover() else { 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")); return; } else { - FVector TargetLocation = FVector(5260, -840, 4070); - FVector CameraLocation = MainCamera->GetComponentLocation(); - FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation); + FObjectPropertyBase* ObjectProperty = static_cast(BuyBuffProperty); + ObjectProperty->SetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr(BuyBuffTextWidget), this); + + CameraLocation = MainCamera->GetComponentLocation(); + FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation); MainCamera->SetWorldRotation(CameraRotation); 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); + } +} + + + + diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h index fb771a9..76af4db 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h @@ -5,6 +5,7 @@ #include "CoreMinimal.h" #include "Camera/CameraComponent.h" #include "GameFramework/Actor.h" +#include "the_twilight_abyss/PlayerTemp/TempCharacter.h" #include "Interaction.generated.h" UCLASS() @@ -24,12 +25,18 @@ public: // Called every frame virtual void Tick(float DeltaTime) override; - UPROPERTY(EditAnywhere) + UPROPERTY(EditAnywhere, Category= "Widgets") TSubclassOf ShopDialog; - UPROPERTY(EditAnywhere) + UPROPERTY(EditAnywhere, Category= "Widgets") TSubclassOf ItemSelector; + UPROPERTY(EditAnywhere, Category = "Widgets") + TSubclassOf BuyBuffText; + + UPROPERTY(EditAnywhere, Category = "Widgets") + TSubclassOf BuyHealingText; + virtual void OnInteract(); virtual void RemoveWidget(); @@ -39,8 +46,14 @@ public: UPROPERTY() UUserWidget* ItemSelectorWidget; + + UPROPERTY() + UUserWidget* BuyBuffTextWidget; - UPROPERTY(EditAnywhere) + UPROPERTY() + UUserWidget* BuyHealingTextWidget; + + UPROPERTY(EditAnywhere, Category= "Widgets") float WaitTimer = 8.0f; UPROPERTY() @@ -48,6 +61,7 @@ public: UPROPERTY() bool bDisableShopDialMove = false; + UFUNCTION(BlueprintCallable, Category= "ButtonLeft") virtual void CameraLeftMover(); @@ -58,7 +72,29 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera") UCameraComponent* MainCamera; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player") - ACharacter* TempCharacter; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items") + 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; }; diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index 50029de..bfdfe06 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -101,18 +101,35 @@ void ATempCharacter::LineTraceLogic() if (AInteraction* MyInteractable = Cast(OutHit.GetActor())) { - 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->ShopDialogWidget->IsVisible()) { - 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(); - break; + return; + } + 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() { UE_LOG(LogTemp, Display, TEXT("Disabling playermovement")); + //GetWorld()->GetFirstPlayerController()->InputComponent->RemoveActionBinding("Interact", IE_Pressed); GetWorld()->GetFirstPlayerController()->SetIgnoreLookInput(true); GetWorld()->GetFirstPlayerController()->SetIgnoreMoveInput(true); GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true; @@ -150,6 +168,7 @@ void ATempCharacter::InputEnabler() GetWorld()->GetFirstPlayerController()->bShowMouseCursor = false; GetWorld()->GetFirstPlayerController()->bEnableClickEvents = false; GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = false; + //GetWorld()->GetFirstPlayerController()->InputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed); TraceDistance = 300; ThisCamera = Cast(this->FindComponentByClass()); if (ThisCamera == nullptr) @@ -161,7 +180,6 @@ void ATempCharacter::InputEnabler() ThisCamera->SetWorldLocation(OriginalCameraLocation); ThisCamera->SetWorldRotation(OriginalCameraRotation); ThisCamera->FieldOfView = OriginalCameraFOV; - //ulog the originalcameralocation value UE_LOG(LogTemp, Display, TEXT("Original Camera Location: %s"), *OriginalCameraLocation.ToString()); } diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index 052239c..928b8df 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -31,7 +31,10 @@ public: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = "true")) class UInventoryComponent* Inventory; //Using the InventoryComponent class - + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets") + UUserWidget* ItemSelectorWidget; + // Called to bind functionality to input virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; @@ -43,6 +46,8 @@ public: void InputDisabler(); void LineTraceLogic(); + + UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health") float Health; @@ -70,5 +75,7 @@ public: UFUNCTION(BlueprintCallable, Category= "Items") void BuyItem(); + + bool bShopKeeperText = false; };