From 55a1a3827ad2b50e986f122962014054ba713085 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 23 Sep 2016 18:29:25 +0800 Subject: [PATCH] Implement KeyCounter and base Count class. --- osu.Game/Graphics/UserInterface/Counter.cs | 74 +++++++++++++++++++ osu.Game/Graphics/UserInterface/KeyCounter.cs | 17 +++++ osu.Game/osu.Game.csproj | 2 + 3 files changed, 93 insertions(+) create mode 100644 osu.Game/Graphics/UserInterface/Counter.cs create mode 100644 osu.Game/Graphics/UserInterface/KeyCounter.cs diff --git a/osu.Game/Graphics/UserInterface/Counter.cs b/osu.Game/Graphics/UserInterface/Counter.cs new file mode 100644 index 0000000000..fce5bf4ebf --- /dev/null +++ b/osu.Game/Graphics/UserInterface/Counter.cs @@ -0,0 +1,74 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; + +namespace osu.Game.Graphics.UserInterface +{ + abstract class Count : AutoSizeContainer + { + private Sprite buttonSprite; + private Sprite glowSprite; + private SpriteText keySpriteText; + private SpriteText countSpriteText; + + public override string Name { get; } + public bool IsCounting { get; set; } + public int Counts { get; private set; } + + private bool isLit; + public bool IsLit + { + get { return isLit; } + set + { + if (value && !isLit && IsCounting) + Counts++; + isLit = value; + } + } + + protected Count(string name) + { + Name = name; + } + + 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.TopCentre, + Origin = Anchor.TopCentre + }, + countSpriteText = new SpriteText + { + Text = Counts.ToString(), + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre + } + }; + glowSprite.Hide(); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs new file mode 100644 index 0000000000..ecb3b133b4 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -0,0 +1,17 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics.Containers; + +namespace osu.Game.Graphics.UserInterface +{ + class KeyCounter : FlowContainer + { + public KeyCounter() + { + Direction = FlowDirection.HorizontalOnly; + } + + public void AddKey(Count key) => base.Add(key); + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 34f7b3801b..5170aa2d57 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -53,6 +53,8 @@ + +