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
@@ -25,9 +25,16 @@ class TitleScreenSourceTests(unittest.TestCase):
|
|||||||
self.assertIn("FInputModeUIOnly", source)
|
self.assertIn("FInputModeUIOnly", source)
|
||||||
self.assertIn("bShowMouseCursor = true", source)
|
self.assertIn("bShowMouseCursor = true", source)
|
||||||
|
|
||||||
|
def test_widget_accepts_and_forwards_keyboard_focus(self):
|
||||||
|
source = read("Source/pogo/UI/PogoTitleScreenWidget.cpp")
|
||||||
|
self.assertIn("SetIsFocusable(true)", source)
|
||||||
|
self.assertIn("SetDesiredFocusWidget(PlayButton)", source)
|
||||||
|
|
||||||
def test_widget_uses_approved_media_and_layout(self):
|
def test_widget_uses_approved_media_and_layout(self):
|
||||||
source = read("Source/pogo/UI/PogoTitleScreenWidget.cpp")
|
source = read("Source/pogo/UI/PogoTitleScreenWidget.cpp")
|
||||||
self.assertIn('TEXT("./Movies/pogo.mp4")', source)
|
self.assertIn("NewObject<UFileMediaSource>", source)
|
||||||
|
self.assertIn('SetFilePath(TEXT("./Movies/pogo.mp4"))', source)
|
||||||
|
self.assertIn("OpenSource(VideoSource)", source)
|
||||||
self.assertIn("SetLooping(true)", source)
|
self.assertIn("SetLooping(true)", source)
|
||||||
self.assertIn("EStretch::ScaleToFill", source)
|
self.assertIn("EStretch::ScaleToFill", source)
|
||||||
self.assertIn("FAnchors(0.5f, 1.0f)", source)
|
self.assertIn("FAnchors(0.5f, 1.0f)", source)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "Components/OverlaySlot.h"
|
#include "Components/OverlaySlot.h"
|
||||||
#include "Components/ScaleBox.h"
|
#include "Components/ScaleBox.h"
|
||||||
#include "Components/TextBlock.h"
|
#include "Components/TextBlock.h"
|
||||||
|
#include "FileMediaSource.h"
|
||||||
#include "Input/Reply.h"
|
#include "Input/Reply.h"
|
||||||
#include "InputCoreTypes.h"
|
#include "InputCoreTypes.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
@@ -30,13 +31,20 @@ namespace PogoTitleScreen
|
|||||||
const FLinearColor Vermilion(0.80f, 0.14f, 0.06f, 1.0f);
|
const FLinearColor Vermilion(0.80f, 0.14f, 0.06f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UPogoTitleScreenWidget::UPogoTitleScreenWidget(const FObjectInitializer& ObjectInitializer)
|
||||||
|
: Super(ObjectInitializer)
|
||||||
|
{
|
||||||
|
SetIsFocusable(true);
|
||||||
|
}
|
||||||
|
|
||||||
void UPogoTitleScreenWidget::NativeOnInitialized()
|
void UPogoTitleScreenWidget::NativeOnInitialized()
|
||||||
{
|
{
|
||||||
Super::NativeOnInitialized();
|
Super::NativeOnInitialized();
|
||||||
|
|
||||||
MediaPlayer = NewObject<UMediaPlayer>(this, TEXT("TitleMediaPlayer"));
|
MediaPlayer = NewObject<UMediaPlayer>(this, TEXT("TitleMediaPlayer"));
|
||||||
MediaTexture = NewObject<UMediaTexture>(this, TEXT("TitleMediaTexture"));
|
MediaTexture = NewObject<UMediaTexture>(this, TEXT("TitleMediaTexture"));
|
||||||
if (MediaPlayer && MediaTexture)
|
VideoSource = NewObject<UFileMediaSource>(this, TEXT("TitleVideoSource"));
|
||||||
|
if (MediaPlayer && MediaTexture && VideoSource)
|
||||||
{
|
{
|
||||||
MediaPlayer->PlayOnOpen = true;
|
MediaPlayer->PlayOnOpen = true;
|
||||||
MediaPlayer->SetLooping(true);
|
MediaPlayer->SetLooping(true);
|
||||||
@@ -44,6 +52,7 @@ void UPogoTitleScreenWidget::NativeOnInitialized()
|
|||||||
MediaTexture->ClearColor = PogoTitleScreen::Petroleum;
|
MediaTexture->ClearColor = PogoTitleScreen::Petroleum;
|
||||||
MediaTexture->SetMediaPlayer(MediaPlayer);
|
MediaTexture->SetMediaPlayer(MediaPlayer);
|
||||||
MediaTexture->UpdateResource();
|
MediaTexture->UpdateResource();
|
||||||
|
VideoSource->SetFilePath(TEXT("./Movies/pogo.mp4"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildLayout();
|
BuildLayout();
|
||||||
@@ -147,18 +156,19 @@ void UPogoTitleScreenWidget::BuildLayout()
|
|||||||
PlaySlot->SetAlignment(FVector2D(0.5f, 1.0f));
|
PlaySlot->SetAlignment(FVector2D(0.5f, 1.0f));
|
||||||
PlaySlot->SetSize(FVector2D(220.0f, 64.0f));
|
PlaySlot->SetSize(FVector2D(220.0f, 64.0f));
|
||||||
PlaySlot->SetPosition(FVector2D(0.0f, -36.0f));
|
PlaySlot->SetPosition(FVector2D(0.0f, -36.0f));
|
||||||
|
SetDesiredFocusWidget(PlayButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UPogoTitleScreenWidget::StartMedia()
|
void UPogoTitleScreenWidget::StartMedia()
|
||||||
{
|
{
|
||||||
if (!MediaPlayer)
|
if (!MediaPlayer || !VideoSource)
|
||||||
{
|
{
|
||||||
UE_LOG(LogTemp, Warning, TEXT("Title screen media player is unavailable"));
|
UE_LOG(LogTemp, Warning, TEXT("Title screen media player is unavailable"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaPlayer->SetLooping(true);
|
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"));
|
UE_LOG(LogTemp, Warning, TEXT("Title screen video could not be opened"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
class UAudioComponent;
|
class UAudioComponent;
|
||||||
class UButton;
|
class UButton;
|
||||||
|
class UFileMediaSource;
|
||||||
class UImage;
|
class UImage;
|
||||||
class UMediaPlayer;
|
class UMediaPlayer;
|
||||||
class UMediaTexture;
|
class UMediaTexture;
|
||||||
@@ -15,6 +16,9 @@ class POGO_API UPogoTitleScreenWidget : public UUserWidget
|
|||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPogoTitleScreenWidget(const FObjectInitializer& ObjectInitializer);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void NativeOnInitialized() override;
|
virtual void NativeOnInitialized() override;
|
||||||
virtual void NativeConstruct() override;
|
virtual void NativeConstruct() override;
|
||||||
@@ -49,6 +53,9 @@ private:
|
|||||||
UPROPERTY(Transient)
|
UPROPERTY(Transient)
|
||||||
TObjectPtr<UMediaTexture> MediaTexture;
|
TObjectPtr<UMediaTexture> MediaTexture;
|
||||||
|
|
||||||
|
UPROPERTY(Transient)
|
||||||
|
TObjectPtr<UFileMediaSource> VideoSource;
|
||||||
|
|
||||||
UPROPERTY(Transient)
|
UPROPERTY(Transient)
|
||||||
TObjectPtr<UAudioComponent> MusicComponent;
|
TObjectPtr<UAudioComponent> MusicComponent;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user