AzureAbyss/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp

112 lines
3.3 KiB
C++
Raw Normal View History

// Fill out your copyright notice in the Description page of Project Settings.
#include "TempCharacter.h"
#include "UObject/SoftObjectPath.h"
#include "Dialogs/Dialogs.h"
#include "Engine/GameViewportClient.h"
#include "Blueprint/UserWidget.h"
#include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h"
2022-11-10 12:57:31 +00:00
// CONSTRUCTOR
ATempCharacter::ATempCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ATempCharacter::BeginPlay()
{
Super::BeginPlay();
}
2022-11-10 12:57:31 +00:00
//Binds the input we made in the setup player component to the forward vector
void ATempCharacter::ForwardInput(float Axis)
{
2022-11-11 22:21:10 +00:00
AddMovementInput(GetActorForwardVector() * Axis);
}
2022-11-10 12:57:31 +00:00
//Binds the input we made in the setup player component to the right vector
void ATempCharacter::RightMoveInput(float Axis)
{
2022-11-11 22:21:10 +00:00
AddMovementInput(GetActorRightVector() * Axis);
}
2022-11-10 12:57:31 +00:00
// Called every frame
void ATempCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("Move Forward / Backward"), this, &ATempCharacter::ForwardInput);
PlayerInputComponent->BindAxis(TEXT("Move Right / Left"), this, &ATempCharacter::RightMoveInput);
PlayerInputComponent->BindAxis(TEXT("Turn Right / Left Mouse"), this, &ATempCharacter::AddControllerYawInput);
PlayerInputComponent->BindAxis(TEXT("Look Up / Down Mouse"), this, &ATempCharacter::AddControllerPitchInput);
2022-11-11 22:21:10 +00:00
PlayerInputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed);
// custom keybind Interact
}
2022-11-11 22:21:10 +00:00
void ATempCharacter::KeyPressed()
{
2022-11-11 22:21:10 +00:00
LineTraceLogic();
}
void ATempCharacter::LineTraceLogic()
{
float GlobalTrace = TraceDistance;
FHitResult OutHit;
FVector Start = GetActorLocation();
2022-11-11 22:21:10 +00:00
FVector End = Start + GlobalTrace * GetActorForwardVector();
FCollisionQueryParams TraceParams;
2022-11-11 22:21:10 +00:00
TraceParams.AddIgnoredActor(this);
/*bool bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams);
2022-11-11 22:21:10 +00:00
if (bHit)
{
2022-11-11 22:21:10 +00:00
if (OutHit.GetActor()->ActorHasTag("MerchantTag"))
{
FStringClassReference WidgetRef(TEXT("WidgetBlueprint/Game/Merchant/BP_OPENDIAL.BP_OPENDIAL"));
TSubclassOf<class UUserWidget> WidgetLoad = WidgetRef.TryLoadClass<UUserWidget>();
UUserWidget* TestWidget = CreateWidget<UUserWidget>(this, WidgetLoad, FName(TEXT("MyWidget")));
if(TestWidget)
{
TestWidget->AddToViewport(0);
}
2022-11-11 22:21:10 +00:00
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
}
}
*/
2022-11-11 23:33:37 +00:00
// In a constructor
FStringClassReference MyWidgetClassRef(TEXT("/Game/Widgets/TestWidget.TestWidget_C"));
// Get the widget class
TSubclassOf<class UUserWidget> TestWidgetClass = MyWidgetClassRef.TryLoadClass<UUserWidget>();
// ... then to display you widget do
// Check if class was found
if (TestWidgetClass )
{
// Create the widget
UUserWidget* TestWidget= CreateWidget<UUserWidget>(this, TestWidgetClass, FName(TEXT("MyWidget")));
// Check if widget was created
if (TestWidget)
{
TestWidget->AddToViewport();
}
}
// I GIVE UP LOL!
}