From d17ba9e06407199181f9d5badf3d6d65d58d9d76 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Sun, 21 May 2023 18:55:22 +0100 Subject: [PATCH] Updated Cursor for Change when Hovering on Interactable Object --- .../Blueprints/Display_UI/BP_CrossHair.uasset | 4 +- .../Display_UI/InteracableIcon.uasset | 3 ++ .../Dialogue/DialogueNPC.cpp | 10 +++-- .../PlayerTemp/TempCharacter.cpp | 42 ++++++++++++++++++- .../PlayerTemp/TempCharacter.h | 7 ++++ UI designs/hand-pointer-icon.png | 3 ++ the_twilight_abyss.uproject.DotSettings | 1 + 7 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 Content/Blueprints/Display_UI/InteracableIcon.uasset create mode 100644 UI designs/hand-pointer-icon.png diff --git a/Content/Blueprints/Display_UI/BP_CrossHair.uasset b/Content/Blueprints/Display_UI/BP_CrossHair.uasset index b5491ab..fc30de8 100644 --- a/Content/Blueprints/Display_UI/BP_CrossHair.uasset +++ b/Content/Blueprints/Display_UI/BP_CrossHair.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ed30c2313ba163a846fe0055fb38d1d6d0075bff1fa3a10d6be868c18a0d25f2 -size 24454 +oid sha256:93e1a7a630f0c086d791fa37a3a7c4fbeb1b8fc550f86f514987a471954bad89 +size 24938 diff --git a/Content/Blueprints/Display_UI/InteracableIcon.uasset b/Content/Blueprints/Display_UI/InteracableIcon.uasset new file mode 100644 index 0000000..969ca28 --- /dev/null +++ b/Content/Blueprints/Display_UI/InteracableIcon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1785d25ee677ecdfc395a7dcd7d8763984e4f3c023b9324b2a16e543a013180 +size 34736 diff --git a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp index e0b82ad..dea1a9c 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp @@ -143,14 +143,17 @@ void UDialogueNPC::TickComponent(float DeltaTime, ELevelTick TickType, FActorCom void UDialogueNPC::StartDialogue() { Cast(GetWorld()->GetFirstPlayerController()->GetPawn())->bIsInDialogue = true; - Cast(GetWorld()->GetFirstPlayerController()->GetPawn())->InventoryWidget->SetVisibility(ESlateVisibility::Hidden); - Cast(GetWorld()->GetFirstPlayerController()->GetPawn())->EscapeMenuWidget->SetVisibility(ESlateVisibility::Hidden); + FOutputDeviceNull AR; + const FString Command333 = FString::Printf(TEXT("CloseInventory")); + GetWorld()->GetFirstPlayerController()->GetPawn()->CallFunctionByNameWithArguments(*Command333, AR, nullptr, true); + const FString Command69 = FString::Printf(TEXT("CloseEscapeMenu")); + GetWorld()->GetFirstPlayerController()->GetPawn()->CallFunctionByNameWithArguments(*Command69, AR, nullptr, true); + Cast(GetWorld()->GetFirstPlayerController()->GetPawn())->CrossHairWidget->SetVisibility(ESlateVisibility::Hidden); bIsInDialogue = true; Quests.Empty(); BlueprintFunctions.Empty(); ItemIndexes.Empty(); QuestFlags.Empty(); - FOutputDeviceNull AR; const FString Command = FString::Printf(TEXT("SetRootDialoguePath")); GetOwner()->CallFunctionByNameWithArguments(*Command, AR, nullptr, true); if (IsValid(RootDialoguePath)) CurrentDialogueStringPath = RootDialoguePath->Dialogue; @@ -195,6 +198,7 @@ void UDialogueNPC::EndDialogue() PlayerController->SetIgnoreLookInput(false); PlayerController->SetInputMode(FInputModeGameOnly()); PlayerController->bShowMouseCursor = false; + Cast(GetWorld()->GetFirstPlayerController()->GetPawn())->CrossHairWidget->SetVisibility(ESlateVisibility::HitTestInvisible); } } diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index c24d8ec..211deb3 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -9,6 +9,7 @@ #include "the_twilight_abyss/MerchantInteraction/Interaction.h" #include #include "Components/PawnNoiseEmitterComponent.h" +#include "Blueprint/WidgetBlueprintLibrary.h" #include "Kismet/KismetMathLibrary.h" @@ -20,6 +21,11 @@ ATempCharacter::ATempCharacter() Inventory = CreateDefaultSubobject("Inventory"); Inventory->MaxItemSlots = 10; this->GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true; + + if (static ConstructorHelpers::FObjectFinder CrossHairTexture(TEXT("Texture2D'/Game/Blueprints/Display_UI/InteracableIcon.InteracableIcon'")); IsValid(CrossHairTexture.Object)) + { + InteractableCrossHair = CrossHairTexture.Object; + } } // Called when the game starts or when spawned @@ -48,6 +54,7 @@ void ATempCharacter::BeginPlay() //Widget Refs CrossHairWidget = CreateWidget(GetWorld(), CrossHairSub); CrossHairWidget->SetVisibility(ESlateVisibility::Visible); + CrossHair = Cast(CrossHairWidget->GetWidgetFromName(TEXT("Crosshair"))); CrossHairWidget->AddToViewport(); InventoryWidget = CreateWidget(GetWorld(), InventoryMenuSub); @@ -107,6 +114,37 @@ void ATempCharacter::Tick(float DeltaTime) FirstPlayerController->DeprojectMousePositionToWorld(WidgetLocation, VectorRotation); WidgetPointer->SetWorldLocationAndRotation(WidgetLocation, VectorRotation.Rotation().Quaternion()); } + else + { + const FVector Start = ThisCamera->GetComponentLocation(); + const FVector End = Start + TraceDistance * ThisCamera->GetForwardVector(); + FCollisionQueryParams TraceParams; + TraceParams.AddIgnoredActor(this); + if (FHitResult OutResult = FHitResult(); GetWorld()->LineTraceSingleByChannel(OutResult, Start, End, ECC_Pawn, TraceParams)) + { + if (!IsValid(OutResult.GetActor())) + { + CrossHair->SetBrush(FSlateBrush()); + CrossHair->SetDesiredSizeOverride(FVector2D(5, 5)); + return; + } + if (OutResult.GetActor()->ActorHasTag("Probertium") || OutResult.GetActor()->ActorHasTag("Iroquid") + || OutResult.GetActor()->ActorHasTag("Azos") || OutResult.GetActor()->ActorHasTag("Eis") + || OutResult.GetActor()->ActorHasTag("NPC") || OutResult.GetActor()->FindComponentByClass()) + { + CrossHair->SetBrush(UWidgetBlueprintLibrary::MakeBrushFromTexture(InteractableCrossHair)); + CrossHair->SetDesiredSizeOverride(FVector2D(43.6, 51.3)); + return; + } + CrossHair->SetBrush(FSlateBrush()); + CrossHair->SetDesiredSizeOverride(FVector2D(5, 5)); + } + else + { + CrossHair->SetBrush(FSlateBrush()); + CrossHair->SetDesiredSizeOverride(FVector2D(5, 5)); + } + } } // Gives the character the functionality @@ -134,8 +172,8 @@ void ATempCharacter::KeyPressed() void ATempCharacter::LineTraceLogic() { //UE_LOG(LogTemp, Display, TEXT("LineTraceLogic activated")); - float GlobalTrace = TraceDistance; ThisCamera = Cast(this->FindComponentByClass()); + float GlobalTrace = TraceDistance; FVector Start = ThisCamera->GetComponentLocation(); FVector End = Start + GlobalTrace * ThisCamera->GetForwardVector(); FCollisionQueryParams TraceParams; @@ -253,7 +291,7 @@ void ATempCharacter::InputEnabler() { PlayerCharacter->EnableInput(GetWorld()->GetFirstPlayerController()); } - + UE_LOG(LogTemp, Display, TEXT("Enabling Inputs")); disableTab = true; TraceDistance = 300; diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index f136c58..8454211 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -9,6 +9,7 @@ #include "Engine/PostProcessVolume.h" #include "Components/WidgetInteractionComponent.h" #include "../TurnBasedCombatV2/TurnBaseCombatV2.h" +#include "Components/Image.h" #include "TempCharacter.generated.h" UCLASS() @@ -24,6 +25,9 @@ public: UPROPERTY(BlueprintReadOnly) bool bIsInDialogue = false; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + UTexture2D* InteractableCrossHair; + protected: // Called when the game starts or when spawned virtual void BeginPlay() override; @@ -42,6 +46,9 @@ protected: UPROPERTY() ATurnBaseCombatV2* CombatSystem; + UPROPERTY() + UImage* CrossHair; + public: // Called every frame virtual void Tick(float DeltaTime) override; diff --git a/UI designs/hand-pointer-icon.png b/UI designs/hand-pointer-icon.png new file mode 100644 index 0000000..c55e029 --- /dev/null +++ b/UI designs/hand-pointer-icon.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8a7e941f2204645a48bb4905bbf2e6aa4aaccc7b8244b867455ae8d473d1d11 +size 21188 diff --git a/the_twilight_abyss.uproject.DotSettings b/the_twilight_abyss.uproject.DotSettings index 81ddebe..dd95502 100644 --- a/the_twilight_abyss.uproject.DotSettings +++ b/the_twilight_abyss.uproject.DotSettings @@ -1,5 +1,6 @@  True + True True True True \ No newline at end of file