diff --git a/UnrealHyperTwist/Config/DefaultEngine.ini b/UnrealHyperTwist/Config/DefaultEngine.ini index 050099c..7e6f3f9 100644 --- a/UnrealHyperTwist/Config/DefaultEngine.ini +++ b/UnrealHyperTwist/Config/DefaultEngine.ini @@ -2,6 +2,7 @@ [/Script/EngineSettings.GameMapsSettings] GameDefaultMap=/Engine/Maps/Templates/OpenWorld +GlobalDefaultGameMode=/Script/UnrealHyperTwist.HyperTwistCoachDashboardGameMode [/Script/Engine.RendererSettings] r.AllowStaticLighting=False diff --git a/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistCoachDashboardGameMode.cpp b/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistCoachDashboardGameMode.cpp new file mode 100644 index 0000000..bfba484 --- /dev/null +++ b/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistCoachDashboardGameMode.cpp @@ -0,0 +1,8 @@ +#include "HyperTwistTraining/HyperTwistCoachDashboardGameMode.h" + +#include "HyperTwistTraining/HyperTwistCoachDashboardPlayerController.h" + +AHyperTwistCoachDashboardGameMode::AHyperTwistCoachDashboardGameMode() +{ + PlayerControllerClass = AHyperTwistCoachDashboardPlayerController::StaticClass(); +} diff --git a/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistCoachDashboardPlayerController.cpp b/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistCoachDashboardPlayerController.cpp new file mode 100644 index 0000000..69cdcd2 --- /dev/null +++ b/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistCoachDashboardPlayerController.cpp @@ -0,0 +1,133 @@ +#include "HyperTwistTraining/HyperTwistCoachDashboardPlayerController.h" + +#include "EngineUtils.h" +#include "HyperTwistTraining/HyperTwistCoachDashboardActor.h" + +AHyperTwistCoachDashboardPlayerController::AHyperTwistCoachDashboardPlayerController() +{ + bShowMouseCursor = true; + bEnableClickEvents = true; + bEnableMouseOverEvents = true; +} + +void AHyperTwistCoachDashboardPlayerController::BeginPlay() +{ + Super::BeginPlay(); + + ApplyDashboardInputMode(); + + if (bBootstrapCoachDashboardOnBeginPlay) + { + EnsureCoachDashboard(); + } +} + +AHyperTwistCoachDashboardActor* AHyperTwistCoachDashboardPlayerController::EnsureCoachDashboard() +{ + if (ActiveDashboardActor == nullptr) + { + ActiveDashboardActor = FindExistingDashboardActor(); + } + + if (ActiveDashboardActor == nullptr) + { + ActiveDashboardActor = SpawnDashboardActor(); + } + + if (ActiveDashboardActor != nullptr) + { + ApplyDashboardDefaults(ActiveDashboardActor); + ActiveDashboardActor->CreateAndShowDashboard(); + } + + return ActiveDashboardActor; +} + +void AHyperTwistCoachDashboardPlayerController::RefreshCoachDashboard() +{ + if (EnsureCoachDashboard() != nullptr) + { + ActiveDashboardActor->RefreshDashboard(); + } +} + +void AHyperTwistCoachDashboardPlayerController::ApplyDashboardInputMode() +{ + bShowMouseCursor = bShowCoachDashboardMouseCursor; + bEnableClickEvents = bShowCoachDashboardMouseCursor; + bEnableMouseOverEvents = bShowCoachDashboardMouseCursor; + + if (bUseGameAndUiInputMode) + { + FInputModeGameAndUI InputMode; + InputMode.SetHideCursorDuringCapture(false); + InputMode.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock); + SetInputMode(InputMode); + } +} + +AHyperTwistCoachDashboardActor* +AHyperTwistCoachDashboardPlayerController::FindExistingDashboardActor() const +{ + if (GetWorld() == nullptr) + { + return nullptr; + } + + for (TActorIterator ActorIt(GetWorld()); ActorIt; ++ActorIt) + { + return *ActorIt; + } + + return nullptr; +} + +AHyperTwistCoachDashboardActor* +AHyperTwistCoachDashboardPlayerController::SpawnDashboardActor() +{ + if (GetWorld() == nullptr) + { + return nullptr; + } + + TSubclassOf ResolvedActorClass = DashboardActorClass; + if (*ResolvedActorClass == nullptr) + { + ResolvedActorClass = AHyperTwistCoachDashboardActor::StaticClass(); + } + if (*ResolvedActorClass == nullptr) + { + return nullptr; + } + + FTransform SpawnTransform; + AHyperTwistCoachDashboardActor* DashboardActor = GetWorld()->SpawnActorDeferred( + ResolvedActorClass, + SpawnTransform, + nullptr, + nullptr, + ESpawnActorCollisionHandlingMethod::AlwaysSpawn + ); + if (DashboardActor == nullptr) + { + return nullptr; + } + + ApplyDashboardDefaults(DashboardActor); + DashboardActor->FinishSpawning(SpawnTransform); + return DashboardActor; +} + +void AHyperTwistCoachDashboardPlayerController::ApplyDashboardDefaults( + AHyperTwistCoachDashboardActor* DashboardActor) const +{ + if (DashboardActor == nullptr) + { + return; + } + + DashboardActor->DashboardDefaultUserId = DashboardDefaultUserId; + DashboardActor->DashboardDefaultSessionId = DashboardDefaultSessionId; + DashboardActor->DashboardDefaultMode = DashboardDefaultMode; + DashboardActor->DashboardDefaultCoachMaxCases = DashboardDefaultCoachMaxCases; +} diff --git a/UnrealHyperTwist/Source/UnrealHyperTwist/Public/HyperTwistTraining/HyperTwistCoachDashboardGameMode.h b/UnrealHyperTwist/Source/UnrealHyperTwist/Public/HyperTwistTraining/HyperTwistCoachDashboardGameMode.h new file mode 100644 index 0000000..555d3a7 --- /dev/null +++ b/UnrealHyperTwist/Source/UnrealHyperTwist/Public/HyperTwistTraining/HyperTwistCoachDashboardGameMode.h @@ -0,0 +1,14 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameModeBase.h" +#include "HyperTwistCoachDashboardGameMode.generated.h" + +UCLASS(BlueprintType, Blueprintable) +class UNREALHYPERTWIST_API AHyperTwistCoachDashboardGameMode : public AGameModeBase +{ + GENERATED_BODY() + +public: + AHyperTwistCoachDashboardGameMode(); +}; diff --git a/UnrealHyperTwist/Source/UnrealHyperTwist/Public/HyperTwistTraining/HyperTwistCoachDashboardPlayerController.h b/UnrealHyperTwist/Source/UnrealHyperTwist/Public/HyperTwistTraining/HyperTwistCoachDashboardPlayerController.h new file mode 100644 index 0000000..f578d03 --- /dev/null +++ b/UnrealHyperTwist/Source/UnrealHyperTwist/Public/HyperTwistTraining/HyperTwistCoachDashboardPlayerController.h @@ -0,0 +1,58 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/PlayerController.h" +#include "HyperTwistTraining/HyperTwistTrainingTypes.h" +#include "HyperTwistCoachDashboardPlayerController.generated.h" + +class AHyperTwistCoachDashboardActor; + +UCLASS(BlueprintType, Blueprintable) +class UNREALHYPERTWIST_API AHyperTwistCoachDashboardPlayerController : public APlayerController +{ + GENERATED_BODY() + +public: + AHyperTwistCoachDashboardPlayerController(); + + virtual void BeginPlay() override; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard") + bool bBootstrapCoachDashboardOnBeginPlay = true; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard") + bool bShowCoachDashboardMouseCursor = true; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard") + bool bUseGameAndUiInputMode = true; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard") + TSubclassOf DashboardActorClass; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard") + FString DashboardDefaultUserId = TEXT("local-user"); + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard") + FString DashboardDefaultSessionId = TEXT("training_session_runtime"); + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard") + EHyperTwistTrainingDeliveryMode DashboardDefaultMode = EHyperTwistTrainingDeliveryMode::Timer; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard") + int32 DashboardDefaultCoachMaxCases = 5; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "HyperTwist|Training|Coach|Dashboard") + TObjectPtr ActiveDashboardActor = nullptr; + + UFUNCTION(BlueprintCallable, Category = "HyperTwist|Training|Coach|Dashboard") + AHyperTwistCoachDashboardActor* EnsureCoachDashboard(); + + UFUNCTION(BlueprintCallable, Category = "HyperTwist|Training|Coach|Dashboard") + void RefreshCoachDashboard(); + +protected: + void ApplyDashboardInputMode(); + AHyperTwistCoachDashboardActor* FindExistingDashboardActor() const; + AHyperTwistCoachDashboardActor* SpawnDashboardActor(); + void ApplyDashboardDefaults(AHyperTwistCoachDashboardActor* DashboardActor) const; +};