2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework;
|
|
|
|
|
using osu.Framework.Allocation;
|
2018-07-23 04:57:55 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2020-01-09 12:43:44 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2021-05-05 16:50:25 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2021-05-05 16:50:25 +08:00
|
|
|
|
using osu.Game.Screens.Ranking;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2020-05-18 18:37:49 +08:00
|
|
|
|
public class SkipOverlay : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly double startTime;
|
|
|
|
|
|
2019-11-21 17:57:19 +08:00
|
|
|
|
public Action RequestSkip;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private Button button;
|
2020-05-16 01:43:01 +08:00
|
|
|
|
private ButtonContainer buttonContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private Box remainingTimeBox;
|
|
|
|
|
|
|
|
|
|
private FadeContainer fadeContainer;
|
|
|
|
|
private double displayTime;
|
|
|
|
|
|
2021-08-25 23:50:55 +08:00
|
|
|
|
private bool isClickable;
|
|
|
|
|
|
2019-11-21 18:51:22 +08:00
|
|
|
|
[Resolved]
|
2022-08-15 16:11:22 +08:00
|
|
|
|
private IGameplayClock gameplayClock { get; set; }
|
2019-11-21 18:51:22 +08:00
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-05-05 19:20:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays a skip overlay, giving the user the ability to skip forward.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="startTime">The time at which gameplay begins to appear.</param>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public SkipOverlay(double startTime)
|
|
|
|
|
{
|
|
|
|
|
this.startTime = startTime;
|
|
|
|
|
|
|
|
|
|
RelativePositionAxes = Axes.Both;
|
2019-01-11 15:54:42 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
Position = new Vector2(0.5f, 0.7f);
|
2019-01-11 15:54:42 +08:00
|
|
|
|
Size = new Vector2(1, 100);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-05 12:26:54 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2019-11-21 18:51:22 +08:00
|
|
|
|
private void load(OsuColour colours)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-05-18 18:37:49 +08:00
|
|
|
|
InternalChild = buttonContainer = new ButtonContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-05-16 01:43:01 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Child = fadeContainer = new FadeContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
button = new Button
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
remainingTimeBox = new Box
|
|
|
|
|
{
|
|
|
|
|
Height = 5,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Colour = colours.Yellow,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const double fade_time = 300;
|
|
|
|
|
|
2021-04-14 16:47:11 +08:00
|
|
|
|
private double fadeOutBeginTime => startTime - MasterGameplayClockContainer.MINIMUM_SKIP_TIME;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-05 16:50:25 +08:00
|
|
|
|
public override void Hide()
|
|
|
|
|
{
|
|
|
|
|
base.Hide();
|
|
|
|
|
fadeContainer.Hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Show()
|
|
|
|
|
{
|
|
|
|
|
base.Show();
|
2021-08-26 12:58:23 +08:00
|
|
|
|
fadeContainer.TriggerShow();
|
2021-05-05 16:50:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2019-05-05 19:20:41 +08:00
|
|
|
|
// skip is not required if there is no extra "empty" time to skip.
|
2019-11-21 18:51:22 +08:00
|
|
|
|
// we may need to remove this if rewinding before the initial player load position becomes a thing.
|
|
|
|
|
if (fadeOutBeginTime < gameplayClock.CurrentTime)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Expire();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 17:57:19 +08:00
|
|
|
|
button.Action = () => RequestSkip?.Invoke();
|
2019-11-21 18:51:22 +08:00
|
|
|
|
displayTime = gameplayClock.CurrentTime;
|
2021-08-26 00:02:27 +08:00
|
|
|
|
|
|
|
|
|
fadeContainer.TriggerShow();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2019-11-21 17:57:19 +08:00
|
|
|
|
|
2021-08-25 23:50:55 +08:00
|
|
|
|
double progress = fadeOutBeginTime <= displayTime ? 1 : Math.Max(0, 1 - (gameplayClock.CurrentTime - displayTime) / (fadeOutBeginTime - displayTime));
|
2019-11-21 18:51:22 +08:00
|
|
|
|
|
|
|
|
|
remainingTimeBox.Width = (float)Interpolation.Lerp(remainingTimeBox.Width, progress, Math.Clamp(Time.Elapsed / 40, 0, 1));
|
|
|
|
|
|
2021-08-25 23:50:55 +08:00
|
|
|
|
isClickable = progress > 0;
|
|
|
|
|
button.Enabled.Value = isClickable;
|
|
|
|
|
buttonContainer.State.Value = isClickable ? Visibility.Visible : Visibility.Hidden;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-08-25 23:50:55 +08:00
|
|
|
|
if (isClickable && !e.HasAnyButtonPressed)
|
2021-08-26 00:02:27 +08:00
|
|
|
|
fadeContainer.TriggerShow();
|
2020-05-16 01:43:01 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnMouseMove(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-11-18 11:35:47 +08:00
|
|
|
|
if (e.Repeat)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
switch (e.Action)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
case GlobalAction.SkipCutscene:
|
2020-11-24 14:42:14 +08:00
|
|
|
|
if (!button.Enabled.Value)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-08-04 16:27:44 +08:00
|
|
|
|
button.TriggerClick();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2020-01-22 12:22:34 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-05 16:50:25 +08:00
|
|
|
|
public class FadeContainer : Container, IStateful<Visibility>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
public event Action<Visibility> StateChanged;
|
|
|
|
|
|
|
|
|
|
private Visibility state;
|
2021-08-26 00:02:27 +08:00
|
|
|
|
private double? nextHideTime;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-07-04 15:53:08 +08:00
|
|
|
|
public override bool IsPresent => true;
|
|
|
|
|
|
2021-08-26 00:02:27 +08:00
|
|
|
|
public void TriggerShow()
|
|
|
|
|
{
|
|
|
|
|
Show();
|
|
|
|
|
|
|
|
|
|
if (!IsHovered && !IsDragged)
|
|
|
|
|
nextHideTime = Time.Current + 1000;
|
|
|
|
|
else
|
|
|
|
|
nextHideTime = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (nextHideTime != null && nextHideTime <= Time.Current)
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
nextHideTime = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public Visibility State
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => state;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2021-08-26 00:02:27 +08:00
|
|
|
|
if (value == state)
|
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
state = value;
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case Visibility.Visible:
|
2021-08-26 00:02:27 +08:00
|
|
|
|
this.FadeIn(500, Easing.OutExpo);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case Visibility.Hidden:
|
|
|
|
|
this.FadeOut(1000, Easing.OutExpo);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StateChanged?.Invoke(State);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-07-04 15:21:01 +08:00
|
|
|
|
Show();
|
2021-08-26 00:02:27 +08:00
|
|
|
|
nextHideTime = null;
|
2019-07-04 15:21:01 +08:00
|
|
|
|
return true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2019-06-11 13:28:52 +08:00
|
|
|
|
|
|
|
|
|
public override void Hide() => State = Visibility.Hidden;
|
|
|
|
|
|
|
|
|
|
public override void Show() => State = Visibility.Visible;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-16 01:43:01 +08:00
|
|
|
|
private class ButtonContainer : VisibilityContainer
|
|
|
|
|
{
|
|
|
|
|
protected override void PopIn() => this.FadeIn(fade_time);
|
|
|
|
|
|
|
|
|
|
protected override void PopOut() => this.FadeOut(fade_time);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private class Button : OsuClickableContainer
|
|
|
|
|
{
|
|
|
|
|
private Color4 colourNormal;
|
|
|
|
|
private Color4 colourHover;
|
|
|
|
|
private Box box;
|
|
|
|
|
private FillFlowContainer flow;
|
|
|
|
|
private Box background;
|
|
|
|
|
private AspectContainer aspect;
|
|
|
|
|
|
2021-01-19 16:11:40 +08:00
|
|
|
|
private Sample sampleConfirm;
|
2018-07-23 04:57:55 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public Button()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-08-31 06:04:40 +08:00
|
|
|
|
private void load(OsuColour colours, AudioManager audio)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
colourNormal = colours.Yellow;
|
|
|
|
|
colourHover = colours.YellowDark;
|
|
|
|
|
|
2021-11-10 16:13:47 +08:00
|
|
|
|
sampleConfirm = audio.Samples.Get(@"UI/submit-select");
|
2018-07-23 04:57:55 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0.2f,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
aspect = new AspectContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Height = 0.6f,
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 15,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
box = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colourNormal,
|
|
|
|
|
},
|
|
|
|
|
flow = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
|
Y = 0.4f,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2019-04-02 18:55:24 +08:00
|
|
|
|
new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.Solid.ChevronRight },
|
|
|
|
|
new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.Solid.ChevronRight },
|
|
|
|
|
new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.Solid.ChevronRight },
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
|
Y = 0.7f,
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 12),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Text = @"SKIP",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
flow.TransformSpacingTo(new Vector2(5), 500, Easing.OutQuint);
|
|
|
|
|
box.FadeColour(colourHover, 500, Easing.OutQuint);
|
|
|
|
|
background.FadeTo(0.4f, 500, Easing.OutQuint);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
flow.TransformSpacingTo(new Vector2(0), 500, Easing.OutQuint);
|
|
|
|
|
box.FadeColour(colourNormal, 500, Easing.OutQuint);
|
|
|
|
|
background.FadeTo(0.2f, 500, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
base.OnHoverLost(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
aspect.ScaleTo(0.75f, 2000, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnMouseDown(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
aspect.ScaleTo(1, 1000, Easing.OutElastic);
|
2020-01-20 17:17:21 +08:00
|
|
|
|
base.OnMouseUp(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
if (!Enabled.Value)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-07-23 04:57:55 +08:00
|
|
|
|
sampleConfirm.Play();
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
box.FlashColour(Color4.White, 500, Easing.OutQuint);
|
|
|
|
|
aspect.ScaleTo(1.2f, 2000, Easing.OutQuint);
|
|
|
|
|
|
2019-11-21 17:57:19 +08:00
|
|
|
|
return base.OnClick(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|