2019-11-25 17:48:58 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-07-10 18:28:25 +08:00
|
|
|
using System;
|
2024-08-27 15:30:49 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2024-01-04 15:42:05 +08:00
|
|
|
using osu.Framework.Bindables;
|
2024-08-27 13:53:49 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-09-21 03:33:07 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2024-08-27 13:53:49 +08:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2017-09-21 03:33:07 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-03-03 23:50:41 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2024-08-27 15:30:49 +08:00
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2017-09-21 03:33:07 +08:00
|
|
|
using osu.Game.Beatmaps.Timing;
|
2024-08-27 13:53:49 +08:00
|
|
|
using osu.Game.Graphics;
|
2024-08-27 15:30:49 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2017-09-23 21:42:18 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2024-01-04 15:42:05 +08:00
|
|
|
using osu.Game.Scoring;
|
2018-03-03 23:50:41 +08:00
|
|
|
using osu.Game.Screens.Play.Break;
|
2024-08-27 15:30:49 +08:00
|
|
|
using osu.Game.Utils;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-03-03 23:50:41 +08:00
|
|
|
namespace osu.Game.Screens.Play
|
2017-09-21 03:33:07 +08:00
|
|
|
{
|
2024-08-27 15:30:49 +08:00
|
|
|
public partial class BreakOverlay : BeatSyncedContainer
|
2017-09-21 03:33:07 +08:00
|
|
|
{
|
2019-08-07 21:59:35 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The duration of the break overlay fading.
|
|
|
|
/// </summary>
|
|
|
|
public const double BREAK_FADE_DURATION = BreakPeriod.MIN_BREAK_DURATION / 2;
|
|
|
|
|
2017-09-23 01:43:51 +08:00
|
|
|
private const float remaining_time_container_max_size = 0.3f;
|
2024-08-27 15:30:49 +08:00
|
|
|
private const int vertical_margin = 15;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-03-03 23:50:41 +08:00
|
|
|
private readonly Container fadeContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-03 20:20:36 +08:00
|
|
|
public override bool RemoveCompletedTransforms => false;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
public BreakTracker BreakTracker { get; init; } = null!;
|
|
|
|
|
2017-10-06 09:49:16 +08:00
|
|
|
private readonly Container remainingTimeAdjustmentBox;
|
2017-09-21 03:33:07 +08:00
|
|
|
private readonly Container remainingTimeBox;
|
|
|
|
private readonly RemainingTimeCounter remainingTimeCounter;
|
2018-03-03 23:50:41 +08:00
|
|
|
private readonly BreakArrows breakArrows;
|
2023-08-03 00:40:22 +08:00
|
|
|
private readonly ScoreProcessor scoreProcessor;
|
|
|
|
private readonly BreakInfo info;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
private readonly IBindable<Period?> currentPeriod = new Bindable<Period?>();
|
|
|
|
|
2020-03-28 11:18:28 +08:00
|
|
|
public BreakOverlay(bool letterboxing, ScoreProcessor scoreProcessor)
|
2017-09-21 03:33:07 +08:00
|
|
|
{
|
2023-08-03 00:40:22 +08:00
|
|
|
this.scoreProcessor = scoreProcessor;
|
2017-09-21 03:33:07 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2020-03-26 14:28:56 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
MinimumBeatLength = 200;
|
|
|
|
|
2018-03-03 23:50:41 +08:00
|
|
|
Child = fadeContainer = new Container
|
2017-09-21 03:33:07 +08:00
|
|
|
{
|
2018-03-03 23:50:41 +08:00
|
|
|
Alpha = 0,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
2017-09-21 03:33:07 +08:00
|
|
|
{
|
2018-03-03 23:50:41 +08:00
|
|
|
new LetterboxOverlay
|
2017-10-06 09:49:16 +08:00
|
|
|
{
|
2018-03-03 23:50:41 +08:00
|
|
|
Alpha = letterboxing ? 1 : 0,
|
2017-10-06 09:49:16 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2018-03-03 23:50:41 +08:00
|
|
|
},
|
2024-08-27 13:53:49 +08:00
|
|
|
new CircularContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Width = 80,
|
|
|
|
Height = 4,
|
|
|
|
Masking = true,
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = 260,
|
|
|
|
Colour = OsuColour.Gray(0.2f).Opacity(0.8f),
|
|
|
|
Roundness = 12
|
|
|
|
},
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Alpha = 0,
|
|
|
|
AlwaysPresent = true,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2018-03-03 23:50:41 +08:00
|
|
|
remainingTimeAdjustmentBox = new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-10-06 09:49:16 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-03-03 23:50:41 +08:00
|
|
|
Width = 0,
|
2024-07-10 18:28:25 +08:00
|
|
|
Child = remainingTimeBox = new Circle
|
2018-03-03 23:50:41 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = 8,
|
|
|
|
Masking = true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
remainingTimeCounter = new RemainingTimeCounter
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
2024-08-27 15:30:49 +08:00
|
|
|
Y = -vertical_margin,
|
2018-03-03 23:50:41 +08:00
|
|
|
},
|
|
|
|
info = new BreakInfo
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2024-08-27 15:30:49 +08:00
|
|
|
Y = vertical_margin,
|
2018-03-03 23:50:41 +08:00
|
|
|
},
|
|
|
|
breakArrows = new BreakArrows
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2017-10-06 09:49:16 +08:00
|
|
|
}
|
2017-09-21 03:33:07 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-03-03 23:50:41 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2023-08-03 00:40:22 +08:00
|
|
|
|
2024-08-27 13:56:57 +08:00
|
|
|
info.AccuracyDisplay.Current.BindTo(scoreProcessor.Accuracy);
|
|
|
|
((IBindable<ScoreRank>)info.GradeDisplay.Current).BindTo(scoreProcessor.Rank);
|
2024-08-27 15:30:49 +08:00
|
|
|
|
|
|
|
currentPeriod.BindTo(BreakTracker.CurrentPeriod);
|
|
|
|
currentPeriod.BindValueChanged(updateDisplay, true);
|
2018-03-03 23:50:41 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
private float remainingTimeForCurrentPeriod =>
|
|
|
|
currentPeriod.Value == null ? 0 : (float)Math.Max(0, (currentPeriod.Value.Value.End - Time.Current - BREAK_FADE_DURATION) / currentPeriod.Value.Value.Duration);
|
|
|
|
|
2024-07-10 18:28:25 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
if (currentPeriod.Value != null)
|
|
|
|
{
|
|
|
|
remainingTimeBox.Height = Math.Min(8, remainingTimeBox.DrawWidth);
|
|
|
|
remainingTimeCounter.X = -(remainingTimeForCurrentPeriod - 0.5f) * 30;
|
|
|
|
info.X = (remainingTimeForCurrentPeriod - 0.5f) * 30;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
|
|
|
|
{
|
|
|
|
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
|
|
|
|
|
|
|
|
if (currentPeriod.Value == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
float timeBoxTargetWidth = (float)Math.Max(0, (remainingTimeForCurrentPeriod - timingPoint.BeatLength / currentPeriod.Value.Value.Duration));
|
|
|
|
remainingTimeBox.ResizeWidthTo(timeBoxTargetWidth, timingPoint.BeatLength * 2, Easing.OutQuint);
|
2024-07-10 18:28:25 +08:00
|
|
|
}
|
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
private void updateDisplay(ValueChangedEvent<Period?> period)
|
2017-09-21 03:33:07 +08:00
|
|
|
{
|
2017-10-02 05:44:57 +08:00
|
|
|
FinishTransforms(true);
|
2017-10-02 13:51:00 +08:00
|
|
|
Scheduler.CancelDelayedTasks();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
if (period.NewValue == null)
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
var b = period.NewValue.Value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
using (BeginAbsoluteSequence(b.Start))
|
|
|
|
{
|
|
|
|
fadeContainer.FadeIn(BREAK_FADE_DURATION);
|
|
|
|
breakArrows.Show(BREAK_FADE_DURATION);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
remainingTimeAdjustmentBox
|
|
|
|
.ResizeWidthTo(remaining_time_container_max_size, BREAK_FADE_DURATION, Easing.OutQuint)
|
|
|
|
.Delay(b.Duration - BREAK_FADE_DURATION)
|
|
|
|
.ResizeWidthTo(0);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
remainingTimeBox.ResizeWidthTo(remainingTimeForCurrentPeriod);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
remainingTimeCounter.CountTo(b.Duration).CountTo(0, b.Duration);
|
|
|
|
|
|
|
|
using (BeginDelayedSequence(b.Duration - BREAK_FADE_DURATION))
|
|
|
|
{
|
|
|
|
fadeContainer.FadeOut(BREAK_FADE_DURATION);
|
|
|
|
breakArrows.Hide(BREAK_FADE_DURATION);
|
2017-09-21 03:33:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|