mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 08:20:00 +09:00
Rename counter classes to avoid confusing.
This commit is contained in:
@ -2,25 +2,109 @@
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class KeyCounter : FlowContainer
|
||||
public abstract class KeyCounter : AutoSizeContainer
|
||||
{
|
||||
public KeyCounter()
|
||||
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
|
||||
{
|
||||
Direction = FlowDirection.HorizontalOnly;
|
||||
get { return isLit; }
|
||||
protected set
|
||||
{
|
||||
if (isLit != value)
|
||||
{
|
||||
isLit = value;
|
||||
UpdateGlowSprite();
|
||||
if (value && ParentCounter.IsCounting)
|
||||
IncreaseCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddKey(Count key)
|
||||
public Color4 KeyDownTextColor { get; set; } = Color4.DarkGray;
|
||||
public Color4 KeyUpTextColor { get; set; } = Color4.White;
|
||||
|
||||
protected KeyCounter(string name)
|
||||
{
|
||||
key.ParentCounter = this;
|
||||
base.Add(key);
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override bool Contains(Vector2 screenSpacePos) => true;
|
||||
public override void Load()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
public bool IsCounting { get; set; }
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void IncreaseCount()
|
||||
{
|
||||
Count++;
|
||||
countSpriteText.Text = Count.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user