Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GAME INSTANCE .CPP
- //Fill out your copyright notice in the Description page of Project Settings.
- #include "DEVP_GameInstance.h"
- #include "Runtime/MoviePlayer/Public/MoviePlayer.h"
- #include "LoadingScreen.h"
- void UDEVP_GameInstance::Init()
- {
- UGameInstance::Init();
- FCoreUObjectDelegates::PreLoadMap.AddUObject(this, &UDEVP_GameInstance::BeginLoadingScreen);
- FCoreUObjectDelegates::PostLoadMap.AddUObject(this, &UDEVP_GameInstance::EndLoadingScreen);
- }
- void UDEVP_GameInstance::BeginLoadingScreen_Implementation(const FString& MapName)
- {
- if (!IsRunningDedicatedServer())
- {
- const ULoadingScreenSettings* Settings = GetDefault<ULoadingScreenSettings>();
- FLoadingScreenAttributes LoadingScreen;
- const FLoadingScreenDescription& ScreenDescription = Settings->StartupScreen;
- LoadingScreen.MinimumLoadingScreenDisplayTime = ScreenDescription.MinimumLoadingScreenDisplayTime;
- LoadingScreen.bAutoCompleteWhenLoadingCompletes = ScreenDescription.bAutoCompleteWhenLoadingCompletes;
- LoadingScreen.bMoviesAreSkippable = ScreenDescription.bMoviesAreSkippable;
- LoadingScreen.bWaitForManualStop = ScreenDescription.bWaitForManualStop;
- LoadingScreen.MoviePaths = ScreenDescription.MoviePaths;
- LoadingScreen.PlaybackType = ScreenDescription.PlaybackType;
- LoadingScreen.WidgetLoadingScreen = SNew(SLoadingScreen, ScreenDescription); /* FLoadingScreenAttributes::NewTestLoadingScreenWidget();*/
- GetMoviePlayer()->SetupLoadingScreen(LoadingScreen);
- }
- }
- void UDEVP_GameInstance::EndLoadingScreen_Implementation()
- {
- //
- }
- ================================================================================================================================
- LOADING SCREEN .h
- // Fill out your copyright notice in the Description page of Project Settings.
- #pragma once
- #include "CoreMinimal.h"
- //#include "SWidget"
- #include "SCompoundWidget.h"
- #include "Fonts/SlateFontInfo.h"
- #include "SScaleBox.h"
- #include "MoviePlayer.h"
- #include "Engine/DeveloperSettings.h"
- #include "Runtime/MoviePlayer/Public/MoviePlayer.h"
- #include "LoadingScreen.generated.h"
- USTRUCT(BlueprintType)
- struct DEV_PARASITICA_API FLoadingScreenDescription
- {
- GENERATED_USTRUCT_BODY()
- FLoadingScreenDescription();
- /** The minimum time that a loading screen should be opened for, -1 if there is no minimum time. */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
- float MinimumLoadingScreenDisplayTime;
- /** If true, the loading screen will disappear as soon as all movies are played and loading is done. */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
- bool bAutoCompleteWhenLoadingCompletes;
- /** If true, movies can be skipped by clicking the loading screen as long as loading is done. */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
- bool bMoviesAreSkippable;
- /** If true, movie playback continues until Stop is called. */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
- bool bWaitForManualStop;
- /** Should we just play back, loop, etc. NOTE: if the playback type is MT_LoopLast, then bAutoCompleteWhenLoadingCompletes will be togged on when the last movie is hit*/
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
- TEnumAsByte<EMoviePlaybackType> PlaybackType;
- /** Should we show the images/tips/loading text? Generally you'll want to set this to false if you just want to show a movie. */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
- bool bShowUIOverlay;
- /** */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
- FText LoadingText;
- /** */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
- FSlateFontInfo LoadingFont;
- /** The movie paths local to the game's Content/Movies/ directory we will play. */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Movies)
- TArray<FString> MoviePaths;
- /** The texture display while in the loading screen on top of the movie. */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Images, meta = (AllowedClasses = "Texture2D"))
- TArray<FStringAssetReference> Images;
- /** The scaling type to apply to images. */
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Images)
- TEnumAsByte<EStretch::Type> ImageStretch;
- };
- UCLASS(config = Game, defaultconfig, meta = (DisplayName = "Loading Screen"))
- class DEV_PARASITICA_API ULoadingScreenSettings : public UDeveloperSettings
- {
- GENERATED_UCLASS_BODY()
- public:
- /** The startup screen for the project. */
- UPROPERTY(config, EditAnywhere, Category = Screens)
- FLoadingScreenDescription StartupScreen;
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
- FSlateFontInfo LoadingFont;
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
- FSlateFontInfo TipFont;
- };
- /**
- * Special brush to prevent garbage collection
- */
- struct FLoadingScreenBrush : public FSlateDynamicImageBrush, public FGCObject
- {
- FLoadingScreenBrush(class UTexture2D* InTexture, const FVector2D& InImageSize, const FName InImagePath)
- : FSlateDynamicImageBrush(InTexture, InImageSize, InImagePath)
- {
- }
- virtual void AddReferencedObjects(FReferenceCollector& Collector) override
- {
- if (ResourceObject)
- {
- Collector.AddReferencedObject(ResourceObject);
- }
- }
- };
- class DEV_PARASITICA_API SLoadingScreen : public SCompoundWidget
- {
- public:
- SLATE_BEGIN_ARGS(SLoadingScreen) {}
- SLATE_END_ARGS()
- void Construct(const FArguments& InArgs, const FLoadingScreenDescription& InScreenDescription);
- virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
- private:
- float GetDPIScale() const;
- private:
- TSharedPtr<FLoadingScreenBrush> LoadingScreenBrush;
- float LastComputedDPIScale;
- };
- ================================================================================================================================
- LOADINGSCREEN .CPP
- // Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
- #include "LoadingScreen.h"
- #include "UObject/ConstructorHelpers.h"
- #include "Widgets/SBoxPanel.h"
- #include "Widgets/Layout/SBorder.h"
- #include "SThrobber.h"
- #include "Widgets/Text/STextBlock.h"
- #include "Widgets/Layout/SSpacer.h"
- #include "Engine/Font.h"
- #include "Engine/UserInterfaceSettings.h"
- #define LOCTEXT_NAMESPACE "ULoadingScreen"
- FLoadingScreenDescription::FLoadingScreenDescription()
- : MinimumLoadingScreenDisplayTime(5)
- , bAutoCompleteWhenLoadingCompletes(true)
- , bMoviesAreSkippable(false)
- , bWaitForManualStop(false)
- , bShowUIOverlay(true)
- , LoadingText(LOCTEXT("Loading", "LOADING"))
- , ImageStretch(EStretch::ScaleToFit)
- {
- }
- ULoadingScreenSettings::ULoadingScreenSettings(const FObjectInitializer& Initializer)
- : Super(Initializer)
- {
- if (!IsRunningDedicatedServer())
- {
- static ConstructorHelpers::FObjectFinder<UFont> RobotoFontObj(TEXT("/Engine/EngineFonts/Roboto"));
- TipFont = FSlateFontInfo(RobotoFontObj.Object, 20, FName("Normal"));
- LoadingFont = FSlateFontInfo(RobotoFontObj.Object, 32, FName("Bold"));
- }
- }
- void SLoadingScreen::Construct(const FArguments& InArgs, const FLoadingScreenDescription& InScreenDescription)
- {
- LastComputedDPIScale = 1.0f;
- TSharedRef<SWidget> TipText = SNullWidget::NullWidget;
- FText Tip = LOCTEXT("tip text", "LOADING...");
- TipText = SNew(STextBlock)
- .WrapTextAt(800)
- //.Font(Settings->TipFont)
- .Text(Tip);
- TSharedRef<SWidget> LoadingText = SNullWidget::NullWidget;
- FText Loadtxt = LOCTEXT("loading text", "LOADING...");
- TipText = SNew(STextBlock)
- .WrapTextAt(800)
- //.Font(Settings->TipFont)
- .Text(Loadtxt);
- TSharedRef<SBorder> Root = SNew(SBorder)
- .HAlign(HAlign_Fill)
- .VAlign(VAlign_Fill)
- .BorderBackgroundColor(FLinearColor(0, 0, 0, 0.75))
- .BorderImage(FCoreStyle::Get().GetBrush("WhiteBrush"))
- [
- SNew(SVerticalBox)
- + SVerticalBox::Slot()
- .Padding(FMargin(20, 20, 20, 20))
- .VAlign(VAlign_Center)
- .HAlign(HAlign_Center)
- [
- SNew(SHorizontalBox)
- + SHorizontalBox::Slot()
- .VAlign(VAlign_Center)
- .AutoWidth()
- [
- LoadingText
- ]
- + SHorizontalBox::Slot()
- .FillWidth(1)
- .HAlign(HAlign_Fill)
- [
- SNew(SSpacer)
- .Size(FVector2D(1.0f, 50.0f))
- ]
- + SHorizontalBox::Slot()
- .Padding(FMargin(25, 0.0f, 0, 0))
- .VAlign(VAlign_Center)
- .AutoWidth()
- [
- SNew(SCircularThrobber)
- // Convert font size to pixels, pixel_size = point_size * resolution / 72, then half it to get radius
- .Radius(100.f)
- ]
- + SHorizontalBox::Slot()
- .VAlign(VAlign_Center)
- .AutoWidth()
- [
- TipText
- ]
- ]
- ];
- ChildSlot
- [
- Root
- ];
- }
- void SLoadingScreen::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
- {
- const FVector2D& LocalSize = AllottedGeometry.GetLocalSize();
- FIntPoint Size((int32)LocalSize.X, (int32)LocalSize.Y);
- const float NewScale = GetDefault<UUserInterfaceSettings>()->GetDPIScaleBasedOnSize(Size);
- if (NewScale != LastComputedDPIScale)
- {
- LastComputedDPIScale = NewScale;
- SlatePrepass(1.0f);
- }
- }
- float SLoadingScreen::GetDPIScale() const
- {
- return LastComputedDPIScale;
- }
- #undef LOCTEXT_NAMESPACE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement