Compare commits

..

No commits in common. 'e8e6d37dad6b033640145cb004df45a906845444' and 'cd94fbc07ff9c19cc3f4297893ed1197b1f8b912' have entirely different histories.

@ -1,10 +1,7 @@
[/Script/EngineSettings.GeneralProjectSettings]
ProjectID=D68B8A08410D0195272328B9EAD1AE41
bShouldWindowPreserveAspectRatio=False
bUseBorderlessWindow=False
[StartupActions]
bAddPacks=True
InsertPack=(PackSource="StarterContent.upack",PackName="StarterContent")

@ -19,7 +19,6 @@ ABattleGameMode::ABattleGameMode()
void ABattleGameMode::BeginPlay() {
Super::BeginPlay();
// UGameplayStatics::PlaySound2D(GetWorld(), BackgroundSound);
}
auto ABattleGameMode::GetMyGameState() const {
@ -35,10 +34,10 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
uint8 TrooperCount = 0;
TArray<const TCHAR *> bpPaths{
TEXT("Blueprint'/Game/Troopers/TrooperWizard.TrooperWizard_C'"),
TEXT(
"Blueprint'/Game/Troopers/TrooperSkeletonMelee.TrooperSkeletonMelee_C'"
)
),
TEXT("Blueprint'/Game/Troopers/TrooperWizard.TrooperWizard_C'")
};
// TArray<UClass *> LoadedBpAssets;
for (int i = 0; i < bpPaths.Num(); ++i) {
@ -52,7 +51,7 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
FTransform SpawnLocationAndRotation(Rotation);
SpawnLocationAndRotation.SetLocation(Location);
AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
LoadedBpAssets[FirstPlayerTrooperKinds[i]], SpawnLocationAndRotation);
LoadedBpAssets[i % 2], SpawnLocationAndRotation);
// AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
// ATrooper::StaticClass(), SpawnLocationAndRotation);
Cast<ATrooper>(Spawned)->Initialize(
@ -69,7 +68,7 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
FTransform SpawnLocationAndRotation(Rotation);
SpawnLocationAndRotation.SetLocation(Location);
AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
LoadedBpAssets[SecondPlayerTrooperKinds[i]], SpawnLocationAndRotation);
LoadedBpAssets[i % 2], SpawnLocationAndRotation);
// AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
// ATrooper::StaticClass(), SpawnLocationAndRotation);
Cast<ATrooper>(Spawned)->Initialize(
@ -79,6 +78,11 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
GetMyGameState()->AddTrooper(Cast<ATrooper>(Spawned));
Location += {0.f, 500.f, 0.0f};
}
} else {
// Cast<ASinglePlayerGS>(GetMyGameState())->GetEnemyAIController()->
// SetTrooperAssetsAndSpawn(
// LoadedBpAssets,
// TrooperCount);
}
}
@ -133,19 +137,8 @@ void ABattleGameMode::PostLogin(APlayerController *NewPlayer) {
// 0-indexation
Cast<ABattlePlayerController>(NewPlayer)->SetPlayerIndex(
CurrentNumberOfPlayers - 1);
Cast<ABattlePlayerController>(NewPlayer)->
StartPlayingMusic(BackgroundSound);
if (CurrentNumberOfPlayers == 1)
{
FirstPlayerTrooperKinds = Cast<ABattlePlayerController>(NewPlayer)->TrooperKinds;
} else if (CurrentNumberOfPlayers == 2)
{
SecondPlayerTrooperKinds = Cast<ABattlePlayerController>(NewPlayer)->TrooperKinds;
}
UE_LOG(LogTemp, Warning, TEXT("%d"), CurrentNumberOfPlayers);
if (!bIsMultiplayer || CurrentNumberOfPlayers == 2) {
if (CurrentNumberOfPlayers == 2) {
UE_LOG(LogTemp, Warning, TEXT("Game Start"));
// start the game
// dynamic_cast<AMyGameState *>(

@ -27,21 +27,12 @@ public:
// void CycleTurns();
protected:
UPROPERTY(BlueprintReadWrite, EditAnywhere)
USoundBase *BackgroundSound;
UPROPERTY()
TArray<UClass *> LoadedBpAssets;
UPROPERTY()
bool bIsMultiplayer = true;
UPROPERTY()
TArray<uint8> FirstPlayerTrooperKinds;
UPROPERTY()
TArray<uint8> SecondPlayerTrooperKinds;
void InitializeSpawnPointsIfNeeded(AController *Player);
UFUNCTION(Server, Reliable)

@ -7,27 +7,19 @@
#include "BattlePlayerState.h"
#include "Blueprint/UserWidget.h"
#include "Net/UnrealNetwork.h"
#include "TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.h"
ABattlePlayerController::ABattlePlayerController()
: Super()/*, bIsMyTurn(false), SelectedTrooper(nullptr)*/ {
UE_LOG(LogTemp, Warning, TEXT("Player controller created"));
SetShowMouseCursor(true);
PlayerIndex = 0;
if (UGameplayStatics::DoesSaveGameExist("Selected troopers", 0)) {
const USelectedTrooperSaveGame *SaveGameInstance = Cast<
USelectedTrooperSaveGame>(
UGameplayStatics::LoadGameFromSlot(TEXT("Selected troopers"), 0));
TrooperKinds = SaveGameInstance->SelectedTroopers;
} else {
TrooperKinds = {0, 0, 0, 0, 0};
}
}
void ABattlePlayerController::BeginPlay() {
Super::BeginPlay();
CreateBattleWidget();
UUserWidget *CreatedWidget = CreateWidget<UUserWidget>(
GetWorld(), WidgetClass);
CreatedWidget->AddToViewport();
}
void ABattlePlayerController::SetupInputComponent() {
@ -72,9 +64,8 @@ void ABattlePlayerController::EndTurn_Implementation() {
// GetMyGameState()->CycleTurns();
// }
// GetMyPlayerState()->CycleTurns();
if (GetMyGameState()->IsInTurn(PlayerIndex)) {
if (GetMyGameState()->IsInTurn(PlayerIndex))
GetMyGameState()->CycleTurns();
}
}
// void AMyPlayerController::EndTurn_Implementation() {
@ -156,25 +147,6 @@ uint8 ABattlePlayerController::GetPlayerIndex() const {
return PlayerIndex;
}
void ABattlePlayerController::CreateBattleWidget_Implementation() {
BattleWidget = CreateWidget<UBattleUI>(
GetWorld(), WidgetClass);
BattleWidget->AddToViewport();
// GetPlayerState<ABattlePlayerState>()->SetBattleWidget(BattleWidget);
}
void ABattlePlayerController::SetWidgetTurn_Implementation(bool bIsMyTurn) {
if (BattleWidget) {
BattleWidget->SetWhoseTurnText(bIsMyTurn);
}
}
void ABattlePlayerController::StartPlayingMusic_Implementation(
USoundBase *BackgroundSound) const {
UGameplayStatics::PlaySound2D(GetWorld(), BackgroundSound, 0.25f);
}
// float AMyPlayerController::SetCurrentActionAndReturnRadius(int action) {
// return GetMyPlayerState()->SetCurrentActionAndReturnRadius(action);
//

@ -2,7 +2,6 @@
#pragma once
#include "CoreMinimal.h"
#include "BattleUI.h"
#include "GameFramework/PlayerController.h"
#include "BattlePlayerController.generated.h"
@ -51,22 +50,7 @@ public:
// UFUNCTION(Client, Reliable)
// void SetEnemySelection(const TArray<ATrooper *> &Troopers) const;
UFUNCTION(Client, Reliable)
void StartPlayingMusic(USoundBase *BackgroundSound) const;
UFUNCTION(Client, Reliable)
void SetWidgetTurn(bool bIsMyTurn);
UPROPERTY()
TArray<uint8> TrooperKinds;
private:
UFUNCTION(Client, Reliable)
void CreateBattleWidget();
UPROPERTY()
UBattleUI *BattleWidget;
UPROPERTY(EditAnywhere)
TSubclassOf<UUserWidget> WidgetClass;

@ -39,11 +39,6 @@ void ABattlePlayerState::SetPlayerIndex(uint8 NewPlayerIndex) {
PlayerIndex = NewPlayerIndex;
}
// void ABattlePlayerState::
// SetBattleWidget_Implementation(UBattleUI *BattleWidget) {
// BattleUI = BattleWidget;
// }
void ABattlePlayerState::GameOver_Implementation(int PlayerLoseIndex) {
UGameOverWidget *CreatedWidget = CreateWidget<UGameOverWidget>(
GetWorld(), GameOverWidgetClass);
@ -66,7 +61,7 @@ void ABattlePlayerState::SetEnemySelection_Implementation(
}
void ABattlePlayerState::MoveTrooper_Implementation(ATrooper *Trooper,
FVector Location) {
FVector Location) {
Location.Z = 0.0f;
if (Trooper->CheckMoveCorrectness(Location)) {
Trooper->MoveTrooper(Location);
@ -92,8 +87,8 @@ void ABattlePlayerState::MoveTrooper_Implementation(ATrooper *Trooper,
// }
void ABattlePlayerState::Attack_Implementation(ATrooper *Attacker,
FVector Location,
int ActionIndex) {
FVector Location,
int ActionIndex) {
if (Attacker->CheckAttackCorrectness(Location, ActionIndex)) {
Attacker->Attack(ActionIndex, Location);
// for (const auto Trooper : Troopers) {
@ -121,14 +116,12 @@ bool ABattlePlayerState::IsMyTurn() const {
void ABattlePlayerState::SetMyTurn(bool bMyTurn) {
bIsMyTurn = bMyTurn;
Cast<ABattlePlayerController>(GetWorld()->GetFirstPlayerController())->
SetWidgetTurn(bIsMyTurn);
// if (bIsMyTurn) {
// GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green,
// FString::Printf(
// TEXT("CURRENT TURN: %d"),
// PlayerIndex));
// }
if (bIsMyTurn) {
GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green,
FString::Printf(
TEXT("CURRENT TURN: %d"),
PlayerIndex));
}
}
void ABattlePlayerState::StartTurn_Implementation() {
@ -146,7 +139,6 @@ void ABattlePlayerState::EndTurn_Implementation() {
SelectedTrooper = nullptr;
}
UE_LOG(LogTemp, Warning, TEXT("Not your turn, %d"), PlayerIndex);
// AMyGameMode *gameMode = GetMyGameMode();
// gameMode->CycleTurns();
// Cast<AMyGameState>(GetWorld()->GetGameState())->CycleTurns();
@ -164,9 +156,8 @@ void ABattlePlayerState::OnPlayerAction(const FHitResult &HitResult) {
return;
}
if (HitResult.GetActor()->ActorHasTag(FName("Floor")) ||
NewlySelectedTrooper != nullptr &&
NewlySelectedTrooper->GetPlayerIndex() !=
if (NewlySelectedTrooper == nullptr || !NewlySelectedTrooper->
IsValidLowLevel() || NewlySelectedTrooper->GetPlayerIndex() !=
PlayerIndex) {
if (SelectedTrooper != nullptr && SelectedTrooper->
IsValidLowLevel()) {

@ -4,7 +4,6 @@
#include "Trooper/Trooper.h"
#include "CoreMinimal.h"
#include "BattlePlayerController.h"
#include "GameFramework/PlayerState.h"
#include "BattlePlayerState.generated.h"
@ -60,13 +59,7 @@ public:
UFUNCTION(Client, Reliable)
void GameOver(int PlayerLoseIndex);
// UFUNCTION(Client, Reliable)
// void SetBattleWidget(UBattleUI *BattleWidget);
protected:
// UPROPERTY()
// UBattleUI *BattleUI;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<UUserWidget> GameOverWidgetClass;

@ -1,63 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "BattleUI.h"
#include "Components/Button.h"
#include "Components/TextBlock.h"
#include "BattlePlayerController.h"
#include "BattlePlayerState.h"
void UBattleUI::NativeConstruct() {
Super::NativeConstruct();
EndTurnButton->OnClicked.AddDynamic(this, &ThisClass::OnEndTurnClicked);
ButtonAction_0->OnClicked.AddDynamic(this, &ThisClass::OnActionSwitched_0);
ButtonAction_1->OnClicked.AddDynamic(this, &ThisClass::OnActionSwitched_1);
ButtonAction_2->OnClicked.AddDynamic(this, &ThisClass::OnActionSwitched_2);
}
void UBattleUI::SetWidgetText_Implementation(const FString &Text) {
InformationText->SetText(FText::FromString(Text));
}
void UBattleUI::SetWhoseTurnText_Implementation(bool IsThisPlayerTurn) {
if (IsThisPlayerTurn) {
SetWidgetText(TEXT("Your turn!"));
} else {
SetWidgetText(TEXT("Opponent's turn"));
}
}
void UBattleUI::OnEndTurnClicked() {
Cast<ABattlePlayerController>(GetWorld()->GetFirstPlayerController())->
EndTurn();
}
void UBattleUI::OnActionSwitched_0() {
ButtonAction_0->SetIsEnabled(false);
ButtonAction_1->SetIsEnabled(true);
ButtonAction_2->SetIsEnabled(true);
ActionType = 0;
OnActionSwitched();
}
void UBattleUI::OnActionSwitched_1() {
ButtonAction_0->SetIsEnabled(true);
ButtonAction_1->SetIsEnabled(false);
ButtonAction_2->SetIsEnabled(true);
ActionType = 1;
OnActionSwitched();
}
void UBattleUI::OnActionSwitched_2() {
ButtonAction_0->SetIsEnabled(true);
ButtonAction_1->SetIsEnabled(true);
ButtonAction_2->SetIsEnabled(false);
ActionType = 2;
OnActionSwitched();
}
void UBattleUI::OnActionSwitched() const {
Cast<ABattlePlayerController>(GetWorld()->GetFirstPlayerController())->
GetPlayerState<ABattlePlayerState>()->SetCurrentAction(ActionType);
}

@ -1,58 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "BattleUI.generated.h"
/**
*
*/
UCLASS()
class TURNBASEDTUTORIAL_API UBattleUI : public UUserWidget {
GENERATED_BODY()
public:
virtual void NativeConstruct() override;
UFUNCTION(Client, Reliable)
void SetWhoseTurnText(bool IsThisPlayerTurn);
UFUNCTION(Client, Reliable)
void SetWidgetText(const FString &Text);
protected:
int ActionType = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget))
class UButton *EndTurnButton;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget))
class UButton *ButtonAction_0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget))
class UButton *ButtonAction_1;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget))
class UButton *ButtonAction_2;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget))
class UTextBlock *InformationText;
UFUNCTION()
void OnEndTurnClicked();
UFUNCTION()
void OnActionSwitched_0();
UFUNCTION()
void OnActionSwitched_1();
UFUNCTION()
void OnActionSwitched_2();
UFUNCTION()
void OnActionSwitched() const;
};

@ -2,7 +2,6 @@
#include "SinglePlayerGM.h"
#include "SinglePlayerGS.h"
#include "TurnBasedTutorial/BattleMode/BattlePlayerController.h"
ASinglePlayerGM::ASinglePlayerGM()
: Super() {
@ -13,12 +12,10 @@ ASinglePlayerGM::ASinglePlayerGM()
void ASinglePlayerGM::BeginPlay() {
Super::BeginPlay();
UE_LOG(LogTemp, Warning, TEXT("SinglePlayer GameMode BeginPlay"));
// GameStateClass = ASinglePlayerGS::StaticClass();
// StartGame();
GameStateClass = ASinglePlayerGS::StaticClass();
StartGame();
}
// void ASinglePlayerGM::PostLogin(APlayerController *NewPlayer) {
// AGameMode::PostLogin(NewPlayer);
// Cast<ABattlePlayerController>(NewPlayer)->
// StartPlayingMusic(BackgroundSound);
// }
void ASinglePlayerGM::PostLogin(APlayerController *NewPlayer) {
AGameMode::PostLogin(NewPlayer);
}

@ -18,5 +18,5 @@ public:
virtual void BeginPlay() override;
// virtual void PostLogin(APlayerController *NewPlayer) override;
virtual void PostLogin(APlayerController *NewPlayer) override;
};

@ -42,8 +42,8 @@ AProjectile::AProjectile() {
}
void AProjectile::Initialize(const UAbility *Ability,
uint8 playerIndex,
float PathLength) {
uint8 playerIndex,
float PathLength) {
ProjectileMovementComponent->InitialSpeed =
ProjectileMovementComponent->MaxSpeed = Ability->Speed;
Damage = Ability->Damage;
@ -69,16 +69,9 @@ void AProjectile::NotifyActorBeginOverlap(AActor *OtherActor) {
),
OtherTrooper->GetId(), OtherTrooper->GetPlayerIndex(), Damage,
PlayerIndex);
if (Damage > 0) {
if (PlayerIndex != -1 && PlayerIndex != OtherTrooper->
GetPlayerIndex()) {
OtherTrooper->TrooperTakeDamage(Damage);
}
} else {
if (PlayerIndex != -1 && PlayerIndex == OtherTrooper->
GetPlayerIndex()) {
OtherTrooper->TrooperTakeDamage(Damage);
}
if (PlayerIndex != -1 && PlayerIndex != OtherTrooper->
GetPlayerIndex()) {
OtherTrooper->TrooperTakeDamage(Damage);
}
} else {
UE_LOG(LogTemp, Warning, TEXT("Overlapped not a trooper"));

@ -308,20 +308,15 @@ void ATrooper::TrooperTakeDamage_Implementation(float Damage) {
if (bIsTakingDamage || bIsDead) {
return;
}
if (Damage > 0) {
HitPoints = FMath::Max<float>(0, HitPoints - Damage);
if (HitPoints == 0) {
bIsDead = true;
SetLifeSpan(DyingAnimationDuration);
GetWorld()->GetGameState<ABattleGameState>()->
DecreaseLivingTroopers(
PlayerIndex);
} else {
// bIsTakingDamage = true;
SetIsTakingDamage(true);
}
HitPoints = FMath::Max<float>(0, HitPoints - Damage);
if (HitPoints == 0) {
bIsDead = true;
SetLifeSpan(DyingAnimationDuration);
GetWorld()->GetGameState<ABattleGameState>()->DecreaseLivingTroopers(
PlayerIndex);
} else {
HitPoints = FMath::Min<float>(StartHitPoints, HitPoints - Damage);
// bIsTakingDamage = true;
SetIsTakingDamage(true);
}
}

@ -12,19 +12,18 @@ void UMainMenuWidget::NativeConstruct() {
this, &ThisClass::UMainMenuWidget::OnHostOnlineGameButtonClicked);
GetMyGameSubsystem()->OnCreateSessionCompleteEvent.AddDynamic(
this, &ThisClass::StartSessionWhenCreatingSessionComplete);
this, &ThisClass::StartSessionWhenCreatingSessonComplete);
}
void UMainMenuWidget::OnHostOnlineGameButtonClicked() {
// Ensure we have left any session
GetMyGameSubsystem()->DestroySession();
const FString SessionName = "Lobby " + FString::FromInt(
FMath::RandRange(1, 1e6));
GetMyGameSubsystem()->CreateSession(SessionName, 2, true);
GetMyGameSubsystem()->CreateSession(
"Lobby " + FString::FromInt(FMath::RandRange(1, 1e6)), 2, true);
}
void UMainMenuWidget::StartSessionWhenCreatingSessionComplete(bool bSuccess) {
void UMainMenuWidget::StartSessionWhenCreatingSessonComplete(bool bSuccess) {
if (!bSuccess) {
return;
}

@ -26,7 +26,7 @@ protected:
void OnHostOnlineGameButtonClicked();
UFUNCTION()
void StartSessionWhenCreatingSessionComplete(bool bSuccess);
void StartSessionWhenCreatingSessonComplete(bool bSuccess);
private:
USessionsGameInstanceSubsystem *GetMyGameSubsystem() const;

@ -4,18 +4,10 @@
#include "SessionListEntryWidget.h"
#include "OnlineSessionSettings.h"
#include "Components/TextBlock.h"
#include "Components/Button.h"
#include "Kismet/GameplayStatics.h"
void USessionListEntryWidget::NativeConstruct() {
Super::NativeConstruct();
JoinSessionButton->OnClicked.AddDynamic(
this, &ThisClass::OnJoinButton);
}
void USessionListEntryWidget::Update(int SessionIndex,
const FOnlineSessionSearchResult &
Session) {
const FOnlineSessionSearchResult &
Session) {
SessionId = SessionIndex;
IndexText->SetText(FText::AsNumber(SessionIndex + 1));
@ -30,16 +22,3 @@ void USessionListEntryWidget::Update(int SessionIndex,
PlayersCountText->SetText(FText::AsNumber(CurPlayerCount));
PingText->SetText(FText::AsNumber(Session.PingInMs));
}
void USessionListEntryWidget::OnJoinButton() {
GetMyGameSubsystem()->JoinSession(SessionId);
}
USessionsGameInstanceSubsystem *
USessionListEntryWidget::GetMyGameSubsystem() const {
const UGameInstance *GameInstance = UGameplayStatics::GetGameInstance(
GetWorld());
USessionsGameInstanceSubsystem *GameInstanceSubsystem = GameInstance->
GetSubsystem<USessionsGameInstanceSubsystem>();
return GameInstanceSubsystem;
}

@ -3,7 +3,6 @@
#pragma once
#include "CoreMinimal.h"
#include "../SessionsGameInstanceSubsystem.h"
#include "Blueprint/UserWidget.h"
#include "SessionListEntryWidget.generated.h"
@ -15,8 +14,6 @@ class TURNBASEDTUTORIAL_API USessionListEntryWidget : public UUserWidget {
GENERATED_BODY()
public:
virtual void NativeConstruct() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget))
class UTextBlock *IndexText;
@ -29,18 +26,8 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget))
class UTextBlock *PingText;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget))
class UButton *JoinSessionButton;
void Update(int SessionIndex, const FOnlineSessionSearchResult &Session);
protected:
int SessionId;
FString SessionName;
USessionsGameInstanceSubsystem *GetMyGameSubsystem() const;
UFUNCTION()
void OnJoinButton();
};

@ -13,8 +13,8 @@ void USessionListWidget::NativeConstruct() {
RefreshListButton->OnClicked.AddDynamic(
this, &ThisClass::OnRefreshListButtonClicked);
// ConnectToSelectedSessionButton->OnClicked.AddDynamic(
// this, &ThisClass::ConnectToFirstSession);
ConnectToSelectedSessionButton->OnClicked.AddDynamic(
this, &ThisClass::ConnectToFirstSession);
const auto MyGameInstanceSubsystem = GetMyGameSubsystem();
MyGameInstanceSubsystem->OnFindSessionsCompleteEvent.AddUObject(
@ -54,9 +54,9 @@ void USessionListWidget::OnRefreshListButtonClicked() {
GetMyGameSubsystem()->FindSessions(10, true);
}
// void USessionListWidget::ConnectToFirstSession() {
// GetMyGameSubsystem()->JoinSession(0);
// }
void USessionListWidget::ConnectToFirstSession() {
GetMyGameSubsystem()->JoinSession(0);
}
void USessionListWidget::OnJoinSessionSuccess(

@ -17,8 +17,8 @@ class TURNBASEDTUTORIAL_API USessionListWidget : public UUserWidget {
protected:
virtual void NativeConstruct() override;
// UPROPERTY(meta = (BindWidget))
// class UButton *ConnectToSelectedSessionButton;
UPROPERTY(meta = (BindWidget))
class UButton *ConnectToSelectedSessionButton;
UPROPERTY(meta = (BindWidget))
class UButton *GoBackToMainMenuButton;
@ -43,6 +43,6 @@ private:
UFUNCTION()
void OnRefreshListButtonClicked();
// UFUNCTION()
// void ConnectToFirstSession();
UFUNCTION()
void ConnectToFirstSession();
};

@ -2,48 +2,10 @@
#include "ManageSquadGameState.h"
#include "ManageSquadTrooper.h"
#include "SelectedTrooperSaveGame.h"
#include "Kismet/GameplayStatics.h"
void AManageSquadGameState::BeginPlay() {
// USelectedTrooperSaveGame *SaveGameInstance = Cast<USelectedTrooperSaveGame>(
// 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();
AManageSquadGameState::AManageSquadGameState() {
TroopersKinds = {0, 0, 0, 0, 0};
}
void AManageSquadGameState::ChangeSquad(int TrooperIndex, int TrooperKind) {
TroopersKinds[TrooperIndex] = TrooperKind;
}
TArray<uint8> 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<AManageSquadTrooper>(
TroopersBpAssets[TroopersKinds[index]], SpawnLocationAndRotation);
Cast<AManageSquadTrooper>(Spawned)->Initialize(index);
Spawned->SetActorRelativeScale3D({1.5f, 1.5f, 1.5f});
Spawned->FinishSpawning(SpawnLocationAndRotation);
Spawned->SetActorLocation(Location);
}
Location += {DeltaX, 0.f, 0.0f};
}
}

@ -14,21 +14,12 @@ class TURNBASEDTUTORIAL_API AManageSquadGameState : public AGameState {
GENERATED_BODY()
public:
virtual void BeginPlay() override;
AManageSquadGameState();
UFUNCTION()
void ChangeSquad(int TrooperIndex, int TrooperKind);
UFUNCTION()
TArray<uint8> GetSquad() const;
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<UClass *> TroopersBpAssets;
UFUNCTION()
void InitializeTroopers() const;
private:
UPROPERTY()
TArray<uint8> TroopersKinds;
TArray<int> TroopersKinds;
};

@ -3,7 +3,6 @@
#include "ManageSquadPlayerController.h"
#include "ManageSquadGameState.h"
#include "ManageSquadWidget.h"
AManageSquadPlayerController::AManageSquadPlayerController() {
SetShowMouseCursor(true);
@ -15,19 +14,6 @@ void AManageSquadPlayerController::SetupInputComponent() {
&AManageSquadPlayerController::OnLeftMouseClick);
}
void AManageSquadPlayerController::BeginPlay() {
Super::BeginPlay();
const TSoftClassPtr<UUserWidget> WidgetClass = TSoftClassPtr<
UUserWidget>(FSoftObjectPath(
"WidgetBlueprint'/Game/ManageSquadMenu/BP_ManageSquadWidget.BP_ManageSquadWidget_C'"
));
UUserWidget *CreatedWidget = CreateWidget<UUserWidget>(
GetWorld(), WidgetClass.LoadSynchronous());
if (CreatedWidget) {
CreatedWidget->AddToViewport();
}
}
void AManageSquadPlayerController::OnLeftMouseClick() {
UE_LOG(LogTemp, Warning, TEXT("Mouse clicked"));
FHitResult HitResult;

@ -20,8 +20,6 @@ public:
virtual void SetupInputComponent() override;
virtual void BeginPlay() override;
private:
UPROPERTY()
AManageSquadTrooper *SelectedTrooper;

@ -29,8 +29,3 @@ ETrooperType AManageSquadTrooper::GetType() const {
int AManageSquadTrooper::GetIndex() const {
return Index;
}
void AManageSquadTrooper::Initialize(int TrooperIndex) {
Index = TrooperIndex;
Type = ETrooperType::TROOPER_IN_SQUAD;
}

@ -40,7 +40,4 @@ public:
UFUNCTION()
int GetIndex() const;
UFUNCTION()
void Initialize(int TrooperIndex);
};

@ -1,27 +0,0 @@
// 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"
void UManageSquadWidget::NativeConstruct() {
Super::NativeConstruct();
BackButton->OnClicked.AddDynamic(
this, &ThisClass::UManageSquadWidget::OnBackButtonClicked);
}
void UManageSquadWidget::OnBackButtonClicked() {
USelectedTrooperSaveGame *SaveGameInstance = Cast<USelectedTrooperSaveGame>(
UGameplayStatics::CreateSaveGameObject(
USelectedTrooperSaveGame::StaticClass()));
SaveGameInstance->SelectedTroopers = GetWorld()->GetGameState<
AManageSquadGameState>()->GetSquad();
UGameplayStatics::SaveGameToSlot(
SaveGameInstance,TEXT("Selected troopers"), 0);
UGameplayStatics::OpenLevel(GetWorld(), "MainMenuLevel");
RemoveFromParent();
}

@ -1,25 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "ManageSquadWidget.generated.h"
/**
*
*/
UCLASS()
class TURNBASEDTUTORIAL_API UManageSquadWidget : public UUserWidget {
GENERATED_BODY()
public:
virtual void NativeConstruct() override;
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget))
class UButton *BackButton;
UFUNCTION()
void OnBackButtonClicked();
};

@ -1,8 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "SelectedTrooperSaveGame.h"
USelectedTrooperSaveGame::USelectedTrooperSaveGame()
: Super() {
}

@ -1,21 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/SaveGame.h"
#include "SelectedTrooperSaveGame.generated.h"
/**
*
*/
UCLASS()
class TURNBASEDTUTORIAL_API USelectedTrooperSaveGame : public USaveGame {
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category=Basic)
TArray<uint8> SelectedTroopers;
USelectedTrooperSaveGame();
};

@ -1,6 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "{B4FE6467-4579-3D84-B22A-558A3D607596}",
"EngineAssociation": "4.27",
"Category": "",
"Description": "",
"Modules": [

Loading…
Cancel
Save