mirror of https://github.com/ppy/osu
Simplify event propagation
This commit is contained in:
parent
bdbfa7bd2f
commit
6640161bc1
|
@ -38,7 +38,7 @@ public class BarHitErrorMeter : HitErrorMeter
|
||||||
private readonly List<double> judgementOffsets = new List<double>();
|
private readonly List<double> judgementOffsets = new List<double>();
|
||||||
private readonly double maxHitWindows;
|
private readonly double maxHitWindows;
|
||||||
|
|
||||||
public BarHitErrorMeter(HitWindows hitWindows, bool reversed = false)
|
public BarHitErrorMeter(HitWindows hitWindows, bool rightAligned = false)
|
||||||
: base(hitWindows)
|
: base(hitWindows)
|
||||||
{
|
{
|
||||||
maxHitWindows = HitWindows.Meh == 0 ? HitWindows.Good : HitWindows.Meh;
|
maxHitWindows = HitWindows.Meh == 0 ? HitWindows.Good : HitWindows.Meh;
|
||||||
|
@ -54,23 +54,23 @@ public BarHitErrorMeter(HitWindows hitWindows, bool reversed = false)
|
||||||
{
|
{
|
||||||
judgementsContainer = new Container
|
judgementsContainer = new Container
|
||||||
{
|
{
|
||||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||||
Width = judgement_line_width,
|
Width = judgement_line_width,
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
},
|
},
|
||||||
bar = new FillFlowContainer<Box>
|
bar = new FillFlowContainer<Box>
|
||||||
{
|
{
|
||||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||||
Width = bar_width,
|
Width = bar_width,
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||||
AutoSizeAxes = Axes.X,
|
AutoSizeAxes = Axes.X,
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Child = arrow = new SpriteIcon
|
Child = arrow = new SpriteIcon
|
||||||
|
@ -78,7 +78,7 @@ public BarHitErrorMeter(HitWindows hitWindows, bool reversed = false)
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
RelativePositionAxes = Axes.Y,
|
RelativePositionAxes = Axes.Y,
|
||||||
Icon = reversed ? FontAwesome.Solid.ChevronRight : FontAwesome.Solid.ChevronLeft,
|
Icon = rightAligned ? FontAwesome.Solid.ChevronRight : FontAwesome.Solid.ChevronLeft,
|
||||||
Size = new Vector2(8),
|
Size = new Vector2(8),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Rulesets.Judgements;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.HitErrorDisplay
|
namespace osu.Game.Screens.Play.HitErrorDisplay
|
||||||
|
@ -19,25 +22,33 @@ public class HitErrorDisplay : Container<HitErrorMeter>
|
||||||
|
|
||||||
private readonly Bindable<ScoreMeterType> type = new Bindable<ScoreMeterType>();
|
private readonly Bindable<ScoreMeterType> type = new Bindable<ScoreMeterType>();
|
||||||
|
|
||||||
private readonly HitWindows hitWindows;
|
private HitWindows hitWindows;
|
||||||
|
|
||||||
private readonly ScoreProcessor processor;
|
private readonly ScoreProcessor processor;
|
||||||
|
|
||||||
private BarHitErrorMeter leftMeter;
|
|
||||||
|
|
||||||
private BarHitErrorMeter rightMeter;
|
|
||||||
|
|
||||||
public HitErrorDisplay(ScoreProcessor processor)
|
public HitErrorDisplay(ScoreProcessor processor)
|
||||||
{
|
{
|
||||||
this.processor = processor;
|
this.processor = processor;
|
||||||
hitWindows = processor.CreateHitWindows();
|
processor.NewJudgement += onNewJudgement;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
processor.NewJudgement -= onNewJudgement;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onNewJudgement(JudgementResult result)
|
||||||
|
{
|
||||||
|
foreach (var c in Children)
|
||||||
|
c.OnNewJudgement(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config, Bindable<WorkingBeatmap> workingBeatmap)
|
private void load(OsuConfigManager config, Bindable<WorkingBeatmap> workingBeatmap)
|
||||||
{
|
{
|
||||||
config.BindWith(OsuSetting.ScoreMeter, type);
|
config.BindWith(OsuSetting.ScoreMeter, type);
|
||||||
hitWindows.SetDifficulty(workingBeatmap.Value.BeatmapInfo.BaseDifficulty.OverallDifficulty);
|
hitWindows = workingBeatmap.Value.Beatmap.HitObjects.First().HitWindows;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -48,82 +59,37 @@ protected override void LoadComplete()
|
||||||
|
|
||||||
private void typeChanged(ValueChangedEvent<ScoreMeterType> type)
|
private void typeChanged(ValueChangedEvent<ScoreMeterType> type)
|
||||||
{
|
{
|
||||||
|
Children.ForEach(c => c.FadeOut(fade_duration, Easing.OutQuint));
|
||||||
|
|
||||||
switch (type.NewValue)
|
switch (type.NewValue)
|
||||||
{
|
{
|
||||||
case ScoreMeterType.None:
|
|
||||||
removeLeftDisplay();
|
|
||||||
removeRightDisplay();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ScoreMeterType.HitErrorBoth:
|
case ScoreMeterType.HitErrorBoth:
|
||||||
addLeftDisplay();
|
createBar(false);
|
||||||
addRightDisplay();
|
createBar(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ScoreMeterType.HitErrorLeft:
|
case ScoreMeterType.HitErrorLeft:
|
||||||
addLeftDisplay();
|
createBar(false);
|
||||||
removeRightDisplay();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ScoreMeterType.HitErrorRight:
|
case ScoreMeterType.HitErrorRight:
|
||||||
addRightDisplay();
|
createBar(true);
|
||||||
removeLeftDisplay();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLeftDisplay()
|
private void createBar(bool rightAligned)
|
||||||
{
|
{
|
||||||
if (leftMeter != null)
|
var display = new BarHitErrorMeter(hitWindows, rightAligned)
|
||||||
return;
|
|
||||||
|
|
||||||
leftMeter = createNew();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addRightDisplay()
|
|
||||||
{
|
|
||||||
if (rightMeter != null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
rightMeter = createNew(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeRightDisplay()
|
|
||||||
{
|
|
||||||
if (rightMeter == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
processor.NewJudgement -= rightMeter.OnNewJudgement;
|
|
||||||
|
|
||||||
rightMeter.FadeOut(fade_duration, Easing.OutQuint).Expire();
|
|
||||||
rightMeter = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeLeftDisplay()
|
|
||||||
{
|
|
||||||
if (leftMeter == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
processor.NewJudgement -= leftMeter.OnNewJudgement;
|
|
||||||
|
|
||||||
leftMeter.FadeOut(fade_duration, Easing.OutQuint).Expire();
|
|
||||||
leftMeter = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BarHitErrorMeter createNew(bool reversed = false)
|
|
||||||
{
|
|
||||||
var display = new BarHitErrorMeter(hitWindows, reversed)
|
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding(margin),
|
Margin = new MarginPadding(margin),
|
||||||
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||||
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
|
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
processor.NewJudgement += display.OnNewJudgement;
|
|
||||||
Add(display);
|
Add(display);
|
||||||
display.FadeInFromZero(fade_duration, Easing.OutQuint);
|
display.FadeInFromZero(fade_duration, Easing.OutQuint);
|
||||||
return display;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue