mirror of
https://github.com/ppy/osu.git
synced 2024-11-14 15:57:24 +08:00
Merge branch 'refs/heads/master' into api-channels-messages
# Conflicts: # osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj
This commit is contained in:
commit
8650e951e5
35
osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs
Normal file
35
osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
//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;
|
||||||
|
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();
|
||||||
|
|
||||||
|
KeyCounterCollection kc = new KeyCounterCollection
|
||||||
|
{
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
IsCounting = true
|
||||||
|
};
|
||||||
|
Add(kc);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,7 @@
|
|||||||
using OpenTK;
|
//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 OpenTK.Graphics;
|
||||||
using osu.Framework.GameModes.Testing;
|
using osu.Framework.GameModes.Testing;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
@ -151,6 +151,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Tests\TestCaseChatDisplay.cs" />
|
<Compile Include="Tests\TestCaseChatDisplay.cs" />
|
||||||
|
<Compile Include="Tests\TestCaseKeyCounter.cs" />
|
||||||
<Compile Include="Tests\TestCaseTextAwesome.cs" />
|
<Compile Include="Tests\TestCaseTextAwesome.cs" />
|
||||||
<Compile Include="VisualTestGame.cs" />
|
<Compile Include="VisualTestGame.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
129
osu.Game/Graphics/UserInterface/KeyCounter.cs
Normal file
129
osu.Game/Graphics/UserInterface/KeyCounter.cs
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
//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 KeyCounter : Container
|
||||||
|
{
|
||||||
|
private Sprite buttonSprite;
|
||||||
|
private Sprite glowSprite;
|
||||||
|
private Container textLayer;
|
||||||
|
private SpriteText countSpriteText;
|
||||||
|
|
||||||
|
public override string Name { get; }
|
||||||
|
public bool IsCounting { get; 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
|
||||||
|
{
|
||||||
|
get { return isLit; }
|
||||||
|
protected set
|
||||||
|
{
|
||||||
|
if (isLit != value)
|
||||||
|
{
|
||||||
|
isLit = value;
|
||||||
|
updateGlowSprite(value);
|
||||||
|
if (value && IsCounting)
|
||||||
|
Count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//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)
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
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,
|
||||||
|
SizeMode = InheritMode.XY,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new SpriteText
|
||||||
|
{
|
||||||
|
Text = Name,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
PositionMode = InheritMode.XY,
|
||||||
|
Position = new Vector2(0, -0.25f),
|
||||||
|
Colour = KeyUpTextColor
|
||||||
|
},
|
||||||
|
countSpriteText = new SpriteText
|
||||||
|
{
|
||||||
|
Text = Count.ToString(@"#,0"),
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
PositionMode = InheritMode.XY,
|
||||||
|
Position = new Vector2(0, 0.25f),
|
||||||
|
Colour = KeyUpTextColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//Set this manually because an element with Alpha=0 won't take it size to AutoSizeContainer,
|
||||||
|
//so the size can be changing between buttonSprite and glowSprite.
|
||||||
|
Height = buttonSprite.Height;
|
||||||
|
Width = buttonSprite.Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateGlowSprite(bool show)
|
||||||
|
{
|
||||||
|
if (show)
|
||||||
|
{
|
||||||
|
glowSprite.FadeIn(FadeTime);
|
||||||
|
textLayer.FadeColour(KeyDownTextColor, FadeTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glowSprite.FadeOut(FadeTime);
|
||||||
|
textLayer.FadeColour(KeyUpTextColor, FadeTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetCount() => Count = 0;
|
||||||
|
}
|
||||||
|
}
|
100
osu.Game/Graphics/UserInterface/KeyCounterCollection.cs
Normal file
100
osu.Game/Graphics/UserInterface/KeyCounterCollection.cs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using OpenTK;
|
||||||
|
using OpenTK.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.UserInterface
|
||||||
|
{
|
||||||
|
public class KeyCounterCollection : FlowContainer
|
||||||
|
{
|
||||||
|
public KeyCounterCollection()
|
||||||
|
{
|
||||||
|
Direction = FlowDirection.HorizontalOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<KeyCounter> counters = new List<KeyCounter>();
|
||||||
|
public IReadOnlyList<KeyCounter> Counters => counters;
|
||||||
|
|
||||||
|
public void AddKey(KeyCounter key)
|
||||||
|
{
|
||||||
|
counters.Add(key);
|
||||||
|
key.IsCounting = this.IsCounting;
|
||||||
|
key.FadeTime = this.FadeTime;
|
||||||
|
key.KeyDownTextColor = this.KeyDownTextColor;
|
||||||
|
key.KeyUpTextColor = this.KeyUpTextColor;
|
||||||
|
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
|
||||||
|
private bool isCounting;
|
||||||
|
public bool IsCounting
|
||||||
|
{
|
||||||
|
get { return isCounting; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
osu.Game/Graphics/UserInterface/KeyCounterKeyboard.cs
Normal file
30
osu.Game/Graphics/UserInterface/KeyCounterKeyboard.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//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.Input;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Input;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.UserInterface
|
||||||
|
{
|
||||||
|
public class KeyCounterKeyboard : KeyCounter
|
||||||
|
{
|
||||||
|
public Key Key { get; }
|
||||||
|
public KeyCounterKeyboard(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
osu.Game/Graphics/UserInterface/KeyCounterMouse.cs
Normal file
33
osu.Game/Graphics/UserInterface/KeyCounterMouse.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//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.Input;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Input;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.UserInterface
|
||||||
|
{
|
||||||
|
public class KeyCounterMouse : KeyCounter
|
||||||
|
{
|
||||||
|
public MouseButton Button { get; }
|
||||||
|
public KeyCounterMouse(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -53,6 +53,10 @@
|
|||||||
<Compile Include="Graphics\Containers\OsuLargeComponent.cs" />
|
<Compile Include="Graphics\Containers\OsuLargeComponent.cs" />
|
||||||
<Compile Include="Graphics\Processing\RatioAdjust.cs" />
|
<Compile Include="Graphics\Processing\RatioAdjust.cs" />
|
||||||
<Compile Include="Graphics\TextAwesome.cs" />
|
<Compile Include="Graphics\TextAwesome.cs" />
|
||||||
|
<Compile Include="Graphics\UserInterface\KeyCounter.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\APIAccess.cs" />
|
||||||
<Compile Include="Online\API\APIRequest.cs" />
|
<Compile Include="Online\API\APIRequest.cs" />
|
||||||
<Compile Include="Online\API\OAuth.cs" />
|
<Compile Include="Online\API\OAuth.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user