Rename counter classes to avoid confusing.

This commit is contained in:
Huo Yaoyuan 2016-09-24 09:53:58 +08:00
parent 4b459b4f67
commit c70bf53486
7 changed files with 130 additions and 130 deletions

View File

@ -16,17 +16,17 @@ public override void Reset()
{
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));
}
}
}

View File

@ -1,110 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,26 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//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; }
}
}

View File

@ -7,10 +7,10 @@
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;
}

View File

@ -8,10 +8,10 @@
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;
}

View File

@ -53,10 +53,10 @@
<Compile Include="Graphics\Containers\OsuLargeComponent.cs" />
<Compile Include="Graphics\Processing\RatioAdjust.cs" />
<Compile Include="Graphics\TextAwesome.cs" />
<Compile Include="Graphics\UserInterface\Counter.cs" />
<Compile Include="Graphics\UserInterface\KeyBoardCount.cs" />
<Compile Include="Graphics\UserInterface\KeyCounter.cs" />
<Compile Include="Graphics\UserInterface\MouseCount.cs" />
<Compile Include="Graphics\UserInterface\KeyCounterKeyBoard.cs" />
<Compile Include="Graphics\UserInterface\KeyCounterCollection.cs" />
<Compile Include="Graphics\UserInterface\KeyCounterMouse.cs" />
<Compile Include="Online\API\APIAccess.cs" />
<Compile Include="Online\API\APIRequest.cs" />
<Compile Include="Online\API\OAuth.cs" />