Added state machine workflow through prebattle menu

feature/refactor_menus
Jers 12 months ago
parent 6417d6644f
commit 3a536e646a

BIN
Content/Blueprints/BP_GameState.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

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
Content/Levels/MainMenu.umap (Stored with Git LFS)

Binary file not shown.

@ -3,11 +3,7 @@
#include "Loot.h"
ULoot::ULoot()
{
}
void ULoot::Init_Implementation(AGameStateBase* GameState)
void ULoot::Init_Implementation(AGameStateBase* GameState, APlayerController* PlayerController)
{
}

@ -0,0 +1,14 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "PartyMember.h"
FPartyMember::FPartyMember()
{
UnitInfo = nullptr;
}
FPartyMember::FPartyMember(UUnitInfo* InUnitInfo)
{
UnitInfo = InUnitInfo;
}

@ -5,41 +5,43 @@
void UPartySubsystem::AddToParty(UUnitInfo* UnitInfo)
{
for (TPair<UUnitInfo*, int32> &Unit : Members)
for (FPartyMember &Unit : Members)
{
if(Unit.Key->GetClass() == UnitInfo->GetClass())
if(GetMemberUnitInfo(Unit)->GetClass() == UnitInfo->GetClass())
{
Unit.Value++;
const bool UpdateAllocated = GetMemberAvailable(Unit) == GetMemberAllocated(Unit);
SetMemberAvailable(Unit, GetMemberAvailable(Unit) + 1);
if (UpdateAllocated)
{
AllocateMember(Unit);
}
return;
}
}
}
TMap<UUnitInfo*, int32> UPartySubsystem::GetMembers()
TArray<FPartyMember> UPartySubsystem::GetMembers()
{
return Members;
}
int32 UPartySubsystem::SpawnParty(float InVerticalSpacing, float InHorizontalOffset, int InNumRows)
int32 UPartySubsystem::SpawnParty(const float InVerticalSpacing, const float InHorizontalOffset, const float InHorizontalSpacing, const int InNumRows)
{
this->VerticalSpacing = InVerticalSpacing;
this->HorizontalOffset = InHorizontalOffset;
this->NumRows = InNumRows;
GetMembers().KeySort([](const UUnitInfo& A, const UUnitInfo& B)
{
return A.GetTier() < B.GetTier();
});
this->HorizontalSpacing = InHorizontalSpacing;
for (TPair<UUnitInfo*, int32> &Unit : GetMembers())
for (FPartyMember &Unit : GetMembers())
{
for(auto i = 0; i < Unit.Value; i++)
for(auto i = 0; i < GetMemberAllocated(Unit); i++)
{
SpawnQueue.Add(Unit.Key->GetCharacterClass());
SpawnQueue.Add(GetMemberUnitInfo(Unit)->GetCharacterClass());
}
}
auto NumUnits= SpawnQueue.Num();
const auto NumUnits= SpawnQueue.Num();
SpawnUnits();
GetWorld()->GetTimerManager().SetTimer(
@ -61,9 +63,94 @@ void UPartySubsystem::SpawnUnits()
GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle);
return;
}
FVector Location = FVector(VerticalSpacing * i - VerticalSpacing, -HorizontalOffset, 0);
GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex], &Location);
FActorSpawnParameters SpawnActorParameters = {};
SpawnActorParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
FVector Location = FVector( VerticalSpacing * i - VerticalSpacing, -HorizontalOffset, 0);
GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex], &Location, nullptr, SpawnActorParameters);
}
LastSpawnIndex += NumRows;
CurrentColumn++;
}
TArray<UUnitInfo*> UPartySubsystem::GetUnitsByTier(const int32 Tier) const
{
TArray<UUnitInfo*> TierMembers;
for(FPartyMember Member : Members)
{
if(GetMemberUnitInfo(Member)->GetTier() == Tier)
{
TierMembers.Add(GetMemberUnitInfo(Member));
}
}
return TierMembers;
}
void UPartySubsystem::SetCredits(const int32 Amount)
{
Credits = Amount;
}
bool UPartySubsystem::AllocateMember(FPartyMember& Member)
{
Member.Allocated++;
if(Member.Allocated > Member.Available)
{
Member.Allocated = Member.Available;
return false;
}
return true;
}
bool UPartySubsystem::DeallocateMember(FPartyMember& Member)
{
Member.Allocated--;
if (Member.Allocated < 0)
{
Member.Allocated = 0;
return false;
}
return true;
}
void UPartySubsystem::SetMemberMax(FPartyMember& Member)
{
Member.Allocated = Member.Available;
}
void UPartySubsystem::ClearMember(FPartyMember& Member)
{
Member.Allocated = 0;
}
int32 UPartySubsystem::GetMemberAllocated(FPartyMember& Member) const
{
return Member.Allocated;
}
int32 UPartySubsystem::GetMemberAvailable(FPartyMember& Member) const
{
return Member.Available;
}
void UPartySubsystem::SetMemberAvailable(FPartyMember& Member, int32 const Amount)
{
Member.Available = Amount;
}
void UPartySubsystem::SetMemberUnitInfo(FPartyMember& Member, UUnitInfo* InUnitInfo)
{
Member.UnitInfo = InUnitInfo;
}
UUnitInfo* UPartySubsystem::GetMemberUnitInfo(FPartyMember& Member) const
{
return Member.UnitInfo;
}

@ -10,7 +10,7 @@ void UStateMachineSubsystem::Initialize(FSubsystemCollectionBase& Collection)
UE_LOG(LogTemp, Display, TEXT("Starting game state machine in MAINMENU state"))
}
bool UStateMachineSubsystem::ChangeState(EGameState NewState)
bool UStateMachineSubsystem::ChangeState(const EGameState NewState)
{
// Exit from old state
switch (CurrentState)

@ -3,13 +3,13 @@
#include "WaveSubsystem.h"
void UWaveSubsystem::Init(TArray<UWave*> InWaves, int32 CurrWave = 0)
void UWaveSubsystem::Init(const TArray<UWave*> InWaves, const int32 CurrWave = 0)
{
CurrentWave = CurrWave;
Waves = InWaves;
}
int32 UWaveSubsystem::SpawnWave(float InVerticalSpacing, float InHorizontalOffset, int InNumRows)
int32 UWaveSubsystem::SpawnWave(const float InVerticalSpacing, const float InHorizontalOffset, const int InNumRows)
{
NumRows = InNumRows;
HorizontalOffset = InHorizontalOffset;

@ -13,10 +13,8 @@ class SPACEBATTLER_API ULoot : public UObject
{
GENERATED_BODY()
public:
ULoot();
UFUNCTION(BlueprintCallable, Blueprintable, BlueprintNativeEvent)
void Init(AGameStateBase* GameState);
void Init(AGameStateBase* GameState, APlayerController* PlayerController);
UPROPERTY(BlueprintReadWrite, EditAnywhere)
FText Name;

@ -0,0 +1,28 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UnitInfo.h"
#include "PartyMember.generated.h"
/**
*
*/
USTRUCT(Blueprintable, BlueprintType)
struct SPACEBATTLER_API FPartyMember
{
GENERATED_BODY()
FPartyMember();
explicit FPartyMember(UUnitInfo* InUnitInfo);
UPROPERTY(BlueprintReadWrite)
UUnitInfo* UnitInfo = nullptr;
UPROPERTY(BlueprintReadOnly)
int32 Available = 0;
UPROPERTY(BlueprintReadOnly)
int32 Allocated = 0;
};

@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "PartyMember.h"
#include "UnitInfo.h"
#include "Subsystems/LocalPlayerSubsystem.h"
#include "PartySubsystem.generated.h"
@ -10,19 +11,52 @@
/**
*
*/
UCLASS()
class SPACEBATTLER_API UPartySubsystem : public ULocalPlayerSubsystem
UCLASS(meta=(ShowWorldContextPin))
class SPACEBATTLER_API UPartySubsystem : public UGameInstanceSubsystem
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
int32 SpawnParty(float VerticalSpacing, float HorizontalOffset, int NumRows);
int32 SpawnParty(const float InVerticalSpacing, const float InHorizontalOffset, const float InHorizontalSpacing, const int InNumRows);
UFUNCTION(BlueprintCallable)
void AddToParty(UUnitInfo* UnitInfo);
UFUNCTION(BlueprintCallable)
TMap<UUnitInfo*, int32> GetMembers();
TArray<FPartyMember> GetMembers();
UFUNCTION(BlueprintCallable)
TArray<UUnitInfo*> GetUnitsByTier(const int32 Tier) const;
UFUNCTION(BlueprintCallable)
void SetCredits(int32 Amount);
UFUNCTION(BlueprintCallable)
void SetMemberUnitInfo(FPartyMember& Member, UUnitInfo* UnitInfo);
UFUNCTION(BlueprintCallable)
bool AllocateMember(FPartyMember& Member);
UFUNCTION(BlueprintCallable)
bool DeallocateMember(FPartyMember& Member);
UFUNCTION(BlueprintCallable)
void SetMemberMax(FPartyMember& Member);
UFUNCTION(BlueprintCallable)
void ClearMember(FPartyMember& Member);
UFUNCTION(BlueprintCallable)
void SetMemberAvailable(FPartyMember& Member,int32 const Amount);
UFUNCTION(BlueprintCallable)
int32 GetMemberAvailable(FPartyMember& Member) const;
UFUNCTION(BlueprintCallable)
int32 GetMemberAllocated(FPartyMember& Member) const;
UFUNCTION(BlueprintCallable)
UUnitInfo* GetMemberUnitInfo(FPartyMember& Member) const;
protected:
void SpawnUnits();
@ -31,14 +65,19 @@ protected:
TArray<TSubclassOf<AActor>> SpawnQueue;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
TMap<UUnitInfo*, int32> Members;
TArray<FPartyMember> Members;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UPrimaryDataAsset* SelectedGeneral;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
int32 Credits;
FTimerHandle SpawnTimerHandle;
int32 LastSpawnIndex;
int32 NumRows;
int32 CurrentColumn;
float HorizontalOffset;
float VerticalSpacing;
float HorizontalSpacing;
};

Loading…
Cancel
Save