Add coach dashboard scene host actor
This commit is contained in:
parent
3d67ba1df7
commit
354c7024b7
2 changed files with 175 additions and 0 deletions
|
|
@ -0,0 +1,109 @@
|
|||
#include "HyperTwistTraining/HyperTwistCoachDashboardActor.h"
|
||||
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "HyperTwistTraining/HyperTwistCoachDashboardWidget.h"
|
||||
|
||||
AHyperTwistCoachDashboardActor::AHyperTwistCoachDashboardActor()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
}
|
||||
|
||||
void AHyperTwistCoachDashboardActor::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (bCreateDashboardOnBeginPlay)
|
||||
{
|
||||
CreateAndShowDashboard();
|
||||
}
|
||||
}
|
||||
|
||||
void AHyperTwistCoachDashboardActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
||||
{
|
||||
if (bRemoveDashboardOnEndPlay)
|
||||
{
|
||||
RemoveDashboard();
|
||||
}
|
||||
|
||||
Super::EndPlay(EndPlayReason);
|
||||
}
|
||||
|
||||
UHyperTwistCoachDashboardWidget* AHyperTwistCoachDashboardActor::CreateAndShowDashboard()
|
||||
{
|
||||
if (ActiveDashboardWidget != nullptr)
|
||||
{
|
||||
RefreshDashboard();
|
||||
return ActiveDashboardWidget;
|
||||
}
|
||||
|
||||
const TSubclassOf<UHyperTwistCoachDashboardWidget> ResolvedWidgetClass = ResolveDashboardWidgetClass();
|
||||
if (GetWorld() == nullptr || *ResolvedWidgetClass == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ActiveDashboardWidget = CreateWidget<UHyperTwistCoachDashboardWidget>(GetWorld(), ResolvedWidgetClass);
|
||||
if (ActiveDashboardWidget == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ApplyDashboardDefaults(ActiveDashboardWidget);
|
||||
ActiveDashboardWidget->AddToViewport(DashboardZOrder);
|
||||
|
||||
if (bRefreshDashboardOnCreate)
|
||||
{
|
||||
ActiveDashboardWidget->RefreshCoachDashboardView();
|
||||
}
|
||||
|
||||
return ActiveDashboardWidget;
|
||||
}
|
||||
|
||||
void AHyperTwistCoachDashboardActor::RemoveDashboard()
|
||||
{
|
||||
if (ActiveDashboardWidget == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ActiveDashboardWidget->RemoveFromParent();
|
||||
ActiveDashboardWidget = nullptr;
|
||||
}
|
||||
|
||||
void AHyperTwistCoachDashboardActor::RefreshDashboard()
|
||||
{
|
||||
if (ActiveDashboardWidget != nullptr)
|
||||
{
|
||||
ApplyDashboardDefaults(ActiveDashboardWidget);
|
||||
ActiveDashboardWidget->RefreshCoachDashboardView();
|
||||
}
|
||||
}
|
||||
|
||||
bool AHyperTwistCoachDashboardActor::HasActiveDashboard() const
|
||||
{
|
||||
return ActiveDashboardWidget != nullptr;
|
||||
}
|
||||
|
||||
TSubclassOf<UHyperTwistCoachDashboardWidget> AHyperTwistCoachDashboardActor::ResolveDashboardWidgetClass() const
|
||||
{
|
||||
if (*DashboardWidgetClass != nullptr)
|
||||
{
|
||||
return DashboardWidgetClass;
|
||||
}
|
||||
|
||||
return UHyperTwistCoachDashboardWidget::StaticClass();
|
||||
}
|
||||
|
||||
void AHyperTwistCoachDashboardActor::ApplyDashboardDefaults(UHyperTwistCoachDashboardWidget* DashboardWidget) const
|
||||
{
|
||||
if (DashboardWidget == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DashboardWidget->bRefreshOnConstruct = bRefreshDashboardOnCreate;
|
||||
DashboardWidget->DefaultUserId = DashboardDefaultUserId;
|
||||
DashboardWidget->DefaultSessionId = DashboardDefaultSessionId;
|
||||
DashboardWidget->DefaultMode = DashboardDefaultMode;
|
||||
DashboardWidget->DefaultCoachMaxCases = DashboardDefaultCoachMaxCases;
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "HyperTwistTraining/HyperTwistTrainingTypes.h"
|
||||
#include "HyperTwistCoachDashboardActor.generated.h"
|
||||
|
||||
class UHyperTwistCoachDashboardWidget;
|
||||
|
||||
UCLASS(BlueprintType, Blueprintable)
|
||||
class UNREALHYPERTWIST_API AHyperTwistCoachDashboardActor : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AHyperTwistCoachDashboardActor();
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard")
|
||||
bool bCreateDashboardOnBeginPlay = true;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard")
|
||||
bool bRemoveDashboardOnEndPlay = true;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard")
|
||||
int32 DashboardZOrder = 0;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard")
|
||||
TSubclassOf<UHyperTwistCoachDashboardWidget> DashboardWidgetClass;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Training|Coach|Dashboard")
|
||||
bool bRefreshDashboardOnCreate = true;
|
||||
|
||||
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_dashboard");
|
||||
|
||||
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<UHyperTwistCoachDashboardWidget> ActiveDashboardWidget = nullptr;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "HyperTwist|Training|Coach|Dashboard")
|
||||
UHyperTwistCoachDashboardWidget* CreateAndShowDashboard();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "HyperTwist|Training|Coach|Dashboard")
|
||||
void RemoveDashboard();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "HyperTwist|Training|Coach|Dashboard")
|
||||
void RefreshDashboard();
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "HyperTwist|Training|Coach|Dashboard")
|
||||
bool HasActiveDashboard() const;
|
||||
|
||||
private:
|
||||
TSubclassOf<UHyperTwistCoachDashboardWidget> ResolveDashboardWidgetClass() const;
|
||||
void ApplyDashboardDefaults(UHyperTwistCoachDashboardWidget* DashboardWidget) const;
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue