Skip to content

Commit

Permalink
Add world placement for Copy and Fill, add anchor building for Copy
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Jul 9, 2021
1 parent 9c7f0f9 commit 0dfde63
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 42 deletions.
Binary file modified Plugins/AreaActions/Content/Actions/Copy/BP_Copy.uasset
Binary file not shown.
Binary file modified Plugins/AreaActions/Content/Actions/Copy/Widget_Copy.uasset
Binary file not shown.
Binary file modified Plugins/AreaActions/Content/Actions/Fill/BP_Fill.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Plugins/AreaActions/Content/Actions/Fill/Widget_Fill.uasset
Binary file not shown.
Binary file modified Plugins/AreaActions/Content/Equipment/Equip_AreaActions.uasset
Binary file not shown.
23 changes: 18 additions & 5 deletions Plugins/AreaActions/Source/AreaActions/Private/AAAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ void AAAAction::Cancel()
this->Done();
}

void AAAAction::OnCancel_Implementation()
{
}

FText AAAAction::GetActionName(const TSubclassOf<AAAAction> InClass)
{
if(!InClass) return FText::FromString(TEXT("N/A"));
Expand All @@ -45,5 +41,22 @@ FSlateBrush AAAAction::GetActionIcon(const TSubclassOf<AAAAction> InClass)
return InClass.GetDefaultObject()->Icon;
}

