diff --git a/Content/BattleField/BattleFieldMap.umap b/Content/BattleField/BattleFieldMap.umap index fae5c30..edac1f0 100644 Binary files a/Content/BattleField/BattleFieldMap.umap and b/Content/BattleField/BattleFieldMap.umap differ diff --git a/Content/MainMenu/MainMenu.uasset b/Content/MainMenu/MainMenu.uasset index 695af62..8420306 100644 Binary files a/Content/MainMenu/MainMenu.uasset and b/Content/MainMenu/MainMenu.uasset differ diff --git a/Content/MainMenu/MainMenuLevel.umap b/Content/MainMenu/MainMenuLevel.umap index 514de22..5b5490d 100644 Binary files a/Content/MainMenu/MainMenuLevel.umap and b/Content/MainMenu/MainMenuLevel.umap differ diff --git a/Content/ManageSquadMenu/BP_ManageSquadTrooper.uasset b/Content/ManageSquadMenu/BP_ManageSquadTrooper.uasset new file mode 100644 index 0000000..4595318 Binary files /dev/null and b/Content/ManageSquadMenu/BP_ManageSquadTrooper.uasset differ diff --git a/Content/ManageSquadMenu/ManageSquadLevel.umap b/Content/ManageSquadMenu/ManageSquadLevel.umap new file mode 100644 index 0000000..fca80b0 Binary files /dev/null and b/Content/ManageSquadMenu/ManageSquadLevel.umap differ diff --git a/Source/TurnBasedTutorial/ManageSquadGameMode.cpp b/Source/TurnBasedTutorial/ManageSquadGameMode.cpp new file mode 100644 index 0000000..529481b --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadGameMode.cpp @@ -0,0 +1,11 @@ +#include "ManageSquadGameMode.h" + +#include "ManageSquadGameState.h" +#include "ManageSquadPawn.h" +#include "ManageSquadPlayerController.h" + +AManageSquadGameMode::AManageSquadGameMode() { + PlayerControllerClass = AManageSquadPlayerController::StaticClass(); + DefaultPawnClass = AManageSquadPawn::StaticClass(); + GameStateClass = AManageSquadGameState::StaticClass(); +} diff --git a/Source/TurnBasedTutorial/ManageSquadGameMode.h b/Source/TurnBasedTutorial/ManageSquadGameMode.h new file mode 100644 index 0000000..7abdf6f --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadGameMode.h @@ -0,0 +1,13 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameMode.h" +#include "ManageSquadGameMode.generated.h" + +UCLASS() +class TURNBASEDTUTORIAL_API AManageSquadGameMode : public AGameMode { + GENERATED_BODY() + +public: + AManageSquadGameMode(); +}; diff --git a/Source/TurnBasedTutorial/ManageSquadGameState.cpp b/Source/TurnBasedTutorial/ManageSquadGameState.cpp new file mode 100644 index 0000000..da48053 --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadGameState.cpp @@ -0,0 +1,11 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "ManageSquadGameState.h" + +AManageSquadGameState::AManageSquadGameState() { + TroopersKinds = {0, 0, 0, 0, 0}; +} + +void AManageSquadGameState::ChangeSquad(int TrooperIndex, int TrooperKind) { + TroopersKinds[TrooperIndex] = TrooperKind; +} diff --git a/Source/TurnBasedTutorial/ManageSquadGameState.h b/Source/TurnBasedTutorial/ManageSquadGameState.h new file mode 100644 index 0000000..1198780 --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadGameState.h @@ -0,0 +1,25 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameState.h" +#include "ManageSquadGameState.generated.h" + +/** + * + */ +UCLASS() +class TURNBASEDTUTORIAL_API AManageSquadGameState : public AGameState { + GENERATED_BODY() + +public: + AManageSquadGameState(); + + UFUNCTION() + void ChangeSquad(int TrooperIndex, int TrooperKind); + +private: + UPROPERTY() + TArray TroopersKinds; +}; diff --git a/Source/TurnBasedTutorial/ManageSquadPawn.cpp b/Source/TurnBasedTutorial/ManageSquadPawn.cpp new file mode 100644 index 0000000..1fafe54 --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadPawn.cpp @@ -0,0 +1,19 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "ManageSquadPawn.h" + +// Called when the game starts or when spawned +void AManageSquadPawn::BeginPlay() { + Super::BeginPlay(); +} + +// Called every frame +void AManageSquadPawn::Tick(float DeltaTime) { + Super::Tick(DeltaTime); +} + +// Called to bind functionality to input +void AManageSquadPawn::SetupPlayerInputComponent( + UInputComponent *PlayerInputComponent) { + // Super::SetupPlayerInputComponent(PlayerInputComponent); +} diff --git a/Source/TurnBasedTutorial/ManageSquadPawn.h b/Source/TurnBasedTutorial/ManageSquadPawn.h new file mode 100644 index 0000000..dace062 --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadPawn.h @@ -0,0 +1,24 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/DefaultPawn.h" +#include "ManageSquadPawn.generated.h" + +UCLASS() +class TURNBASEDTUTORIAL_API AManageSquadPawn : public ADefaultPawn { + GENERATED_BODY() + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + + // Called to bind functionality to input + virtual void SetupPlayerInputComponent( + class UInputComponent *PlayerInputComponent) override; +}; diff --git a/Source/TurnBasedTutorial/ManageSquadPlayerController.cpp b/Source/TurnBasedTutorial/ManageSquadPlayerController.cpp new file mode 100644 index 0000000..5c324df --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadPlayerController.cpp @@ -0,0 +1,63 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "ManageSquadPlayerController.h" + +#include "ManageSquadGameState.h" + +AManageSquadPlayerController::AManageSquadPlayerController() { + SetShowMouseCursor(true); +} + +void AManageSquadPlayerController::SetupInputComponent() { + Super::SetupInputComponent(); + InputComponent->BindAction("MyAction", IE_Pressed, this, + &AManageSquadPlayerController::OnLeftMouseClick); +} + +void AManageSquadPlayerController::OnLeftMouseClick() { + UE_LOG(LogTemp, Warning, TEXT("Mouse clicked")); + FHitResult HitResult; + bool const IsHitResult = GetHitResultUnderCursorForObjects( + TArray>{ObjectTypeQuery1}, false, + HitResult); + if (!IsHitResult) + return; + + UE_LOG(LogTemp, Warning, TEXT("Got hit result")); + // auto const NewlySelectedLocation = HitResult.Location; + AManageSquadTrooper *NewlySelectedTrooper = dynamic_cast + ( + HitResult.GetActor()); + + if (NewlySelectedTrooper == nullptr || !NewlySelectedTrooper-> + IsValidLowLevel()) { + // we selected something that is not a trooper (or trooper in shitty state...) + UE_LOG(LogTemp, Warning, TEXT("Not a trooper")); + return; + } + // skip re-selection + if (SelectedTrooper == NewlySelectedTrooper) { + UE_LOG(LogTemp, Warning, TEXT("Skip reselection")); + return; + } + UE_LOG(LogTemp, Warning, TEXT("Trooper")); + switch (NewlySelectedTrooper->GetType()) { + case ETrooperType::TROOPER_SAMPLE: + if (SelectedTrooper) { + UE_LOG(LogTemp, Warning, TEXT("Trooper replacement")); + SelectedTrooper->ChangeSkeletalMesh(NewlySelectedTrooper); + dynamic_cast( + GetWorld()->GetGameState())->ChangeSquad( + SelectedTrooper->GetIndex(), + NewlySelectedTrooper->GetIndex() + ); + } + break; + case ETrooperType::TROOPER_IN_SQUAD: + SelectedTrooper = NewlySelectedTrooper; + UE_LOG(LogTemp, Warning, TEXT("Changed selection")); + break; + default: + break; + } +} diff --git a/Source/TurnBasedTutorial/ManageSquadPlayerController.h b/Source/TurnBasedTutorial/ManageSquadPlayerController.h new file mode 100644 index 0000000..5fe2a53 --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadPlayerController.h @@ -0,0 +1,29 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/PlayerController.h" +#include "ManageSquadTrooper.h" +#include "ManageSquadPlayerController.generated.h" + +/** + * + */ +UCLASS() +class TURNBASEDTUTORIAL_API AManageSquadPlayerController + : public APlayerController { + GENERATED_BODY() + +public: + AManageSquadPlayerController(); + + virtual void SetupInputComponent() override; + +private: + UPROPERTY() + AManageSquadTrooper *SelectedTrooper; + + UFUNCTION() + void OnLeftMouseClick(); +}; diff --git a/Source/TurnBasedTutorial/ManageSquadTrooper.cpp b/Source/TurnBasedTutorial/ManageSquadTrooper.cpp new file mode 100644 index 0000000..3019c63 --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadTrooper.cpp @@ -0,0 +1,30 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "ManageSquadTrooper.h" + +AManageSquadTrooper::AManageSquadTrooper() { + GetMesh()->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap); +} + +// Called when the game starts or when spawned +void AManageSquadTrooper::BeginPlay() { + Super::BeginPlay(); +} + +// Called every frame +void AManageSquadTrooper::Tick(float DeltaTime) { + Super::Tick(DeltaTime); +} + +void AManageSquadTrooper:: +ChangeSkeletalMesh(const AManageSquadTrooper *OtherTrooper) { + GetMesh()->SetSkeletalMesh(OtherTrooper->GetMesh()->SkeletalMesh); +} + +ETrooperType AManageSquadTrooper::GetType() const { + return Type; +} + +int AManageSquadTrooper::GetIndex() const { + return Index; +} diff --git a/Source/TurnBasedTutorial/ManageSquadTrooper.h b/Source/TurnBasedTutorial/ManageSquadTrooper.h new file mode 100644 index 0000000..5e49790 --- /dev/null +++ b/Source/TurnBasedTutorial/ManageSquadTrooper.h @@ -0,0 +1,43 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Character.h" +#include "ManageSquadTrooper.generated.h" + +UENUM() +enum ETrooperType { + TROOPER_SAMPLE, + TROOPER_IN_SQUAD +}; + +UCLASS() +class TURNBASEDTUTORIAL_API AManageSquadTrooper : public ACharacter { + GENERATED_BODY() + + AManageSquadTrooper(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + + UPROPERTY(EditAnywhere) + int Index = -1; + + UPROPERTY(EditAnywhere) + TEnumAsByte Type; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + + UFUNCTION() + void ChangeSkeletalMesh(const AManageSquadTrooper *OtherTrooper); + + UFUNCTION() + ETrooperType GetType() const; + + UFUNCTION() + int GetIndex() const; +}; diff --git a/Source/TurnBasedTutorial/MyPlayerController.cpp b/Source/TurnBasedTutorial/MyPlayerController.cpp index 4a722dd..5dab816 100644 --- a/Source/TurnBasedTutorial/MyPlayerController.cpp +++ b/Source/TurnBasedTutorial/MyPlayerController.cpp @@ -48,8 +48,7 @@ void AMyPlayerController::MoveTrooper_Implementation( if (Trooper->CheckMoveCorrectness(Location)) { Trooper->MoveTrooper(Location); GetMyGameMode()->CycleTurns(); - } - else { + } else { GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red, FString::Printf( TEXT("Out of move radius!"))); @@ -92,7 +91,8 @@ void AMyPlayerController::OnLeftMouseClick() { UE_LOG(LogTemp, Warning, TEXT("Mouse clicked")); FHitResult HitResult; bool const IsHitResult = GetHitResultUnderCursorForObjects( - TArray>{ObjectTypeQuery1}, false, HitResult); + TArray>{ObjectTypeQuery1}, false, + HitResult); // GetHitResultUnderCursorForObjects(); // bool const IsHitResult = GetHitResultUnderCursorByChannel( // TraceTypeQuery1, false, HitResult);