1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 04:27:34 +08:00
osu-lazer/osu.Game/Screens/Play/BreakOverlay.cs

205 lines
6.9 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
using System.Collections.Generic;
using osu.Framework.Allocation;
2019-07-25 16:07:53 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.Break;
namespace osu.Game.Screens.Play
{
public class BreakOverlay : Container
{
/// <summary>
/// The duration of the break overlay fading.
/// </summary>
public const double BREAK_FADE_DURATION = BreakPeriod.MIN_BREAK_DURATION / 2;
2018-04-13 17:19:50 +08:00
private const float remaining_time_container_max_size = 0.3f;
private const int vertical_margin = 25;
private readonly Container fadeContainer;
private IReadOnlyList<BreakPeriod> breaks;
public IReadOnlyList<BreakPeriod> Breaks
2018-04-13 17:19:50 +08:00
{
get => breaks;
set
{
breaks = value;
// reset index in case the new breaks list is smaller than last one
2019-07-28 14:16:19 +08:00
isBreakTime.Value = false;
2019-07-30 18:29:41 +08:00
CurrentBreakIndex = 0;
if (IsLoaded)
initializeBreaks();
2018-04-13 17:19:50 +08:00
}
}
public override bool RemoveCompletedTransforms => false;
2019-07-25 16:07:53 +08:00
/// <summary>
2019-07-25 16:27:32 +08:00
/// Whether the gameplay is currently in a break.
2019-07-25 16:07:53 +08:00
/// </summary>
2019-07-25 16:26:38 +08:00
public IBindable<bool> IsBreakTime => isBreakTime;
2019-07-30 18:29:41 +08:00
protected int CurrentBreakIndex;
2019-07-25 16:26:38 +08:00
private readonly BindableBool isBreakTime = new BindableBool();
2019-07-25 16:07:53 +08:00
2018-04-13 17:19:50 +08:00
private readonly Container remainingTimeAdjustmentBox;
private readonly Container remainingTimeBox;
private readonly RemainingTimeCounter remainingTimeCounter;
private readonly BreakInfo info;
private readonly BreakArrows breakArrows;
public BreakOverlay(bool letterboxing, ScoreProcessor scoreProcessor = null)
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both;
Child = fadeContainer = new Container
{
Alpha = 0,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new LetterboxOverlay
{
Alpha = letterboxing ? 1 : 0,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
remainingTimeAdjustmentBox = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Width = 0,
Child = remainingTimeBox = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
Height = 8,
CornerRadius = 4,
Masking = true,
Child = new Box { RelativeSizeAxes = Axes.Both }
}
},
remainingTimeCounter = new RemainingTimeCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.BottomCentre,
Margin = new MarginPadding { Bottom = vertical_margin },
},
info = new BreakInfo
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Margin = new MarginPadding { Top = vertical_margin },
},
breakArrows = new BreakArrows
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
}
};
if (scoreProcessor != null) bindProcessor(scoreProcessor);
}
[BackgroundDependencyLoader(true)]
private void load(GameplayClock clock)
{
if (clock != null) Clock = clock;
2018-04-13 17:19:50 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
initializeBreaks();
}
2019-07-25 16:07:53 +08:00
protected override void Update()
{
base.Update();
2019-07-25 16:27:01 +08:00
updateBreakTimeBindable();
}
private void updateBreakTimeBindable()
{
if (breaks == null || breaks.Count == 0)
2019-07-25 16:53:32 +08:00
return;
var time = Clock.CurrentTime;
2019-07-30 18:29:41 +08:00
if (time > breaks[CurrentBreakIndex].EndTime)
{
2019-07-30 18:29:41 +08:00
while (time > breaks[CurrentBreakIndex].EndTime && CurrentBreakIndex < breaks.Count - 1)
CurrentBreakIndex++;
}
2019-07-27 20:52:30 +08:00
else
{
2019-07-30 18:29:41 +08:00
while (time < breaks[CurrentBreakIndex].StartTime && CurrentBreakIndex > 0)
CurrentBreakIndex--;
}
2019-07-25 16:27:01 +08:00
2019-07-30 18:29:41 +08:00
var currentBreak = breaks[CurrentBreakIndex];
2019-08-07 21:28:16 +08:00
isBreakTime.Value = currentBreak.HasEffect && currentBreak.Contains(time);
2019-07-25 16:07:53 +08:00
}
2018-04-13 17:19:50 +08:00
private void initializeBreaks()
{
FinishTransforms(true);
Scheduler.CancelDelayedTasks();
if (breaks == null) return; //we need breaks.
foreach (var b in breaks)
{
if (!b.HasEffect)
continue;
using (BeginAbsoluteSequence(b.StartTime, true))
{
fadeContainer.FadeIn(BREAK_FADE_DURATION);
breakArrows.Show(BREAK_FADE_DURATION);
2018-04-13 17:19:50 +08:00
remainingTimeAdjustmentBox
.ResizeWidthTo(remaining_time_container_max_size, BREAK_FADE_DURATION, Easing.OutQuint)
.Delay(b.Duration - BREAK_FADE_DURATION)
2018-04-13 17:19:50 +08:00
.ResizeWidthTo(0);
remainingTimeBox
.ResizeWidthTo(0, b.Duration - BREAK_FADE_DURATION)
2018-04-13 17:19:50 +08:00
.Then()
.ResizeWidthTo(1);
remainingTimeCounter.CountTo(b.Duration).CountTo(0, b.Duration);
using (BeginDelayedSequence(b.Duration - BREAK_FADE_DURATION, true))
2018-04-13 17:19:50 +08:00
{
fadeContainer.FadeOut(BREAK_FADE_DURATION);
breakArrows.Hide(BREAK_FADE_DURATION);
2018-04-13 17:19:50 +08:00
}
}
}
}
private void bindProcessor(ScoreProcessor processor)
{
info.AccuracyDisplay.Current.BindTo(processor.Accuracy);
info.GradeDisplay.Current.BindTo(processor.Rank);
}
}
}