Merge remote-tracking branch 'upstream/master' into collapse-graph-option

This commit is contained in:
Dean Herbert
2020-01-24 13:55:42 +09:00
1449 changed files with 49544 additions and 17465 deletions

View File

@ -1,8 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// 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.
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
@ -15,34 +16,58 @@ namespace osu.Game.Screens.Play
{
public class BreakOverlay : Container
{
private const double fade_duration = BreakPeriod.MIN_BREAK_DURATION / 2;
private readonly ScoreProcessor scoreProcessor;
/// <summary>
/// The duration of the break overlay fading.
/// </summary>
public const double BREAK_FADE_DURATION = BreakPeriod.MIN_BREAK_DURATION / 2;
private const float remaining_time_container_max_size = 0.3f;
private const int vertical_margin = 25;
private List<BreakPeriod> breaks;
private readonly Container fadeContainer;
public List<BreakPeriod> Breaks
private IReadOnlyList<BreakPeriod> breaks;
public IReadOnlyList<BreakPeriod> Breaks
{
get => breaks;
set
{
breaks = value;
initializeBreaks();
// reset index in case the new breaks list is smaller than last one
isBreakTime.Value = false;
CurrentBreakIndex = 0;
if (IsLoaded)
initializeBreaks();
}
}
public override bool RemoveCompletedTransforms => false;
/// <summary>
/// Whether the gameplay is currently in a break.
/// </summary>
public IBindable<bool> IsBreakTime => isBreakTime;
protected int CurrentBreakIndex;
private readonly BindableBool isBreakTime = new BindableBool();
private readonly Container remainingTimeAdjustmentBox;
private readonly Container remainingTimeBox;
private readonly RemainingTimeCounter remainingTimeCounter;
private readonly BreakInfo info;
private readonly BreakArrows breakArrows;
private readonly double gameplayStartTime;
public BreakOverlay(bool letterboxing, ScoreProcessor scoreProcessor = null)
public BreakOverlay(bool letterboxing, double gameplayStartTime = 0, ScoreProcessor scoreProcessor = null)
{
this.gameplayStartTime = gameplayStartTime;
this.scoreProcessor = scoreProcessor;
RelativeSizeAxes = Axes.Both;
Child = fadeContainer = new Container
{
@ -109,10 +134,44 @@ namespace osu.Game.Screens.Play
initializeBreaks();
}
protected override void Update()
{
base.Update();
updateBreakTimeBindable();
}
private void updateBreakTimeBindable() =>
isBreakTime.Value = getCurrentBreak()?.HasEffect == true
|| Clock.CurrentTime < gameplayStartTime
|| scoreProcessor?.HasCompleted == true;
private BreakPeriod getCurrentBreak()
{
if (breaks?.Count > 0)
{
var time = Clock.CurrentTime;
if (time > breaks[CurrentBreakIndex].EndTime)
{
while (time > breaks[CurrentBreakIndex].EndTime && CurrentBreakIndex < breaks.Count - 1)
CurrentBreakIndex++;
}
else
{
while (time < breaks[CurrentBreakIndex].StartTime && CurrentBreakIndex > 0)
CurrentBreakIndex--;
}
var closest = breaks[CurrentBreakIndex];
return closest.Contains(time) ? closest : null;
}
return null;
}
private void initializeBreaks()
{
if (!IsLoaded) return; // we need a clock.
FinishTransforms(true);
Scheduler.CancelDelayedTasks();
@ -125,25 +184,25 @@ namespace osu.Game.Screens.Play
using (BeginAbsoluteSequence(b.StartTime, true))
{
fadeContainer.FadeIn(fade_duration);
breakArrows.Show(fade_duration);
fadeContainer.FadeIn(BREAK_FADE_DURATION);
breakArrows.Show(BREAK_FADE_DURATION);
remainingTimeAdjustmentBox
.ResizeWidthTo(remaining_time_container_max_size, fade_duration, Easing.OutQuint)
.Delay(b.Duration - fade_duration)
.ResizeWidthTo(remaining_time_container_max_size, BREAK_FADE_DURATION, Easing.OutQuint)
.Delay(b.Duration - BREAK_FADE_DURATION)
.ResizeWidthTo(0);
remainingTimeBox
.ResizeWidthTo(0, b.Duration - fade_duration)
.ResizeWidthTo(0, b.Duration - BREAK_FADE_DURATION)
.Then()
.ResizeWidthTo(1);
remainingTimeCounter.CountTo(b.Duration).CountTo(0, b.Duration);
using (BeginDelayedSequence(b.Duration - fade_duration, true))
using (BeginDelayedSequence(b.Duration - BREAK_FADE_DURATION, true))
{
fadeContainer.FadeOut(fade_duration);
breakArrows.Hide(fade_duration);
fadeContainer.FadeOut(BREAK_FADE_DURATION);
breakArrows.Hide(BREAK_FADE_DURATION);
}
}
}

View File

@ -0,0 +1,55 @@
// 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.
using osu.Framework.Allocation;
using osu.Game.Graphics.Containers;
using osu.Game.Storyboards;
using osu.Game.Storyboards.Drawables;
namespace osu.Game.Screens.Play
{
/// <summary>
/// A container that handles <see cref="Storyboard"/> loading, as well as applies user-specified visual settings to it.
/// </summary>
public class DimmableStoryboard : UserDimContainer
{
private readonly Storyboard storyboard;
private DrawableStoryboard drawableStoryboard;
public DimmableStoryboard(Storyboard storyboard)
{
this.storyboard = storyboard;
}
[BackgroundDependencyLoader]
private void load()
{
initializeStoryboard(false);
}
protected override void LoadComplete()
{
ShowStoryboard.BindValueChanged(_ => initializeStoryboard(true), true);
base.LoadComplete();
}
protected override bool ShowDimContent => IgnoreUserSettings.Value || (ShowStoryboard.Value && DimLevel < 1);
private void initializeStoryboard(bool async)
{
if (drawableStoryboard != null)
return;
if (!ShowStoryboard.Value && !IgnoreUserSettings.Value)
return;
drawableStoryboard = storyboard.CreateDrawable();
drawableStoryboard.Masking = true;
if (async)
LoadComponentAsync(drawableStoryboard, Add);
else
Add(drawableStoryboard);
}
}
}

View File

@ -0,0 +1,88 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Video;
using osu.Game.Graphics.Containers;
using osuTK.Graphics;
namespace osu.Game.Screens.Play
{
public class DimmableVideo : UserDimContainer
{
private readonly VideoSprite video;
private DrawableVideo drawableVideo;
public DimmableVideo(VideoSprite video)
{
this.video = video;
}
[BackgroundDependencyLoader]
private void load()
{
initializeVideo(false);
}
protected override void LoadComplete()
{
ShowVideo.BindValueChanged(_ => initializeVideo(true), true);
base.LoadComplete();
}
protected override bool ShowDimContent => IgnoreUserSettings.Value || (ShowVideo.Value && DimLevel < 1);
private void initializeVideo(bool async)
{
if (video == null)
return;
if (drawableVideo != null)
return;
if (!ShowVideo.Value && !IgnoreUserSettings.Value)
return;
drawableVideo = new DrawableVideo(video);
if (async)
LoadComponentAsync(drawableVideo, Add);
else
Add(drawableVideo);
}
private class DrawableVideo : Container
{
public DrawableVideo(VideoSprite video)
{
RelativeSizeAxes = Axes.Both;
Masking = true;
video.RelativeSizeAxes = Axes.Both;
video.FillMode = FillMode.Fit;
video.Anchor = Anchor.Centre;
video.Origin = Anchor.Centre;
AddRangeInternal(new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
video,
});
}
[BackgroundDependencyLoader]
private void load(GameplayClock clock)
{
if (clock != null)
Clock = clock;
}
}
}
}

View File

@ -10,7 +10,7 @@ using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics;
using osu.Framework.MathUtils;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK;

View File

@ -34,7 +34,6 @@ namespace osu.Game.Screens.Play
public void ProcessFrame()
{
// we do not want to process the underlying clock.
// this is handled by PauseContainer.
}
public double ElapsedFrameTime => underlyingClock.ElapsedFrameTime;
@ -42,5 +41,7 @@ namespace osu.Game.Screens.Play
public double FramesPerSecond => underlyingClock.FramesPerSecond;
public FrameTimeInfo TimeInfo => underlyingClock.TimeInfo;
public IClock Source => underlyingClock;
}
}

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -27,9 +28,9 @@ namespace osu.Game.Screens.Play
private readonly IReadOnlyList<Mod> mods;
/// <summary>
/// The original source (usually a <see cref="WorkingBeatmap"/>'s track).
/// The <see cref="WorkingBeatmap"/>'s track.
/// </summary>
private readonly IAdjustableClock sourceClock;
private Track track;
public readonly BindableBool IsPaused = new BindableBool();
@ -40,7 +41,9 @@ namespace osu.Game.Screens.Play
private readonly double gameplayStartTime;
public readonly Bindable<double> UserPlaybackRate = new BindableDouble(1)
private readonly double firstHitObjectTime;
public readonly BindableNumber<double> UserPlaybackRate = new BindableDouble(1)
{
Default = 1,
MinValue = 0.5,
@ -65,11 +68,11 @@ namespace osu.Game.Screens.Play
this.beatmap = beatmap;
this.mods = mods;
this.gameplayStartTime = gameplayStartTime;
firstHitObjectTime = beatmap.Beatmap.HitObjects.First().StartTime;
RelativeSizeAxes = Axes.Both;
sourceClock = (IAdjustableClock)beatmap.Track ?? new StopwatchClock();
(sourceClock as IAdjustableAudioComponent)?.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
track = beatmap.Track;
adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
@ -88,6 +91,11 @@ namespace osu.Game.Screens.Play
private double totalOffset => userOffsetClock.Offset + platformOffsetClock.Offset;
/// <summary>
/// Duration before gameplay start time required before skip button displays.
/// </summary>
public const double MINIMUM_SKIP_TIME = 1000;
private readonly BindableDouble pauseFreqAdjust = new BindableDouble(1);
[BackgroundDependencyLoader]
@ -96,20 +104,32 @@ namespace osu.Game.Screens.Play
userAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset);
userAudioOffset.BindValueChanged(offset => userOffsetClock.Offset = offset.NewValue, true);
UserPlaybackRate.ValueChanged += _ => updateRate();
// sane default provided by ruleset.
double startTime = Math.Min(0, gameplayStartTime);
Seek(Math.Min(-beatmap.BeatmapInfo.AudioLeadIn, gameplayStartTime));
// if a storyboard is present, it may dictate the appropriate start time by having events in negative time space.
// this is commonly used to display an intro before the audio track start.
startTime = Math.Min(startTime, beatmap.Storyboard.FirstEventTime);
// some beatmaps specify a current lead-in time which should be used instead of the ruleset-provided value when available.
// this is not available as an option in the live editor but can still be applied via .osu editing.
if (beatmap.BeatmapInfo.AudioLeadIn > 0)
startTime = Math.Min(startTime, firstHitObjectTime - beatmap.BeatmapInfo.AudioLeadIn);
Seek(startTime);
adjustableClock.ProcessFrame();
}
public void Restart()
{
Task.Run(() =>
{
sourceClock.Reset();
track.Reset();
Schedule(() =>
{
adjustableClock.ChangeSource(sourceClock);
adjustableClock.ChangeSource(track);
updateRate();
if (!IsPaused.Value)
@ -129,6 +149,23 @@ namespace osu.Game.Screens.Play
this.TransformBindableTo(pauseFreqAdjust, 1, 200, Easing.In);
}
/// <summary>
/// Skip forward to the next valid skip point.
/// </summary>
public void Skip()
{
if (GameplayClock.CurrentTime > gameplayStartTime - MINIMUM_SKIP_TIME)
return;
double skipTarget = gameplayStartTime - MINIMUM_SKIP_TIME;
if (GameplayClock.CurrentTime < 0 && skipTarget > 6000)
// double skip exception for storyboards with very long intros
skipTarget = 0;
Seek(skipTarget);
}
/// <summary>
/// Seek to a specific time in gameplay.
/// <remarks>
@ -153,10 +190,18 @@ namespace osu.Game.Screens.Play
IsPaused.Value = true;
}
public void ResetLocalAdjustments()
/// <summary>
/// Changes the backing clock to avoid using the originally provided beatmap's track.
/// </summary>
public void StopUsingBeatmapClock()
{
// In the case of replays, we may have changed the playback rate.
UserPlaybackRate.Value = 1;
if (track != beatmap.Track)
return;
removeSourceClockAdjustments();
track = new TrackVirtual(beatmap.Track.Length);
adjustableClock.ChangeSource(track);
}
protected override void Update()
@ -167,25 +212,37 @@ namespace osu.Game.Screens.Play
base.Update();
}
private bool speedAdjustmentsApplied;
private void updateRate()
{
if (sourceClock == null) return;
if (track == null) return;
sourceClock.ResetSpeedAdjustments();
speedAdjustmentsApplied = true;
track.ResetSpeedAdjustments();
if (sourceClock is IHasTempoAdjust tempo)
tempo.TempoAdjust = UserPlaybackRate.Value;
else
sourceClock.Rate = UserPlaybackRate.Value;
track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
track.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
foreach (var mod in mods.OfType<IApplicableToClock>())
mod.ApplyToClock(sourceClock);
foreach (var mod in mods.OfType<IApplicableToTrack>())
mod.ApplyToTrack(track);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
(sourceClock as IAdjustableAudioComponent)?.RemoveAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
removeSourceClockAdjustments();
track = null;
}
private void removeSourceClockAdjustments()
{
if (speedAdjustmentsApplied)
{
track.ResetSpeedAdjustments();
speedAdjustmentsApplied = false;
}
}
}
}

