Bootstrap coach dashboard by default
This commit is contained in:
parent
354c7024b7
commit
ead48b43aa
5 changed files with 214 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
[/Script/EngineSettings.GameMapsSettings]
|
||||
GameDefaultMap=/Engine/Maps/Templates/OpenWorld
|
||||
GlobalDefaultGameMode=/Script/UnrealHyperTwist.HyperTwistCoachDashboardGameMode
|
||||
|
||||
[/Script/Engine.RendererSettings]
|
||||
r.AllowStaticLighting=False
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
#include "HyperTwistTraining/HyperTwistCoachDashboardGameMode.h"
|
||||
|
||||
#include "HyperTwistTraining/HyperTwistCoachDashboardPlayerController.h"
|
||||
|
||||
AHyperTwistCoachDashboardGameMode::AHyperTwistCoachDashboardGameMode()
|
||||
{
|
||||
PlayerControllerClass = AHyperTwistCoachDashboardPlayerController::StaticClass();
|
||||
}
|
||||
|
|
@ -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<AHyperTwistCoachDashboardActor> ActorIt(GetWorld()); ActorIt; ++ActorIt)
|
||||
{
|
||||
return *ActorIt;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AHyperTwistCoachDashboardActor*
|
||||
AHyperTwistCoachDashboardPlayerController::SpawnDashboardActor()
|
||||
{
|
||||
if (GetWorld() == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TSubclassOf<AHyperTwistCoachDashboardActor> ResolvedActorClass = DashboardActorClass;
|
||||
if (*ResolvedActorClass == nullptr)
|
||||
{
|
||||
ResolvedActorClass = AHyperTwistCoachDashboardActor::StaticClass();
|
||||
}
|
||||
if (*ResolvedActorClass == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FTransform SpawnTransform;
|
||||
AHyperTwistCoachDashboardActor* DashboardActor = GetWorld()->SpawnActorDeferred<AHyperTwistCoachDashboardActor>(
|
||||
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;
|
||||
}
|
||||
|
|
@ -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();
|
||||
};
|
||||
|
|
@ -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<AHyperTwistCoachDashboardActor> 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<AHyperTwistCoachDashboardActor> 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;
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue