2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
2023-02-17 05:59:39 +08:00
|
|
|
|
using System;
|
2023-02-13 09:24:27 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2016-09-23 18:29:25 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-01-27 20:57:22 +08:00
|
|
|
|
namespace osu.Game.Screens.Play
|
2016-09-23 18:29:25 +08:00
|
|
|
|
{
|
2016-09-24 10:19:50 +08:00
|
|
|
|
public abstract partial class KeyCounter : Container
|
2016-09-23 18:29:25 +08:00
|
|
|
|
{
|
2023-02-14 05:59:17 +08:00
|
|
|
|
public readonly InputTrigger Trigger;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-02-13 09:24:27 +08:00
|
|
|
|
protected Bindable<bool> IsCountingBindable = new BindableBool(true);
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2023-02-13 18:59:10 +08:00
|
|
|
|
private readonly Container content;
|
|
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
2023-02-13 09:24:27 +08:00
|
|
|
|
protected Bindable<int> PressesCount = new BindableInt
|
2016-09-26 14:07:43 +08:00
|
|
|
|
{
|
2023-02-13 09:24:27 +08:00
|
|
|
|
MinValue = 0
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-02-13 09:24:27 +08:00
|
|
|
|
public bool IsCounting
|
|
|
|
|
{
|
|
|
|
|
get => IsCountingBindable.Value;
|
|
|
|
|
set => IsCountingBindable.Value = value;
|
|
|
|
|
}
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2023-02-13 09:24:27 +08:00
|
|
|
|
public int CountPresses
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
2023-02-13 09:24:27 +08:00
|
|
|
|
get => PressesCount.Value;
|
|
|
|
|
private set => PressesCount.Value = value;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-02-14 05:59:17 +08:00
|
|
|
|
protected KeyCounter(InputTrigger trigger)
|
2023-02-13 18:59:10 +08:00
|
|
|
|
{
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
2023-02-14 05:59:17 +08:00
|
|
|
|
Trigger = trigger,
|
2023-02-13 18:59:10 +08:00
|
|
|
|
};
|
|
|
|
|
|
2023-02-17 05:59:39 +08:00
|
|
|
|
Trigger.OnLightUp += LightUp;
|
|
|
|
|
Trigger.OnUnlight += Unlight;
|
|
|
|
|
|
2023-02-13 18:59:10 +08:00
|
|
|
|
Name = trigger.Name;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 09:24:27 +08:00
|
|
|
|
protected Bindable<bool> IsLit = new BindableBool();
|
|
|
|
|
|
2019-09-12 14:41:53 +08:00
|
|
|
|
public void Increment()
|
|
|
|
|
{
|
|
|
|
|
if (!IsCounting)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CountPresses++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Decrement()
|
|
|
|
|
{
|
|
|
|
|
if (!IsCounting)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CountPresses--;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-17 05:59:39 +08:00
|
|
|
|
protected virtual void LightUp(bool increment = true)
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
2023-02-17 05:59:39 +08:00
|
|
|
|
IsLit.Value = true;
|
|
|
|
|
if (increment)
|
|
|
|
|
Increment();
|
|
|
|
|
}
|
2023-02-13 09:24:27 +08:00
|
|
|
|
|
2023-02-17 05:59:39 +08:00
|
|
|
|
protected virtual void Unlight(bool preserve = true)
|
|
|
|
|
{
|
|
|
|
|
IsLit.Value = false;
|
|
|
|
|
if (!preserve)
|
|
|
|
|
Decrement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
Trigger.OnLightUp -= LightUp;
|
|
|
|
|
Trigger.OnUnlight -= Unlight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract partial class InputTrigger : Component
|
|
|
|
|
{
|
|
|
|
|
public event Action<bool>? OnLightUp;
|
|
|
|
|
public event Action<bool>? OnUnlight;
|
2023-02-13 09:24:27 +08:00
|
|
|
|
|
2023-02-14 05:59:17 +08:00
|
|
|
|
protected InputTrigger(string name)
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
2023-02-13 09:24:27 +08:00
|
|
|
|
Name = name;
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
2023-02-13 09:24:27 +08:00
|
|
|
|
|
2023-02-17 05:59:39 +08:00
|
|
|
|
protected void LightUp(bool increment = true) => OnLightUp?.Invoke(increment);
|
2023-02-13 09:24:27 +08:00
|
|
|
|
|
2023-02-17 05:59:39 +08:00
|
|
|
|
protected void Unlight(bool preserve = true) => OnUnlight?.Invoke(preserve);
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
2016-09-23 18:29:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|