mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:52:55 +08:00
Make HitErrorDisplay an abstract class
This commit is contained in:
parent
70084b5553
commit
6d3aa0520b
174
osu.Game/Screens/Play/HitErrorDisplay/DefaultHitErrorDisplay.cs
Normal file
174
osu.Game/Screens/Play/HitErrorDisplay/DefaultHitErrorDisplay.cs
Normal file
@ -0,0 +1,174 @@
|
||||
// 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.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osuTK.Graphics;
|
||||
using osuTK;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Screens.Play.HitErrorDisplay
|
||||
{
|
||||
public class DefaultHitErrorDisplay : HitErrorDisplay
|
||||
{
|
||||
private const int stored_judgements_amount = 5;
|
||||
private const int bar_width = 3;
|
||||
private const int judgement_line_width = 8;
|
||||
private const int bar_height = 200;
|
||||
private const int arrow_move_duration = 500;
|
||||
private const int judgement_life_time = 10000;
|
||||
private const int spacing = 3;
|
||||
|
||||
private readonly SpriteIcon arrow;
|
||||
private readonly FillFlowContainer bar;
|
||||
private readonly Container judgementsContainer;
|
||||
private readonly Queue<double> judgementOffsets = new Queue<double>();
|
||||
|
||||
public DefaultHitErrorDisplay(float overallDifficulty, HitWindows hitWindows, bool reversed = false)
|
||||
: base(overallDifficulty, hitWindows)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft;
|
||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft;
|
||||
|
||||
AddInternal(new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.X,
|
||||
Height = bar_height,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(spacing, 0),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
judgementsContainer = new Container
|
||||
{
|
||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Width = judgement_line_width,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
},
|
||||
bar = new FillFlowContainer
|
||||
{
|
||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Width = bar_width,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
AutoSizeAxes = Axes.X,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Child = arrow = new SpriteIcon
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativePositionAxes = Axes.Y,
|
||||
Icon = reversed ? FontAwesome.Solid.ChevronRight : FontAwesome.Solid.ChevronLeft,
|
||||
Size = new Vector2(8),
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
bar.AddRange(new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = ColourInfo.GradientVertical(colours.Yellow.Opacity(0), colours.Yellow),
|
||||
Height = (float)((getMehHitWindows() - HitWindows.Good) / (getMehHitWindows() * 2))
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.Green,
|
||||
Height = (float)((HitWindows.Good - HitWindows.Great) / (getMehHitWindows() * 2))
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.BlueLight,
|
||||
Height = (float)(HitWindows.Great / getMehHitWindows())
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.Green,
|
||||
Height = (float)((HitWindows.Good - HitWindows.Great) / (getMehHitWindows() * 2))
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = ColourInfo.GradientVertical(colours.Yellow, colours.Yellow.Opacity(0)),
|
||||
Height = (float)((getMehHitWindows() - HitWindows.Good) / (getMehHitWindows() * 2))
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private double getMehHitWindows()
|
||||
{
|
||||
// In case if ruleset has no Meh hit windows (like Taiko)
|
||||
if (HitWindows.Meh == 0)
|
||||
return HitWindows.Good + 40;
|
||||
|
||||
return HitWindows.Meh;
|
||||
}
|
||||
|
||||
public override void OnNewJudgement(JudgementResult newJudgement)
|
||||
{
|
||||
if (!newJudgement.IsHit)
|
||||
return;
|
||||
|
||||
var judgementLine = CreateJudgementLine(newJudgement);
|
||||
|
||||
judgementsContainer.Add(judgementLine);
|
||||
|
||||
judgementLine.FadeOut(judgement_life_time, Easing.OutQuint).Expire();
|
||||
|
||||
arrow.MoveToY(calculateArrowPosition(newJudgement), arrow_move_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected virtual Container CreateJudgementLine(JudgementResult judgement) => new CircularContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Masking = true,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 2,
|
||||
RelativePositionAxes = Axes.Y,
|
||||
Y = getRelativeJudgementPosition(judgement.TimeOffset),
|
||||
Child = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.White,
|
||||
}
|
||||
};
|
||||
|
||||
private float getRelativeJudgementPosition(double value) => (float)(value / getMehHitWindows());
|
||||
|
||||
private float calculateArrowPosition(JudgementResult newJudgement)
|
||||
{
|
||||
if (judgementOffsets.Count > stored_judgements_amount)
|
||||
judgementOffsets.Dequeue();
|
||||
|
||||
judgementOffsets.Enqueue(newJudgement.TimeOffset);
|
||||
|
||||
return getRelativeJudgementPosition(judgementOffsets.Average());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,177 +1,22 @@
|
||||
// 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.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osuTK.Graphics;
|
||||
using osuTK;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Screens.Play.HitErrorDisplay
|
||||
{
|
||||
public class HitErrorDisplay : CompositeDrawable
|
||||
public abstract class HitErrorDisplay : CompositeDrawable
|
||||
{
|
||||
private const int stored_judgements_amount = 5;
|
||||
private const int bar_width = 3;
|
||||
private const int judgement_line_width = 8;
|
||||
private const int bar_height = 200;
|
||||
private const int arrow_move_duration = 500;
|
||||
private const int judgement_life_time = 10000;
|
||||
private const int spacing = 3;
|
||||
protected readonly HitWindows HitWindows;
|
||||
|
||||
private readonly HitWindows hitWindows;
|
||||
private readonly SpriteIcon arrow;
|
||||
private readonly FillFlowContainer bar;
|
||||
private readonly Container judgementsContainer;
|
||||
private readonly Queue<double> judgementOffsets = new Queue<double>();
|
||||
|
||||
public HitErrorDisplay(float overallDifficulty, HitWindows hitWindows, bool reversed = false)
|
||||
public HitErrorDisplay(float overallDifficulty, HitWindows hitWindows)
|
||||
{
|
||||
this.hitWindows = hitWindows;
|
||||
hitWindows.SetDifficulty(overallDifficulty);
|
||||
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft;
|
||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft;
|
||||
|
||||
AddInternal(new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.X,
|
||||
Height = bar_height,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(spacing, 0),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
judgementsContainer = new Container
|
||||
{
|
||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Width = judgement_line_width,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
},
|
||||
bar = new FillFlowContainer
|
||||
{
|
||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Width = bar_width,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||
AutoSizeAxes = Axes.X,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Child = arrow = new SpriteIcon
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativePositionAxes = Axes.Y,
|
||||
Icon = reversed ? FontAwesome.Solid.ChevronRight : FontAwesome.Solid.ChevronLeft,
|
||||
Size = new Vector2(8),
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
HitWindows = hitWindows;
|
||||
HitWindows.SetDifficulty(overallDifficulty);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
bar.AddRange(new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = ColourInfo.GradientVertical(colours.Yellow.Opacity(0), colours.Yellow),
|
||||
Height = (float)((getMehHitWindows() - hitWindows.Good) / (getMehHitWindows() * 2))
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.Green,
|
||||
Height = (float)((hitWindows.Good - hitWindows.Great) / (getMehHitWindows() * 2))
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.BlueLight,
|
||||
Height = (float)(hitWindows.Great / getMehHitWindows())
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.Green,
|
||||
Height = (float)((hitWindows.Good - hitWindows.Great) / (getMehHitWindows() * 2))
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = ColourInfo.GradientVertical(colours.Yellow, colours.Yellow.Opacity(0)),
|
||||
Height = (float)((getMehHitWindows() - hitWindows.Good) / (getMehHitWindows() * 2))
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private double getMehHitWindows()
|
||||
{
|
||||
// In case if ruleset has no Meh hit windows (like Taiko)
|
||||
if (hitWindows.Meh == 0)
|
||||
return hitWindows.Good + 40;
|
||||
|
||||
return hitWindows.Meh;
|
||||
}
|
||||
|
||||
public void OnNewJudgement(JudgementResult newJudgement)
|
||||
{
|
||||
if (!newJudgement.IsHit)
|
||||
return;
|
||||
|
||||
var judgementLine = CreateJudgementLine(newJudgement);
|
||||
|
||||
judgementsContainer.Add(judgementLine);
|
||||
|
||||
judgementLine.FadeOut(judgement_life_time, Easing.OutQuint).Expire();
|
||||
|
||||
arrow.MoveToY(calculateArrowPosition(newJudgement), arrow_move_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected virtual Container CreateJudgementLine(JudgementResult judgement) => new CircularContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Masking = true,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 2,
|
||||
RelativePositionAxes = Axes.Y,
|
||||
Y = getRelativeJudgementPosition(judgement.TimeOffset),
|
||||
Child = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.White,
|
||||
}
|
||||
};
|
||||
|
||||
private float getRelativeJudgementPosition(double value) => (float)(value / getMehHitWindows());
|
||||
|
||||
private float calculateArrowPosition(JudgementResult newJudgement)
|
||||
{
|
||||
if (judgementOffsets.Count > stored_judgements_amount)
|
||||
judgementOffsets.Dequeue();
|
||||
|
||||
judgementOffsets.Enqueue(newJudgement.TimeOffset);
|
||||
|
||||
return getRelativeJudgementPosition(judgementOffsets.Average());
|
||||
}
|
||||
public abstract void OnNewJudgement(JudgementResult newJudgement);
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ namespace osu.Game.Screens.Play.HitErrorDisplay
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Children = new[]
|
||||
{
|
||||
new HitErrorDisplay(overallDifficulty, processor.CreateHitWindows())
|
||||
new DefaultHitErrorDisplay(overallDifficulty, processor.CreateHitWindows())
|
||||
{
|
||||
Margin = new MarginPadding { Left = margin }
|
||||
},
|
||||
new HitErrorDisplay(overallDifficulty, processor.CreateHitWindows(), true)
|
||||
new DefaultHitErrorDisplay(overallDifficulty, processor.CreateHitWindows(), true)
|
||||
{
|
||||
Margin = new MarginPadding { Right = margin }
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user