Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce common structure for key counters #22654

Merged
merged 41 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
74a58fb
refactor: separate things in KeyCounter
ItsShamed Feb 13, 2023
11d0e18
refactor: separate impl of KeyCounterDisplay
ItsShamed Feb 13, 2023
aa2e002
refactor: hide trigger presence from content
ItsShamed Feb 13, 2023
157bba7
refactor: rename `Trigger` class to `InputTrigger`
ItsShamed Feb 13, 2023
df06338
fix(KeyCounter): don't override Handle
ItsShamed Feb 13, 2023
a644fae
style(KeyCounter): rename `(Un)lit` methods to `(Un)light`
ItsShamed Feb 13, 2023
076eb81
refactor: rename trigger classes
ItsShamed Feb 13, 2023
b0a2e69
style: nullable pass on `KeyCounterDisplay`
ItsShamed Feb 15, 2023
e9dcc25
reafactor: simplify type checking
ItsShamed Feb 15, 2023
6340730
refactor(KeyCounter): remove circularity
ItsShamed Feb 16, 2023
ddd6c1a
refactor(KeyCounter): address bindables issues
ItsShamed Feb 16, 2023
c61fac5
style(KeyCounter): rename methods and arguments
ItsShamed Feb 16, 2023
e3ca751
refactor: make `FillFlowContainer` read-only
ItsShamed Feb 16, 2023
6193aee
fix(TestSceneOsuTouchInput): missing Value call
ItsShamed Feb 17, 2023
d0e8d65
style(KeyCounter): rename `IsLit` to `IsActive`
ItsShamed Feb 17, 2023
c94e647
style(KeyCounterDisplay): remove type check
ItsShamed Feb 17, 2023
8830e06
fix: compilation
ItsShamed Feb 17, 2023
5bec2d7
style(KeyCounter): `forwardPlayback`
ItsShamed Feb 21, 2023
42a5a06
style(KeyCounter): fields and methods visiblity
ItsShamed Feb 21, 2023
1beec71
refactor(KeyCounterDisplay): apply suggestions
ItsShamed Feb 22, 2023
8c94b77
refactor(InputTrigger): move out of KCD
ItsShamed Feb 22, 2023
6307b39
style: use Trigger initialisation
ItsShamed Feb 22, 2023
8f6df5e
Merge branch 'master' into gameplay/key-counter-abstraction
peppy Mar 7, 2023
15d6505
Tidy up `Add` method logic
peppy Mar 7, 2023
2852041
Move `KeyCounter` components to `HUD` namespace
peppy Mar 7, 2023
97ba236
Add basic xmldoc to `KeyCounter` classes
peppy Mar 7, 2023
6a7c4d0
Remove `NRT` disables in new classes
peppy Mar 7, 2023
f711915
Remove unused using directive
bdach Mar 7, 2023
98f40b2
Improve documentation of `InputTrigger`
bdach Mar 7, 2023
12af002
Reorder and add xmldoc to `KeyCounter` members
bdach Mar 7, 2023
44297a7
refactor: make KCD a `CompositeDrawable`
ItsShamed Mar 8, 2023
5b0db94
docs: add XMLDoc for methods in KCD
ItsShamed Mar 8, 2023
5d15426
refactor: make `Counters` return a `Container`
ItsShamed Mar 8, 2023
d806b85
revert: make `counters` an `IEnumerable` again
ItsShamed Mar 8, 2023
8908648
Fix super-dodgy cast of `IEnumerable` to `Drawable`
peppy Mar 15, 2023
9e444af
Use object initialisers and fix order of initialisation vs add
peppy Mar 15, 2023
5f9b13a
Rename `Add`/`AddRange` methods as they are no longer conflicting wit…
peppy Mar 15, 2023
b0c09df
Merge branch 'master' into gameplay/key-counter-abstraction
peppy Apr 3, 2023
6239789
Fix missing using statements in multiple test scenes
peppy Apr 3, 2023
432f698
Merge branch 'master' into gameplay/key-counter-abstraction
bdach Apr 5, 2023
e5d57a6
Fix incorrect indent
bdach Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions osu.Game.Rulesets.Osu.Tests/TestSceneOsuTouchInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Tests.Visual;
using osuTK;
using osuTK.Graphics;
Expand All @@ -34,9 +34,9 @@ public partial class TestSceneOsuTouchInput : OsuManualInputManagerTestScene
[Resolved]
private OsuConfigManager config { get; set; } = null!;

