2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2018-07-22 14:16:17 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-02-02 11:46:50 +00:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-09-18 08:48:37 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2019-03-26 02:28:43 +00:00
|
|
|
|
public class KeyCounterDisplay : FillFlowContainer<KeyCounter>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
private const int duration = 100;
|
2019-09-12 05:27:29 +00:00
|
|
|
|
private const double key_fade_time = 80;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-06-12 08:59:59 +00:00
|
|
|
|
public readonly Bindable<bool> Visible = new Bindable<bool>(true);
|
2020-02-02 11:48:07 +00:00
|
|
|
|
protected readonly Bindable<bool> ConfigVisibility = new Bindable<bool>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-26 02:28:43 +00:00
|
|
|
|
public KeyCounterDisplay()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
2019-09-12 05:27:29 +00:00
|
|
|
|
key.FadeTime = key_fade_time;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
key.KeyDownTextColor = KeyDownTextColor;
|
|
|
|
|
key.KeyUpTextColor = KeyUpTextColor;
|
2018-07-22 16:42:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
|
{
|
2020-02-02 11:48:07 +00:00
|
|
|
|
config.BindWith(OsuSetting.KeyOverlay, ConfigVisibility);
|
2019-12-19 14:52:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2018-06-12 08:59:59 +00:00
|
|
|
|
|
|
|
|
|
Visible.BindValueChanged(_ => updateVisibility());
|
2020-02-02 11:48:07 +00:00
|
|
|
|
ConfigVisibility.BindValueChanged(_ => updateVisibility(), true);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-20 08:08:25 +00:00
|
|
|
|
private bool isCounting = true;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public bool IsCounting
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => isCounting;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == isCounting) return;
|
|
|
|
|
|
|
|
|
|
isCounting = value;
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
child.IsCounting = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 keyDownTextColor = Color4.DarkGray;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public Color4 KeyDownTextColor
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => keyDownTextColor;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != keyDownTextColor)
|
|
|
|
|
{
|
|
|
|
|
keyDownTextColor = value;
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
child.KeyDownTextColor = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 keyUpTextColor = Color4.White;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public Color4 KeyUpTextColor
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => keyUpTextColor;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != keyUpTextColor)
|
|
|
|
|
{
|
|
|
|
|
keyUpTextColor = value;
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
child.KeyUpTextColor = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:46:50 +00:00
|
|
|
|
private void updateVisibility() =>
|
|
|
|
|
// Change visibility of all key counters internally to isolate from showing them by fading in this container.
|
|
|
|
|
Children.ForEach(k => k.FadeTo(Visible.Value || ConfigVisibility.Value ? 1 : 0, duration));
|
2018-06-12 08:59:59 +00:00
|
|
|
|
|
2018-09-26 05:01:15 +00:00
|
|
|
|
public override bool HandleNonPositionalInput => receptor == null;
|
|
|
|
|
public override bool HandlePositionalInput => receptor == null;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
private Receptor receptor;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2019-03-26 02:28:43 +00:00
|
|
|
|
protected readonly KeyCounterDisplay Target;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-26 02:28:43 +00:00
|
|
|
|
public Receptor(KeyCounterDisplay target)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
Depth = float.MinValue;
|
|
|
|
|
Target = target;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-26 05:01:15 +00:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-18 08:48:37 +00: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));
|
|
|
|
|
}
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-09-18 08:48:37 +00:00
|
|
|
|
return base.Handle(e);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|