From d34c1f6bb5d424769af4c0911c5af252d8d7889f Mon Sep 17 00:00:00 2001 From: Christophe Del Vecchio Date: Thu, 1 Oct 2026 13:50:01 +0200 Subject: [PATCH] fix: stabilize title screen media and focus --- Scripts/tests/test_title_screen.py | 9 ++++++++- Source/pogo/UI/PogoTitleScreenWidget.cpp | 16 +++++++++++++--- Source/pogo/UI/PogoTitleScreenWidget.h | 7 +++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Scripts/tests/test_title_screen.py b/Scripts/tests/test_title_screen.py index c9a8360..152a12e 100644 --- a/Scripts/tests/test_title_screen.py +++ b/Scripts/tests/test_title_screen.py @@ -25,9 +25,16 @@ class TitleScreenSourceTests(unittest.TestCase): self.assertIn("FInputModeUIOnly", 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): source = read("Source/pogo/UI/PogoTitleScreenWidget.cpp") - self.assertIn('TEXT("./Movies/pogo.mp4")', source) + self.assertIn("NewObject", source) + self.assertIn('SetFilePath(TEXT("./Movies/pogo.mp4"))', source) + self.assertIn("OpenSource(VideoSource)", source) self.assertIn("SetLooping(true)", source) self.assertIn("EStretch::ScaleToFill", source) self.assertIn("FAnchors(0.5f, 1.0f)", source) diff --git a/Source/pogo/UI/PogoTitleScreenWidget.cpp b/Source/pogo/UI/PogoTitleScreenWidget.cpp index c9e775a..0653094 100644 --- a/Source/pogo/UI/PogoTitleScreenWidget.cpp +++ b/Source/pogo/UI/PogoTitleScreenWidget.cpp @@ -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(this, TEXT("TitleMediaPlayer")); MediaTexture = NewObject(this, TEXT("TitleMediaTexture")); - if (MediaPlayer && MediaTexture) + VideoSource = NewObject(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")); } diff --git a/Source/pogo/UI/PogoTitleScreenWidget.h b/Source/pogo/UI/PogoTitleScreenWidget.h index a3ec4a6..ac64e5e 100644 --- a/Source/pogo/UI/PogoTitleScreenWidget.h +++ b/Source/pogo/UI/PogoTitleScreenWidget.h @@ -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 MediaTexture; + UPROPERTY(Transient) + TObjectPtr VideoSource; + UPROPERTY(Transient) TObjectPtr MusicComponent;