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;
|
2018-05-21 23:49:33 +08:00
|
|
|
|
using osu.Framework.MathUtils;
|
2018-04-21 23:24:31 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-05-22 00:44:06 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-04-21 23:24:31 +08:00
|
|
|
|
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-21 23:02:03 +08:00
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => button.ReceiveMouseInputAt(screenSpacePos);
|
|
|
|
|
|
2018-05-04 04:50:30 +08:00
|
|
|
|
private readonly Button button;
|
2018-05-11 02:08:02 +08:00
|
|
|
|
|
2018-05-22 00:44:06 +08:00
|
|
|
|
public Action Action
|
2018-05-04 04:29:58 +08:00
|
|
|
|
{
|
2018-05-22 00:44:06 +08:00
|
|
|
|
set => button.Action = value;
|
2018-05-04 04:29:58 +08:00
|
|
|
|
}
|
2018-04-21 23:24:31 +08:00
|
|
|
|
|
2018-05-21 23:49:33 +08:00
|
|
|
|
private readonly OsuSpriteText text;
|
2018-05-21 23:02:03 +08:00
|
|
|
|
|
2018-05-04 04:50:30 +08:00
|
|
|
|
public QuitButton()
|
2018-04-21 23:24:31 +08:00
|
|
|
|
{
|
2018-04-22 01:21:09 +08:00
|
|
|
|
Direction = FillDirection.Horizontal;
|
|
|
|
|
Spacing = new Vector2(20, 0);
|
2018-05-21 23:02:03 +08:00
|
|
|
|
Margin = new MarginPadding(10);
|
2018-04-21 23:24:31 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
text = new OsuSpriteText
|
|
|
|
|
{
|
2018-05-22 01:09:52 +08:00
|
|
|
|
Text = "hold for menu",
|
2018-04-22 01:21:09 +08:00
|
|
|
|
Font = @"Exo2.0-Bold",
|
2018-04-21 23:24:31 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft
|
|
|
|
|
},
|
2018-05-21 23:02:03 +08:00
|
|
|
|
button = new Button()
|
2018-04-21 23:24:31 +08:00
|
|
|
|
};
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-21 23:02:03 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
text.FadeInFromZero(500, Easing.OutQuint).Delay(1500).FadeOut(500, Easing.OutQuint);
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
text.FadeIn(500, Easing.OutQuint);
|
2018-05-22 01:05:08 +08:00
|
|
|
|
return true;
|
2018-05-21 23:02:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
text.FadeOut(500, Easing.OutQuint);
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-21 23:49:33 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
float adjust = Vector2.Distance(GetContainingInputManager().CurrentState.Mouse.NativeState.Position, button.ScreenSpaceDrawQuad.Centre) / 200;
|
|
|
|
|
double elapsed = MathHelper.Clamp(Clock.ElapsedFrameTime, 0, 1000);
|
|
|
|
|
|
2018-05-22 00:44:06 +08:00
|
|
|
|
bool stayVisible = text.Alpha > 0 || button.Progress.Value > 0 || IsHovered;
|
2018-05-21 23:49:33 +08:00
|
|
|
|
|
|
|
|
|
Alpha = stayVisible ? 1 : Interpolation.ValueAt(elapsed, Alpha, MathHelper.Clamp(1 - adjust, 0.04f, 1), 0, 200, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 00:44:06 +08:00
|
|
|
|
private class Button : HoldToCofirmContainer
|
2018-04-21 23:24:31 +08:00
|
|
|
|
{
|
|
|
|
|
private SpriteIcon icon;
|
2018-05-22 01:08:44 +08:00
|
|
|
|
private CircularProgress circularProgress;
|
2018-05-21 23:49:33 +08:00
|
|
|
|
private Circle innerCircle;
|
|
|
|
|
|
2018-05-22 01:08:44 +08:00
|
|
|
|
protected override bool AllowMultipleFires => true;
|
|
|
|
|
|
2018-04-21 23:24:31 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(60);
|
2018-05-22 00:44:06 +08:00
|
|
|
|
|
|
|
|
|
Child = new CircularContainer
|
2018-04-21 23:24:31 +08:00
|
|
|
|
{
|
2018-05-22 00:44:06 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
2018-04-21 23:24:31 +08:00
|
|
|
|
{
|
2018-05-22 00:44:06 +08:00
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colours.Gray1,
|
|
|
|
|
Alpha = 0.5f,
|
|
|
|
|
},
|
2018-05-22 01:08:44 +08:00
|
|
|
|
circularProgress = new CircularProgress
|
2018-05-22 00:44:06 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
InnerRadius = 1
|
|
|
|
|
},
|
|
|
|
|
innerCircle = new Circle
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colours.Gray1,
|
|
|
|
|
Size = new Vector2(0.9f),
|
|
|
|
|
},
|
|
|
|
|
icon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Shadow = false,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(15),
|
|
|
|
|
Icon = FontAwesome.fa_close
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-22 01:08:44 +08:00
|
|
|
|
bind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void bind()
|
|
|
|
|
{
|
|
|
|
|
circularProgress.Current.BindTo(Progress);
|
2018-05-22 00:44:06 +08:00
|
|
|
|
Progress.ValueChanged += v => icon.Scale = new Vector2(1 + (float)v * 0.4f);
|
2018-04-21 23:24:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 01:08:44 +08:00
|
|
|
|
private bool pendingAnimation;
|
|
|
|
|
|
2018-05-22 00:44:06 +08:00
|
|
|
|
protected override void Confirm()
|
2018-04-21 23:24:31 +08:00
|
|
|
|
{
|
2018-05-22 00:44:06 +08:00
|
|
|
|
base.Confirm();
|
2018-05-22 01:08:44 +08:00
|
|
|
|
|
|
|
|
|
// temporarily unbind as to not look weird during flash animation.
|
|
|
|
|
Progress.UnbindAll();
|
|
|
|
|
pendingAnimation = true;
|
|
|
|
|
|
|
|
|
|
innerCircle.ScaleTo(0, 100)
|
|
|
|
|
.Then().FadeOut().ScaleTo(1).FadeIn(500)
|
|
|
|
|
.OnComplete(a => circularProgress.FadeOut(100).OnComplete(_ =>
|
|
|
|
|
{
|
|
|
|
|
bind();
|
|
|
|
|
circularProgress.FadeIn();
|
|
|
|
|
pendingAnimation = false;
|
|
|
|
|
}));
|
2018-05-22 00:44:06 +08:00
|
|
|
|
}
|
2018-04-22 00:25:21 +08:00
|
|
|
|
|
2018-05-22 00:44:06 +08:00
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
2018-05-22 01:08:44 +08:00
|
|
|
|
if (!pendingAnimation && state.Mouse.Buttons.Count == 1)
|
2018-05-22 00:44:06 +08:00
|
|
|
|
BeginConfirm();
|
|
|
|
|
return true;
|
2018-04-21 23:24:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
|
|
|
|
{
|
2018-05-22 00:44:06 +08:00
|
|
|
|
if (state.Mouse.Buttons.Count == 0)
|
|
|
|
|
AbortConfirm();
|
|
|
|
|
return true;
|
2018-04-21 23:24:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|