Updated Cursor for Change when Hovering on Interactable Object

This commit is contained in:
Philip W 2023-05-21 18:55:22 +01:00
parent ba4e8bf07c
commit d17ba9e064
7 changed files with 63 additions and 7 deletions

Binary file not shown.

BIN
Content/Blueprints/Display_UI/InteracableIcon.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -143,14 +143,17 @@ void UDialogueNPC::TickComponent(float DeltaTime, ELevelTick TickType, FActorCom
void UDialogueNPC::StartDialogue()
{
Cast<ATempCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn())->bIsInDialogue = true;
Cast<ATempCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn())->InventoryWidget->SetVisibility(ESlateVisibility::Hidden);
Cast<ATempCharacter>(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<ATempCharacter>(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<ATempCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn())->CrossHairWidget->SetVisibility(ESlateVisibility::HitTestInvisible);
}
}

View File

@ -9,6 +9,7 @@
#include "the_twilight_abyss/MerchantInteraction/Interaction.h"
#include <Runtime/Engine/Classes/Kismet/GameplayStatics.h>
#include "Components/PawnNoiseEmitterComponent.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Kismet/KismetMathLibrary.h"
@ -20,6 +21,11 @@ ATempCharacter::ATempCharacter()
Inventory = CreateDefaultSubobject<UInventoryComponent>("Inventory");
Inventory->MaxItemSlots = 10;
this->GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true;
if (static ConstructorHelpers::FObjectFinder<UTexture2D> 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<UUserWidget>(GetWorld(), CrossHairSub);
CrossHairWidget->SetVisibility(ESlateVisibility::Visible);
CrossHair = Cast<UImage>(CrossHairWidget->GetWidgetFromName(TEXT("Crosshair")));
CrossHairWidget->AddToViewport();
InventoryWidget = CreateWidget<UUserWidget>(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<UInventoryComponent>())
{
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<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
float GlobalTrace = TraceDistance;
FVector Start = ThisCamera->GetComponentLocation();
FVector End = Start + GlobalTrace * ThisCamera->GetForwardVector();
FCollisionQueryParams TraceParams;

View File

@ -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;

BIN
UI designs/hand-pointer-icon.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Azos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Iroquid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Iroquoid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Probertium/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=UFUNCTION/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>