almost made manage squad menu (except back button and saving data)

pull/6/head
m4xxx1m 2 years ago
parent ae01088fcd
commit 7816cf735f

Binary file not shown.

@ -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();
}

@ -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();
};

@ -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;
}

@ -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<int> TroopersKinds;
};

@ -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);
}

@ -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;
};

@ -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<TEnumAsByte<EObjectTypeQuery>>{ObjectTypeQuery1}, false,
HitResult);
if (!IsHitResult)
return;
UE_LOG(LogTemp, Warning, TEXT("Got hit result"));
// auto const NewlySelectedLocation = HitResult.Location;
AManageSquadTrooper *NewlySelectedTrooper = dynamic_cast
<AManageSquadTrooper *>(
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<AManageSquadGameState *>(
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;
}
}

@ -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();
};

@ -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;
}

@ -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<ETrooperType> 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;
};

@ -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<TEnumAsByte<EObjectTypeQuery>>{ObjectTypeQuery1}, false, HitResult);
TArray<TEnumAsByte<EObjectTypeQuery>>{ObjectTypeQuery1}, false,
HitResult);
// GetHitResultUnderCursorForObjects();
// bool const IsHitResult = GetHitResultUnderCursorByChannel(
// TraceTypeQuery1, false, HitResult);

Loading…
Cancel
Save