diff --git a/Content/ManageSquadMenu/BP_MSMelee.uasset b/Content/ManageSquadMenu/BP_MSMelee.uasset new file mode 100644 index 0000000..2750e12 Binary files /dev/null and b/Content/ManageSquadMenu/BP_MSMelee.uasset differ diff --git a/Content/ManageSquadMenu/BP_MSWizard.uasset b/Content/ManageSquadMenu/BP_MSWizard.uasset new file mode 100644 index 0000000..8064ccb Binary files /dev/null and b/Content/ManageSquadMenu/BP_MSWizard.uasset differ diff --git a/Content/ManageSquadMenu/BP_ManageSquadGameMode.uasset b/Content/ManageSquadMenu/BP_ManageSquadGameMode.uasset new file mode 100644 index 0000000..5521ae6 Binary files /dev/null and b/Content/ManageSquadMenu/BP_ManageSquadGameMode.uasset differ diff --git a/Content/ManageSquadMenu/BP_ManageSquadGameState.uasset b/Content/ManageSquadMenu/BP_ManageSquadGameState.uasset new file mode 100644 index 0000000..6bfe6b5 Binary files /dev/null and b/Content/ManageSquadMenu/BP_ManageSquadGameState.uasset differ diff --git a/Content/ManageSquadMenu/ManageSquadLevel.umap b/Content/ManageSquadMenu/ManageSquadLevel.umap index fca80b0..b8a61c3 100644 Binary files a/Content/ManageSquadMenu/ManageSquadLevel.umap and b/Content/ManageSquadMenu/ManageSquadLevel.umap differ diff --git a/Source/TurnBasedTutorial/ManageSquad/ManageSquadGameState.cpp b/Source/TurnBasedTutorial/ManageSquad/ManageSquadGameState.cpp index da48053..8d20f22 100644 --- a/Source/TurnBasedTutorial/ManageSquad/ManageSquadGameState.cpp +++ b/Source/TurnBasedTutorial/ManageSquad/ManageSquadGameState.cpp @@ -2,10 +2,48 @@ #include "ManageSquadGameState.h" -AManageSquadGameState::AManageSquadGameState() { - TroopersKinds = {0, 0, 0, 0, 0}; +#include "ManageSquadTrooper.h" +#include "SelectedTrooperSaveGame.h" +#include "Kismet/GameplayStatics.h" + +void AManageSquadGameState::BeginPlay() { + // USelectedTrooperSaveGame *SaveGameInstance = Cast( + // UGameplayStatics::CreateSaveGameObject( + // USelectedTrooperSaveGame::StaticClass())); + if (UGameplayStatics::DoesSaveGameExist("Selected troopers", 0)) { + const USelectedTrooperSaveGame *SaveGameInstance = Cast< + USelectedTrooperSaveGame>( + UGameplayStatics::LoadGameFromSlot(TEXT("Selected troopers"), 0)); + TroopersKinds = SaveGameInstance->SelectedTroopers; + } else { + TroopersKinds = {0, 0, 0, 0, 0}; + } + InitializeTroopers(); } void AManageSquadGameState::ChangeSquad(int TrooperIndex, int TrooperKind) { TroopersKinds[TrooperIndex] = TrooperKind; } + +TArray AManageSquadGameState::GetSquad() const { + return TroopersKinds; +} + +void AManageSquadGameState::InitializeTroopers() const { + FVector Location(-1150.0f, -2850.0f, 3000.0f); + const FRotator Rotation(0.0f, 90.0f, 0.0f); + for (int index = 0; index < 5; ++index) { + constexpr float DeltaX = 500.0f; + FTransform SpawnLocationAndRotation(Rotation); + SpawnLocationAndRotation.SetLocation(Location); + if (TroopersBpAssets.Num() > TroopersKinds[index]) { + AActor *Spawned = GetWorld()->SpawnActorDeferred( + TroopersBpAssets[TroopersKinds[index]], SpawnLocationAndRotation); + Cast(Spawned)->Initialize(index); + Spawned->SetActorRelativeScale3D({1.5f, 1.5f, 1.5f}); + Spawned->FinishSpawning(SpawnLocationAndRotation); + Spawned->SetActorLocation(Location); + } + Location += {DeltaX, 0.f, 0.0f}; + } +} diff --git a/Source/TurnBasedTutorial/ManageSquad/ManageSquadGameState.h b/Source/TurnBasedTutorial/ManageSquad/ManageSquadGameState.h index 1198780..ede79cc 100644 --- a/Source/TurnBasedTutorial/ManageSquad/ManageSquadGameState.h +++ b/Source/TurnBasedTutorial/ManageSquad/ManageSquadGameState.h @@ -14,12 +14,21 @@ class TURNBASEDTUTORIAL_API AManageSquadGameState : public AGameState { GENERATED_BODY() public: - AManageSquadGameState(); + virtual void BeginPlay() override; UFUNCTION() void ChangeSquad(int TrooperIndex, int TrooperKind); -private: + UFUNCTION() + TArray GetSquad() const; + +protected: + UPROPERTY(EditAnywhere, BlueprintReadWrite) + TArray TroopersBpAssets; + + UFUNCTION() + void InitializeTroopers() const; + UPROPERTY() - TArray TroopersKinds; + TArray TroopersKinds; }; diff --git a/Source/TurnBasedTutorial/ManageSquad/ManageSquadTrooper.cpp b/Source/TurnBasedTutorial/ManageSquad/ManageSquadTrooper.cpp index 3e140f4..40bf7fe 100644 --- a/Source/TurnBasedTutorial/ManageSquad/ManageSquadTrooper.cpp +++ b/Source/TurnBasedTutorial/ManageSquad/ManageSquadTrooper.cpp @@ -29,3 +29,8 @@ ETrooperType AManageSquadTrooper::GetType() const { int AManageSquadTrooper::GetIndex() const { return Index; } + +void AManageSquadTrooper::Initialize(int TrooperIndex) { + Index = TrooperIndex; + Type = ETrooperType::TROOPER_IN_SQUAD; +} diff --git a/Source/TurnBasedTutorial/ManageSquad/ManageSquadTrooper.h b/Source/TurnBasedTutorial/ManageSquad/ManageSquadTrooper.h index 2da243b..783da94 100644 --- a/Source/TurnBasedTutorial/ManageSquad/ManageSquadTrooper.h +++ b/Source/TurnBasedTutorial/ManageSquad/ManageSquadTrooper.h @@ -40,4 +40,7 @@ public: UFUNCTION() int GetIndex() const; + + UFUNCTION() + void Initialize(int TrooperIndex); }; diff --git a/Source/TurnBasedTutorial/ManageSquad/ManageSquadWidget.cpp b/Source/TurnBasedTutorial/ManageSquad/ManageSquadWidget.cpp index f68b47d..724860d 100644 --- a/Source/TurnBasedTutorial/ManageSquad/ManageSquadWidget.cpp +++ b/Source/TurnBasedTutorial/ManageSquad/ManageSquadWidget.cpp @@ -1,6 +1,9 @@ // Fill out your copyright notice in the Description page of Project Settings. #include "ManageSquadWidget.h" + +#include "ManageSquadGameState.h" +#include "SelectedTrooperSaveGame.h" #include "Components/Button.h" #include "Kismet/GameplayStatics.h" @@ -12,6 +15,13 @@ void UManageSquadWidget::NativeConstruct() { } void UManageSquadWidget::OnBackButtonClicked() { + USelectedTrooperSaveGame *SaveGameInstance = Cast( + UGameplayStatics::CreateSaveGameObject( + USelectedTrooperSaveGame::StaticClass())); + SaveGameInstance->SelectedTroopers = GetWorld()->GetGameState< + AManageSquadGameState>()->GetSquad(); + UGameplayStatics::SaveGameToSlot( + SaveGameInstance,TEXT("Selected troopers"), 0); UGameplayStatics::OpenLevel(GetWorld(), "MainMenuLevel"); RemoveFromParent(); } diff --git a/Source/TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.cpp b/Source/TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.cpp index 4324d33..0d483c6 100644 --- a/Source/TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.cpp +++ b/Source/TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.cpp @@ -3,8 +3,6 @@ #include "SelectedTrooperSaveGame.h" -USelectedTrooperSaveGame::USelectedTrooperSaveGame(): Super() -{ - +USelectedTrooperSaveGame::USelectedTrooperSaveGame() + : Super() { } - diff --git a/Source/TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.h b/Source/TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.h index aa7410e..1f533e9 100644 --- a/Source/TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.h +++ b/Source/TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.h @@ -10,13 +10,12 @@ * */ UCLASS() -class TURNBASEDTUTORIAL_API USelectedTrooperSaveGame : public USaveGame -{ - GENERATED_BODY() +class TURNBASEDTUTORIAL_API USelectedTrooperSaveGame : public USaveGame { + GENERATED_BODY() public: - UPROPERTY(EditAnywhere, Category=Basic) - TArray SelectedTroopers; + UPROPERTY(EditAnywhere, Category=Basic) + TArray SelectedTroopers; - USelectedTrooperSaveGame(); + USelectedTrooperSaveGame(); };