From 18ceedfa03079992646c57e4f057aec7b7ab63b0 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Mon, 24 Apr 2023 18:01:51 +0100 Subject: [PATCH] Updated Character to Convert Screen Space to World for Interaction --- Content/Blueprints/Combat_UI/BookCombat_UI.uasset | 4 ++-- Content/Blueprints/Combat_UI/BookWorldWidget.uasset | 4 ++-- Content/Blueprints/Combat_UI/CombatCharacter.uasset | 4 ++-- Content/Blueprints/Combat_UI/CombatTutorial.uasset | 4 ++-- .../the_twilight_abyss/PlayerTemp/TempCharacter.cpp | 11 +++++++++++ Source/the_twilight_abyss/PlayerTemp/TempCharacter.h | 8 ++++++++ .../TurnBasedCombatV2/TurnBaseCombatV2.cpp | 6 +++++- .../TurnBasedCombatV2/TurnBaseCombatV2.h | 2 ++ 8 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Content/Blueprints/Combat_UI/BookCombat_UI.uasset b/Content/Blueprints/Combat_UI/BookCombat_UI.uasset index b5dd3bc..2a821b7 100644 --- a/Content/Blueprints/Combat_UI/BookCombat_UI.uasset +++ b/Content/Blueprints/Combat_UI/BookCombat_UI.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:24239f11123eae1d8dfb8b8c91123a03047dd09ca6f9dc374f22257fe05209ad -size 79303 +oid sha256:5300666477d0304bccf1ca8e12806a2d06ce5e1d3337076b921735b4245aa2a0 +size 91639 diff --git a/Content/Blueprints/Combat_UI/BookWorldWidget.uasset b/Content/Blueprints/Combat_UI/BookWorldWidget.uasset index 27542e5..218e2d7 100644 --- a/Content/Blueprints/Combat_UI/BookWorldWidget.uasset +++ b/Content/Blueprints/Combat_UI/BookWorldWidget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:df5d8b3aeb9cd7bcbe0d78c90f2a7278f6133c89b58600fee8e8f7b63f7dcbda -size 23477 +oid sha256:6aea2b49abbfdd1ac0da1147e3419e5f6410fa4e940075c7e56262d90c703fb2 +size 23653 diff --git a/Content/Blueprints/Combat_UI/CombatCharacter.uasset b/Content/Blueprints/Combat_UI/CombatCharacter.uasset index d1994e4..da92e03 100644 --- a/Content/Blueprints/Combat_UI/CombatCharacter.uasset +++ b/Content/Blueprints/Combat_UI/CombatCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7f5c422149980fd84aae6d5e3c93acb836034a66de360907cfedbc5b9384ce77 -size 129743 +oid sha256:2324577c80acdf9a2bad2b0923dabf42f580b80b6e391aa2f44aeaf528b57fe5 +size 131883 diff --git a/Content/Blueprints/Combat_UI/CombatTutorial.uasset b/Content/Blueprints/Combat_UI/CombatTutorial.uasset index 4d5595b..72bdb4a 100644 --- a/Content/Blueprints/Combat_UI/CombatTutorial.uasset +++ b/Content/Blueprints/Combat_UI/CombatTutorial.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:105769fa75c92ede5d6755984d7e6ab2bb8a06f64de788b296dd59752966dab7 -size 59828 +oid sha256:4b4aab87269ca504b3c501ffc37ba58bcffa14975659fa61a31239fc365a0f1d +size 59827 diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index b2aeee5..c102921 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -28,6 +28,10 @@ ATempCharacter::ATempCharacter() void ATempCharacter::BeginPlay() { Super::BeginPlay(); + + FirstPlayerController = GetWorld()->GetFirstPlayerController(); + WidgetPointer = Cast(this->GetComponentByClass(UWidgetInteractionComponent::StaticClass())); + Health = 100; ThisCamera = Cast(this->FindComponentByClass()); PlayerCapsule = GetCapsuleComponent(); @@ -93,6 +97,13 @@ void ATempCharacter::Sneak() void ATempCharacter::Tick(float DeltaTime) { Super::Tick(DeltaTime); + if (CombatSystem->bIsInCombat) + { + FVector VectorRotation; + FVector WidgetLocation; + FirstPlayerController->DeprojectMousePositionToWorld(WidgetLocation, VectorRotation); + WidgetPointer->SetWorldLocationAndRotation(WidgetLocation, VectorRotation.Rotation().Quaternion()); + } } // Gives the character the functionality diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index 64b95b0..06d50f0 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -7,6 +7,8 @@ #include "the_twilight_abyss/BaseItems/Items/BaseItem.h" #include "Camera/CameraComponent.h" #include "Engine/PostProcessVolume.h" +#include "Components/WidgetInteractionComponent.h" +#include "../TurnBasedCombatV2/TurnBaseCombatV2.h" #include "TempCharacter.generated.h" UCLASS() @@ -29,6 +31,12 @@ protected: void Sneak(); UCapsuleComponent* PlayerCapsule; + UPROPERTY() + APlayerController* FirstPlayerController; + UPROPERTY() + UWidgetInteractionComponent* WidgetPointer; + UPROPERTY() + ATurnBaseCombatV2* CombatSystem; public: // Called every frame diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp index 4e257fb..bd39e85 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp @@ -36,6 +36,7 @@ ATurnBaseCombatV2::ATurnBaseCombatV2() void ATurnBaseCombatV2::StartCombat(AActor* Enemy) { if (Enemy == nullptr) return; + bIsInCombat = true; UBlackboardComponent* EnemyBlackboard = Cast(Enemy->GetInstigatorController())->GetBlackboardComponent(); if (!HasSeenTutorial) { @@ -62,7 +63,7 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy) } if (HUD->IsInViewport()) return; - HUD->AddToViewport(); + //HUD->AddToViewport(); EnemyActor = Enemy; ProbertiumResource = 10; @@ -77,6 +78,7 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy) } //Set to UI Mode Only APlayerController* PlayerController = GetWorld()->GetFirstPlayerController(); + PlayerController->SetInputMode(FInputModeUIOnly()); PlayerController->bShowMouseCursor = true; @@ -100,6 +102,7 @@ void ATurnBaseCombatV2::EndCombat() { bEnemyHasExtraTurn = false; bPlayerHasExtraTurn = false; + bIsInCombat = false; for (UStatusEffect* StatusEffect : StatusEffects) { StatusEffect->OnExpiry(PlayerActor); @@ -516,3 +519,4 @@ void ATurnBaseCombatV2::EnemyTurn() TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn")); ToggleButtons(); } + diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h index 7a9ca72..962c0f6 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h @@ -26,6 +26,8 @@ public: int* EnemyHealth = nullptr; float* PlayerHealth = nullptr; + bool bIsInCombat = false; + UPROPERTY(EditDefaultsOnly) int DefaultActionPoints = 2; UPROPERTY(EditDefaultsOnly)