View File

@ -163,8 +163,6 @@ namespace osu.Game.Screens.Play
// Don't let mouse down events through the overlay or people can click circles while paused.
protected override bool OnMouseDown(MouseDownEvent e) => true;
protected override bool OnMouseUp(MouseUpEvent e) => true;
protected override bool OnMouseMove(MouseMoveEvent e) => true;
protected void AddButton(string text, Color4 colour, Action action)
@ -188,26 +186,22 @@ namespace osu.Game.Screens.Play
InternalButtons.Add(button);
}
private int _selectionIndex = -1;
private int selectionIndex = -1;
private int selectionIndex
private void setSelected(int value)
{
get => _selectionIndex;
set
{
if (_selectionIndex == value)
return;
if (selectionIndex == value)
return;
// Deselect the previously-selected button
if (_selectionIndex != -1)
InternalButtons[_selectionIndex].Selected.Value = false;
// Deselect the previously-selected button
if (selectionIndex != -1)
InternalButtons[selectionIndex].Selected.Value = false;
_selectionIndex = value;
selectionIndex = value;
// Select the newly-selected button
if (_selectionIndex != -1)
InternalButtons[_selectionIndex].Selected.Value = true;
}
// Select the newly-selected button
if (selectionIndex != -1)
InternalButtons[selectionIndex].Selected.Value = true;
}
protected override bool OnKeyDown(KeyDownEvent e)
@ -218,16 +212,16 @@ namespace osu.Game.Screens.Play
{
case Key.Up:
if (selectionIndex == -1 || selectionIndex == 0)
selectionIndex = InternalButtons.Count - 1;
setSelected(InternalButtons.Count - 1);
else
selectionIndex--;
setSelected(selectionIndex - 1);
return true;
case Key.Down:
if (selectionIndex == -1 || selectionIndex == InternalButtons.Count - 1)
selectionIndex = 0;
setSelected(0);
else
selectionIndex++;
setSelected(selectionIndex + 1);
return true;
}
}
@ -251,24 +245,16 @@ namespace osu.Game.Screens.Play
return false;
}
public bool OnReleased(GlobalAction action)
public void OnReleased(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
case GlobalAction.Select:
return true;
}
return false;
}
private void buttonSelectionChanged(DialogButton button, bool isSelected)
{
if (!isSelected)
selectionIndex = -1;
setSelected(-1);
else
selectionIndex = InternalButtons.IndexOf(button);
setSelected(InternalButtons.IndexOf(button));
}
private void updateRetryCount()
@ -304,6 +290,7 @@ namespace osu.Game.Screens.Play
private class Button : DialogButton
{
// required to ensure keyboard navigation always starts from an extremity (unless the cursor is moved)
protected override bool OnHover(HoverEvent e) => true;
protected override bool OnMouseMove(MouseMoveEvent e)
@ -312,5 +299,22 @@ namespace osu.Game.Screens.Play
return base.OnMouseMove(e);
}
}
[Resolved]
private GlobalActionContainer globalAction { get; set; }
protected override bool Handle(UIEvent e)
{
switch (e)
{
case ScrollEvent _:
if (ReceivePositionalInputAt(e.ScreenSpaceMousePosition))
return globalAction.TriggerEvent(e);
break;
}
return base.Handle(e);
}
}
}

View File

@ -114,7 +114,7 @@ namespace osu.Game.Screens.Play.HUD
/// <param name="amount"></param>
public void Increment(int amount = 1)
{
Current.Value = Current.Value + amount;
Current.Value += amount;
}
/// <summary>

View File

@ -26,7 +26,7 @@ namespace osu.Game.Screens.Play.HUD
public override void Increment(long amount)
{
Current.Value = Current.Value + amount;
Current.Value += amount;
}
}
}

View File

@ -0,0 +1,136 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD.HitErrorMeters;
namespace osu.Game.Screens.Play.HUD
{
public class HitErrorDisplay : Container<HitErrorMeter>
{
private const int fade_duration = 200;
private const int margin = 10;
private readonly Bindable<ScoreMeterType> type = new Bindable<ScoreMeterType>();
private readonly HitWindows hitWindows;
private readonly ScoreProcessor processor;
public HitErrorDisplay(ScoreProcessor processor, HitWindows hitWindows)
{
this.processor = processor;
this.hitWindows = hitWindows;
RelativeSizeAxes = Axes.Both;
if (processor != null)
processor.NewJudgement += onNewJudgement;
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
config.BindWith(OsuSetting.ScoreMeter, type);
}
protected override void LoadComplete()
{
base.LoadComplete();
type.BindValueChanged(typeChanged, true);
}
private void onNewJudgement(JudgementResult result)
{
if (result.HitObject.HitWindows.WindowFor(HitResult.Miss) == 0)
return;
foreach (var c in Children)
c.OnNewJudgement(result);
}
private void typeChanged(ValueChangedEvent<ScoreMeterType> type)
{
Children.ForEach(c => c.FadeOut(fade_duration, Easing.OutQuint));
if (hitWindows == null)
return;
switch (type.NewValue)
{
case ScoreMeterType.HitErrorBoth:
createBar(false);
createBar(true);
break;
case ScoreMeterType.HitErrorLeft:
createBar(false);
break;
case ScoreMeterType.HitErrorRight:
createBar(true);
break;
case ScoreMeterType.ColourBoth:
createColour(false);
createColour(true);
break;
case ScoreMeterType.ColourLeft:
createColour(false);
break;
case ScoreMeterType.ColourRight:
createColour(true);
break;
}
}
private void createBar(bool rightAligned)
{
var display = new BarHitErrorMeter(hitWindows, rightAligned)
{
Margin = new MarginPadding(margin),
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
Alpha = 0,
};
completeDisplayLoading(display);
}
private void createColour(bool rightAligned)
{
var display = new ColourHitErrorMeter(hitWindows)
{
Margin = new MarginPadding(margin),
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
Alpha = 0,
};
completeDisplayLoading(display);
}
private void completeDisplayLoading(HitErrorMeter display)
{
Add(display);
display.FadeInFromZero(fade_duration, Easing.OutQuint);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (processor != null)
processor.NewJudgement -= onNewJudgement;
}
}
}

View File

