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