mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 07:22:55 +08:00
Share button repeating logic with TimelineButton
for better UX
This commit is contained in:
parent
efbde06c11
commit
b51e0a5047
@ -6,13 +6,11 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Framework.Threading;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Screens.Edit.Timing;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||||
{
|
{
|
||||||
@ -27,7 +25,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
set => button.Icon = value;
|
set => button.Icon = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IconButton button;
|
private readonly TimelineIconButton button;
|
||||||
|
|
||||||
public TimelineButton()
|
public TimelineButton()
|
||||||
{
|
{
|
||||||
@ -54,46 +52,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
IconHoverColour = Color4.White;
|
IconHoverColour = Color4.White;
|
||||||
HoverColour = OsuColour.Gray(0.25f);
|
HoverColour = OsuColour.Gray(0.25f);
|
||||||
FlashColour = OsuColour.Gray(0.5f);
|
FlashColour = OsuColour.Gray(0.5f);
|
||||||
|
|
||||||
|
Add(new RepeatingButtonBehaviour(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledDelegate repeatSchedule;
|
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverSounds(sampleSet);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The initial delay before mouse down repeat begins.
|
|
||||||
/// </summary>
|
|
||||||
private const int repeat_initial_delay = 250;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The delay between mouse down repeats after the initial repeat.
|
|
||||||
/// </summary>
|
|
||||||
private const int repeat_tick_rate = 70;
|
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
|
||||||
{
|
|
||||||
// don't actuate a click since we are manually handling repeats.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnMouseDown(MouseDownEvent e)
|
|
||||||
{
|
|
||||||
if (e.Button == MouseButton.Left)
|
|
||||||
{
|
|
||||||
Action clickAction = () => base.OnClick(new ClickEvent(e.CurrentState, e.Button));
|
|
||||||
|
|
||||||
// run once for initial down
|
|
||||||
clickAction();
|
|
||||||
|
|
||||||
Scheduler.Add(repeatSchedule = new ScheduledDelegate(clickAction, Clock.CurrentTime + repeat_initial_delay, repeat_tick_rate));
|
|
||||||
}
|
|
||||||
|
|
||||||
return base.OnMouseDown(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnMouseUp(MouseUpEvent e)
|
|
||||||
{
|
|
||||||
repeatSchedule?.Cancel();
|
|
||||||
base.OnMouseUp(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user