private TestActionKeyCounter leftKeyCounter = null!;
private DefaultKeyCounter leftKeyCounter = null!;

private TestActionKeyCounter rightKeyCounter = null!;
private DefaultKeyCounter rightKeyCounter = null!;

private OsuInputManager osuInputManager = null!;

Expand All @@ -59,14 +59,14 @@ public void SetUpSteps()
Origin = Anchor.Centre,
Children = new Drawable[]
{
leftKeyCounter = new TestActionKeyCounter(OsuAction.LeftButton)
leftKeyCounter = new DefaultKeyCounter(new TestActionKeyCounterTrigger(OsuAction.LeftButton))
{
Anchor = Anchor.Centre,
Origin = Anchor.CentreRight,
Depth = float.MinValue,
X = -100,
},
rightKeyCounter = new TestActionKeyCounter(OsuAction.RightButton)
rightKeyCounter = new DefaultKeyCounter(new TestActionKeyCounterTrigger(OsuAction.RightButton))
{
Anchor = Anchor.Centre,
Origin = Anchor.CentreLeft,
Expand Down Expand Up @@ -562,8 +562,8 @@ private void checkPosition(TouchSource touchSource) =>

private void assertKeyCounter(int left, int right)
{
AddAssert($"The left key was pressed {left} times", () => leftKeyCounter.CountPresses, () => Is.EqualTo(left));
AddAssert($"The right key was pressed {right} times", () => rightKeyCounter.CountPresses, () => Is.EqualTo(right));
AddAssert($"The left key was pressed {left} times", () => leftKeyCounter.CountPresses.Value, () => Is.EqualTo(left));
AddAssert($"The right key was pressed {right} times", () => rightKeyCounter.CountPresses.Value, () => Is.EqualTo(right));
}

private void releaseAllTouches()
Expand All @@ -579,11 +579,11 @@ private void releaseAllTouches()
private void checkNotPressed(OsuAction action) => AddAssert($"Not pressing {action}", () => !osuInputManager.PressedActions.Contains(action));
private void checkPressed(OsuAction action) => AddAssert($"Is pressing {action}", () => osuInputManager.PressedActions.Contains(action));

public partial class TestActionKeyCounter : KeyCounter, IKeyBindingHandler<OsuAction>
public partial class TestActionKeyCounterTrigger : InputTrigger, IKeyBindingHandler<OsuAction>
{
public OsuAction Action { get; }

public TestActionKeyCounter(OsuAction action)
public TestActionKeyCounterTrigger(OsuAction action)
: base(action.ToString())
{
Action = action;
Expand All @@ -593,16 +593,16 @@ public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
{
if (e.Action == Action)
{
IsLit = true;
Increment();
Activate();
}

return false;
}

public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
{
if (e.Action == Action) IsLit = false;
if (e.Action == Action)
Deactivate();
}
}

Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Tests/Visual/Gameplay/TestSceneAutoplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ protected override void AddCheckSteps()
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 > 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);
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 == 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);
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Tests/Visual/Gameplay/TestSceneGameplayRewinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public void TestNoJudgementsOnRewind()
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).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 == 0));
AddUntilStep("key counters reset", () => Player.HUDOverlay.KeyCounter.Counters.All(kc => kc.CountPresses.Value == 0));
AddAssert("no results triggered", () => Player.Results.Count == 0);
}

Expand Down
5 changes: 2 additions & 3 deletions osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Configuration;
Expand Down Expand Up @@ -45,7 +44,7 @@ public partial class TestSceneHUDOverlay : OsuManualInputManagerTestScene

