Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.16 KB | None | 0 0
  1. GAME INSTANCE .CPP
  2.  
  3. //Fill out your copyright notice in the Description page of Project Settings.
  4.  
  5. #include "DEVP_GameInstance.h"
  6. #include "Runtime/MoviePlayer/Public/MoviePlayer.h"
  7. #include "LoadingScreen.h"
  8.  
  9.  
  10.  
  11. void UDEVP_GameInstance::Init()
  12. {
  13. UGameInstance::Init();
  14.  
  15. FCoreUObjectDelegates::PreLoadMap.AddUObject(this, &UDEVP_GameInstance::BeginLoadingScreen);
  16. FCoreUObjectDelegates::PostLoadMap.AddUObject(this, &UDEVP_GameInstance::EndLoadingScreen);
  17. }
  18.  
  19. void UDEVP_GameInstance::BeginLoadingScreen_Implementation(const FString& MapName)
  20. {
  21. if (!IsRunningDedicatedServer())
  22. {
  23.  
  24. const ULoadingScreenSettings* Settings = GetDefault<ULoadingScreenSettings>();
  25. FLoadingScreenAttributes LoadingScreen;
  26. const FLoadingScreenDescription& ScreenDescription = Settings->StartupScreen;
  27. LoadingScreen.MinimumLoadingScreenDisplayTime = ScreenDescription.MinimumLoadingScreenDisplayTime;
  28. LoadingScreen.bAutoCompleteWhenLoadingCompletes = ScreenDescription.bAutoCompleteWhenLoadingCompletes;
  29. LoadingScreen.bMoviesAreSkippable = ScreenDescription.bMoviesAreSkippable;
  30. LoadingScreen.bWaitForManualStop = ScreenDescription.bWaitForManualStop;
  31. LoadingScreen.MoviePaths = ScreenDescription.MoviePaths;
  32. LoadingScreen.PlaybackType = ScreenDescription.PlaybackType;
  33. LoadingScreen.WidgetLoadingScreen = SNew(SLoadingScreen, ScreenDescription); /* FLoadingScreenAttributes::NewTestLoadingScreenWidget();*/
  34.  
  35. GetMoviePlayer()->SetupLoadingScreen(LoadingScreen);
  36. }
  37. }
  38.  
  39. void UDEVP_GameInstance::EndLoadingScreen_Implementation()
  40. {
  41. //
  42. }
  43.  
  44.  
  45. ================================================================================================================================
  46.  
  47.  
  48.  
  49.  
  50. LOADING SCREEN .h
  51.  
  52. // Fill out your copyright notice in the Description page of Project Settings.
  53.  
  54. #pragma once
  55.  
  56. #include "CoreMinimal.h"
  57. //#include "SWidget"
  58. #include "SCompoundWidget.h"
  59. #include "Fonts/SlateFontInfo.h"
  60. #include "SScaleBox.h"
  61. #include "MoviePlayer.h"
  62. #include "Engine/DeveloperSettings.h"
  63. #include "Runtime/MoviePlayer/Public/MoviePlayer.h"
  64. #include "LoadingScreen.generated.h"
  65.  
  66.  
  67.  
  68. USTRUCT(BlueprintType)
  69. struct DEV_PARASITICA_API FLoadingScreenDescription
  70. {
  71. GENERATED_USTRUCT_BODY()
  72.  
  73. FLoadingScreenDescription();
  74.  
  75. /** The minimum time that a loading screen should be opened for, -1 if there is no minimum time. */
  76. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
  77. float MinimumLoadingScreenDisplayTime;
  78.  
  79. /** If true, the loading screen will disappear as soon as all movies are played and loading is done. */
  80. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
  81. bool bAutoCompleteWhenLoadingCompletes;
  82.  
  83. /** If true, movies can be skipped by clicking the loading screen as long as loading is done. */
  84. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
  85. bool bMoviesAreSkippable;
  86.  
  87. /** If true, movie playback continues until Stop is called. */
  88. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
  89. bool bWaitForManualStop;
  90.  
  91. /** 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*/
  92. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Loading)
  93. TEnumAsByte<EMoviePlaybackType> PlaybackType;
  94.  
  95. /** 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. */
  96. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
  97. bool bShowUIOverlay;
  98.  
  99. /** */
  100. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
  101. FText LoadingText;
  102.  
  103. /** */
  104. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
  105. FSlateFontInfo LoadingFont;
  106.  
  107. /** The movie paths local to the game's Content/Movies/ directory we will play. */
  108. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Movies)
  109. TArray<FString> MoviePaths;
  110.  
  111. /** The texture display while in the loading screen on top of the movie. */
  112. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Images, meta = (AllowedClasses = "Texture2D"))
  113. TArray<FStringAssetReference> Images;
  114.  
  115. /** The scaling type to apply to images. */
  116. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Images)
  117. TEnumAsByte<EStretch::Type> ImageStretch;
  118. };
  119.  
  120. UCLASS(config = Game, defaultconfig, meta = (DisplayName = "Loading Screen"))
  121. class DEV_PARASITICA_API ULoadingScreenSettings : public UDeveloperSettings
  122. {
  123. GENERATED_UCLASS_BODY()
  124.  
  125. public:
  126.  
  127. /** The startup screen for the project. */
  128. UPROPERTY(config, EditAnywhere, Category = Screens)
  129. FLoadingScreenDescription StartupScreen;
  130. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
  131. FSlateFontInfo LoadingFont;
  132. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Display)
  133. FSlateFontInfo TipFont;
  134.  
  135. };
  136.  
  137.  
  138.  
  139. /**
  140. * Special brush to prevent garbage collection
  141. */
  142. struct FLoadingScreenBrush : public FSlateDynamicImageBrush, public FGCObject
  143. {
  144. FLoadingScreenBrush(class UTexture2D* InTexture, const FVector2D& InImageSize, const FName InImagePath)
  145. : FSlateDynamicImageBrush(InTexture, InImageSize, InImagePath)
  146. {
  147. }
  148.  
  149. virtual void AddReferencedObjects(FReferenceCollector& Collector) override
  150. {
  151. if (ResourceObject)
  152. {
  153. Collector.AddReferencedObject(ResourceObject);
  154. }
  155. }
  156. };
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. class DEV_PARASITICA_API SLoadingScreen : public SCompoundWidget
  164. {
  165. public:
  166.  
  167. SLATE_BEGIN_ARGS(SLoadingScreen) {}
  168.  
  169. SLATE_END_ARGS()
  170.  
  171. void Construct(const FArguments& InArgs, const FLoadingScreenDescription& InScreenDescription);
  172.  
  173. virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
  174.  
  175.  
  176. private:
  177. float GetDPIScale() const;
  178.  
  179. private:
  180. TSharedPtr<FLoadingScreenBrush> LoadingScreenBrush;
  181. float LastComputedDPIScale;
  182. };
  183.  
  184. ================================================================================================================================
  185.  
  186. LOADINGSCREEN .CPP
  187.  
  188.  
  189. // Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
  190.  
  191. #include "LoadingScreen.h"
  192.  
  193. #include "UObject/ConstructorHelpers.h"
  194. #include "Widgets/SBoxPanel.h"
  195. #include "Widgets/Layout/SBorder.h"
  196. #include "SThrobber.h"
  197. #include "Widgets/Text/STextBlock.h"
  198. #include "Widgets/Layout/SSpacer.h"
  199. #include "Engine/Font.h"
  200. #include "Engine/UserInterfaceSettings.h"
  201.  
  202.  
  203. #define LOCTEXT_NAMESPACE "ULoadingScreen"
  204.  
  205. FLoadingScreenDescription::FLoadingScreenDescription()
  206. : MinimumLoadingScreenDisplayTime(5)
  207. , bAutoCompleteWhenLoadingCompletes(true)
  208. , bMoviesAreSkippable(false)
  209. , bWaitForManualStop(false)
  210. , bShowUIOverlay(true)
  211. , LoadingText(LOCTEXT("Loading", "LOADING"))
  212. , ImageStretch(EStretch::ScaleToFit)
  213. {
  214. }
  215.  
  216. ULoadingScreenSettings::ULoadingScreenSettings(const FObjectInitializer& Initializer)
  217. : Super(Initializer)
  218. {
  219. if (!IsRunningDedicatedServer())
  220. {
  221. static ConstructorHelpers::FObjectFinder<UFont> RobotoFontObj(TEXT("/Engine/EngineFonts/Roboto"));
  222. TipFont = FSlateFontInfo(RobotoFontObj.Object, 20, FName("Normal"));
  223. LoadingFont = FSlateFontInfo(RobotoFontObj.Object, 32, FName("Bold"));
  224.  
  225. }
  226. }
  227.  
  228.  
  229. void SLoadingScreen::Construct(const FArguments& InArgs, const FLoadingScreenDescription& InScreenDescription)
  230. {
  231.  
  232. LastComputedDPIScale = 1.0f;
  233.  
  234.  
  235. TSharedRef<SWidget> TipText = SNullWidget::NullWidget;
  236. FText Tip = LOCTEXT("tip text", "LOADING...");
  237. TipText = SNew(STextBlock)
  238. .WrapTextAt(800)
  239. //.Font(Settings->TipFont)
  240. .Text(Tip);
  241.  
  242. TSharedRef<SWidget> LoadingText = SNullWidget::NullWidget;
  243. FText Loadtxt = LOCTEXT("loading text", "LOADING...");
  244. TipText = SNew(STextBlock)
  245. .WrapTextAt(800)
  246. //.Font(Settings->TipFont)
  247. .Text(Loadtxt);
  248.  
  249.  
  250.  
  251. TSharedRef<SBorder> Root = SNew(SBorder)
  252. .HAlign(HAlign_Fill)
  253. .VAlign(VAlign_Fill)
  254. .BorderBackgroundColor(FLinearColor(0, 0, 0, 0.75))
  255. .BorderImage(FCoreStyle::Get().GetBrush("WhiteBrush"))
  256. [
  257. SNew(SVerticalBox)
  258. + SVerticalBox::Slot()
  259. .Padding(FMargin(20, 20, 20, 20))
  260. .VAlign(VAlign_Center)
  261. .HAlign(HAlign_Center)
  262. [
  263. SNew(SHorizontalBox)
  264. + SHorizontalBox::Slot()
  265. .VAlign(VAlign_Center)
  266. .AutoWidth()
  267. [
  268. LoadingText
  269. ]
  270.  
  271. + SHorizontalBox::Slot()
  272. .FillWidth(1)
  273. .HAlign(HAlign_Fill)
  274. [
  275. SNew(SSpacer)
  276. .Size(FVector2D(1.0f, 50.0f))
  277. ]
  278.  
  279. + SHorizontalBox::Slot()
  280. .Padding(FMargin(25, 0.0f, 0, 0))
  281. .VAlign(VAlign_Center)
  282. .AutoWidth()
  283. [
  284. SNew(SCircularThrobber)
  285. // Convert font size to pixels, pixel_size = point_size * resolution / 72, then half it to get radius
  286. .Radius(100.f)
  287. ]
  288.  
  289. + SHorizontalBox::Slot()
  290. .VAlign(VAlign_Center)
  291. .AutoWidth()
  292. [
  293. TipText
  294. ]
  295.  
  296. ]
  297. ];
  298.  
  299. ChildSlot
  300. [
  301. Root
  302. ];
  303.  
  304. }
  305.  
  306.  
  307. void SLoadingScreen::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
  308. {
  309. const FVector2D& LocalSize = AllottedGeometry.GetLocalSize();
  310. FIntPoint Size((int32)LocalSize.X, (int32)LocalSize.Y);
  311. const float NewScale = GetDefault<UUserInterfaceSettings>()->GetDPIScaleBasedOnSize(Size);
  312.  
  313. if (NewScale != LastComputedDPIScale)
  314. {
  315. LastComputedDPIScale = NewScale;
  316. SlatePrepass(1.0f);
  317. }
  318. }
  319.  
  320. float SLoadingScreen::GetDPIScale() const
  321. {
  322. return LastComputedDPIScale;
  323. }
  324.  
  325. #undef LOCTEXT_NAMESPACE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement