1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 12:37:47 +08:00
osu-lazer/osu.Game/Skinning/LegacyKeyCounter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.3 KiB
C#
Raw Normal View History

2024-07-23 19:05:14 +08:00
// 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;
2024-07-23 19:05:14 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
2024-07-23 19:05:14 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
2024-07-23 19:05:14 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Play.HUD;
namespace osu.Game.Skinning
{
public partial class LegacyKeyCounter : KeyCounter
{
private const float transition_duration = 160;
2024-07-23 19:05:14 +08:00
public Colour4 ActiveColour { get; set; }
2024-07-23 19:05:14 +08:00
private Colour4 textColour;
public Colour4 TextColour
2024-07-23 23:35:25 +08:00
{
get => textColour;
2024-07-23 23:35:25 +08:00
set
{
textColour = value;
2024-07-23 23:35:25 +08:00
overlayKeyText.Colour = value;
}
}
2024-07-23 19:05:14 +08:00
2024-07-24 12:57:30 +08:00
private readonly Container keyContainer;
private readonly OsuSpriteText overlayKeyText;
private readonly Sprite keySprite;
2024-07-23 19:05:14 +08:00
public LegacyKeyCounter(InputTrigger trigger)
: base(trigger)
{
Origin = Anchor.Centre;
Anchor = Anchor.Centre;
Child = keyContainer = new Container
{
AutoSizeAxes = Axes.Both,
2024-07-23 19:05:14 +08:00
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new Drawable[]
{
keySprite = new Sprite
2024-07-23 19:05:14 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
new UprightAspectMaintainingContainer
2024-07-23 19:05:14 +08:00
{
AutoSizeAxes = Axes.Both,
2024-07-23 19:05:14 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Child = overlayKeyText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = trigger.Name,
Colour = textColour,
2024-08-06 14:17:43 +08:00
Font = OsuFont.GetFont(weight: FontWeight.SemiBold),
},
2024-07-23 19:05:14 +08:00
},
}
};
// matches longest dimension of default skin asset
Height = Width = 46;
2024-07-23 19:05:14 +08:00
}
[BackgroundDependencyLoader]
private void load(ISkinSource source)
{
2024-07-24 12:57:30 +08:00
Texture? keyTexture = source.GetTexture(@"inputoverlay-key");
if (keyTexture != null)
keySprite.Texture = keyTexture;
}
2024-07-23 19:05:14 +08:00
protected override void Activate(bool forwardPlayback = true)
{
base.Activate(forwardPlayback);
keyContainer.ScaleTo(0.75f, transition_duration, Easing.Out);
keySprite.Colour = ActiveColour;
2024-07-23 19:05:14 +08:00
overlayKeyText.Text = CountPresses.Value.ToString();
2024-08-06 14:17:43 +08:00
overlayKeyText.Font = overlayKeyText.Font.With(weight: FontWeight.SemiBold);
2024-07-23 19:05:14 +08:00
}
protected override void Deactivate(bool forwardPlayback = true)
{
base.Deactivate(forwardPlayback);
keyContainer.ScaleTo(1f, transition_duration, Easing.Out);
keySprite.Colour = Colour4.White;
2024-07-23 19:05:14 +08:00
}
}
}