1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 06:42:54 +08:00
osu-lazer/osu.Game/Screens/Play/BreaksOverlay/BreakOverlay.cs

158 lines
5.2 KiB
C#
Raw Normal View History

2017-09-21 03:33:07 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps.Timing;
2017-09-23 21:42:18 +08:00
using osu.Game.Rulesets.Scoring;
2017-09-21 03:33:07 +08:00
using System.Collections.Generic;
using osu.Framework.Graphics.UserInterface;
2017-09-21 03:33:07 +08:00
namespace osu.Game.Screens.Play.BreaksOverlay
{
public class BreakOverlay : Container
{
private const double 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;
2017-09-21 06:44:30 +08:00
private const int vertical_margin = 25;
2017-09-21 03:33:07 +08:00
private List<BreakPeriod> breaks;
public List<BreakPeriod> Breaks
{
set
{
breaks = value;
initializeBreaks();
}
get
{
return breaks;
}
}
public override bool RemoveCompletedTransforms => false;
2017-09-21 03:33:07 +08:00
private readonly bool letterboxing;
private readonly LetterboxOverlay letterboxOverlay;
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;
private readonly InfoContainer info;
2017-09-22 06:16:05 +08:00
private readonly ArrowsOverlay arrowsOverlay;
2017-09-21 06:44:30 +08:00
2017-09-21 03:33:07 +08:00
public BreakOverlay(bool letterboxing)
{
this.letterboxing = letterboxing;
RelativeSizeAxes = Axes.Both;
Children = new Drawable[]
{
2017-09-21 06:44:30 +08:00
letterboxOverlay = new LetterboxOverlay
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
2017-10-06 09:49:16 +08:00
remainingTimeAdjustmentBox = new Container
2017-09-21 03:33:07 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2017-10-06 09:49:16 +08:00
AutoSizeAxes = Axes.Y,
2017-09-21 06:44:30 +08:00
RelativeSizeAxes = Axes.X,
2017-10-06 09:49:16 +08:00
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 }
}
2017-09-21 03:33:07 +08:00
},
remainingTimeCounter = new RemainingTimeCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.BottomCentre,
2017-09-21 06:44:30 +08:00
Margin = new MarginPadding { Bottom = vertical_margin },
2017-09-21 03:33:07 +08:00
},
info = new InfoContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
2017-09-21 06:44:30 +08:00
Margin = new MarginPadding { Top = vertical_margin },
},
2017-09-22 06:16:05 +08:00
arrowsOverlay = new ArrowsOverlay
2017-09-21 06:44:30 +08:00
{
2017-09-22 06:16:05 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2017-09-21 03:33:07 +08:00
}
};
}
private void initializeBreaks()
2017-09-21 03:33:07 +08:00
{
FinishTransforms(true);
2017-10-02 13:51:00 +08:00
Scheduler.CancelDelayedTasks();
if (breaks == null)
2017-09-22 03:54:46 +08:00
return;
foreach (var b in breaks)
2017-09-21 03:33:07 +08:00
{
2017-09-22 03:54:46 +08:00
if (!b.HasEffect)
continue;
using (BeginAbsoluteSequence(b.StartTime, true))
{
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 (BeginAbsoluteSequence(b.StartTime))
2017-09-21 03:33:07 +08:00
{
2017-11-10 18:32:09 +08:00
Schedule(showBreak);
using (BeginDelayedSequence(b.Duration - fade_duration))
Schedule(hideBreak);
2017-09-21 03:33:07 +08:00
}
}
}
2017-11-10 18:32:09 +08:00
private void showBreak()
2017-09-21 03:33:07 +08:00
{
if (letterboxing)
2017-10-05 09:38:13 +08:00
letterboxOverlay.Show();
2017-09-21 03:33:07 +08:00
2017-10-05 09:38:13 +08:00
remainingTimeCounter.Show();
info.Show();
arrowsOverlay.Show();
2017-09-21 03:33:07 +08:00
}
private void hideBreak()
2017-09-21 03:33:07 +08:00
{
if (letterboxing)
2017-10-05 09:38:13 +08:00
letterboxOverlay.Hide();
2017-09-21 03:33:07 +08:00
2017-10-05 09:38:13 +08:00
remainingTimeCounter.Hide();
info.Hide();
arrowsOverlay.Hide();
2017-09-21 03:33:07 +08:00
}
2017-09-23 21:42:18 +08:00
public void BindProcessor(ScoreProcessor processor)
{
info.AccuracyDisplay.Current.BindTo(processor.Accuracy);
info.GradeDisplay.Current.BindTo(processor.Rank);
2017-09-23 21:42:18 +08:00
}
2017-09-21 03:33:07 +08:00
}
}