1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 00:47:24 +08:00

feat: implement new design of key counter

This commit is contained in:
tsrk 2023-02-15 22:18:02 +00:00
parent e9dcc257b4
commit 74e7cc2056
No known key found for this signature in database
GPG Key ID: EBD46BB3049B56D6
3 changed files with 147 additions and 10 deletions

View File

@ -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,11 +19,16 @@ namespace osu.Game.Tests.Visual.Gameplay
public TestSceneKeyCounter()
{
DefaultKeyCounter testCounter;
KeyCounterDisplay kc;
KeyCounterDisplay argonKc;
KeyCounterDisplay kc = new DefaultKeyCounterDisplay
Children = new Drawable[]
{
kc = new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Position = new Vector2(0, -50),
Children = new[]
{
testCounter = new DefaultKeyCounter(new KeyCounterKeyboardTrigger(Key.X)),
@ -30,12 +36,27 @@ namespace osu.Game.Tests.Visual.Gameplay
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);
}
}
}

View File

@ -0,0 +1,76 @@
// 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.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);
}
}
}

View File

@ -0,0 +1,42 @@
// 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 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<ArgonKeyCounter> Children
{
get => (IReadOnlyList<ArgonKeyCounter>)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);
}
}