1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 22:07:28 +08:00
osu-lazer/osu.Game/Screens/Play/SongProgress.cs

155 lines
4.6 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2017-03-23 17:37:12 +08:00
using System;
using System.Collections.Generic;
using osu.Game.Graphics;
using osu.Framework.Allocation;
using System.Linq;
using osu.Framework.Timing;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Screens.Play
{
public class SongProgress : OverlayContainer
{
2017-04-18 17:29:24 +08:00
private const int bottom_bar_height = 5;
2017-04-07 14:20:39 +08:00
private static readonly Vector2 handle_size = new Vector2(14, 25);
private const float transition_duration = 200;
2017-03-24 11:41:56 +08:00
private readonly SongProgressBar bar;
private readonly SongProgressGraph graph;
2017-04-28 09:56:34 +08:00
private readonly SongProgressInfo info;
2017-03-23 17:37:12 +08:00
public Action<double> OnSeek;
public override bool HandleInput => AllowSeeking;
2017-05-09 11:05:37 +08:00
private IClock audioClock;
2017-05-10 08:45:31 +08:00
public IClock AudioClock { set { audioClock = info.AudioClock = value; } }
private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1;
private double firstHitTime => objects.First().StartTime;
private IEnumerable<HitObject> objects;
public IEnumerable<HitObject> Objects
{
set
{
graph.Objects = objects = value;
2017-05-09 11:05:37 +08:00
info.StartTime = firstHitTime;
info.EndTime = lastHitTime;
2017-06-23 00:42:29 +08:00
bar.StartTime = firstHitTime;
bar.EndTime = lastHitTime;
}
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
graph.FillColour = bar.FillColour = colours.BlueLighter;
}
public SongProgress()
{
const float graph_height = SquareGraph.Column.WIDTH * 6;
Height = bottom_bar_height + graph_height + handle_size.Y;
2017-04-18 17:29:24 +08:00
Y = bottom_bar_height;
Children = new Drawable[]
{
2017-04-28 09:56:34 +08:00
info = new SongProgressInfo
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2017-05-09 11:05:37 +08:00
Margin = new MarginPadding { Bottom = bottom_bar_height + graph_height },
2017-04-28 09:56:34 +08:00
},
graph = new SongProgressGraph
{
RelativeSizeAxes = Axes.X,
2017-03-23 19:13:03 +08:00
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Height = graph_height,
2017-04-18 17:29:24 +08:00
Margin = new MarginPadding { Bottom = bottom_bar_height },
},
bar = new SongProgressBar(bottom_bar_height, graph_height, handle_size)
{
Alpha = 0,
2017-03-23 19:13:03 +08:00
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
OnSeek = position => OnSeek?.Invoke(position),
2017-03-23 19:13:03 +08:00
},
};
}
2017-03-23 17:37:12 +08:00
protected override void LoadComplete()
{
State = Visibility.Visible;
}
private bool allowSeeking;
public bool AllowSeeking
2017-03-23 17:37:12 +08:00
{
get
{
return allowSeeking;
}
set
{
if (allowSeeking == value) return;
allowSeeking = value;
updateBarVisibility();
}
}
private void updateBarVisibility()
{
2017-07-23 02:50:25 +08:00
bar.FadeTo(allowSeeking ? 1 : 0, transition_duration, Easing.In);
this.MoveTo(new Vector2(0, allowSeeking ? 0 : bottom_bar_height), transition_duration, Easing.In);
}
protected override void PopIn()
{
updateBarVisibility();
2017-07-23 02:50:25 +08:00
this.FadeIn(500, Easing.OutQuint);
2017-03-23 17:37:12 +08:00
}
protected override void PopOut()
{
this.FadeOut(100);
2017-03-23 17:37:12 +08:00
}
2017-04-07 14:20:39 +08:00
protected override void Update()
{
base.Update();
if (objects == null)
return;
2017-06-23 00:42:29 +08:00
double position = audioClock?.CurrentTime ?? Time.Current;
double progress = (position - firstHitTime) / (lastHitTime - firstHitTime);
2017-06-08 14:35:10 +08:00
if (progress < 1)
2017-05-11 06:48:46 +08:00
{
2017-06-23 00:42:29 +08:00
bar.CurrentTime = position;
2017-05-11 06:48:46 +08:00
graph.Progress = (int)(graph.ColumnCount * progress);
}
2017-04-07 14:20:39 +08:00
}
}
}