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
|
|
|
|
|
2017-08-21 03:31:21 +00:00
|
|
|
|
using System;
|
2023-02-22 14:58:27 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-03-07 10:30:39 +00:00
|
|
|
|
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;
|
2023-02-22 14:58:27 +00:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
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;
|
2018-09-18 08:48:37 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2017-05-23 08:53:42 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-03-07 07:28:54 +00:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2016-09-24 01:53:58 +00:00
|
|
|
|
{
|
2023-03-07 07:31:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A flowing display of all gameplay keys. Individual keys can be added using <see cref="InputTrigger"/> implementations.
|
|
|
|
|
/// </summary>
|
2023-03-08 00:47:16 +00:00
|
|
|
|
public abstract partial class KeyCounterDisplay : CompositeDrawable
|
2016-09-24 01:53:58 +00:00
|
|
|
|
{
|
2020-02-03 17:00:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the key counter should be visible regardless of the configuration value.
|
|
|
|
|
/// This is true by default, but can be changed.
|
|
|
|
|
/// </summary>
|
2023-02-22 14:58:27 +00:00
|
|
|
|
public Bindable<bool> AlwaysVisible { get; } = new Bindable<bool>(true);
|
|
|
|
|
|
2023-03-08 00:47:16 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The <see cref="KeyCounter"/>s contained in this <see cref="KeyCounterDisplay"/>.
|
|
|
|
|
/// </summary>
|
2023-03-08 21:10:34 +00:00
|
|
|
|
public abstract IEnumerable<KeyCounter> Counters { get; }
|
2023-03-08 00:47:16 +00:00
|
|
|
|
|
2023-03-08 00:58:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the actions reported by all <see cref="InputTrigger"/>s within this <see cref="KeyCounterDisplay"/> should be counted.
|
|
|
|
|
/// </summary>
|
2023-02-22 14:58:27 +00:00
|
|
|
|
public Bindable<bool> IsCounting { get; } = new BindableBool(true);
|
|
|
|
|
|
|
|
|
|
protected readonly Bindable<bool> ConfigVisibility = new Bindable<bool>();
|
|
|
|
|
|
|
|
|
|
protected abstract void UpdateVisibility();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-08 00:58:54 +00:00
|
|
|
|
/// <summary>
|
2023-03-15 09:02:41 +00:00
|
|
|
|
/// Add a <see cref="InputTrigger"/> to this display.
|
2023-03-08 00:58:54 +00:00
|
|
|
|
/// </summary>
|
2023-03-15 09:02:41 +00:00
|
|
|
|
public abstract void Add(InputTrigger trigger);
|
2023-02-22 14:58:27 +00:00
|
|
|
|
|
2023-03-08 00:58:54 +00:00
|
|
|
|
/// <summary>
|
2023-03-15 09:02:41 +00:00
|
|
|
|
/// Add a range of <see cref="InputTrigger"/> to this display.
|
2023-03-08 00:58:54 +00:00
|
|
|
|
/// </summary>
|
2023-03-15 09:02:41 +00:00
|
|
|
|
public void AddRange(IEnumerable<InputTrigger> triggers) => triggers.ForEach(Add);
|
2023-02-22 14:58:27 +00:00
|
|
|
|
|
2017-05-23 08:53:42 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
|
{
|
2023-02-13 01:33:09 +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
|
|
|
|
|
2023-02-13 01:33:09 +00:00
|
|
|
|
AlwaysVisible.BindValueChanged(_ => UpdateVisibility());
|
|
|
|
|
ConfigVisibility.BindValueChanged(_ => UpdateVisibility(), true);
|
2017-05-23 08:53:42 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-26 05:01:15 +00:00
|
|
|
|
public override bool HandleNonPositionalInput => receptor == null;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-02-22 14:58:27 +00:00
|
|
|
|
public override bool HandlePositionalInput => receptor == null;
|
2023-02-13 01:33:09 +00:00
|
|
|
|
|
2017-03-07 10:30:39 +00:00
|
|
|
|
public partial 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)
|
2017-03-07 10:30:39 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-08-21 03:31:21 +00:00
|
|
|
|
Depth = float.MinValue;
|
|
|
|
|
Target = target;
|
2017-03-07 10:30:39 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
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)
|
|
|
|
|
{
|
2022-06-24 12:25:23 +00:00
|
|
|
|
case KeyDownEvent:
|
|
|
|
|
case KeyUpEvent:
|
|
|
|
|
case MouseDownEvent:
|
|
|
|
|
case MouseUpEvent:
|
2023-03-07 07:21:57 +00:00
|
|
|
|
return Target.InternalChildren.Any(c => c.TriggerEvent(e));
|
2018-09-18 08:48:37 +00:00
|
|
|
|
}
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-09-18 08:48:37 +00:00
|
|
|
|
return base.Handle(e);
|
|
|
|
|
}
|
2017-03-07 10:30:39 +00:00
|
|
|
|
}
|
2016-09-24 01:53:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|