@ -0,0 +1,262 @@
// 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.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{
public class BarHitErrorMeter : HitErrorMeter
{
private readonly Anchor alignment;
private const int arrow_move_duration = 400;
private const int judgement_line_width = 6;
private const int bar_height = 200;
private const int bar_width = 2;
private const int spacing = 2;
private const float chevron_size = 8;
private SpriteIcon arrow;
private Container colourBarsEarly;
private Container colourBarsLate;
private Container judgementsContainer;
private double maxHitWindow;
public BarHitErrorMeter(HitWindows hitWindows, bool rightAligned = false)
: base(hitWindows)
{
alignment = rightAligned ? Anchor.x0 : Anchor.x2;
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.X,
Height = bar_height,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(spacing, 0),
Margin = new MarginPadding(2),
Children = new Drawable[]
{
judgementsContainer = new Container
{
Anchor = Anchor.y1 | alignment,
Origin = Anchor.y1 | alignment,
Width = judgement_line_width,
RelativeSizeAxes = Axes.Y,
},
colourBars = new Container
{
Width = bar_width,
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.y1 | alignment,
Origin = Anchor.y1 | alignment,
Children = new Drawable[]
{
colourBarsEarly = new Container
{
Anchor = Anchor.y1 | alignment,
Origin = alignment,
RelativeSizeAxes = Axes.Both,
Height = 0.5f,
Scale = new Vector2(1, -1),
},
colourBarsLate = new Container
{
Anchor = Anchor.y1 | alignment,
Origin = alignment,
RelativeSizeAxes = Axes.Both,
Height = 0.5f,
},
new SpriteIcon
{
Y = -10,
Size = new Vector2(10),
Icon = FontAwesome.Solid.ShippingFast,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
new SpriteIcon
{
Y = 10,
Size = new Vector2(10),
Icon = FontAwesome.Solid.Bicycle,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
}
}
},
new Container
{
Anchor = Anchor.y1 | alignment,
Origin = Anchor.y1 | alignment,
Width = chevron_size,
RelativeSizeAxes = Axes.Y,
Child = arrow = new SpriteIcon
{
Anchor = Anchor.TopCentre,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.Y,
Y = 0.5f,
Icon = alignment == Anchor.x2 ? FontAwesome.Solid.ChevronRight : FontAwesome.Solid.ChevronLeft,
Size = new Vector2(chevron_size),
}
},
}
};
createColourBars(colours);
}
protected override void LoadComplete()
{
base.LoadComplete();
colourBars.Height = 0;
colourBars.ResizeHeightTo(1, 800, Easing.OutQuint);
arrow.Alpha = 0;
arrow.Delay(200).FadeInFromZero(600);
}
private void createColourBars(OsuColour colours)
{
var windows = HitWindows.GetAllAvailableWindows().ToArray();
maxHitWindow = windows.First().length;
for (var i = 0; i < windows.Length; i++)
{
var (result, length) = windows[i];
colourBarsEarly.Add(createColourBar(result, (float)(length / maxHitWindow), i == 0));
colourBarsLate.Add(createColourBar(result, (float)(length / maxHitWindow), i == 0));
}
// a little nub to mark the centre point.
var centre = createColourBar(windows.Last().result, 0.01f);
centre.Anchor = centre.Origin = Anchor.y1 | (alignment == Anchor.x2 ? Anchor.x0 : Anchor.x2);
centre.Width = 2.5f;
colourBars.Add(centre);
Drawable createColourBar(HitResult result, float height, bool first = false)
{
var colour = GetColourForHitResult(result);
if (first)
{
// the first bar needs gradient rendering.
const float gradient_start = 0.8f;
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colour,
Height = height * gradient_start
},
new Box
{
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(colour, colour.Opacity(0)),
Y = gradient_start,
Height = height * (1 - gradient_start)
},
}
};
}
return new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colour,
Height = height
};
}
}
private double floatingAverage;
private Container colourBars;
public override void OnNewJudgement(JudgementResult judgement)
{
if (!judgement.IsHit)
return;
judgementsContainer.Add(new JudgementLine
{
Y = getRelativeJudgementPosition(judgement.TimeOffset),
Anchor = alignment == Anchor.x2 ? Anchor.x0 : Anchor.x2,
Origin = Anchor.y1 | (alignment == Anchor.x2 ? Anchor.x0 : Anchor.x2),
});
arrow.MoveToY(
getRelativeJudgementPosition(floatingAverage = floatingAverage * 0.9 + judgement.TimeOffset * 0.1)
, arrow_move_duration, Easing.Out);
}
private float getRelativeJudgementPosition(double value) => (float)((value / maxHitWindow) + 1) / 2;
private class JudgementLine : CompositeDrawable
{
private const int judgement_fade_duration = 10000;
public JudgementLine()
{
RelativeSizeAxes = Axes.X;
RelativePositionAxes = Axes.Y;
Height = 3;
InternalChild = new CircularContainer
{
Masking = true,
RelativeSizeAxes = Axes.Both,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Width = 0;
this.ResizeWidthTo(1, 200, Easing.OutElasticHalf);
this.FadeTo(0.8f, 150).Then().FadeOut(judgement_fade_duration, Easing.OutQuint).Expire();
}
}
}
}

View File

@ -0,0 +1,92 @@
// 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.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{
public class ColourHitErrorMeter : HitErrorMeter
{
private const int animation_duration = 200;
private readonly JudgementFlow judgementsFlow;
public ColourHitErrorMeter(HitWindows hitWindows)
: base(hitWindows)
{
AutoSizeAxes = Axes.Both;
InternalChild = judgementsFlow = new JudgementFlow();
}
public override void OnNewJudgement(JudgementResult judgement) => judgementsFlow.Push(GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset)));
private class JudgementFlow : FillFlowContainer<HitErrorCircle>
{
private const int max_available_judgements = 20;
private const int drawable_judgement_size = 8;
private const int spacing = 2;
public override IEnumerable<Drawable> FlowingChildren => base.FlowingChildren.Reverse();
public JudgementFlow()
{
AutoSizeAxes = Axes.X;
Height = max_available_judgements * (drawable_judgement_size + spacing) - spacing;
Spacing = new Vector2(0, spacing);
Direction = FillDirection.Vertical;
LayoutDuration = animation_duration;
LayoutEasing = Easing.OutQuint;
}
public void Push(Color4 colour)
{
Add(new HitErrorCircle(colour, drawable_judgement_size));
if (Children.Count > max_available_judgements)
Children.FirstOrDefault(c => !c.IsRemoved)?.Remove();
}
}
private class HitErrorCircle : Container
{
public bool IsRemoved { get; private set; }
private readonly Circle circle;
public HitErrorCircle(Color4 colour, int size)
{
Size = new Vector2(size);
Child = circle = new Circle
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Colour = colour
};
}
protected override void LoadComplete()
{
base.LoadComplete();
circle.FadeInFromZero(animation_duration, Easing.OutQuint);
circle.MoveToY(-DrawSize.Y);
circle.MoveToY(0, animation_duration, Easing.OutQuint);
}
public void Remove()
{
IsRemoved = true;
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
}
}
}
}

View File

@ -0,0 +1,51 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{
public abstract class HitErrorMeter : CompositeDrawable
{
protected readonly HitWindows HitWindows;
[Resolved]
private OsuColour colours { get; set; }
protected HitErrorMeter(HitWindows hitWindows)
{
HitWindows = hitWindows;
}
public abstract void OnNewJudgement(JudgementResult judgement);
protected Color4 GetColourForHitResult(HitResult result)
{
switch (result)
{
case HitResult.Miss:
return colours.Red;
case HitResult.Meh:
return colours.Yellow;
case HitResult.Ok:
return colours.Green;
case HitResult.Good:
return colours.GreenLight;
case HitResult.Great:
return colours.Blue;
default:
return colours.BlueLight;
}
}
}
}

View File

@ -12,7 +12,8 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.MathUtils;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
@ -45,7 +46,6 @@ namespace osu.Game.Screens.Play.HUD
{
text = new OsuSpriteText
{
Text = "hold for menu",
Font = OsuFont.GetFont(weight: FontWeight.Bold),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
@ -60,9 +60,23 @@ namespace osu.Game.Screens.Play.HUD
AutoSizeAxes = Axes.Both;
}
[Resolved]
private OsuConfigManager config { get; set; }
private Bindable<float> activationDelay;
protected override void LoadComplete()
{
activationDelay = config.GetBindable<float>(OsuSetting.UIHoldActivationDelay);
activationDelay.BindValueChanged(v =>
{
text.Text = v.NewValue > 0
? "hold for menu"
: "press for menu";
}, true);
text.FadeInFromZero(500, Easing.OutQuint).Delay(1500).FadeOut(500, Easing.OutQuint);
base.LoadComplete();
}
@ -86,9 +100,11 @@ namespace osu.Game.Screens.Play.HUD
if (text.Alpha > 0 || button.Progress.Value > 0 || button.IsHovered)
Alpha = 1;
else
{
Alpha = Interpolation.ValueAt(
MathHelper.Clamp(Clock.ElapsedFrameTime, 0, 200),
Alpha, MathHelper.Clamp(1 - positionalAdjust, 0.04f, 1), 0, 200, Easing.OutQuint);
Math.Clamp(Clock.ElapsedFrameTime, 0, 200),
Alpha, Math.Clamp(1 - positionalAdjust, 0.04f, 1), 0, 200, Easing.OutQuint);
}
}
private class Button : HoldToConfirmContainer, IKeyBindingHandler<GlobalAction>
@ -243,16 +259,14 @@ namespace osu.Game.Screens.Play.HUD
return false;
}
public bool OnReleased(GlobalAction action)
public void OnReleased(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
AbortConfirm();
return true;
break;
}
return false;
}
protected override bool OnMouseDown(MouseDownEvent e)
@ -262,11 +276,10 @@ namespace osu.Game.Screens.Play.HUD
return true;
}
protected override bool OnMouseUp(MouseUpEvent e)
protected override void OnMouseUp(MouseUpEvent e)
{
if (!e.HasAnyButtonPressed)
AbortConfirm();
return true;
}
}
}

View File

