From 74e7cc205601bc4edb9d88e12afb8c63f8e967d2 Mon Sep 17 00:00:00 2001 From: tsrk Date: Wed, 15 Feb 2023 22:18:02 +0000 Subject: [PATCH] feat: implement new design of key counter --- .../Visual/Gameplay/TestSceneKeyCounter.cs | 39 +++++++--- osu.Game/Screens/Play/ArgonKeyCounter.cs | 76 +++++++++++++++++++ .../Screens/Play/ArgonKeyCounterDisplay.cs | 42 ++++++++++ 3 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 osu.Game/Screens/Play/ArgonKeyCounter.cs create mode 100644 osu.Game/Screens/Play/ArgonKeyCounterDisplay.cs diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneKeyCounter.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneKeyCounter.cs index 975a5c9465..41add82245 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneKeyCounter.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneKeyCounter.cs @@ -8,6 +8,7 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Utils; using osu.Game.Screens.Play; +using osuTK; using osuTK.Input; namespace osu.Game.Tests.Visual.Gameplay @@ -18,24 +19,44 @@ namespace osu.Game.Tests.Visual.Gameplay public TestSceneKeyCounter() { DefaultKeyCounter testCounter; + KeyCounterDisplay kc; + KeyCounterDisplay argonKc; - KeyCounterDisplay kc = new DefaultKeyCounterDisplay + Children = new Drawable[] { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Children = new[] + kc = new DefaultKeyCounterDisplay { - testCounter = new DefaultKeyCounter(new KeyCounterKeyboardTrigger(Key.X)), - new DefaultKeyCounter(new KeyCounterKeyboardTrigger(Key.X)), - new DefaultKeyCounter(new KeyCounterMouseTrigger(MouseButton.Left)), - new DefaultKeyCounter(new KeyCounterMouseTrigger(MouseButton.Right)), + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Position = new Vector2(0, -50), + Children = new[] + { + testCounter = new DefaultKeyCounter(new KeyCounterKeyboardTrigger(Key.X)), + new DefaultKeyCounter(new KeyCounterKeyboardTrigger(Key.X)), + new DefaultKeyCounter(new KeyCounterMouseTrigger(MouseButton.Left)), + new DefaultKeyCounter(new KeyCounterMouseTrigger(MouseButton.Right)), + }, }, + argonKc = new ArgonKeyCounterDisplay + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Position = new Vector2(0, 50), + Children = new[] + { + new ArgonKeyCounter(new KeyCounterKeyboardTrigger(Key.X)), + new ArgonKeyCounter(new KeyCounterKeyboardTrigger(Key.X)), + new ArgonKeyCounter(new KeyCounterMouseTrigger(MouseButton.Left)), + new ArgonKeyCounter(new KeyCounterMouseTrigger(MouseButton.Right)), + }, + } }; AddStep("Add random", () => { Key key = (Key)((int)Key.A + RNG.Next(26)); kc.Add(kc.CreateKeyCounter(new KeyCounterKeyboardTrigger(key))); + argonKc.Add(argonKc.CreateKeyCounter(new KeyCounterKeyboardTrigger(key))); }); Key testKey = ((KeyCounterKeyboardTrigger)kc.Children.First().Trigger).Key; @@ -52,8 +73,6 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("Disable counting", () => testCounter.IsCounting = false); addPressKeyStep(); AddAssert($"Check {testKey} count has not changed", () => testCounter.CountPresses == 2); - - Add(kc); } } } diff --git a/osu.Game/Screens/Play/ArgonKeyCounter.cs b/osu.Game/Screens/Play/ArgonKeyCounter.cs new file mode 100644 index 0000000000..a275a7e017 --- /dev/null +++ b/osu.Game/Screens/Play/ArgonKeyCounter.cs @@ -0,0 +1,76 @@ +// Copyright (c) ppy Pty Ltd . 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.Shapes; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osuTK; + +namespace osu.Game.Screens.Play +{ + public partial class ArgonKeyCounter : KeyCounter + { + private Circle inputIndicator = null!; + private OsuSpriteText countText = null!; + + // These values were taken from Figma + private const float line_height = 3; + private const float name_font_size = 10; + private const float count_font_size = 14; + + // Make things look bigger without using Scale + private const float scale_factor = 1.5f; + + public ArgonKeyCounter(InputTrigger trigger) + : base(trigger) + { + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + Children = new Drawable[] + { + inputIndicator = new Circle + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.X, + Height = line_height * scale_factor, + Alpha = 0.5f + }, + new OsuSpriteText + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Position = new Vector2(0, -13) * scale_factor, + Font = OsuFont.Torus.With(size: name_font_size * scale_factor, weight: FontWeight.Bold), + Colour = colours.Blue0, + Text = Name + }, + countText = new OsuSpriteText + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Font = OsuFont.Torus.With(size: count_font_size * scale_factor, weight: FontWeight.Bold), + Text = "0" + }, + }; + + // Values from Figma didn't match visually + // So these were just eyeballed + Height = 30 * scale_factor; + Width = 35 * scale_factor; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + IsLit.BindValueChanged(e => inputIndicator.Alpha = e.NewValue ? 1 : 0.5f, true); + PressesCount.BindValueChanged(e => countText.Text = e.NewValue.ToString(@"#,0"), true); + } + } +} diff --git a/osu.Game/Screens/Play/ArgonKeyCounterDisplay.cs b/osu.Game/Screens/Play/ArgonKeyCounterDisplay.cs new file mode 100644 index 0000000000..da34a64a4c --- /dev/null +++ b/osu.Game/Screens/Play/ArgonKeyCounterDisplay.cs @@ -0,0 +1,42 @@ +// Copyright (c) ppy Pty Ltd . 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.Graphics; +using osu.Framework.Graphics.Containers; +using osuTK; + +namespace osu.Game.Screens.Play +{ + public partial class ArgonKeyCounterDisplay : KeyCounterDisplay + { + private const int duration = 100; + + public new IReadOnlyList Children + { + get => (IReadOnlyList)base.Children; + set => base.Children = value; + } + + [BackgroundDependencyLoader] + private void load() + { + KeyFlow.Direction = FillDirection.Horizontal; + KeyFlow.AutoSizeAxes = Axes.Both; + KeyFlow.Spacing = new Vector2(2); + + InternalChildren = new[] + { + KeyFlow + }; + } + + protected override bool CheckType(KeyCounter key) => key is ArgonKeyCounter; + + protected override void UpdateVisibility() + => KeyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration); + + public override KeyCounter CreateKeyCounter(KeyCounter.InputTrigger trigger) => new ArgonKeyCounter(trigger); + } +}