1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 03:12:54 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/QuitButton.cs

104 lines
3.4 KiB
C#
Raw Normal View History

2018-04-21 23:24:31 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using OpenTK;
namespace osu.Game.Screens.Play.HUD
{
2018-05-04 04:50:30 +08:00
public class QuitButton : FillFlowContainer
2018-04-21 23:24:31 +08:00
{
2018-05-04 04:50:30 +08:00
private readonly Button button;
public Action ExitAction
{
get => button.ExitAction;
set => button.ExitAction = value;
}
2018-04-21 23:24:31 +08:00
2018-05-04 04:50:30 +08:00
public QuitButton()
2018-04-21 23:24:31 +08:00
{
OsuSpriteText text;
Direction = FillDirection.Horizontal;
Spacing = new Vector2(20, 0);
2018-04-21 23:24:31 +08:00
Children = new Drawable[]
{
text = new OsuSpriteText
{
Text = "Hold to Quit",
Font = @"Exo2.0-Bold",
2018-04-21 23:24:31 +08:00
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
2018-05-04 04:50:30 +08:00
button = new Button(text)
2018-04-21 23:24:31 +08:00
};
AutoSizeAxes = Axes.Both;
}
2018-05-04 04:50:30 +08:00
private class Button : CircularContainer
2018-04-21 23:24:31 +08:00
{
private readonly OsuSpriteText text;
private SpriteIcon icon;
private CircularProgress progress;
public Action ExitAction { get; set; }
2018-04-22 00:25:21 +08:00
2018-04-21 23:24:31 +08:00
private const int fade_duration = 200;
2018-04-29 01:43:41 +08:00
private const int progress_duration = 1000;
2018-04-22 00:25:21 +08:00
private const int text_display_time = 5000;
2018-04-21 23:24:31 +08:00
2018-05-04 04:50:30 +08:00
public Button(OsuSpriteText text) => this.text = text;
2018-04-21 23:24:31 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Masking = true;
Size = new Vector2(60);
AddRange(new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Gray1,
Alpha = 0.8f,
},
icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(15),
Icon = FontAwesome.fa_close
},
2018-04-22 00:25:21 +08:00
progress = new CircularProgress { RelativeSizeAxes = Axes.Both, InnerRadius = 0.1f }
2018-04-21 23:24:31 +08:00
});
2018-04-29 01:43:41 +08:00
Scheduler.AddDelayed(() => text.FadeOut(fade_duration), text_display_time);
2018-04-21 23:24:31 +08:00
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
icon.ScaleTo(1.5f);
text.FadeIn(fade_duration);
2018-04-29 01:43:41 +08:00
progress.FillTo(1, progress_duration).OnComplete(cp => ExitAction());
2018-04-22 00:25:21 +08:00
2018-04-21 23:24:31 +08:00
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
icon.ScaleTo(1f);
2018-04-29 01:43:41 +08:00
Scheduler.AddDelayed(() => text.FadeOut(fade_duration), text_display_time);
progress.FillTo(0, progress_duration / 4).OnComplete(cp => progress.Current.SetDefault());
2018-04-22 00:25:21 +08:00
2018-04-21 23:24:31 +08:00
return base.OnMouseUp(state, args);
}
}
}
}