@@ -38,6 +38,7 @@ import funkin.play.character.BaseCharacter;
3838import funkin .data .character .CharacterData .CharacterDataParser ;
3939import funkin .play .components .HealthIcon ;
4040import funkin .play .components .PopUpStuff ;
41+ import funkin .play .components .Subtitles ;
4142import funkin .play .cutscene .dialogue .Conversation ;
4243import funkin .play .cutscene .VanillaCutscenes ;
4344import funkin .play .cutscene .VideoCutscene ;
@@ -512,6 +513,11 @@ class PlayState extends MusicBeatSubState
512513 */
513514 public var healthBarBG : FunkinSprite ;
514515
516+ /**
517+ * A sprite group for subtitle display.
518+ */
519+ public var subtitles : Null <Subtitles >;
520+
515521 /**
516522 * The health icon representing the player.
517523 */
@@ -558,6 +564,11 @@ class PlayState extends MusicBeatSubState
558564 */
559565 public var camCutouts : FlxCamera ;
560566
567+ /**
568+ * The camera which contains, and controls visibility of, the subtitles.
569+ */
570+ public var camSubtitles : FlxCamera ;
571+
561572 /**
562573 * The camera which contains, and controls visibility of, pause menu.
563574 */
@@ -724,6 +735,7 @@ class PlayState extends MusicBeatSubState
724735 camHUD = new FlxCamera ();
725736 camCutscene = new FlxCamera ();
726737 camCutouts = new FlxCamera ();
738+ camSubtitles = new FlxCamera ();
727739 camPause = new FlxCamera ();
728740
729741 var currentChart = currentSong .getDifficulty (currentDifficulty , currentVariation );
@@ -1856,12 +1868,14 @@ class PlayState extends MusicBeatSubState
18561868 camCutouts .setPosition ((FlxG .width - FlxG .initialWidth ) / 2 , (FlxG .height - FlxG .initialHeight ) / 2 );
18571869 camCutouts .setSize (FlxG .initialWidth , FlxG .initialHeight );
18581870 camCutouts .bgColor .alpha = 0 ; // Show the game scene behind the camera.
1871+ if (Preferences .subtitles ) camSubtitles .bgColor .alpha = 0 ; // Show the game scene behind the camera.
18591872 camPause .bgColor .alpha = 0 ; // Show the game scene behind the camera.
18601873
18611874 FlxG .cameras .reset (camGame );
18621875 FlxG .cameras .add (camHUD , false );
18631876 FlxG .cameras .add (camCutscene , false );
18641877 FlxG .cameras .add (camCutouts , false );
1878+ if (Preferences .subtitles ) FlxG .cameras .add (camSubtitles , false );
18651879 FlxG .cameras .add (camPause , false );
18661880
18671881 // Configure camera follow point.
@@ -1878,11 +1892,11 @@ class PlayState extends MusicBeatSubState
18781892 */
18791893 function initHealthBar (): Void
18801894 {
1881- var healthBarYPos : Float = Preferences . downscroll ? FlxG . height * 0.1 : FlxG . height * 0.9 ;
1882- #if mobile
1883- if ( Preferences . controlsScheme == FunkinHitboxControlSchemes . Arrows
1884- && ! ControlsHandler . usingExternalInputDevice ) healthBarYPos = FlxG . height * 0.1 ;
1885- #end
1895+ final isDownscroll : Bool = #if mobile ( Preferences . controlsScheme == FunkinHitboxControlSchemes . Arrows
1896+ && ! ControlsHandler . usingExternalInputDevice )
1897+ || #end Preferences . downscroll ;
1898+
1899+ var healthBarYPos : Float = isDownscroll ? FlxG . height * 0.1 : FlxG . height * 0.9 ;
18861900
18871901 healthBarBG .y = healthBarYPos ;
18881902 healthBarBG .screenCenter (X );
@@ -1911,6 +1925,21 @@ class PlayState extends MusicBeatSubState
19111925 healthBar .cameras = [camHUD ];
19121926 healthBarBG .cameras = [camHUD ];
19131927 scoreText .cameras = [camHUD ];
1928+
1929+ // Create subtitles if they are enabled.
1930+ if (Preferences .subtitles )
1931+ {
1932+ final isDownscroll : Bool = #if mobile (Preferences .controlsScheme == FunkinHitboxControlSchemes . Arrows
1933+ && ! ControlsHandler .usingExternalInputDevice )
1934+ || #end Preferences .downscroll ;
1935+
1936+ final subtitlesAlignment : SubtitlesAlignment = isDownscroll ? SubtitlesAlignment .SUBTITLES_TOP : SubtitlesAlignment .SUBTITLES_BOTTOM ;
1937+ subtitles = new Subtitles (0 , 139 , subtitlesAlignment );
1938+ subtitles .zIndex = 10000 ;
1939+ add (subtitles );
1940+
1941+ subtitles .cameras = [camSubtitles ];
1942+ }
19141943 }
19151944
19161945 /**
@@ -2472,6 +2501,16 @@ class PlayState extends MusicBeatSubState
24722501 FlxG .sound .music .time = startTimestamp ;
24732502 FlxG .sound .music .pitch = playbackRate ;
24742503
2504+ if (Preferences .subtitles )
2505+ {
2506+ var subtitlesFile : String = ' songs/ ${currentSong .id }/subtitles/song-lyrics' ;
2507+ if (currentVariation != Constants .DEFAULT_VARIATION )
2508+ {
2509+ subtitlesFile + = ' - ${currentVariation }' ;
2510+ }
2511+ if (subtitles != null ) subtitles .assignSubtitles (subtitlesFile , FlxG .sound .music );
2512+ }
2513+
24752514 // Prevent the volume from being wrong.
24762515 FlxG .sound .music .volume = 1.0 ;
24772516 if (FlxG .sound .music .fadeTween != null ) FlxG .sound .music .fadeTween .cancel ();
0 commit comments