osu/osu.Game/Screens/Play/BreakOverlay.cs

156 lines
5.4 KiB
C#
Raw Normal View History

2018-01-05 11:21:19 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-09-20 19:33:07 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
2017-09-20 19:33:07 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
2017-09-20 19:33:07 +00:00
using osu.Game.Beatmaps.Timing;
2017-09-23 13:42:18 +00:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.Break;
2017-09-20 19:33:07 +00:00
namespace osu.Game.Screens.Play
2017-09-20 19:33:07 +00:00
{
public class BreakOverlay : Container
{
private const double fade_duration = BreakPeriod.MIN_BREAK_DURATION / 2;
2017-09-22 17:43:51 +00:00
private const float remaining_time_container_max_size = 0.3f;
2017-09-20 22:44:30 +00:00
private const int vertical_margin = 25;
2017-09-20 19:33:07 +00:00
private List<BreakPeriod> breaks;
private readonly Container fadeContainer;
public List<BreakPeriod> Breaks
{
get => breaks;
set
{
breaks = value;
initializeBreaks();
}
}
public override bool RemoveCompletedTransforms => false;
2017-10-06 01:49:16 +00:00
private readonly Container remainingTimeAdjustmentBox;
2017-09-20 19:33:07 +00:00
private readonly Container remainingTimeBox;
private readonly RemainingTimeCounter remainingTimeCounter;
private readonly BreakInfo info;
private readonly BreakArrows breakArrows;
2017-09-20 22:44:30 +00:00
2018-01-24 08:48:42 +00:00
public BreakOverlay(bool letterboxing, ScoreProcessor scoreProcessor)
: this(letterboxing)
{
bindProcessor(scoreProcessor);
}
2017-09-20 19:33:07 +00:00
public BreakOverlay(bool letterboxing)
{
RelativeSizeAxes = Axes.Both;
Child = fadeContainer = new Container
2017-09-20 19:33:07 +00:00
{
Alpha = 0,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2017-09-20 19:33:07 +00:00
{
new LetterboxOverlay
2017-10-06 01:49:16 +00:00
{
Alpha = letterboxing ? 1 : 0,
2017-10-06 01:49:16 +00:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
remainingTimeAdjustmentBox = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Y,
2017-10-06 01:49:16 +00:00
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,
2017-10-06 01:49:16 +00:00
}
2017-09-20 19:33:07 +00:00
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
initializeBreaks();
}
private void initializeBreaks()
2017-09-20 19:33:07 +00:00
{
if (!IsLoaded) return; // we need a clock.
FinishTransforms(true);
2017-10-02 05:51:00 +00:00
Scheduler.CancelDelayedTasks();
if (breaks == null) return; //we need breaks.
2017-09-21 19:54:46 +00:00
foreach (var b in breaks)
2017-09-20 19:33:07 +00:00
{
2017-09-21 19:54:46 +00:00
if (!b.HasEffect)
continue;
using (BeginAbsoluteSequence(b.StartTime, true))
{
fadeContainer.FadeIn(fade_duration);
breakArrows.Show(fade_duration);
remainingTimeAdjustmentBox
.ResizeWidthTo(remaining_time_container_max_size, fade_duration, Easing.OutQuint)
.Delay(b.Duration - fade_duration)
.ResizeWidthTo(0);
remainingTimeBox
.ResizeWidthTo(0, b.Duration - fade_duration)
.Then()
.ResizeWidthTo(1);
remainingTimeCounter.CountTo(b.Duration).CountTo(0, b.Duration);
using (BeginDelayedSequence(b.Duration - fade_duration, true))
{
fadeContainer.FadeOut(fade_duration);
breakArrows.Hide(fade_duration);
}
2017-09-20 19:33:07 +00:00
}
}
}
private void bindProcessor(ScoreProcessor processor)
2017-09-23 13:42:18 +00:00
{
info.AccuracyDisplay.Current.BindTo(processor.Accuracy);
info.GradeDisplay.Current.BindTo(processor.Rank);
2017-09-23 13:42:18 +00:00
}
2017-09-20 19:33:07 +00:00
}
}