2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2016-11-09 07:13:20 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2016-09-23 18:29:25 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-11-09 07:13:20 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2019-02-12 12:04:46 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-01-31 17:53:52 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-01-27 20:57:22 +08:00
|
|
|
|
namespace osu.Game.Screens.Play
|
2016-09-23 18:29:25 +08:00
|
|
|
|
{
|
2016-09-24 10:19:50 +08:00
|
|
|
|
public abstract class KeyCounter : Container
|
2016-09-23 18:29:25 +08:00
|
|
|
|
{
|
2016-09-24 09:53:58 +08:00
|
|
|
|
private Sprite buttonSprite;
|
|
|
|
|
private Sprite glowSprite;
|
2016-09-24 10:19:50 +08:00
|
|
|
|
private Container textLayer;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
private SpriteText countSpriteText;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-20 16:08:25 +08:00
|
|
|
|
public bool IsCounting { get; set; } = true;
|
2017-07-11 21:58:06 +08:00
|
|
|
|
private int countPresses;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2017-07-11 21:58:06 +08:00
|
|
|
|
public int CountPresses
|
2016-09-26 14:07:43 +08:00
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => countPresses;
|
2016-09-26 14:07:43 +08:00
|
|
|
|
private set
|
|
|
|
|
{
|
2017-07-11 21:58:06 +08:00
|
|
|
|
if (countPresses != value)
|
2016-09-26 14:07:43 +08:00
|
|
|
|
{
|
2017-07-11 21:58:06 +08:00
|
|
|
|
countPresses = value;
|
2016-09-26 14:07:43 +08:00
|
|
|
|
countSpriteText.Text = value.ToString(@"#,0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-09-24 09:53:58 +08:00
|
|
|
|
private bool isLit;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2016-09-24 09:53:58 +08:00
|
|
|
|
public bool IsLit
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => isLit;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
protected set
|
|
|
|
|
{
|
|
|
|
|
if (isLit != value)
|
|
|
|
|
{
|
|
|
|
|
isLit = value;
|
2016-09-26 14:07:43 +08:00
|
|
|
|
updateGlowSprite(value);
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-09-12 14:41:53 +08:00
|
|
|
|
public void Increment()
|
|
|
|
|
{
|
|
|
|
|
if (!IsCounting)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CountPresses++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Decrement()
|
|
|
|
|
{
|
|
|
|
|
if (!IsCounting)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CountPresses--;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 10:26:42 +08:00
|
|
|
|
//further: change default values here and in KeyCounterCollection if needed, instead of passing them in every constructor
|
2016-09-24 09:53:58 +08:00
|
|
|
|
public Color4 KeyDownTextColor { get; set; } = Color4.DarkGray;
|
|
|
|
|
public Color4 KeyUpTextColor { get; set; } = Color4.White;
|
2019-09-12 13:27:29 +08:00
|
|
|
|
public double FadeTime { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-09-24 09:53:58 +08:00
|
|
|
|
protected KeyCounter(string name)
|
2016-09-23 18:29:25 +08:00
|
|
|
|
{
|
2016-09-24 09:53:58 +08:00
|
|
|
|
Name = name;
|
2016-09-23 18:29:25 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-05 12:26:54 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2019-09-12 14:48:07 +08:00
|
|
|
|
private void load(TextureStore textures)
|
2016-09-23 19:14:11 +08:00
|
|
|
|
{
|
2016-09-24 09:53:58 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
buttonSprite = new Sprite
|
|
|
|
|
{
|
2016-11-09 07:13:20 +08:00
|
|
|
|
Texture = textures.Get(@"KeyCounter/key-up"),
|
2016-09-24 09:53:58 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
2016-09-24 10:19:50 +08:00
|
|
|
|
glowSprite = new Sprite
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
2016-11-09 07:13:20 +08:00
|
|
|
|
Texture = textures.Get(@"KeyCounter/key-glow"),
|
2016-09-24 09:53:58 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-09-24 10:19:50 +08:00
|
|
|
|
Alpha = 0
|
2016-09-24 09:53:58 +08:00
|
|
|
|
},
|
2016-09-24 10:19:50 +08:00
|
|
|
|
textLayer = new Container
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-10-01 17:40:14 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-09-24 10:19:50 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-01-31 17:53:52 +08:00
|
|
|
|
new OsuSpriteText
|
2016-09-24 10:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Text = Name,
|
2019-02-22 18:42:09 +08:00
|
|
|
|
Font = OsuFont.Numeric.With(size: 12),
|
2016-09-24 10:19:50 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-10-01 17:40:14 +08:00
|
|
|
|
RelativePositionAxes = Axes.Both,
|
2016-09-26 16:56:39 +08:00
|
|
|
|
Position = new Vector2(0, -0.25f),
|
2016-09-24 10:19:50 +08:00
|
|
|
|
Colour = KeyUpTextColor
|
|
|
|
|
},
|
2017-01-31 17:53:52 +08:00
|
|
|
|
countSpriteText = new OsuSpriteText
|
2016-09-24 10:19:50 +08:00
|
|
|
|
{
|
2017-07-11 21:58:06 +08:00
|
|
|
|
Text = CountPresses.ToString(@"#,0"),
|
2016-09-24 10:19:50 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-10-01 17:40:14 +08:00
|
|
|
|
RelativePositionAxes = Axes.Both,
|
2016-09-26 16:56:39 +08:00
|
|
|
|
Position = new Vector2(0, 0.25f),
|
2016-09-24 10:19:50 +08:00
|
|
|
|
Colour = KeyUpTextColor
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// Set this manually because an element with Alpha=0 won't take it size to AutoSizeContainer,
|
|
|
|
|
// so the size can be changing between buttonSprite and glowSprite.
|
2016-10-19 00:53:31 +08:00
|
|
|
|
Height = buttonSprite.DrawHeight;
|
|
|
|
|
Width = buttonSprite.DrawWidth;
|
2016-09-23 19:14:11 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-09-26 14:07:43 +08:00
|
|
|
|
private void updateGlowSprite(bool show)
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
2016-09-26 14:07:43 +08:00
|
|
|
|
if (show)
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
2019-09-12 13:27:29 +08:00
|
|
|
|
double remainingFadeTime = FadeTime * (1 - glowSprite.Alpha);
|
|
|
|
|
glowSprite.FadeIn(remainingFadeTime, Easing.OutQuint);
|
|
|
|
|
textLayer.FadeColour(KeyDownTextColor, remainingFadeTime, Easing.OutQuint);
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-12 13:27:29 +08:00
|
|
|
|
double remainingFadeTime = 8 * FadeTime * glowSprite.Alpha;
|
|
|
|
|
glowSprite.FadeOut(remainingFadeTime, Easing.OutQuint);
|
|
|
|
|
textLayer.FadeColour(KeyUpTextColor, remainingFadeTime, Easing.OutQuint);
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-23 18:29:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|