mirror of
https://github.com/ppy/osu
synced 2025-01-09 23:59:44 +00:00
Implement CircularProgress filling
This commit is contained in:
parent
633c775306
commit
3b621db460
@ -10,6 +10,7 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
@ -47,22 +48,24 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
private CircularProgress progress;
|
private CircularProgress progress;
|
||||||
|
|
||||||
private Action exitAction;
|
private Action exitAction;
|
||||||
private readonly Scheduler scheduler;
|
|
||||||
private ScheduledDelegate scheduledExitAction;
|
private ScheduledDelegate scheduledExitAction;
|
||||||
|
|
||||||
|
private readonly Scheduler scheduler;
|
||||||
|
private readonly StopwatchClock stopwatchClock;
|
||||||
|
|
||||||
private const int fade_duration = 200;
|
private const int fade_duration = 200;
|
||||||
|
private const int text_display_time = 5000;
|
||||||
|
|
||||||
public HoldToQuitButton(OsuSpriteText text)
|
public HoldToQuitButton(OsuSpriteText text)
|
||||||
{
|
{
|
||||||
this.text = text;
|
this.text = text;
|
||||||
scheduler = new Scheduler();
|
scheduler = new Scheduler();
|
||||||
|
stopwatchClock = new StopwatchClock();
|
||||||
|
|
||||||
// TODO provide action
|
// TODO provide action
|
||||||
exitAction = () => Thread.Sleep(1);
|
exitAction = () => Thread.Sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideText() => scheduler.AddDelayed(() => text.FadeOut(fade_duration), 5000);
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
@ -83,34 +86,42 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
Size = new Vector2(15),
|
Size = new Vector2(15),
|
||||||
Icon = FontAwesome.fa_close
|
Icon = FontAwesome.fa_close
|
||||||
},
|
},
|
||||||
progress = new CircularProgress { RelativeSizeAxes = Axes.Both, InnerRadius = 0.1f, Current = { Value = 1 } }
|
progress = new CircularProgress { RelativeSizeAxes = Axes.Both, InnerRadius = 0.1f }
|
||||||
});
|
});
|
||||||
progress.Hide();
|
scheduler.AddDelayed(() => text.FadeOut(fade_duration), text_display_time);
|
||||||
hideText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||||
{
|
{
|
||||||
icon.ScaleTo(1.5f);
|
icon.ScaleTo(1.5f);
|
||||||
text.FadeIn(fade_duration);
|
text.FadeIn(fade_duration);
|
||||||
progress.FadeIn(1000);
|
stopwatchClock.Restart();
|
||||||
scheduledExitAction = scheduler.AddDelayed(exitAction, 1000);
|
scheduledExitAction = scheduler.AddDelayed(exitAction, 1000);
|
||||||
|
|
||||||
return base.OnMouseDown(state, args);
|
return base.OnMouseDown(state, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||||
{
|
{
|
||||||
icon.ScaleTo(1f);
|
icon.ScaleTo(1f);
|
||||||
hideText();
|
scheduler.AddDelayed(() => text.FadeOut(fade_duration), text_display_time);
|
||||||
|
stopwatchClock.Stop();
|
||||||
if (scheduledExitAction != null && !scheduledExitAction.Completed)
|
if (scheduledExitAction != null && !scheduledExitAction.Completed)
|
||||||
scheduledExitAction.Cancel();
|
scheduledExitAction.Cancel();
|
||||||
progress.FadeOut(fade_duration);
|
progress.Current.SetDefault();
|
||||||
|
|
||||||
return base.OnMouseUp(state, args);
|
return base.OnMouseUp(state, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
scheduler.Update();
|
scheduler.Update();
|
||||||
|
if (stopwatchClock.IsRunning)
|
||||||
|
{
|
||||||
|
var clampedTime = MathHelper.Clamp(stopwatchClock.CurrentTime, 0, 1000);
|
||||||
|
progress.Current.Value = clampedTime / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
base.Update();
|
base.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user