@ -45,8 +45,6 @@ namespace osu.Game.Screens.Play.HUD
VisualSettings = new VisualSettings { Expanded = false }
}
};
Show();
}
protected override void PopIn() => this.FadeIn(fade_duration);

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
@ -23,8 +24,8 @@ namespace osu.Game.Screens.Play
{
public class HUDOverlay : Container
{
private const int duration = 250;
private const Easing easing = Easing.OutQuint;
private const float fade_duration = 400;
private const Easing fade_easing = Easing.Out;
public readonly KeyCounterDisplay KeyCounter;
public readonly RollingCounter<int> ComboCounter;
@ -33,17 +34,26 @@ namespace osu.Game.Screens.Play
public readonly HealthDisplay HealthDisplay;
public readonly SongProgress Progress;
public readonly ModDisplay ModDisplay;
public readonly HitErrorDisplay HitErrorDisplay;
public readonly HoldForMenuButton HoldToQuit;
public readonly PlayerSettingsOverlay PlayerSettingsOverlay;
public Bindable<bool> ShowHealthbar = new Bindable<bool>(true);
private readonly ScoreProcessor scoreProcessor;
private readonly HealthProcessor healthProcessor;
private readonly DrawableRuleset drawableRuleset;
private readonly IReadOnlyList<Mod> mods;
private Bindable<bool> showHud;
/// <summary>
/// Whether the elements that can optionally be hidden should be visible.
/// </summary>
public Bindable<bool> ShowHud { get; } = new BindableBool();
private Bindable<bool> configShowHud;
private readonly Container visibilityContainer;
private readonly BindableBool replayLoaded = new BindableBool();
private static bool hasShownNotificationOnce;
@ -52,9 +62,12 @@ namespace osu.Game.Screens.Play
private readonly Container topScoreContainer;
public HUDOverlay(ScoreProcessor scoreProcessor, DrawableRuleset drawableRuleset, IReadOnlyList<Mod> mods)
private IEnumerable<Drawable> hideTargets => new Drawable[] { visibilityContainer, KeyCounter };
public HUDOverlay(ScoreProcessor scoreProcessor, HealthProcessor healthProcessor, DrawableRuleset drawableRuleset, IReadOnlyList<Mod> mods)
{
this.scoreProcessor = scoreProcessor;
this.healthProcessor = healthProcessor;
this.drawableRuleset = drawableRuleset;
this.mods = mods;
@ -67,13 +80,12 @@ namespace osu.Game.Screens.Play
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
HealthDisplay = CreateHealthDisplay(),
topScoreContainer = new Container
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
AutoSizeDuration = 200,
AutoSizeEasing = Easing.Out,
Children = new Drawable[]
{
AccuracyCounter = CreateAccuracyCounter(),
@ -81,18 +93,20 @@ namespace osu.Game.Screens.Play
ComboCounter = CreateComboCounter(),
},
},
HealthDisplay = CreateHealthDisplay(),
Progress = CreateProgress(),
ModDisplay = CreateModsContainer(),
HitErrorDisplay = CreateHitErrorDisplayOverlay(),
PlayerSettingsOverlay = CreatePlayerSettingsOverlay(),
}
},
PlayerSettingsOverlay = CreatePlayerSettingsOverlay(),
new FillFlowContainer
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Position = -new Vector2(5, TwoLayerButton.SIZE_RETRACTED.Y),
AutoSizeAxes = Axes.Both,
LayoutDuration = fade_duration / 2,
LayoutEasing = fade_easing,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
@ -106,33 +120,27 @@ namespace osu.Game.Screens.Play
[BackgroundDependencyLoader(true)]
private void load(OsuConfigManager config, NotificationOverlay notificationOverlay)
{
BindProcessor(scoreProcessor);
BindDrawableRuleset(drawableRuleset);
if (scoreProcessor != null)
BindScoreProcessor(scoreProcessor);
Progress.Objects = drawableRuleset.Objects;
Progress.RequestSeek = time => RequestSeek(time);
Progress.ReferenceClock = drawableRuleset.FrameStableClock;
if (healthProcessor != null)
BindHealthProcessor(healthProcessor);
if (drawableRuleset != null)
{
BindDrawableRuleset(drawableRuleset);
Progress.Objects = drawableRuleset.Objects;
Progress.AllowSeeking = drawableRuleset.HasReplayLoaded.Value;
Progress.RequestSeek = time => RequestSeek(time);
Progress.ReferenceClock = drawableRuleset.FrameStableClock;
}
ModDisplay.Current.Value = mods;
showHud = config.GetBindable<bool>(OsuSetting.ShowInterface);
showHud.BindValueChanged(visible => visibilityContainer.FadeTo(visible.NewValue ? 1 : 0, duration, easing), true);
configShowHud = config.GetBindable<bool>(OsuSetting.ShowInterface);
ShowHealthbar.BindValueChanged(healthBar =>
{
if (healthBar.NewValue)
{
HealthDisplay.FadeIn(duration, easing);
topScoreContainer.MoveToY(30, duration, easing);
}
else
{
HealthDisplay.FadeOut(duration, easing);
topScoreContainer.MoveToY(0, duration, easing);
}
}, true);
if (!showHud.Value && !hasShownNotificationOnce)
if (!configShowHud.Value && !hasShownNotificationOnce)
{
hasShownNotificationOnce = true;
@ -141,12 +149,39 @@ namespace osu.Game.Screens.Play
Text = @"The score overlay is currently disabled. You can toggle this by pressing Shift+Tab."
});
}
// start all elements hidden
hideTargets.ForEach(d => d.Hide());
}
public override void Hide() => throw new InvalidOperationException($"{nameof(HUDOverlay)} should not be hidden as it will remove the ability of a user to quit. Use {nameof(ShowHud)} instead.");
protected override void LoadComplete()
{
base.LoadComplete();
ShowHud.BindValueChanged(visible => hideTargets.ForEach(d => d.FadeTo(visible.NewValue ? 1 : 0, fade_duration, fade_easing)));
ShowHealthbar.BindValueChanged(healthBar =>
{
if (healthBar.NewValue)
{
HealthDisplay.FadeIn(fade_duration, fade_easing);
topScoreContainer.MoveToY(30, fade_duration, fade_easing);
}
else
{
HealthDisplay.FadeOut(fade_duration, fade_easing);
topScoreContainer.MoveToY(0, fade_duration, fade_easing);
}
}, true);
configShowHud.BindValueChanged(visible =>
{
if (!ShowHud.Disabled)
ShowHud.Value = visible.NewValue;
}, true);
replayLoaded.BindValueChanged(replayLoadedValueChanged, true);
}
@ -186,7 +221,7 @@ namespace osu.Game.Screens.Play
switch (e.Key)
{
case Key.Tab:
showHud.Value = !showHud.Value;
configShowHud.Value = !configShowHud.Value;
return true;
}
}
@ -228,7 +263,6 @@ namespace osu.Game.Screens.Play
protected virtual KeyCounterDisplay CreateKeyCounter() => new KeyCounterDisplay
{
FadeTime = 50,
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding(10),
@ -255,17 +289,23 @@ namespace osu.Game.Screens.Play
Margin = new MarginPadding { Top = 20, Right = 10 },
};
protected virtual HitErrorDisplay CreateHitErrorDisplayOverlay() => new HitErrorDisplay(scoreProcessor, drawableRuleset?.FirstAvailableHitWindows);
protected virtual PlayerSettingsOverlay CreatePlayerSettingsOverlay() => new PlayerSettingsOverlay();
protected virtual void BindProcessor(ScoreProcessor processor)
protected virtual void BindScoreProcessor(ScoreProcessor processor)
{
ScoreCounter?.Current.BindTo(processor.TotalScore);
AccuracyCounter?.Current.BindTo(processor.Accuracy);
ComboCounter?.Current.BindTo(processor.Combo);
HealthDisplay?.Current.BindTo(processor.Health);
if (HealthDisplay is StandardHealthDisplay shd)
processor.NewJudgement += shd.Flash;
}
protected virtual void BindHealthProcessor(HealthProcessor processor)
{
HealthDisplay?.Current.BindTo(processor.Health);
}
}
}

View File

@ -17,12 +17,11 @@ namespace osu.Game.Screens.Play
return true;
}
public bool OnReleased(GlobalAction action)
public void OnReleased(GlobalAction action)
{
if (action != GlobalAction.QuickExit) return false;
if (action != GlobalAction.QuickExit) return;
AbortConfirm();
return true;
}
}
}

View File

@ -17,12 +17,11 @@ namespace osu.Game.Screens.Play
return true;
}
public bool OnReleased(GlobalAction action)
public void OnReleased(GlobalAction action)
{
if (action != GlobalAction.QuickRetry) return false;
if (action != GlobalAction.QuickRetry) return;
AbortConfirm();
return true;
}
}
}

View File

@ -1,8 +1,6 @@
// 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.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -22,9 +20,6 @@ namespace osu.Game.Screens.Play
private Container textLayer;
private SpriteText countSpriteText;
private readonly List<KeyCounterState> states = new List<KeyCounterState>();
private KeyCounterState currentState;
public bool IsCounting { get; set; } = true;
private int countPresses;
@ -52,20 +47,30 @@ namespace osu.Game.Screens.Play
{
isLit = value;
updateGlowSprite(value);
if (value && IsCounting)
{
CountPresses++;
saveState();
}
}
}
}
public void Increment()
{
if (!IsCounting)
return;
CountPresses++;
}
public void Decrement()
{
if (!IsCounting)
return;
CountPresses--;
}
//further: change default values here and in KeyCounterCollection if needed, instead of passing them in every constructor
public Color4 KeyDownTextColor { get; set; } = Color4.DarkGray;
public Color4 KeyUpTextColor { get; set; } = Color4.White;
public int FadeTime { get; set; }
public double FadeTime { get; set; }
protected KeyCounter(string name)
{
@ -73,11 +78,8 @@ namespace osu.Game.Screens.Play
}
[BackgroundDependencyLoader(true)]
private void load(TextureStore textures, GameplayClock clock)
private void load(TextureStore textures)
{
if (clock != null)
Clock = clock;
Children = new Drawable[]
{
buttonSprite = new Sprite
@ -132,42 +134,16 @@ namespace osu.Game.Screens.Play
{
if (show)
{
glowSprite.FadeIn(FadeTime);
textLayer.FadeColour(KeyDownTextColor, FadeTime);
double remainingFadeTime = FadeTime * (1 - glowSprite.Alpha);
glowSprite.FadeIn(remainingFadeTime, Easing.OutQuint);
textLayer.FadeColour(KeyDownTextColor, remainingFadeTime, Easing.OutQuint);
}
else
{
glowSprite.FadeOut(FadeTime);
textLayer.FadeColour(KeyUpTextColor, FadeTime);
double remainingFadeTime = 8 * FadeTime * glowSprite.Alpha;
glowSprite.FadeOut(remainingFadeTime, Easing.OutQuint);
textLayer.FadeColour(KeyUpTextColor, remainingFadeTime, Easing.OutQuint);
}
}
public void ResetCount()
{
CountPresses = 0;
states.Clear();
}
protected override void Update()
{
base.Update();
if (currentState?.Time > Clock.CurrentTime)
restoreStateTo(Clock.CurrentTime);
}
private void saveState()
{
if (currentState == null || currentState.Time < Clock.CurrentTime)
states.Add(currentState = new KeyCounterState(Clock.CurrentTime, CountPresses));
}
private void restoreStateTo(double time)
{
states.RemoveAll(state => state.Time > time);
currentState = states.LastOrDefault();
CountPresses = currentState?.Count ?? 0;
}
}
}

View File

@ -1,11 +1,11 @@
// 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.
using osu.Framework.Input.Bindings;
using System.Collections.Generic;
namespace osu.Game.Screens.Play
{
public class KeyCounterAction<T> : KeyCounter, IKeyBindingHandler<T>
public class KeyCounterAction<T> : KeyCounter
where T : struct
{
public T Action { get; }
@ -16,16 +16,25 @@ namespace osu.Game.Screens.Play
Action = action;
}
public bool OnPressed(T action)
public bool OnPressed(T action, bool forwards)
{
if (action.Equals(Action)) IsLit = true;
if (!EqualityComparer<T>.Default.Equals(action, Action))
return false;
IsLit = true;
if (forwards)
Increment();
return false;
}
public bool OnReleased(T action)
public void OnReleased(T action, bool forwards)
{
if (action.Equals(Action)) IsLit = false;
return false;
if (!EqualityComparer<T>.Default.Equals(action, Action))
return;
IsLit = false;
if (!forwards)
Decrement();
}
}
}

