2017-02-07 04:59:30 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-09-23 10:29:25 +00:00
|
|
|
|
|
2016-11-08 23:13:20 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2016-09-24 01:53:58 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2016-09-23 10:29:25 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-09-24 01:53:58 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-11-08 23:13:20 +00:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2017-01-31 09:53:52 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-01-27 12:57:22 +00:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2016-09-23 10:29:25 +00:00
|
|
|
|
|
2017-01-27 12:57:22 +00:00
|
|
|
|
namespace osu.Game.Screens.Play
|
2016-09-23 10:29:25 +00:00
|
|
|
|
{
|
2016-09-24 02:19:50 +00:00
|
|
|
|
public abstract class KeyCounter : Container
|
2016-09-23 10:29:25 +00:00
|
|
|
|
{
|
2016-09-24 01:53:58 +00:00
|
|
|
|
private Sprite buttonSprite;
|
|
|
|
|
private Sprite glowSprite;
|
2016-09-24 02:19:50 +00:00
|
|
|
|
private Container textLayer;
|
2016-09-24 01:53:58 +00:00
|
|
|
|
private SpriteText countSpriteText;
|
|
|
|
|
|
2016-09-24 02:04:08 +00:00
|
|
|
|
public bool IsCounting { get; set; }
|
2017-07-11 13:58:06 +00:00
|
|
|
|
private int countPresses;
|
|
|
|
|
public int CountPresses
|
2016-09-26 06:07:43 +00:00
|
|
|
|
{
|
2017-07-11 13:58:06 +00:00
|
|
|
|
get { return countPresses; }
|
2016-09-26 06:07:43 +00:00
|
|
|
|
private set
|
|
|
|
|
{
|
2017-07-11 13:58:06 +00:00
|
|
|
|
if (countPresses != value)
|
2016-09-26 06:07:43 +00:00
|
|
|
|
{
|
2017-07-11 13:58:06 +00:00
|
|
|
|
countPresses = value;
|
2016-09-26 06:07:43 +00:00
|
|
|
|
countSpriteText.Text = value.ToString(@"#,0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-24 01:53:58 +00:00
|
|
|
|
|
|
|
|
|
private bool isLit;
|
|
|
|
|
public bool IsLit
|
|
|
|
|
{
|
|
|
|
|
get { return isLit; }
|
|
|
|
|
protected set
|
|
|
|
|
{
|
|
|
|
|
if (isLit != value)
|
|
|
|
|
{
|
|
|
|
|
isLit = value;
|
2016-09-26 06:07:43 +00:00
|
|
|
|
updateGlowSprite(value);
|
2016-09-24 02:04:08 +00:00
|
|
|
|
if (value && IsCounting)
|
2017-07-11 13:58:06 +00:00
|
|
|
|
CountPresses++;
|
2016-09-24 01:53:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 02:26:42 +00:00
|
|
|
|
//further: change default values here and in KeyCounterCollection if needed, instead of passing them in every constructor
|
2016-09-24 01:53:58 +00:00
|
|
|
|
public Color4 KeyDownTextColor { get; set; } = Color4.DarkGray;
|
|
|
|
|
public Color4 KeyUpTextColor { get; set; } = Color4.White;
|
2017-03-09 05:24:16 +00:00
|
|
|
|
public int FadeTime { get; set; }
|
2016-09-24 01:53:58 +00:00
|
|
|
|
|
|
|
|
|
protected KeyCounter(string name)
|
2016-09-23 10:29:25 +00:00
|
|
|
|
{
|
2016-09-24 01:53:58 +00:00
|
|
|
|
Name = name;
|
2016-09-23 10:29:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 10:44:16 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore textures)
|
2016-09-23 11:14:11 +00:00
|
|
|
|
{
|
2016-09-24 01:53:58 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
buttonSprite = new Sprite
|
|
|
|
|
{
|
2016-11-08 23:13:20 +00:00
|
|
|
|
Texture = textures.Get(@"KeyCounter/key-up"),
|
2016-09-24 01:53:58 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
2016-09-24 02:19:50 +00:00
|
|
|
|
glowSprite = new Sprite
|
2016-09-24 01:53:58 +00:00
|
|
|
|
{
|
2016-11-08 23:13:20 +00:00
|
|
|
|
Texture = textures.Get(@"KeyCounter/key-glow"),
|
2016-09-24 01:53:58 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-09-24 02:19:50 +00:00
|
|
|
|
Alpha = 0
|
2016-09-24 01:53:58 +00:00
|
|
|
|
},
|
2016-09-24 02:19:50 +00:00
|
|
|
|
textLayer = new Container
|
2016-09-24 01:53:58 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-10-01 09:40:14 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-09-24 02:19:50 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-01-31 09:53:52 +00:00
|
|
|
|
new OsuSpriteText
|
2016-09-24 02:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Text = Name,
|
2017-02-16 13:43:49 +00:00
|
|
|
|
Font = @"Venera",
|
|
|
|
|
TextSize = 12,
|
2016-09-24 02:19:50 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-10-01 09:40:14 +00:00
|
|
|
|
RelativePositionAxes = Axes.Both,
|
2016-09-26 08:56:39 +00:00
|
|
|
|
Position = new Vector2(0, -0.25f),
|
2016-09-24 02:19:50 +00:00
|
|
|
|
Colour = KeyUpTextColor
|
|
|
|
|
},
|
2017-01-31 09:53:52 +00:00
|
|
|
|
countSpriteText = new OsuSpriteText
|
2016-09-24 02:19:50 +00:00
|
|
|
|
{
|
2017-07-11 13:58:06 +00:00
|
|
|
|
Text = CountPresses.ToString(@"#,0"),
|
2016-09-24 02:19:50 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-10-01 09:40:14 +00:00
|
|
|
|
RelativePositionAxes = Axes.Both,
|
2016-09-26 08:56:39 +00:00
|
|
|
|
Position = new Vector2(0, 0.25f),
|
2016-09-24 02:19:50 +00:00
|
|
|
|
Colour = KeyUpTextColor
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-24 01:53:58 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2016-09-24 02:19:50 +00:00
|
|
|
|
//Set this manually because an element with Alpha=0 won't take it size to AutoSizeContainer,
|
2016-09-24 06:28:59 +00:00
|
|
|
|
//so the size can be changing between buttonSprite and glowSprite.
|
2016-10-18 16:53:31 +00:00
|
|
|
|
Height = buttonSprite.DrawHeight;
|
|
|
|
|
Width = buttonSprite.DrawWidth;
|
2016-09-23 11:14:11 +00:00
|
|
|
|
}
|
2016-09-23 10:57:19 +00:00
|
|
|
|
|
2016-09-26 06:07:43 +00:00
|
|
|
|
private void updateGlowSprite(bool show)
|
2016-09-24 01:53:58 +00:00
|
|
|
|
{
|
2016-09-26 06:07:43 +00:00
|
|
|
|
if (show)
|
2016-09-24 01:53:58 +00:00
|
|
|
|
{
|
2016-09-24 02:26:42 +00:00
|
|
|
|
glowSprite.FadeIn(FadeTime);
|
|
|
|
|
textLayer.FadeColour(KeyDownTextColor, FadeTime);
|
2016-09-24 01:53:58 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-09-26 06:07:43 +00:00
|
|
|
|
glowSprite.FadeOut(FadeTime);
|
2016-09-24 02:26:42 +00:00
|
|
|
|
textLayer.FadeColour(KeyUpTextColor, FadeTime);
|
2016-09-24 01:53:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-26 06:10:51 +00:00
|
|
|
|
|
2017-07-11 13:58:06 +00:00
|
|
|
|
public void ResetCount() => CountPresses = 0;
|
2016-09-23 10:29:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|