mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 10:22:56 +08:00
refactor: make KCD a CompositeDrawable
This commit is contained in:
parent
12af002c4d
commit
44297a7d0a
@ -35,14 +35,14 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
var referenceBeatmap = CreateBeatmap(new OsuRuleset().RulesetInfo);
|
||||
|
||||
AddUntilStep("score above zero", () => Player.ScoreProcessor.TotalScore.Value > 0);
|
||||
AddUntilStep("key counter counted keys", () => Player.HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses.Value > 2));
|
||||
AddUntilStep("key counter counted keys", () => Player.HUDOverlay.KeyCounter.Counters.Any(kc => kc.CountPresses.Value > 2));
|
||||
|
||||
seekTo(referenceBeatmap.Breaks[0].StartTime);
|
||||
AddAssert("keys not counting", () => !Player.HUDOverlay.KeyCounter.IsCounting.Value);
|
||||
AddAssert("overlay displays 100% accuracy", () => Player.BreakOverlay.ChildrenOfType<BreakInfo>().Single().AccuracyDisplay.Current.Value == 1);
|
||||
|
||||
AddStep("rewind", () => Player.GameplayClockContainer.Seek(-80000));
|
||||
AddUntilStep("key counter reset", () => Player.HUDOverlay.KeyCounter.Children.All(kc => kc.CountPresses.Value == 0));
|
||||
AddUntilStep("key counter reset", () => Player.HUDOverlay.KeyCounter.Counters.All(kc => kc.CountPresses.Value == 0));
|
||||
|
||||
seekTo(referenceBeatmap.HitObjects[^1].GetEndTime());
|
||||
AddUntilStep("results displayed", () => getResultsScreen()?.IsLoaded == true);
|
||||
|
@ -31,11 +31,11 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
||||
addSeekStep(3000);
|
||||
AddAssert("all judged", () => Player.DrawableRuleset.Playfield.AllHitObjects.All(h => h.Judged));
|
||||
AddUntilStep("key counter counted keys", () => Player.HUDOverlay.KeyCounter.Children.Select(kc => kc.CountPresses.Value).Sum() == 15);
|
||||
AddUntilStep("key counter counted keys", () => Player.HUDOverlay.KeyCounter.Counters.Select(kc => kc.CountPresses.Value).Sum() == 15);
|
||||
AddStep("clear results", () => Player.Results.Clear());
|
||||
addSeekStep(0);
|
||||
AddAssert("none judged", () => Player.DrawableRuleset.Playfield.AllHitObjects.All(h => !h.Judged));
|
||||
AddUntilStep("key counters reset", () => Player.HUDOverlay.KeyCounter.Children.All(kc => kc.CountPresses.Value == 0));
|
||||
AddUntilStep("key counters reset", () => Player.HUDOverlay.KeyCounter.Counters.All(kc => kc.CountPresses.Value == 0));
|
||||
AddAssert("no results triggered", () => Player.Results.Count == 0);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
new KeyCounterMouseTrigger(MouseButton.Right),
|
||||
});
|
||||
|
||||
var testCounter = (DefaultKeyCounter)kc.Children.First();
|
||||
var testCounter = (DefaultKeyCounter)kc.Counters.First();
|
||||
|
||||
AddStep("Add random", () =>
|
||||
{
|
||||
@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
kc.AddTrigger(new KeyCounterKeyboardTrigger(key));
|
||||
});
|
||||
|
||||
Key testKey = ((KeyCounterKeyboardTrigger)kc.Children.First().Trigger).Key;
|
||||
Key testKey = ((KeyCounterKeyboardTrigger)kc.Counters.First().Trigger).Key;
|
||||
|
||||
void addPressKeyStep()
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
protected override void AddCheckSteps()
|
||||
{
|
||||
AddUntilStep("score above zero", () => ((ScoreAccessibleReplayPlayer)Player).ScoreProcessor.TotalScore.Value > 0);
|
||||
AddUntilStep("key counter counted keys", () => ((ScoreAccessibleReplayPlayer)Player).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses.Value > 0));
|
||||
AddUntilStep("key counter counted keys", () => ((ScoreAccessibleReplayPlayer)Player).HUDOverlay.KeyCounter.Counters.Any(kc => kc.CountPresses.Value > 0));
|
||||
AddAssert("cannot fail", () => !((ScoreAccessibleReplayPlayer)Player).AllowFail);
|
||||
}
|
||||
|
||||
|
@ -176,14 +176,14 @@ namespace osu.Game.Rulesets.UI
|
||||
{
|
||||
}
|
||||
|
||||
public bool OnPressed(KeyBindingPressEvent<T> e) => Target.Children.Where(c => c.Trigger is KeyCounterActionTrigger<T>)
|
||||
public bool OnPressed(KeyBindingPressEvent<T> e) => Target.Counters.Where(c => c.Trigger is KeyCounterActionTrigger<T>)
|
||||
.Select(c => (KeyCounterActionTrigger<T>)c.Trigger)
|
||||
.Any(c => c.OnPressed(e.Action, Clock.Rate >= 0));
|
||||
|
||||
public void OnReleased(KeyBindingReleaseEvent<T> e)
|
||||
{
|
||||
foreach (var c
|
||||
in Target.Children.Where(c => c.Trigger is KeyCounterActionTrigger<T>).Select(c => (KeyCounterActionTrigger<T>)c.Trigger))
|
||||
in Target.Counters.Where(c => c.Trigger is KeyCounterActionTrigger<T>).Select(c => (KeyCounterActionTrigger<T>)c.Trigger))
|
||||
c.OnReleased(e.Action, Clock.Rate >= 0);
|
||||
}
|
||||
}
|
||||
|
@ -13,18 +13,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
private const int duration = 100;
|
||||
private const double key_fade_time = 80;
|
||||
|
||||
private readonly FillFlowContainer<KeyCounter> keyFlow = new FillFlowContainer<KeyCounter>();
|
||||
private readonly FillFlowContainer<DefaultKeyCounter> keyFlow = new FillFlowContainer<DefaultKeyCounter>();
|
||||
|
||||
protected override Container<KeyCounter> Content => keyFlow;
|
||||
|
||||
public new IReadOnlyList<DefaultKeyCounter> Children
|
||||
{
|
||||
get => (IReadOnlyList<DefaultKeyCounter>)base.Children;
|
||||
set => base.Children = value;
|
||||
}
|
||||
public override IEnumerable<KeyCounter> Counters => keyFlow;
|
||||
|
||||
public DefaultKeyCounterDisplay()
|
||||
: base(typeof(DefaultKeyCounter))
|
||||
{
|
||||
keyFlow.Direction = FillDirection.Horizontal;
|
||||
keyFlow.AutoSizeAxes = Axes.Both;
|
||||
@ -45,23 +38,12 @@ namespace osu.Game.Screens.Play.HUD
|
||||
public override void AddTrigger(InputTrigger trigger)
|
||||
{
|
||||
DefaultKeyCounter key = new DefaultKeyCounter(trigger);
|
||||
Add(key);
|
||||
keyFlow.Add(key);
|
||||
key.FadeTime = key_fade_time;
|
||||
key.KeyDownTextColor = KeyDownTextColor;
|
||||
key.KeyUpTextColor = KeyUpTextColor;
|
||||
}
|
||||
|
||||
public override void Add(KeyCounter key)
|
||||
{
|
||||
base.Add(key);
|
||||
|
||||
DefaultKeyCounter defaultKey = (DefaultKeyCounter)key;
|
||||
|
||||
defaultKey.FadeTime = key_fade_time;
|
||||
defaultKey.KeyDownTextColor = KeyDownTextColor;
|
||||
defaultKey.KeyUpTextColor = KeyUpTextColor;
|
||||
}
|
||||
|
||||
protected override void UpdateVisibility() =>
|
||||
// Isolate changing visibility of the key counters from fading this component.
|
||||
keyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration);
|
||||
@ -76,7 +58,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
if (value != keyDownTextColor)
|
||||
{
|
||||
keyDownTextColor = value;
|
||||
foreach (var child in Children)
|
||||
foreach (var child in keyFlow)
|
||||
child.KeyDownTextColor = value;
|
||||
}
|
||||
}
|
||||
@ -92,7 +74,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
if (value != keyUpTextColor)
|
||||
{
|
||||
keyUpTextColor = value;
|
||||
foreach (var child in Children)
|
||||
foreach (var child in keyFlow)
|
||||
child.KeyUpTextColor = value;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
/// <summary>
|
||||
/// A flowing display of all gameplay keys. Individual keys can be added using <see cref="InputTrigger"/> implementations.
|
||||
/// </summary>
|
||||
public abstract partial class KeyCounterDisplay : Container<KeyCounter>
|
||||
public abstract partial class KeyCounterDisplay : CompositeDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the key counter should be visible regardless of the configuration value.
|
||||
@ -26,6 +26,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
/// </summary>
|
||||
public Bindable<bool> AlwaysVisible { get; } = new Bindable<bool>(true);
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="KeyCounter"/>s contained in this <see cref="KeyCounterDisplay"/>.
|
||||
/// </summary>
|
||||
public abstract IEnumerable<KeyCounter> Counters { get; }
|
||||
|
||||
public Bindable<bool> IsCounting { get; } = new BindableBool(true);
|
||||
|
||||
protected readonly Bindable<bool> ConfigVisibility = new Bindable<bool>();
|
||||
@ -34,13 +39,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private Receptor? receptor;
|
||||
|
||||
private readonly Type[] acceptedTypes;
|
||||
|
||||
protected KeyCounterDisplay(params Type[] acceptedTypes)
|
||||
{
|
||||
this.acceptedTypes = acceptedTypes;
|
||||
}
|
||||
|
||||
public void SetReceptor(Receptor receptor)
|
||||
{
|
||||
if (this.receptor != null)
|
||||
@ -53,17 +51,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
public void AddTriggerRange(IEnumerable<InputTrigger> triggers) => triggers.ForEach(AddTrigger);
|
||||
|
||||
public override void Add(KeyCounter counter)
|
||||
{
|
||||
if (!checkType(counter))
|
||||
throw new InvalidOperationException($"{counter.GetType()} is not a supported counter type. (hint: you may want to use {nameof(AddTrigger)} instead.)");
|
||||
|
||||
base.Add(counter);
|
||||
counter.IsCounting.BindTo(IsCounting);
|
||||
}
|
||||
|
||||
private bool checkType(KeyCounter counter) => acceptedTypes.Length == 0 || acceptedTypes.Any(t => t.IsInstanceOfType(counter));
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user