View File

@ -17,6 +17,7 @@ namespace osu.Game.Screens.Play
public class KeyCounterDisplay : FillFlowContainer<KeyCounter>
{
private const int duration = 100;
private const double key_fade_time = 80;
public readonly Bindable<bool> Visible = new Bindable<bool>(true);
private readonly Bindable<bool> configVisibility = new Bindable<bool>();
@ -33,21 +34,20 @@ namespace osu.Game.Screens.Play
base.Add(key);
key.IsCounting = IsCounting;
key.FadeTime = FadeTime;
key.FadeTime = key_fade_time;
key.KeyDownTextColor = KeyDownTextColor;
key.KeyUpTextColor = KeyUpTextColor;
}
public void ResetCount()
{
foreach (var counter in Children)
counter.ResetCount();
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
config.BindWith(OsuSetting.KeyOverlay, configVisibility);
}
protected override void LoadComplete()
{
base.LoadComplete();
Visible.BindValueChanged(_ => updateVisibility());
configVisibility.BindValueChanged(_ => updateVisibility(), true);
@ -68,22 +68,6 @@ namespace osu.Game.Screens.Play
}
}
private int fadeTime;
public int FadeTime
{
get => fadeTime;
set
{
if (value != fadeTime)
{
fadeTime = value;
foreach (var child in Children)
child.FadeTime = value;
}
}
}
private Color4 keyDownTextColor = Color4.DarkGray;
public Color4 KeyDownTextColor
@ -123,11 +107,6 @@ namespace osu.Game.Screens.Play
private Receptor receptor;
public Receptor GetReceptor()
{
return receptor ?? (receptor = new Receptor(this));
}
public void SetReceptor(Receptor receptor)
{
if (this.receptor != null)

View File

@ -18,14 +18,19 @@ namespace osu.Game.Screens.Play
protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.Key == Key) IsLit = true;
if (e.Key == Key)
{
IsLit = true;
Increment();
}
return base.OnKeyDown(e);
}
protected override bool OnKeyUp(KeyUpEvent e)
protected override void OnKeyUp(KeyUpEvent e)
{
if (e.Key == Key) IsLit = false;
return base.OnKeyUp(e);
base.OnKeyUp(e);
}
}
}

View File

@ -36,14 +36,19 @@ namespace osu.Game.Screens.Play
protected override bool OnMouseDown(MouseDownEvent e)
{
if (e.Button == Button) IsLit = true;
if (e.Button == Button)
{
IsLit = true;
Increment();
}
return base.OnMouseDown(e);
}
protected override bool OnMouseUp(MouseUpEvent e)
protected override void OnMouseUp(MouseUpEvent e)
{
if (e.Button == Button) IsLit = false;
return base.OnMouseUp(e);
base.OnMouseUp(e);
}
}
}

View File