// best way to check without exposing.
private Drawable hideTarget => hudOverlay.KeyCounter;
private FillFlowContainer<KeyCounter> keyCounterFlow => hudOverlay.KeyCounter.ChildrenOfType<FillFlowContainer<KeyCounter>>().First();
private Drawable keyCounterFlow => hudOverlay.KeyCounter.ChildrenOfType<FillFlowContainer<DefaultKeyCounter>>().Single();

[BackgroundDependencyLoader]
private void load()
Expand Down Expand Up @@ -267,7 +266,7 @@ private void createNew(Action<HUDOverlay>? action = null)
hudOverlay = new HUDOverlay(null, Array.Empty<Mod>());

// Add any key just to display the key counter visually.
hudOverlay.KeyCounter.Add(new KeyCounterKeyboard(Key.Space));
hudOverlay.KeyCounter.Add(new KeyCounterKeyboardTrigger(Key.Space));

scoreProcessor.Combo.Value = 1;

Expand Down
35 changes: 18 additions & 17 deletions osu.Game.Tests/Visual/Gameplay/TestSceneKeyCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osuTK.Input;

namespace osu.Game.Tests.Visual.Gameplay
Expand All @@ -17,41 +17,42 @@ public partial class TestSceneKeyCounter : OsuManualInputManagerTestScene
{
public TestSceneKeyCounter()
{
KeyCounterKeyboard testCounter;

KeyCounterDisplay kc = new KeyCounterDisplay
KeyCounterDisplay kc = new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new KeyCounter[]
{
testCounter = new KeyCounterKeyboard(Key.X),
new KeyCounterKeyboard(Key.X),
new KeyCounterMouse(MouseButton.Left),
new KeyCounterMouse(MouseButton.Right),
},
};

kc.AddRange(new InputTrigger[]
{
new KeyCounterKeyboardTrigger(Key.X),
new KeyCounterKeyboardTrigger(Key.X),
new KeyCounterMouseTrigger(MouseButton.Left),
new KeyCounterMouseTrigger(MouseButton.Right),
});

var testCounter = (DefaultKeyCounter)kc.Counters.First();

AddStep("Add random", () =>
{
Key key = (Key)((int)Key.A + RNG.Next(26));
kc.Add(new KeyCounterKeyboard(key));
kc.Add(new KeyCounterKeyboardTrigger(key));
});

Key testKey = ((KeyCounterKeyboard)kc.Children.First()).Key;
Key testKey = ((KeyCounterKeyboardTrigger)kc.Counters.First().Trigger).Key;

void addPressKeyStep()
{
AddStep($"Press {testKey} key", () => InputManager.Key(testKey));
}

addPressKeyStep();
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses == 1);
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 1);
addPressKeyStep();
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses == 2);
AddStep("Disable counting", () => testCounter.IsCounting = false);
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 2);
AddStep("Disable counting", () => testCounter.IsCounting.Value = false);
addPressKeyStep();
AddAssert($"Check {testKey} count has not changed", () => testCounter.CountPresses == 2);
AddAssert($"Check {testKey} count has not changed", () => testCounter.CountPresses.Value == 2);

Add(kc);
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Tests/Visual/Gameplay/TestSceneReplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override Player CreatePlayer(Ruleset ruleset)
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 > 0));
AddUntilStep("key counter counted keys", () => ((ScoreAccessibleReplayPlayer)Player).HUDOverlay.KeyCounter.Counters.Any(kc => kc.CountPresses.Value > 0));
AddAssert("cannot fail", () => !((ScoreAccessibleReplayPlayer)Player).AllowFail);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Tests.Gameplay;
using osuTK.Input;

Expand Down Expand Up @@ -57,7 +58,7 @@ public void SetUpSteps()
};

// Add any key just to display the key counter visually.
hudOverlay.KeyCounter.Add(new KeyCounterKeyboard(Key.Space));
hudOverlay.KeyCounter.Add(new KeyCounterKeyboardTrigger(Key.Space));
scoreProcessor.Combo.Value = 1;