void AAAAction::PrimaryFire_Implementation() {
void AAAAction::PrimaryFire_Implementation()
{
}

void AAAAction::MouseWheelUp_Implementation()
{
}

void AAAAction::SecondaryFire_Implementation()
{
}

void AAAAction::OnCancel_Implementation()
{
}

void AAAAction::MouseWheelDown_Implementation()
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "AABlueprintFunctionLibrary.h"

#include "Hologram/FGHologram.h"

FTransform UAABlueprintFunctionLibrary::GetHologramSnap(AFGHologram* Hologram, FHitResult HitResult)
{
const FTransform PreviousHologramTransform = Hologram->GetActorTransform();
if(!Hologram->TrySnapToActor(HitResult)) {
Hologram->SetHologramLocationAndRotation(HitResult);
}
FTransform NewHologramTransform = Hologram->GetActorTransform();
Hologram->SetActorTransform(PreviousHologramTransform);
Hologram->SetPlacementMaterial(true);
Hologram->SetActorHiddenInGame(false);
return NewHologramTransform;
}

FTransform UAABlueprintFunctionLibrary::GetHologramScroll(AFGHologram* Hologram, const int32 Delta)
{
const FTransform PreviousHologramTransform = Hologram->GetActorTransform();
Hologram->Scroll(Delta);
FTransform NewHologramTransform = Hologram->GetActorTransform();
Hologram->SetActorTransform(PreviousHologramTransform);
Hologram->SetPlacementMaterial(true);
Hologram->SetActorHiddenInGame(false);
return NewHologramTransform;
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,13 @@ bool UAACopyBuildingsComponent::TryTakeItems(TArray<UFGInventoryComponent*> Inve
if(AFGBuildableFactory* FactoryBuildable = Cast<AFGBuildableFactory>(Buildable))
{
TArray<FInventoryStack> Stacks;
FactoryBuildable->mInventoryPotential->GetInventoryStacks(Stacks);
for(const FInventoryStack Stack : Stacks)
if(Stack.HasItems())
ItemsPerCopy.FindOrAdd(Stack.Item.ItemClass) += Stack.NumItems;
if(FactoryBuildable->mInventoryPotential)
{
FactoryBuildable->mInventoryPotential->GetInventoryStacks(Stacks);
for(const FInventoryStack Stack : Stacks)
if(Stack.HasItems())
ItemsPerCopy.FindOrAdd(Stack.Item.ItemClass) += Stack.NumItems;
}
}
}
}
Expand Down Expand Up @@ -528,3 +531,21 @@ bool UAACopyBuildingsComponent::Finish(TArray<UFGInventoryComponent*> Inventorie
this->CopyLocations.Empty();
return true;
}

AFGBuildableHologram* UAACopyBuildingsComponent::GetPreviewHologram(int CopyId, AFGBuildable* Buildable)
{
if(!this->Preview.Contains(CopyId)) return nullptr;
if(!this->Preview[CopyId].Holograms.Contains(Buildable)) return nullptr;
return this->Preview[CopyId].Holograms[Buildable];
}

void UAACopyBuildingsComponent::GetAllPreviewHolograms(TArray<AFGBuildableHologram*>& OutPreviewHolograms)
{
for(const auto& [CopyId, CopyPreview] : this->Preview)
{
for(const auto& [_, Hologram] : CopyPreview.Holograms)
{
OutPreviewHolograms.Add(Hologram);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ AAACopy::AAACopy() {
this->CopyBuildingsComponent = CreateDefaultSubobject<UAACopyBuildingsComponent>(TEXT("CopyBuildings"));
this->DeltaPosition = FVector::ZeroVector;
this->DeltaRotation = FRotator::ZeroRotator;
this->PreviewExists = false;
}

void AAACopy::Run_Implementation() {
Expand Down Expand Up @@ -40,23 +39,19 @@ void AAACopy::Run_Implementation() {
}
}
else {
this->CopyBuildingsComponent->AddCopy(DeltaPosition, DeltaRotation, Anchor ? Anchor->GetActorLocation() : CopyBuildingsComponent->GetBuildingsCenter());
this->ShowCopyWidget();
}
}

void AAACopy::OnCancel_Implementation()
{
if(PreviewExists)
this->CopyBuildingsComponent->RemoveCopy(0);
this->CopyBuildingsComponent->RemoveCopy(0);
}

void AAACopy::Preview()
{
if(!PreviewExists)
this->CopyBuildingsComponent->AddCopy(DeltaPosition, DeltaRotation, IsRotationCenterSet ? RotationCenter : CopyBuildingsComponent->GetBuildingsCenter());
else
this->CopyBuildingsComponent->MoveCopy(0, DeltaPosition, DeltaRotation, IsRotationCenterSet ? RotationCenter : CopyBuildingsComponent->GetBuildingsCenter());
PreviewExists = true;
this->CopyBuildingsComponent->MoveCopy(0, DeltaPosition, DeltaRotation, Anchor ? Anchor->GetActorLocation() : CopyBuildingsComponent->GetBuildingsCenter());
}

void AAACopy::Finish()
Expand Down
13 changes: 11 additions & 2 deletions Plugins/AreaActions/Source/AreaActions/Public/AAAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "GameFramework/Actor.h"
#include "AAAction.generated.h"

UCLASS(Abstract, hidecategories = (Rendering, Replication, Input, Actor, Collision, "Actor Tick", LOD, Cooking))
UCLASS(Abstract)
class AREAACTIONS_API AAAAction : public AActor
{
GENERATED_BODY()
Expand All @@ -22,10 +22,19 @@ class AREAACTIONS_API AAAAction : public AActor
void OnCancel();

UFUNCTION(BlueprintCallable)
void Cancel();
void Cancel();

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void PrimaryFire();

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void SecondaryFire();

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void MouseWheelUp();

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void MouseWheelDown();

FORCEINLINE void SetActors(const TArray<AActor*> InActors) { this->Actors = InActors; }
FORCEINLINE void SetAAEquipment(class AAAEquipment* InEquipment) { this->AAEquipment = InEquipment; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "AABlueprintFunctionLibrary.generated.h"

/**
*
*/
UCLASS()
class AREAACTIONS_API UAABlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category="AreaActions|Hologram")
static FTransform GetHologramSnap(class AFGHologram* Hologram, FHitResult HitResult);

UFUNCTION(BlueprintCallable, Category="AreaActions|Hologram")
static FTransform GetHologramScroll(class AFGHologram* Hologram, int32 Delta);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

#include "AACopyBuildingsComponent.generated.h"

USTRUCT()
USTRUCT(Blueprintable)
struct FRotatedBoundingBox
{
GENERATED_BODY()

UPROPERTY()
UPROPERTY(BlueprintReadWrite)
FVector Center;
UPROPERTY()
UPROPERTY(BlueprintReadWrite)
FVector Extents;
/** Only has yaw */
UPROPERTY()
UPROPERTY(BlueprintReadWrite)
FRotator Rotation;

FVector GetCorner(uint32 CornerNum) const;
Expand Down Expand Up @@ -94,7 +94,7 @@ struct FCopyLocation
bool Relative;
};

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent))
class AREAACTIONS_API UAACopyBuildingsComponent : public UActorComponent
{
GENERATED_BODY()
Expand All @@ -106,7 +106,10 @@ class AREAACTIONS_API UAACopyBuildingsComponent : public UActorComponent
bool SetBuildings(TArray<AFGBuildable*>& Buildings, TArray<AFGBuildable*>& OutBuildingsWithIssues, FText& Error);
bool ValidateObjects(TArray<AFGBuildable*>& OutBuildingsWithIssues);

UFUNCTION(BlueprintPure)
FORCEINLINE FVector GetBuildingsCenter() const { return BuildingsBounds.Center; }

UFUNCTION(BlueprintPure)
FORCEINLINE FRotatedBoundingBox GetBounds() const { return BuildingsBounds; }

int AddCopy(FVector Offset, FRotator Rotation, FVector RotationCenter, bool Relative = true);
Expand All @@ -117,6 +120,12 @@ class AREAACTIONS_API UAACopyBuildingsComponent : public UActorComponent

bool Finish(TArray<UFGInventoryComponent*> Inventories, TArray<FInventoryStack>& OutMissingItems);

UFUNCTION(BlueprintCallable)
AFGBuildableHologram* GetPreviewHologram(int CopyId, AFGBuildable* Buildable);

UFUNCTION(BlueprintCallable)
void GetAllPreviewHolograms(TArray<AFGBuildableHologram*>& OutPreviewHolograms);

private:
void FixReferencesForCopy(const FCopyMap& Copy);

Expand Down
11 changes: 8 additions & 3 deletions Plugins/AreaActions/Source/AreaActions/Public/AAEquipment.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ class AREAACTIONS_API AAAEquipment : public AFGEquipment

UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, meta = (AutoCreateRefTerm = "message"))
UWidget* CreateActionMessageYesNo(const FText& Message, const FOnMessageYes& OnYesClicked, const FOnMessageNo& OnNoClicked);


bool RaycastMouseWithRange(FHitResult & OutHitResult, bool bIgnoreCornerIndicators = false, bool bIgnoreWallIndicators = false, bool bIgnoreHeightIndicators = false, TArray<AActor*> OtherIgnoredActors = TArray<AActor*>()) const;

UFUNCTION(BlueprintCallable, BlueprintPure=false, meta=(DisplayName = "RaycastMouseWithRange", AutoCreateRefTerm = "OtherIgnoredActors"))
FORCEINLINE bool K2_RaycastMouseWithRange(FHitResult & OutHitResult, bool bIgnoreCornerIndicators, bool bIgnoreWallIndicators, bool bIgnoreHeightIndicators, TArray<AActor*> OtherIgnoredActors) const
{
return RaycastMouseWithRange(OutHitResult, bIgnoreCornerIndicators, bIgnoreWallIndicators, bIgnoreHeightIndicators, OtherIgnoredActors);
}
protected:
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
void AddWidget(UFGInteractWidget* Widget);
Expand All @@ -103,8 +110,6 @@ class AREAACTIONS_API AAAEquipment : public AFGEquipment
FOnActionDone OnActionDone;

private:
bool RaycastMouseWithRange(FHitResult & OutHitResult, bool bIgnoreCornerIndicators = false, bool bIgnoreWallIndicators = false, bool bIgnoreHeightIndicators = false, TArray<AActor*> OtherIgnoredActors = TArray<AActor*>()) const;

void AddCorner(FVector2D Location);
void RemoveCorner(int CornerIdx);
void UpdateHeight();
Expand Down
34 changes: 21 additions & 13 deletions Plugins/AreaActions/Source/AreaActions/Public/Actions/AACopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,29 @@ class AREAACTIONS_API AAACopy : public AAAAction
virtual void OnCancel_Implementation() override;

UFUNCTION(BlueprintCallable)
void SetDelta(const FVector InDeltaPosition, const FRotator InDeltaRotation, const FVector InRotationCenter, const bool InIsRotationCenterSet)
void SetDelta(const FVector InDeltaPosition, const FRotator InDeltaRotation)
{
this->DeltaPosition = InDeltaPosition;
this->DeltaRotation = InDeltaRotation;
this->RotationCenter = InRotationCenter;
this->IsRotationCenterSet = InIsRotationCenterSet;
}

UFUNCTION(BlueprintCallable)
void SetAnchor(AFGBuildable* InAnchor)
{
this->Anchor = InAnchor;
}

UFUNCTION(BlueprintPure)
void GetDelta(FVector& OutDeltaPosition, FRotator& OutDeltaRotation, FVector& OutRotationCenter, bool& OutIsRotationCenterSet) const
void GetDelta(FVector& OutDeltaPosition, FRotator& OutDeltaRotation) const
{
OutDeltaPosition = this->DeltaPosition;
OutDeltaRotation = this->DeltaRotation;
OutRotationCenter = this->RotationCenter;
OutIsRotationCenterSet = this->IsRotationCenterSet;
}

UFUNCTION(BlueprintPure)
void GetAnchor(AFGBuildable*& OutAnchor) const
{
OutAnchor = this->Anchor;
}

UFUNCTION(BlueprintImplementableEvent)
Expand All @@ -48,17 +56,17 @@ class AREAACTIONS_API AAACopy : public AAAAction
void Finish();

UFUNCTION()
void RemoveMissingItemsWidget();
private:
UPROPERTY()
void RemoveMissingItemsWidget();

protected:
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
UAACopyBuildingsComponent* CopyBuildingsComponent;

FVector DeltaPosition;
FRotator DeltaRotation;
FVector RotationCenter;
bool IsRotationCenterSet;

bool PreviewExists;

UPROPERTY()
AFGBuildable* Anchor;

UPROPERTY()
UWidget* MissingItemsWidget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class AREAACTIONS_API AAAFill : public AAAAction
UFUNCTION()
void RemoveMissingItemsWidget();

private:
UPROPERTY()
protected:
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
UAACopyBuildingsComponent* CopyBuildingsComponent;

FVector AreaSize;
Expand Down

0 comments on commit 0dfde63

Please sign in to comment.