@ -26,11 +26,11 @@ using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking;
using osu.Game.Skinning;
using osu.Game.Storyboards.Drawables;
using osu.Game.Users;
namespace osu.Game.Screens.Play
{
[Cached]
public class Player : ScreenWithBeatmapBackground
{
public override bool AllowBackButton => false; // handled by HoldForMenuButton
@ -61,13 +61,20 @@ namespace osu.Game.Screens.Play
[Resolved]
private ScoreManager scoreManager { get; set; }
private RulesetInfo ruleset;
private RulesetInfo rulesetInfo;
private Ruleset ruleset;
private IAPIProvider api;
private SampleChannel sampleRestart;
public BreakOverlay BreakOverlay;
protected ScoreProcessor ScoreProcessor { get; private set; }
protected HealthProcessor HealthProcessor { get; private set; }
protected DrawableRuleset DrawableRuleset { get; private set; }
protected HUDOverlay HUDOverlay { get; private set; }
@ -76,10 +83,19 @@ namespace osu.Game.Screens.Play
protected GameplayClockContainer GameplayClockContainer { get; private set; }
public DimmableStoryboard DimmableStoryboard { get; private set; }
public DimmableVideo DimmableVideo { get; private set; }
[Cached]
[Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))]
protected new readonly Bindable<IReadOnlyList<Mod>> Mods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
/// <summary>
/// Whether failing should be allowed.
/// By default, this checks whether all selected mods allow failing.
/// </summary>
protected virtual bool AllowFail => Mods.Value.OfType<IApplicableFailOverride>().All(m => m.AllowFail);
private readonly bool allowPause;
private readonly bool showResults;
@ -101,48 +117,101 @@ namespace osu.Game.Screens.Play
Mods.Value = base.Mods.Value.Select(m => m.CreateCopy()).ToArray();
WorkingBeatmap working = loadBeatmap();
if (Beatmap.Value is DummyWorkingBeatmap)
return;
if (working == null)
IBeatmap playableBeatmap = loadPlayableBeatmap();
if (playableBeatmap == null)
return;
sampleRestart = audio.Samples.Get(@"Gameplay/restart");
mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
showStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
ScoreProcessor = DrawableRuleset.CreateScoreProcessor();
DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, Mods.Value);
ScoreProcessor = ruleset.CreateScoreProcessor();
ScoreProcessor.ApplyBeatmap(playableBeatmap);
ScoreProcessor.Mods.BindTo(Mods);
HealthProcessor = ruleset.CreateHealthProcessor(playableBeatmap.HitObjects[0].StartTime);
HealthProcessor.ApplyBeatmap(playableBeatmap);
if (!ScoreProcessor.Mode.Disabled)
config.BindWith(OsuSetting.ScoreDisplayMode, ScoreProcessor.Mode);
InternalChild = GameplayClockContainer = new GameplayClockContainer(working, Mods.Value, DrawableRuleset.GameplayStartTime);
InternalChild = GameplayClockContainer = new GameplayClockContainer(Beatmap.Value, Mods.Value, DrawableRuleset.GameplayStartTime);
GameplayClockContainer.Children = new[]
addUnderlayComponents(GameplayClockContainer);
addGameplayComponents(GameplayClockContainer, Beatmap.Value);
addOverlayComponents(GameplayClockContainer, Beatmap.Value);
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
// bind clock into components that require it
DrawableRuleset.IsPaused.BindTo(GameplayClockContainer.IsPaused);
DrawableRuleset.OnNewResult += r =>
{
HealthProcessor.ApplyResult(r);
ScoreProcessor.ApplyResult(r);
};
DrawableRuleset.OnRevertResult += r =>
{
HealthProcessor.RevertResult(r);
ScoreProcessor.RevertResult(r);
};
// Bind the judgement processors to ourselves
ScoreProcessor.AllJudged += onCompletion;
HealthProcessor.Failed += onFail;
foreach (var mod in Mods.Value.OfType<IApplicableToScoreProcessor>())
mod.ApplyToScoreProcessor(ScoreProcessor);
foreach (var mod in Mods.Value.OfType<IApplicableToHealthProcessor>())
mod.ApplyToHealthProcessor(HealthProcessor);
BreakOverlay.IsBreakTime.ValueChanged += _ => updatePauseOnFocusLostState();
}
private void addUnderlayComponents(Container target)
{
target.Add(DimmableVideo = new DimmableVideo(Beatmap.Value.Video) { RelativeSizeAxes = Axes.Both });
target.Add(DimmableStoryboard = new DimmableStoryboard(Beatmap.Value.Storyboard) { RelativeSizeAxes = Axes.Both });
}
private void addGameplayComponents(Container target, WorkingBeatmap working)
{
var beatmapSkinProvider = new BeatmapSkinProvidingContainer(working.Skin);
// the beatmapSkinProvider is used as the fallback source here to allow the ruleset-specific skin implementation
// full access to all skin sources.
var rulesetSkinProvider = new SkinProvidingContainer(ruleset.CreateLegacySkinProvider(beatmapSkinProvider));
// load the skinning hierarchy first.
// this is intentionally done in two stages to ensure things are in a loaded state before exposing the ruleset to skin sources.
target.Add(new ScalingContainer(ScalingMode.Gameplay)
.WithChild(beatmapSkinProvider
.WithChild(target = rulesetSkinProvider)));
target.AddRange(new Drawable[]
{
DrawableRuleset,
new ComboEffects(ScoreProcessor)
});
}
private void addOverlayComponents(Container target, WorkingBeatmap working)
{
target.AddRange(new[]
{
StoryboardContainer = CreateStoryboardContainer(),
new ScalingContainer(ScalingMode.Gameplay)
{
Child = new LocalSkinOverrideContainer(working.Skin)
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
DrawableRuleset,
new ComboEffects(ScoreProcessor)
}
}
},
new BreakOverlay(working.Beatmap.BeatmapInfo.LetterboxInBreaks, ScoreProcessor)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Breaks = working.Beatmap.Breaks
},
// display the cursor above some HUD elements.
DrawableRuleset.Cursor?.CreateProxy() ?? new Container(),
HUDOverlay = new HUDOverlay(ScoreProcessor, DrawableRuleset, Mods.Value)
DrawableRuleset.ResumeOverlay?.CreateProxy() ?? new Container(),
HUDOverlay = new HUDOverlay(ScoreProcessor, HealthProcessor, DrawableRuleset, Mods.Value)
{
HoldToQuit =
{
@ -157,7 +226,7 @@ namespace osu.Game.Screens.Play
},
new SkipOverlay(DrawableRuleset.GameplayStartTime)
{
RequestSeek = GameplayClockContainer.Seek
RequestSkip = GameplayClockContainer.Skip
},
FailOverlay = new FailOverlay
{
@ -192,54 +261,52 @@ namespace osu.Game.Screens.Play
},
},
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, }
};
});
DrawableRuleset.HasReplayLoaded.BindValueChanged(e => HUDOverlay.HoldToQuit.PauseOnFocusLost = !e.NewValue && PauseOnFocusLost, true);
DrawableRuleset.Overlays.Add(BreakOverlay = new BreakOverlay(working.Beatmap.BeatmapInfo.LetterboxInBreaks, DrawableRuleset.GameplayStartTime, ScoreProcessor)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Breaks = working.Beatmap.Breaks
});
// bind clock into components that require it
DrawableRuleset.IsPaused.BindTo(GameplayClockContainer.IsPaused);
DrawableRuleset.Overlays.Add(ScoreProcessor);
DrawableRuleset.Overlays.Add(HealthProcessor);
// load storyboard as part of player's load if we can
initializeStoryboard(false);
// Bind ScoreProcessor to ourselves
ScoreProcessor.AllJudged += onCompletion;
ScoreProcessor.Failed += onFail;
foreach (var mod in Mods.Value.OfType<IApplicableToScoreProcessor>())
mod.ApplyToScoreProcessor(ScoreProcessor);
HealthProcessor.IsBreakTime.BindTo(BreakOverlay.IsBreakTime);
}
private WorkingBeatmap loadBeatmap()
private void updatePauseOnFocusLostState() =>
HUDOverlay.HoldToQuit.PauseOnFocusLost = PauseOnFocusLost
&& !DrawableRuleset.HasReplayLoaded.Value
&& !BreakOverlay.IsBreakTime.Value;
private IBeatmap loadPlayableBeatmap()
{
WorkingBeatmap working = Beatmap.Value;
if (working is DummyWorkingBeatmap)
return null;
IBeatmap playable;
try
{
var beatmap = working.Beatmap;
if (beatmap == null)
if (Beatmap.Value.Beatmap == null)
throw new InvalidOperationException("Beatmap was not loaded");
ruleset = Ruleset.Value ?? beatmap.BeatmapInfo.Ruleset;
var rulesetInstance = ruleset.CreateInstance();
rulesetInfo = Ruleset.Value ?? Beatmap.Value.BeatmapInfo.Ruleset;
ruleset = rulesetInfo.CreateInstance();
try
{
DrawableRuleset = rulesetInstance.CreateDrawableRulesetWith(working, Mods.Value);
playable = Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, Mods.Value);
}
catch (BeatmapInvalidForRulesetException)
{
// we may fail to create a DrawableRuleset if the beatmap cannot be loaded with the user's preferred ruleset
// let's try again forcing the beatmap's ruleset.
ruleset = beatmap.BeatmapInfo.Ruleset;
rulesetInstance = ruleset.CreateInstance();
DrawableRuleset = rulesetInstance.CreateDrawableRulesetWith(Beatmap.Value, Mods.Value);
// A playable beatmap may not be creatable with the user's preferred ruleset, so try using the beatmap's default ruleset
rulesetInfo = Beatmap.Value.BeatmapInfo.Ruleset;
ruleset = rulesetInfo.CreateInstance();
playable = Beatmap.Value.GetPlayableBeatmap(rulesetInfo, Mods.Value);
}
if (!DrawableRuleset.Objects.Any())
if (playable.HitObjects.Count == 0)
{
Logger.Log("Beatmap contains no hit objects!", level: LogLevel.Error);
return null;
@ -252,13 +319,13 @@ namespace osu.Game.Screens.Play
return null;
}
return working;
return playable;
}
private void performImmediateExit()
{
// if a restart has been requested, cancel any pending completion (user has shown intent to restart).
onCompletionEvent = null;
completionProgressDelegate?.Cancel();
ValidForResume = false;
@ -269,29 +336,39 @@ namespace osu.Game.Screens.Play
{
if (!this.IsCurrentScreen()) return;
this.Exit();
if (ValidForResume && HasFailed && !FailOverlay.IsPresent)
{
failAnimation.FinishTransforms(true);
return;
}
if (canPause)
Pause();
else
this.Exit();
}
/// <summary>
/// Restart gameplay via a parent <see cref="PlayerLoader"/>.
/// <remarks>This can be called from a child screen in order to trigger the restart process.</remarks>
/// </summary>
public void Restart()
{
if (!this.IsCurrentScreen()) return;
sampleRestart?.Play();
// if a restart has been requested, cancel any pending completion (user has shown intent to restart).
onCompletionEvent = null;
ValidForResume = false;
RestartRequested?.Invoke();
this.Exit();
if (this.IsCurrentScreen())
performImmediateExit();
else
this.MakeCurrent();
}
private ScheduledDelegate onCompletionEvent;
private ScheduledDelegate completionProgressDelegate;
private void onCompletion()
{
// Only show the completion screen if the player hasn't failed
if (ScoreProcessor.HasFailed || onCompletionEvent != null)
if (HealthProcessor.HasFailed || completionProgressDelegate != null)
return;
ValidForResume = false;
@ -299,20 +376,7 @@ namespace osu.Game.Screens.Play
if (!showResults) return;
using (BeginDelayedSequence(1000))
{
onCompletionEvent = Schedule(delegate
{
if (!this.IsCurrentScreen()) return;
var score = CreateScore();
if (DrawableRuleset.ReplayScore == null)
scoreManager.Import(score).Wait();
this.Push(CreateResults(score));
onCompletionEvent = null;
});
}
scheduleGotoRanking();
}
protected virtual ScoreInfo CreateScore()
@ -320,7 +384,7 @@ namespace osu.Game.Screens.Play
var score = DrawableRuleset.ReplayScore?.ScoreInfo ?? new ScoreInfo
{
Beatmap = Beatmap.Value.BeatmapInfo,
Ruleset = ruleset,
Ruleset = rulesetInfo,
Mods = Mods.Value.ToArray(),
User = api.LocalUser.Value,
};
@ -334,41 +398,6 @@ namespace osu.Game.Screens.Play
protected virtual Results CreateResults(ScoreInfo score) => new SoloResults(score);
#region Storyboard
private DrawableStoryboard storyboard;
protected UserDimContainer StoryboardContainer { get; private set; }
protected virtual UserDimContainer CreateStoryboardContainer() => new UserDimContainer(true)
{
RelativeSizeAxes = Axes.Both,
Alpha = 1,
EnableUserDim = { Value = true }
};
private Bindable<bool> showStoryboard;
private void initializeStoryboard(bool asyncLoad)
{
if (StoryboardContainer == null || storyboard != null)
return;
if (!showStoryboard.Value)
return;
var beatmap = Beatmap.Value;
storyboard = beatmap.Storyboard.CreateDrawable();
storyboard.Masking = true;
if (asyncLoad)
LoadComponentAsync(storyboard, StoryboardContainer.Add);
else
StoryboardContainer.Add(storyboard);
}
#endregion
#region Fail Logic
protected FailOverlay FailOverlay { get; private set; }
@ -377,7 +406,7 @@ namespace osu.Game.Screens.Play
private bool onFail()
{
if (Mods.Value.OfType<IApplicableFailOverride>().Any(m => !m.AllowFail))
if (!AllowFail)
return false;
HasFailed = true;
@ -389,6 +418,10 @@ namespace osu.Game.Screens.Play
PauseOverlay.Hide();
failAnimation.Start();
if (Mods.Value.OfType<IApplicableFailOverride>().Any(m => m.RestartOnFail))
Restart();
return true;
}
@ -441,7 +474,12 @@ namespace osu.Game.Screens.Play
{
if (!canPause) return;
IsResuming = false;
if (IsResuming)
{
DrawableRuleset.CancelResume();
IsResuming = false;
}
GameplayClockContainer.Stop();
PauseOverlay.Show();
lastPauseActionTime = GameplayClockContainer.GameplayClock.CurrentTime;
@ -455,8 +493,7 @@ namespace osu.Game.Screens.Play
PauseOverlay.Hide();
// breaks and time-based conditions may allow instant resume.
double time = GameplayClockContainer.GameplayClock.CurrentTime;
if (Beatmap.Value.Beatmap.Breaks.Any(b => b.Contains(time)) || time < Beatmap.Value.Beatmap.HitObjects.First().StartTime)
if (BreakOverlay.IsBreakTime.Value)
completeResume();
else
DrawableRuleset.RequestResume(completeResume);
@ -486,19 +523,25 @@ namespace osu.Game.Screens.Play
.Delay(250)
.FadeIn(250);
showStoryboard.ValueChanged += _ => initializeStoryboard(true);
Background.EnableUserDim.Value = true;
Background.BlurAmount.Value = 0;
// bind component bindables.
Background.IsBreakTime.BindTo(BreakOverlay.IsBreakTime);
DimmableStoryboard.IsBreakTime.BindTo(BreakOverlay.IsBreakTime);
DimmableVideo.IsBreakTime.BindTo(BreakOverlay.IsBreakTime);
Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
DimmableStoryboard.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
GameplayClockContainer.Restart();
GameplayClockContainer.FadeInFromZero(750, Easing.OutQuint);
foreach (var mod in Mods.Value.OfType<IApplicableToPlayer>())
mod.ApplyToPlayer(this);
foreach (var mod in Mods.Value.OfType<IApplicableToHUD>())
mod.ApplyToHUD(HUDOverlay);
}
@ -511,31 +554,30 @@ namespace osu.Game.Screens.Play
public override bool OnExiting(IScreen next)
{
if (onCompletionEvent != null)
if (completionProgressDelegate != null && !completionProgressDelegate.Cancelled && !completionProgressDelegate.Completed)
{
// Proceed to result screen if beatmap already finished playing
onCompletionEvent.RunTask();
// proceed to result screen if beatmap already finished playing
scheduleGotoRanking();
return true;
}
// ValidForResume is false when restarting
if (ValidForResume)
{
if (pauseCooldownActive && !GameplayClockContainer.IsPaused.Value)
// still want to block if we are within the cooldown period and not already paused.
return true;
}
if (canPause)
{
Pause();
return true;
}
if (pauseCooldownActive && !GameplayClockContainer.IsPaused.Value)
// still want to block if we are within the cooldown period and not already paused.
return true;
if (HasFailed && ValidForResume && !FailOverlay.IsPresent)
// ValidForResume is false when restarting
{
failAnimation.FinishTransforms(true);
return true;
}
GameplayClockContainer.ResetLocalAdjustments();
// GameplayClockContainer performs seeks / start / stop operations on the beatmap's track.
// as we are no longer the current screen, we cannot guarantee the track is still usable.
GameplayClockContainer?.StopUsingBeatmapClock();
fadeOut();
return base.OnExiting(next);
@ -550,6 +592,19 @@ namespace osu.Game.Screens.Play
storyboardReplacesBackground.Value = false;
}
private void scheduleGotoRanking()
{
completionProgressDelegate?.Cancel();
completionProgressDelegate = Schedule(delegate
{
var score = CreateScore();
if (DrawableRuleset.ReplayScore == null)
scoreManager.Import(score).Wait();
this.Push(CreateResults(score));
});
}
#endregion
}
}

View File

