Skip to content

Commit e0bd5b8

Browse files
sector-aHundrec
authored andcommitted
Add Subtitles to the Chart Editor!
1 parent 0691207 commit e0bd5b8

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

source/funkin/play/PlayState.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,7 @@ class PlayState extends MusicBeatSubState
24982498

24992499
if (Preferences.subtitles)
25002500
{
2501-
var subtitlesFile = 'songs/${currentSong.id}/subtitles/song-lyrics';
2501+
var subtitlesFile:String = 'songs/${currentSong.id}/subtitles/song-lyrics';
25022502
if (currentVariation != Constants.DEFAULT_VARIATION)
25032503
{
25042504
subtitlesFile += '-${currentVariation}';

source/funkin/save/Save.hx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,23 @@ class Save implements ConsoleClass
379379
return data.optionsChartEditor.showNoteKinds;
380380
}
381381

382+
public var chartEditorShowSubtitles(get, set):Bool;
383+
384+
function get_chartEditorShowSubtitles():Bool
385+
{
386+
if (data.optionsChartEditor.showSubtitles == null) data.optionsChartEditor.showSubtitles = true;
387+
388+
return data.optionsChartEditor.showSubtitles;
389+
}
390+
391+
function set_chartEditorShowSubtitles(value:Bool):Bool
392+
{
393+
// Set and apply.
394+
data.optionsChartEditor.showSubtitles = value;
395+
flush();
396+
return data.optionsChartEditor.showSubtitles;
397+
}
398+
382399
public var chartEditorPlaytestStartTime(get, set):Bool;
383400

384401
function get_chartEditorPlaytestStartTime():Bool
@@ -1886,6 +1903,12 @@ typedef SaveDataChartEditorOptions =
18861903
*/
18871904
var ?showNoteKinds:Bool;
18881905

1906+
/**
1907+
* Show Subtitles in the Chart Editor.
1908+
* @default `true`
1909+
*/
1910+
var ?showSubtitles:Bool;
1911+
18891912
/**
18901913
* Metronome volume in the Chart Editor.
18911914
* @default `1.0`

source/funkin/ui/debug/charting/ChartEditorState.hx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import funkin.play.notes.notekind.NoteKindManager;
4545
import funkin.play.character.BaseCharacter.CharacterType;
4646
import funkin.data.character.CharacterData.CharacterDataParser;
4747
import funkin.play.components.HealthIcon;
48+
import funkin.play.components.Subtitles;
4849
import funkin.play.notes.NoteSprite;
4950
import funkin.play.PlayStatePlaylist;
5051
import funkin.play.song.Song;
@@ -640,6 +641,23 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
640641
*/
641642
var showNoteKindIndicators:Bool = false;
642643

644+
/**
645+
* Toggles the subtitles.
646+
*/
647+
var showSubtitles(default, set):Bool = false;
648+
649+
function set_showSubtitles(value:Bool):Bool
650+
{
651+
showSubtitles = value;
652+
653+
if (subtitles != null)
654+
{
655+
subtitles.exists = showSubtitles;
656+
}
657+
658+
return showSubtitles;
659+
}
660+
643661
/**
644662
* The current theme used by the editor.
645663
* Dictates the appearance of many UI elements.
@@ -1915,6 +1933,11 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
19151933
*/
19161934
var menubarItemViewIndicators:MenuCheckBox;
19171935

1936+
/**
1937+
* The `View -> Subtitles` menu item.
1938+
*/
1939+
var menubarItemViewSubtitles:MenuCheckBox;
1940+
19181941
/**
19191942
* The `View -> Increase Difficulty` menu item.
19201943
*/
@@ -2226,6 +2249,11 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
22262249
*/
22272250
var menuBG:Null<FlxSprite> = null;
22282251

2252+
/**
2253+
* The subtitles to display song's lyrics.
2254+
*/
2255+
var subtitles:Null<Subtitles> = null;
2256+
22292257
/**
22302258
* The sprite group containing the note graphics.
22312259
* Only displays a subset of the data from `currentSongChartNoteData`,
@@ -2338,6 +2366,8 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
23382366
populateOpenRecentMenu();
23392367
this.applyPlatformShortcutText();
23402368

2369+
createSubtitles();
2370+
23412371
// Setup the onClick listeners for the UI after it's been created.
23422372
setupUIListeners();
23432373
setupContextMenu();
@@ -2435,6 +2465,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
24352465
currentLiveInputStyle = save.chartEditorLiveInputStyle;
24362466
isViewDownscroll = save.chartEditorDownscroll;
24372467
showNoteKindIndicators = save.chartEditorShowNoteKinds;
2468+
showSubtitles = save.chartEditorShowSubtitles;
24382469
playtestStartTime = save.chartEditorPlaytestStartTime;
24392470
currentTheme = save.chartEditorTheme;
24402471
metronomeVolume = save.chartEditorMetronomeVolume;
@@ -2654,6 +2685,14 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
26542685
add(audioWaveforms);
26552686
}
26562687

2688+
function createSubtitles():Void
2689+
{
2690+
subtitles = new Subtitles(FlxG.height * 0.85);
2691+
subtitles.zIndex = 100;
2692+
subtitles.cameras = [uiCamera];
2693+
add(subtitles);
2694+
}
2695+
26572696
function buildMeasureTicks():Void
26582697
{
26592698
measureTicks = new ChartEditorMeasureTicks(this);
@@ -3179,6 +3218,9 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
31793218
menubarItemViewIndicators.onClick = event -> showNoteKindIndicators = menubarItemViewIndicators.selected;
31803219
menubarItemViewIndicators.selected = showNoteKindIndicators;
31813220

3221+
menubarItemViewSubtitles.onClick = event -> showSubtitles = menubarItemViewSubtitles.selected;
3222+
menubarItemViewSubtitles.selected = showSubtitles;
3223+
31823224
menubarItemDifficultyUp.onClick = _ -> incrementDifficulty(1);
31833225
menubarItemDifficultyDown.onClick = _ -> incrementDifficulty(-1);
31843226

@@ -6866,6 +6908,16 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
68666908
healthIconsDirty = true;
68676909
}
68686910

6911+
public function loadSubtitles():Void
6912+
{
6913+
var subtitlesFile:String = 'songs/${currentSongId}/subtitles/song-lyrics';
6914+
if (selectedVariation != Constants.DEFAULT_VARIATION)
6915+
{
6916+
subtitlesFile += '-${selectedVariation}';
6917+
}
6918+
subtitles.assignSubtitles(subtitlesFile, audioInstTrack);
6919+
}
6920+
68696921
public function postLoadVocals():Void
68706922
{
68716923
// Reapply the volume and playback rate.

source/funkin/ui/debug/charting/handlers/ChartEditorAudioHandler.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class ChartEditorAudioHandler
144144

145145
state.hardRefreshFreeplayToolbox();
146146

147+
state.loadSubtitles();
148+
147149
return true;
148150
}
149151

0 commit comments

Comments
 (0)