return new Container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Tests.Gameplay;
using osuTK.Input;

Expand All @@ -43,7 +42,7 @@ public partial class TestSceneSkinnableHUDOverlay : SkinnableTestScene

// best way to check without exposing.
private Drawable hideTarget => hudOverlay.KeyCounter;
private FillFlowContainer<KeyCounter> keyCounterFlow => hudOverlay.KeyCounter.ChildrenOfType<FillFlowContainer<KeyCounter>>().First();
private Drawable keyCounterFlow => hudOverlay.KeyCounter.ChildrenOfType<FillFlowContainer<DefaultKeyCounter>>().Single();

[Test]
public void TestComboCounterIncrementing()
Expand Down Expand Up @@ -88,7 +87,7 @@ private void createNew(Action<HUDOverlay> action = null)
hudOverlay = new HUDOverlay(null, Array.Empty<Mod>());

// Add any key just to display the key counter visually.
hudOverlay.KeyCounter.Add(new KeyCounterKeyboard(Key.Space));
hudOverlay.KeyCounter.Add(new KeyCounterKeyboardTrigger(Key.Space));

action?.Invoke(hudOverlay);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using osu.Game.Input.Bindings;
using osu.Game.Overlays.Settings.Sections.Input;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Select;
using osu.Game.Tests.Beatmaps.IO;
using osuTK.Input;
Expand Down Expand Up @@ -69,10 +70,10 @@ public void TestGameplayKeyBindings()
AddUntilStep("wait for gameplay", () => player?.IsBreakTime.Value == false);

AddStep("press 'z'", () => InputManager.Key(Key.Z));
AddAssert("key counter didn't increase", () => keyCounter.CountPresses == 0);
AddAssert("key counter didn't increase", () => keyCounter.CountPresses.Value == 0);

AddStep("press 's'", () => InputManager.Key(Key.S));
AddAssert("key counter did increase", () => keyCounter.CountPresses == 1);
AddAssert("key counter did increase", () => keyCounter.CountPresses.Value == 1);
}

private KeyBindingsSubsection osuBindingSubsection => keyBindingPanel
Expand Down
1 change: 1 addition & 0 deletions osu.Game/Rulesets/UI/DrawableRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Play.HUD.ClicksPerSecond;
using osuTK;

Expand Down
17 changes: 10 additions & 7 deletions osu.Game/Rulesets/UI/RulesetInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using osu.Game.Input.Bindings;
using osu.Game.Input.Handlers;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Play.HUD.ClicksPerSecond;
using static osu.Game.Input.Handlers.ReplayInputHandler;

Expand Down Expand Up @@ -163,10 +163,10 @@ public void Attach(KeyCounterDisplay keyCounter)

keyCounter.SetReceptor(receptor);
keyCounter.AddRange(KeyBindingContainer.DefaultKeyBindings
.Select(b => b.GetAction<T>())
.Distinct()
.OrderBy(action => action)
.Select(action => new KeyCounterAction<T>(action)));
.Select(b => b.GetAction<T>())
.Distinct()
.OrderBy(action => action)
.Select(action => new KeyCounterActionTrigger<T>(action)));
}

private partial class ActionReceptor : KeyCounterDisplay.Receptor, IKeyBindingHandler<T>
Expand All @@ -176,11 +176,14 @@ public ActionReceptor(KeyCounterDisplay target)
{
}

public bool OnPressed(KeyBindingPressEvent<T> e) => Target.Children.OfType<KeyCounterAction<T>>().Any(c => c.OnPressed(e.Action, Clock.Rate >= 0));
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.OfType<KeyCounterAction<T>>())
foreach (var c
in Target.Counters.Where(c => c.Trigger is KeyCounterActionTrigger<T>).Select(c => (KeyCounterActionTrigger<T>)c.Trigger))
c.OnReleased(e.Action, Clock.Rate >= 0);
}
}
Expand Down
Loading