@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -14,11 +16,14 @@ using osu.Framework.Localisation;
using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play.HUD;
@ -39,7 +44,7 @@ namespace osu.Game.Screens.Play
private LogoTrackingContainer content;
private BeatmapMetadataDisplay info;
protected BeatmapMetadataDisplay MetadataInfo;
private bool hideOverlays;
public override bool HideOverlaysOnEnter => hideOverlays;
@ -50,12 +55,24 @@ namespace osu.Game.Screens.Play
protected override bool PlayResumeSound => false;
private Task loadTask;
protected Task LoadTask { get; private set; }
protected Task DisposalTask { get; private set; }
private InputManager inputManager;
private IdleTracker idleTracker;
[Resolved(CanBeNull = true)]
private NotificationOverlay notificationOverlay { get; set; }
[Resolved(CanBeNull = true)]
private VolumeOverlay volumeOverlay { get; set; }
[Resolved]
private AudioManager audioManager { get; set; }
private Bindable<bool> muteWarningShownOnce;
public PlayerLoader(Func<Player> createPlayer)
{
this.createPlayer = createPlayer;
@ -68,8 +85,10 @@ namespace osu.Game.Screens.Play
}
[BackgroundDependencyLoader]
private void load()
private void load(SessionStatics sessionStatics)
{
muteWarningShownOnce = sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce);
InternalChild = (content = new LogoTrackingContainer
{
Anchor = Anchor.Centre,
@ -77,7 +96,7 @@ namespace osu.Game.Screens.Play
RelativeSizeAxes = Axes.Both,
}).WithChildren(new Drawable[]
{
info = new BeatmapMetadataDisplay(Beatmap.Value, Mods.Value, content.LogoFacade)
MetadataInfo = new BeatmapMetadataDisplay(Beatmap.Value, Mods, content.LogoFacade)
{
Alpha = 0,
Anchor = Anchor.Centre,
@ -99,11 +118,39 @@ namespace osu.Game.Screens.Play
},
idleTracker = new IdleTracker(750)
});
loadNewPlayer();
}
private void playerLoaded(Player player) => info.Loading = false;
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
public override void OnEntering(IScreen last)
{
base.OnEntering(last);
loadNewPlayer();
content.ScaleTo(0.7f);
Background?.FadeColour(Color4.White, 800, Easing.OutQuint);
contentIn();
MetadataInfo.Delay(750).FadeIn(500);
this.Delay(1800).Schedule(pushWhenLoaded);
if (!muteWarningShownOnce.Value)
{
//Checks if the notification has not been shown yet and also if master volume is muted, track/music volume is muted or if the whole game is muted.
if (volumeOverlay?.IsMuted.Value == true || audioManager.Volume.Value <= audioManager.Volume.MinValue || audioManager.VolumeTrack.Value <= audioManager.VolumeTrack.MinValue)
{
notificationOverlay?.Post(new MutedNotification());
muteWarningShownOnce.Value = true;
}
}
}
public override void OnResuming(IScreen last)
{
@ -111,7 +158,7 @@ namespace osu.Game.Screens.Play
contentIn();
info.Loading = true;
MetadataInfo.Loading = true;
//we will only be resumed if the player has requested a re-run (see ValidForResume setting above)
loadNewPlayer();
@ -127,7 +174,7 @@ namespace osu.Game.Screens.Play
player.RestartCount = restartCount;
player.RestartRequested = restartRequested;
loadTask = LoadComponentAsync(player, playerLoaded);
LoadTask = LoadComponentAsync(player, _ => MetadataInfo.Loading = false);
}
private void contentIn()
@ -145,19 +192,6 @@ namespace osu.Game.Screens.Play
content.FadeOut(250);
}
public override void OnEntering(IScreen last)
{
base.OnEntering(last);
content.ScaleTo(0.7f);
Background?.FadeColour(Color4.White, 800, Easing.OutQuint);
contentIn();
info.Delay(750).FadeIn(500);
this.Delay(1800).Schedule(pushWhenLoaded);
}
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
@ -185,12 +219,6 @@ namespace osu.Game.Screens.Play
content.StopTracking();
}
protected override void LoadComplete()
{
inputManager = GetContainingInputManager();
base.LoadComplete();
}
private ScheduledDelegate pushDebounce;
protected VisualSettings VisualSettings;
@ -224,7 +252,7 @@ namespace osu.Game.Screens.Play
{
if (!this.IsCurrentScreen()) return;
loadTask = null;
LoadTask = null;
//By default, we want to load the player and never be returned to.
//Note that this may change if the player we load requested a re-run.
@ -275,7 +303,7 @@ namespace osu.Game.Screens.Play
if (isDisposing)
{
// if the player never got pushed, we should explicitly dispose it.
loadTask?.ContinueWith(_ => player.Dispose());
DisposalTask = LoadTask?.ContinueWith(_ => player.Dispose());
}
}
@ -322,7 +350,7 @@ namespace osu.Game.Screens.Play
}
}
private class BeatmapMetadataDisplay : Container
protected class BeatmapMetadataDisplay : Container
{
private class MetadataLine : Container
{
@ -351,11 +379,13 @@ namespace osu.Game.Screens.Play
}
private readonly WorkingBeatmap beatmap;
private readonly IReadOnlyList<Mod> mods;
private readonly Bindable<IReadOnlyList<Mod>> mods;
private readonly Drawable facade;
private LoadingAnimation loading;
private Sprite backgroundSprite;
public IBindable<IReadOnlyList<Mod>> Mods => mods;
public bool Loading
{
set
@ -373,11 +403,13 @@ namespace osu.Game.Screens.Play
}
}
public BeatmapMetadataDisplay(WorkingBeatmap beatmap, IReadOnlyList<Mod> mods, Drawable facade)
public BeatmapMetadataDisplay(WorkingBeatmap beatmap, Bindable<IReadOnlyList<Mod>> mods, Drawable facade)
{
this.beatmap = beatmap;
this.mods = mods;
this.facade = facade;
this.mods = new Bindable<IReadOnlyList<Mod>>();
this.mods.BindTo(mods);
}
[BackgroundDependencyLoader]
@ -464,7 +496,7 @@ namespace osu.Game.Screens.Play
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Top = 20 },
Current = { Value = mods }
Current = mods
}
},
}
@ -473,5 +505,33 @@ namespace osu.Game.Screens.Play
Loading = true;
}
}
private class MutedNotification : SimpleNotification
{
public MutedNotification()
{
Text = "Your music volume is set to 0%! Click here to restore it.";
}
public override bool IsImportant => true;
[BackgroundDependencyLoader]
private void load(OsuColour colours, AudioManager audioManager, NotificationOverlay notificationOverlay, VolumeOverlay volumeOverlay)
{
Icon = FontAwesome.Solid.VolumeMute;
IconBackgound.Colour = colours.RedDark;
Activated = delegate
{
notificationOverlay.Hide();
volumeOverlay.IsMuted.Value = false;
audioManager.Volume.SetDefault();
audioManager.VolumeTrack.SetDefault();
return true;
};
}
}
}
}

View File

@ -11,7 +11,7 @@ using osu.Game.Overlays.Settings;
namespace osu.Game.Screens.Play.PlayerSettings
{
public class PlayerSliderBar<T> : SettingsSlider<T>
where T : struct, IEquatable<T>, IComparable, IConvertible
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{
public OsuSliderBar<T> Bar => (OsuSliderBar<T>)Control;

View File

@ -15,6 +15,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
private readonly PlayerSliderBar<double> dimSliderBar;
private readonly PlayerSliderBar<double> blurSliderBar;
private readonly PlayerCheckbox showStoryboardToggle;
private readonly PlayerCheckbox showVideoToggle;
private readonly PlayerCheckbox beatmapSkinsToggle;
private readonly PlayerCheckbox beatmapHitsoundsToggle;
@ -37,6 +38,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
Text = "Toggles:"
},
showStoryboardToggle = new PlayerCheckbox { LabelText = "Storyboards" },
showVideoToggle = new PlayerCheckbox { LabelText = "Video" },
beatmapSkinsToggle = new PlayerCheckbox { LabelText = "Beatmap skins" },
beatmapHitsoundsToggle = new PlayerCheckbox { LabelText = "Beatmap hitsounds" }
};
@ -48,6 +50,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
dimSliderBar.Bindable = config.GetBindable<double>(OsuSetting.DimLevel);
blurSliderBar.Bindable = config.GetBindable<double>(OsuSetting.BlurLevel);
showStoryboardToggle.Current = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
showVideoToggle.Current = config.GetBindable<bool>(OsuSetting.ShowVideoBackground);
beatmapSkinsToggle.Current = config.GetBindable<bool>(OsuSetting.BeatmapSkins);
beatmapHitsoundsToggle.Current = config.GetBindable<bool>(OsuSetting.BeatmapHitsounds);
}

View File

@ -1,99 +0,0 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online;
using osu.Game.Scoring;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Screens.Play
{
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>
{
private DownloadButton button;
private ShakeContainer shakeContainer;
private ReplayAvailability replayAvailability
{
get
{
if (State.Value == DownloadState.LocallyAvailable)
return ReplayAvailability.Local;
if (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay)
return ReplayAvailability.Online;
return ReplayAvailability.NotAvailable;
}
}
public ReplayDownloadButton(ScoreInfo score)
: base(score)
{
}
[BackgroundDependencyLoader(true)]
private void load(OsuGame game, ScoreManager scores)
{
InternalChild = shakeContainer = new ShakeContainer
{
RelativeSizeAxes = Axes.Both,
Child = button = new DownloadButton
{
RelativeSizeAxes = Axes.Both,
}
};
button.Action = () =>
{
switch (State.Value)
{
case DownloadState.LocallyAvailable:
game?.PresentScore(Model.Value);
break;
case DownloadState.NotDownloaded:
scores.Download(Model.Value);
break;
case DownloadState.Downloaded:
case DownloadState.Downloading:
shakeContainer.Shake();
break;
}
};
State.BindValueChanged(state =>
{
button.State.Value = state.NewValue;
switch (replayAvailability)
{
case ReplayAvailability.Local:
button.TooltipText = @"Watch replay";
break;
case ReplayAvailability.Online:
button.TooltipText = @"Download replay";
break;
default:
button.TooltipText = @"Replay unavailable";
break;
}
}, true);
button.Enabled.Value = replayAvailability != ReplayAvailability.NotAvailable;
}
private enum ReplayAvailability
{
Local,
Online,
NotAvailable,
}
}
}

View File

