Skip to content

Commit c39046d

Browse files
sector-aHundrec
authored andcommitted
Improve the way positioning is done
1 parent 476336b commit c39046d

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

source/funkin/play/PlayState.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,8 +1933,8 @@ class PlayState extends MusicBeatSubState
19331933
&& !ControlsHandler.usingExternalInputDevice)
19341934
|| #end Preferences.downscroll;
19351935

1936-
var subtitlesYPos:Float = isDownscroll ? healthBarBG.y * 1.85 : healthBarBG.y * 0.85;
1937-
subtitles = new Subtitles(subtitlesYPos);
1936+
final subtitlesAlignment:SubtitlesAlignment = isDownscroll ? SubtitlesAlignment.SUBTITLES_TOP : SubtitlesAlignment.SUBTITLES_BOTTOM;
1937+
subtitles = new Subtitles(0, 139, subtitlesAlignment);
19381938
subtitles.zIndex = 10000;
19391939
add(subtitles);
19401940

source/funkin/play/components/Subtitles.hx

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ class Subtitles extends FlxSpriteGroup
1919
var subtitlesData:Array<SubtitleEntry>;
2020
var assignedSound:FlxSound;
2121

22-
public function new(y:Float = 0)
22+
public var offsets(default, set):Array<Float> = [0, 0];
23+
public var alignment(default, set):SubtitlesAlignment = SubtitlesAlignment.SUBTITLES_BOTTOM;
24+
25+
public function new(x:Float = 0, y:Float = 0, alignment:SubtitlesAlignment = SubtitlesAlignment.SUBTITLES_BOTTOM)
2326
{
24-
super(0, y);
27+
super(0, 0);
28+
29+
this.offsets = [x, y];
30+
this.alignment = alignment;
2531

2632
background = new FlxSprite(0, 0);
2733
background.alpha = 0.5;
@@ -97,7 +103,37 @@ class Subtitles extends FlxSpriteGroup
97103

98104
background.makeGraphic(Math.ceil(subtitleText.width), Math.ceil(subtitleText.height), FlxColor.BLACK, true);
99105

106+
updatePosition();
107+
}
108+
109+
function updatePosition():Void
110+
{
100111
screenCenter(X);
112+
x += offsets[0];
113+
114+
switch (alignment)
115+
{
116+
case SubtitlesAlignment.SUBTITLES_TOP:
117+
y = 0 + offsets[1];
118+
case SubtitlesAlignment.SUBTITLES_BOTTOM:
119+
y = FlxG.height - this.height - offsets[1];
120+
}
121+
}
122+
123+
function set_alignment(value:SubtitlesAlignment):SubtitlesAlignment
124+
{
125+
alignment = value;
126+
updatePosition();
127+
128+
return alignment;
129+
}
130+
131+
function set_offsets(value:Array<Float>):Array<Float>
132+
{
133+
offsets = value;
134+
updatePosition();
135+
136+
return offsets;
101137
}
102138
}
103139

@@ -130,3 +166,19 @@ class SubtitlesText extends FlxText
130166
return Text;
131167
}
132168
}
169+
170+
/**
171+
* An abstract for subtitles alignment.
172+
*/
173+
enum abstract SubtitlesAlignment(String) from String to String
174+
{
175+
/**
176+
* Subtitles will be aligned at the top.
177+
*/
178+
var SUBTITLES_TOP:String = 'top';
179+
180+
/**
181+
* Subtitles will be aligned at the bottom.
182+
*/
183+
var SUBTITLES_BOTTOM:String = 'bottom';
184+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2687,7 +2687,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
26872687

26882688
function createSubtitles():Void
26892689
{
2690-
subtitles = new Subtitles(FlxG.height * 0.85);
2690+
subtitles = new Subtitles(0, -78);
26912691
subtitles.zIndex = 100;
26922692
subtitles.cameras = [uiCamera];
26932693
add(subtitles);

0 commit comments

Comments
 (0)