1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 07:38:21 +08:00
osu-lazer/osu.Game/Screens/Play/KeyCounter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
2.6 KiB
C#
Raw Normal View History

// 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
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
2017-01-27 20:57:22 +08:00
namespace osu.Game.Screens.Play
{
2016-09-24 10:19:50 +08:00
public abstract partial class KeyCounter : Container
{
public readonly Trigger CounterTrigger;
2018-04-13 17:19:50 +08:00
protected Bindable<bool> IsCountingBindable = new BindableBool(true);
2019-02-28 12:31:40 +08:00
private readonly Container content;
protected override Container<Drawable> Content => content;
protected Bindable<int> PressesCount = new BindableInt
2016-09-26 14:07:43 +08:00
{
MinValue = 0
};
2018-04-13 17:19:50 +08:00
public bool IsCounting
{
get => IsCountingBindable.Value;
set => IsCountingBindable.Value = value;
}
2019-02-28 12:31:40 +08:00
public int CountPresses
{
get => PressesCount.Value;
private set => PressesCount.Value = value;
}
2018-04-13 17:19:50 +08:00
protected KeyCounter(Trigger trigger)
{
InternalChildren = new Drawable[]
{
content = new Container
{
RelativeSizeAxes = Axes.Both
},
CounterTrigger = trigger,
};
CounterTrigger.Target = this;
Name = trigger.Name;
}
protected Bindable<bool> IsLit = new BindableBool();
public void Increment()
{
if (!IsCounting)
return;
CountPresses++;
}
public void Decrement()
{
if (!IsCounting)
return;
CountPresses--;
}
protected override bool Handle(UIEvent e) => CounterTrigger.TriggerEvent(e);
public abstract partial class Trigger : Component
{
private KeyCounter? target;
public KeyCounter Target
{
set => target = value;
}
protected Trigger(string name)
{
Name = name;
}
protected void Lit(bool increment = true)
{
if (target == null) return;
target.IsLit.Value = true;
if (increment)
target.Increment();
}
protected void Unlit(bool preserve = true)
{
if (target == null) return;
target.IsLit.Value = false;
if (!preserve)
target.Decrement();
}
}
}
}