fix: stabilize title screen media and focus
This commit is contained in:
1 parent
1d5988bc03
commit
d34c1f6bb5
3 files changed
+28
-4
No files matched your search
@@ -13,6 +13,7 @@
|
||||
#include "Components/OverlaySlot.h"
|
||||
#include "Components/ScaleBox.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "FileMediaSource.h"
|
||||
#include "Input/Reply.h"
|
||||
#include "InputCoreTypes.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
@@ -30,13 +31,20 @@ namespace PogoTitleScreen
|
||||
const FLinearColor Vermilion(0.80f, 0.14f, 0.06f, 1.0f);
|
||||
}
|
||||
|
||||
UPogoTitleScreenWidget::UPogoTitleScreenWidget(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
SetIsFocusable(true);
|
||||
}
|
||||
|
||||
void UPogoTitleScreenWidget::NativeOnInitialized()
|
||||
{
|
||||
Super::NativeOnInitialized();
|
||||
|
||||
MediaPlayer = NewObject<UMediaPlayer>(this, TEXT("TitleMediaPlayer"));
|
||||
MediaTexture = NewObject<UMediaTexture>(this, TEXT("TitleMediaTexture"));
|
||||
if (MediaPlayer && MediaTexture)
|
||||
VideoSource = NewObject<UFileMediaSource>(this, TEXT("TitleVideoSource"));
|
||||
if (MediaPlayer && MediaTexture && VideoSource)
|
||||
{
|
||||
MediaPlayer->PlayOnOpen = true;
|
||||
MediaPlayer->SetLooping(true);
|
||||
@@ -44,6 +52,7 @@ void UPogoTitleScreenWidget::NativeOnInitialized()
|
||||
MediaTexture->ClearColor = PogoTitleScreen::Petroleum;
|
||||
MediaTexture->SetMediaPlayer(MediaPlayer);
|
||||
MediaTexture->UpdateResource();
|
||||
VideoSource->SetFilePath(TEXT("./Movies/pogo.mp4"));
|
||||
}
|
||||
|
||||
BuildLayout();
|
||||
@@ -147,18 +156,19 @@ void UPogoTitleScreenWidget::BuildLayout()
|
||||
PlaySlot->SetAlignment(FVector2D(0.5f, 1.0f));
|
||||
PlaySlot->SetSize(FVector2D(220.0f, 64.0f));
|
||||
PlaySlot->SetPosition(FVector2D(0.0f, -36.0f));
|
||||
SetDesiredFocusWidget(PlayButton);
|
||||
}
|
||||
|
||||
void UPogoTitleScreenWidget::StartMedia()
|
||||
{
|
||||
if (!MediaPlayer)
|
||||
if (!MediaPlayer || !VideoSource)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Title screen media player is unavailable"));
|
||||
return;
|
||||
}
|
||||
|
||||
MediaPlayer->SetLooping(true);
|
||||
if (!MediaPlayer->OpenUrl(TEXT("./Movies/pogo.mp4")))
|
||||
if (!MediaPlayer->OpenSource(VideoSource))
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Title screen video could not be opened"));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
class UAudioComponent;
|
||||
class UButton;
|
||||
class UFileMediaSource;
|
||||
class UImage;
|
||||
class UMediaPlayer;
|
||||
class UMediaTexture;
|
||||
@@ -15,6 +16,9 @@ class POGO_API UPogoTitleScreenWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPogoTitleScreenWidget(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
protected:
|
||||
virtual void NativeOnInitialized() override;
|
||||
virtual void NativeConstruct() override;
|
||||
@@ -49,6 +53,9 @@ private:
|
||||
UPROPERTY(Transient)
|
||||
TObjectPtr<UMediaTexture> MediaTexture;
|
||||
|
||||
UPROPERTY(Transient)
|
||||
TObjectPtr<UFileMediaSource> VideoSource;
|
||||
|
||||
UPROPERTY(Transient)
|
||||
TObjectPtr<UAudioComponent> MusicComponent;
|
||||
|
||||
|
||||
Reference in new issue
Block a user