From c70bf53486a8bc7e4dc020f29df45c0cd26e7229 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 09:53:58 +0800 Subject: [PATCH] Rename counter classes to avoid confusing. --- .../Tests/TestCaseKeyCounter.cs | 10 +- osu.Game/Graphics/UserInterface/Counter.cs | 110 ------------------ osu.Game/Graphics/UserInterface/KeyCounter.cs | 100 ++++++++++++++-- .../UserInterface/KeyCounterCollection.cs | 26 +++++ ...KeyBoardCount.cs => KeyCounterKeyBoard.cs} | 4 +- .../{MouseCount.cs => KeyCounterMouse.cs} | 4 +- osu.Game/osu.Game.csproj | 6 +- 7 files changed, 130 insertions(+), 130 deletions(-) delete mode 100644 osu.Game/Graphics/UserInterface/Counter.cs create mode 100644 osu.Game/Graphics/UserInterface/KeyCounterCollection.cs rename osu.Game/Graphics/UserInterface/{KeyBoardCount.cs => KeyCounterKeyBoard.cs} (83%) rename osu.Game/Graphics/UserInterface/{MouseCount.cs => KeyCounterMouse.cs} (85%) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs index d2184a04c9..064f114f22 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs @@ -16,17 +16,17 @@ namespace osu.Desktop.Tests { base.Reset(); - KeyCounter kc = new KeyCounter + KeyCounterCollection kc = new KeyCounterCollection { Origin = Anchor.Centre, Anchor = Anchor.Centre, IsCounting = true }; Add(kc); - kc.AddKey(new KeyBoardCount(@"Z", Key.Z)); - kc.AddKey(new KeyBoardCount(@"X", Key.X)); - kc.AddKey(new MouseCount(@"M1", MouseButton.Left)); - kc.AddKey(new MouseCount(@"M2", MouseButton.Right)); + kc.AddKey(new KeyCounterKeyBoard(@"Z", Key.Z)); + kc.AddKey(new KeyCounterKeyBoard(@"X", Key.X)); + kc.AddKey(new KeyCounterMouse(@"M1", MouseButton.Left)); + kc.AddKey(new KeyCounterMouse(@"M2", MouseButton.Right)); } } } diff --git a/osu.Game/Graphics/UserInterface/Counter.cs b/osu.Game/Graphics/UserInterface/Counter.cs deleted file mode 100644 index aea2d4c457..0000000000 --- a/osu.Game/Graphics/UserInterface/Counter.cs +++ /dev/null @@ -1,110 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//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 abstract class Count : AutoSizeContainer - { - private Sprite buttonSprite; - private Sprite glowSprite; - private SpriteText keySpriteText; - private SpriteText countSpriteText; - - public override string Name { get; } - public KeyCounter ParentCounter { get; set; } - public int Counts { 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 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.Centre, - Origin = Anchor.Centre, - Position = new Vector2(0, -buttonSprite.Height / 4), - Colour = KeyUpTextColor - }, - countSpriteText = new SpriteText - { - Text = Counts.ToString(), - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Position = new Vector2(0, buttonSprite.Height / 4), - Colour = KeyUpTextColor - } - }; - glowSprite.Hide(); - } - - 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() - { - Counts++; - countSpriteText.Text = Counts.ToString(); - } - } -} diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index 3decba11ed..ae7a1b5c3e 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -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(); + } } } diff --git a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs new file mode 100644 index 0000000000..7ee313423c --- /dev/null +++ b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs @@ -0,0 +1,26 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using osu.Framework.Graphics.Containers; + +namespace osu.Game.Graphics.UserInterface +{ + public class KeyCounterCollection : FlowContainer + { + public KeyCounterCollection() + { + Direction = FlowDirection.HorizontalOnly; + } + + public void AddKey(KeyCounter key) + { + key.ParentCounter = this; + base.Add(key); + } + + public override bool Contains(Vector2 screenSpacePos) => true; + + public bool IsCounting { get; set; } + } +} diff --git a/osu.Game/Graphics/UserInterface/KeyBoardCount.cs b/osu.Game/Graphics/UserInterface/KeyCounterKeyBoard.cs similarity index 83% rename from osu.Game/Graphics/UserInterface/KeyBoardCount.cs rename to osu.Game/Graphics/UserInterface/KeyCounterKeyBoard.cs index 1b2289e5ce..c58515658f 100644 --- a/osu.Game/Graphics/UserInterface/KeyBoardCount.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounterKeyBoard.cs @@ -7,10 +7,10 @@ using osu.Framework.Input; namespace osu.Game.Graphics.UserInterface { - public class KeyBoardCount : Count + public class KeyCounterKeyBoard : KeyCounter { public Key Key { get; } - public KeyBoardCount(string name, Key key) : base(name) + public KeyCounterKeyBoard(string name, Key key) : base(name) { Key = key; } diff --git a/osu.Game/Graphics/UserInterface/MouseCount.cs b/osu.Game/Graphics/UserInterface/KeyCounterMouse.cs similarity index 85% rename from osu.Game/Graphics/UserInterface/MouseCount.cs rename to osu.Game/Graphics/UserInterface/KeyCounterMouse.cs index bfa0def26e..982721c7a7 100644 --- a/osu.Game/Graphics/UserInterface/MouseCount.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounterMouse.cs @@ -8,10 +8,10 @@ using osu.Framework.Input; namespace osu.Game.Graphics.UserInterface { - public class MouseCount : Count + public class KeyCounterMouse : KeyCounter { public MouseButton Button { get; } - public MouseCount(string name, MouseButton button) : base(name) + public KeyCounterMouse(string name, MouseButton button) : base(name) { Button = button; } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 16ebc40bc8..b33493bd3d 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -53,10 +53,10 @@ - - - + + +