2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 12:59:30 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-09-24 09:53:58 +08:00
|
|
|
|
|
2017-08-21 11:31:21 +08:00
|
|
|
|
using System;
|
2017-03-07 18:30:39 +08:00
|
|
|
|
using System.Linq;
|
2016-10-22 18:37:27 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-01-27 20:57:22 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-09-24 10:26:42 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-03-07 18:30:39 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-05-23 16:53:42 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Game.Configuration;
|
2017-06-24 00:02:24 +08:00
|
|
|
|
using OpenTK;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
|
2017-01-27 20:57:22 +08:00
|
|
|
|
namespace osu.Game.Screens.Play
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
2017-03-02 02:33:01 +08:00
|
|
|
|
public class KeyCounterCollection : FillFlowContainer<KeyCounter>
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
2017-05-23 16:53:42 +08:00
|
|
|
|
private const int duration = 100;
|
|
|
|
|
|
|
|
|
|
private Bindable<bool> showKeyCounter;
|
|
|
|
|
|
2016-09-24 09:53:58 +08:00
|
|
|
|
public KeyCounterCollection()
|
|
|
|
|
{
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Horizontal;
|
2016-10-22 18:37:27 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 15:58:27 +08:00
|
|
|
|
public override void Add(KeyCounter key)
|
2016-10-06 22:33:09 +08:00
|
|
|
|
{
|
2017-09-11 10:41:09 +08:00
|
|
|
|
if (key == null) throw new ArgumentNullException(nameof(key));
|
|
|
|
|
|
2016-12-03 15:58:27 +08:00
|
|
|
|
base.Add(key);
|
2016-10-09 17:56:41 +08:00
|
|
|
|
key.IsCounting = IsCounting;
|
|
|
|
|
key.FadeTime = FadeTime;
|
|
|
|
|
key.KeyDownTextColor = KeyDownTextColor;
|
|
|
|
|
key.KeyUpTextColor = KeyUpTextColor;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 14:10:51 +08:00
|
|
|
|
public void ResetCount()
|
|
|
|
|
{
|
2016-12-03 15:58:27 +08:00
|
|
|
|
foreach (var counter in Children)
|
2016-09-26 14:10:51 +08:00
|
|
|
|
counter.ResetCount();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 16:53:42 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
|
{
|
|
|
|
|
showKeyCounter = config.GetBindable<bool>(OsuSetting.KeyOverlay);
|
2017-07-15 00:18:12 +08:00
|
|
|
|
showKeyCounter.ValueChanged += keyCounterVisibility => this.FadeTo(keyCounterVisibility ? 1 : 0, duration);
|
2017-05-23 16:53:42 +08:00
|
|
|
|
showKeyCounter.TriggerChange();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 10:26:42 +08:00
|
|
|
|
//further: change default values here and in KeyCounter if needed, instead of passing them in every constructor
|
2016-09-24 10:04:08 +08:00
|
|
|
|
private bool isCounting;
|
|
|
|
|
public bool IsCounting
|
|
|
|
|
{
|
|
|
|
|
get { return isCounting; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-05-17 20:57:01 +08:00
|
|
|
|
if (value == isCounting) return;
|
|
|
|
|
|
|
|
|
|
isCounting = value;
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
child.IsCounting = value;
|
2016-09-24 10:26:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private int fadeTime;
|
2016-09-24 10:26:42 +08:00
|
|
|
|
public int FadeTime
|
|
|
|
|
{
|
|
|
|
|
get { return fadeTime; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != fadeTime)
|
|
|
|
|
{
|
|
|
|
|
fadeTime = value;
|
2016-12-03 15:58:27 +08:00
|
|
|
|
foreach (var child in Children)
|
2016-09-24 10:26:42 +08:00
|
|
|
|
child.FadeTime = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 keyDownTextColor = Color4.DarkGray;
|
|
|
|
|
public Color4 KeyDownTextColor
|
|
|
|
|
{
|
|
|
|
|
get { return keyDownTextColor; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != keyDownTextColor)
|
|
|
|
|
{
|
|
|
|
|
keyDownTextColor = value;
|
2016-12-03 15:58:27 +08:00
|
|
|
|
foreach (var child in Children)
|
2016-09-24 10:26:42 +08:00
|
|
|
|
child.KeyDownTextColor = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 keyUpTextColor = Color4.White;
|
|
|
|
|
public Color4 KeyUpTextColor
|
|
|
|
|
{
|
|
|
|
|
get { return keyUpTextColor; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != keyUpTextColor)
|
|
|
|
|
{
|
|
|
|
|
keyUpTextColor = value;
|
2016-12-03 15:58:27 +08:00
|
|
|
|
foreach (var child in Children)
|
2016-09-24 10:26:42 +08:00
|
|
|
|
child.KeyUpTextColor = value;
|
|
|
|
|
}
|
2016-09-24 10:04:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-07 18:30:39 +08:00
|
|
|
|
|
2018-01-08 04:40:00 +08:00
|
|
|
|
public override bool HandleKeyboardInput => handleInput;
|
|
|
|
|
public override bool HandleMouseInput => handleInput;
|
|
|
|
|
private bool handleInput => receptor == null;
|
2017-03-07 18:30:39 +08:00
|
|
|
|
|
|
|
|
|
private Receptor receptor;
|
|
|
|
|
|
|
|
|
|
public Receptor GetReceptor()
|
|
|
|
|
{
|
|
|
|
|
return receptor ?? (receptor = new Receptor(this));
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-21 11:31:21 +08:00
|
|
|
|
public void SetReceptor(Receptor receptor)
|
|
|
|
|
{
|
|
|
|
|
if (this.receptor != null)
|
|
|
|
|
throw new InvalidOperationException("Cannot set a new receptor when one is already active");
|
|
|
|
|
|
|
|
|
|
this.receptor = receptor;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:30:39 +08:00
|
|
|
|
public class Receptor : Drawable
|
|
|
|
|
{
|
2017-08-21 11:31:21 +08:00
|
|
|
|
protected readonly KeyCounterCollection Target;
|
2017-03-07 18:30:39 +08:00
|
|
|
|
|
|
|
|
|
public Receptor(KeyCounterCollection target)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-08-21 11:31:21 +08:00
|
|
|
|
Depth = float.MinValue;
|
|
|
|
|
Target = target;
|
2017-03-07 18:30:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-30 14:54:03 +08:00
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
2017-06-24 00:02:24 +08:00
|
|
|
|
|
2017-08-21 11:31:21 +08:00
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) => Target.Children.Any(c => c.TriggerOnKeyDown(state, args));
|
2017-03-07 18:30:39 +08:00
|
|
|
|
|
2017-08-21 11:31:21 +08:00
|
|
|
|
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) => Target.Children.Any(c => c.TriggerOnKeyUp(state, args));
|
2017-03-07 18:30:39 +08:00
|
|
|
|
|
2017-08-21 11:31:21 +08:00
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => Target.Children.Any(c => c.TriggerOnMouseDown(state, args));
|
2017-03-07 18:30:39 +08:00
|
|
|
|
|
2017-08-21 11:31:21 +08:00
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) => Target.Children.Any(c => c.TriggerOnMouseUp(state, args));
|
2017-03-07 18:30:39 +08:00
|
|
|
|
}
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|