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" #include "Loot.h"
ULoot::ULoot() void ULoot::Init_Implementation(AGameStateBase* GameState, APlayerController* PlayerController)
{
}
void ULoot::Init_Implementation(AGameStateBase* GameState)
{ {
} }

@ -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) 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; return;
} }
} }
} }
TMap<UUnitInfo*, int32> UPartySubsystem::GetMembers() TArray<FPartyMember> UPartySubsystem::GetMembers()
{ {
return Members; 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->VerticalSpacing = InVerticalSpacing;
this->HorizontalOffset = InHorizontalOffset; this->HorizontalOffset = InHorizontalOffset;
this->NumRows = InNumRows; this->NumRows = InNumRows;
this->HorizontalSpacing = InHorizontalSpacing;
GetMembers().KeySort([](const UUnitInfo& A, const UUnitInfo& B) for (FPartyMember &Unit : GetMembers())
{ {
return A.GetTier() < B.GetTier(); for(auto i = 0; i < GetMemberAllocated(Unit); i++)
});
for (TPair<UUnitInfo*, int32> &Unit : GetMembers())
{ {
for(auto i = 0; i < Unit.Value; i++) SpawnQueue.Add(GetMemberUnitInfo(Unit)->GetCharacterClass());
{
SpawnQueue.Add(Unit.Key->GetCharacterClass());
} }
} }
auto NumUnits= SpawnQueue.Num(); const auto NumUnits= SpawnQueue.Num();
SpawnUnits(); SpawnUnits();
GetWorld()->GetTimerManager().SetTimer( GetWorld()->GetTimerManager().SetTimer(
@ -61,9 +63,94 @@ void UPartySubsystem::SpawnUnits()
GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle); GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle);
return; 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; 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")) 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 // Exit from old state
switch (CurrentState) switch (CurrentState)

@ -3,13 +3,13 @@
#include "WaveSubsystem.h" #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; CurrentWave = CurrWave;
Waves = InWaves; 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; NumRows = InNumRows;
HorizontalOffset = InHorizontalOffset; HorizontalOffset = InHorizontalOffset;

@ -13,10 +13,8 @@ class SPACEBATTLER_API ULoot : public UObject
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
ULoot();
UFUNCTION(BlueprintCallable, Blueprintable, BlueprintNativeEvent) UFUNCTION(BlueprintCallable, Blueprintable, BlueprintNativeEvent)
void Init(AGameStateBase* GameState); void Init(AGameStateBase* GameState, APlayerController* PlayerController);
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
FText Name; 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 #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "PartyMember.h"
#include "UnitInfo.h" #include "UnitInfo.h"
#include "Subsystems/LocalPlayerSubsystem.h" #include "Subsystems/LocalPlayerSubsystem.h"
#include "PartySubsystem.generated.h" #include "PartySubsystem.generated.h"
@ -10,19 +11,52 @@
/** /**
* *
*/ */
UCLASS() UCLASS(meta=(ShowWorldContextPin))
class SPACEBATTLER_API UPartySubsystem : public ULocalPlayerSubsystem class SPACEBATTLER_API UPartySubsystem : public UGameInstanceSubsystem
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
UFUNCTION(BlueprintCallable) 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) UFUNCTION(BlueprintCallable)
void AddToParty(UUnitInfo* UnitInfo); void AddToParty(UUnitInfo* UnitInfo);
UFUNCTION(BlueprintCallable) 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: protected:
void SpawnUnits(); void SpawnUnits();
@ -31,14 +65,19 @@ protected:
TArray<TSubclassOf<AActor>> SpawnQueue; TArray<TSubclassOf<AActor>> SpawnQueue;
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
TMap<UUnitInfo*, int32> Members; TArray<FPartyMember> Members;
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
UPrimaryDataAsset* SelectedGeneral; UPrimaryDataAsset* SelectedGeneral;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
int32 Credits;
FTimerHandle SpawnTimerHandle; FTimerHandle SpawnTimerHandle;
int32 LastSpawnIndex; int32 LastSpawnIndex;
int32 NumRows; int32 NumRows;
int32 CurrentColumn;
float HorizontalOffset; float HorizontalOffset;
float VerticalSpacing; float VerticalSpacing;
float HorizontalSpacing;
}; };

Loading…
Cancel
Save