mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 18:42:56 +08:00
HoldToQuitButton cleanup
This commit is contained in:
parent
b3cf381c5d
commit
c78c5195f3
@ -8,8 +8,6 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using OpenTK;
|
||||
@ -46,20 +44,12 @@ namespace osu.Game.Screens.Play.HUD
|
||||
private CircularProgress progress;
|
||||
|
||||
public Action ExitAction { get; set; }
|
||||
private ScheduledDelegate scheduledExitAction;
|
||||
|
||||
private readonly Scheduler scheduler;
|
||||
private readonly StopwatchClock stopwatchClock;
|
||||
|
||||
private const int fade_duration = 200;
|
||||
private const int progress_duration = 1000;
|
||||
private const int text_display_time = 5000;
|
||||
|
||||
public HoldToQuitButton(OsuSpriteText text)
|
||||
{
|
||||
this.text = text;
|
||||
scheduler = new Scheduler();
|
||||
stopwatchClock = new StopwatchClock();
|
||||
}
|
||||
public HoldToQuitButton(OsuSpriteText text) => this.text = text;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
@ -83,15 +73,14 @@ namespace osu.Game.Screens.Play.HUD
|
||||
},
|
||||
progress = new CircularProgress { RelativeSizeAxes = Axes.Both, InnerRadius = 0.1f }
|
||||
});
|
||||
scheduler.AddDelayed(() => text.FadeOut(fade_duration), text_display_time);
|
||||
Scheduler.AddDelayed(() => text.FadeOut(fade_duration), text_display_time);
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||
{
|
||||
icon.ScaleTo(1.5f);
|
||||
text.FadeIn(fade_duration);
|
||||
stopwatchClock.Restart();
|
||||
scheduledExitAction = scheduler.AddDelayed(ExitAction, 1000);
|
||||
progress.FillTo(1, progress_duration).OnComplete(cp => ExitAction());
|
||||
|
||||
return base.OnMouseDown(state, args);
|
||||
}
|
||||
@ -99,26 +88,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||
{
|
||||
icon.ScaleTo(1f);
|
||||
scheduler.AddDelayed(() => text.FadeOut(fade_duration), text_display_time);
|
||||
stopwatchClock.Stop();
|
||||
if (scheduledExitAction != null && !scheduledExitAction.Completed)
|
||||
scheduledExitAction.Cancel();
|
||||
progress.Current.SetDefault();
|
||||
Scheduler.AddDelayed(() => text.FadeOut(fade_duration), text_display_time);
|
||||
progress.FillTo(0, progress_duration / 4).OnComplete(cp => progress.Current.SetDefault());
|
||||
|
||||
return base.OnMouseUp(state, args);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
scheduler.Update();
|
||||
if (stopwatchClock.IsRunning)
|
||||
{
|
||||
var clampedTime = MathHelper.Clamp(stopwatchClock.CurrentTime, 0, 1000);
|
||||
progress.Current.Value = clampedTime / 1000;
|
||||
}
|
||||
|
||||
base.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user