2016-09-23 18:29:25 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2016-09-23 18:57:19 +08:00
|
|
|
|
using OpenTK;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
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-09-23 18:29:25 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2016-09-24 09:53:58 +08:00
|
|
|
|
public abstract class KeyCounter : AutoSizeContainer
|
2016-09-23 18:29:25 +08:00
|
|
|
|
{
|
2016-09-24 09:53:58 +08:00
|
|
|
|
private Sprite buttonSprite;
|
|
|
|
|
private Sprite glowSprite;
|
|
|
|
|
private SpriteText keySpriteText;
|
|
|
|
|
private SpriteText countSpriteText;
|
|
|
|
|
|
|
|
|
|
public override string Name { get; }
|
|
|
|
|
public KeyCounterCollection ParentCounter { get; set; }
|
|
|
|
|
public int Count { get; private set; }
|
|
|
|
|
|
|
|
|
|
private bool isLit;
|
|
|
|
|
public bool IsLit
|
|
|
|
|
{
|
|
|
|
|
get { return isLit; }
|
|
|
|
|
protected set
|
|
|
|
|
{
|
|
|
|
|
if (isLit != value)
|
|
|
|
|
{
|
|
|
|
|
isLit = value;
|
|
|
|
|
UpdateGlowSprite();
|
|
|
|
|
if (value && ParentCounter.IsCounting)
|
|
|
|
|
IncreaseCount();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color4 KeyDownTextColor { get; set; } = Color4.DarkGray;
|
|
|
|
|
public Color4 KeyUpTextColor { get; set; } = Color4.White;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 09:53:58 +08:00
|
|
|
|
public override void Load()
|
2016-09-23 19:14:11 +08:00
|
|
|
|
{
|
2016-09-24 09:53:58 +08:00
|
|
|
|
base.Load();
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
buttonSprite = new Sprite
|
|
|
|
|
{
|
|
|
|
|
Texture = Game.Textures.Get(@"KeyCounter/key-up"),
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
glowSprite = new Sprite
|
|
|
|
|
{
|
|
|
|
|
Texture = Game.Textures.Get(@"KeyCounter/key-glow"),
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
keySpriteText = new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = Name,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Position = new Vector2(0, -buttonSprite.Height / 4),
|
|
|
|
|
Colour = KeyUpTextColor
|
|
|
|
|
},
|
|
|
|
|
countSpriteText = new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = Count.ToString(),
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Position = new Vector2(0, buttonSprite.Height / 4),
|
|
|
|
|
Colour = KeyUpTextColor
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
glowSprite.Hide();
|
2016-09-23 19:14:11 +08:00
|
|
|
|
}
|
2016-09-23 18:57:19 +08:00
|
|
|
|
|
2016-09-24 09:53:58 +08:00
|
|
|
|
private void UpdateGlowSprite()
|
|
|
|
|
{
|
|
|
|
|
//can have a FadeTime property or const
|
|
|
|
|
if (IsLit)
|
|
|
|
|
{
|
|
|
|
|
glowSprite.Show();
|
|
|
|
|
countSpriteText.FadeColour(KeyDownTextColor, 0);
|
|
|
|
|
keySpriteText.FadeColour(KeyDownTextColor, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
glowSprite.Hide();
|
|
|
|
|
countSpriteText.FadeColour(KeyUpTextColor, 0);
|
|
|
|
|
keySpriteText.FadeColour(KeyUpTextColor, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-23 19:14:11 +08:00
|
|
|
|
|
2016-09-24 09:53:58 +08:00
|
|
|
|
private void IncreaseCount()
|
|
|
|
|
{
|
|
|
|
|
Count++;
|
|
|
|
|
countSpriteText.Text = Count.ToString();
|
|
|
|
|
}
|
2016-09-23 18:29:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|