2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2018-07-22 22:16:17 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-09-18 16:48:37 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-07-23 04:58:21 +08:00
|
|
|
|
using osu.Framework.Timing;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using OpenTK;
|
2018-07-23 04:58:21 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
|
|
|
|
public class KeyCounterCollection : FillFlowContainer<KeyCounter>
|
|
|
|
|
{
|
|
|
|
|
private const int duration = 100;
|
|
|
|
|
|
2018-06-12 16:59:59 +08:00
|
|
|
|
public readonly Bindable<bool> Visible = new Bindable<bool>(true);
|
2018-06-13 10:38:15 +08:00
|
|
|
|
private readonly Bindable<bool> configVisibility = new Bindable<bool>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public KeyCounterCollection()
|
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Horizontal;
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Add(KeyCounter key)
|
|
|
|
|
{
|
|
|
|
|
if (key == null) throw new ArgumentNullException(nameof(key));
|
|
|
|
|
|
|
|
|
|
base.Add(key);
|
|
|
|
|
key.IsCounting = IsCounting;
|
|
|
|
|
key.FadeTime = FadeTime;
|
|
|
|
|
key.KeyDownTextColor = KeyDownTextColor;
|
|
|
|
|
key.KeyUpTextColor = KeyUpTextColor;
|
2018-09-08 02:39:41 +08:00
|
|
|
|
// Use the same clock object as SongProgress for saving KeyCounter state
|
|
|
|
|
if (AudioClock != null)
|
|
|
|
|
key.Clock = AudioClock;
|
2018-07-23 00:42:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public void ResetCount()
|
|
|
|
|
{
|
|
|
|
|
foreach (var counter in Children)
|
|
|
|
|
counter.ResetCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
|
{
|
2018-06-13 10:38:15 +08:00
|
|
|
|
config.BindWith(OsuSetting.KeyOverlay, configVisibility);
|
2018-06-12 16:59:59 +08:00
|
|
|
|
|
|
|
|
|
Visible.BindValueChanged(_ => updateVisibility());
|
2018-06-13 10:38:15 +08:00
|
|
|
|
configVisibility.BindValueChanged(_ => updateVisibility(), true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-20 16:08:25 +08:00
|
|
|
|
private bool isCounting = true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public bool IsCounting
|
|
|
|
|
{
|
|
|
|
|
get { return isCounting; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == isCounting) return;
|
|
|
|
|
|
|
|
|
|
isCounting = value;
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
child.IsCounting = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int fadeTime;
|
|
|
|
|
public int FadeTime
|
|
|
|
|
{
|
|
|
|
|
get { return fadeTime; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != fadeTime)
|
|
|
|
|
{
|
|
|
|
|
fadeTime = value;
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
child.FadeTime = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 keyDownTextColor = Color4.DarkGray;
|
|
|
|
|
public Color4 KeyDownTextColor
|
|
|
|
|
{
|
|
|
|
|
get { return keyDownTextColor; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != keyDownTextColor)
|
|
|
|
|
{
|
|
|
|
|
keyDownTextColor = value;
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
child.KeyDownTextColor = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 keyUpTextColor = Color4.White;
|
|
|
|
|
public Color4 KeyUpTextColor
|
|
|
|
|
{
|
|
|
|
|
get { return keyUpTextColor; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != keyUpTextColor)
|
|
|
|
|
{
|
|
|
|
|
keyUpTextColor = value;
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
child.KeyUpTextColor = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 10:38:15 +08:00
|
|
|
|
private void updateVisibility() => this.FadeTo(Visible.Value || configVisibility.Value ? 1 : 0, duration);
|
2018-06-12 16:59:59 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public override bool HandleKeyboardInput => receptor == null;
|
|
|
|
|
public override bool HandleMouseInput => receptor == null;
|
|
|
|
|
|
2018-09-08 02:39:41 +08:00
|
|
|
|
public IFrameBasedClock AudioClock { get; set; }
|
2018-07-22 22:16:17 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private Receptor receptor;
|
|
|
|
|
|
|
|
|
|
public Receptor GetReceptor()
|
|
|
|
|
{
|
|
|
|
|
return receptor ?? (receptor = new Receptor(this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Receptor : Drawable
|
|
|
|
|
{
|
|
|
|
|
protected readonly KeyCounterCollection Target;
|
|
|
|
|
|
|
|
|
|
public Receptor(KeyCounterCollection target)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
Depth = float.MinValue;
|
|
|
|
|
Target = target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
protected override bool Handle(UIEvent e)
|
|
|
|
|
{
|
|
|
|
|
switch (e)
|
|
|
|
|
{
|
|
|
|
|
case KeyDownEvent _:
|
|
|
|
|
case KeyUpEvent _:
|
|
|
|
|
case MouseDownEvent _:
|
|
|
|
|
case MouseUpEvent _:
|
|
|
|
|
return Target.Children.Any(c => c.TriggerEvent(e));
|
|
|
|
|
}
|
|
|
|
|
return base.Handle(e);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|