Base functionality for MapObject placement
This commit is contained in:
parent
74eab48a6e
commit
237c056b30
@ -28,6 +28,7 @@ AAdventureCameraPawn::AAdventureCameraPawn()
|
|||||||
ESAMinBoundSlope = -1 / ESASize;
|
ESAMinBoundSlope = -1 / ESASize;
|
||||||
ESAMinBoundIntercept = 0 - (ESAMinBoundSlope * ESASize);
|
ESAMinBoundIntercept = 0 - (ESAMinBoundSlope * ESASize);
|
||||||
|
|
||||||
|
AutoPossessPlayer = EAutoReceiveInput::Player0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
@ -36,7 +37,7 @@ void AAdventureCameraPawn::BeginPlay()
|
|||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
ControllerRef = (AAdventurePlayerController*)UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
ControllerRef = (AAdventurePlayerController*)UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||||
|
|
||||||
// The Viewport properties are inaccurate right after BeginPlay, so we need to wait a short time before saving them here.
|
// Viewport properties not accurate on BeginPlay (must wait before accessing)
|
||||||
FTimerHandle UnusedHandle;
|
FTimerHandle UnusedHandle;
|
||||||
GetWorldTimerManager().SetTimer(
|
GetWorldTimerManager().SetTimer(
|
||||||
UnusedHandle, this, &AAdventureCameraPawn::GetTheDamnViewport, 1, false);
|
UnusedHandle, this, &AAdventureCameraPawn::GetTheDamnViewport, 1, false);
|
||||||
@ -63,8 +64,21 @@ void AAdventureCameraPawn::SetupPlayerInputComponent(UInputComponent* PlayerInpu
|
|||||||
{
|
{
|
||||||
PlayerInputComponent->BindAxis("Mouse X", this, &AAdventureCameraPawn::EdgeScrollSide);
|
PlayerInputComponent->BindAxis("Mouse X", this, &AAdventureCameraPawn::EdgeScrollSide);
|
||||||
PlayerInputComponent->BindAxis("Mouse Y", this, &AAdventureCameraPawn::EdgeScrollVert);
|
PlayerInputComponent->BindAxis("Mouse Y", this, &AAdventureCameraPawn::EdgeScrollVert);
|
||||||
|
|
||||||
|
PlayerInputComponent->BindAxis("Move AD", this, &AAdventureCameraPawn::ScrollSide);
|
||||||
|
PlayerInputComponent->BindAxis("Move WS", this, &AAdventureCameraPawn::ScrollVert);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void AAdventureCameraPawn::ScrollSide(float AxisValue)
|
||||||
|
{
|
||||||
|
float DeltaLoc = AxisValue * BaseScrollSpeed * 3;
|
||||||
|
AddActorLocalOffset(FVector(DeltaLoc, 0, 0));
|
||||||
|
}
|
||||||
|
void AAdventureCameraPawn::ScrollVert(float AxisValue)
|
||||||
|
{
|
||||||
|
float DeltaLoc = AxisValue * BaseScrollSpeed * -3;
|
||||||
|
AddActorLocalOffset(FVector(0, DeltaLoc, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AAdventureCameraPawn::EdgeScrollSide(float AxisValue)
|
void AAdventureCameraPawn::EdgeScrollSide(float AxisValue)
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
FVector AdvPawnLocationDelta;
|
FVector AdvPawnLocationDelta;
|
||||||
UPROPERTY(BlueprintReadWrite, Category = "Runtime")
|
UPROPERTY(BlueprintReadWrite, Category = "Runtime")
|
||||||
bool bAdvPawnIsMoving;
|
bool bAdvPawnIsMoving = false;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite, Category = "Runtime")
|
UPROPERTY(BlueprintReadWrite, Category = "Runtime")
|
||||||
class AHexTile* SelectedHex;
|
class AHexTile* SelectedHex;
|
||||||
@ -67,6 +67,10 @@ public:
|
|||||||
// Called to bind functionality to input
|
// Called to bind functionality to input
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void ScrollSide(float AxisValue);
|
||||||
|
UFUNCTION()
|
||||||
|
void ScrollVert(float AxisValue);
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void EdgeScrollSide(float AxisValue);
|
void EdgeScrollSide(float AxisValue);
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
|
@ -118,6 +118,7 @@ TArray<AHexTile*> AAdventureMap::AStar(AHexTile* Start, AHexTile* Goal)
|
|||||||
// expand frontier & adjust path data
|
// expand frontier & adjust path data
|
||||||
for (AHexTile* Neighbor : Neighbors(Candidate)) {
|
for (AHexTile* Neighbor : Neighbors(Candidate)) {
|
||||||
if (Neighbor->Distance(Candidate) > 1) { continue; }
|
if (Neighbor->Distance(Candidate) > 1) { continue; }
|
||||||
|
if (!(Neighbor->bFree)) { continue; }
|
||||||
if (Processed.Contains(Neighbor)) { continue; }
|
if (Processed.Contains(Neighbor)) { continue; }
|
||||||
|
|
||||||
bool bInToExamine = ToExamine.Contains(Neighbor);
|
bool bInToExamine = ToExamine.Contains(Neighbor);
|
||||||
@ -134,13 +135,15 @@ TArray<AHexTile*> AAdventureMap::AStar(AHexTile* Start, AHexTile* Goal)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return LinkPath(Start, Goal);
|
return LinkPath(Start, Goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
TArray<AHexTile*> AAdventureMap::LinkPath(AHexTile* Start, AHexTile* Goal)
|
TArray<AHexTile*> AAdventureMap::LinkPath(AHexTile* Start, AHexTile* Goal)
|
||||||
{
|
{
|
||||||
TArray<AHexTile*> Path;
|
TArray<AHexTile*> Path;
|
||||||
|
|
||||||
|
if (!IsValid(Goal->CameFrom)) { return Path; }
|
||||||
|
|
||||||
AHexTile* iPathNode = Goal;
|
AHexTile* iPathNode = Goal;
|
||||||
|
|
||||||
while (iPathNode != Start) {
|
while (iPathNode != Start) {
|
||||||
|
@ -6,18 +6,27 @@
|
|||||||
#include "HexTile.h"
|
#include "HexTile.h"
|
||||||
#include "AdventureCameraPawn.h"
|
#include "AdventureCameraPawn.h"
|
||||||
#include "AdventureCharacter.h"
|
#include "AdventureCharacter.h"
|
||||||
|
#include "MapObject.h"
|
||||||
|
|
||||||
|
|
||||||
AAdventurePlayerController::AAdventurePlayerController()
|
AAdventurePlayerController::AAdventurePlayerController()
|
||||||
{
|
{
|
||||||
PrimaryActorTick.bCanEverTick = true;
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
PrimaryActorTick.bStartWithTickEnabled = true;
|
PrimaryActorTick.bStartWithTickEnabled = true;
|
||||||
|
AutoReceiveInput = EAutoReceiveInput::Player0;
|
||||||
}
|
}
|
||||||
void AAdventurePlayerController::BeginPlay()
|
void AAdventurePlayerController::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
World = GetWorld();
|
World = GetWorld();
|
||||||
|
HoveredHex = CurrentHex;
|
||||||
|
}
|
||||||
|
// Called every frame
|
||||||
|
void AAdventurePlayerController::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
|
if (bInPlacementMode) { FitOnGrid(PlaceObj); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void AAdventurePlayerController::SetupInputComponent()
|
void AAdventurePlayerController::SetupInputComponent()
|
||||||
@ -26,18 +35,41 @@ void AAdventurePlayerController::SetupInputComponent()
|
|||||||
Super::SetupInputComponent();
|
Super::SetupInputComponent();
|
||||||
|
|
||||||
// This is initialized on startup, you can go straight to binding
|
// This is initialized on startup, you can go straight to binding
|
||||||
// InputComponent->BindAction("LeftClick", IE_Pressed, this, &AAdventurePlayerController::AdvClick);
|
InputComponent->BindAction("LeftClick", IE_Pressed, this, &AAdventurePlayerController::LeftClick);
|
||||||
|
InputComponent->BindAction("DebugAlt", IE_Pressed, this, &AAdventurePlayerController::TogglePlacing); // Change binding eventually
|
||||||
}
|
}
|
||||||
|
|
||||||
void AAdventurePlayerController::AdvClick()
|
void AAdventurePlayerController::LeftClick()
|
||||||
{
|
{
|
||||||
FHitResult Hit;
|
if (bInPlacementMode) { PlaceObject(PlaceObjClass, HoveredHex); }
|
||||||
GetHitResultUnderCursor(ECollisionChannel::ECC_Vehicle,false,Hit);
|
}
|
||||||
|
|
||||||
if (IsValid(Hit.GetActor()))
|
void AAdventurePlayerController::TogglePlacing()
|
||||||
{
|
{
|
||||||
AHexTile* HitHex = (AHexTile*)Hit.GetActor();
|
bInPlacementMode = !bInPlacementMode;
|
||||||
// MapRef->FindPathAStar(CurrentHex, HitHex);
|
if (bInPlacementMode) {
|
||||||
// UE_LOG(LogTemp, Warning, TEXT("%d"), HitHex->Index);
|
PlaceObj = World->SpawnActor<AMapObject>(PlaceObjClass, FTransform());
|
||||||
}
|
}
|
||||||
|
else { if (IsValid(PlaceObj)) { PlaceObj->Destroy(); } }
|
||||||
|
}
|
||||||
|
|
||||||
|
void AAdventurePlayerController::FitOnGrid(AMapObject* MapObject)
|
||||||
|
{
|
||||||
|
if (!IsValid(HoveredHex)) { return; }
|
||||||
|
if (HoveredHex->bFree) {
|
||||||
|
MapObject->SetActorLocation(FVector(HoveredHex->GetActorLocation()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// called from BP; generally takes the Hex under the player cursor as argument
|
||||||
|
void AAdventurePlayerController::PlaceObject(TSubclassOf<AMapObject> MapObjClass, AHexTile* OnHex)
|
||||||
|
{
|
||||||
|
// spawn this Actor at World location of Origin Hex;
|
||||||
|
AMapObject* SpawnedObj = World->SpawnActor<AMapObject>(MapObjClass, FTransform(OnHex->GetActorTransform().GetLocation()));
|
||||||
|
// Origin = OnHex;
|
||||||
|
SpawnedObj->Origin = OnHex;
|
||||||
|
// set Hexes to bOccupied according to BlockVectors;
|
||||||
|
OnHex->bFree = false;
|
||||||
|
// set bPlacementMode = false;
|
||||||
|
//
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ class AAdventureMap;
|
|||||||
class AHexTile;
|
class AHexTile;
|
||||||
class AAdventureCameraPawn;
|
class AAdventureCameraPawn;
|
||||||
class AAdventureCharacter;
|
class AAdventureCharacter;
|
||||||
|
class AMapObject;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -23,6 +23,7 @@ class FRAY_API AAdventurePlayerController : public APlayerController
|
|||||||
public:
|
public:
|
||||||
AAdventurePlayerController();
|
AAdventurePlayerController();
|
||||||
|
|
||||||
|
// General
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
UWorld* World;
|
UWorld* World;
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
@ -31,11 +32,31 @@ public:
|
|||||||
AHexTile* SpawnHex;
|
AHexTile* SpawnHex;
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Runtime")
|
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Runtime")
|
||||||
AHexTile* CurrentHex;
|
AHexTile* CurrentHex;
|
||||||
|
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||||
|
AHexTile* HoveredHex;
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void LeftClick();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
virtual void SetupInputComponent() override;
|
virtual void SetupInputComponent() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void AdvClick();
|
|
||||||
|
// Object Placement
|
||||||
|
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
||||||
|
bool bInPlacementMode;
|
||||||
|
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||||
|
TSubclassOf<AMapObject> PlaceObjClass;
|
||||||
|
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
||||||
|
AMapObject* PlaceObj;
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void TogglePlacing();
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void FitOnGrid(AMapObject* MapObject);
|
||||||
|
UFUNCTION()
|
||||||
|
void PlaceObject(TSubclassOf<AMapObject> MapObjClass, AHexTile* OnHex);
|
||||||
|
|
||||||
|
// Called every frame
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
};
|
};
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
// Fill out your copyright notice in the Description page of Project Settings.
|
|
||||||
|
|
||||||
|
|
||||||
#include "Clickable.h"
|
|
||||||
|
|
||||||
// Sets default values for this component's properties
|
|
||||||
UClickable::UClickable()
|
|
||||||
{
|
|
||||||
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
|
||||||
// off to improve performance if you don't need them.
|
|
||||||
PrimaryComponentTick.bCanEverTick = true;
|
|
||||||
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Called when the game starts
|
|
||||||
void UClickable::BeginPlay()
|
|
||||||
{
|
|
||||||
Super::BeginPlay();
|
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Called every frame
|
|
||||||
void UClickable::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
|
||||||
{
|
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
|
||||||
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
|
|
28
Clickable.h
28
Clickable.h
@ -1,28 +0,0 @@
|
|||||||
// Fill out your copyright notice in the Description page of Project Settings.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
|
||||||
#include "Components/ActorComponent.h"
|
|
||||||
#include "Clickable.generated.h"
|
|
||||||
|
|
||||||
|
|
||||||
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
|
|
||||||
class FRAY_API UClickable : public UActorComponent
|
|
||||||
{
|
|
||||||
GENERATED_BODY()
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Sets default values for this component's properties
|
|
||||||
UClickable();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// Called when the game starts
|
|
||||||
virtual void BeginPlay() override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Called every frame
|
|
||||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
@ -49,8 +49,6 @@ public:
|
|||||||
int32 MoveCost = 1;
|
int32 MoveCost = 1;
|
||||||
UPROPERTY(BlueprintReadWrite, VisibleInstanceOnly, Category = "Movement")
|
UPROPERTY(BlueprintReadWrite, VisibleInstanceOnly, Category = "Movement")
|
||||||
AHexTile* CameFrom;
|
AHexTile* CameFrom;
|
||||||
UPROPERTY(VisibleInstanceOnly, Category = "Movement")
|
|
||||||
int32 CostSoFar = 0;
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
int32 FCost;
|
int32 FCost;
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
@ -58,6 +56,10 @@ public:
|
|||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
int32 HCost;
|
int32 HCost;
|
||||||
|
|
||||||
|
// MapObject Placement
|
||||||
|
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
||||||
|
bool bFree = true;
|
||||||
|
|
||||||
FORCEINLINE bool operator == (const AHexTile &Other)
|
FORCEINLINE bool operator == (const AHexTile &Other)
|
||||||
{
|
{
|
||||||
if (this->Q == Other.Q && this->R == Other.R) { return true; }
|
if (this->Q == Other.Q && this->R == Other.R) { return true; }
|
||||||
|
Loading…
Reference in New Issue
Block a user