playback speed WIP

This commit is contained in:
lunarcleint
2023-09-30 12:41:50 -07:00
parent bfb8f4c771
commit f1ea88ec02
2 changed files with 63 additions and 16 deletions
+5 -2
View File
@@ -376,8 +376,11 @@ class Charter extends UIState {
songPosInfo.alignment = RIGHT;
uiGroup.add(songPosInfo);
//playBackSlider = new UISlider(FlxG.width - 180 - 26 - 12, (23/2) - (4/2), 180, [{start: 0.25, end: 1, size: 0.5}, {start: 1, end: 3, size: 0.5}]);
//uiGroup.add(playBackSlider);
playBackSlider = new UISlider(FlxG.width - 180 - 26 - 12, (23/2) - (4/2), 180, [{start: 0.5, end: 1, size: 0.5}, {start: 1, end: 3, size: 0.5}], 0.5);
playBackSlider.onChange = function (v) {
FlxG.sound.music.pitch = vocals.pitch = v;
};
uiGroup.add(playBackSlider);
strumlineInfoBG = new UISprite();
strumlineInfoBG.loadGraphic(Paths.image('editors/charter/strumline-info-bg'));
+58 -14
View File
@@ -18,19 +18,28 @@ class UISlider extends UISprite {
public var endText:UIText;
public var barSegements:Map<{segment:Float, size:Float}, UISprite> = [];
public var selectableBar:UISprite;
public var selectableHitbox:UISprite;
public function new(x:Float, y:Float, width:Int = 120, segments:Array<SliderSegement>) {
public var value:Float = 0;
public var onChange:Float->Void;
public function new(x:Float, y:Float, width:Int = 120, segments:Array<SliderSegement>, defaultStart:Float = 0) {
this.segments = segments;
this.barWidth = width;
x -= 6;
super(x, y);
makeSolid(barWidth, 4, -1);
makeSolid((barWidth+6), 4, -1);
cursor = BUTTON;
__barProgress = defaultStart;
members.push(barStartSpr = new FlxSprite(x-4,y+((4/2))).makeSolid(4, 12, -1));
members.push(barEndSpr = new FlxSprite(x+barWidth,y+((4/2))).makeSolid(4, 12, -1));
members.push(barEndSpr = new FlxSprite(x+barWidth+6,y+((4/2))).makeSolid(4, 12, -1));
members.push(startText = new UIText(x, y, 0, Std.string(segments[0].start).replace("0.", ".")));
members.push(endText = new UIText(x + barWidth + 8, y, 0, Std.string(segments[segments.length-1].end)));
members.push(endText = new UIText(x + (barWidth+6) + 8, y, 0, Std.string(segments[segments.length-1].end)));
var midSegments:Map<Int, Float> = [];
for (segment in segments) {
@@ -44,26 +53,61 @@ class UISlider extends UISprite {
for (segment => size in midSegments) {
var segmentSpr:UISprite = new UISprite(x,y);
segmentSpr.makeSolid(4, 8, -1);
segmentSpr.members = [new UIText(x, y, 0, Std.string(segment/1000).replace("0.", "."), 10)];
members.push(segmentSpr);
barSegements.set({segment: segment/1000, size: size}, segmentSpr);
}
selectableBar = new UISprite(x,y);
selectableBar.makeSolid(6, 12, 0xFFA0A0A0);
selectableBar.cursor = BUTTON;
members.push(selectableBar);
selectableHitbox = new UISprite(x,y);
selectableHitbox.makeSolid(barWidth+6, 16, -1);
selectableHitbox.cursor = BUTTON;
selectableHitbox.alpha = 0;
members.push(selectableHitbox);
}
var __barProgress:Float = 0;
public override function update(elapsed:Float) {
barStartSpr.follow(this, -4, (4-12)/2);
barEndSpr.follow(this, barWidth, (4-12)/2);
barStartSpr.follow(this, -4, (height-barStartSpr.height)/2);
barEndSpr.follow(this, barWidth+6, (height-barEndSpr.height)/2);
selectableHitbox.follow(this, 0, (height-selectableHitbox.height)/2);
var lastBarProgress:Float = __barProgress;
if (selectableHitbox.hovered && FlxG.mouse.pressed) {
var mousePos = FlxG.mouse.getScreenPosition(__lastDrawCameras[0], FlxPoint.get());
__barProgress = FlxMath.bound(mousePos.x-x, 0, barWidth)/barWidth;
mousePos.put();
}
if (__barProgress != lastBarProgress)
onChange(value = calcValue(__barProgress));
selectableBar.follow(this, __barProgress * barWidth, (4-12)/2);
startText.follow(this, -startText.width-10, (4/2) - (startText.height/2));
endText.follow(this, barWidth + 10, (4/2) - (endText.height/2));
endText.follow(this, barWidth+6 + 10, (4/2) - (endText.height/2));
for (segmentData => sprite in barSegements) {
sprite.follow(this, (barWidth * segmentData.size) - (sprite.width/2), ((4-8)/2) -2);
if (sprite.members[0] != null && sprite.members[0] is UIText)
cast(sprite.members[0], UIText).follow(sprite,0,sprite.height);
}
for (segmentData => sprite in barSegements)
sprite.follow(this, (barWidth * segmentData.size) + ((selectableBar.width-sprite.width)/2), ((4-8)/2));
super.update(elapsed);
}
function calcValue(progress:Float):Float {
var totalProgress:Float = 0;
for (segment in segments) {
if (progress < totalProgress + segment.size) {
var relativeProgress = (progress - totalProgress) / segment.size;
return FlxMath.remapToRange(relativeProgress, 0, 1, segment.start, segment.end);
}
totalProgress += segment.size;
}
return segments[segments.length-1].end;
}
}