Migration
This commit is contained in:
BIN
Plugins/LibAmasson/Content/Blueprints/BFL_GenericFunctionsExtension.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Blueprints/BFL_GenericFunctionsExtension.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Blueprints/BPL_ActorMacros.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Blueprints/BPL_ActorMacros.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Blueprints/BPL_GenericMacrosExtension.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Blueprints/BPL_GenericMacrosExtension.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Blueprints/BPL_UserWidgetMacros.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Blueprints/BPL_UserWidgetMacros.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Blueprints/BP_OnlineSessionManager.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Blueprints/BP_OnlineSessionManager.uasset
LFS
Normal file
Binary file not shown.
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Materials/Functions/MF_CircleMask.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Materials/Functions/MF_CircleMask.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Materials/Functions/MF_Juliabrot.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Materials/Functions/MF_Juliabrot.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Materials/Functions/MF_RadialMask.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Materials/Functions/MF_RadialMask.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Materials/Masters/MI_WidgetMask_Circle.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Materials/Masters/MI_WidgetMask_Circle.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Materials/Masters/M_CircleRadialProgress.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Materials/Masters/M_CircleRadialProgress.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Materials/Masters/M_WidgetCircleMask.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Materials/Masters/M_WidgetCircleMask.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Materials/Masters/M_WidgetTextureMask.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Materials/Masters/M_WidgetTextureMask.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Tests/TestMap_LibAmasson.umap
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Tests/TestMap_LibAmasson.umap
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Tests/TestMap_LibAmasson_GameMode.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Tests/TestMap_LibAmasson_GameMode.uasset
LFS
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Widgets/SegmentPicker/S_SegmentPickerElement.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Widgets/SegmentPicker/S_SegmentPickerElement.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Widgets/SegmentPicker/Widget_SegmentButton.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Widgets/SegmentPicker/Widget_SegmentButton.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Widgets/SegmentPicker/Widget_SegmentPicker.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Widgets/SegmentPicker/Widget_SegmentPicker.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Widgets/Widget_CircularRadialProgress.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Widgets/Widget_CircularRadialProgress.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Widgets/Widget_DraggableButton.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Widgets/Widget_DraggableButton.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Widgets/Widget_Image.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Widgets/Widget_Image.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Widgets/Widget_Spacer.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Widgets/Widget_Spacer.uasset
LFS
Normal file
Binary file not shown.
BIN
Plugins/LibAmasson/Content/Widgets/Widget_Text.uasset
LFS
Normal file
BIN
Plugins/LibAmasson/Content/Widgets/Widget_Text.uasset
LFS
Normal file
Binary file not shown.
30
Plugins/LibAmasson/LibAmasson.uplugin
Normal file
30
Plugins/LibAmasson/LibAmasson.uplugin
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"FileVersion": 3,
|
||||
"Version": 1,
|
||||
"VersionName": "1.0",
|
||||
"FriendlyName": "LibAmasson",
|
||||
"Description": "My plugin of frequently implemented functions",
|
||||
"Category": "Blueprints",
|
||||
"CreatedBy": "Amasson",
|
||||
"CreatedByURL": "",
|
||||
"DocsURL": "",
|
||||
"MarketplaceURL": "",
|
||||
"SupportURL": "",
|
||||
"CanContainContent": true,
|
||||
"IsBetaVersion": false,
|
||||
"IsExperimentalVersion": false,
|
||||
"Installed": false,
|
||||
"Modules": [
|
||||
{
|
||||
"Name": "LibAmasson",
|
||||
"Type": "Runtime",
|
||||
"LoadingPhase": "Default"
|
||||
}
|
||||
],
|
||||
"Plugins": [
|
||||
{
|
||||
"Name": "OnlineSubsystemUtils",
|
||||
"Enabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
Plugins/LibAmasson/Resources/Icon128.png
LFS
Normal file
BIN
Plugins/LibAmasson/Resources/Icon128.png
LFS
Normal file
Binary file not shown.
55
Plugins/LibAmasson/Source/LibAmasson/LibAmasson.Build.cs
Normal file
55
Plugins/LibAmasson/Source/LibAmasson/LibAmasson.Build.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class LibAmasson : ModuleRules
|
||||
{
|
||||
public LibAmasson(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicIncludePaths.AddRange(
|
||||
new string[] {
|
||||
// ... add public include paths required here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PrivateIncludePaths.AddRange(
|
||||
new string[] {
|
||||
// ... add other private include paths required here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Core",
|
||||
// ... add other public dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"CoreUObject",
|
||||
"Engine",
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
"UMG",
|
||||
"OnlineSubsystemUtils",
|
||||
// ... add private dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
DynamicallyLoadedModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
// ... add any modules that your module loads dynamically here ...
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Animation/CharacterMovementAnimInstance.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
|
||||
void UCharacterMovementAnimInstance::NativeInitializeAnimation()
|
||||
{
|
||||
Super::NativeInitializeAnimation();
|
||||
|
||||
if (APawn* Owner = TryGetPawnOwner()) {
|
||||
CharacterMovementComponent = Owner->GetComponentByClass<UCharacterMovementComponent>();
|
||||
_PreviousYaw = Owner->GetActorRotation().Yaw;
|
||||
}
|
||||
}
|
||||
|
||||
void UCharacterMovementAnimInstance::NativeUpdateAnimation(float DeltaTime)
|
||||
{
|
||||
Super::NativeUpdateAnimation(DeltaTime);
|
||||
|
||||
if (APawn* Owner = TryGetPawnOwner())
|
||||
{
|
||||
FRotator Rotation = Owner->GetActorRotation();
|
||||
TurnVelocity = (Rotation.Yaw - _PreviousYaw) / DeltaTime;
|
||||
|
||||
if (CharacterMovementComponent)
|
||||
{
|
||||
bFalling = CharacterMovementComponent->IsFalling();
|
||||
bCrouching = CharacterMovementComponent->IsCrouching();
|
||||
bSwimming = CharacterMovementComponent->IsSwimming();
|
||||
|
||||
LocalVelocity = Rotation.UnrotateVector(CharacterMovementComponent->Velocity);
|
||||
LocalVelocityAngle = LocalVelocity.IsNearlyZero() ? 0 : FMath::RadiansToDegrees(FMath::Atan2(LocalVelocity.Y, LocalVelocity.X));
|
||||
|
||||
}
|
||||
|
||||
_PreviousYaw = Rotation.Yaw;
|
||||
}
|
||||
}
|
||||
|
||||
bool UCharacterMovementAnimInstance::IsPawnMoving() const
|
||||
{
|
||||
return LocalVelocity.SquaredLength() > 10;
|
||||
}
|
||||
|
||||
bool UCharacterMovementAnimInstance::IsJumpingUp() const
|
||||
{
|
||||
return LocalVelocity.Z > 0 && bFalling;
|
||||
}
|
||||
|
||||
bool UCharacterMovementAnimInstance::IsFallingDown() const
|
||||
{
|
||||
return LocalVelocity.Z <= 0 && bFalling;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "Components/NetInterpToMovementComponent.h"
|
||||
|
||||
|
||||
UNetInterpToMovementComponent::UNetInterpToMovementComponent()
|
||||
{
|
||||
SetIsReplicatedByDefault(true);
|
||||
}
|
||||
|
||||
UNetInterpToMovementComponent::~UNetInterpToMovementComponent()
|
||||
{
|
||||
if (GetOwner() && GetOwner()->GetWorld())
|
||||
GetOwner()->GetWorldTimerManager().ClearTimer(TimerHandle_BroadcastMovement);
|
||||
}
|
||||
|
||||
void UNetInterpToMovementComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (AActor* Owner = GetOwner())
|
||||
{
|
||||
if (Owner->HasAuthority())
|
||||
{
|
||||
if (Owner->GetWorld())
|
||||
{
|
||||
Owner->GetWorldTimerManager().SetTimer(TimerHandle_BroadcastMovement, this, &ThisClass::BroadcastMovement, 5.0f, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UNetInterpToMovementComponent::BroadcastMovement()
|
||||
{
|
||||
if (GetOwner())
|
||||
NetMulticast_UpdateMovement(GetOwner()->GetActorLocation(), CurrentTime, CurrentDirection, bIsWaiting, bStopped);
|
||||
}
|
||||
|
||||
void UNetInterpToMovementComponent::NetMulticast_UpdateMovement_Implementation(const FVector& Location, float InCurrentTime, float InCurrentDirection, bool bInIsWaiting, bool bInStopped)
|
||||
{
|
||||
FVector Diff = GetOwner()->GetActorLocation() - Location;
|
||||
UE_LOG(LogTemp, Warning, TEXT("Location Difference: %s"), *Diff.ToString());
|
||||
|
||||
if (!Diff.IsNearlyZero())
|
||||
UE_LOG(LogTemp, Warning, TEXT("Location Difference: %s"), *Diff.ToString());
|
||||
|
||||
if (GetOwner())
|
||||
GetOwner()->SetActorLocation(Location);
|
||||
CurrentTime = InCurrentTime;
|
||||
CurrentDirection = InCurrentDirection;
|
||||
bIsWaiting = bInIsWaiting;
|
||||
bStopped = bInStopped;
|
||||
}
|
||||
20
Plugins/LibAmasson/Source/LibAmasson/Private/LibAmasson.cpp
Normal file
20
Plugins/LibAmasson/Source/LibAmasson/Private/LibAmasson.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "LibAmasson.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FLibAmassonModule"
|
||||
|
||||
void FLibAmassonModule::StartupModule()
|
||||
{
|
||||
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
|
||||
}
|
||||
|
||||
void FLibAmassonModule::ShutdownModule()
|
||||
{
|
||||
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
|
||||
// we call this function before unloading the module.
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
IMPLEMENT_MODULE(FLibAmassonModule, LibAmasson)
|
||||
105
Plugins/LibAmasson/Source/LibAmasson/Private/MathLibrary.cpp
Normal file
105
Plugins/LibAmasson/Source/LibAmasson/Private/MathLibrary.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "MathLibrary.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
|
||||
|
||||
void UMathLibrary::GetTraceForward(USceneComponent* Component, double Distance, FVector& StartPoint, FVector& EndPoint)
|
||||
{
|
||||
FVector Location = Component->GetComponentLocation();
|
||||
FVector Forward = Component->GetForwardVector();
|
||||
|
||||
StartPoint = Location;
|
||||
EndPoint = Location + Forward * Distance;
|
||||
}
|
||||
|
||||
void UMathLibrary::TraceClampDistance(const FVector& StartPoint, const FVector& EndPoint,
|
||||
double MinDistance, double MaxDistance,
|
||||
FVector& NewStartPoint, FVector& NewEndPoint)
|
||||
{
|
||||
FVector StartToEnd = EndPoint - StartPoint;
|
||||
StartToEnd = UKismetMathLibrary::ClampVectorSize(StartToEnd, MinDistance, MaxDistance);
|
||||
NewStartPoint = StartPoint;
|
||||
NewEndPoint = StartPoint + StartToEnd;
|
||||
}
|
||||
|
||||
FVector UMathLibrary::AddLengthToVector(FVector Vector, double Length)
|
||||
{
|
||||
FVector NewVector = Vector;
|
||||
NewVector.Normalize();
|
||||
return Vector + NewVector * Length;
|
||||
}
|
||||
|
||||
FVector UMathLibrary::SetLengthToVector(FVector Vector, double Length)
|
||||
{
|
||||
FVector NewVector = Vector;
|
||||
NewVector.Normalize();
|
||||
return NewVector * Length;
|
||||
}
|
||||
|
||||
TArray<FVector> UMathLibrary::TransformPoints(const TArray<FVector>& Points, const FTransform& Transform)
|
||||
{
|
||||
TArray<FVector> NewPoints = Points;
|
||||
for (FVector& NewPoint : NewPoints)
|
||||
{
|
||||
NewPoint = Transform.TransformPosition(NewPoint);
|
||||
}
|
||||
return NewPoints;
|
||||
}
|
||||
|
||||
TArray<FTransform> UMathLibrary::TransformTransforms(const TArray<FTransform>& Transforms, const FTransform& Transform)
|
||||
{
|
||||
TArray<FTransform> NewTransforms = Transforms;
|
||||
for (FTransform& NewTransform : NewTransforms)
|
||||
{
|
||||
NewTransform = NewTransform * Transform;
|
||||
}
|
||||
return NewTransforms;
|
||||
}
|
||||
|
||||
void UMathLibrary::ArcPoints(float ArcAngle, int32 Count, float Distance, TArray<FVector>& Points)
|
||||
{
|
||||
if (Count <= 0)
|
||||
return;
|
||||
|
||||
const float StepAngle = ArcAngle / (Count - 1);
|
||||
FVector Direction = Count == 1 ?
|
||||
FVector(1, 0, 0) :
|
||||
FVector(1, 0, 0).RotateAngleAxis(-ArcAngle / 2.0f, FVector::UpVector);
|
||||
|
||||
for (int32 i = 0; i < Count; i++)
|
||||
{
|
||||
const FVector Location = Direction * Distance;
|
||||
|
||||
Points.Add(Location);
|
||||
|
||||
Direction = Direction.RotateAngleAxis(StepAngle, FVector::UpVector);
|
||||
}
|
||||
}
|
||||
|
||||
void UMathLibrary::ArcTransforms(float ArcAngle, int32 Count, float Distance, TArray<FTransform>& Transforms)
|
||||
{
|
||||
if (Count <= 0)
|
||||
return;
|
||||
|
||||
if (Count == 1)
|
||||
{
|
||||
Transforms.Add(FTransform(FVector(Distance, 0.0f, 0.0f)));
|
||||
return;
|
||||
}
|
||||
|
||||
float StepAngle = ArcAngle / static_cast<float>(Count - 1);
|
||||
FRotator DirectionRotator;
|
||||
|
||||
for (int32 i = 0; i < Count; i++)
|
||||
{
|
||||
const FRotator Rotation(0.0f, -(ArcAngle / 2.0f) + i * StepAngle, 0.0f);
|
||||
const FQuat QuatRotation = Rotation.Quaternion();
|
||||
|
||||
const FVector Location = QuatRotation.GetForwardVector() * Distance;
|
||||
|
||||
const FTransform Transform = FTransform(QuatRotation, Location);
|
||||
Transforms.Add(Transform);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "Sorting/ObjectSortPredicate.h"
|
||||
|
||||
|
||||
bool UObjectSortPredicate::Compare(UObject* Left, UObject* Right) const
|
||||
{
|
||||
if (CanScorify())
|
||||
return ScorifyElement(Left) < ScorifyElement(Right);
|
||||
|
||||
return BP_Compare(Left, Right);
|
||||
}
|
||||
|
||||
float UObjectSortPredicate::ScorifyElement(UObject* Element) const
|
||||
{
|
||||
return BP_ScorifyElement(Element);
|
||||
}
|
||||
|
||||
TArray<TPair<UObject*, float>> UObjectSortPredicate::ScorifyArray(const TArray<UObject*>& Array) const
|
||||
{
|
||||
checkf(CanScorify(), TEXT("ScorifyArray used on predicate that cannot scorify"));
|
||||
|
||||
TArray<TPair<UObject*, float>> ScorifiedElements;
|
||||
|
||||
for (UObject* Element : Array)
|
||||
{
|
||||
TPair<UObject*, float> ScorifiedElement;
|
||||
ScorifiedElement.Key = Element;
|
||||
ScorifiedElement.Value = ScorifyElement(Element);
|
||||
ScorifiedElements.Add(ScorifiedElement);
|
||||
}
|
||||
return ScorifiedElements;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "Sorting/Predicates/DistanceSortPredicate.h"
|
||||
|
||||
|
||||
UDistanceSortPredicate::UDistanceSortPredicate()
|
||||
{
|
||||
bCanScorify = true;
|
||||
}
|
||||
|
||||
float UDistanceSortPredicate::ScorifyElement(UObject* Element) const
|
||||
{
|
||||
FVector Location;
|
||||
|
||||
if (IsValid(Element))
|
||||
{
|
||||
if (AActor* AsActor = Cast<AActor>(Element))
|
||||
Location = AsActor->GetActorLocation();
|
||||
else if (USceneComponent* AsSceneComponent = Cast<USceneComponent>(Element))
|
||||
Location = AsSceneComponent->GetComponentLocation();
|
||||
}
|
||||
else
|
||||
Location = FVector::ZeroVector;
|
||||
|
||||
return (Location - ComparisonPoint).SquaredLength();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "Sorting/Predicates/NameSortPredicate.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
|
||||
|
||||
UNameSortPredicate::UNameSortPredicate()
|
||||
{
|
||||
bCanScorify = false;
|
||||
}
|
||||
|
||||
bool UNameSortPredicate::Compare(UObject* Left, UObject* Right) const
|
||||
{
|
||||
const FString LeftName = UKismetSystemLibrary::GetDisplayName(Left);
|
||||
const FString RightName = UKismetSystemLibrary::GetDisplayName(Right);
|
||||
|
||||
return LeftName <= RightName;
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "Sorting/SortingFunctionLibrary.h"
|
||||
|
||||
void USortingFunctionLibrary::SortInPlace(TArray<UObject*>& Array, TSubclassOf<UObjectSortPredicate> PredicateClass)
|
||||
{
|
||||
if (!IsValid(PredicateClass))
|
||||
return;
|
||||
|
||||
UObjectSortPredicate *Predicate = NewObject<UObjectSortPredicate>(GetTransientPackage(), PredicateClass);
|
||||
SortInPlaceUsingPredicate(Array, Predicate);
|
||||
}
|
||||
|
||||
void USortingFunctionLibrary::SortInPlaceUsingPredicate(TArray<UObject*>& Array, UObjectSortPredicate* Predicate)
|
||||
{
|
||||
if (!IsValid(Predicate))
|
||||
return;
|
||||
|
||||
const bool bAscending = Predicate->bSortAscending;
|
||||
if (Predicate->CanScorify())
|
||||
{
|
||||
TArray<TPair<UObject*, float>> ScorifiedArray = Predicate->ScorifyArray(Array);
|
||||
|
||||
ScorifiedArray.Sort([bAscending](TPair<UObject*, float> Left, TPair<UObject*, float> Right) {
|
||||
return bAscending ? Left.Value <= Right.Value : Right.Value <= Left.Value;
|
||||
});
|
||||
|
||||
for (int i = 0; i < ScorifiedArray.Num(); i++)
|
||||
{
|
||||
Array[i] = ScorifiedArray[i].Key;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Sort([Predicate, bAscending](UObject& Left, UObject& Right) {
|
||||
return bAscending ? Predicate->Compare(&Left, &Right) : Predicate->Compare(&Right, &Left);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool USortingFunctionLibrary::IsArraySorted(const TArray<UObject*>& Array, TSubclassOf<UObjectSortPredicate> PredicateClass)
|
||||
{
|
||||
UObjectSortPredicate *Predicate = NewObject<UObjectSortPredicate>(GetTransientPackage(), PredicateClass);
|
||||
return IsArraySortedUsingPredicate(Array, Predicate);
|
||||
}
|
||||
|
||||
bool USortingFunctionLibrary::IsArraySortedUsingPredicate(const TArray<UObject*>& Array, UObjectSortPredicate* Predicate)
|
||||
{
|
||||
// Array of 0 or 1 element is always sorted
|
||||
if (Array.Num() <= 1)
|
||||
return true;
|
||||
|
||||
if (Predicate->CanScorify())
|
||||
{
|
||||
float PreviousElementScore = Predicate->ScorifyElement(Array[0]);
|
||||
for (int32 i = 1; i < Array.Num(); i++)
|
||||
{
|
||||
const float ElementScore = Predicate->ScorifyElement(Array[i]);
|
||||
|
||||
const bool bSorted = Predicate->bSortAscending ?
|
||||
PreviousElementScore <= ElementScore :
|
||||
ElementScore <= PreviousElementScore;
|
||||
|
||||
if (!bSorted)
|
||||
return false;
|
||||
|
||||
PreviousElementScore = ElementScore;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int32 i = 1; i < Array.Num(); i++)
|
||||
{
|
||||
const bool bSorted = Predicate->bSortAscending ?
|
||||
Predicate->Compare(Array[i - 1], Array[i]) :
|
||||
Predicate->Compare(Array[i], Array[i - 1]);
|
||||
|
||||
if (!bSorted)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Sort range */
|
||||
|
||||
TArray<UObject*> USortingFunctionLibrary::GetNMin(const TArray<UObject*>& Array, int32 N, TSubclassOf<UObjectSortPredicate> PredicateClass)
|
||||
{
|
||||
UObjectSortPredicate *Predicate = NewObject<UObjectSortPredicate>(GetTransientPackage(), PredicateClass);
|
||||
|
||||
return GetNMinUsingPredicate(Array, N, Predicate);
|
||||
}
|
||||
|
||||
TArray<UObject*> USortingFunctionLibrary::GetNMinUsingPredicate(const TArray<UObject*>& Array, int32 N, UObjectSortPredicate* Predicate)
|
||||
{
|
||||
TArray<UObject*> SortedArray(Array);
|
||||
|
||||
SortInPlaceUsingPredicate(SortedArray, Predicate);
|
||||
|
||||
if (SortedArray.Num() > N)
|
||||
SortedArray.SetNum(N, true);
|
||||
|
||||
return SortedArray;
|
||||
}
|
||||
|
||||
TArray<UObject*> USortingFunctionLibrary::GetNMax(const TArray<UObject*>& Array, int32 N, TSubclassOf<UObjectSortPredicate> PredicateClass)
|
||||
{
|
||||
UObjectSortPredicate *Predicate = NewObject<UObjectSortPredicate>(GetTransientPackage(), PredicateClass);
|
||||
|
||||
return GetNMaxUsingPredicate(Array, N, Predicate);
|
||||
}
|
||||
|
||||
TArray<UObject*> USortingFunctionLibrary::GetNMaxUsingPredicate(const TArray<UObject*>& Array, int32 N, UObjectSortPredicate* Predicate)
|
||||
{
|
||||
TArray<UObject*> SortedArray(Array);
|
||||
|
||||
SortInPlaceUsingPredicate(SortedArray, Predicate);
|
||||
|
||||
for (int32 i = 0; N + i - 1 < SortedArray.Num(); i++)
|
||||
{
|
||||
SortedArray[i] = SortedArray[N + i - 1];
|
||||
}
|
||||
|
||||
if (SortedArray.Num() > N)
|
||||
SortedArray.SetNum(N, true);
|
||||
|
||||
return SortedArray;
|
||||
}
|
||||
|
||||
|
||||
/** Cast */
|
||||
|
||||
TArray<UObject*>& USortingFunctionLibrary::CastArray(TArray<UObject*>& ObjectArray, TSubclassOf<UObject> NewClass, bool bSafe)
|
||||
{
|
||||
if (!bSafe)
|
||||
return ObjectArray;
|
||||
|
||||
for (UObject*& ElementPtr : ObjectArray)
|
||||
{
|
||||
if (IsValid(ElementPtr) && !ElementPtr->IsA(NewClass))
|
||||
ElementPtr = nullptr;
|
||||
}
|
||||
|
||||
return ObjectArray;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "UI/ControllableUserWidget.h"
|
||||
#include "Blueprint/WidgetTree.h"
|
||||
#include "UI/WidgetControllerComponent.h"
|
||||
#include "UI/WidgetController.h"
|
||||
|
||||
|
||||
UWidgetControllerComponent* UControllableUserWidget::GetComponentFromControllerByClass(TSubclassOf<UWidgetControllerComponent> ComponentClass) const
|
||||
{
|
||||
if (!WidgetController) return nullptr;
|
||||
|
||||
return WidgetController->GetComponentByClass(ComponentClass);
|
||||
}
|
||||
|
||||
void UControllableUserWidget::SetWidgetController(UWidgetController* NewWidgetController)
|
||||
{
|
||||
WidgetController = NewWidgetController;
|
||||
WidgetControllerSet(WidgetController);
|
||||
|
||||
PropagateWidgetController(this);
|
||||
}
|
||||
|
||||
bool UControllableUserWidget::AcceptWidgetController(UWidgetController* InWidgetController) const
|
||||
{
|
||||
// We accept invalid objects as widget controllers
|
||||
if (!InWidgetController || !InWidgetController->GetClass())
|
||||
return true;
|
||||
|
||||
// If we have no required class, we accept any of them
|
||||
if (AcceptedControllerClasses.IsEmpty())
|
||||
return true;
|
||||
|
||||
if (AcceptedControllerClasses.Contains(InWidgetController->GetClass()))
|
||||
return true;
|
||||
|
||||
for (TSubclassOf<UWidgetController> AcceptedControllerClass : AcceptedControllerClasses)
|
||||
{
|
||||
if (InWidgetController->GetClass()->IsChildOf(AcceptedControllerClass))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void UControllableUserWidget::PropagateWidgetController(UWidget* Parent)
|
||||
{
|
||||
TArray<UWidget*> AllWidgets;
|
||||
WidgetTree->GetAllWidgets(AllWidgets);
|
||||
for (UWidget* Widget : AllWidgets)
|
||||
{
|
||||
if (!IsValid(Widget)) continue;
|
||||
|
||||
if (UControllableUserWidget* ControlledWidget = Cast<UControllableUserWidget>(Widget))
|
||||
{
|
||||
if (ControlledWidget->TakeControllerFromParent && ControlledWidget->AcceptWidgetController(WidgetController))
|
||||
{
|
||||
ControlledWidget->SetWidgetController(WidgetController);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TArray<UWidget*> ChildWidgets;
|
||||
// UWidgetTree::GetChildWidgets(Parent, ChildWidgets);
|
||||
|
||||
// for (UWidget* ChildWidget : ChildWidgets)
|
||||
// {
|
||||
// if (UControllableUserWidget* ControlledWidget = Cast<UControllableUserWidget>(ChildWidget))
|
||||
// {
|
||||
// if (ControlledWidget->TakeControllerFromParent)
|
||||
// {
|
||||
// ControlledWidget->SetWidgetController(WidgetController);
|
||||
// PropagateWidgetController(ChildWidget);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// PropagateWidgetController(ChildWidget);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "UI/WidgetController.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "GameFramework/PlayerState.h"
|
||||
#include "GameFramework/Pawn.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "UI/WidgetControllerComponent.h"
|
||||
|
||||
|
||||
UWidgetController::UWidgetController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UWidgetController* UWidgetController::MakeWidgetController(UObject* Outer, TSubclassOf<UWidgetController> WidgetControllerClass, AActor* ObservedActor)
|
||||
{
|
||||
if (!IsValid(WidgetControllerClass))
|
||||
return nullptr;
|
||||
|
||||
UWidgetController* NewWidgetController = NewObject<UWidgetController>(Outer, WidgetControllerClass);
|
||||
|
||||
if (!IsValid(NewWidgetController))
|
||||
return nullptr;
|
||||
|
||||
NewWidgetController->Construct();
|
||||
NewWidgetController->BP_Construct();
|
||||
|
||||
if (IsValid(ObservedActor))
|
||||
NewWidgetController->SetObservedActor(ObservedActor, true);
|
||||
|
||||
return NewWidgetController;
|
||||
}
|
||||
|
||||
void UWidgetController::SetObservedController(AController* InController)
|
||||
{
|
||||
if (!IsValid(InController)) return;
|
||||
|
||||
Controller = InController;
|
||||
if (APlayerController* AsPC = Cast<APlayerController>(InController))
|
||||
PlayerState = AsPC->GetPlayerState<APlayerState>();
|
||||
else
|
||||
PlayerState = nullptr;
|
||||
Pawn = InController->GetPawn();
|
||||
Actor = InController;
|
||||
|
||||
FinishSetObserved();
|
||||
}
|
||||
|
||||
void UWidgetController::SetObservedPlayerState(APlayerState* InPlayerState)
|
||||
{
|
||||
if (!IsValid(InPlayerState)) return;
|
||||
|
||||
Controller = InPlayerState->GetPlayerController();
|
||||
PlayerState = InPlayerState;
|
||||
Pawn = InPlayerState->GetPawn();
|
||||
Actor = InPlayerState;
|
||||
|
||||
FinishSetObserved();
|
||||
}
|
||||
|
||||
void UWidgetController::SetObservedPawn(APawn* InPawn)
|
||||
{
|
||||
if (!IsValid(InPawn)) return;
|
||||
|
||||
Controller = InPawn->GetController();
|
||||
if (APlayerController* AsPC = Cast<APlayerController>(Controller))
|
||||
PlayerState = AsPC->GetPlayerState<APlayerState>();
|
||||
else
|
||||
PlayerState = nullptr;
|
||||
Pawn = InPawn;
|
||||
Actor = InPawn;
|
||||
|
||||
FinishSetObserved();
|
||||
}
|
||||
|
||||
void UWidgetController::SetObservedActor(AActor* InActor, bool bTryCast)
|
||||
{
|
||||
if (!IsValid(InActor)) return;
|
||||
|
||||
if (bTryCast)
|
||||
{
|
||||
if (AController* AsPC = Cast<AController>(InActor))
|
||||
{
|
||||
return SetObservedController(AsPC);
|
||||
}
|
||||
else if (APlayerState* AsPS = Cast<APlayerState>(InActor))
|
||||
{
|
||||
return SetObservedPlayerState(AsPS);
|
||||
}
|
||||
else if (APawn* AsPawn = Cast<APawn>(InActor))
|
||||
{
|
||||
return SetObservedPawn(AsPawn);
|
||||
}
|
||||
}
|
||||
|
||||
Controller = nullptr;
|
||||
PlayerState = nullptr;
|
||||
Pawn = nullptr;
|
||||
Actor = InActor;
|
||||
|
||||
FinishSetObserved();
|
||||
}
|
||||
|
||||
void UWidgetController::BroadcastValues()
|
||||
{
|
||||
for (UWidgetControllerComponent* Component : Components)
|
||||
{
|
||||
Component->BroadcastValues();
|
||||
}
|
||||
BP_BroadcastValues();
|
||||
}
|
||||
|
||||
void UWidgetController::BindCallbacksToDependencies()
|
||||
{
|
||||
for (UWidgetControllerComponent* Component : Components)
|
||||
{
|
||||
Component->BindCallbacksToDependencies();
|
||||
}
|
||||
}
|
||||
|
||||
UWidgetControllerComponent* UWidgetController::GetComponentByClass(TSubclassOf<UWidgetControllerComponent> ComponentClass) const
|
||||
{
|
||||
for (UWidgetControllerComponent* Component : Components)
|
||||
{
|
||||
if (Component->IsA(ComponentClass))
|
||||
{
|
||||
return Component;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UWidgetControllerComponent* UWidgetController::GetComponentByClassAndName(TSubclassOf<UWidgetControllerComponent> ComponentClass, FName ComponentName) const
|
||||
{
|
||||
for (UWidgetControllerComponent* Component : Components)
|
||||
{
|
||||
if (Component->IsA(ComponentClass) && Component->GetFName() == ComponentName)
|
||||
{
|
||||
return Component;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TArray<UWidgetControllerComponent*> UWidgetController::GetComponentsByClass(TSubclassOf<UWidgetControllerComponent> ComponentClass) const
|
||||
{
|
||||
TArray<UWidgetControllerComponent*> ComponentsList;
|
||||
for (UWidgetControllerComponent* Component : Components)
|
||||
{
|
||||
if (Component->IsA(ComponentClass))
|
||||
{
|
||||
ComponentsList.Add(Component);
|
||||
}
|
||||
}
|
||||
return ComponentsList;
|
||||
}
|
||||
|
||||
UWidgetControllerComponent* UWidgetController::AddComponentByClass(TSubclassOf<UWidgetControllerComponent> ComponentClass, FName ComponentName)
|
||||
{
|
||||
UWidgetControllerComponent* NewComponent = NewObject<UWidgetControllerComponent>(this, ComponentClass, ComponentName);
|
||||
Components.Add(NewComponent);
|
||||
return NewComponent;
|
||||
}
|
||||
|
||||
void UWidgetController::FinishSetObserved()
|
||||
{
|
||||
ObservedActorSet();
|
||||
BP_ObservedActorSet();
|
||||
|
||||
BindCallbacksToDependencies();
|
||||
BP_BindCallbacksToDependencies();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "UI/WidgetControllerComponent.h"
|
||||
|
||||
void UWidgetControllerComponent::BroadcastValues()
|
||||
{
|
||||
BP_BroadcastValues();
|
||||
}
|
||||
|
||||
void UWidgetControllerComponent::BindCallbacksToDependencies()
|
||||
{
|
||||
BP_BindCallbacksToDependencies();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Amasson
|
||||
|
||||
|
||||
#include "UI/WidgetControllerComponents/GameManagementWcc.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
|
||||
void UGameManagementWcc::Initialize(UObject* InWorldContextObject)
|
||||
{
|
||||
WorldContextObject = InWorldContextObject;
|
||||
}
|
||||
|
||||
|
||||
/** GameplayStatics */
|
||||
|
||||
void UGameManagementWcc::OpenLevel(FName LevelName, bool bAbsolute, FString Options)
|
||||
{
|
||||
UGameplayStatics::OpenLevel(WorldContextObject, LevelName, bAbsolute, Options);
|
||||
}
|
||||
|
||||
void UGameManagementWcc::OpenLevelBySoftObjectPtr(const TSoftObjectPtr<UWorld> Level, bool bAbsolute, FString Options)
|
||||
{
|
||||
UGameplayStatics::OpenLevelBySoftObjectPtr(WorldContextObject, Level, bAbsolute, Options);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Animation/AnimInstance.h"
|
||||
#include "CharacterMovementAnimInstance.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class LIBAMASSON_API UCharacterMovementAnimInstance : public UAnimInstance
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
virtual void NativeInitializeAnimation() override;
|
||||
virtual void NativeUpdateAnimation(float DeltaTime) override;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, Category = Movement)
|
||||
class UCharacterMovementComponent* CharacterMovementComponent;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = Movement)
|
||||
FVector LocalVelocity;
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe), Category = Movement)
|
||||
bool IsPawnMoving() const;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = Movement)
|
||||
float LocalVelocityAngle = 0;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = Movement)
|
||||
float TurnVelocity = 0;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = Movement)
|
||||
bool bFalling = false;
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe), Category = Movement)
|
||||
bool IsJumpingUp() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe), Category = Movement)
|
||||
bool IsFallingDown() const;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = Movement)
|
||||
bool bCrouching = false;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = Movement)
|
||||
bool bSwimming = false;
|
||||
|
||||
|
||||
private:
|
||||
float _PreviousYaw = 0;
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/InterpToMovementComponent.h"
|
||||
#include "NetInterpToMovementComponent.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(ClassGroup=Movement, meta=(BlueprintSpawnableComponent),HideCategories=Velocity)
|
||||
class LIBAMASSON_API UNetInterpToMovementComponent : public UInterpToMovementComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UNetInterpToMovementComponent();
|
||||
virtual ~UNetInterpToMovementComponent();
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Network")
|
||||
float MovementUpdatePeriod = 5.0f;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual void BeginPlay();
|
||||
|
||||
UPROPERTY()
|
||||
FTimerHandle TimerHandle_BroadcastMovement;
|
||||
|
||||
UFUNCTION()
|
||||
void BroadcastMovement();
|
||||
|
||||
UFUNCTION(NetMulticast, Reliable, Category = "Network")
|
||||
void NetMulticast_UpdateMovement(const FVector& Location, float InCurrentTime, float InCurrentDirection, bool bInIsWaiting, bool bInStopped);
|
||||
|
||||
};
|
||||
15
Plugins/LibAmasson/Source/LibAmasson/Public/LibAmasson.h
Normal file
15
Plugins/LibAmasson/Source/LibAmasson/Public/LibAmasson.h
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
class FLibAmassonModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
|
||||
/** IModuleInterface implementation */
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
};
|
||||
43
Plugins/LibAmasson/Source/LibAmasson/Public/MathLibrary.h
Normal file
43
Plugins/LibAmasson/Source/LibAmasson/Public/MathLibrary.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
#include "MathLibrary.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class LIBAMASSON_API UMathLibrary : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Math|Trace")
|
||||
static void GetTraceForward(USceneComponent* Component, double Distance, FVector& StartPoint, FVector& EndPoint);
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Math|Trace")
|
||||
static void TraceClampDistance(const FVector& StartPoint, const FVector& EndPoint, double MinDistance, double MaxDistance, FVector& NewStartPoint, FVector& NewEndPoint);
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Math|Vector")
|
||||
static FVector AddLengthToVector(FVector Vector, double Length);
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Math|Vector")
|
||||
static FVector SetLengthToVector(FVector Vector, double Length);
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Math|Vector")
|
||||
static TArray<FVector> TransformPoints(const TArray<FVector>& Points, const FTransform& Transform);
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Math|Vector")
|
||||
static TArray<FTransform> TransformTransforms(const TArray<FTransform>& Transforms, const FTransform& Transform);
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Math|Vector")
|
||||
static void ArcPoints(float ArcAngle, int32 Count, float Distance, TArray<FVector>& Points);
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Math|Vector")
|
||||
static void ArcTransforms(float ArcAngle, int32 Count, float Distance, TArray<FTransform>& Transforms);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/NoExportTypes.h"
|
||||
#include "ObjectSortPredicate.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(Abstract, Blueprintable, BlueprintType)
|
||||
class LIBAMASSON_API UObjectSortPredicate : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
virtual bool Compare(UObject* Left, UObject* Right) const;
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, DisplayName = "Compare", Category = "Sorting")
|
||||
bool BP_Compare(UObject* Left, UObject* Right) const;
|
||||
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sort", meta = (ExposeOnSpawn = true))
|
||||
bool bSortAscending = true;
|
||||
|
||||
/** Scorify */
|
||||
|
||||
FORCEINLINE float CanScorify() const { return bCanScorify; }
|
||||
|
||||
virtual float ScorifyElement(UObject* Element) const;
|
||||
|
||||
/** CanScorify must be activated for this function to be used */
|
||||
UFUNCTION(BlueprintImplementableEvent, DisplayName = "ScorifyElement", Category = "Score")
|
||||
float BP_ScorifyElement(UObject* Element) const;
|
||||
|
||||
TArray<TPair<UObject*, float>> ScorifyArray(const TArray<UObject*>& Array) const;
|
||||
|
||||
protected:
|
||||
|
||||
/** When activated, the sort algorithm will not use the Compare function,
|
||||
* but Instead, will attribute a float value to each elements using the
|
||||
* ScorifyElement function and sort them with this value.
|
||||
* Allowing us to do performance intensive calculations only once per
|
||||
* elements like calculating a distance from a point.
|
||||
*/
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Score")
|
||||
bool bCanScorify = false;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Sorting/ObjectSortPredicate.h"
|
||||
#include "DistanceSortPredicate.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(BlueprintType)
|
||||
class LIBAMASSON_API UDistanceSortPredicate : public UObjectSortPredicate
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UDistanceSortPredicate();
|
||||
|
||||
virtual float ScorifyElement(UObject* Element) const override;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Distance", meta = (ExposeOnSpawn = true))
|
||||
FVector ComparisonPoint;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Sorting/ObjectSortPredicate.h"
|
||||
#include "NameSortPredicate.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(BlueprintType)
|
||||
class LIBAMASSON_API UNameSortPredicate : public UObjectSortPredicate
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UNameSortPredicate();
|
||||
|
||||
virtual bool Compare(UObject* Left, UObject* Right) const override;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
#include "Sorting/ObjectSortPredicate.h"
|
||||
#include "SortingFunctionLibrary.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class LIBAMASSON_API USortingFunctionLibrary : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Sort")
|
||||
static void SortInPlace(UPARAM(Ref) TArray<UObject*>& Array, TSubclassOf<UObjectSortPredicate> PredicateClass);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Sort")
|
||||
static void SortInPlaceUsingPredicate(UPARAM(Ref) TArray<UObject*>& Array, UObjectSortPredicate* Predicate);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Sort")
|
||||
static bool IsArraySorted(const TArray<UObject*>& Array, TSubclassOf<UObjectSortPredicate> PredicateClass);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Sort")
|
||||
static bool IsArraySortedUsingPredicate(const TArray<UObject*>& Array, UObjectSortPredicate* Predicate);
|
||||
|
||||
|
||||
/** Sort range */
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Sort")
|
||||
static TArray<UObject*> GetNMin(const TArray<UObject*>& Array, int32 N, TSubclassOf<UObjectSortPredicate> PredicateClass);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Sort")
|
||||
static TArray<UObject*> GetNMinUsingPredicate(const TArray<UObject*>& Array, int32 N, UObjectSortPredicate* Predicate);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Sort")
|
||||
static TArray<UObject*> GetNMax(const TArray<UObject*>& Array, int32 N, TSubclassOf<UObjectSortPredicate> PredicateClass);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Sort")
|
||||
static TArray<UObject*> GetNMaxUsingPredicate(const TArray<UObject*>& Array, int32 N, UObjectSortPredicate* Predicate);
|
||||
|
||||
|
||||
/** Cast */
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Array", meta = (DeterminesOutputType = "NewClass"))
|
||||
static TArray<UObject*>& CastArray(UPARAM(Ref) TArray<UObject*>& ObjectArray, TSubclassOf<UObject> NewClass, bool bSafe = false);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "ControllableUserWidget.generated.h"
|
||||
|
||||
class UWidgetController;
|
||||
class UWidgetControllerComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class LIBAMASSON_API UControllableUserWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "Controller|Component", meta = (DeterminesOutputType = "ComponentClass"))
|
||||
UWidgetControllerComponent* GetComponentFromControllerByClass(TSubclassOf<UWidgetControllerComponent> ComponentClass) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Controller")
|
||||
void SetWidgetController(UWidgetController* NewWidgetController);
|
||||
|
||||
protected:
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Controller")
|
||||
void WidgetControllerSet(UWidgetController* NewWidgetController);
|
||||
|
||||
UFUNCTION(Category = "Controller|Propagation")
|
||||
virtual bool AcceptWidgetController(UWidgetController* InWidgetController) const;
|
||||
|
||||
private:
|
||||
|
||||
UFUNCTION()
|
||||
void PropagateWidgetController(UWidget* Parent);
|
||||
|
||||
protected:
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Controller", meta = (AllowPrivateAccess = true))
|
||||
TObjectPtr<UWidgetController> WidgetController;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Controller|Propagation")
|
||||
bool TakeControllerFromParent = true;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Controller|Propagation")
|
||||
TSet<TSubclassOf<UWidgetController>> AcceptedControllerClasses;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,139 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/NoExportTypes.h"
|
||||
#include "UI/WidgetControllerComponent.h"
|
||||
#include "WidgetController.generated.h"
|
||||
|
||||
|
||||
class AController;
|
||||
class APlayerState;
|
||||
class APawn;
|
||||
class ACharacter;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(BlueprintType, Blueprintable)
|
||||
class LIBAMASSON_API UWidgetController : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UWidgetController();
|
||||
|
||||
/** Make and construct a widget controller from the specific class.
|
||||
* If there is an observed actor given, it will cast it to the correct type and
|
||||
* call SetObserved_X with it.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "WidgetController|Construct", meta = (HidePin = "Outer", DefaultToSelf = "Outer"), meta = (DeterminesOutputType = "WidgetControllerClass"))
|
||||
static UWidgetController* MakeWidgetController(UObject* Outer, TSubclassOf<UWidgetController> WidgetControllerClass, AActor* ObservedActor);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Observed")
|
||||
virtual void SetObservedController(AController* InController);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Observed")
|
||||
virtual void SetObservedPlayerState(APlayerState* InPlayerState);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Observed")
|
||||
virtual void SetObservedPawn(APawn* InPawn);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Observed")
|
||||
virtual void SetObservedActor(AActor* InActor, bool bTryCast = false);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Broadcast")
|
||||
virtual void BroadcastValues();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Observed")
|
||||
FORCEINLINE AController* GetController() const { return Controller; }
|
||||
UFUNCTION(BlueprintCallable, Category = "Observed")
|
||||
FORCEINLINE APlayerState* GetPlayerState() const { return PlayerState; }
|
||||
UFUNCTION(BlueprintCallable, Category = "Observed")
|
||||
FORCEINLINE APawn* GetPawn() const { return Pawn; }
|
||||
UFUNCTION(BlueprintCallable, Category = "Observed")
|
||||
AActor* GetObservedActor() const { return Actor; }
|
||||
|
||||
template<class TComponentType>
|
||||
TComponentType* GetComponent()
|
||||
{
|
||||
static_assert(std::is_base_of<UWidgetControllerComponent, TComponentType>::value, "TComponentType must be a subclass of UWidgetControllerComponent.");
|
||||
|
||||
for (UWidgetControllerComponent* Component : Components)
|
||||
{
|
||||
if (TComponentType* CastComponent = Cast<TComponentType>(Component))
|
||||
{
|
||||
return CastComponent;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Component", meta = (DeterminesOutputType = "ComponentClass"))
|
||||
UWidgetControllerComponent* GetComponentByClass(TSubclassOf<UWidgetControllerComponent> ComponentClass) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Component", meta = (DeterminesOutputType = "ComponentClass"))
|
||||
UWidgetControllerComponent* GetComponentByClassAndName(TSubclassOf<UWidgetControllerComponent> ComponentClass, FName ComponentName) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Component", meta = (DeterminesOutputType = "ComponentClass"))
|
||||
TArray<UWidgetControllerComponent*> GetComponentsByClass(TSubclassOf<UWidgetControllerComponent> ComponentClass) const;
|
||||
|
||||
template<class TComponentType>
|
||||
TComponentType* AddComponent(FName ComponentName)
|
||||
{
|
||||
static_assert(std::is_base_of<UWidgetControllerComponent, TComponentType>::value, "TComponentType must be a subclass of UWidgetControllerComponent.");
|
||||
|
||||
TComponentType* NewComponent = NewObject<TComponentType>(this, TComponentType::StaticClass(), ComponentName);
|
||||
Components.Add(NewComponent);
|
||||
return NewComponent;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Component", meta = (DeterminesOutputType = "ComponentClass"))
|
||||
UWidgetControllerComponent* AddComponentByClass(TSubclassOf<UWidgetControllerComponent> ComponentClass, FName ComponentName);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
UFUNCTION()
|
||||
virtual void Construct() {}
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Construction", DisplayName = "Construct")
|
||||
void BP_Construct();
|
||||
|
||||
UFUNCTION()
|
||||
virtual void ObservedActorSet() {}
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Observed", DisplayName = "ObservedActorSet")
|
||||
void BP_ObservedActorSet();
|
||||
|
||||
UFUNCTION()
|
||||
virtual void BindCallbacksToDependencies();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Broadcast", DisplayName = "BindCallbacksToDependencies")
|
||||
void BP_BindCallbacksToDependencies();
|
||||
|
||||
/** Called at the end of controller SetObserved_X */
|
||||
UFUNCTION(BlueprintCallable, Category = "Observed")
|
||||
void FinishSetObserved();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Broadcast", DisplayName = "BroadcastValues")
|
||||
void BP_BroadcastValues();
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "WidgetController")
|
||||
TObjectPtr<AController> Controller;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "WidgetController")
|
||||
TObjectPtr<APlayerState> PlayerState;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "WidgetController")
|
||||
TObjectPtr<APawn> Pawn;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "WidgetController")
|
||||
TObjectPtr<AActor> Actor;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<TObjectPtr<UWidgetControllerComponent>> Components;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/NoExportTypes.h"
|
||||
#include "WidgetControllerComponent.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(Abstract, Blueprintable)
|
||||
class LIBAMASSON_API UWidgetControllerComponent : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Broadcast")
|
||||
virtual void BroadcastValues();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Broadcast", DisplayName = "BroadcastValues")
|
||||
void BP_BroadcastValues();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
UFUNCTION()
|
||||
virtual void BindCallbacksToDependencies();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Bind", DisplayName = "BindCallbacksToDependencies")
|
||||
void BP_BindCallbacksToDependencies();
|
||||
|
||||
friend class UWidgetController;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
// Amasson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UI/WidgetControllerComponent.h"
|
||||
#include "GameManagementWcc.generated.h"
|
||||
|
||||
|
||||
class APlayerController;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class LIBAMASSON_API UGameManagementWcc : public UWidgetControllerComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Initialize")
|
||||
void Initialize(UObject* WorldContextObject);
|
||||
|
||||
|
||||
/** GameplayStatics */
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(AdvancedDisplay = "2", DisplayName = "Open Level (by Name)"), Category="Game")
|
||||
void OpenLevel(FName LevelName, bool bAbsolute = true, FString Options = FString(TEXT("")));
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(AdvancedDisplay = "2", DisplayName = "Open Level (by Object Reference)"), Category="Game")
|
||||
void OpenLevelBySoftObjectPtr(const TSoftObjectPtr<UWorld> Level, bool bAbsolute = true, FString Options = FString(TEXT("")));
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<UObject> WorldContextObject;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user