Removed DragBar from song progress

This commit is contained in:
Jai Sharma 2017-06-22 17:42:29 +01:00
parent ce2242a979
commit 73c004fb71
5 changed files with 97 additions and 163 deletions

View File

@ -1,110 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using OpenTK;
using osu.Framework.Graphics.Shapes;
namespace osu.Game.Overlays
{
public class DragBar : Container
{
protected readonly Container Fill;
public Action<float> SeekRequested;
public bool IsSeeking { get; private set; }
private bool enabled = true;
public bool IsEnabled
{
get { return enabled; }
set
{
enabled = value;
if (!enabled)
Fill.Width = 0;
}
}
public DragBar()
{
RelativeSizeAxes = Axes.X;
Children = new Drawable[]
{
Fill = new Container
{
Name = "FillContainer",
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Width = 0,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both
}
}
}
};
}
public void UpdatePosition(float position)
{
if (IsSeeking || !IsEnabled) return;
updatePosition(position, false);
}
private void seek(InputState state)
{
float seekLocation = state.Mouse.Position.X / DrawWidth;
if (!IsEnabled) return;
SeekRequested?.Invoke(seekLocation);
updatePosition(seekLocation);
}
private void updatePosition(float position, bool easing = true)
{
position = MathHelper.Clamp(position, 0, 1);
Fill.TransformTo(() => Fill.Width, position, easing ? 200 : 0, EasingTypes.OutQuint, new TransformSeek());
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
seek(state);
return true;
}
protected override bool OnDrag(InputState state)
{
seek(state);
return true;
}
protected override bool OnDragStart(InputState state) => IsSeeking = true;
protected override bool OnDragEnd(InputState state)
{
IsSeeking = false;
return true;
}
private class TransformSeek : TransformFloat<Drawable>
{
public override void Apply(Drawable d)
{
base.Apply(d);
d.Width = CurrentValue;
}
}
}
}

View File

@ -226,7 +226,7 @@ protected override void Update()
{ {
var track = current.Track; var track = current.Track;
progressBar.Progress = track.CurrentTime; progressBar.CurrentTime = track.CurrentTime;
playButton.Icon = track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o; playButton.Icon = track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o;
if (track.HasCompleted && !track.Looping) next(); if (track.HasCompleted && !track.Looping) next();
@ -437,7 +437,7 @@ public double EndTime
set { CurrentNumber.MaxValue = value; } set { CurrentNumber.MaxValue = value; }
} }
public double Progress public double CurrentTime
{ {
set { CurrentNumber.Value = value; } set { CurrentNumber.Value = value; }
} }
@ -445,7 +445,7 @@ public double Progress
public ProgressBar() public ProgressBar()
{ {
CurrentNumber.MinValue = 0; CurrentNumber.MinValue = 0;
CurrentNumber.MaxValue = 1; CurrentNumber.MinValue = 1;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Children = new Drawable[] Children = new Drawable[]

View File

@ -50,6 +50,9 @@ public IEnumerable<HitObject> Objects
info.StartTime = firstHitTime; info.StartTime = firstHitTime;
info.EndTime = lastHitTime; info.EndTime = lastHitTime;
bar.StartTime = firstHitTime;
bar.EndTime = lastHitTime;
} }
} }
@ -89,10 +92,7 @@ public SongProgress()
Alpha = 0, Alpha = 0,
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
SeekRequested = delegate (float position) OnSeek = position => this.OnSeek?.Invoke(position),
{
OnSeek?.Invoke(firstHitTime + position * (lastHitTime - firstHitTime));
},
}, },
}; };
} }
@ -144,11 +144,12 @@ protected override void Update()
if (objects == null) if (objects == null)
return; return;
double progress = ((audioClock?.CurrentTime ?? Time.Current) - firstHitTime) / (lastHitTime - firstHitTime); double position = audioClock?.CurrentTime ?? Time.Current;
double progress = (position - firstHitTime) / (lastHitTime - firstHitTime);
if (progress < 1) if (progress < 1)
{ {
bar.UpdatePosition((float)progress); bar.CurrentTime = position;
graph.Progress = (int)(graph.ColumnCount * progress); graph.Progress = (int)(graph.ColumnCount * progress);
} }
} }

View File

@ -1,31 +1,55 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Overlays;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public class SongProgressBar : DragBar public class SongProgressBar : SliderBar<double>
{ {
public Action<double> OnSeek;
private Box fill;
private Box background;
private Container handleBase;
public Color4 FillColour public Color4 FillColour
{ {
get { return Fill.Colour; } set { fill.Colour = value; }
set { Fill.Colour = value; } }
public double StartTime
{
set { CurrentNumber.MinValue = value; }
}
public double EndTime
{
set { CurrentNumber.MaxValue = value; }
}
public double CurrentTime
{
set { CurrentNumber.Value = value; }
} }
public SongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSize) public SongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSize)
{ {
CurrentNumber.MinValue = 0;
CurrentNumber.MaxValue = 1;
RelativeSizeAxes = Axes.X;
Height = barHeight + handleBarHeight + handleSize.Y; Height = barHeight + handleBarHeight + handleSize.Y;
Fill.RelativeSizeAxes = Axes.X; Children = new Drawable[]
Fill.Height = barHeight; {
background = new Box
Add(new Box
{ {
Name = "Background", Name = "Background",
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
@ -34,13 +58,20 @@ public SongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSiz
Height = barHeight, Height = barHeight,
Colour = Color4.Black, Colour = Color4.Black,
Alpha = 0.5f, Alpha = 0.5f,
Depth = 1 Depth = 1,
}); },
fill = new Box
Fill.Add(new Container
{ {
Origin = Anchor.BottomRight, Name = "Fill",
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Height = barHeight,
},
handleBase = new Container
{
Name = "HandleBar container",
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Width = 2, Width = 2,
Height = barHeight + handleBarHeight, Height = barHeight + handleBarHeight,
Colour = Color4.White, Colour = Color4.White,
@ -49,10 +80,12 @@ public SongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSiz
{ {
new Box new Box
{ {
Name = "HandleBar box",
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
new Container new Container
{ {
Name = "Handle container",
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Size = handleSize, Size = handleSize,
@ -62,13 +95,24 @@ public SongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSiz
{ {
new Box new Box
{ {
Name = "Handle box",
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4.White Colour = Color4.White
} }
} }
} }
} }
}); }
} };
}
protected override void UpdateValue(float value)
{
var xFill = value * UsableWidth;
fill.Width = xFill;
handleBase.MoveToX(xFill);
}
protected override void OnUserChange() => OnSeek?.Invoke(Current);
} }
} }

View File

@ -214,7 +214,6 @@
<Compile Include="Online\API\Requests\GetScoresRequest.cs" /> <Compile Include="Online\API\Requests\GetScoresRequest.cs" />
<Compile Include="Online\API\Requests\GetBeatmapDetailsRequest.cs" /> <Compile Include="Online\API\Requests\GetBeatmapDetailsRequest.cs" />
<Compile Include="Online\API\Requests\GetUserRequest.cs" /> <Compile Include="Online\API\Requests\GetUserRequest.cs" />
<Compile Include="Overlays\DragBar.cs" />
<Compile Include="Overlays\LoginOverlay.cs" /> <Compile Include="Overlays\LoginOverlay.cs" />
<Compile Include="Overlays\MusicController.cs" /> <Compile Include="Overlays\MusicController.cs" />
<Compile Include="Beatmaps\Beatmap.cs" /> <Compile Include="Beatmaps\Beatmap.cs" />