100 lines
3.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "UObject/WeakInterfacePtr.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "LoadingScreenManager.generated.h"
/**
* Handles showing/hiding the loading screen
*/
UCLASS()
class COMMONLOADINGSCREEN_API ULoadingScreenManager : public UGameInstanceSubsystem
{
GENERATED_BODY()
public:
//~USubsystem interface
virtual void Initialize(FSubsystemCollectionBase &Collection) override;
virtual void Deinitialize() override;
virtual bool ShouldCreateSubsystem(UObject *Outer) const override;
//~End of USubsystem interface
/** Shows the loading screen. Sets up the loading screen widget on the viewport. */
class ULoadingScreenWidget *ShowLoadingScreen();
/** Hides the loading screen. The loading screen widget will begin to fade out. */
void HideLoadingScreen();
UFUNCTION(BlueprintCallable, Category=LoadingScreen)
FString GetDebugReasonForShowingOrHidingLoadingScreen() const
{
return this->DebugReasonForShowingOrHidingLoadingScreen;
}
/** Returns True when the loading screen is currently being shown */
bool GetLoadingScreenDisplayStatus() const
{
return this->bCurrentlyShowingLoadingScreen;
}
/** Called when the loading screen visibility changes */
DECLARE_MULTICAST_DELEGATE_OneParam(FOnLoadingScreenVisibilityChangedDelegate, bool);
FORCEINLINE FOnLoadingScreenVisibilityChangedDelegate &OnLoadingScreenVisibilityChangedDelegate() { return LoadingScreenVisibilityChanged; }
private:
/** Actually hides the loading screen, either immediately or after a delay if necessary. */
void HideLoadingScreen_Private();
/** Removes the loading screen. The loading screen widget will be destroyed. */
void RemoveLoadingScreen();
/** Removes the widget from the viewport */
void RemoveWidgetFromViewport();
/** Prevents input from being used in-game while the loading screen is visible */
void StartBlockingInput();
/** Resumes in-game input, if blocking */
void StopBlockingInput();
void ChangePerformanceSettings(bool bEnabingLoadingScreen);
private:
/** Delegate broadcast when the loading screen visibility changes */
FOnLoadingScreenVisibilityChangedDelegate LoadingScreenVisibilityChanged;
/** A reference to the loading screen widget we are displaying (if any) */
TObjectPtr<ULoadingScreenWidget> LoadingScreenUMGWidget;
/** A reference to the loading screen widget we are displaying (if any) */
TSharedPtr<SWidget> LoadingScreenWidget;
/** Input processor to eat all input while the loading screen is shown */
TSharedPtr<IInputProcessor> InputPreProcessor;
/** The reason why the loading screen is up (or not) */
FString DebugReasonForShowingOrHidingLoadingScreen;
/** The time when we started showing the loading screen */
double TimeLoadingScreenShown = 0.0;
/** The time the loading screen most recently wanted to be dismissed (might still be up due to a min display duration requirement) **/
double TimeLoadingScreenLastDismissed = -1.0;
/** The time until the next log for why the loading screen is still up */
double TimeUntilNextLogHeartbeatSeconds = 0.0;
/** True when we are between PreLoadMap and PostLoadMap */
bool bCurrentlyInLoadMap = false;
/** True when the loading screen is currently being shown */
bool bCurrentlyShowingLoadingScreen = false;
/** Handle for the timer that controls how much extra time to wait before fading the loading screen away */
FTimerHandle HideLoadingScreenTimerHandle;
};