2017-02-07 04:59:30 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-09-24 01:53:58 +00:00
|
|
|
|
|
2017-03-07 10:30:39 +00:00
|
|
|
|
using System.Linq;
|
2016-10-22 10:37:27 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-01-27 12:57:22 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-09-24 02:26:42 +00:00
|
|
|
|
using OpenTK.Graphics;
|
2017-03-07 10:30:39 +00:00
|
|
|
|
using osu.Framework.Input;
|
2016-09-24 01:53:58 +00:00
|
|
|
|
|
2017-01-27 12:57:22 +00:00
|
|
|
|
namespace osu.Game.Screens.Play
|
2016-09-24 01:53:58 +00:00
|
|
|
|
{
|
2017-03-01 18:33:01 +00:00
|
|
|
|
public class KeyCounterCollection : FillFlowContainer<KeyCounter>
|
2016-09-24 01:53:58 +00:00
|
|
|
|
{
|
|
|
|
|
public KeyCounterCollection()
|
|
|
|
|
{
|
2017-03-16 08:38:36 +00:00
|
|
|
|
AlwaysReceiveInput = true;
|
|
|
|
|
|
2017-03-04 10:00:17 +00:00
|
|
|
|
Direction = FillDirection.Horizontal;
|
2016-10-22 10:37:27 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2016-09-24 01:53:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 07:58:27 +00:00
|
|
|
|
public override void Add(KeyCounter key)
|
2016-10-06 14:33:09 +00:00
|
|
|
|
{
|
2016-12-03 07:58:27 +00:00
|
|
|
|
base.Add(key);
|
2016-10-09 09:56:41 +00:00
|
|
|
|
key.IsCounting = IsCounting;
|
|
|
|
|
key.FadeTime = FadeTime;
|
|
|
|
|
key.KeyDownTextColor = KeyDownTextColor;
|
|
|
|
|
key.KeyUpTextColor = KeyUpTextColor;
|
2016-09-24 01:53:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 06:10:51 +00:00
|
|
|
|
public void ResetCount()
|
|
|
|
|
{
|
2016-12-03 07:58:27 +00:00
|
|
|
|
foreach (var counter in Children)
|
2016-09-26 06:10:51 +00:00
|
|
|
|
counter.ResetCount();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 02:26:42 +00:00
|
|
|
|
//further: change default values here and in KeyCounter if needed, instead of passing them in every constructor
|
2016-09-24 02:04:08 +00:00
|
|
|
|
private bool isCounting;
|
|
|
|
|
public bool IsCounting
|
|
|
|
|
{
|
|
|
|
|
get { return isCounting; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-09-24 02:26:42 +00:00
|
|
|
|
if (value != isCounting)
|
|
|
|
|
{
|
|
|
|
|
isCounting = value;
|
2016-12-03 07:58:27 +00:00
|
|
|
|
foreach (var child in Children)
|
2016-09-24 02:26:42 +00:00
|
|
|
|
child.IsCounting = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 01:59:19 +00:00
|
|
|
|
private int fadeTime;
|
2016-09-24 02:26:42 +00:00
|
|
|
|
public int FadeTime
|
|
|
|
|
{
|
|
|
|
|
get { return fadeTime; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != fadeTime)
|
|
|
|
|
{
|
|
|
|
|
fadeTime = value;
|
2016-12-03 07:58:27 +00:00
|
|
|
|
foreach (var child in Children)
|
2016-09-24 02:26:42 +00:00
|
|
|
|
child.FadeTime = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 keyDownTextColor = Color4.DarkGray;
|
|
|
|
|
public Color4 KeyDownTextColor
|
|
|
|
|
{
|
|
|
|
|
get { return keyDownTextColor; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != keyDownTextColor)
|
|
|
|
|
{
|
|
|
|
|
keyDownTextColor = value;
|
2016-12-03 07:58:27 +00:00
|
|
|
|
foreach (var child in Children)
|
2016-09-24 02:26:42 +00:00
|
|
|
|
child.KeyDownTextColor = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 keyUpTextColor = Color4.White;
|
|
|
|
|
public Color4 KeyUpTextColor
|
|
|
|
|
{
|
|
|
|
|
get { return keyUpTextColor; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != keyUpTextColor)
|
|
|
|
|
{
|
|
|
|
|
keyUpTextColor = value;
|
2016-12-03 07:58:27 +00:00
|
|
|
|
foreach (var child in Children)
|
2016-09-24 02:26:42 +00:00
|
|
|
|
child.KeyUpTextColor = value;
|
|
|
|
|
}
|
2016-09-24 02:04:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-07 10:30:39 +00:00
|
|
|
|
|
|
|
|
|
public override bool HandleInput => receptor?.IsAlive != true;
|
|
|
|
|
|
|
|
|
|
private Receptor receptor;
|
|
|
|
|
|
|
|
|
|
public Receptor GetReceptor()
|
|
|
|
|
{
|
|
|
|
|
return receptor ?? (receptor = new Receptor(this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Receptor : Drawable
|
|
|
|
|
{
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly KeyCounterCollection target;
|
2017-03-07 10:30:39 +00:00
|
|
|
|
|
|
|
|
|
public Receptor(KeyCounterCollection target)
|
|
|
|
|
{
|
2017-03-16 08:38:36 +00:00
|
|
|
|
AlwaysReceiveInput = true;
|
2017-03-07 10:30:39 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
this.target = target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool HandleInput => true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) => target.Children.Any(c => c.TriggerKeyDown(state, args));
|
|
|
|
|
|
|
|
|
|
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) => target.Children.Any(c => c.TriggerKeyUp(state, args));
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => target.Children.Any(c => c.TriggerMouseDown(state, args));
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) => target.Children.Any(c => c.TriggerMouseUp(state, args));
|
|
|
|
|
}
|
2016-09-24 01:53:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|