From 55a1a3827ad2b50e986f122962014054ba713085 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 23 Sep 2016 18:29:25 +0800 Subject: [PATCH 01/19] 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 @@ + + From e5ef3e1d024ea13cc686749e8ff4687f3f309522 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 23 Sep 2016 18:34:54 +0800 Subject: [PATCH 02/19] Adjust children position of Counter. --- osu.Game/Graphics/UserInterface/Counter.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/Counter.cs b/osu.Game/Graphics/UserInterface/Counter.cs index fce5bf4ebf..e3270a4392 100644 --- a/osu.Game/Graphics/UserInterface/Counter.cs +++ b/osu.Game/Graphics/UserInterface/Counter.cs @@ -1,6 +1,7 @@ //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; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -58,14 +59,16 @@ namespace osu.Game.Graphics.UserInterface keySpriteText = new SpriteText { Text = Name, - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Position = new Vector2(0, -buttonSprite.Height / 4) }, countSpriteText = new SpriteText { Text = Counts.ToString(), - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Position = new Vector2(0, buttonSprite.Height / 4) } }; glowSprite.Hide(); From 81f269ee6951ff4aa86528e48b7a5b99b62de506 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 23 Sep 2016 18:57:19 +0800 Subject: [PATCH 03/19] MouseCount and KeyBoardCount, input handling. --- .../Graphics/UserInterface/KeyBoardCount.cs | 30 +++++++++++++++++ osu.Game/Graphics/UserInterface/KeyCounter.cs | 3 ++ osu.Game/Graphics/UserInterface/MouseCount.cs | 33 +++++++++++++++++++ osu.Game/osu.Game.csproj | 2 ++ 4 files changed, 68 insertions(+) create mode 100644 osu.Game/Graphics/UserInterface/KeyBoardCount.cs create mode 100644 osu.Game/Graphics/UserInterface/MouseCount.cs diff --git a/osu.Game/Graphics/UserInterface/KeyBoardCount.cs b/osu.Game/Graphics/UserInterface/KeyBoardCount.cs new file mode 100644 index 0000000000..2f9997feea --- /dev/null +++ b/osu.Game/Graphics/UserInterface/KeyBoardCount.cs @@ -0,0 +1,30 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK.Input; +using osu.Framework.Graphics; +using osu.Framework.Input; + +namespace osu.Game.Graphics.UserInterface +{ + class KeyBoardCount : Count + { + public Key Key { get; } + public KeyBoardCount(string name, Key key) : base(name) + { + Key = key; + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (args.Key == this.Key) IsLit = true; + return base.OnKeyDown(state, args); + } + + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + { + if (args.Key == this.Key) IsLit = false; + return base.OnKeyUp(state, args); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index ecb3b133b4..dad7c84745 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -1,6 +1,7 @@ //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 @@ -13,5 +14,7 @@ namespace osu.Game.Graphics.UserInterface } public void AddKey(Count key) => base.Add(key); + + public override bool Contains(Vector2 screenSpacePos) => true; } } diff --git a/osu.Game/Graphics/UserInterface/MouseCount.cs b/osu.Game/Graphics/UserInterface/MouseCount.cs new file mode 100644 index 0000000000..b993ce3a53 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/MouseCount.cs @@ -0,0 +1,33 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Input; +using osu.Framework.Graphics; +using osu.Framework.Input; + +namespace osu.Game.Graphics.UserInterface +{ + class MouseCount : Count + { + public MouseButton Button { get; } + public MouseCount(string name, MouseButton button) : base(name) + { + Button = button; + } + + public override bool Contains(Vector2 screenSpacePos) => true; + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + if (args.Button == this.Button) IsLit = true; + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) + { + if (args.Button == this.Button) IsLit = false; + return base.OnMouseUp(state, args); + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 5170aa2d57..16ebc40bc8 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -54,7 +54,9 @@ + + From 409bb0d068eee7e5b3490b5588beff9f3d876350 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 23 Sep 2016 19:10:14 +0800 Subject: [PATCH 04/19] Counter animation. --- osu.Game/Graphics/UserInterface/Counter.cs | 41 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/Counter.cs b/osu.Game/Graphics/UserInterface/Counter.cs index e3270a4392..17e0f65f0d 100644 --- a/osu.Game/Graphics/UserInterface/Counter.cs +++ b/osu.Game/Graphics/UserInterface/Counter.cs @@ -2,6 +2,7 @@ //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; @@ -26,11 +27,18 @@ namespace osu.Game.Graphics.UserInterface set { if (value && !isLit && IsCounting) - Counts++; - isLit = value; + IncreaseCount(); + if (isLit != value) + { + isLit = value; + UpdateGlowSprite(); + } } } + public Color4 KeyDownTextColor { get; set; } = Color4.DarkGray; + public Color4 KeyUpTextColor { get; set; } = Color4.White; + protected Count(string name) { Name = name; @@ -61,17 +69,42 @@ namespace osu.Game.Graphics.UserInterface Text = Name, Anchor = Anchor.Centre, Origin = Anchor.Centre, - Position = new Vector2(0, -buttonSprite.Height / 4) + 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) + 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(); + } } } From ba19fe1b9751918d3d7646832bcc7582c42ee7e2 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 23 Sep 2016 19:14:11 +0800 Subject: [PATCH 05/19] Move IsCounting to KeyCounter. --- osu.Game/Graphics/UserInterface/Counter.cs | 4 ++-- osu.Game/Graphics/UserInterface/KeyCounter.cs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/Counter.cs b/osu.Game/Graphics/UserInterface/Counter.cs index 17e0f65f0d..5296bef1c0 100644 --- a/osu.Game/Graphics/UserInterface/Counter.cs +++ b/osu.Game/Graphics/UserInterface/Counter.cs @@ -17,7 +17,7 @@ namespace osu.Game.Graphics.UserInterface private SpriteText countSpriteText; public override string Name { get; } - public bool IsCounting { get; set; } + public KeyCounter ParentCounter { get; set; } public int Counts { get; private set; } private bool isLit; @@ -26,7 +26,7 @@ namespace osu.Game.Graphics.UserInterface get { return isLit; } set { - if (value && !isLit && IsCounting) + if (value && !isLit && ParentCounter.IsCounting) IncreaseCount(); if (isLit != value) { diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index dad7c84745..3b974be19c 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -13,8 +13,14 @@ namespace osu.Game.Graphics.UserInterface Direction = FlowDirection.HorizontalOnly; } - public void AddKey(Count key) => base.Add(key); + public void AddKey(Count key) + { + key.ParentCounter = this; + base.Add(key); + } public override bool Contains(Vector2 screenSpacePos) => true; + + public bool IsCounting { get; set; } } } From d8666deaa0351ef3c6d38309aebdd73496339da8 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 23 Sep 2016 19:41:25 +0800 Subject: [PATCH 06/19] IsLit Adjustment. --- osu.Game/Graphics/UserInterface/Counter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/Counter.cs b/osu.Game/Graphics/UserInterface/Counter.cs index 5296bef1c0..c2910bb490 100644 --- a/osu.Game/Graphics/UserInterface/Counter.cs +++ b/osu.Game/Graphics/UserInterface/Counter.cs @@ -24,14 +24,14 @@ namespace osu.Game.Graphics.UserInterface public bool IsLit { get { return isLit; } - set + protected set { - if (value && !isLit && ParentCounter.IsCounting) - IncreaseCount(); if (isLit != value) { isLit = value; UpdateGlowSprite(); + if (value && ParentCounter.IsCounting) + IncreaseCount(); } } } From 16f1dff8490046babcf3bfd941151337d28405fc Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 08:52:41 +0800 Subject: [PATCH 07/19] Make counter public. --- osu.Game/Graphics/UserInterface/Counter.cs | 2 +- osu.Game/Graphics/UserInterface/KeyBoardCount.cs | 2 +- osu.Game/Graphics/UserInterface/KeyCounter.cs | 2 +- osu.Game/Graphics/UserInterface/MouseCount.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/Counter.cs b/osu.Game/Graphics/UserInterface/Counter.cs index c2910bb490..aea2d4c457 100644 --- a/osu.Game/Graphics/UserInterface/Counter.cs +++ b/osu.Game/Graphics/UserInterface/Counter.cs @@ -9,7 +9,7 @@ using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { - abstract class Count : AutoSizeContainer + public abstract class Count : AutoSizeContainer { private Sprite buttonSprite; private Sprite glowSprite; diff --git a/osu.Game/Graphics/UserInterface/KeyBoardCount.cs b/osu.Game/Graphics/UserInterface/KeyBoardCount.cs index 2f9997feea..1b2289e5ce 100644 --- a/osu.Game/Graphics/UserInterface/KeyBoardCount.cs +++ b/osu.Game/Graphics/UserInterface/KeyBoardCount.cs @@ -7,7 +7,7 @@ using osu.Framework.Input; namespace osu.Game.Graphics.UserInterface { - class KeyBoardCount : Count + public class KeyBoardCount : Count { public Key Key { get; } public KeyBoardCount(string name, Key key) : base(name) diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index 3b974be19c..3decba11ed 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -6,7 +6,7 @@ using osu.Framework.Graphics.Containers; namespace osu.Game.Graphics.UserInterface { - class KeyCounter : FlowContainer + public class KeyCounter : FlowContainer { public KeyCounter() { diff --git a/osu.Game/Graphics/UserInterface/MouseCount.cs b/osu.Game/Graphics/UserInterface/MouseCount.cs index b993ce3a53..bfa0def26e 100644 --- a/osu.Game/Graphics/UserInterface/MouseCount.cs +++ b/osu.Game/Graphics/UserInterface/MouseCount.cs @@ -8,7 +8,7 @@ using osu.Framework.Input; namespace osu.Game.Graphics.UserInterface { - class MouseCount : Count + public class MouseCount : Count { public MouseButton Button { get; } public MouseCount(string name, MouseButton button) : base(name) From 4b459b4f67ab5296f647a98b109f337cb5cb537e Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 08:57:13 +0800 Subject: [PATCH 08/19] Visual test for KeyCounter. --- .../Tests/TestCaseKeyCounter.cs | 32 +++++++++++++++++++ .../osu.Desktop.VisualTests.csproj | 1 + 2 files changed, 33 insertions(+) create mode 100644 osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs new file mode 100644 index 0000000000..d2184a04c9 --- /dev/null +++ b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs @@ -0,0 +1,32 @@ +using System; +using OpenTK.Input; +using osu.Framework.GameModes.Testing; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; + +namespace osu.Desktop.Tests +{ + class TestCaseKeyCounter : TestCase + { + public override string Name => @"KeyCounter"; + + public override string Description => @"Tests key counter"; + + public override void Reset() + { + base.Reset(); + + KeyCounter kc = new KeyCounter + { + 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)); + } + } +} diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index 4430339937..8cb922cfee 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -147,6 +147,7 @@ + From c70bf53486a8bc7e4dc020f29df45c0cd26e7229 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 09:53:58 +0800 Subject: [PATCH 09/19] 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 @@ - - - + + + From 0da0d4f35e71bb37f3994b9adf0a106b7d321da1 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 10:04:08 +0800 Subject: [PATCH 10/19] Avoid accessing container in each counter. --- osu.Game/Graphics/UserInterface/KeyCounter.cs | 4 ++-- .../UserInterface/KeyCounterCollection.cs | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index ae7a1b5c3e..095ecc2394 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -17,7 +17,7 @@ namespace osu.Game.Graphics.UserInterface private SpriteText countSpriteText; public override string Name { get; } - public KeyCounterCollection ParentCounter { get; set; } + public bool IsCounting { get; set; } public int Count { get; private set; } private bool isLit; @@ -30,7 +30,7 @@ namespace osu.Game.Graphics.UserInterface { isLit = value; UpdateGlowSprite(); - if (value && ParentCounter.IsCounting) + if (value && IsCounting) IncreaseCount(); } } diff --git a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs index 7ee313423c..f9811a4b25 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs @@ -1,6 +1,7 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; using OpenTK; using osu.Framework.Graphics.Containers; @@ -13,14 +14,29 @@ namespace osu.Game.Graphics.UserInterface Direction = FlowDirection.HorizontalOnly; } + private List counters = new List(); + //default capacity is 4, and osu! uses 4 keys usually, so it won't trouble + public IReadOnlyList Counters => counters; + public void AddKey(KeyCounter key) { - key.ParentCounter = this; + counters.Add(key); + key.IsCounting = this.IsCounting; base.Add(key); } public override bool Contains(Vector2 screenSpacePos) => true; - public bool IsCounting { get; set; } + private bool isCounting; + public bool IsCounting + { + get { return isCounting; } + set + { + isCounting = value; + foreach (var child in counters) + child.IsCounting = value; + } + } } } From f4ac1f630d37ea7d7fb89daf7a49d6d0a7ada0ab Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 10:19:50 +0800 Subject: [PATCH 11/19] Adjust visual tree of counter. --- osu.Game/Graphics/UserInterface/KeyCounter.cs | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index 095ecc2394..43dbd36d18 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -9,10 +9,11 @@ using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { - public abstract class KeyCounter : AutoSizeContainer + public abstract class KeyCounter : Container { private Sprite buttonSprite; private Sprite glowSprite; + private Container textLayer; private SpriteText keySpriteText; private SpriteText countSpriteText; @@ -54,34 +55,43 @@ namespace osu.Game.Graphics.UserInterface Texture = Game.Textures.Get(@"KeyCounter/key-up"), Anchor = Anchor.Centre, Origin = Anchor.Centre, + }, + glowSprite = new Sprite + { + Texture = Game.Textures.Get(@"KeyCounter/key-glow"), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Alpha = 0 + }, + textLayer = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, Children = new Drawable[] { - glowSprite = new Sprite + keySpriteText = new SpriteText { - Texture = Game.Textures.Get(@"KeyCounter/key-glow"), + 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 } } - }, - 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(); + //Set this manually because an element with Alpha=0 won't take it size to AutoSizeContainer, + //so the size can be changing between buttonSpirit and glowSpirit. + Height = buttonSprite.Height; + Width = buttonSprite.Width; } private void UpdateGlowSprite() @@ -89,15 +99,13 @@ namespace osu.Game.Graphics.UserInterface //can have a FadeTime property or const if (IsLit) { - glowSprite.Show(); - countSpriteText.FadeColour(KeyDownTextColor, 0); - keySpriteText.FadeColour(KeyDownTextColor, 0); + glowSprite.FadeIn(); + textLayer.FadeColour(KeyDownTextColor, 0); } else { - glowSprite.Hide(); - countSpriteText.FadeColour(KeyUpTextColor, 0); - keySpriteText.FadeColour(KeyUpTextColor, 0); + glowSprite.FadeOut(); + textLayer.FadeColour(KeyUpTextColor, 0); } } From ed4fae53cbb6b0fd761c78f61cc9278fdd38e6cd Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 10:26:42 +0800 Subject: [PATCH 12/19] Add FadeTime and allow setting custom styles directly from container. --- osu.Game/Graphics/UserInterface/KeyCounter.cs | 9 +-- .../UserInterface/KeyCounterCollection.cs | 59 ++++++++++++++++++- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index 43dbd36d18..560e5866d6 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -37,8 +37,10 @@ namespace osu.Game.Graphics.UserInterface } } + //further: change default values here and in KeyCounterCollection if needed, instead of passing them in every constructor public Color4 KeyDownTextColor { get; set; } = Color4.DarkGray; public Color4 KeyUpTextColor { get; set; } = Color4.White; + public int FadeTime { get; set; } = 0; protected KeyCounter(string name) { @@ -96,16 +98,15 @@ namespace osu.Game.Graphics.UserInterface private void UpdateGlowSprite() { - //can have a FadeTime property or const if (IsLit) { - glowSprite.FadeIn(); - textLayer.FadeColour(KeyDownTextColor, 0); + glowSprite.FadeIn(FadeTime); + textLayer.FadeColour(KeyDownTextColor, FadeTime); } else { glowSprite.FadeOut(); - textLayer.FadeColour(KeyUpTextColor, 0); + textLayer.FadeColour(KeyUpTextColor, FadeTime); } } diff --git a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs index f9811a4b25..85ae255d1b 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using OpenTK; +using OpenTK.Graphics; using osu.Framework.Graphics.Containers; namespace osu.Game.Graphics.UserInterface @@ -22,20 +23,72 @@ namespace osu.Game.Graphics.UserInterface { counters.Add(key); key.IsCounting = this.IsCounting; + key.FadeTime = this.FadeTime; + key.KeyDownTextColor = this.KeyDownTextColor; + key.KeyUpTextColor = this.KeyUpTextColor; base.Add(key); } public override bool Contains(Vector2 screenSpacePos) => true; + //further: change default values here and in KeyCounter if needed, instead of passing them in every constructor private bool isCounting; public bool IsCounting { get { return isCounting; } set { - isCounting = value; - foreach (var child in counters) - child.IsCounting = value; + if (value != isCounting) + { + isCounting = value; + foreach (var child in counters) + child.IsCounting = value; + } + } + } + + private int fadeTime = 0; + public int FadeTime + { + get { return fadeTime; } + set + { + if (value != fadeTime) + { + fadeTime = value; + foreach (var child in counters) + child.FadeTime = value; + } + } + } + + private Color4 keyDownTextColor = Color4.DarkGray; + public Color4 KeyDownTextColor + { + get { return keyDownTextColor; } + set + { + if (value != keyDownTextColor) + { + keyDownTextColor = value; + foreach (var child in counters) + child.KeyDownTextColor = value; + } + } + } + + private Color4 keyUpTextColor = Color4.White; + public Color4 KeyUpTextColor + { + get { return keyUpTextColor; } + set + { + if (value != keyUpTextColor) + { + keyUpTextColor = value; + foreach (var child in counters) + child.KeyUpTextColor = value; + } } } } From ec2bc4720d52622f2e10316fe7198c2d64d6d4f8 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 10:31:14 +0800 Subject: [PATCH 13/19] Comma seperator in numbers. --- osu.Game/Graphics/UserInterface/KeyCounter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index 560e5866d6..4a22ae48c4 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -81,7 +81,7 @@ namespace osu.Game.Graphics.UserInterface }, countSpriteText = new SpriteText { - Text = Count.ToString(), + Text = Count.ToString(@"#,0"), Anchor = Anchor.Centre, Origin = Anchor.Centre, Position = new Vector2(0, buttonSprite.Height / 4), @@ -113,7 +113,7 @@ namespace osu.Game.Graphics.UserInterface private void IncreaseCount() { Count++; - countSpriteText.Text = Count.ToString(); + countSpriteText.Text = Count.ToString(@"#,0"); } } } From 63535df6dca3a48ff28dd8b8d75010d88fc0d567 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 14:28:59 +0800 Subject: [PATCH 14/19] Fix typo and missnaming. --- osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs | 4 ++-- osu.Game/Graphics/UserInterface/KeyCounter.cs | 2 +- .../{KeyCounterKeyBoard.cs => KeyCounterKeyboard.cs} | 4 ++-- osu.Game/osu.Game.csproj | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename osu.Game/Graphics/UserInterface/{KeyCounterKeyBoard.cs => KeyCounterKeyboard.cs} (84%) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs index 064f114f22..8d0acf98f0 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs @@ -23,8 +23,8 @@ namespace osu.Desktop.Tests IsCounting = true }; Add(kc); - kc.AddKey(new KeyCounterKeyBoard(@"Z", Key.Z)); - kc.AddKey(new KeyCounterKeyBoard(@"X", Key.X)); + 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/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index 4a22ae48c4..d89791d98f 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -91,7 +91,7 @@ namespace osu.Game.Graphics.UserInterface } }; //Set this manually because an element with Alpha=0 won't take it size to AutoSizeContainer, - //so the size can be changing between buttonSpirit and glowSpirit. + //so the size can be changing between buttonSprite and glowSprite. Height = buttonSprite.Height; Width = buttonSprite.Width; } diff --git a/osu.Game/Graphics/UserInterface/KeyCounterKeyBoard.cs b/osu.Game/Graphics/UserInterface/KeyCounterKeyboard.cs similarity index 84% rename from osu.Game/Graphics/UserInterface/KeyCounterKeyBoard.cs rename to osu.Game/Graphics/UserInterface/KeyCounterKeyboard.cs index c58515658f..9b75924cb6 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounterKeyBoard.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounterKeyboard.cs @@ -7,10 +7,10 @@ using osu.Framework.Input; namespace osu.Game.Graphics.UserInterface { - public class KeyCounterKeyBoard : KeyCounter + public class KeyCounterKeyboard : KeyCounter { public Key Key { get; } - public KeyCounterKeyBoard(string name, Key key) : base(name) + public KeyCounterKeyboard(string name, Key key) : base(name) { Key = key; } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index b33493bd3d..9510df2932 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -54,7 +54,7 @@ - + From 9491bd7f59db4e1b3e7206d4e7dedad62f7b6f63 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 25 Sep 2016 13:32:53 +0900 Subject: [PATCH 15/19] Fix OpenTK reference in VisualTests. --- osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index 4430339937..22946a6433 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -92,7 +92,10 @@ - + + ..\packages\ppy.OpenTK.1.1.2225.3\lib\net20\OpenTK.dll + True + From 756e7a6a6712353b6d72a2d71b6879a1225f6582 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 26 Sep 2016 13:56:05 +0800 Subject: [PATCH 16/19] Add missing lincense header, remove unnecessary comment and field. --- osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs | 5 ++++- osu.Desktop.VisualTests/Tests/TestCaseTextAwesome.cs | 5 ++++- osu.Game/Graphics/UserInterface/KeyCounter.cs | 3 +-- osu.Game/Graphics/UserInterface/KeyCounterCollection.cs | 1 - 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs index 8d0acf98f0..87642f3004 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs @@ -1,4 +1,7 @@ -using System; +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; using OpenTK.Input; using osu.Framework.GameModes.Testing; using osu.Framework.Graphics; diff --git a/osu.Desktop.VisualTests/Tests/TestCaseTextAwesome.cs b/osu.Desktop.VisualTests/Tests/TestCaseTextAwesome.cs index 3e2c1f095d..ace1daf205 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseTextAwesome.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseTextAwesome.cs @@ -1,4 +1,7 @@ -using OpenTK; +//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.GameModes.Testing; using osu.Framework.Graphics; diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index d89791d98f..a704c4c15b 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -14,7 +14,6 @@ namespace osu.Game.Graphics.UserInterface private Sprite buttonSprite; private Sprite glowSprite; private Container textLayer; - private SpriteText keySpriteText; private SpriteText countSpriteText; public override string Name { get; } @@ -71,7 +70,7 @@ namespace osu.Game.Graphics.UserInterface Origin = Anchor.Centre, Children = new Drawable[] { - keySpriteText = new SpriteText + new SpriteText { Text = Name, Anchor = Anchor.Centre, diff --git a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs index 85ae255d1b..60ebd7671d 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs @@ -16,7 +16,6 @@ namespace osu.Game.Graphics.UserInterface } private List counters = new List(); - //default capacity is 4, and osu! uses 4 keys usually, so it won't trouble public IReadOnlyList Counters => counters; public void AddKey(KeyCounter key) From b4bb3d6317a31d82412de0a1c64a3947dd92670b Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 26 Sep 2016 14:07:43 +0800 Subject: [PATCH 17/19] Update private methods implementation. --- osu.Game/Graphics/UserInterface/KeyCounter.cs | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index a704c4c15b..4ac7ae017d 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -18,7 +18,19 @@ namespace osu.Game.Graphics.UserInterface public override string Name { get; } public bool IsCounting { get; set; } - public int Count { get; private set; } + private int count; + public int Count + { + get { return count; } + private set + { + if (count != value) + { + count = value; + countSpriteText.Text = value.ToString(@"#,0"); + } + } + } private bool isLit; public bool IsLit @@ -29,9 +41,9 @@ namespace osu.Game.Graphics.UserInterface if (isLit != value) { isLit = value; - UpdateGlowSprite(); + updateGlowSprite(value); if (value && IsCounting) - IncreaseCount(); + Count++; } } } @@ -95,24 +107,18 @@ namespace osu.Game.Graphics.UserInterface Width = buttonSprite.Width; } - private void UpdateGlowSprite() + private void updateGlowSprite(bool show) { - if (IsLit) + if (show) { glowSprite.FadeIn(FadeTime); textLayer.FadeColour(KeyDownTextColor, FadeTime); } else { - glowSprite.FadeOut(); + glowSprite.FadeOut(FadeTime); textLayer.FadeColour(KeyUpTextColor, FadeTime); } } - - private void IncreaseCount() - { - Count++; - countSpriteText.Text = Count.ToString(@"#,0"); - } } } From bb13da2b329f25582ee6a420d05fcddf3bdeca1a Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 26 Sep 2016 14:10:51 +0800 Subject: [PATCH 18/19] Add ResetCount method for Counter. --- osu.Game/Graphics/UserInterface/KeyCounter.cs | 2 ++ osu.Game/Graphics/UserInterface/KeyCounterCollection.cs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index 4ac7ae017d..6159b9ab05 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -120,5 +120,7 @@ namespace osu.Game.Graphics.UserInterface textLayer.FadeColour(KeyUpTextColor, FadeTime); } } + + public void ResetCount() => Count = 0; } } diff --git a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs index 60ebd7671d..ee1447c03b 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs @@ -28,6 +28,12 @@ namespace osu.Game.Graphics.UserInterface base.Add(key); } + public void ResetCount() + { + foreach (var counter in counters) + counter.ResetCount(); + } + public override bool Contains(Vector2 screenSpacePos) => true; //further: change default values here and in KeyCounter if needed, instead of passing them in every constructor From 25fecfca064e9c4babbd7c3988f7c3502f1c4394 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 26 Sep 2016 16:56:39 +0800 Subject: [PATCH 19/19] Relative size and position for text layer. --- osu.Game/Graphics/UserInterface/KeyCounter.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index 6159b9ab05..d715c7c0fd 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -80,6 +80,7 @@ namespace osu.Game.Graphics.UserInterface { Anchor = Anchor.Centre, Origin = Anchor.Centre, + SizeMode = InheritMode.XY, Children = new Drawable[] { new SpriteText @@ -87,7 +88,8 @@ namespace osu.Game.Graphics.UserInterface Text = Name, Anchor = Anchor.Centre, Origin = Anchor.Centre, - Position = new Vector2(0, -buttonSprite.Height / 4), + PositionMode = InheritMode.XY, + Position = new Vector2(0, -0.25f), Colour = KeyUpTextColor }, countSpriteText = new SpriteText @@ -95,7 +97,8 @@ namespace osu.Game.Graphics.UserInterface Text = Count.ToString(@"#,0"), Anchor = Anchor.Centre, Origin = Anchor.Centre, - Position = new Vector2(0, buttonSprite.Height / 4), + PositionMode = InheritMode.XY, + Position = new Vector2(0, 0.25f), Colour = KeyUpTextColor } }