1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 20:07:26 +08:00
osu-lazer/osu.Game/Screens/Play/KeyCounter.cs

101 lines
2.4 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;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Play
{
2022-11-24 13:32:20 +08:00
public abstract partial class KeyCounter : Container
2018-04-13 17:19:50 +08:00
{
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
protected Bindable<int> PressesCount = new BindableInt
2018-04-13 17:19:50 +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
2018-04-13 17:19:50 +08:00
{
get => PressesCount.Value;
private set => PressesCount.Value = value;
2018-04-13 17:19:50 +08:00
}
protected Bindable<bool> IsLit = new BindableBool();
public void Increment()
{
if (!IsCounting)
return;
CountPresses++;
}
public void Decrement()
{
if (!IsCounting)
return;
CountPresses--;
}
protected override void LoadComplete()
2018-04-13 17:19:50 +08:00
{
Add(CounterTrigger);
base.LoadComplete();
2018-04-13 17:19:50 +08:00
}
protected override bool Handle(UIEvent e) => CounterTrigger.TriggerEvent(e);
protected KeyCounter(Trigger trigger)
2018-04-13 17:19:50 +08:00
{
CounterTrigger = trigger;
trigger.Target = this;
Name = trigger.Name;
2018-04-13 17:19:50 +08:00
}
public abstract partial class Trigger : Component
2018-04-13 17:19:50 +08:00
{
private KeyCounter? target;
public KeyCounter Target
{
set => target = value;
}
protected Trigger(string name)
2018-04-13 17:19:50 +08:00
{
Name = name;
2018-04-13 17:19:50 +08:00
}
protected void Lit(bool increment = true)
{
if (target == null) return;
target.IsLit.Value = true;
if (increment)
target.Increment();
}
protected void Unlit(bool preserve = true)
2018-04-13 17:19:50 +08:00
{
if (target == null) return;
target.IsLit.Value = false;
if (!preserve)
target.Decrement();
2018-04-13 17:19:50 +08:00
}
}
}
}