@ -9,6 +9,9 @@ namespace osu.Game.Screens.Play
{
private readonly Score score;
// Disallow replays from failing. (see https://github.com/ppy/osu/issues/6108)
protected override bool AllowFail => false;
public ReplayPlayer(Score score, bool allowPause = true, bool showResults = true)
: base(allowPause, showResults)
{

View File

@ -2,7 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Screens;
using osu.Game.Scoring;
namespace osu.Game.Screens.Play
@ -15,20 +15,18 @@ namespace osu.Game.Screens.Play
: base(() => new ReplayPlayer(score))
{
if (score.Replay == null)
throw new ArgumentNullException(nameof(score.Replay), $"{nameof(score)} must have a non-null {nameof(score.Replay)}.");
throw new ArgumentException($"{nameof(score)} must have a non-null {nameof(score.Replay)}.", nameof(score));
scoreInfo = score.ScoreInfo;
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
public override void OnEntering(IScreen last)
{
var dependencies = base.CreateChildDependencies(parent);
// these will be reverted thanks to PlayerLoader's lease.
Mods.Value = scoreInfo.Mods;
Ruleset.Value = scoreInfo.Ruleset;
return dependencies;
base.OnEntering(last);
}
}
}

View File

@ -16,7 +16,7 @@ namespace osu.Game.Screens.Play
/// <summary>
/// An overlay which can be used to require further user actions before gameplay is resumed.
/// </summary>
public abstract class ResumeOverlay : OverlayContainer
public abstract class ResumeOverlay : VisibilityContainer
{
public CursorContainer GameplayCursor { get; set; }
@ -29,8 +29,6 @@ namespace osu.Game.Screens.Play
protected const float TRANSITION_TIME = 500;
protected override bool BlockPositionalInput => false;
protected abstract string Message { get; }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;

View File

@ -9,6 +9,6 @@ namespace osu.Game.Screens.Play
{
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
protected new BackgroundScreenBeatmap Background => (BackgroundScreenBeatmap)base.Background;
public new BackgroundScreenBeatmap Background => (BackgroundScreenBeatmap)base.Background;
}
}

View File

@ -19,15 +19,16 @@ using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Input.Bindings;
namespace osu.Game.Screens.Play
{
public class SkipOverlay : OverlayContainer, IKeyBindingHandler<GlobalAction>
public class SkipOverlay : VisibilityContainer, IKeyBindingHandler<GlobalAction>
{
private readonly double startTime;
public Action<double> RequestSeek;
public Action RequestSkip;
private Button button;
private Box remainingTimeBox;
@ -35,8 +36,10 @@ namespace osu.Game.Screens.Play
private FadeContainer fadeContainer;
private double displayTime;
[Resolved]
private GameplayClock gameplayClock { get; set; }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
protected override bool BlockPositionalInput => false;
/// <summary>
/// Displays a skip overlay, giving the user the ability to skip forward.
@ -46,8 +49,6 @@ namespace osu.Game.Screens.Play
{
this.startTime = startTime;
Show();
RelativePositionAxes = Axes.Both;
RelativeSizeAxes = Axes.X;
@ -58,13 +59,8 @@ namespace osu.Game.Screens.Play
}
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, GameplayClock clock)
private void load(OsuColour colours)
{
var baseClock = Clock;
if (clock != null)
Clock = clock;
Children = new Drawable[]
{
fadeContainer = new FadeContainer
@ -74,7 +70,6 @@ namespace osu.Game.Screens.Play
{
button = new Button
{
Clock = baseClock,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
@ -91,46 +86,42 @@ namespace osu.Game.Screens.Play
};
}
/// <summary>
/// Duration before gameplay start time required before skip button displays.
/// </summary>
private const double skip_buffer = 1000;
private const double fade_time = 300;
private double beginFadeTime => startTime - fade_time;
private double fadeOutBeginTime => startTime - GameplayClockContainer.MINIMUM_SKIP_TIME;
protected override void LoadComplete()
{
base.LoadComplete();
// skip is not required if there is no extra "empty" time to skip.
if (Clock.CurrentTime > beginFadeTime - skip_buffer)
// we may need to remove this if rewinding before the initial player load position becomes a thing.
if (fadeOutBeginTime < gameplayClock.CurrentTime)
{
Alpha = 0;
Expire();
return;
}
this.FadeInFromZero(fade_time);
using (BeginAbsoluteSequence(beginFadeTime))
this.FadeOut(fade_time);
button.Action = () => RequestSkip?.Invoke();
displayTime = gameplayClock.CurrentTime;
button.Action = () => RequestSeek?.Invoke(beginFadeTime);
displayTime = Time.Current;
Expire();
Show();
}
protected override void PopIn() => this.FadeIn();
protected override void PopIn() => this.FadeIn(fade_time);
protected override void PopOut() => this.FadeOut();
protected override void PopOut() => this.FadeOut(fade_time);
protected override void Update()
{
base.Update();
remainingTimeBox.ResizeWidthTo((float)Math.Max(0, 1 - (Time.Current - displayTime) / (beginFadeTime - displayTime)), 120, Easing.OutQuint);
var progress = Math.Max(0, 1 - (gameplayClock.CurrentTime - displayTime) / (fadeOutBeginTime - displayTime));
remainingTimeBox.Width = (float)Interpolation.Lerp(remainingTimeBox.Width, progress, Math.Clamp(Time.Elapsed / 40, 0, 1));
button.Enabled.Value = progress > 0;
State.Value = progress > 0 ? Visibility.Visible : Visibility.Hidden;
}
protected override bool OnMouseMove(MouseMoveEvent e)
@ -152,7 +143,9 @@ namespace osu.Game.Screens.Play
return false;
}
public bool OnReleased(GlobalAction action) => false;
public void OnReleased(GlobalAction action)
{
}
private class FadeContainer : Container, IStateful<Visibility>
{
@ -161,6 +154,8 @@ namespace osu.Game.Screens.Play
private Visibility state;
private ScheduledDelegate scheduledHide;
public override bool IsPresent => true;
public Visibility State
{
get => state;
@ -180,8 +175,11 @@ namespace osu.Game.Screens.Play
this.FadeIn(500, Easing.OutExpo);
if (!IsHovered && !IsDragged)
{
using (BeginDelayedSequence(1000))
scheduledHide = Schedule(Hide);
}
break;
case Visibility.Hidden:
@ -201,14 +199,14 @@ namespace osu.Game.Screens.Play
protected override bool OnMouseDown(MouseDownEvent e)
{
Show();
scheduledHide?.Cancel();
return base.OnMouseDown(e);
return true;
}
protected override bool OnMouseUp(MouseUpEvent e)
protected override void OnMouseUp(MouseUpEvent e)
{
Show();
return base.OnMouseUp(e);
}
public override void Hide() => State = Visibility.Hidden;
@ -314,10 +312,10 @@ namespace osu.Game.Screens.Play
return base.OnMouseDown(e);
}
protected override bool OnMouseUp(MouseUpEvent e)
protected override void OnMouseUp(MouseUpEvent e)
{
aspect.ScaleTo(1, 1000, Easing.OutElastic);
return base.OnMouseUp(e);
base.OnMouseUp(e);
}
protected override bool OnClick(ClickEvent e)
@ -330,13 +328,7 @@ namespace osu.Game.Screens.Play
box.FlashColour(Color4.White, 500, Easing.OutQuint);
aspect.ScaleTo(1.2f, 2000, Easing.OutQuint);
bool result = base.OnClick(e);
// for now, let's disable the skip button after the first press.
// this will likely need to be contextual in the future (bound from external components).
Enabled.Value = false;
return result;
return base.OnClick(e);
}
}
}

View File

@ -13,7 +13,6 @@ using osu.Framework.Bindables;
using osu.Framework.Timing;
using osu.Game.Configuration;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.UI;
namespace osu.Game.Screens.Play
@ -40,6 +39,9 @@ namespace osu.Game.Screens.Play
public readonly Bindable<bool> ShowGraph = new Bindable<bool>();
//TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list).
private double lastHitTime => objects.Last().GetEndTime() + 1;
public override bool HandleNonPositionalInput => AllowSeeking.Value;
public override bool HandlePositionalInput => AllowSeeking.Value;
@ -101,8 +103,7 @@ namespace osu.Game.Screens.Play
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, GameplayClock clock, OsuConfigManager config)
{
if (clock != null)
gameplayClock = clock;
base.LoadComplete();
config.BindWith(OsuSetting.ShowProgressGraph, ShowGraph);

View File

@ -8,7 +8,8 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.MathUtils;
using osu.Framework.Utils;
using osu.Framework.Threading;
namespace osu.Game.Screens.Play
{
@ -116,12 +117,18 @@ namespace osu.Game.Screens.Play
base.Update();
handleBase.Height = Height - handleContainer.Height;
float newX = (float)Interpolation.Lerp(handleBase.X, NormalizedValue * UsableWidth, MathHelper.Clamp(Time.Elapsed / 40, 0, 1));
float newX = (float)Interpolation.Lerp(handleBase.X, NormalizedValue * UsableWidth, Math.Clamp(Time.Elapsed / 40, 0, 1));
fill.Width = newX;
handleBase.X = newX;
}
protected override void OnUserChange(double value) => OnSeek?.Invoke(value);
private ScheduledDelegate scheduledSeek;
protected override void OnUserChange(double value)
{
scheduledSeek?.Cancel();
scheduledSeek = Schedule(() => OnSeek?.Invoke(value));
}
}
}

View File

@ -4,7 +4,6 @@
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Screens.Play
@ -26,7 +25,7 @@ namespace osu.Game.Screens.Play
return;
var firstHit = objects.First().StartTime;
var lastHit = objects.Max(o => (o as IHasEndTime)?.EndTime ?? o.StartTime);
var lastHit = objects.Max(o => o.GetEndTime());
if (lastHit == 0)
lastHit = objects.Last().StartTime;
@ -35,7 +34,7 @@ namespace osu.Game.Screens.Play
foreach (var h in objects)
{
var endTime = (h as IHasEndTime)?.EndTime ?? h.StartTime;
var endTime = h.GetEndTime();
Debug.Assert(endTime >= h.StartTime);

View File

@ -38,7 +38,7 @@ namespace osu.Game.Screens.Play
}
}
private float[] calculatedValues = { }; // values but adjusted to fit the amount of columns
private float[] calculatedValues = Array.Empty<float>(); // values but adjusted to fit the amount of columns
private int[] values;
@ -75,7 +75,7 @@ namespace osu.Game.Screens.Play
return base.Invalidate(invalidation, source, shallPropagate);
}
private Cached layout = new Cached();
private readonly Cached layout = new Cached();
private ScheduledDelegate scheduledCreate;
protected override void Update()
@ -103,6 +103,7 @@ namespace osu.Game.Screens.Play
var newColumns = new BufferedContainer<Column>
{
CacheDrawnFrameBuffer = true,
RedrawOnScale = false,
RelativeSizeAxes = Axes.Both,
};
@ -255,7 +256,7 @@ namespace osu.Game.Screens.Play
{
Color4 colour = State == ColumnState.Lit ? LitColour : DimmedColour;
int countFilled = (int)MathHelper.Clamp(filled * drawableRows.Count, 0, drawableRows.Count);
int countFilled = (int)Math.Clamp(filled * drawableRows.Count, 0, drawableRows.Count);
for (int i = 0; i < drawableRows.Count; i++)
drawableRows[i].Colour = i < countFilled ? colour : EmptyColour;