1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 00:43:21 +08:00

Merge pull request #25349 from Joehuu/argon-key-counter-upright

Keep `ArgonKeyCounterDisplay` text upright
This commit is contained in:
Bartłomiej Dach 2023-11-06 09:19:49 +01:00 committed by GitHub
commit 5ef8500d2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 110 additions and 21 deletions

View File

@ -31,19 +31,66 @@ namespace osu.Game.Tests.Visual.Gameplay
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(72.7f),
Children = new KeyCounterDisplay[]
Spacing = new Vector2(20),
Children = new Drawable[]
{
new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
},
new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Scale = new Vector2(1, -1)
},
new ArgonKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
},
new ArgonKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
}
Scale = new Vector2(1, -1)
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Spacing = new Vector2(20),
Children = new Drawable[]
{
new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Rotation = -90,
},
new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Rotation = 90,
},
new ArgonKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Rotation = -90,
},
new ArgonKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Rotation = 90,
},
}
},
}
}
};
@ -77,8 +124,15 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("Disable counting", () => controller.IsCounting.Value = false);
addPressKeyStep();
AddAssert($"Check {testKey} count has not changed", () => testTrigger.ActivationCount.Value == 2);
AddStep("Enable counting", () => controller.IsCounting.Value = true);
addPressKeyStep(100);
addPressKeyStep(1000);
void addPressKeyStep() => AddStep($"Press {testKey} key", () => InputManager.Key(testKey));
void addPressKeyStep(int repeat = 1) => AddStep($"Press {testKey} key {repeat} times", () =>
{
for (int i = 0; i < repeat; i++)
InputManager.Key(testKey);
});
}
}
}

View File

@ -1,13 +1,15 @@
// 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;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Play.HUD;
using osuTK;
namespace osu.Game.Screens.Play
{
@ -17,6 +19,8 @@ namespace osu.Game.Screens.Play
private OsuSpriteText keyNameText = null!;
private OsuSpriteText countText = null!;
private UprightAspectMaintainingContainer uprightContainer = null!;
// These values were taken from Figma
private const float line_height = 3;
private const float name_font_size = 10;
@ -25,6 +29,8 @@ namespace osu.Game.Screens.Play
// Make things look bigger without using Scale
private const float scale_factor = 1.5f;
private const float indicator_press_offset = 4;
[Resolved]
private OsuColour colours { get; set; } = null!;
@ -40,26 +46,40 @@ namespace osu.Game.Screens.Play
{
inputIndicator = new Circle
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
Height = line_height * scale_factor,
Alpha = 0.5f
},
keyNameText = new OsuSpriteText
new Container
{
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 = Trigger.Name
},
countText = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Font = OsuFont.Torus.With(size: count_font_size * scale_factor, weight: FontWeight.Bold),
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = line_height * scale_factor + indicator_press_offset },
Children = new Drawable[]
{
uprightContainer = new UprightAspectMaintainingContainer
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
keyNameText = new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Font = OsuFont.Torus.With(size: name_font_size * scale_factor, weight: FontWeight.Bold),
Colour = colours.Blue0,
Text = Trigger.Name
},
countText = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Font = OsuFont.Torus.With(size: count_font_size * scale_factor, weight: FontWeight.Bold),
},
}
}
}
},
};
@ -76,6 +96,21 @@ namespace osu.Game.Screens.Play
CountPresses.BindValueChanged(e => countText.Text = e.NewValue.ToString(@"#,0"), true);
}
protected override void Update()
{
base.Update();
const float allowance = 6;
float absRotation = Math.Abs(uprightContainer.Rotation) % 180;
bool isRotated = absRotation > allowance && absRotation < (180 - allowance);
keyNameText.Anchor =
keyNameText.Origin = isRotated ? Anchor.TopCentre : Anchor.TopLeft;
countText.Anchor =
countText.Origin = isRotated ? Anchor.BottomCentre : Anchor.BottomLeft;
}
protected override void Activate(bool forwardPlayback = true)
{
base.Activate(forwardPlayback);
@ -87,7 +122,7 @@ namespace osu.Game.Screens.Play
.FadeIn(10, Easing.OutQuint)
.MoveToY(0)
.Then()
.MoveToY(4, 60, Easing.OutQuint);
.MoveToY(indicator_press_offset, 60, Easing.OutQuint);
}
protected override void Deactivate(bool forwardPlayback = true)