Files
pogo/docs/superpowers/plans/2026-10-01-title-screen.md

370 lines
17 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Title Screen Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Livrer un écran titre Unreal Engine 5.8 qui lit la vidéo Pogo plein écran, joue `pogo.wav` en boucle à 65 %, et ouvre le niveau Third Person via un bouton Jouer bas-centre.
**Architecture:** Une map dédiée utilise un GameMode et un PlayerController C++ natifs. Le PlayerController crée un widget UMG natif ; le widget construit son arbre visuel en C++, possède le `MediaPlayer`/`MediaTexture` transitoire et le composant audio, puis navigue vers la map de gameplay. Un script Unreal Python reproductible importe le WAV, crée la map et assigne le GameMode.
**Tech Stack:** Unreal Engine 5.8, C++/UMG/Media Framework, Unreal Python commandlet, Python `unittest`, Git LFS, macOS arm64.
**Spec:** `docs/superpowers/specs/2026-10-01-title-screen.md`
## Global Constraints
- La vidéo source est `/Users/cdelvecchio/Desktop/pogo.mp4`, H.264 1280×720 à 24 fps, et doit finir sous `Content/Movies/pogo.mp4`.
- La musique source est `/Users/cdelvecchio/Desktop/pogo.wav`, PCM 16-bit stéréo 48 kHz, et doit finir sous `SourceArt/Audio/pogo.wav` puis être importée en `/Game/Pogo/Audio/S_PogoTitleMusic`.
- La vidéo et la musique bouclent automatiquement ; le volume musique est exactement `0.65f`.
- La vidéo utilise un fill uniforme avec crop central, jamais une déformation ou des bandes noires.
- L'unique action est Jouer, en bas-centre, utilisable à la souris, avec Entrée et Espace.
- Jouer ouvre `/Game/ThirdPerson/Lvl_ThirdPerson` et ignore toute seconde activation.
- Un échec vidéo ou audio ne bloque jamais Jouer.
- `Lvl_TitleScreen` devient `GameDefaultMap`; `EditorStartupMap` reste `/Game/ThirdPerson/Lvl_ThirdPerson`.
- Les assets binaires et médias restent couverts par Git LFS.
- Hors scope : options, crédits, continue, retour Échap, volume réglable, système audio global.
## Review Focus
- Média vidéo absent/corrompu : le fond utilise sa couleur de clear et Jouer reste activable.
- BGM absente : aucun crash ni blocage de navigation ; l'écran reste utilisable silencieusement.
- Double clic ou double touche : un seul appel d'ouverture de niveau grâce au guard de transition.
- Viewports ultra-larges/étroits : `ScaleToFill` conserve le ratio et croppe au centre.
- Navigation sans souris : le widget prend le focus et Entrée/Espace déclenchent exactement la même action que le clic.
---
### Task 1: Native title-screen flow
**Files:**
- Create: `Scripts/tests/test_title_screen.py`
- Create: `Source/pogo/UI/PogoTitleScreenWidget.h`
- Create: `Source/pogo/UI/PogoTitleScreenWidget.cpp`
- Create: `Source/pogo/UI/PogoTitleScreenPlayerController.h`
- Create: `Source/pogo/UI/PogoTitleScreenPlayerController.cpp`
- Create: `Source/pogo/UI/PogoTitleScreenGameMode.h`
- Create: `Source/pogo/UI/PogoTitleScreenGameMode.cpp`
- Modify: `Source/pogo/pogo.Build.cs:11-24`
**Interfaces:**
- Consumes: `/Game/Pogo/Audio/S_PogoTitleMusic`, `./Movies/pogo.mp4`, `/Game/ThirdPerson/Lvl_ThirdPerson`.
- Produces: `UPogoTitleScreenWidget`, `APogoTitleScreenPlayerController`, `APogoTitleScreenGameMode`; Task 2 assigns the GameMode to the generated map.
- [ ] **Step 1: Write the failing source-contract tests**
Create `Scripts/tests/test_title_screen.py` with one test per behavior. Resolve the repository root from `Path(__file__).parents[2]`, read the C++ files/config as UTF-8, and assert:
```python
from pathlib import Path
import unittest
ROOT = Path(__file__).resolve().parents[2]
def path(relative):
return ROOT / relative
def read(relative):
return path(relative).read_text(encoding="utf-8")
class TitleScreenSourceTests(unittest.TestCase):
def test_media_modules_are_linked(self):
build = read("Source/pogo/pogo.Build.cs")
self.assertIn('"MediaAssets"', build)
self.assertIn('"SlateCore"', build)
def test_controller_owns_ui_input_mode(self):
source = read("Source/pogo/UI/PogoTitleScreenPlayerController.cpp")
self.assertIn("CreateWidget<UPogoTitleScreenWidget>", source)
self.assertIn("FInputModeUIOnly", source)
self.assertIn("bShowMouseCursor = true", 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("SetLooping(true)", source)
self.assertIn("EStretch::ScaleToFill", source)
self.assertIn("FAnchors(0.5f, 1.0f)", source)
self.assertIn("0.65f", source)
def test_play_is_idempotent_and_opens_gameplay(self):
source = read("Source/pogo/UI/PogoTitleScreenWidget.cpp")
self.assertLess(source.index("if (bTransitionStarted)"), source.index("bTransitionStarted = true"))
self.assertIn('FName(TEXT("/Game/ThirdPerson/Lvl_ThirdPerson"))', source)
self.assertIn("EKeys::Enter", source)
self.assertIn("EKeys::SpaceBar", source)
def test_failure_paths_do_not_disable_play(self):
source = read("Source/pogo/UI/PogoTitleScreenWidget.cpp")
self.assertNotIn("PlayButton->SetIsEnabled(false)", source[:source.index("void UPogoTitleScreenWidget::RequestPlay")])
```
- [ ] **Step 2: Run the focused test and verify RED**
Run: `python3 -m unittest Scripts.tests.test_title_screen -v`
Expected: FAIL because the title-screen source files and Media Framework dependencies do not exist.
- [ ] **Step 3: Add the native classes and module dependencies**
Add `MediaAssets` and `SlateCore` to `PublicDependencyModuleNames` in `pogo.Build.cs`.
Implement `APogoTitleScreenGameMode` as a concrete `AGameModeBase`. In its constructor set `PlayerControllerClass = APogoTitleScreenPlayerController::StaticClass()`, `DefaultPawnClass = nullptr`, `HUDClass = nullptr`, and `bStartPlayersAsSpectators = true`.
Implement `APogoTitleScreenPlayerController::BeginPlay()`:
```cpp
Super::BeginPlay();
if (!IsLocalPlayerController()) { return; }
TitleScreenWidget = CreateWidget<UPogoTitleScreenWidget>(this, UPogoTitleScreenWidget::StaticClass());
if (!TitleScreenWidget) { return; }
TitleScreenWidget->AddToViewport(0);
bShowMouseCursor = true;
FInputModeUIOnly InputMode;
InputMode.SetWidgetToFocus(TitleScreenWidget->TakeWidget());
InputMode.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
SetInputMode(InputMode);
TitleScreenWidget->SetKeyboardFocus();
```
Implement `UPogoTitleScreenWidget` with these exact responsibilities:
- `NativeOnInitialized()` constructs a root `UOverlay`.
- Background layer: `UScaleBox` with `SetStretch(EStretch::ScaleToFill)`, `SetStretchDirection(EStretchDirection::Both)`, clipping to bounds, and a `UImage` whose brush image size is `FVector2D(1280.0, 720.0)`.
- Foreground layer: `UCanvasPanel`; a focusable `UButton` in a `UCanvasPanelSlot` with anchors `(0.5, 1.0)`, alignment `(0.5, 1.0)`, size `220×64`, and position `(0, -36)`.
- Button style: `FSlateRoundedBoxBrush` with dark petroleum normal fill, lighter petroleum hover/focus fill, ivory 1 px outline, 10 px radius. Label text is `◆ JOUER ◆`, ivory, 20 px, uppercase.
- `OnHovered` applies render translation `(0, -4)`; `OnUnhovered` resets it.
- Create transient `UMediaPlayer` and `UMediaTexture`, call `MediaTexture->SetMediaPlayer(MediaPlayer)`, set `AutoClear = true`, clear color petroleum, assign the texture to the background brush, call `SetLooping(true)`, then call `OpenUrl(TEXT("./Movies/pogo.mp4"))`. Log failure but leave the button enabled.
- Load `/Game/Pogo/Audio/S_PogoTitleMusic.S_PogoTitleMusic`; if present call `UGameplayStatics::SpawnSound2D(this, Sound, 0.65f, 1.0f, 0.0f, nullptr, false, false)`. The first boolean prevents persistence into gameplay; the second keeps the component controllable until `StopPlayback()`. Log absence without changing the button.
- `NativeKeyDown()` calls `RequestPlay()` for `EKeys::Enter` and `EKeys::SpaceBar`, returning `FReply::Handled()`; other keys call `Super`.
- `RequestPlay()` uses this ordering:
```cpp
if (bTransitionStarted) { return; }
bTransitionStarted = true;
PlayButton->SetIsEnabled(false);
StopPlayback();
UGameplayStatics::OpenLevel(this, FName(TEXT("/Game/ThirdPerson/Lvl_ThirdPerson")));
```
- `StopPlayback()` closes a valid `MediaPlayer` and stops a valid `MusicComponent`.
- `NativeDestruct()` invokes `StopPlayback()` before `Super::NativeDestruct()`.
- [ ] **Step 4: Run the source-contract test and verify GREEN**
Run: `python3 -m unittest Scripts.tests.test_title_screen -v`
Expected: all title-screen source tests PASS.
- [ ] **Step 5: Build the full editor target**
Run:
```bash
"/Users/Shared/Epic Games/UE_5.8/Engine/Build/BatchFiles/Mac/Build.sh" pogoEditor Mac Development -Project="$PWD/pogo.uproject" -WaitMutex
```
Expected: `Result: Succeeded` and `Binaries/Mac/libUnrealEditor-pogo.dylib` updated.
- [ ] **Step 6: Run the complete Python suite**
Run: `python3 -m unittest discover -s Scripts/tests -v`
Expected: gameplay-blocker and title-screen tests all PASS.
- [ ] **Step 7: Commit Task 1**
```bash
git add Source/pogo/pogo.Build.cs Source/pogo/UI Scripts/tests/test_title_screen.py
git commit -m "feat: add native title screen flow"
```
---
### Task 2: Package media and generate the title map
**Files:**
- Create: `Content/Movies/pogo.mp4`
- Create: `SourceArt/Audio/pogo.wav`
- Create: `Scripts/setup_title_screen.py`
- Create: `Scripts/verify_title_screen_assets.py`
- Create through Unreal: `Content/Pogo/Audio/S_PogoTitleMusic.uasset`
- Create through Unreal: `Content/Pogo/Maps/Lvl_TitleScreen.umap`
- Modify: `Config/DefaultEngine.ini:3-6`
- Modify: `Scripts/tests/test_title_screen.py`
**Interfaces:**
- Consumes: `APogoTitleScreenGameMode` from Task 1 and the two Desktop media files.
- Produces: packaged video URL `./Movies/pogo.mp4`, sound asset `/Game/Pogo/Audio/S_PogoTitleMusic`, map `/Game/Pogo/Maps/Lvl_TitleScreen`, and startup configuration.
- [ ] **Step 1: Extend tests for generated content and configuration**
Add assertions to `Scripts/tests/test_title_screen.py`:
```python
def test_packaged_media_sources_exist(self):
self.assertTrue(path("Content/Movies/pogo.mp4").is_file())
self.assertTrue(path("SourceArt/Audio/pogo.wav").is_file())
def test_title_map_is_the_runtime_default(self):
config = read("Config/DefaultEngine.ini")
self.assertIn("GameDefaultMap=/Game/Pogo/Maps/Lvl_TitleScreen.Lvl_TitleScreen", config)
self.assertIn("EditorStartupMap=/Game/ThirdPerson/Lvl_ThirdPerson.Lvl_ThirdPerson", config)
def test_setup_script_creates_required_assets(self):
setup = read("Scripts/setup_title_screen.py")
self.assertIn('"/Game/Pogo/Audio/S_PogoTitleMusic"', setup)
self.assertIn('"/Game/Pogo/Maps/Lvl_TitleScreen"', setup)
self.assertIn('set_editor_property("looping", True)', setup)
self.assertIn("unreal.PogoTitleScreenGameMode", setup)
```
- [ ] **Step 2: Run the focused test and verify RED**
Run: `python3 -m unittest Scripts.tests.test_title_screen -v`
Expected: FAIL because media files, setup script, generated assets, and startup map configuration are absent.
- [ ] **Step 3: Stage the source media**
Copy without transcoding:
```bash
mkdir -p Content/Movies SourceArt/Audio
cp /Users/cdelvecchio/Desktop/pogo.mp4 Content/Movies/pogo.mp4
cp /Users/cdelvecchio/Desktop/pogo.wav SourceArt/Audio/pogo.wav
```
Confirm metadata with `ffprobe`; expected H.264 1280×720/24 fps for MP4 and PCM s16le/48 kHz/stereo for WAV.
- [ ] **Step 4: Implement the idempotent Unreal setup script**
`Scripts/setup_title_screen.py` must:
1. call `AssetRegistry.search_all_assets(True)` and wait for completion;
2. create `/Game/Pogo/Audio` and `/Game/Pogo/Maps` when absent;
3. resolve the WAV source with `Path(unreal.Paths.project_dir()) / "SourceArt/Audio/pogo.wav"`;
4. import it with `unreal.AssetImportTask` only when `/Game/Pogo/Audio/S_PogoTitleMusic` is absent;
5. load the `SoundWave`, set `looping` to `True`, and save it;
6. create `/Game/Pogo/Maps/Lvl_TitleScreen` with `unreal.EditorLevelLibrary.new_level()` only when absent, otherwise load it;
7. set `world.get_world_settings().default_game_mode` to `unreal.PogoTitleScreenGameMode`;
8. save the current level and emit `POGO_TITLE_SETUP` log lines for each check;
9. raise `RuntimeError` when source media, imported sound, world, class assignment, or save operation is unavailable.
- [ ] **Step 5: Generate and verify the assets headlessly**
Run:
```bash
"/Users/Shared/Epic Games/UE_5.8/Engine/Binaries/Mac/UnrealEditor-Cmd" "$PWD/pogo.uproject" \
-run=pythonscript -script=Scripts/setup_title_screen.py \
-nullrhi -unattended -nosplash -FullStdOutLogOutput
```
Expected: logs confirm the SoundWave is looping, `Lvl_TitleScreen` uses `PogoTitleScreenGameMode`, and both packages save successfully.
Create `Scripts/verify_title_screen_assets.py` that loads both assets, loads the map, and raises on any mismatch:
```python
sound = unreal.EditorAssetLibrary.load_asset("/Game/Pogo/Audio/S_PogoTitleMusic")
assert sound and sound.get_editor_property("looping") is True
assert unreal.EditorLevelLibrary.load_level("/Game/Pogo/Maps/Lvl_TitleScreen")
world = unreal.EditorLevelLibrary.get_editor_world()
assert world.get_world_settings().get_editor_property("default_game_mode") == unreal.PogoTitleScreenGameMode
unreal.log("POGO_TITLE_VERIFY PASS")
```
Run it with the same commandlet shape and expect `POGO_TITLE_VERIFY PASS` with exit code 0.
- [ ] **Step 6: Set the runtime default map**
Change only `GameDefaultMap` in `Config/DefaultEngine.ini`:
```ini
[/Script/EngineSettings.GameMapsSettings]
GameDefaultMap=/Game/Pogo/Maps/Lvl_TitleScreen.Lvl_TitleScreen
EditorStartupMap=/Game/ThirdPerson/Lvl_ThirdPerson.Lvl_ThirdPerson
GlobalDefaultGameMode=/Game/Pogo/Blueprints/BP_PogoGameMode.BP_PogoGameMode_C
```
- [ ] **Step 7: Verify tests, build, media attributes, and asset health**
Run:
```bash
python3 -m unittest discover -s Scripts/tests -v
"/Users/Shared/Epic Games/UE_5.8/Engine/Build/BatchFiles/Mac/Build.sh" pogoEditor Mac Development -Project="$PWD/pogo.uproject" -WaitMutex
git check-attr filter -- Content/Movies/pogo.mp4 SourceArt/Audio/pogo.wav Content/Pogo/Audio/S_PogoTitleMusic.uasset Content/Pogo/Maps/Lvl_TitleScreen.umap
git lfs fsck
git diff --check
```
Expected: tests PASS, build succeeds, all four files report `filter: lfs`, LFS fsck succeeds, and diff check is empty.
- [ ] **Step 8: Commit Task 2**
```bash
git add Config/DefaultEngine.ini Content/Movies/pogo.mp4 SourceArt/Audio/pogo.wav \
Content/Pogo/Audio/S_PogoTitleMusic.uasset Content/Pogo/Maps/Lvl_TitleScreen.umap \
Scripts/setup_title_screen.py Scripts/verify_title_screen_assets.py Scripts/tests/test_title_screen.py
git commit -m "feat: ship title screen media and map"
```
---
### Task 3: Runtime title-screen smoke test
**Files:**
- Verify only; no production file is created in this task.
**Interfaces:**
- Consumes: complete title-screen flow and assets from Tasks 1–2.
- Produces: runtime evidence for video, audio, focus, mouse activation, keyboard activation, and map transition.
- [ ] **Step 1: Launch the standalone title screen with rendering enabled**
Run the game target in a 1280×720 window and preserve its log:
```bash
"/Users/Shared/Epic Games/UE_5.8/Engine/Binaries/Mac/UnrealEditor" "$PWD/pogo.uproject" \
/Game/Pogo/Maps/Lvl_TitleScreen -game -windowed -ResX=1280 -ResY=720 \
-log -ABSLOG="$PWD/Saved/Logs/TitleScreenSmoke.log"
```
Expected: title screen window opens without a crash or modal dialog.
- [ ] **Step 2: Verify visual composition and video loop**
Capture the running window immediately and again after at least 12 seconds. Confirm both captures show the video filling the window, the embedded logo unobscured, Pogo unobscured, and the Jouer button in the approved bottom-center position. Confirm the two captures are not the same video frame and no black bars appear.
- [ ] **Step 3: Verify BGM**
Listen during the standalone run and confirm the BGM starts automatically, continues past the 10-second video loop, and has no clipping or obvious restart at the video boundary. The default multiplier remains `0.65f` in source.
- [ ] **Step 4: Verify mouse activation and single transition**
Click Jouer twice rapidly. Confirm the button disables on the first activation and the game opens `/Game/ThirdPerson/Lvl_ThirdPerson` once. Check `Saved/Logs/TitleScreenSmoke.log` for one gameplay world load and no media/audio errors that block navigation.
- [ ] **Step 5: Verify keyboard activation**
Relaunch twice. In one run press Entrée without clicking; in the other press Espace. Each must open the Third Person level once while the button has initial focus.
- [ ] **Step 6: Verify media-failure fallback**
Temporarily rename `Content/Movies/pogo.mp4` outside the process, launch the title screen, and confirm the petroleum clear color appears while Jouer still opens the gameplay map. Restore the exact filename before continuing and verify `git status` reports no deletion.
- [ ] **Step 7: Final regression gate**
Run:
```bash
python3 -m unittest discover -s Scripts/tests -v
"/Users/Shared/Epic Games/UE_5.8/Engine/Build/BatchFiles/Mac/Build.sh" pogoEditor Mac Development -Project="$PWD/pogo.uproject" -WaitMutex
git lfs fsck
git diff --check
git status --short
```
Expected: all tests pass, build succeeds, LFS is healthy, diff check is empty, and only intentional committed changes exist.